jiahuimbzuai/CoQuIR huggingface dataset:
//  [java]
import java.util.*;
import java.util.stream.IntStream;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        List<Integer> s,c;
        s = new ArrayList<>();
        c = new ArrayList<>();
        for(int i=0;i<M;i++) {
            s.add(sc.nextInt());
            c.add(sc.nextInt());
        }
        int res;
        if(N == 1){
            res = IntStream.range(0, pow10(N)).filter(a ->
                    {
                        for (int i = 0; i < M; i++) {
                            if (getKeta(N - s.get(i) + 1, a) != c.get(i)) {
                                return false;
                            }
                        }
                        return true;
                    }
            ).findFirst().orElseGet(() -> -1);
        }else {
            res = IntStream.range(pow10(N - 1), pow10(N)).filter(a ->
                    {
                        for (int i = 0; i < M; i++) {
                            if (getKeta(N - s.get(i) + 1, a) != c.get(i)) {
                                return false;
                            }
                        }
                        return true;
                    }
            ).findFirst().orElseGet(() -> -1);
        }
        System.out.println(res);
    }

    private static int getKeta(int k, int val){
        return (val / pow10(k-1)) % 10;
    }

    private static int pow10(int k){
        if(k == 0){return 1;}
        return pow10(k-1) * 10;
    }

}
//  [cpp]
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const int mod = 1000000007;
int n,m;
std::vector<int> s;
std::vector<char> c;
string ans; bool can=false;
int main(){ //srand((unsigned)time(NULL));
  cin >> n >> m;
  s.resize(m);
  c.resize(m);
  for (size_t i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (size_t i = 0; i < 1000000; i++) {
    string a = to_string(i);
    bool y = true;
    for (size_t l = 0; l < m; l++) {
      if(a[s[l]-1] != c[l])y = false;
    }
    if(a.length() == n && y){
      can = true;
      ans = a;
      break;
    }
  }
  cout << (can ? ans : "-1") << endl;
}
//  [cpp]
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long


int n, m;
vector<pair<int, int>> v;

bool satisfy(int x) {
    string s = to_string(x);
    if(s.size() != n)
        return 0;
    for(int i = 0; i < m; i++) {
        if(s[v[i].first] != v[i].second + '0')
            return 0;
    }
    return 1;
}

signed main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    //int t = 1; cin >> t; while(t--)
    {
        cin >> n >> m;

        for(int i = 0; i < m; i++) {
            int x, y;
            cin >> x >> y;
            v.push_back({--x, y});
        }

        for(int i = 0; i < 1000000; i++) {
            if(satisfy(i)) {
                cout << i;
                return 0;
            }
        }

        cout << -1;
        
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>

using namespace std;

int d[10];
int main() {
    memset(d, -1, sizeof d);
    int n,m;
    cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        int s,c;
        cin >> s >> c;
        s--;
        if(d[s] != -1 and d[s] != c) return puts("-1"), 0;
        d[s] = c;
    }
    
    for (int i = 0; i < 1000000; ++i) {
        string x = to_string(i);
        if(x.size() != n) continue;
        bool flag = 1;
        for (int j = 0; j < (int)x.size(); ++j) 
            flag &= (x[j] == d[j] + '0' or d[j] == -1);
        if(flag) return cout << i << "\n", 0;
    }
    cout << -1 << "\n";
    return 0;
}
//  [c]
#include <stdio.h>

int d[9],c[9];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)scanf("%d%d",d+i,c+i);
	int l,r;
	if(n==1)l=0,r=10;
	if(n==2)l=10,r=100;
	if(n==3)l=100,r=1000;
	
	for(int x=l;x<r;x++){
		char s[9];
		sprintf(s,"%d",x);
		int flag=1;
		for(int i=0;i<m;i++)flag&=s[d[i]-1]-'0'==c[i];
		if(flag){
			printf("%d",x);
			return 0;
		}
	}
	puts("-1");
}
//  [c]
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
 
#define N 3
#define M 5
 
int n, m, s[5];
char c[5];  

