jiahuimbzuai/CoQuIR huggingface dataset:
//  [go]
package main

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	defer flush()

	H := readInt()
	W := readInt()
	Ch := readInt() - 1
	Cw := readInt() - 1
	Dh := readInt() - 1
	Dw := readInt() - 1
	S := make([]string, H)
	for i := 0; i < H; i++ {
		S[i] = readString()
	}

	t := make([][]int, H)
	for i := 0; i < H; i++ {
		t[i] = make([]int, W)
		for j := 0; j < W; j++ {
			if S[i][j] == '#' {
				t[i][j] = -1
			} else {
				t[i][j] = math.MaxInt64
			}
		}
	}

	a := 0
	t[Ch][Cw] = a
	q := make([][2]int, 0, 1024)
	q = append(q, [2]int{Ch, Cw})

	warpq := make([][2]int, 0, 1024)
	for len(q) != 0 {
		for len(q) != 0 {
			h, w := q[0][0], q[0][1]
			warpq = append(warpq, [2]int{h, w})
			q = q[1:]
			if h-1 >= 0 && t[h-1][w] > a {
				q = append(q, [2]int{h - 1, w})
				t[h-1][w] = t[h][w]
			}
			if h+1 < H && t[h+1][w] > a {
				q = append(q, [2]int{h + 1, w})
				t[h+1][w] = t[h][w]
			}
			if w-1 >= 0 && t[h][w-1] > a {
				q = append(q, [2]int{h, w - 1})
				t[h][w-1] = t[h][w]
			}
			if w+1 < W && t[h][w+1] > a {
				q = append(q, [2]int{h, w + 1})
				t[h][w+1] = t[h][w]
			}
		}

		if t[Dh][Dw] != math.MaxInt64 {
			break
		}

		a++
		for i := 0; i < len(warpq); i++ {
			h, w := warpq[i][0], warpq[i][1]
			for i := max(0, h-2); i <= min(H-1, h+2); i++ {
				for j := max(0, w-2); j <= min(W-1, w+2); j++ {
					if t[i][j] <= a {
						continue
					}
					t[i][j] = a
					q = append(q, [2]int{i, j})
				}
			}
		}
		warpq = warpq[:0]
	}

	if t[Dh][Dw] == math.MaxInt64 {
		println(-1)
	} else {
		println(t[Dh][Dw])
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}
//  [go]
package main

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	defer flush()

	H := readInt()
	W := readInt()
	Ch := readInt() - 1
	Cw := readInt() - 1
	Dh := readInt() - 1
	Dw := readInt() - 1
	S := make([]string, H)
	for i := 0; i < H; i++ {
		S[i] = readString()
	}

	t := make([][]int, H)
	for i := 0; i < H; i++ {
		t[i] = make([]int, W)
		for j := 0; j < W; j++ {
			if S[i][j] == '#' {
				t[i][j] = -1
			} else {
				t[i][j] = math.MaxInt64
			}
		}
	}

	a := 0
	t[Ch][Cw] = a
	q := make([][2]int, 0, 1024)
	q = append(q, [2]int{Ch, Cw})

	for len(q) != 0 {
		warpq := make([][2]int, 0, 1024)
		for len(q) != 0 {
			h, w := q[0][0], q[0][1]
			warpq = append(warpq, [2]int{h, w})
			q = q[1:]
			if h-1 >= 0 && t[h-1][w] > a {
				q = append(q, [2]int{h - 1, w})
				t[h-1][w] = t[h][w]
			}
			if h+1 < H && t[h+1][w] > a {
				q = append(q, [2]int{h + 1, w})
				t[h+1][w] = t[h][w]
			}
			if w-1 >= 0 && t[h][w-1] > a {
				q = append(q, [2]int{h, w - 1})
				t[h][w-1] = t[h][w]
			}
			if w+1 < W && t[h][w+1] > a {
				q = append(q, [2]int{h, w + 1})
				t[h][w+1] = t[h][w]
			}
		}

		if t[Dh][Dw] != math.MaxInt64 {
			break
		}

		a++
		for i := 0; i < len(warpq); i++ {
			h, w := warpq[i][0], warpq[i][1]
			for i := max(0, h-2); i <= min(H-1, h+2); i++ {
				for j := max(0, w-2); j <= min(W-1, w+2); j++ {
					if t[i][j] <= a {
						continue
					}
					t[i][j] = a
					q = append(q, [2]int{i, j})
				}
			}
		}
	}

	if t[Dh][Dw] == math.MaxInt64 {
		println(-1)
	} else {
		println(t[Dh][Dw])
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}
//  [ruby]
H, W = gets.chomp.split(" ").map(&:to_i)
C = gets.chomp.split(" ").map(&:to_i)
D = gets.chomp.split(" ").map(&:to_i)
S = [Array.new(W+4, -2), Array.new(W+4, -2)]
H.times{
  S << [-2, -2] + gets.chomp.chars.map{|s| s=='#' ? -2 : -1} + [-2, -2]
}
S << Array.new(W+4, -2)
S << Array.new(W+4, -2)

def add_lst(c, r, stp, lst)
  (S[c][r] = stp; lst << [c, r]) if S[c][r] == -1
end

WP = (-2..2).to_a.product((-2..2).to_a).select{|c, r| c.abs+r.abs > 1}
idx,stp, nxt = 0, 0, []
add_lst(C[0]+1, C[1]+1, stp, nxt)

until nxt.empty? do
  while nxt.size > idx do
    c, r = nxt[idx]
    add_lst(c, r+1, stp, nxt)
    add_lst(c, r-1, stp, nxt)
    add_lst(c+1, r, stp, nxt)
    add_lst(c-1, r, stp, nxt)
    idx += 1
  end
  wrp = []
  stp += 1
  nxt.each{|c, r|
    WP.each{|i, j| add_lst(c+i, r+j, stp, wrp)}
  }
  idx, nxt = 0, wrp
