jiahuimbzuai/CoQuIR huggingface dataset:
//  [cpp]
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;

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

	int n, m,on=0,off=0; cin >> n; bool flag =true;
	for (int i = 0; i < n; i++) {
		cin >> m;
		if (flag==true) {
			on++;
			flag = false;
		}
		else {
			off++;
			flag = true;
		}
             
	}
	if (on > off)cout << on << endl;
	else cout << -1 << endl;

	return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
          if(n/i==i)
            c++;
          else
            c+=2;
        }

    }

    
    return  c;
}
int func(int n)
{
    return (n*(n+1))/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   
   int n;
   cin>>n;
   int arr[n];
   bool g=false;
   for(int i=0;i<n;i++)
   {
      cin>>arr[i];
      if(arr[i]==2)
        g=true;
   }
     if(g==false)
     {  
        cout<<-1;
        return 0;
     }
  int a=1;
  int c=0;
  int k;
  while(1)
  { 
    k=a;
    a=arr[a-1];
   
    c++;
    if(a==2)
    {
       cout<<c;
       return 0;
    }
     if(arr[a-1]==k && arr[a-1])
    {
       cout<<-1;
       return 0;
    }
    
  }


 return 0;
}
//  [c]
#include <unistd.h>
#include <stdlib.h>

void writing(int ans)
{
    char c;
    if (ans < 10)
    {
        c = ans + '0';
        write(1, &c, 1);
    }
    else
    {
        writing(ans / 10);
        writing(ans % 10);
    }
}

int get_num(char *s)
{
    int num;
    int i;
    
    i = -1;
    while (s[++i] != 10)
    {
        if (s[i] != 32)
        {
            num = 0;
            while ('0' <= s[i] && s[i] <= '9')
            {
                num = num * 10 + s[i++] - '0';
                    
            }
            return (num);
        }
    }  
}

void get_nums(int *array, char *s, int count)
{
    int num;
    int i;
    
    i = -1;
    while (s[++i])
    {
        if (s[i] != 10 && s[i] != 32)
        {
            num = 0;
            while ('0' <= s[i] && s[i] <= '9')
            {
                num = num * 10 + s[i++] - '0';
                if (!s[i])
                {
                    array[count] = num;
                    return ;                    
                }
            }
            array[count++] = num;
            i--;
        }
    }  
}

void get_num_plus(int *tab, char *tmp, int pass_flag, int count)
{
    int i;
    
    i = -1;
    while (count < pass_flag)
    {
        while (tmp[++i] != 10)
            ;
        count++;
    }
    get_nums(tab, &tmp[++i], 0);
}

void get_ans(int n, char *tmp)
{
    int i;
    int j;
    int tab[n];
    int count;
    
    get_num_plus(tab, tmp, 1, 0);
    count = 0;
    j = 0;
    i = -1;
    while (++i < n)
    {
        count++;
        if (tab[j] == 2)
        {
            writing(count);
            return ;
        }
        j = tab[j] - 1;
    }
    write(1, "-1", 2);
}

char *create_array(char *s, char *new_arr, char *t, int size)
{
    int i;
    int j;
    
    i = -1;
    while (s[++i])
        new_arr[i] = s[i];
    free(s);
    j = 0;
    while (j < size)
        new_arr[i++] = t[j++];   
    new_arr[i] = 0;
    return (new_arr);
}

char *get_data(char *s)
{
    int size;
    int sum_size;
    char t[10000000];
    char *new_arr;
    
    sum_size = 0;
    while ((size = read(0, t, 10000000)))
    {
        if (size == -1)
            return (NULL);
        sum_size += size;
        if (!(new_arr = (char*)malloc(sum_size + 1)))
            return (NULL);
        s = create_array(s, new_arr, t, size);
    }
    return (s);
}

