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

import (
        "fmt"
)

func main () {
        var n, x, na, ana, an int 
        fmt.Scan(&n)
        for i := 0 ; i < n ; i++ {
                x = 0
                na = n - i
                for{
                        x += 1
                        xx := x * x
                        if xx == na {
                                ana +=1
                                an = xx
                                break 
                        }  else if xx > na {
                                break
                        }
                }
                if ana != 0 {
                        fmt.Println(an)
                        break
                }
        }
}
//  [go]
// contest.go
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var n uint64
	n = nextInt()
	var d uint64
	if n == 1 {
		d = 1
		fmt.Println(d)
		return
	}
	d = sqr(n)
	fmt.Println(d)

}
func nextInt() uint64 {
	sc.Scan()
	i, e := strconv.ParseUint(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}
func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func sqr(n uint64) uint64 {
	var a uint64
	var d uint64
	d = n
	for i := n; i != (d * d); i-- {
		for d = 0; i != (d * d); d++ {
			a = i
			if i <= (d * d) {
				break
			}
		}
		if i == (d * d) {
			a = i
			break
		}
		if i < 0 {
			break
		}
	}
	return a
}
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	ans := 1
	for i := 1; i*i <= n; i++ {
		ans = i * i
	}
	fmt.Println(ans)
}
//  [ruby]
n = gets.to_i

while n > 0
  break if Math.sqrt(n).to_s.match(/\.0\Z/)
  n -= 1
end

puts n
//  [ruby]
n = gets.to_i
puts (Math.sqrt(n).floor)**2
//  [ruby]
N=gets.to_i
puts (N**0.5).to_i**2
//  [rust]
#![allow(unused_imports)]

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::fmt;
use std::io::{self, BufWriter, Read, Write};
use std::ops::{Add, Div, Mul, Sub};
use std::str::{self, FromStr};


fn solve(n: u64) -> u64 {
    let i = (1..n + 1).rev().find(|i| i * i <= n).unwrap_or(1);
    i * i
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    println!("{}", solve(sc.next()));
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(1024),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        let buf = &mut self.buf;
        buf.clear();
        self.bytes
            .by_ref()
            .map(Result::unwrap)
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
            .foreach(|c| buf.push(c));
        str::from_utf8(&buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<T1: FromStr, T2: FromStr>(&mut self, n: usize) -> Vec<(T1, T2)>
    where
        <T1 as FromStr>::Err: fmt::Debug,
        <T2 as FromStr>::Err: fmt::Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<T1: FromStr, T2: FromStr, T3: FromStr>(&mut self, n: usize) -> Vec<(T1, T2, T3)>
    where
        <T1 as FromStr>::Err: fmt::Debug,
        <T2 as FromStr>::Err: fmt::Debug,
        <T3 as FromStr>::Err: fmt::Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        (0..m).map(|_| self.vec(n)).collect()
    }
}


trait Foreach {
    type Item;
    fn foreach<F: FnMut(Self::Item)>(self, f: F);
}

impl<T, I: Iterator<Item = T>> Foreach for I {
    type Item = T;

    fn foreach<F: FnMut(T)>(self, mut f: F) {
        self.fold((), move |(), x| f(x));
    }
}


#[allow(dead_code)]
fn print_yesno(x: bool, yes: &'static str, no: &'static str) {
    println!("{}", if x { yes } else { no });
}


#[allow(dead_code)]
fn print_foreach<T: fmt::Display, I: IntoIterator<Item = T>>(xs: I) {
    let stdout = io::stdout();
    let mut stdout = BufWriter::new(stdout.lock());
    for x in xs.into_iter() {
        writeln!(stdout, "{}", x).unwrap();
    }
    stdout.flush().unwrap();
}


#[allow(dead_code)]
fn print_or<T: fmt::Display>(x: Option<T>, or: &'static str) {
    if let Some(x) = x {
        println!("{}", x);
    } else {
        println!("{}", or);
    }
}
//  [rust]
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
	}

	let f = n as f64;
	let r = f.sqrt();
	let i = r as usize;
	println!("{}", i*i);
}
//  [python]
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7