end

puts S[D[0]+1][D[1]+1]
//  [ruby]
L=100000000
h,w=gets.split.map &:to_i
ch,cw=gets.split.map &:to_i
dh,dw=gets.split.map &:to_i
cp=(w+4)*(ch+1)+cw+1
dp=(w+4)*(dh+1)+dw+1
d=w+4
f=[nil]*( (h+4)*(w+4) )
h.times{|i|
  gets.chomp.each_char.with_index{|c,j|
    next if c==?#
    f[d*(i+2)+j+2]=L
  }
}
qc=[cp]
qn=[]
dns=[-d,-1,1,d]
dms=(-2..2).flat_map{|i|
  (-2..2).each_with_object([]){|j,r|
    e=i*d+j
    r.push(e) if e.abs>1 && e.abs!=d
  }
}
#p [cp,dp,dns,dms,f]
0.step{|x|
  break if qc.empty? && qn.empty?
  until qc.empty?
    e=qc.pop
    next if f[e]<=x
    f[e]=x
    dns.each{|y|
      qc.push(e+y) if f[e+y]
    }
    dms.each{|y|
      qn.push(e+y) if f[e+y]
    }
  end
  qc=qn
  qn=[]
}
puts f[dp]==L ? -1 : f[dp]
//  [ruby]
h, w = gets.split.map(&:to_i)
ch, cw = gets.split.map(&:to_i)
dh, dw = gets.split.map(&:to_i)

c = [?., ?#]
s = Array.new(h+3) {Array.new(w+3, c[1])}
h.times {|i| s[i+1][1,w+1] = gets.chars}

move = [[1,0], [-1,0], [0,1], [0,-1]]
warp = (-2..2).to_a.product((-2..2).to_a) - move - [[0,0]]

init = 1 << 20
d = Array.new(h+3) {Array.new(w+3, init)}
d[ch][cw] = 0
t = [[ch, cw]]

(0..).each do |k|
    break if t.empty? || d[dh][dw] < init
    u = []

    while (x,y = t.pop)
        next if d[x][y] < k

        move.each do |i,j|
            xx = x + i
            yy = y + j
            if s[xx][yy] == c[0] && d[xx][yy] > k
                d[xx][yy] = k
                t << [xx, yy]
            end
        end

        warp.each do |i,j|
            xx = x + i
            yy = y + j
            if s[xx][yy] == c[0] && d[xx][yy] > k + 1
                d[xx][yy] = k + 1
                u << [xx, yy]
            end
        end
    end

    t = u
end

p d[dh][dw] == init ? -1 : d[dh][dw]
//  [ruby]
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7

h,w = gets.chomp.split.map(&:to_i)
ch, cw = gets.chomp.split.map(&:to_i).map{|e| e-1}
dh, dw = gets.chomp.split.map(&:to_i).map{|e| e-1}
grid = Array.new(h, :a)
# h = w= 100
# dh, dw = 99, 99
h.times do |i|
  grid[i] = gets.chomp.chars.map(&:to_sym)
  # grid.push(('.' * w).chars)
end

q = []
q.push [0, ch, cw]
grid[ch][cw] = 0

ans = 10000000
until q.empty?
  count, y, x = q.shift
  # p count
  break if count >= ans
  gridyx = grid[y][x]
  # p ['main', count, [y, x], gridyx]
  next if gridyx < count

  [y-2, 0].max.upto([y+2,h-1].min) do |ny|
    [x-2, 0].max.upto([x+2,w-1].min) do |nx|
      next if ny == y && nx == x
      ncount = count
      is_near = (ny-y).abs + (nx-x).abs == 1
      ncount += 1 unless is_near

      val = grid[ny][nx]
      if ny == dh && nx == dw
        ans = [ans, ncount].min
      elsif val == :'#'
        # skip
      elsif val == :'.' || val > ncount
        grid[ny][nx] = ncount
        if is_near
          q.unshift [ncount, ny, nx]
        else
          q.push [ncount, ny, nx]
        end
      end
    end
  end
end

# grid.each{|l| p l }
if ans == 10000000
  puts -1
else
  puts ans
end
//  [ruby]
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7

h,w = gets.chomp.split.map(&:to_i)
ch, cw = gets.chomp.split.map(&:to_i).map{|e| e-1}
dh, dw = gets.chomp.split.map(&:to_i).map{|e| e-1}
grid = Array.new(h, :a)
# h = w= 100
# dh, dw = 99, 99
h.times do |i|
  grid[i] = gets.chomp.chars.map(&:to_sym)
  # grid.push(('.' * w).chars)
end

q = []
q.push [0, ch, cw]
grid[ch][cw] = 0

ans = 10000000
until q.empty?
  q.uniq!
  count, y, x = q.shift
  break if count >= ans
  gridyx = grid[y][x]
  # p ['main', count, [y, x], gridyx]
  next if gridyx != :'.' && gridyx < count

  [y-2, 0].max.upto([y+2,h-1].min) do |ny|
    [x-2, 0].max.upto([x+2,w-1].min) do |nx|
      next if ny == y && nx == x
      ncount = count
      is_near = (ny-y).abs + (nx-x).abs == 1
      ncount += 1 unless is_near

      val = grid[ny][nx]
      if ny == dh && nx == dw
        ans = [ans, ncount].min
      elsif val == :'#'
        # skip
      elsif val == :'.' || val > ncount
        grid[ny][nx] = ncount
        if is_near
          q.unshift [ncount, ny, nx]
        else
          q.push [ncount, ny, nx]
        end
      end
    end
  end
end

# grid.each{|l| p l }
if ans == 10000000
  puts -1
else
  puts ans
end
//  [ruby]
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7

h,w = gets.chomp.split.map(&:to_i)
ch, cw = gets.chomp.split.map(&:to_i).map{|e| e-1}
dh, dw = gets.chomp.split.map(&:to_i).map{|e| e-1}
grid = Array.new(h, :a)
# h = w= 100
# dh, dw = 99, 99
h.times do |i|
  grid[i] = gets.chomp.chars.map(&:to_sym)
  # grid.push(('.' * w).chars)
end

q = []
q.push [0, ch, cw]
grid[ch][cw] = 0

ans = 10000000
until q.empty?
  count, y, x = q.shift
  break if count >= ans
  gridyx = grid[y][x]
  # p ['main', count, [y, x], gridyx]
  next if gridyx != :'.' && gridyx < count

  [y-2, 0].max.upto([y+2,h-1].min) do |ny|
    [x-2, 0].max.upto([x+2,w-1].min) do |nx|
      next if ny == y && nx == x
      ncount = count
      is_near = (ny-y).abs + (nx-x).abs == 1
      ncount += 1 unless is_near

      val = grid[ny][nx]
      if ny == dh && nx == dw
        ans = [ans, ncount].min
      elsif val == :'#'
        # skip
      elsif val == :'.' || val > ncount
        grid[ny][nx] = ncount
        if is_near
          q.unshift [ncount, ny, nx]
        else
          q.push [ncount, ny, nx]
        end
      end
    end
  end
end

# grid.each{|l| p l }
if ans == 10000000
  puts -1
else
  puts ans
end
//  [rust]
use std::collections::VecDeque;

pub fn main() {
  fn read_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf);
    buf
  }
  fn read_tuple() -> (i32, i32) {
    let a: Vec<usize> = read_line()
      .split_whitespace()
      .map(|e| e.parse().unwrap())
      .collect();
    (a[0] as i32, a[1] as i32)
  }
  let (h, w) = read_tuple();
  let (ch, cw) = read_tuple();
  let (dh, dw) = read_tuple();

  let mut map: Vec<Vec<i32>> = Vec::new();
  for _ in 0..h {
    let mut row: Vec<i32> = Vec::new();
    let s: Vec<char> = read_line().trim().chars().collect();
    for j in 0..w {
      if s[j as usize] == '.' {
        row.push(-1);
      } else {
        row.push(-2);
      }
    }
    map.push(row);
  }

  let mv: Vec<(i32, i32)> = {
    let mut v = Vec::new();
    for i in -2..3 {
      for j in -2..3 {
        if !(i == 0 && j == 0) {
          v.push((i, j));
        }
      }
    }
    v
  };

  let mut deque: VecDeque<(i32, i32, i32)> = VecDeque::new();
  deque.push_front((ch, cw, 0));

  while !deque.is_empty() {
    let (cur_h, cur_w, point) = deque.pop_front().unwrap();
    if map[(cur_h as usize) - 1][(cur_w as usize) - 1] != -1 {
      continue;
    }
    map[(cur_h as usize) - 1][(cur_w as usize) - 1] = point;
    if cur_h == dh && cur_w == dw {
      println!("{}", point);
      return;
    }

    for next in &mv {
      let next_h = cur_h + next.0;
      let next_w = cur_w + next.1;
      if (next_h >= 1)
        && (next_w >= 1)
        && next_h <= h
        && next_w <= w
        && map[next_h as usize - 1][next_w as usize - 1] == -1
      {
        if next.0.abs() + next.1.abs() == 1 {
          deque.push_front((next_h, next_w, point));
        } else {
          deque.push_back((next_h, next_w, point + 1));
        }
      }
    }
  }
  println!("-1");
  return;
}
//  [rust]
use proconio::*;
use proconio::marker::*;