int main(void){
    int num;
    char *s;
    
    s = malloc(1);
    s = get_data(s);
    num = get_num(s);
    get_ans(num, s);
    free(s);
    return (0);
}
//  [c]
i,a[1<<17],b[1<<17];c;
buf[1145141];char*p=buf;
main(s){
	for(read(0,buf,1000000);*p;p++)if(*p>10)a[i]=a[i]*10+*p-48;else ++i;
	for(b[i=s]=1;!b[s=a[s]]++&&s-2;i++);
	printf("%d",s==2?i:-1);
}
//  [c]
i,a[1<<17],b[1<<17];c;
main(s){
	for(;~(c=getchar_unlocked());)if(c>10)a[i]=a[i]*10+c-48;else ++i;
	for(b[i=s]=1;!b[s=a[s]]++&&s-2;i++);
	printf("%d",s-2?-1:i);
}
//  [c]
#include <stdio.h>
#include <string.h>
#pragma warning(disable : 4996)

int main()
{
    long N;
    int i,p;
    long a[100001] = {0};
    long count = 0;
    long pp[100001] = {1};

    scanf("%ld", &N);

    for (i = 1; i <= N; i++) {
        scanf("%ld", &a[i]);
    }

    i = 1;
    pp[i++] = p = a[1];
    count++;

    while (1) {
        
       pp[i++] = p = a[p];
       count++;

       if (p == 2)
           break;

       for (int j = 0; j < i - 1; j++) {
           if (p == pp[j]) {
               printf("-1");
               return 0;
           }
       }
       


    }

    printf("%ld", count);

    return 0;

}
//  [c]
#include <stdio.h>
#include <string.h>
#pragma warning(disable : 4996)

int main()
{
    long N;
    int i,p;
    long a[100001] = {0};
    long count = 0;
    long pp[100000] = {1};

    scanf("%ld", &N);

    for (i = 1; i <= N; i++) {
        scanf("%ld", &a[i]);
    }

    i = 1;
    pp[i++] = p = a[1];
    count++;

    while (1) {
        
       pp[i++] = p = a[p];
       count++;

       if (p == 2)
           break;

       for (int j = 0; j < i - 1; j++) {
           if (p == pp[j]) {
               printf("-1");
               return 0;
           }
       }
       


    }

    printf("%ld", count);

    return 0;

}
//  [c]
#include <stdio.h>
#include <string.h>
#pragma warning(disable : 4996)

int main()
{
    long N;
    int i,p;
    long a[100001] = {0};
    long count = 0;
    long pp[10000] = {1};

    scanf("%ld", &N);

    for (i = 1; i <= N; i++) {
        scanf("%ld", &a[i]);
    }

    i = 1;
    pp[i++] = p = a[1];
    count++;

    while (1) {
        
       pp[i++] = p = a[p];
       count++;

       if (p == 2)
           break;

       for (int j = 0; j < i - 1; j++) {
           if (p == pp[j]) {
               printf("-1");
               return 0;
           }
       }
       


    }

    printf("%ld", count);

    return 0;

}
//  [javascript]
'use strict'

