A - Triple Four
Source: atcoder
Difficulty: 100

Problem Statement
You are given an integer sequence of length
N
:
A = (A_1,A_2,\ldots,A_N)
.
Determine whether there is a place in
A
where the same element appears three or more times in a row.
More formally, determine whether there exists an integer
i
with
1 \le i \le N-2
such that
A_i = A_{i+1} = A_{i+2}
.
Constraints
3 \le N \le 100
1 \le A_i \le 100
All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
A_2
\ldots
A_N
Output
If there is a place in
A
where the same element appears three or more times in a row, print
Yes
. Otherwise, print
No
.
Sample Input 1
5
1 4 4 4 2
Sample Output 1
Yes
We have
A=(1,4,4,4,2)
. There is a place where
4
appears three times in a row, so print
Yes
.
Sample Input 2
6
2 4 4 2 2 4
Sample Output 2
No
We have
A=(2,4,4,2,2,4)
. There is no place where the same element appears three or more times in a row, so print
No
.
Sample Input 3
8
1 4 2 5 7 7 7 2
Sample Output 3
Yes
Sample Input 4
10
1 2 3 4 5 6 7 8 9 10
Sample Output 4
No
Sample Input 5
13
1 1 1 1 1 1 1 1 1 1 1 1 1
Sample Output 5
Yes

C++ solution:
#include<iostream>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<numeric>
#include<array>
#include<cstring>
#include<unordered_set>
#include<iomanip>
#include<set>
using namespace std;
using ll = long long;
using u64 = unsigned long long;
using u32 = unsigned;

//#define int long long
const int MAX_INT = 2147483647;
const ll MAX_LL = 9223372036854775807;
signed main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin >> n;
    bool ok = 0;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i + 2 < n; i++){
        if(a[i] == a[i + 1] && a[i + 1] == a[i + 2]) ok = 1;
    }
    cout << (ok ? "Yes" : "No") << '\n';
    return 0;
}

Go solution:
package main

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

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func main() {
	defer flush()

	n := ni()
	a := nis(n)

	for i := 0; i < n-2; i++ {
		if a[i] == a[i+1] && a[i+1] == a[i+2] {
			out("Yes")
			return
		}
	}

	out("No")
}

func init() {
	scanner.Buffer([]byte{}, math.MaxInt64)
	scanner.Split(bufio.ScanWords)
}

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

func nis(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ni()
	}
	return a
}

func out(v ...interface{}) {
	_, e := fmt.Fprintln(writer, v...)
	if e != nil {
		panic(e)
	}
}

func flush() {
	e := writer.Flush()
	if e != nil {
		panic(e)
	}
}

func min(values ...int) int {
	ret := values[0]
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max(values ...int) int {
	ret := values[0]
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

// type compFunc func(p, q interface{}) bool

// type pq struct {
// 	arr  []interface{}
// 	comp compFunc
// }

// func newpq(comp compFunc) *pq {
// 	return &pq{
// 		comp: comp,
// 	}
// }

// func (pq pq) Len() int {
// 	return len(pq.arr)
// }

// func (pq pq) Swap(i, j int) {
// 	pq.arr[i], pq.arr[j] = pq.arr[j], pq.arr[i]
// }

// func (pq *pq) Push(x interface{}) {
// 	pq.arr = append(pq.arr, x)
// }

// func (pq *pq) Pop() interface{} {
// 	n := pq.Len()
// 	item := pq.arr[n-1]
// 	pq.arr = pq.arr[:n-1]
// 	return item
// }

// func (pq pq) Less(i, j int) bool {
// 	return pq.comp(pq.arr[i], pq.arr[j])
// }

Java solution:
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i = 0; i < N; i ++){
		  list.add(sc.nextInt());
		}
		for(int i = 0; i < N - 2; i ++){
		  if(list.get(i) == list.get(i + 1) && list.get(i) == list.get(i + 2)){
		    System.out.println("Yes");
		    return;
		  }
		}
		System.out.println("No");
	}
}

JavaScript solution:
function main(input){
  inputArray = input.split("\n");
  inputLength = inputArray[0];
  inputNumbers = inputArray[1].split(" ");
  
  for (let i = 0; i < inputLength - 2; i++){
    if (inputNumbers[i] === inputNumbers[i+1] && inputNumbers[i+1] === inputNumbers[i+2]){
      console.log('Yes');
      return;
    }
  }
  console.log('No');
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Python solution:
n = int(input())
a = list(map(int, input().split()))
for i in range(n - 2):
    if a[i] == a[i+1] == a[i+2]:
        print("Yes")
        exit()
print("No")

Ruby solution:
def has_three_consecutive?(array)
  # 長さが3未満なら連続する3つの要素は存在しない
  return false if array.size < 3

  # 配列を走査し、連続する3つの要素を確認
  (0..array.size - 3).each do |i|
    # 現在の要素と次の2つの要素が等しいかチェック
    if array[i] == array[i + 1] && array[i + 1] == array[i + 2]
      return true
    end
  end

  # どの箇所にも連続する3つの要素がない場合
  false
end

# 入力の読み取り
n = gets.to_i
a = gets.split.map(&:to_i)

# 結果の判定と出力
if has_three_consecutive?(a)
  puts "Yes"
else
  puts "No"
end