fn run() {
    input! {
        h: usize,
        w: usize,
        src: (Usize1, Usize1),
        dst: (Usize1, Usize1),
        mut s: [Chars; h],
    }
    for s in s.iter_mut() {
        for _ in 0..2 {
            s.insert(0, '#');
            s.push('#');
        }
    }
    for _ in 0..2 {
        s.insert(0, vec!['#'; w + 4]);
        s.push(vec!['#'; w + 4]);
    }
    let h = h + 4;
    let w = w + 4;
    let src = (src.0 + 2, src.1 + 2);
    let dst = (dst.0 + 2, dst.1 + 2);
    let mut used = vec![vec![false; w]; h];
    used[src.0][src.1] = true;
    let mut que = std::collections::VecDeque::new();
    que.push_back(src);
    for i in 0.. {
        if que.is_empty() {
            println!("-1");
            return;
        }
        let mut a = vec![];
        while let Some((x, y)) = que.pop_front() {
            a.push((x, y));
            for d in [!0, 0, 1, 0, !0].windows(2) {
                let x = x + d[0];
                let y = y + d[1];
                if !used[x][y] && s[x][y] != '#' {
                    used[x][y] = true;
                    que.push_back((x, y));
                }
            }
        }
        if used[dst.0][dst.1] {
            println!("{}", i);
            return;
        }
        for (x, y) in a {
            for p in [!1, !0, 0, 1, 2].iter() {
                for q in [!1, !0, 0, 1, 2].iter() {
                    let x = x + *p;
                    let y = y + *q;
                    if !used[x][y] && s[x][y] != '#' {
                        used[x][y] = true;
                        que.push_back((x, y));
                    }
                }
            }
        }
    }
}

fn main() {
    run();
}
//  [rust]
use proconio::input;
use proconio::marker::{Chars};
use std::collections::VecDeque;