function main(s) {

  s = s.split('\n');
  const N = Number(s[0]);
  const buttons = s.slice(1, -1).map(n => Number(n));

  let ans = -1;

  for (var i = 1, j = 0; i <= N; i++) {
    j = buttons[j] - 1;

    if (j === 1) {
      ans = i;
      break;
    }
  }

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = ~~arg[0];
    const S = arg.slice(1, N + 1).map(n=>~~n);
    
    let now = 1;
    let cnt = 0;
    
    while(now !== 2) {
        now = S[now - 1];
        cnt++;
        
        if(cnt > N) {
            console.log(-1);
            return;
        }
    }
    
    console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function Main(input) {
  input = input.split('\n');

  var n = parseInt(input[0], 10);
  var a = [];
  for (var i = 0; i < n; i++) {
    a[i + 1] = parseInt(input[i + 1], 10);
  }

  var cur = 1;
  for (var i = 0; i < n + 100; i++) {
    if (a[cur] == 2) {
      console.log(i + 1);
      return;
    }
    cur = a[cur];
  }

  console.log(-1);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
console.log((args=>{
  let [N,...a] = args.trim().split`\n`.map(v=>v-1);
  let c = a[0];
  for ( let i = 1; i <= N; i++ ) {
    c = a[c];
    if ( c === 1 ) return i+1;
  }
  return '-1';
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
//  [javascript]
'use strict';
function Main(stdin){
  const input = stdin.trim().split(/\r?\n/g).map(str => Number(str));
  const N = input.shift();
  let btn_num = 2;
  let result = -1;
  let count = 0;

  for(let i = 0; i < N; i++){
      if(input.indexOf(btn_num) > -1){
        btn_num = input.indexOf(btn_num) + 1;
        count++;
        if(btn_num === 1){
            result = count;
            break;
        }
      } else {
          break;
      }
  }
  console.log(result);
}

// 固定
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const A = arg.slice(1, N + 1).map(n=>parseInt(n));
    
    let now = 0;
    let cnt = 0;
    let done = [];
    
    while(true) {
        now = A[now] - 1;
        
        if(now === 1) {
            cnt++;
            console.log(cnt);
            return;
        }
        
        cnt++;
        
        console.log("now:" + now)
        console.log("done:" + done)
        
        if(done.indexOf(now) !== -1) {
            console.log(-1);
            return;
        }
        
        done.push(now);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func r() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := r()

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = r() - 1
	}

	var nowIdx int
	var ct int
	for {
		nextIdx := a[nowIdx]

		if ct >= n {
			ct = -1
			break
		}

		if nowIdx == 1 {
			break
		}

		nowIdx = nextIdx
		ct++
	}
	fmt.Println(ct)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func r() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := r()

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = r() - 1
	}

	var nowIdx int
	var ct int
	for {
		nextIdx := a[nowIdx]

		a[nowIdx] = -1

		if nextIdx == -1 {
			ct = -1
			break
		}

		if nowIdx == 1 {
			break
		}

		nowIdx = nextIdx
		ct++
	}
	fmt.Println(ct)
}
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

func NextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	n := NextInt()
	a := make([]int, n)
	for i := range a {
		a[i] = NextInt() - 1
	}

	var now, cnt int
	for {
		if now == 1 {
			fmt.Println(cnt)
			break
		}

		if cnt >= n {
			fmt.Println(-1)
			break
		}

		cnt++
		now = a[now]
	}
}
//  [go]
package main

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

func BufScan(n int) []string {
	var in []string
	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		in = append(in, sc.Text())
	}

	return in
}

func IntBufScan(n int) []int {
	var inInts []int
	inStrings := BufScan(n)
	for _, i := range inStrings {
		tmp, _ := strconv.Atoi(i)
		inInts = append(inInts, tmp)
	}
	return inInts
}

func main() {
	n := 0
	fmt.Scanf("%d", &n)
	a := IntBufScan(n)
	m := 1
	for i := 1; ; i++ {
		m = a[m-1]
		if m == 1 {
			fmt.Println("-1")
			return
		}
		if m == 2 {
			fmt.Println(i)
			return
		}
	}
}
//  [go]
package main

import "fmt"

func main() {
	n := 0
	var a []int
	a = append(a, 0)

	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		tmp := 0
		fmt.Scanf("%d", &tmp)
		a = append(a, tmp)
	}

	m := 1
	for i := 1; ; i++ {
		m = a[m]
		if m == 1 {
			fmt.Println("-1")
			return
		}
		if m == 2 {
			fmt.Println(i)
			return
		}
	}
}
//  [ruby]
n = gets.to_i
as = $<.map(&:to_i)
i = 0
ans = 0
n.times {
  i = as[i] - 1
  ans += 1
  break if i == 1
}
puts (i == 1 ? ans : -1)
//  [ruby]
button = $stdin.read.split("\n")
button.map! do |element|
	element.to_i
end
button.shift()
#p button
#p button.size
current = 1
cnt = 0 
while true
	if current == 2
		print("#{cnt}\n")
		break
	elsif cnt >= button.size
		print("-1\n")
		break
	end
	cnt += 1
	current = button[current-1]
end
//  [ruby]
n = gets.to_i
num = []
n.times do
  num << gets.to_i
end

rec = [1] #光ったことのあるボタンを記録
i = 0
while i >= 0 do
  unless rec.include?(num[rec[i]-1])
    rec << num[rec[i]-1]
  else
    break
  end
  i += 1
end
if rec.include?(2)
  puts rec.index(2)