def main():
    a = int(input())
    b = int(input())
    h = int(input())
    return (a+b) * h // 2




print(main())
//  [python]
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

a = i()
b = i()
h = i()
print((a+b)*h//2)
//  [python]
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

a = INT()
b = INT()
h = INT()
print((a + b) * h // 2)
//  [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 h = sc.nextInt();



		System.out.println(((a+b)*h)/2);


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


public class Main {


    public static void main(String[] args) throws IOException {
        MyScanner scanner = new MyScanner();
        PrintStream out = System.out;

        Main main = new Main();

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int h = scanner.nextInt();

        out.println( ((a + b)*h)/2  );

        scanner.reader.close();
        out.close();
    }

    // -----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader reader;

        public MyScanner() {
            this.reader = new BufferedReader(new InputStreamReader(System.in));
        }

        public void close() throws IOException {
            this.reader.close();
        }

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

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

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

        String next() {
            String str = "";
            try {
                str = this.reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        String[] nextStringArray() {
            String[] str = null;
            try {
                str = this.reader.readLine().trim().split(" ");
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] nextIntArray() {
            String[] data  = nextStringArray();
            int[] a  = new int[data.length];

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

            return a;
        }

        Integer[] nextIntegerArray() {
            String[] data  = nextStringArray();
            Integer[] a  = new Integer[data.length];

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

            return a;
        }

        long[] nextLongArray() {
            String[] data  = nextStringArray();
            long[] a  = new long[data.length];

            for (int i = 0; i < a.length; i++) {
                a[i] = Long.parseLong(data[i]);
            }

            return a;
        }
    }
}
//  [java]

import java.util.*;

//クラス名をMainに変える
public class Main {
	public static void main(String[] args) {

		// input
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int h = scan.nextInt();

		scan.close();

		int res = (a + b) * h / 2;

		// output
		System.out.println(res);
	}
}
//  [cpp]
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

int main()
{
	int a, b, h;
	cin >> a >> b >> h;

	cout << ((a + b) * h) / 2 << endl;

	return 0;
}
//  [cpp]
#include <iostream>
using namespace std;

int main(){
	int a,b,h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
}
//  [cpp]
#include <iostream>
using namespace std;

int main()
{
	int a,b,h;
	scanf("%d %d %d", &a, &b, &h);
	int area = (a+b) * h / 2;
	printf("%d\n", area);
}
//  [c]
#include<stdio.h>
int main()
{
    int a,b,c,area;
    scanf("%d%d%d",&a,&b,&c);
    area=(a+b)*c/2;
    printf("%d\n",area);
}
//  [c]
#include <stdio.h>
#include <stdlib.h>


int main() {
	int a, b, h;

	scanf("%d %d %d", &a, &b, &h);

	printf("%d\n", (a+b)*h/(2));

	return 0;
}
//  [c]
#include<stdio.h>
int main()
{
    int a,b,h,area;
    scanf("%d%d%d",&a,&b,&h);


        area=((a+b)*h)/2;



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

    return 0;
}
//  [javascript]
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const a = parseInt(arg[0].split(" ")[0]);
    const b = parseInt(arg[1].split(" ")[0]);
    const h = parseInt(arg[2].split(" ")[0]);
    
    console.log(((a + b) * h) / 2);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
'use strict'
 
function main(s) {
 
  s = s.split('\n').map(x => Number(x));
  const a = s[0];
  const b = s[1];
  const h = s[2];
 
  const area = ((a + b) * h) / 2
  console.log(area);
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main(input) {
  input = input.trim();
  const [a,b,c] = input.split('\n').map(Number);
  console.log((a+b)*c/2);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

import (
	"fmt"
)

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

	fmt.Println((a + b) * h / 2)
}
//  [go]
package main

import "fmt"

func main() {
	var a, b, h int
	fmt.Scan(&a, &b, &h)
	fmt.Println((a + b) * h / 2)
}
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b := intScanner(), intScanner()
	h := intScanner()
	fmt.Println((a + b) * h / 2)
}
//  [ruby]
p (gets.to_i+gets.to_i)*gets.to_i/2
//  [ruby]
a = gets.to_i
b = gets.to_i
h = gets.to_i
puts (a + b) * h / 2
//  [ruby]
a, b, h  = 3.times.map{gets.to_i}

def area (a,b,h)
    (a+b)*h/2
end

puts area(a,b,h)
//  [rust]
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
        h: usize,
    }
    println!("{}", (a+b)*h/2);
}
//  [rust]
#[allow(unused_imports)]
use std::io::Write;

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(non_snake_case)]
fn main() {
    input![a: usize, b: usize, h: usize];
    println!("{}", (a + b) * h / 2);
}
//  [rust]
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:isize,
    b:isize,
    c:isize,
    }
    println!("{}",(a+b)*c/2)
}
//  [swift]
import Foundation
 