fn main() {
    input!{
        h: usize,
        w: usize,
        c: [usize; 2],
        d: [usize; 2],
        sdash: [Chars; h],
    }
    let inf: usize = 999999999999;
    let mut v = vec![vec![inf; w+4]; h+4];
    let mut s = vec![vec!['#'; w+4]; h+4];
    for i in 0..h {
        for j in 0..w {
            s[i+2][j+2] = sdash[i][j];
        }
    }
    let mut q = VecDeque::new();

    q.push_back((c[0]+1, c[1]+1, 0));

    while q.len() > 0 {
        let (x, y, cost) = q.pop_front().unwrap();
        v[x][y] = cost;
        if v[x+1][y] == inf && s[x+1][y] == '.' {
            q.push_front((x+1, y, cost));
//            v[x+1][y] = cost;
        }
        else if v[x][y+1] == inf && s[x][y+1] == '.' {
            q.push_front((x, y+1, cost));
//            v[x][y+1] = cost;
        }
        else if v[x-1][y] == inf && s[x-1][y] == '.' {
            q.push_front((x-1, y, cost));
//            v[x-1][y] = cost;
        }
        else if v[x][y-1] == inf && s[x][y-1] == '.' {
            q.push_front((x, y-1, cost));
            v[x][y-1] = cost;
        }
        else {
            for i in x-2..x+3 {
                for j in x-2..x+3 {
                    if v[i][j] == inf && s[i][j] == '.' {
                        q.push_back((i, j, cost+1));
//                        v[i][j] = cost+1;
                    }
                }
            }
        }
    }
    if v[d[0]+1][d[1]+1] == inf {
        println!("-1");
    }
    else {
        println!("{}", v[d[0]+1][d[1]+1]);
    }
}
//  [rust]
use proconio::input;
use proconio::marker::{Chars};
use std::collections::VecDeque;

fn main() {
    input!{
        h: usize,
        w: usize,
        c: [usize; 2],
        d: [usize; 2],
        sdash: [Chars; h],
    }
    let inf: usize = 999999999999;
    let mut v = vec![vec![inf; w+4]; h+4];
    let mut s = vec![vec!['#'; w+4]; h+4];
    for i in 0..h {
        for j in 0..w {
            s[i+2][j+2] = sdash[i][j];
        }
    }
    let mut q = VecDeque::new();

    q.push_back((c[0]+1, c[1]+1, 0));

    while q.len() > 0 {
        let (x, y, cost) = q.pop_front().unwrap();
        if v[x+1][y] == inf && s[x+1][y] == '.' {
            q.push_front((x+1, y, cost));
            v[x+1][y] = cost;
        }
        else if v[x][y+1] == inf && s[x][y+1] == '.' {
            q.push_front((x, y+1, cost));
            v[x][y+1] = cost;
        }
        else if v[x-1][y] == inf && s[x-1][y] == '.' {
            q.push_front((x-1, y, cost));
            v[x-1][y] = cost;
        }
        else if v[x][y-1] == inf && s[x][y-1] == '.' {
            q.push_front((x, y-1, cost));
            v[x][y-1] = cost;
        }
        else {
            for i in x-2..x+3 {
                for j in x-2..x+3 {
                    if v[i][j] == inf && s[i][j] == '.' {
                        q.push_back((i, j, cost+1));
                        v[i][j] = cost+1;
                    }
                }
            }
        }
    }
    if v[d[0]+1][d[1]+1] == inf {
        println!("-1");
    }
    else {
        println!("{}", v[d[0]+1][d[1]+1]);
    }
}
//  [rust]
use proconio::input;
use proconio::marker::{Chars};
use std::collections::VecDeque;

fn main() {
    input!{
        h: usize,
        w: usize,
        c: [usize; 2],
        d: [usize; 2],
        sdash: [Chars; h],
    }
    let inf = 1000000000;
    let mut v = vec![vec![inf; w+4]; h+4];
    let mut s = vec![vec!['#'; w+4]; h+4];
    for i in 0..h {
        for j in 0..w {
            s[i+2][j+2] = sdash[i][j];
        }
    }
    let mut q = VecDeque::new();

    q.push_back((c[0]+1, c[1]+1, 0));

    while q.len() > 0 {
        let (x, y, cost) = q.pop_front().unwrap();
        if v[x+1][y] == inf && s[x+1][y] == '.' {
            q.push_front((x+1, y, cost));
            v[x+1][y] = cost;
        }
        else if v[x][y+1] == inf && s[x][y+1] == '.' {
            q.push_front((x, y+1, cost));
            v[x][y+1] = cost;
        }
        else if v[x-1][y] == inf && s[x-1][y] == '.' {
            q.push_front((x-1, y, cost));
            v[x-1][y] = cost;
        }
        else if v[x][y-1] == inf && s[x][y-1] == '.' {
            q.push_front((x, y-1, cost));
            v[x][y-1] = cost;
        }
        else {
            for i in x-2..x+3 {
                for j in x-2..x+3 {
                    if v[i][j] == inf && s[i][j] == '.' {
                        q.push_back((i, j, cost+1));
                        v[i][j] = cost+1;
                    }
                }
            }
        }
    }
    if v[d[0]+1][d[1]+1] == inf {
        println!("-1");
    }
    else {
        println!("{}", v[d[0]+1][d[1]+1]);
    }
}
//  [swift]
let HW = readLine()!.split(separator: " ").compactMap { Int($0) }
let h = HW[0]
let w = HW[1]

let C = readLine()!.split(separator: " ").compactMap { Int($0) }
let ch = C[0]-1
let cw = C[1]-1

let D = readLine()!.split(separator: " ").compactMap { Int($0) }
let dh = D[0]-1
let dw = D[1]-1

var shw = (1...h).map { _ in Array(readLine()!) }