else
  puts "-1"
end
//  [ruby]
N = gets.to_i
a = N.times.map{ (gets.chomp.to_i) -1 }
cnt = 1
i = a[0]
a[0] = -1

while true
  if a[i] == 1
    cnt += 1
    break
  elsif a[i] == -1
    cnt = -1
    break
  else
    tmp = i
    i = a[i]
    a[tmp] = -1
    cnt += 1
  end
end

puts cnt
//  [ruby]
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> buttons(n);

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    buttons.at(i) = a;
  }

  bool ok = false;
  int cnt = 0;
  int pos = 0;
  while (true) {
    int nextPos = buttons.at(pos);
    cnt++;
    if (nextPos == 2) {
      ok = true;
      break;
    }
    if (nextPos - 1 == pos) {
      break;
    }
      
    pos = nextPos - 1;
  }
      
  if (ok) {
    cout << cnt << endl;
  } else {
    cout << -1 << endl;
  }
}
//  [rust]
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let a: Vec<_> = s.map(|a| a.parse::<i32>().unwrap() - 1).collect();
	let mut visit = vec![false; n];
	let mut cur = 0;
	let mut ans = 0;
	while !visit[cur] {
		visit[cur] = true;
		cur = a[cur] as usize;
		ans += 1;
		if cur == 1 {
			println!("{}", ans);
			return;
		}
	}
	println!("-1");
}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        lit_by: [usize1; n], 
    }
    let mut seen = vec![-1; n];
    let mut now_on = 0usize;
    for i in 0.. {
        let dist = seen.get_mut(now_on).unwrap();
        if *dist != -1 { break; }
        *dist = i;
        if now_on == 1 { break; }

        now_on = *lit_by.get(now_on).unwrap();
    }
    println!("{}", seen[1]);
}
//  [rust]
#![allow(non_snake_case)]
use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    use std::collections::HashMap;
    let mut map: HashMap<usize, usize> = HashMap::new();
    let N: usize = read();
    for i in 1..=N {
        let v: usize = read();
        map.insert(i, v);
    }
    let mut now = 1;
    let mut ans = 0;
    while let Some(v) = map.get(&now) {
        ans += 1;
        if *v == 2 {
            println!("{}", ans);
            return;
        } else if *v == 1 {
            break;
        }
        now = *v;
    }
    println!("{}", -1);
}
//  [rust]
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let mut now = 0;
    let mut cnt = 0;
    for i in 0..n {
        if now == i {
            now = a[i] - 1;
            cnt += 1;
        }
        if now == 1 {
            println!("{}", cnt);
            return;
        }
    }
    println!("-1");
}
//  [swift]
func readInt() -> Int {
    return Int(readLine()!)!
}

func mainB() {
    let n = readInt()
    let bottoms = (0..<n).map { _ in readInt() }

    var flashBotton = 1
    var count = 0
    while true {
        count += 1
        flashBotton = bottoms[flashBotton - 1]
        if flashBotton == 2 {
            print(count)
            return
        }

        if count > 2 * n {
            print(-1)
            return
        }
    }
}

mainB()
//  [swift]
import Foundation

let n = Int(readLine()!)!
var ai: [Int] = []
var ans = 0
var index = 0
for _ in 0..<n {
  ai.append(Int(readLine()!)!)
}
while true {
  ans += 1
  if ans > n || ai[index] == 2 {
    break
  }
  index = ai[index] - 1
}
print(ans > n ? -1 : ans)
//  [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)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
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)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#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 N = readInt()!
var button = [Int]()
for _ in 0..<N {
    button += [readInt()!]
}
var i = 1
for ans in 1...N {
    i = button[i-1]
    if i == 2 {
        print(ans)
        break
    }
    if ans == N {
        print(-1)
    }
}
//  [swift]
func readInt() -> Int {
    return Int(readLine()!)!
}

func mainB() {
    let n = readInt()
    let bottoms = (0..<n).map { _ in readInt() }

    var flashBotton = 1
    var count = 0
    while true {
        count += 1
        flashBotton = bottoms[flashBotton - 1]
        if flashBotton == 2 {
            print(count)
            return
        }

        if count > n * n {
            print(-1)
            return
        }
    }
}