int main(){
    scanf("%d %d",&n, &m);
    for (int i = 0; i < m; i++){
        scanf("%d %c",&s[i], &c[i]);     
    }
    
    char ans[3]={'n','n','n'};
    for (int i = 0; i < m; i++){
        if(ans[s[i]-1]=='n'){
            ans[s[i]-1] = c[i];
        }
        else if(ans[s[i]-1]!=c[i]){
            printf("-1\n");
            return 0;
        }
    }
    for (int j = 0; j < n; j++){
        if(ans[j]=='n'){
            if(j==0 && n!=1){
                ans[j] = '1';
            }
            else{
                ans[j] = '0';
            }
        }
    }
    if( n!=1 && atoi(ans)<pow(10,n-1) ){
        printf("-1\n");
        return 0;
    }
    printf("%d\n",atoi(ans));  
    return 0;
}
//  [c]
#include <stdio.h>
int main(){
	int n, m, c, s, d, ss[3]={-1,-1,-1}, ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0; i<m; i++){
        scanf("%d%d",&s,&c);
		if( ss[s-1] != -1 && ss[s-1] != c ){ printf("-1\n"); return 0; }
		if( ss[s-1] != -1 ){ continue; }
        ss[s-1] = c;
      	if	   ( (s==3) || (s==2 && n==2) || (s==1 && n==1) ){ d=  1; }
      	else if( 		   (s==2 && n==3) || (s==1 && n==2) ){ d= 10; }
      	else if( 							  s==1 && n==3  ){ d=100; }
      	ans += (d*c);
	}
  	if	   ( (n==2 || n==3) && ss[0]==0 ){ printf("-1\n"); return 0; }
    else if(  n==2 && ans< 10 ){ ans+= 10; }
  	else if(  n==3 && ans<100 ){ ans+=100; }
	printf("%d\n",ans);
	return 0;
}
//  [javascript]
// inputに入力データ全体が入る
function Main(input) {
    var N = input[0].split(" ")[0]-0;
    var M = input[0].split(" ")[1]-0;
    var list = input.filter((v,i)=>i>0).map(v=>v.split(" ").map(v=>v-0));
    var ans = -1;
    start:for(var i=0;i<=999;i++){
        var str = i.toString();
        if(str.length != N) continue;
        for(var j=0;j<M;j++){
            var s = list[j][0];
            var c = list[j][1];
            if(str[s-1] != c) continue start;
        }
        ans = i;
        break;
    }
    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));
//  [javascript]
'use strict'
const Main=input=>{
    input=input.split("\n");
    for(let i=0;i<input.length;i++){
        input[i]=input[i].split(" ");
    }
    
    let answer=-1;
    for(let i=0;i<1000;i++){
        const si=""+i;
        if(si.length!=input[0][0])continue;
        let flag=true;
        for(let j=0;j<input[0][1];j++){
            if(si[input[j+1][0]-1]!=input[j+1][1])flag=false;
        }
        if(flag){
            answer=si;
            break;
        }
    }
    
    console.log(answer);
}

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