var queue: [[(Int, Int)]] = Array(repeating: [], count: 1000000)
var currentResult: Int = 0
var isExist = false

func isDot(i: Int, j: Int) -> Bool {
    if i < 0 || shw.count <= i { return false }
    if j < 0 || shw[i].count <= j { return false }
    return shw[i][j] == "."
}

func search(i: Int, j: Int) {
    for idot in i-2...i+2 {
        for jdot in j-2...j+2 {
            if idot == i && jdot == j { continue }

            if isDot(i: idot, j: jdot) {
                if ((idot == i - 1 || idot == i + 1) && jdot == j) || ((jdot == j - 1 || jdot == j + 1) && idot == i) {
                    queue[currentResult].append((idot, jdot))
                } else {
                    queue[currentResult+1].append((idot, jdot))
                }
            }
        }
    }
    shw[i][j] = "#"
}

search(i: ch, j: cw)
if queue[currentResult].isEmpty {
    currentResult += 1
}
while !queue[currentResult].isEmpty {
    let element = queue[currentResult].popLast()!

    if element.0 == dh && element.1 == dw {
        isExist = true
        break
    }

    if isDot(i: element.0, j: element.1) {
        search(i: element.0, j: element.1)
    }

    if queue[currentResult].isEmpty {
        currentResult += 1
    }
}
print(isExist ? currentResult : -1)
//  [swift]
let HW = readLine()!.split(separator: " ").compactMap { Int($0) }
let h = HW[0]
let w = HW[1]

let C = readLine()!.split(separator: " ").compactMap { Int($0) }
let ch = C[0]-1
let cw = C[1]-1

let D = readLine()!.split(separator: " ").compactMap { Int($0) }
let dh = D[0]-1
let dw = D[1]-1

var shw = (1...h).map { _ in Array(readLine()!) }

var queue: [[(Int, Int)]] = Array(repeating: [], count: 1000)
var currentResult: Int = 0
var isExist = false

func isDot(i: Int, j: Int) -> Bool {
    if i < 0 || shw.count <= i { return false }
    if j < 0 || shw[i].count <= j { return false }
    return shw[i][j] == "."
}

func search(i: Int, j: Int) {
    for idot in i-2...i+2 {
        for jdot in j-2...j+2 {
            if idot == i && jdot == j { continue }

            if isDot(i: idot, j: jdot) {
                if ((idot == i - 1 || idot == i + 1) && jdot == j) || ((jdot == j - 1 || jdot == j + 1) && idot == i) {
                    queue[currentResult].append((idot, jdot))
                } else {
                    queue[currentResult+1].append((idot, jdot))
                }
            }
        }
    }
    shw[i][j] = "#"
}

search(i: ch, j: cw)
if queue[currentResult].isEmpty {
    currentResult += 1
}
while !queue[currentResult].isEmpty {
    let element = queue[currentResult].popLast()!

    if element.0 == dh && element.1 == dw {
        isExist = true
        break
    }

    if isDot(i: element.0, j: element.1) {
        search(i: element.0, j: element.1)
    }

    if queue[currentResult].isEmpty {
        currentResult += 1
    }
}
print(isExist ? currentResult : -1)
//  [swift]
let HW = readLine()!.split(separator: " ").compactMap { Int($0) }
let h = HW[0]
let w = HW[1]

let C = readLine()!.split(separator: " ").compactMap { Int($0) }
let ch = C[0]-1
let cw = C[1]-1

let D = readLine()!.split(separator: " ").compactMap { Int($0) }
let dh = D[0]-1
let dw = D[1]-1

var shw = (1...h).map { _ in Array(readLine()!) }
var shwResults = shw.map { $0.map { _ in -1 } }

var queue: [[(Int, Int)]] = Array(repeating: [], count: 1000)
var currentResult: Int = 0
var isExist = false

func isDot(i: Int, j: Int) -> Bool {
    if i < 0 || shw.count <= i { return false }
    if j < 0 || shw[i].count <= j { return false }
    return shw[i][j] == "."
}

func search(i: Int, j: Int) {
    for idot in i-2...i+2 {
        for jdot in j-2...j+2 {
            if idot == i && jdot == j { continue }

            if isDot(i: idot, j: jdot) {
                if ((idot == i - 1 || idot == i + 1) && jdot == j) || ((jdot == j - 1 || jdot == j + 1) && idot == i) {
                    queue[currentResult].append((idot, jdot))
                } else {
                    queue[currentResult+1].append((idot, jdot))
                }
            }
        }
    }
    shw[i][j] = "#"
}