mainB()
//  [swift]
func readInt() -> Int {
    return Int(readLine()!)!
}

func mainB() {
    let n = readInt()
    let bottoms = (0..<n).map { _ in readInt() }

    var flashBotton = 1
    var count = 0
    while true {
        count += 1
        flashBotton = bottoms[flashBotton - 1]
        if flashBotton == 2 {
            print(count)
            return
        }

        if count > n * n * n {
            print(-1)
            return
        }
    }
}

mainB()
//  [swift]
func readInt() -> Int {
    return Int(readLine()!)!
}

func mainB() {
    let n = readInt()
    let bottoms = (0..<n).map { _ in readInt() }

    var flashBotton = 1
    var count = 0
    while true {
        count += 1
        flashBotton = bottoms[flashBotton - 1]
        if flashBotton == 2 {
            print(count)
            return
        }

        if count > n * n * n {
            print(-1)
            return
        }
    }
}
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))}
const main=()=>{
  let n=tn()
  let nr=tnn(n)
  let j=false;
  let i=0
  let cnt=0
  let check=new Array(n)
  check.fill(false)
  while(!j){
    if(i==1){
      to(cnt)
      return
    }
    if(check[i]==true||i==nr[i]-1){
      to(-1)
      return
    }
    check[i]=true
    i=nr[i]-1
    cnt++;
  }
}
main()
//  [typescript]
import * as fs from "fs";

const [line1, ...linesA] = fs.readFileSync("/dev/stdin", "utf8").split("\n");
let N = Number(line1)

let B: number[] = linesA.slice(0, N).map((n) => {return Number(n)-1});
let visited: boolean[] = Array(N).fill(false);

let position = 0;
let steps = 0;

while (position != 1 && visited[position] == false) {
	visited[position] = true;
	position = B[position];
	steps += 1;
}

if (position == 1)
	console.log(steps);
else
	console.log(-1);
//  [typescript]
{
  const run = (input: string) => {
    const list = input.trim().split("\n").map(v => parseInt(v))
    let index = 1
    const used = {}
    while (true) {
      index = list[index]
      if (index === 2) {
        return Object.keys(used).length + 1
      }

      if (used[index] === 1) {
        return -1;
      }
      used[index] = 1
    }
  }

  const Main = (input: string) => {
    console.log(run(input))
  };

  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}
//  [typescript]
{
  const run = (input: string) => {
    const list = input.trim().split("\n").map(v => parseInt(v))
    let index = 1
    let count = 0
    const used = []
    while (true) {
      count++
      index = list[index]
      if (index === 2) {
        return count
      }
      if (used.indexOf(index) >= 0) {
        return -1;
      }
      used.push(index)
    }
  }

  const Main = (input: string) => {
    console.log(run(input))
  };

  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const buttons = input.slice(1, -1).map((line) => Number(line[0]));

  let count = 1;
  let next = buttons[0];

  buttons[0] = -1;

  while (true) {
    const button = buttons[next - 1];
    buttons[next - 1] = -1;

    count += 1;

    if (button === -1) {
      return -1;
    }

    if (button === 2) {
      break;
    }

    next = button;
  }

  return count;
};

console.log(main(read()));
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const buttons = input.slice(1, -1).map((line) => Number(line[0]));

  let count = 1;
  let next = buttons[0];

  while (true) {
    const label = buttons[next - 1];
    buttons[next - 1] = -1;

    next = label;
    count += 1;

    if (next === -1) {
      return -1;
    }

    if (next === 2) {
      break;
    }
  }

  return count;
};