function Main(arg)
{
  var N = arg.split("\n")[0].split(" ")[0]-0;
  var M = arg.split("\n")[0].split(" ")[1]-0;
  var c = arg.split("\n").slice(1);

  var arr = new Array(N);
  arr.fill(-1);
  for (var i = 0; i < M; i++){
    var idx = (c[i].split(" ")[0] - 0)-1;
    var tmp = c[i].split(" ")[1] - 0;
    if (arr[idx] === -1) {
      arr[idx] = tmp;
      continue;
    }

    if (arr[idx] === tmp) {
      continue;
    }
    console.log(-1);
    return;
  }

  for (var i = 0; i < N; i++){
    if (arr[i] === -1) {
      if (N !==1 && i === 0) {
        arr[i] = 1;
      }
      else {
        arr[i] = 0; 
      }
    }
  }
  
  var ans = arr.join("") - 0;
  var asd = ans + "";
  if (asd.length !== N) {
    console.log(-1);
    return;
  }
  
  console.log(ans);
  return;
}

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

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000009
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	M := nextInt()
	s := make([]int, M)
	c := make([]int, M)
	ans := -1
	for i := 0; i < M; i++ {
		s[i] = nextInt() - 1
		c[i] = nextInt()
	}
	// 計算量が多くないので総当りでチェックできる
	for i := 0; i < 1000; i++ {
		nums := strconv.Itoa(i)
		check := true
		// 桁数をまずはチェック。数値をstringに変換してlenで桁数が出せる
		if len(nums) == N {
			//  条件を一つずつ確認する。M=0の場合は何も行われないでそのままcheck == true
			for j := 0; j < M; j++ {
				// 確認中の数値がそれぞれの条件に一致するかをチェックする。
				num, _ := strconv.Atoi(string(nums[s[j]]))
				if num != c[j] {
					check = false
				}
			}
		} else {
			check = false
		}
		if check == true {
			ans = i
			fmt.Println(ans)
			return
		}
	}
	fmt.Println(ans)
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
//  [go]
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000009
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	var ans int
	N := nextInt()
	M := nextInt()
	conditions := make([]int, N)
	nums := make([]int, N)
	if M == 0 {
		if N == 1 {
			fmt.Println(0)
			return
		}
		nums[0] = 1
		for i := 0; i < N; i++ {
			ans += nums[len(nums)-i-1] * int(math.Pow10(i))
		}
		fmt.Println(ans)
		return
	}
	for i := 0; i < M; i++ {
		s := nextInt() - 1
		c := nextInt()
		if conditions[s] == 1 && nums[s] != c {
			fmt.Println(-1)
			return
		}
		if N != 1 && s == 0 && c == 0 {
			fmt.Println(-1)
			return
		}
		nums[s] = c
		conditions[s] = 1
	}
	if conditions[0] == 0 {
		nums[0] = 1
	}
	if N != 1 && nums[0] == 0 {
		fmt.Println(-1)
		return
	}
	for i := 0; i < N; i++ {
		ans += nums[len(nums)-i-1] * int(math.Pow10(i))
	}
	if ans >= 0 {
		fmt.Println(ans)
	} else {
		fmt.Println(-1)
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
//  [ruby]
N, M = gets.split.map(&:to_i)
s = []
c = []
str = Hash.new
M.times do |i|
  s[i], c[i] = gets.split.map(&:to_i)
  if str[s[i]-1].nil?
    str[s[i]-1] = []
  end
  str[s[i]-1] << c[i]
end

# puts "#{str}"

ans = []
ans = ans.fill('0',0..N-1)
if N>=2
  ans[0] = '1'
end

str.each do |key, val|
  if key==0 and val.first==0 and N>=2
    puts -1
    exit
  end
  val.uniq!
  if val.size >= 2
    puts -1
    exit
  end
  ans[key] = val.first.to_s
end
puts "#{ans.inject(:+)}"
//  [ruby]
N, M = gets.split.map(&:to_i)
s, c = [], []
flag = false
hash = {}

M.times do |i|
  s[i], c[i] = gets.split.map(&:to_i)
  if hash[s[i]].nil?
    hash[s[i]] = c[i]
  # 同じ桁数に異なる2つの数が要求された場合，-1出力
  elsif hash[s[i]] != c[i]
    flag = true
  end
end

# puts "#{hash}"

# 左から1桁目が0かつ桁数が2以上の時，-1出力
if hash[1] == 0 and N >= 2
  flag = true
end

if flag
  puts -1
  exit
end

# ansは最初は先頭に'1'と，その後にN-1個の'0'で埋めておく
ans = []
ans = ans.fill('0',0..N-1)
if N >= 2
  ans[0] = '1'
end

hash.each do |key, val|
    ans[key-1] = val.to_s
end 

puts "#{ans.inject(:+)}"
//  [rust]
use proconio::input;

fn main() {
    input! {
        n: u32,
        m: usize,
        sc: [(usize, char); m],
    }

    let ans = (0..10i32.pow(n))
        .filter(|x| {
            dbg!(x);
            let x = x.to_string().as_bytes().to_vec();
            x.len() == n as usize
                && sc
                    .iter()
                    .all(|(s, c)| matches!(x.get(*s-1), Some(x) if * x as char == * c))
        })
        .next()
        .unwrap_or(-1);

    println!("{}", ans);
}
//  [rust]
use std::io::BufReader;
use std::io;
use std::io::prelude::*;

fn main() {

    let mut first = true;
    let mut N :i32 = 0;
    let mut M: i32 = 0;
    let mut svec = Vec::new();
    let mut cvec = Vec::new();
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        let s: Vec<String> = line.unwrap().split(' ').map(|s| String::from(s)).collect();
        if first {
            N = s[0].parse::<i32>().unwrap();
            M = s[1].parse::<i32>().unwrap();
        } else {
            let sv = s[0].parse::<i32>().unwrap();
            let cv = s[1].parse::<i32>().unwrap();
            svec.push(sv);
            cvec.push(cv);
        }
        first = false
    }

    let mut val = Vec::new();
    for i in 0..N {
        val.push(-1);
    }

    for i in 0..svec.len() {
        let pos = (svec[i as usize] - 1) as usize;
        if val[pos] != -1 && val[pos] != cvec[i as usize] {
            println!("-1");
            return
        }
        val[pos] = cvec[i as usize] ;
    }

    if val[0] == -1 {
        if N > 1 {
            val[0] = 1
        } else {
            val[0] = 0
        }
    } else {
        if N > 1 && val[0] == 0 {
            println!("-1");
            return
        }
    }

    for i in 1..N {
        if val[i as usize] == -1 {
            val[i as usize] = 0
        }
    }

    let ans: String = val.iter().map(|v| v.to_string()).collect();

    println!("{}", ans);
}
//  [typescript]
import * as fs from 'fs';