search(i: ch, j: cw)
if queue[currentResult].isEmpty {
    currentResult += 1
}
while !queue[currentResult].isEmpty {
    let element = queue[currentResult].popLast()!

    if element.0 == dh && element.1 == dw {
        isExist = true
        break
    }

    if (shwResults[element.0][element.1] != -1) && (shwResults[element.0][element.1] <= currentResult) { return }

    search(i: element.0, j: element.1)
    if queue[currentResult].isEmpty {
        currentResult += 1
    }
}
print(isExist ? currentResult : -1)
//  [swift]
func main() {
    let hw = readLine()!.split(separator: " ").map{Int($0)!}
    let (h, w) = (hw[0], hw[1])
    let cArray = readLine()!.split(separator: " ").map{Int($0)!}
    let ch = cArray[0]
    let cw = cArray[1]
    let dArray = readLine()!.split(separator: " ").map{Int($0)!}
    let dh = dArray[0]
    let dw = dArray[1]
    var maze = [Int]()
    for _ in 0..<h {
        let line = readLine()!.map{$0 == "#" ? 1 : 0}
        maze += line
    }
    let walk = [(01,00), (-1,00), (00,01), (00,-1)]
    
    let warp = [(-2,02), (-2,01), (-2,00), (-2,-1), (-2,-2),
                (-1,02), (-1,01),          (-1,-1), (-1,-2),
                (00,02),                            (00,-2),
                (01,02), (01,01),          (01,-1), (02,-2),
                (02,02), (02,01), (02,00), (02,-1), (02,-2)
                ]
    
    var dist = 0
    var set1 = Set<Int>()
    func indexing(a: Int, b: Int) -> Int {
        return w*(a-1) + (b-1)
    }
    let start = indexing(a: ch, b: cw)
    let goal = indexing(a: dh, b: dw)
    set1.insert(start)
    var set2 = Set<Int>() // walked
    var set3 = Set<Int>() // warped
    while true {
        let one = set1.popFirst()!
        set2.insert(one)
        if one == goal {
            break
        }
        for each in walk {
            let x = one / w + each.0
            let y = one % w + each.1
            if x >= 0 && x < h && y >= 0 && y < w {
                if !set2.contains(one + w*each.0 + each.1) && maze[one + w*each.0 + each.1] == 0 {
                    set1.insert(one + w*each.0 + each.1)
                }
            }
        }
        if set1.isEmpty {
            dist += 1
            set1 = set2
            for item in set2 {
                for each in warp {
                    let x = item / w + each.0
                    let y = item % w + each.1
                    if x >= 0 && x < h && y >= 0 && y < w {
                        if !set1.contains(item + w*each.0 + each.1) && maze[item + w*each.0 + each.1] == 0 {
                            set3.insert(item + w*each.0 + each.1)
                        }
                    }
                }
            }
            if set3.isEmpty {
                dist = -1
                break
            }
            set1 = set3
            set2 = Set<Int>()
            set3 = Set<Int>()
        }
    }
    print(dist)
}
main()
//  [python]

ans = 0
s = input()
for s_ in list(s):
    if s_ == '+':
        ans += 1

    else:
        ans -= 1

print(ans)
//  [python]
a = input()
print(a.count("+") - a.count("-"))
//  [python]
S=input()
for i in range(len(S)):
  S=S[:2*i+1]+"1"+S[2*i+1:]
print(eval("0"+S))
//  [python]
n, k = map(int, input().split())
x = list(map(int, input().split()))

ans = pow(10, 9)
for i in range(n - k + 1):
    tmp = min(abs(x[i]), abs(x[i + k - 1]))
    ans = min(ans, tmp + x[i + k - 1] - x[i])
print(ans)
//  [python]
s = list(map(str, input()))
a = s.count(+)
b = s.count(-)
print(a - b)
//  [python]
s = map(int, input().split(1))
a = s.count(+)
b = s.count(-)
print(a - b)
//  [java]
import java.io.*;
import java.util.*;
import java.math.*;
class Main
{ 
	public static int M = 1000000007;
    public static void main(String[] args)throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String s = br.readLine();	
        int n=0;
        for(int i=0;i<s.length();i++)
        {
            if(s.charAt(i)=='+')
                n++;
            else
                n--;
        }
        out.println(n);
        out.flush();
    }
    /** Loops
    *	i: for(int i=0;i<n;i++)
    *	j: for(int j=0;j<n;j++)
    *	k: for(int k=0;k<n;k++)

    *	ArrayList<Integer> arr1 = new ArrayList<>();
    
    * 	HashMap
    *	HashMap<Integer, Integer> hm = new HashMap<>();
    * 	for (Map.Entry<String,String> entry : hm.entrySet()) 
    		out.println(entry.getValue());
    
    *	Count frequencies
    	for(int i=0;i<n;i++)
        {
            Integer c = hm.get(Integer.parseInt(s[i]));
            if(c==null)
                hm.put(Integer.parseInt(s[i]),1);
            else
                hm.put(Integer.parseInt(s[i]),++c);
        }
	**/		
    public static long modularExpo(long x,long n,int M)
	{
		long result=1;
		while(n>0)
		{
		    if(n%2==1)
		        result=(result*x)%M;
		    x=(x*x)%M;
		    n=n/2;
		}	
		return result;												
	}
	//FLT, only when a and M are co-prime
	public static long modInverse(int a,int M)
	{
		long g = gcd(a,M);
		if(g!=1)
			return -1;
	    return modularExpo(a,M-2,M);
	}
	public static long gcd(int a, int b) 
	{
	    if(b==0)
	        return a;
	    else
	        return gcd(b, a % b);
	}
}
//  [java]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
	    String line = Io.read();

	    int answer = 0;
	    for (int i = 0; i < line.length(); i++) {
	        if (line.charAt(i) == '+') answer++;
	        else answer--;
        }

        Io.write(answer);
    }
}

class Io {

    public static String read() throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        br.close();
        return line;
    }

    public static void write(int answer)
    {
        System.out.println(answer);
    }
}
//  [java]
import java.io.*;
import java.util.*;

class Main {
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      char[] a=br.readLine().toCharArray();
      long count=0;
      for(int i=0;i<a.length;i++){
        if(a[i]=='+')
         count++;
        else
        count--;
      }
      System.out.println(count);
    }
  }
//  [java]
package abc101.a;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        String chara = scan.nextLine();
        int count = 0;
        for (char c :chara.toCharArray()) {
            if (c == '+') {
                count++;
            } else {
                count--;
            }
        }
        System.out.println(count);
    }
}
//  [java]
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    
    Scanner scan = new Scanner(System.in);
    int x = 0;
    String str = scan.next();
    
    for (int i = 0; i <= 4; i++) {
      char ch = str.charAt(i);
      
      if (ch == '+') {
        x = x + 1;
      }
      
      if (ch == '-') {
        x = x - 1;
      }
    }
    
    System.out.println(x);
  }
}
//  [java]
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    
    Scanner scan = new Scanner(System.in);
    int x = 0;
    String str = scan.next();
    String plus = "+";
    String minus = "-";
    
    for (int i = 0; i <= 4; i++) {
      char ch = str.charAt(i);
      
      if (ch.equals(plus)) {
        x = x + 1;
      }
      
      if (ch.equals(minus)) {
        x = x - 1;
      }
    }
    
    System.out.println(0);
  }
}
//  [cpp]
#include <stdio.h>