var aa = readLine()!
var bb = readLine()!
var cc = readLine()!

var a = Int(aa)!
var b = Int(bb)!
var c = Int(cc)!


print((a+b)*c/2)
//  [swift]
let a: Int = Int(readLine()!)!
let b: Int = Int(readLine()!)!
let h: Int = Int(readLine()!)!

print((a + b) * h / 2)
//  [typescript]
import { readFileSync } from "fs";

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

const main = (input: string[][]) => {
  const a = Number(input[0][0]);
  const b = Number(input[1][0]);
  const h = Number(input[2][0]);

  return ((a + b) * h) / 2;
};

console.log(main(read()));
//  [typescript]
import * as fs from 'fs';

const inputs = fs.readFileSync('/dev/stdin', 'utf8').split(/\n/);

const calc = (a: number, b: number, h: number) => ((a + b) * h) / 2;

console.log(calc(+inputs[0], +inputs[1], +inputs[2]));
//  [typescript]
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8').split(/[ \n]/);

const a = +input.shift();
const b = +input.shift();
const h = +input.shift();

console.log(((a + b) * h) / 2);
//  [python]
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N, K = MAP()
S = input()

def searchRL(S):
    ans = []
    for i in range(N-1):
        if S[i] == "R" and S[i+1] == "L":
            ans.append(i)
    return ans

def searchLR(S):
    ans = []
    for i in range(N-1):
        if S[i] == "L" and S[i+1] == "R":
            ans.append(i)
    return ans

def reverse(S):
    S = list(S)
    for i in range(len(S)):
        if S[i] == 'L':
            S[i] = 'R'
        if S[i] == 'R':
            S[i] = 'L'
    return ''.join(S)


def solve(S):
    if len(RL) == 0 and len(LR) == 0:
        return S, 0
    if len(RL) == 0:
        S = reverse(S[LR[0]::-1]) + S[LR[0]+1:]
        LR.pop(0)
        return S, 1
    if len(LR) == 0:
        S = reverse(S[RL[0]::-1]) + S[RL[0]+1:]
        RL.pop(0)
        return S, 1
    fir = min(LR[0], RL[0])
    sec = max(LR[0], RL[0])
    S = S[:fir+1] + reverse(S[sec:fir:-1]) + S[sec+1:]
    LR.pop(0)
    RL.pop(0)
    return S, 2

def cal(S):
    ans = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            ans +=1
    return ans

RL = searchRL(S)
LR = searchLR(S)
ans = cal(S)
for i in range(K):
    S, res = solve(S)
    ans += res
print(ans)
//  [python]
n,k=map(int,input().split())
s = input()

ans = 0
count = k
ans = 0
for i in range(1,n-1):
    if s[i+1] in s[:i] and s[i] != s[i+1] and count > 0:
        count -=1
        j = i
        while s[j] != s[i+1]:
            if s[j] == 'R':
                s = s[:j] + 'L' + s[j+1:]
                j -=1
            elif s[j] == 'L':
                s = s[:j] + 'R' + s[j+1:]
                j-=1

if count > 0 and s != 'L'*n and s != 'R'*n:
    ans += 1

for i in range(1,n):
    if s[i] == s[i-1]:
        ans += 1

print(ans)
//  [python]
n,m = map(int,input().split())
s = str(input())
L = []
R = []

if s == "L"*n or s == "R"*n:
    print(n-1)
    exit()