console.log(main(read()));
//  [python]
n,m,k=map(int,input().split())
n,m=min(n,m),max(n,m)
for i in range(n//2+n%2):
  num,dem=k-i*m,n-2*i
  if num%dem or not(0<=num//dem<=m):continue
  print("Yes");exit()
print("No")
//  [python]
N , M , K = input().split()
N = int(N)
M = int(M)
K = int(K)
OK = False


for n in range(N + 1):
    if N == 2*n : 
        if K == N*M / 2 : OK = True
    else :     
        flag =  (K - M * n) % (N - 2*n) == 0
        if(flag):
            m = (K - M * n) / (N - 2*n)
            if( (m >= 0) & (m <= M) ) : 
                OK = True
            
if(OK) : print("Yes")
else : print("No")
//  [python]
nmk = input().split()
n = int(nmk[0])
m = int(nmk[1])
k = int(nmk[2])

message = "No"
for i in range(m):
    x = int(i)
    if m-2*x == 0:
        y=-1
    else:
        y = (-n*x+k)/(m-2*x)
#         print(y)
    if y >= 0 and y <= n and y%1 == 0:
        message="Yes"
        break

print(message)
//  [python]
H, W, K = map(int, input().split())
for h in range(0, H+1):
  for w in range(0, W+1):
    if h*W + w*H - h*w == K:
      print('Yes')
      exit()
print('No')
//  [python]
H, W = map(int, input().split())
for h in range(0, H+1):
  for w in range(0, W+1):
    if h*W + w*H - h*w == K:
      print('Yes')
      exit()
print('No')
//  [python]
n, m, k = map(int, input().split())



for i in range(n):
  for j in range(m):
    a = m*i + n*j - 2*i*j
    if a == k:
      print('Yes')
      exit()
print('No')
//  [java]
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ips = br.readLine().split(" ");
        int n = Integer.parseInt(ips[0]);
        int m = Integer.parseInt(ips[1]);
        int k = Integer.parseInt(ips[2]);
        for(int i = 0; i <= n; ++i){
            int num = (k-m*i);
            int den = (n-2*i);
            if(den==0)
                continue;
            if(num%den == 0 && num/den <= m && num/den >= 0){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}
//  [java]
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= m; j++) {
				if (n * j + m * i - 2 * i * j == k) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}


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 || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}
//  [java]
import java.util.Scanner;

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

			int N = scan.nextInt();
			int M = scan.nextInt();
			int K = scan.nextInt();



			int goukei = 0;
			int ok = 0;
			for(int i = 1;i<=N;i++) {
				for(int j = 1;j<=M;j++) {
					goukei =  i*M+j*N-2*i*j;
					if(goukei==K) {
						ok=1;break;
					}
				}
			}

			if(ok==1)System.out.println("Yes");
			else System.out.println("No");

		}


	}


}
//  [cpp]
#include <cstdio>

int n, m, k;

int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= m; ++j)
      if (i * m + j * n - 2 * i * j == k) return puts("Yes"), 0;
  puts("No");
  return 0;
}
//  [cpp]
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<=a;i++)for(int j=0;j<=b;j++){
		if(i*b+j*a-i*j*2==c){printf("Yes\n");return 0;}
	}
	printf("No\n");
}
//  [cpp]
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 100005
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
using namespace std;

int n, m, k;

int main(){
	scanf("%d %d %d", &n, &m, &k);
	
	FI(i, 0, n) FI(j, 0, m){
		if(k == i * m + j * n - (i * j) * 2){
			puts("Yes");
			return 0;
		}
	}
	
	puts("No");
	return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;


int main(){
    int n, m, k; cin >> n >> m >> k;

    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            int tmp = i*(m-j) + j*(n-i);
            if(tmp == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}
//  [c]
#include <stdio.h>

int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<=n;i++)for(int j=0;j<=m;j++){
		if(i*j+(n-i)*(m-j)==k){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}
//  [c]
#include <stdio.h>

int main(void) {

  int n,m,k;
  scanf("%d %d %d", &n, &m, &k);
  int black;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      black = i*j+(n-i)*(m-j);
      if (black == k) {
        printf("Yes\n");
        return 0;
      }
    }
  }
  printf("No\n");

  return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)

int main() {
	int n,m,k;
	scanf("%d %d %d", &n, &m, &k);
	if (k == n * m) { printf("Yes"); return 0; }
	rep(i, n) {
		rep(j, m) {
			if (k - i * (m - j) - j * (n - i) == 0) { printf("Yes"); return 0; }
		}
	}
	printf("No");
}
//  [c]
#include<stdio.h>
int main(){
  int a,b,c,i,j;
  scanf("%d %d %d",&a,&b,&c);
  for(i=0;i<a;i++){
    for(j=0;j<b;j++){
      if(i*j+(a-i)*(b-j)==c){
	printf("Yes\n");
	return 0;
      }
    }
  }
  printf("No\n");
  return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)