int main(void){
  char input;
  int count = 0;
  for(int i = 0; i < 4; i++){
    input = getchar();
    if(input == '+')
      count++;
    else
      count--;
  }
  printf("%d\n", count);
}
//  [cpp]
#include <cstdio>
char s[7];
int Ans;
int main(){
	scanf("%s",s);
	for (char *i=s;*i;++i) if (*i=='+') ++Ans; else --Ans;
	printf("%d",Ans);
	return 0;
}
//  [cpp]
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n;
ll K;

int main()
{
	char a;
	int ans=0;
	for(int i=0;i<4;i++){
		scanf("%c",&a);
		if(a == '+')ans ++;
		else ans--;
	}
	printf("%d\n",ans);
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i=0; i < (n); i++)
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;

int main() {
    string s;
    int ans = 0;
    cin >> s;
    rep(i,4){
        if(s[i] == '+')ans += 1;
        else ans -= 1;
    }
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i=0; i < (n); i++)
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;

int main() {
    string s;
    int ans = 0;
    cin >> s;
    rep(i,4){
        if(s[i] = '+')ans += 1;
        else ans -= 1;
    }
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  string a;
  ll b=0;
  ll c=0;
  for(ll i=0;i<4;i++){
    if(a.at(i)=='+'){
      b+=1;
    }
    else{
      c+=1;
    }
  }
  cout<<b-c<<endl;
    
  return 0;
}
//  [c]
#include <stdio.h>
int main(void)
{
	char s[4];
	int t;
	int takahasi = 0;
	
	scanf("%s", s);
	
	for (t = 0; t < 4; t++){
		 if (s[t] == '+'){
		 	takahasi++;
		 }
		 
		 else if (s[t] == '-'){
		 	takahasi--;
		 }
		 
	}
	
	printf("%d", takahasi);
	
	return 0;
}
//  [c]
#include<stdio.h>
int main()
{
    char s[5];
    scanf("%s", s);
    int i;
    int ans = 0;
    for (i = 0; i < 4; i++)
    {
        if (s[i] == '+')
            ans++;
        else
            ans--;
    }
    printf("%d\n", ans);
    return 0;
}
//  [c]
#include <stdio.h>

int main(void)
{
    int n;
    char str[5];
    int i;

    scanf("%s", str);

    n = 0;
    for(i = 0; str[i] != '\0'; i++){
        if(str[i] == '+'){
            n++;
        }
        else{
            n--;
        }
    }

    printf("%d\n", n);

    return(0);
}
//  [c]
#include<iostream>
 
using namespace std;
 
int main(){
    char S[5];
    scanf("%s", S);
    int sum=0;
    for(int i=0; i<4; i++){
        if(S[i]=='-')sum--;
        else sum++;
    }
    printf("%d\n", sum);
    return 0;
}
//  [c]
#include<stdio.h>

int main(void){
  char s[3];
  scanf("%s",s);
  int c=0;
  for(int i=0;i<4;i++){
    if(s[i]=='+'){
      c++;
    }else{
      c--;
    }
  }
    printf("%d",c);
   return 0;
}
//  [c]
#include<stdio.h>

int main(void){
  char s[20];
  scanf("%s",s);
  int c=0;
  for(int i=0;i<5;i++){
    if(s[i]=='+'){
      c++;
    }else{
      c--;
    }
  }
    printf("%d",c);
   return 0;
}
//  [javascript]
var input = require("fs").readFileSync("/dev/stdin","utf-8").trim();
var num=0;
for(var i=0;i<input.length;i++){
	if(input[i]==="+") num++;
  	if(input[i]==="-") num--;
}
console.log(num);
//  [javascript]
function main(input) {

    input = input.split('\n')[0].split('');
    var plus = 0;
    var minus = 0;
    for (var i = 0; i < input.length; i++) {
        if (input[i] == '+') plus++;
        else minus++;
    }


    console.log(plus - minus)

}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
  var s = 0;
  var result = input.split('');

  for (var i = 0; i < 4; i++) {
    if(result[i] === '+') {
      s++;
    } else if(result[i] === '-') {
      s--;
    }
  }
  console.log(s);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
const main = (arg) => {
  const lines = arg.trim().split('\n');
  const S = lines[0];
  let ans = 0;
  S.forEach((c) => {
    ans += c === '+' ? 1 : -1;
  });
  console.log(ans);
};
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function main(input) {
  const N = parseInt(input, 10);
  (N % 2 === 0) ? console.log(N) : console.log(N * 2);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function main(input) {
  const S = input.split('');
  let ans = 0;
  
  for (let i = 0; i < S.length; i++) {
    S[i] === '+' ? ans++ : ans--;
  }
  
  console.log(ans);
}

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

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	ans := 0
	for _, v := range s {
		if string(v) == "+" {
			ans++
		} else {
			ans--
		}
	}
	fmt.Println(ans)

}
//  [go]
package main

import (
    . "fmt"
    "strings"
)

func main() {
    var s string
    Scanf("%s", &s)

    ans := 0
    ss := strings.Split(s, "")
    for _, v := range ss {
        if v == "+" {
            ans++
        } else if v == "-" {
            ans--
        }
    }
    Println(ans)
}
//  [go]
// https://atcoder.jp/contests/abc101/tasks/abc101_a