now = "E"
ss = 0
for i in range(n):
    if s[i] != now:
        if s[i] == "R" and ss:
            L.append(ss)
        elif s[i] == "L" and ss:
            R.append(ss)
        ss = 1
        now = s[i]
    else:
        ss += 1
    if i == n-1:
        if s[i] == "R" and ss:
            R.append(ss)
        elif s[i] == "L" and ss:
            L.append(ss)
lis = []
ri = 0
li = 0
if s[0] == "R":
    key = 0
else:
    key = 1
for i in range(len(R)+len(L)):
    if key == 0:
        lis.append(R[ri])
        ri += 1
        key = 1
    else:
        lis.append(L[li])
        li += 1
        key = 0


if len(lis) == 2:
    print(sum(lis)-1)
    exit()

m-=1
ans = 0

for i in range(3):
    ans += lis.pop(0)
for i in range(m):
    try:
        ans += lis.pop(0)
    except:
        continue
    try:
        ans += lis.pop(0)
    except:
        continue
ans -= 1
for nu in lis:
    ans += nu-1
print(ans)
//  [java]
import java.util.*;
import java.util.regex.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		s.next();
		int k=s.nextInt();
		Matcher m=Pattern.compile("(.)\\1*").matcher(s.next());
		List<Integer>l=new ArrayList<>();
		while(m.find())
			l.add(m.group().length());
		System.out.println(l.stream().mapToInt(i->i-1).sum()+Math.min(k*2,l.size()-1));
	}
}
//  [java]
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String[] info=sc.nextLine().split(" ");
		Integer n=Integer.valueOf(info[0]);
		Integer k=Integer.valueOf(info[1]);
		List<Character> line=Arrays.asList(sc.nextLine().split(""))
				.stream().map(s->s.charAt(0)).collect(Collectors.toList());
		int happy=0;
		for(int i=0;i<n-1;i++) {
			if(line.get(i)==line.get(i+1)) {
				happy++;
			}
		}
		System.out.println(Integer.min(happy+2*k, n-1));
	}
}
//  [cpp]
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
signed main(){
  ll n,k,tk,l,r,len,tmp,ans;
  string s,ts;
  ans=0;
  char ch;
  cin >> n >> k>>s;
  vector<ll> seg;
  vector<ll> ls;
  ch=s[0];
  len=1;
  for(int i=1;i<n;i++){
    if(s[i]!=ch){
      ch=s[i];
      seg.push_back(len);
      len=1;
    }else{
      len++;
    }
  }
      seg.push_back(len);
  while(k!=0){
    if(seg.size()==1){
      break;
    }else if(seg.size()==2){
      seg[0]+=seg[1];
      seg.erase(seg.begin()+1);
      k--;
      break;
    }else{
      seg[1]+=seg[0]+seg[2];
      seg.erase(seg.begin()+2);
      seg.erase(seg.begin());
      k--;
    }
  }
  for(int i=0;i<seg.size();i++){
    ans+=seg[i]-1;
  }
  cout << ans << endl;
}
//  [cpp]
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
    int n,k;
    cin>>n>>k;
	string s;
	cin>>s;
	vector<int> vec;
	rep(i,0,n){
		if(k==0)break;
		int j=i+1;
		while(j<n&&s[i]==s[j])j++;
		if(j==n)break;
		int p=j+1;
		s[j]=s[i];
		while(p<n&&s[j]!=s[p]){
			s[p]=s[j];
			p++;
		}
		k--;
	}
	int cnt=0;
	rep(i,0,n-1){
		if(s[i+1]==s[i])cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}
//  [cpp]
#include <iostream>
#include <string>

using namespace std;
string s;

void revert(int begin, int end)
{
    for (int i = end; i <= begin; i++)
    {
        if (s[i] == 'L')
            s[i] = 'R';
        else
            s[i] = 'L';
    }
}

void cal(int N, int *K, int *num)
{
    int f_begin, begin, end;
    f_begin = begin = N - 2;
    while ((*K) > 0 && f_begin > 0)
    {
        for (; begin > 0 && s[begin] == s[N - 1]; begin--)
            ;
        for (end = begin - 1; end > 0 && s[end] != s[begin]; end--)
            ;
        for (; end > 0 && s[end] == s[begin] && s[end - 1] == s[begin]; end--)
            ;

        if (end > 0)
        {
            revert(begin, end);
            (*K)--;
            begin = end - 2;
        }
        else
        {
            for (f_begin = f_begin - 1; f_begin > 0 && s[f_begin] == s[N - 1]; f_begin--)
                ;
            begin = f_begin;
        }
    }
}