int main() {
	int n,m,k;
	scanf("%d %d %d", &n,&m,&k);
	rep(i,n) {
		rep(j,m) {
			if (k-i*(m-j)-j*(n-i)==0) { printf("Yes"); return 0; }
		}
	}
	printf("No");
}
//  [c]
#include <stdio.h>
int main() {
	int n, m, k, num;
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			num = i * m + j * n - 2 * (i * j);
			if (num == k) {
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}
//  [javascript]
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = myconv(next(),4);
  var N = one[0];
  var M = one[1];
  var K = one[2];
  if(K % M == 0 || K % N == 0){
     myout("Yes");
    return;
  }
  for(var i = 1; i <= N; i++){
    for(var j = 1; j <= M; j++){
      var count = (M * i) + (N * j) - 2 * (i * j);
      if(count == K){
         myout("Yes");
        return;
      }
    }
  }
  myout("No");
}
//  [javascript]
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
N = l[0] * 1
M = l[1] * 1 
K = l[2] * 1
f = 0
for (i=0; i<=N; i++) {
  for (j=0; j<=M; j++) {
      if ((M - j) * i + (N - i) * j == K) {
          f = 1
      } 
  }
}
console.log(f ? 'Yes' : 'No')
//  [javascript]
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(e,r,t){"use strict";function n(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=[],n=!0,o=!1,u=void 0;try{for(var i,f=e[Symbol.iterator]();!(n=(i=f.next()).done)&&(t.push(i.value),!r||t.length!==r);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==f.return||f.return()}finally{if(o)throw u}}return t}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}e.exports=function(e){for(var r=n(e[0].split(" ").map(function(e){return Number(e)}),3),t=r[0],o=r[1],u=r[2],i=0;i<=t;i++)for(var f=0;f<=o;f++)if((t-i)*f+(o-f)*i==u)return void console.log("Yes");console.log("No")}},function(e,r){e.exports=require("fs")}]);
//  [javascript]
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
N = l[0] * 1
M = l[1] * 1 
K = l[2] * 1
f = 0
for (i=0; i<N; i++) {
  for (j=0; j<M; j++) {
      if ((M - j) * i + (N - i) * j == K) {
          f = 1
      } 
  }
}
console.log(f ? 'Yes' : 'No')
//  [javascript]
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
N = l[0] * 1
M = l[1] * 1 
K = l[2] * 1
f = 0
for (i=0; i<=N; i++) {
  for (j=0; j<=M; j++) {
      if ((N - j) * i + (M - i) * j == K) {
          f = 1
      } 
  }
}
console.log(f ? 'Yes' : 'No')
//  [javascript]
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
N = l[0] * 1
M = l[1] * 1 
K = l[2] * 1
f = 0
for (i=0; i<N; i++) {
  for (j=0; j<M; j++) {
      if ((N - j) * i + (M - i) * j == K) {
          f = 1
      } 
  }
}
console.log(f ? 'Yes' : 'No')
//  [go]
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N, M, K := getInt(), getInt(), getInt()

	for i := 0; i <= N; i++ {
		for j := 0; j <= M; j++ {
			k := (M-j)*i + (N-i)*j
			if K == k {
				out("Yes")
				return
			}
		}
	}
	out("No")
}
//  [go]
package main
import "fmt"
func main(){
	var N, M, K int
	fmt.Scan(&N, &M, &K)
	for i:=0; i<=N; i++{
		for j:=0; j<=M; j++{
			if (M-j)*i + (N-i)*j==K{
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, M, K := ReadInt(), ReadInt(), ReadInt()
	for a := 0; a < M; a++ {
		for b := 0; b < N; b++ {
			x := N*a + M*b - 2*a*b
			if x == K {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

func swap(a int64, b int64) (int64, int64) {
	return b, a
}

func gcd(a int64, b int64) int64 {
	if b > a {
		a, b = swap(a, b)
	}
	if b == 0 {
		return a
	} else {
		return gcd(a%b, b)
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func min(nums ...int64) int64 {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int64(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int64) int64 {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int64(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func nextLong() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func nextByte() byte {
	sc.Scan()
	s := sc.Bytes()
	return s[0]
}

func main() {
	sc.Split(bufio.ScanWords)
	//ans := 1
	N := nextInt()
	M := nextInt()
	K := nextInt()
	Blacknum := 0
	Clear := false
	for row := 0; row <= N; row++ {
		for col := 0; col <= M; col++ {
			Blacknum = (N-col)*row + (M-row)*col
			if Blacknum == K {
				Clear = true
			}
		}
	}
	if Clear {
		fmt.Printf("Yes\n")
	} else {
		fmt.Printf("No\n")
	}
}
//  [ruby]
n,m,k = gets.split.map(&:to_i)

(n+1).times do |i|
    if n - 2 * i == 0
        if n * m / 2 == 0 
            puts "Yes"
            exit
        else
            next
        end
    end
    
    j = (k - i * m) / (n - 2 * i)
    if 0 <= j && j <= m && i * (m - j) + (n - i) * j == k
        puts "Yes"
        exit
    end
end

puts "No"
//  [ruby]
N,M,K=gets.split.map &:to_i
puts (0..M).any?{|a|g=K-N*a;t=M-2*a;g==0||t!=0&&g%t==0&&(0..N)===g/t}?:Yes: :No
//  [ruby]
N,M,K=gets.split.map &:to_i;puts (0..N).any?{|k|x=K-k*M;y=N-2*k;y==0?x==0:(l=x/y;x%y==0&&0<=l&&l<=M)}?:Yes: :No
//  [ruby]
n, m, k = gets.split.map(&:to_i)
n.times do |i|
  m.times do |j|
    if n * m - (n - i) * (m - j) - i * j == k
      puts 'Yes'
      exit
    end
  end
end
puts 'No'
//  [ruby]
n, m, k = gets.split.map(&:to_i)
n.times do |i|
  m.times do |j|
    if (n - j) * (m - i) + i * j == k
      puts 'Yes'
      exit
    end
  end
end
puts 'No'
//  [ruby]
n, m, k = gets.split.map(&:to_i)
n.times do |i|
  m.times do |j|
    if (n - j) * i + (m - i) * j == k
      puts 'Yes'
      exit
    end
  end
end
puts 'No'
//  [rust]
use std::io::stdin;
// code...
fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let (n, m, k): (usize, usize, usize) = {
        let p: Vec<usize> = buf
            .trim()
            .split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect();
        (p[0], p[1], p[2])
    };

    let mut ans = "No";
    for i in 0..n + 1 {
        for j in 0..m + 1 {
            if i * m + j * n - 2 * i * j == k {
                ans = "Yes";
            }
        }
    }

    println!("{}", ans);
}
//  [rust]
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();
    let k: usize = sc.cin();
    let mut ans = "No";
    for i in 0..n+1 {
        for j in 0..m+1 {
            let a = i * m + j * n - i * j * 2;
            // trace!((i, j), (m, n), a);
            if a == k {
                ans = "Yes";
            }
        }
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}
//  [rust]
#[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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      m: usize,
      k: usize,
    }

    for i in 0..n+1 {
        for j in 0..m+1 {
            let black = m*i + n*j - 2*i*j;
            if black == k {
                return puts!("{}\n", "Yes");
            }
        }
    }
    puts!("{}\n", "No");
}
//  [rust]
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        k: usize,
    };
    let mut ans = false;
    for r in 0..n {
        for c in 0..m {
            if r * (m - c) + c * (n - r) == k {
                ans = true;
            }
        }
    }
    println!("{}", if ans { "Yes" } else { "No" });
}
//  [rust]
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        k: usize,
    };
    let mut ans = false;
    for r in 0..n {
        for c in 0..m {
            if r * m + c * n - r * c * 2 == k {
                ans = true;
            }
        }
    }
    println!("{}", if ans { "Yes" } else { "No" });
}