package main

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

func main() {
  scanner := bufio.NewScanner(os.Stdin)
  scanner.Scan()
  S := scanner.Text()

  n := 4
  res := 0
  for i := 0; i < n; i++ {
    if string(S[0]) == "+" {
      res++
    } else {
      res--
    }
  }

  fmt.Println(res)
}

type Io struct {
  reader *bufio.Reader
  writer *bufio.Writer
  tokens []string
  nextToken int
}

func NewIo() *Io {
  return &Io{
    reader: bufio.NewReader(os.Stdin),
    writer: bufio.NewWriter(os.Stdout),
  }
}

func (io *Io) Next() string {
  if io.nextToken >= len(io.tokens) {
    line := io.NextLine()
    io.tokens = strings.Fields(line)
    io.nextToken = 0
  }

  res := io.tokens[io.nextToken]
  io.nextToken++
  return res
}

func (io *Io) NextInt() int {
  res, err := strconv.Atoi(io.Next())
  if err != nil {
    panic(err)
  }
  return res
}

func (io *Io) NextStrings(n int) []string {
  res := make([]string, n)
  for i := 0; i < n; i++ {
    res[i] = io.Next()
  }
  return res
}

func (io *Io) Println(a ...interface{}) {
  var values []string
  for i := 0; i < len(a); i++ {
    values = append(values, "%v")
  }
  io.Printfln(strings.Join(values, " "), a...)
}

func (io *Io) Printfln(format string, a ...interface{}) {
  fmt.Fprintf(io.writer, format+"\n", a...)
}

func (io *Io) NextLine() string {
  if io.nextToken < len(io.tokens) {
    panic("io.nextToken < len(io.tokens)")
  }

  var buffer bytes.Buffer

  for {
    line, isPrefix, err := io.reader.ReadLine()
    if err != nil {
      panic(err)
    }
    buffer.Write(line)
    if !isPrefix {
      break
    }
  }

  return buffer.String()
}
//  [go]
package main

import "fmt"

func main(){
  var s string
  fmt.Scan(&s)
  cnt := 0
  for _, x := range s {
    switch x {
    case "+": cnt++
    case "-": cnt--
    }
  }
  fmt.Println(cnt)
}
//  [go]
package main

import (
    "fmt"
    "os"
    "strings"
)

func main() {
    var s string
    fmt.Scan(&s)

    fmt.Fprint(os.Stdin, strings.Count(s, "+") - strings.Count(s, "-"))
}
//  [ruby]
s = gets.chomp

print("#{2 * s.count('+') - 4}")
//  [ruby]
s = gets.chomp.chars
ans = 0
s.each do |ss|
  if ss == "+"
    ans += 1
  else
    ans -= 1
  end
end

puts ans
//  [ruby]
a=gets.chomp.count("+");p (0 + a) - (4 - a)
//  [ruby]
s = gets.chomp
p s.size - s.count("-")
//  [ruby]
r = 0
gets.chomp.chars.do |c|
  r += (c == "+") ? 1 : -1
end
p r
//  [ruby]
int = 0
S = ["+", "-", "+", "+"]

if S[0] == "+" then
  int+=1
else
  int-=1
end
if S[1] == "+" then
  int+=1
else
  int-=1
end
if S[2] == "+" then
  int+=1
else
  int-=1
end
if S[3] == "+" then
  int+=1
else
  int-=1
end

print int
//  [rust]
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let s = buf.trim().chars().collect::<Vec<char>>();
	let mut ret:i32 = 0;
	for i in s {
		if i == '+' {
			ret += 1;
		}else{
			ret -= 1;
		}
	}
	println!("{}", ret);
}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main(){

    input!{
        s:chars,
    }

    let mut ans = 0;

    for i in s{
        if i=='+' {
            ans += 1;
        } else {
            ans -= 1;
        }
    }

    println!("{}", ans);

}
//  [rust]
//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
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 ) * } } ; }
//入力マクロここまで

fn main() {
    input! {
        n: usize,
        k: usize,
        _a: [u64;n],
    }

    let ans = if n % (k - 1) == 0 {
        n / (k - 1)
    } else {
        n / (k - 1) + 1
    };

    println!("{}", ans);
}
//  [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 s = read_as_string().chars().collect::<Vec<char>>();

    println!("{}", s.iter().filter(|x| **x == '+').count()*2 - s.len());
}
//  [rust]
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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<_>>()
    };

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

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

test! {
// r#"2018 218"# => "Yes",
// r#"2763 0"# => "No",
r#"999"# => "ABC",

}

fn solve(src: &str) -> String {
    input! {
        source = src,
        s: chars,
    }

    let mut ans:i64 = 0;

    for i in 0..s.len() {
        if s[i] == '+' {
            ans += 1;
        } else {
            ans += 0;
        }
    }

    ans.to_string()
}
//  [swift]
var i=0;readLine()!.characters.forEach{String($0)=="+" ?i++:i--};print(i)
//  [swift]
let s = Array(readLine()!.characters)
var ans = 0
for i in 0...3 {
  ans += s[i] == Character("+") ? 1 : -1
}
print(ans)
//  [swift]
var i=0;readLine()!.characters.forEach(String($0)=="+" ?i++:i--);print(i)
//  [typescript]
import * as fs from 'fs';

namespace AtCoder.abc101 {
    class ProgramA {
        args: string[];

        // +-++
        // 2
        constructor(args: string[]) {
            this.args = args;
        }

        main(): void {
            const s: string = args[0];
            let ans: number = 0;

            s.split('').forEach(x => {
                if (x === '+') ans++;
                if (x === '-') ans--;
            });
            console.log(ans);
        }
    }

    const args: string[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
    const func: ProgramA = new ProgramA(args);
    func.main();
}