//in
// 3 3
// 1 7
// 3 2
// 1 7
//out
// 702
const main = (inp: string) => {
    let inpArray: string[] = inp.split('\n');
    const [n, m]: number[] = inpArray[0].split(' ').map(Number);
    inpArray.shift();

    // if (m === 0 && n===1) {
    //     // console.log(0);
    //     // return;
    // }

    for (let i: number = 0; i < 1000; i++) {

        if (n != i.toString().length)
            continue;

        let ok: boolean = true;

        for (let j: number = 0; j < m; j++) {
            const [s, c]: number[] = inpArray[j].split(' ').map(Number);

            if (n < s) {
                console.log(-1);
                return;
            }

            if (i.toString().length < s)
                break;

//            console.log(`${parseInt(i.toString()[0])}  ${parseInt(i.toString()[1])}  ${parseInt(i.toString()[2])}`);
            if (s === 1) {
                if (parseInt(i.toString()[0]) !== c) {
                    ok = false;
                }
            }

            if (s === 2) {
                if (parseInt(i.toString()[1]) !== c) {
                    ok = false;
                }
            }

            if (s === 3) {
                if (parseInt(i.toString()[2]) !== c) {
                    ok = false;
                }
            }

        }

        if (ok) {
            console.log(i.toString());
            return;
        }

    }
    console.log(-1);
};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());
//  [typescript]
function Main(input) {
    const lines = input.split("\n");
    const [n, m] = lines.shift().split(' ').map(v => +v);

    let result = Array(n).fill(false);

    try {
        lines.forEach(l => {
            let [s, c] = l.split(' ');
            s -= 1;
            if (result[s] !== false && result[s] != c) {
                throw 0;
            }
            result[s] = c;
        });
        if (n != 1 && result[0] === '0') throw 0;
        if (result[0] === false) result[0] = n == 1 ? 0 : 1;
        result = result.map(v => v === false ? 0 : v);
        console.log(result.join(''));
    } catch (_) {
        console.log(-1);
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [typescript]
const main = (input: string) => {
  const lines = input.trim().split("\n")
  const [N, M] = lines[0].split(" ").map(str => parseInt(str))
  const checkList: [number, string][] = lines.slice(1).map(line => {
    const [s, c] = line.split(' ');
    return [parseInt(s) - 1, c];
  });

  for (let i = 0; i < Math.pow(10, N); i++) {
    const strNum = i.toString();

    if (strNum.length === N && checkList.every(sc => strNum[sc[0]] === sc[1])) {
      console.log(strNum)
      process.exit(0);
    }
  }
  console.log(-1);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [python]
A, B, C = map(int, input().split())
if A + B >= C:
    print(B + C)
else:
    print(2 * B + A + 1)
//  [python]
A,B,C = map(int,input().split(" "))
if C > (A+B):
    print(A+2*B+1)
elif C == (A+B):
    print(C+B)
elif C > B:
    print(C+B)
else:
    print(C+B)
//  [python]
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc 030 A
"""

a, b, c = map(int, input().split())

if c <= a+b:
    ans = b+c
if c > a+b:
    ans = a+b+b+1

print (ans)
//  [python]
import numpy as np
a,b,c = list(map(int,input().split()))

if a + b >= c:
    ans = b + c
else:
    ans = b + a + b + 1

print(ans)
//  [python]
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# なんこか入力
a,b,c = map(int, input().split())

if b>=c:
    answer=b+c
elif a+b<c:
    answer=2*b+a+1
else:
    answer = b+c

print(answer)
//  [python]
#!C:\Users\t.kida\vs_code\atcoder\.venv\Scripts\python.exe
import numpy
import scipy

A, B, C = [ int(x) for x in input().split(" ") ]
ans = 0
if(A + B < C):
    ans = B + (A+B) + 1
else:
    ans = B + C

print(ans)
//  [java]
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

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

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");
        int a = Integer.valueOf(arr01[0]);
        int b = Integer.valueOf(arr01[1]);
        int c = Integer.valueOf(arr01[2]);

        int cnt = 0;

        //        System.out.println(a + " " + b + " " + c);

        if (c >= a) {
            cnt += a;
            c -= a;
            a = 0;
        } else {
            cnt += c;
            a -= c;
            c = 0;

        }

        //        System.out.println(a + " " + b + " " + c + " " + cnt);

        if (c >= b) {
            //cnt += c;
            cnt += b * 2;
            c -= b;
            b = 0;

            if (c > 0) {
                cnt += 1;
            }
            //            c = 0;
            //            b = 0;
        } else {
            cnt += b;
            cnt += c;
        }

        //        System.out.println(a + " " + b + " " + c + " " + cnt);
        System.out.println(cnt);

    }

}
//  [java]
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.min;
import static java.lang.System.exit;

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

public class Main {

	static void solve() throws Exception {
		int a = scanInt();
		int b = scanInt();
		int c = scanInt();
		out.print(b + min(c, a + b + 1));
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}
//  [java]
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Collections;


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] abc = br.readLine().split(" ");
        int a = Integer.parseInt(abc[0]);
        int b = Integer.parseInt(abc[1]);
        int c = Integer.parseInt(abc[2]);
        int ans = 0;
        
        if (a >= c-1) {
            ans = b+c;
        }
        else {
            ans += (a+1);
            c -= (a+1);
            if (b >= c) {
                ans += (b+c);
            }
            else {
                ans += b*2;
            }
        }
        
        System.out.println(ans);
        
    }
}

class Box {
    int w;
    int h;
    public Box(int w, int h) {
        this.w = w;
        this.h = h;
    }
}

class BoxComparator1 implements Comparator<Box>{
	public int compare(Box b1, Box b2) {
		return b1.w - b2.w;
	}
}

class BoxComparator2 implements Comparator<Box> {
    public int compare(Box b1, Box b2) {
        return b1.h - b2.h;
    }
}
//  [java]
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int delicious = 0;
		boolean poison = false;

		while(c > 0) {

			if(poison) 	break;

			c--;
			delicious++;

			poison = true;

			if(b > 0) {
				b--;
				delicious++;
				poison = false;
			} else if(a > 0) {
				a--;
				poison = false;
			}
		}

		delicious += b;
		System.out.println(delicious);
	}
}
//  [java]
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt();
      	int B=sc.nextInt();
      	int C=sc.nextInt();
      	int count=0;
      	boolean eatFlag=true;
      
      	while(eatFlag){
         	if(C>0){
            	C-=1;
              	count++;
              	if(A>0){
                	A-=1;
                } else {
                	if(B>0){
                    	B-=1;
                       	count++;
                    }else{
                    	eatFlag=false;
                    }
                }
            }else{
            	if(B>0){
                	count+=B;
                }
              	eatFlag=false;
            } 
        }
      	System.out.println(count);
    }
}
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		String s = (new Main()).run();
		System.out.println(s);
	}

	public String run() {

		Entity e = input();
		int a = e.getA();
		int b = e.getB();
		int c = e.getC();

		int eaten = 0;
		while (true) {

			// eatc
			if (c > 0) {
				c--;
				eaten++;
			} else {
				break;
			}

			if (b > 0) {
				b--;
				eaten++;

				continue;
			}

			if (a > 0) {
				a--;
				continue;
			}

			if (a == 0 && b == 0) {
				break;
			}

		}

		// eaten += c;
		eaten += b;

		return "" + eaten;

	}

	private Entity input() {

		Scanner scan = new Scanner(System.in);
		String tmp = scan.nextLine();

		scan.close();

		String[] tmps = tmp.split("\\s");
		int[] a = new int[tmps.length];

		for (int i = 0; i < tmps.length; i++) {
			a[i] = Integer.parseInt(tmps[i]);
		}

		Entity e = new Entity();
		e.setA(a[0]);
		e.setB(a[1]);
		e.setC(a[2]);

		return e;

	}

	private class Entity {

		int a = -1;
		int b = -1;
		int c = -1;

		public int getA() {
			return a;
		}

		public void setA(int a) {
			this.a = a;
		}

		public int getB() {
			return b;
		}

		public void setB(int b) {
			this.b = b;
		}

		public int getC() {
			return c;
		}

		public void setC(int c) {
			this.c = c;
		}

	}

}
//  [cpp]
#include<cstdio>
#include<cctype>
#include<algorithm>
inline int getint() {
	register char ch;
	while(!isdigit(ch=getchar()));
	register int x=ch^'0';
	while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
	return x;
}
int main() {
	const int a=getint(),b=getint(),c=getint();
	printf("%d\n",b+std::min(c,a+b+1));
	return 0;
}
//  [cpp]
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<cctype>
using namespace std;
#define fec(i,x,y) (int i=head[x],y=g[i].to;i;i=g[i].ne,y=g[i].to)
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define FO(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define Edg(N,M) struct Edge{int to,ne;}g[M];int head[N],tot;\
	inline void Ad(int x,int y){g[++tot].to=y;g[tot].ne=head[x];head[x]=tot;}\
	inline void Adde(int x,int y){Ad(x,y);Ad(y,x);}
#define Edgc(N,M) struct Edge{int to,ne,w;}g[M];int head[N],tot;\
	inline void Ad(int x,int y,int z){g[++tot].to=y;g[tot].w=z;g[tot].ne=head[x];head[x]=tot;}\
	inline void Adde(int x,int y,int z){Ad(x,y,z);Ad(y,x,z);}
#define fi first
#define se second
#define pb push_back
template<typename I>inline void read(I&x){int f=0,c;while(!isdigit(c=getchar()))c=='-'?f=1:0;x=c&15;while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);f?x=-x:0;}
template<typename A,typename B>inline char SMAX(A&a,const B&b){return a<b?a=b,1:0;}
template<typename A,typename B>inline char SMIN(A&a,const B&b){return a>b?a=b,1:0;}
typedef long long ll;typedef unsigned long long ull;typedef std::pair<int,int>pii;

int A,B,C;

int main(){
	read(A),read(B),read(C);--C;
	int hkk=min(C,B+A),ans=hkk;
	ans+=B;++ans;
	printf("%d\n",ans);
}
//  [cpp]
#include<iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int a, b, c;
  int ans = 0;
  cin >> a >> b >> c;
  ans = b + min(a + b + 1, c);
  cout << ans << endl;

  return 0;
}
//  [cpp]
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}




int main(){
  long long A,B,C;
  cin>>A>>B>>C;
  int jotai=0;
  long long sum=0;
  while(true){
    if(jotai==0){
      if(C>0){
      C--;
      sum++;
      jotai=-1;}
      else{
        break;
      }

    }else{
      if(B>0){
        B--;
        sum++;
        jotai=0;
      }else if(A>0){
        A--;
        jotai=0;
      }else{
        break;
      }
    }
  }
  sum+=B;
  cout<<sum<<endl;

  
  


  

  



}
//  [cpp]
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <bitset>
#include <tuple>
#include <stack>
#include <utility>

using namespace std;
typedef long long ll;

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll state = 0, ans = 0;
    while(1){
        if(state == 0){
            if(c > 0){
                ans += 1;
                c -= 1;
                state = 1;
            }
            else if(b > 0){
                b -= 1;
                ans += 1;
            }
            else break;
        }
        else{
            if(a > 0){
                a -= 1;
                state = 0;
            }
            else if(b > 0){
                b -= 1;
                ans += 1;
                state = 0;
            }
            else break;
        }
    }
    cout << ans << endl;
    return 0;
}
//  [c]
#include <stdio.h>
int main() {
  int A,B,C;
  /* A:not delicious medicine B:delicious mesicine C:delicious poison */
  scanf("%d %d %d",&A,&B,&C);
  int ans;
  if (A + B >= C) {
    ans	= B + C;
  } else {
    ans	= (A + B) + B + 1;
  }
  printf("%d\n",ans);
  return 0;
}
//  [c]
#include <stdio.h>

int main() {
    unsigned long a, b, c, ans = 0;

    scanf("%lu%lu%lu", &a, &b, &c);

    if (a+b < c) {
        ans = a + b + b + 1;
    } else {
        ans = b + c;
    }

    printf("%lu\n", ans);

    return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
int min(int a, int b) { return a < b ? a : b; }
int main(){
    int a,b,c,poison;
    scanf("%d %d %d",&a,&b,&c);
    poison=min(a+b+1,c);
    printf("%d",b+poison);
    return 0;
}
//  [c]
#include<stdio.h>
int main(){
	int a,b,c,d=0;//taoyandejie meiweidejie meiweidedu
	scanf("%d %d %d",&a,&b,&c);
	

	if(c>a || c>b){

	while(c>0){	
		d++;
		if(b>0){
			d++;
			c--;
			b--;
			continue;
		}
		if(b==0){
			if(a>0){
				c--;
				
				a--;
				continue;
			}
			if(a==0){
				break;
			}
		}
	}

	}
	else if(c<b || c==b){
		d=c+b;
	}
	
	
	
	printf("%d",d);
}
//  [c]
#include<stdio.h>
int main(void){
    int a, b, c, poi = 1, count =0;
    if(scanf("%d %d %d", &a, &b, &c) ==1){};
    
    while(1){
	
	if (c>0){
	    count +=1;
	    c-= 1;
	    poi = 0;
	}
	if(b>0){
	    count +=1;
	    b -= 1;
	    poi = 1;
	}
	else if (a>0 && poi ==0){
	    a -= 1;
	    poi = 1;
	}
	else {
	    if (poi==1 && c>0) count +=1;
	    break;
	}
    }
    printf("%d\n", count);
    return 0;
}
//  [javascript]
function myout(text){console.log(text);}//standard output
function Main(input) {
	input = input.trim();
	//input = parseInt(input.trim());
	//input = input.trim().split(" ");
	//input = input.trim().split("\n");
	input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  //var output = 0;
  if(input[0] + input[1] >= input[2]){
     myout(input[1] + input[2]);
  }else{
    myout(input[0] + input[1] * 2 + 1);
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input){
	input = input.split(" ").map(a=>~~a);
	var A = input[0];
  var B = input[1];
  var C = input[2];
  
  var delicious = 0;
  
  var hoge = Math.min(B,C);
  
  delicious += hoge * 2;
  B -= hoge;
  C -= hoge;
  
  var fuga = Math.min(A,C);
  
  delicious += fuga;
  
  A -= fuga;
  C -= fuga;
  
  if(B != 0)delicious += B;
  if(C != 0)delicious += 1;
  
 	return delicious; 
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
8 8 1
`);
//  [javascript]
"use strict";

const main = arg => {
  let a = parseInt(arg.split(" ")[0]);
  let b = parseInt(arg.split(" ")[1]);
  let c = parseInt(arg.split(" ")[2]);

  let ans = 0;
  
  if(b >= c) {
    ans += c + b;
    c = 0;
  } else {
    ans += b*2;
    c -= b, b = 0;
  }
  
  if(c>0) {
    let tmp = Math.min(c,a);
    c -= tmp;
    ans += tmp;
  }

  if(c > 0) ans++;
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [javascript]
'use strict';

function Main(input) {

  input = input.trim().split(" ").map(Number);
  let badKusuri = input[0];
  let goodKusuri = input[1];
  let goodPoison = input[2];
  
  for(;(goodKusuri>0)&&(goodPoison>0);){
  	goodKusuri--;
    goodPoison--;
  }
  
  if(goodPoison == 0){
  	goodKusuri = 0;
  } else {
  	for(;(badKusuri>0)&&(goodPoison>0);){
  		badKusuri--;
      	goodPoison--;
  	}
  }
  
  if(goodPoison > 0){
  	goodPoison--;
  }
  
  console.log((input[1] + input[2]) - (goodKusuri + goodPoison));
  
  
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var a = o.a();
  var b = o.a();
  var c = o.a();
  var d = a + b + 1;
  if(d >= c)return b + c;
  return b + d;
}
//  [javascript]
function main(arg) {
	arg = arg.split("\n")[0].split(" ")
	var A = Number(arg[0]) // - 
	var B = Number(arg[1]) // + 
	var C = Number(arg[2]) // + *

	if ( A + B >= C) {
		console.log(B + C)
		return
	} else {
		var tmp = A + B
		console.log(B + tmp + 1)
		return
	}

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

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	if a+b >= c {
		fmt.Println(b + c)
	} else {
		fmt.Println(a + b + b + 1)
	}
}
//  [go]
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	if c <= a+b {
		fmt.Println(b + c)
	} else {
		fmt.Println(a + b*2 + 1)
	}
}
//  [go]
package main

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

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

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	if a+b >= c {
		fmt.Println(b + c)
		return
	}
	fmt.Println(a + 2*b + 1)
}

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 nextSlice() []string {
	return strings.Split(readLine(), "")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func scanSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func scanFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

// ---------------------------------------------------

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

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

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

// ---------------------------------------------------

func yesOrNo(b bool) {
	if b {
		reply = "Yes"
		fmt.Println(reply)
		return
	}
	reply = "No"
	fmt.Println(reply)
}

func yesorNO(b bool) {
	if b {
		reply = "YES"
		fmt.Println(reply)
		return
	}
	reply = "NO"
	fmt.Println(reply)
}
//  [go]
package main

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

func main() {
	scanInit()

	a := nextInt()
	b := nextInt()
	c := nextInt()

	if a > c-2 || b > c-2 || (a+b) > c-2 {
		fmt.Println(b + c)
		return
	}

	fmt.Println(a + b + 1 + b)

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
//  [go]
package main

import "fmt"

func main() {
	// Code for A - Poisonous Cookies
	var A, B, C int
	fmt.Scanf("%d %d %d", &A, &B, &C)

	if A+B >= C {
		fmt.Println(B + C)
	} else {
		fmt.Println(A + 2*B + 1)
	}
}
//  [ruby]
# frozen_string_literal: true

a, b, c = gets.split.map(&:to_i)

puts b + [a + b + 1, c].min
//  [ruby]
a, b, c = gets.split.map(&:to_i)
ans = 0
if (a + b) >= c - 1
  ans = b + c
else
  ans = (a + b + 1) + b
end
puts ans
//  [ruby]
a,b,c=gets.split.map(&:to_i)
p c>(a+b)? a+2*b+1:b+c
//  [ruby]
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

A,B,C=get_i
x=A+B
n=min(x,C)
if n==C
    puts B+C
else
    puts x+B+1
end
//  [ruby]
DBG = true
a,b,c = gets.split.map{|x| x.to_i}
print ((a+b >= c) ? b+c : (a+2*b+1))
//  [ruby]
a,b,c = gets.split(" ").map!{|p| p.to_i}
#d 食べられるｃの最大値
if c > a + b 
  d = a + b + 1
elsif c == a + b
  d = a + b
else 
  d = c
end
# e 食べるおいしいクッキーの最大値
e = b + d
puts e
//  [rust]
use std::io::Read;

fn main(){
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let a = it.next().unwrap().parse::<i32>().unwrap();
    let b = it.next().unwrap().parse::<i32>().unwrap();
    let c = it.next().unwrap().parse::<i32>().unwrap();
    println!("{}", b + std::cmp::min(a+b+1, c));
}
//  [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_vec::<u64>();
    let (mut a, mut b, mut c) = (line[0], line[1], line[2]);

    let mut ans = cmp::min(b, c)*2;
    b -= ans/2;
    c -= ans/2;

    let ac_set = cmp::min(a, c);
    ans += ac_set;
    a -= ac_set;
    c -= ac_set;

    println!("{}", ans + b + cmp::min(1, c));
}
//  [rust]
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> 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().expect("failed to parse token")
}

fn main() {
    let a = read::<usize>();
    let b = read::<usize>();
    let c = read::<usize>();
    let ans = b + std::cmp::min(a + b + 1, c);
    println!("{}", ans);
}
//  [rust]
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
    mut a:i64,
    mut b:i64,
    mut c:i64,
    }
    let mut ans = 0;

    // c -> b
    if c > 0 {
        if b < c {
            ans += b * 2 + 1;
            c -= b + 1;
            b = 0;
            if a > 1 {
                a -= 1;
                ans += min(a + 1, c);
            }
            println!("{}", ans);
            return;
        } else {
            println!("{}", b + c);
            return;
        }
    } else {
        println!("{}", b + c);
        return;
    }
}
//  [rust]
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
    mut a:i64,
    mut b:i64,
    mut c:i64,
    }
    if a + b + 1 >= c {
        println!("{}", b + c);
    } else {
        println!("{}", 2 * b + a + 1);
    }
}
//  [rust]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let a: usize = read!();
    let b: usize = read!();
    let c: usize = read!();

    let mut ans = b;

    if a + b >= c {
        ans += c;
    } else {
        ans += a + b + 1;
    }

    println!("{}", ans);
}
//  [swift]
let i=readLine()!.characters.split(" ").map{Int(String($0))!},A=i[0],B=i[1],C=i[2]
print(B+min(C,A+B+1))
//  [swift]
import Foundation

extension String {
    func split(separator: String) -> [Int] {
        return self.componentsSeparatedByString(separator).map { Int($0)! }
    }
}

let input = readLine()!.split(" ")
let A = input[0]
let B = input[1]
let C = input[2]

if A+B >= C {
    print(B+C)
} else {
    print(A+B+1+B)
}
//  [typescript]
function main(input) {
    const nums = input.split(' ').map(v => parseInt(v));
    const a = nums[0]; const b = nums[1]; const c = nums[2];
    const yum = b + c;
    const med = a + b;
    console.log(Math.min(yum, med + 1 + b));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [python]
import itertools
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
xy = 0
for i in range(1,n+1):
    for h in itertools.combinations(range(0,n),i):
        x = 0
        y = 0
        for j in h:
            x += v[j]
            y += c[j]
        if xy < x-y:
            xy = x-y
print(xy)
//  [python]
import itertools
N = int(input())

test = {}

V = list(map(int,input().split()))
C = list(map(int,input().split()))
new_n = 0
for i in range(N):
    if V[i] <=  C[i]:
        continue
    else:
        test[i] = [V[i],C[i]]
        new_n += 1

N = new_n

def calc_cost(com,test,i):
    x = 0
    y = 0
    for j in com:
        x += test[j][0]
        y += test[j][1]
    return x - y

ans = 0

for i in range(N):
    c = itertools.combinations(test.keys(), i+1)
    for j in c:
        ans = max(ans,calc_cost(j,test,i))


print(ans)
//  [python]
import numpy as np

n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = 0

for i in range(n):
    if(v[i]-c[i]>0):
        ans += v[i] - c[i]

print(ans)
//  [java]
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        try (InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
        }
    }

    private void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        in.nextLine();

        List<Integer> vs = Arrays.stream(in.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
        List<Integer> cs = Arrays.stream(in.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
        int ans = IntStream.range(0, 1 << n)
                .map(i -> IntStream.range(0, n)
                    .map(j -> (((i >> j) & 1) == 1) ? vs.get(j) - cs.get(j) : 0)
                    .sum()
                )
                .max()
                .getAsInt();
        out.println(ans);
    }
}

class InputReader implements AutoCloseable {
    private final Scanner sc = new Scanner(System.in);

    String next() {
        return this.sc.next();
    }

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

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

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

    String nextLine() {
        return this.sc.nextLine();
    }

    @Override
    public void close() {
        this.sc.close();
    }
}
//  [java]
import java.util.Scanner;
import java.util.stream.Stream;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.nextLine());
		int[] v_list = Stream.of(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		int[] c_list = Stream.of(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		int[] x_y_data = new int[N];
		int result=0;
		
		for(int i=0;i<N;i++) {
			if(v_list[i]-c_list[i]>0) {
				result += v_list[i]-c_list[i];
			}
		}
		System.out.println(result);
	}
}
//  [java]
import java.io.*;
import java.util.*;
class Program{
    int N,v[], c[], arr[];
    ArrayList<Integer> sub_c = new ArrayList<Integer>();
    ArrayList<Integer> sub_v = new ArrayList<Integer>();
    ArrayList<Integer> p = new ArrayList<Integer>();
    Program(int v[], int c[], int N){
        this.v = v;
        this.c = c;
        this.N = N;
        this.arr = new int[N];
    }
    void solve(int i){
        if (i==N) p.add(price());
        else{
            sub_c.add(c[i]);
            sub_v.add(v[i]);
            solve(i+1);
            sub_c.remove(sub_c.size()-1);
            sub_v.remove(sub_v.size()-1);
            solve(i+1);
        }    
    }
    int ans(){
        return Math.max(0,Collections.max(p));
    }
    int price(){
        int sum = 0;
        for(int i=0;i<sub_c.size();i++) sum += sub_v.get(i) - sub_c.get(i);
        return sum;
    }
}
class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int v []= new int[N];
        int c []= new int[N];
        for(int i=0;i<N;i++) v[i] = in.nextInt();
        for(int i = 0;i<N;i++) c[i] = in.nextInt();
        Program obj = new Program(v,c,N);
        obj.solve(0); System.out.println(obj.ans());
    }
}
//  [cpp]
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <bitset>
#include <cmath>

int main(){
   int N;
   std::cin >> N;
   std::vector<int> V(N);
   std::vector<int> C(N);
   for (int i=0; i<N; i++){
      std::cin >> V.at(i);
   }
   for (int i=0; i<N; i++){
      std::cin >> C.at(i);
   }
   int max = 0;
   int nmax = std::pow(2, N);
   for (int i=0; i<nmax; i++){
      std::stringstream i_ss;
      i_ss << std::bitset<20>(i);
      std::string i_s = i_ss.str();
      if (i<10){
         std::cerr << i_s << std::endl;
      }
      int Y = 0, X = 0;
      for (int j=0; j<N; j++){
         if (i_s.at(19-j) == '1'){
            Y = Y + C.at(j);
            X = X + V.at(j);
            max = std::max(max, X-Y);
         }
      }
   }
   std::cout << max << std::endl;
}