int main()
{
    int N, K, num = 0;
    char t;

    cin >> N >> K;
    cin >> s;

    cal(N, &K, &num);

    if (N > 1)
    {
        if (K > 0 && s[1] == s[N - 1])
        {
            for (int i = 2; i < N; i++)
                if (s[i] != s[N - 1])
                {
                    s[i] = s[N - 1];
                    K--;
                    break;
                }
        }
        if (K > 0 && s[0] != s[N - 1])
        {
            int i;
            for (i = 1; s[i] == s[0]; i++)
                ;
            revert(i - 1, 0);
            K--;
        }
        if (K > 0 && s[1] != s[N - 1])
        {
            s[1] = s[N - 1];
            K--;
        }
    }

    for (int i = 0; i < N - 1; i++)
    {
        if (s[i + 1] == s[i])
            num++;
    }

    cout<< num << endl;

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

int main(void)
{
  int n, k;
  scanf("%d %d", &n, &k);
  char s[n + 1];
  scanf("%s", s);
  
  for (int i = 0; i < k; i++){
    int j = 1;
    while (j < n){
      if (s[0] == s[j]) j++;
      else break;
    }
    if (j == n){
      printf("%d\n", n - 1);
      return 0;
    }
    
    int l = j + 1;
    while (l < n){
      if (s[j] == s[l]) l++;
      else break;
    }
    
    int len = l - j;
    for (int m = 1; m <= len; m++){
      s[j + m - 1] = s[j - 1];
    }
  }
  
  int sum = 0;
  for (int i = 1; i < n; i++){
    if (s[i] == s[i - 1]) sum++;
  }
  
  printf("%d", sum);
  return 0;
}
//  [c]
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//abc140D
int main(void) {
  int n, i=0, j=0, k=0, len=0, lmax=0,c=0;
  char sx;
  scanf("%d %d", &n, &k);
  int s[n];
  for(i=0; i < n; i++){
    scanf(" %c", &sx);
    if(sx == 'L') s[i]=0;
    else s[i]=2;
    //printf("%d",s[i]);
  }

  //printf("\n");

  for(i=0; i < n; i++){ //s: 0 LUnhappy,1 LHappy,2 RU,3 RH
    if(s[i] == 0 && i != 0 && s[i - 1] <= 1) s[i]=1;
    else if(s[i] == 2 && i != n - 1 && s[i + 1] >= 2) s[i]=3;
    if(s[i]==1||s[i]==3)c++;
    //printf("%d",s[i]);
  }
  if(c+2*k<n)printf("%d",c+2*k);
  else printf("%d",n-1);


  return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
char s[100010];
int a[100010];
int main()
{
	int n, k;
	int d = 0;
	scanf("%d", &n);
	scanf("%d\n", &k);
	gets(s);
	int i,  c;
	int b;
	int l;
	memset(a, 0, sizeof(a));
	b = 0;
	c = 0;
	i = 0;
	while (i < n-1)
	{
		if (s[i] != s[i + 1])
		{
			a[b] = i + 1;
			if ((b>0)&&((b%2)!=0))
			{
				d = a[b-1];
				while (d < a[b])
				{
					s[d] = s[d - 1];
					d++;
				}
				c++;
				if (c >= k)
					break;
			}
			b++;
		}
		i++;
	}
	if (c < k)
	{
		d = a[b - 1];
		while (d < n)
		{
			s[d] = s[d - 1];
			d++;
		}

	}
	d = 0;
	l = 0;
	while (d < n - 1)
	{
		if (s[d] == s[d + 1])
			l++;
		d++;
	}
	printf("%d\n", l);
	return 0;
}
//  [javascript]
'use strict';

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function main(lines) {
  var _lines$0$split$map = lines[0].split(' ').map(Number),
      _lines$0$split$map2 = _slicedToArray(_lines$0$split$map, 2),
      N = _lines$0$split$map2[0],
      K = _lines$0$split$map2[1];

  var S = lines[1];
  var s = shorten(S); // console.log(s);

  for (var i = 0; i < K; i++) {
    if (s.length === 1) break;
    s = s[0] + s.slice(3); // console.log(s);
  }

  var happiness = N - s.length;
  console.log(happiness);
}

function shorten(s) {
  var len = s.length;

  for (var i = 0; i < len;) {
    if (i !== len - 1 && s[i] === s[i + 1]) {
      s = s.slice(0, i + 1) + s.slice(i + 2);
      len--;
    } else {
      i++;
    }
  }

  return s;
}

function calcHappiness(s) {
  return s.length - shorten(s).length;
}

function runWithStdin() {
  var input = "";
  process.stdin.resume();
  process.stdin.setEncoding("utf8");
  process.stdin.on("data", function (v) {
    input += v;
  });
  process.stdin.on("end", function () {
    main(input.split("\n"));
  });
}

runWithStdin();
//  [javascript]
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + end + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException ‚There is no more input";}else{var returnInput = this.list[this.index++];return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var K = one[1];
  var list = nextCharArray();
  var rl = 0;
  var count = 0;
  for(var i = 0; i < N - 1; i++){
    if(list[i] == list[i + 1]){
      count++;
    }else if(list[i] == "R" && list[i + 1] == "L"){
      rl++;
    }
  }
  
  
  myout(Math.min(count + K * 2, N - 1));
}
//  [javascript]
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
line = lines.shift().split(' ')
N = line[0] * 1
K = line[1] * 1 
S = lines.shift()

cnt = 0
s = S[0]
for (i=1; i<N; i++) {
    if (s != S[i]) {
        cnt++
        s = S[i]
    }
}

d = cnt - 2 * K
if (d < 1) {
    d = 0
}

console.log(N - 1 - d)
//  [go]
package main

import (
	"container/list"
	"fmt"
)

func main() {
	var n, k int
	var s string
	fmt.Scan(&n, &k, &s)

	itemList := list.New()
	cur := &Item{s: s[0], cnt: 1}
	itemList.PushBack(cur)

	for i := 1; i < n; i++ {
		if cur.s == s[i] {
			cur.cnt++
		} else {
			cur = &Item{s: s[i], cnt: 1}
			itemList.PushBack(cur)
		}
	}

	// fmt.Println(listToString(itemList))
	// dumpList(itemList)

	ce := itemList.Front()
	for e := ce.Next(); e != nil; e = ce.Next() {
		item1 := ce.Value.(*Item)
		item2 := e.Value.(*Item)
		item1.cnt += item2.cnt
		itemList.Remove(e)

		e3 := ce.Next()
		if e3 != nil {
			item3 := e3.Value.(*Item)
			item1.cnt += item3.cnt
			itemList.Remove(e3)
		}

		k--
		if k == 0 {
			break
		}
	}

	// fmt.Println(listToString(itemList))
	// dumpList(itemList)

	ans := 0
	for e := itemList.Front(); e != nil; e = e.Next() {
		item := e.Value.(*Item)
		ans += item.cnt - 1
	}
	fmt.Println(ans)
}

// Item .
type Item struct {
	s   byte
	cnt int
}

func dumpList(l *list.List) {
	for e := l.Front(); e != nil; e = e.Next() {
		it := e.Value.(*Item)
		fmt.Printf("{%s%d} ", string(it.s), it.cnt)
	}
	fmt.Println()
}

func listToString(l *list.List) string {
	s := ""
	for e := l.Front(); e != nil; e = e.Next() {
		item := e.Value.(*Item)
		for i := 0; i < item.cnt; i++ {
			s += string(item.s)
		}
	}

	return s
}
//  [go]
package main

import (
	"container/list"
	"fmt"
)

func main() {
	var N, K int
	var S string
	fmt.Scan(&N, &K)
	fmt.Scan(&S)

	l := list.New()
	l.PushBack(S[0:1])
	for i := 1; i < N; i++ {
		if l.Back().Value != S[i:i+1] {
			l.PushBack(S[i : i+1])
		}
	}
	s := l.Len()
	for i := 0; i < K; i++ {
		if 3 <= s {
			s -= 2
		} else if s == 2 {
			s = 1
		}
	}
	fmt.Println(N - s)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	var s []byte
	fmt.Scan(&s)
	p := s[0]
	cnt := 1
	var ans int
	for i := 1; i < n; i++ {
		if s[i] != p {
			cnt++
		} else {
			ans++
		}
		p = s[i]
	}
	if cnt == 1 {
		fmt.Println(ans)
		return
	}
	cnt -= 2
	if cnt%2 == 1 {
		ans += min((cnt+1)/2, k) * 2
	} else {
		if k >= cnt/2 {
			ans += cnt / 2 * 2
			if k-cnt/2 > 0 {
				ans++
			}
		} else {
			ans += k * 2
		}
	}
	fmt.Println(ans)
}

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

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
//  [ruby]
n,k = gets.chomp.split.collect{ |item| item.to_i}
s = gets.chomp
s.insert(0,"R")
s += "L"

def check(arr,i)
  if(arr[i] == "R")
  return (arr[i] == arr[i+1])
  else
    return (arr[i] == arr[i-1])
  end
end

ans = n
badn = 0
1.upto(n) do |ni|
  badn += 1 if check(s,ni) == false
end
ans -= [1,(badn - 2*k)].max

puts ans
//  [ruby]
n,k = gets.chomp.split.collect{ |item| item.to_i}
s = gets.chomp
s.insert(0,"R")
s += "L"
 
ans = n
badn = 0
1.upto(n) do |i|
  if(s[i] == "R")
  	badn += 1 if (s[i] != s[i+1])
  else
    badn += 1 if (s[i] != s[i-1])
  end
end
ans -= [1,(badn - 2*k)].max
 
puts ans
//  [ruby]
(n,k)=gets.split.map(&:to_i)
s=gets.chars


lr= s.each_cons(2).select{|ss| ss==["L","R"] }.size
rl= s.each_cons(2).select{|ss| ss==["R","L"] }.size
h0=s.each_cons(2).select{|a,b| a==b }.size

p h0+[lr,k].min + [rl,k].min
//  [python]
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n = int(input())
    aa = LI()
    cnt = [0] * 100005
    for a in aa:
        cnt[a] += 1

    ans = s = sum(cnt[:3])
    for x in range(100000):
        s += cnt[x + 3] - cnt[x]
        if s > ans: ans = s

    print(ans)

main()
//  [python]
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    count = [0]*100000

    for i in a:
        count[i] += 1

    print(max(map(sum,zip(count,count[1:],count[2:]))))


if __name__ == '__main__':
    solve()
//  [python]
def main():
  import sys
  input = sys.stdin.readline
  n=input()
  a=tuple(map(int,input().split()))
  cnt=[0]*(max(a)+3)
  for i in a:
    cnt[i]+= 1
  x,y,z=cnt,cnt[1:],cnt[2:]
  print(max(map(sum,zip(x,y,z))))  
if __name__=='__main__':
  main()
//  [python]
# encoding: "utf-8"

from collections import defaultdict

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def count_and_del(xs):
    cnt = 0
    fst = xs[0]
    # cnt = xs.count(fst)
    for x in xs:
        if x != fst:
            break
        cnt += 1
    del xs[:cnt]
    return cnt   

def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort()
    ys = defaultdict(int)
    while xs:
        key = xs[0]
        cnt = count_and_del(xs)
        ys[key] += cnt
        ys[key-1] += cnt
        ys[key+1] += cnt

    print(max(ys.values()))


if __name__ == "__main__":
    main()
//  [python]
# encoding: "utf-8"

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def count_and_drop(xs):
    cnt = 0
    key = xs[0]
    for x in xs:
        if x != key:
            break
        cnt += 1
    del xs[:cnt]
    return (key, cnt)


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort()
    ys = dict()
    while xs:
        key, cnt = count_and_drop(xs)
        ys[key] = cnt
    m = 0
    for x in ys.keys():
        temp = ys.get(x-1, 0) + ys.get(x, 0) + ys.get(x+1, 0)
        if m < temp:
            m = temp
    print(m)

if __name__ == "__main__":
    main()
//  [python]
import numpy as np
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

ans = 0
counter = Counter(A)
for a, cnt in counter.most_common():
    tmp = counter[a-1] + cnt + counter[a+1]
    if ans < tmp:
        ans = tmp
        

print(ans)
//  [java]
import java.util.*;
import java.io.*;

public class Main {
	
	public static void main (String[] args) {
	   InputReader in = new InputReader(System.in);
	   int n = in.readInt();
	   int arr[] = new int[100003];
	   for(int i = 0; i<n; i++) {
		   int a = in.readInt();
		   if(a != 0) {
			  arr[a-1]++; 
		   }
			   arr[a]++;  
			   arr[a+1]++;
	   }
	   int max = 0; 
	   for(int i : arr) {
		 max = Math.max(max, i);
	   }
	   System.out.println(max);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}
//  [java]
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {

    private final static Scanner sc = new Scanner(System.in);

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        int n = nextInt();
        Map<Integer, Integer> highMap = new HashMap<>(n);
        Map<Integer, Integer> lowMap = new HashMap<>(n);
        Map<Integer, Integer> origMap = new HashMap<>(n);

        for (int i = 0; i < n; i++) {
            int a = nextInt();
            int high = a + 1;
            int low = a - 1;

            putCountMap(highMap, high);
            putCountMap(lowMap, low);
            putCountMap(origMap, a);
        }

        Map<Integer, Integer> mergeMap = Stream.of(highMap, lowMap, origMap)
                .flatMap(m -> m.entrySet().stream())
                .collect(Collectors.toMap(Entry::getKey, Entry::getValue, Integer::sum));

        // マージされたマップを降順ソート
        List<Entry<Integer, Integer>> mergeEntry = new ArrayList<Entry<Integer, Integer>>(mergeMap.entrySet());
        valueReverseSort(mergeEntry);

        out(mergeEntry.get(0).getValue());
    }

    private static void valueReverseSort(List<Entry<Integer, Integer>> highEntry) {
        Collections.sort(highEntry, new Comparator<Entry<Integer, Integer>>() {
            //compareを使用して値を比較する
            public int compare(Entry<Integer, Integer> obj1, Entry<Integer, Integer> obj2)
            {
                //降順
                return obj2.getValue().compareTo(obj1.getValue());
            }
        });
    }

    private static void putCountMap(Map<Integer, Integer> map, int value) {
        if (map.containsKey(value)) {
            map.put(value, map.get(value) + 1);
        } else {
            map.put(value, 1);
        }
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt() {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString() {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt();
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }
}
//  [java]
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int val = scanner.nextInt();
            int val1 = val + 1;
            int val2 = val - 1;
            int count = map.getOrDefault(val , 0) + 1;
            map.put(val, count);
            int count1 = map.getOrDefault(val1 , 0) + 1;
            map.put(val1, count1);
            int count2 = map.getOrDefault(val2 , 0) + 1;
            map.put(val2, count2);
        }

        List<Map.Entry<Integer, Integer>> list = new ArrayList<>(map.entrySet());
        list.sort((e1,e2) -> e2.getValue() - e1.getValue());
        System.out.println(list.get(0).getValue());
    }
}
//  [java]
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {


	static Map<Integer, Integer> map = new HashMap<>();
	
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		int length = scanner.nextInt();
		for(int i = 0; i < length; i++) {
			int t = scanner.nextInt();
			increment(t - 1);
			increment(t);
			increment(t + 1);
		}
		int max = map.entrySet().stream()
			.max(Comparator.comparingInt(m -> m.getValue()))
			.get().getValue();

		System.out.println(max);
	}
	
	public static void increment(int key) {
		map.put(key, map.getOrDefault(key, 0) + 1);
	}
}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int A[100010];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();
	rep(i, N) A[getint()]++;
	int saidai = 0;
	rep1(i, 99998) {
		chmax(saidai, A[i - 1] + A[i] + A[i + 1]);
	}
	printf("%d", saidai);

	Would you please return 0;
}