Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

// 文字列を1行取得
func StrStdin() (stringReturned string) {
//	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	stringInput := scanner.Text()

	stringReturned = strings.TrimSpace(stringInput)
	return
}

// 整数値1つ取得
func IntStdin() (int, error) {
	stringInput := StrStdin()
	return strconv.Atoi(strings.TrimSpace(stringInput))
}

// 空白や空文字だけの値を除去したSplit()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
	stringSplited := strings.Split(stringTargeted, delim)

	for _, str := range stringSplited {
		if str != "" {
			stringReturned = append(stringReturned, str)
		}
	}

	return
}

// デリミタで分割して文字列スライスを取得
func SplitStrStdin(delim string) (stringReturned []string) {
	// 文字列で1行取得
	stringInput := StrStdin()

	// 空白で分割
	// stringSplited := strings.Split(stringInput, delim)
	stringReturned = SplitWithoutEmpty(stringInput, delim)

	return
}

// デリミタで分割して整数値スライスを取得
func SplitIntStdin(delim string) (intSlices []int, err error) {
	// 文字列スライスを取得
	stringSplited := SplitStrStdin(" ")

	// 整数スライスに保存
	for i := range stringSplited {
		var iparam int
		iparam, err = strconv.Atoi(stringSplited[i])
		if err != nil {
			return
		}
		intSlices = append(intSlices, iparam)
	}
	return
}

func main() {
	nk, _ := SplitIntStdin(" ")
	n, k := nk[0], nk[1]
	kind := make([]int, n)
	for i := 0; i < k; i++ {
		var tmp []int
		var err error
		if tmp, err = SplitIntStdin(" "); err != nil {
			panic(err)
		}
		kind[tmp[0]-1] = tmp[1]
	}
	dp := make([][3][3]int, n)
	if kind[0] > 0 {
		dp[0][0][kind[0]-1] = 1
	} else {
		for i := 0; i < 3; i++ {
			dp[0][0][i] = 1
		}
	}
	if kind[1] > 0 {
		for i := 0; i < 3; i++ {
			dp[1][i][kind[1]-1] = dp[0][0][i]
		}
	} else {
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				dp[1][i][j] = dp[0][0][i]
			}
		}
	}
	for i := 1; i < n-1; i++ {
		if kind[i+1] > 0 {
			for j := 0; j < 3; j++ {
				if j == kind[i+1]-1 {
					for k := 0; k < 3; k++ {
						if j != k {
							dp[i+1][j][kind[i+1]-1] += dp[i][k][j]
							dp[i+1][j][kind[i+1]-1] %= 10000
						}
					}
				} else {
					for k := 0; k < 3; k++ {
						dp[i+1][j][kind[i+1]-1] += dp[i][k][j]
						dp[i+1][j][kind[i+1]-1] %= 10000
					}
				}
			}
		} else {
			for j := 0; j < 3; j++ {
				for k := 0; k < 3; k++ {
					for l := 0; l < 3; l++ {
						if j != k || k != l {
							dp[i+1][k][j] += dp[i][l][k]
							dp[i+1][k][j] %= 10000
						}
					}
				}
			}
		}
	}
	result := 0
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			result += dp[n-1][i][j]
		}
	}
	// fmt.Println(dp)
	// fmt.Println(kind)
	fmt.Println(result % 10000)
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int N, K;
int memo[101][3][3];
int p_fixed[100];
int mod = 10000;

int pasta(int n, int y2, int y1) {
	if (memo[n][y2][y1] > -1) return memo[n][y2][y1];

	if (p_fixed[n-1] > -1 && p_fixed[n-1] != y1) return memo[n][y2][y1] = 0;
	if (p_fixed[n-2] > -1 && p_fixed[n-2] != y2) return memo[n][y2][y1] = 0;
	if (n == N) return memo[n][y2][y1] = 1;
	
	memo[n][y2][y1] = 0;
	REP(i, 3) if (! (y2 == y1 && y1 == i)) memo[n][y2][y1] += pasta(n + 1, y1, i);

	return memo[n][y2][y1] %= mod;
}

int main() {
	fill(memo[0][0], memo[101][0], -1);
	fill(p_fixed, p_fixed + 100, -1);

	cin >> N >> K;
	REP(i, K) {
		int a, b;
		scanf("%d %d", &a, &b);
		p_fixed[a - 1] = b - 1;
	}

	int ans = 0;
	REP(i, 3) REP(j, 3) ans += pasta(2, i, j);

	cout << ans % mod << endl;
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

struct Clothes {
	int a, b, c;
};

int main() {
	int dp[201][200] = {};
	int d, n, mt[200];
	Clothes clothes[200];

	cin >> d >> n;
	REP(i, d) scanf("%d", &mt[i]);
	REP(i, n) scanf("%d %d %d", &clothes[i].a, &clothes[i].b, &clothes[i].c);
	
	REP(i, d - 1) {
		REP(j, n) {
			if (clothes[j].a > mt[i] || clothes[j].b < mt[i]) continue;
			REP(k, n) {
				if (clothes[k].a > mt[i+1] || clothes[k].b < mt[i+1]) continue;
				dp[i+1][k] = max(dp[i+1][k], dp[i][j] + abs(clothes[k].c - clothes[j].c));
			}
		}
	}

	int ans = 0;
	REP(i, n) ans = max(ans, dp[d - 1][i]);
	cout << ans << endl;

	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

#define reps(i,f,n) for(int i=0;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int main(void){
	int dp[101][3][3]={0};
	
	int n,m;
	cin>>n>>m;
	
	int plan[101]={0};
	rep(i,101)plan[i]=-1;
	
	rep(i,m){
		int a,b;
		cin>>a>>b;
		plan[a]=b-1;
	}
	
	dp[0][0][0]=1;
	rep(i,n){
		rep(j,3){
			rep(k,3){
				rep(p,3){
					if(i>=2 && j==k && k==p)continue;
					if(plan[i+1]!=-1 && plan[i+1]!=p)continue;
					dp[i+1][p][k] += dp[i][k][j];
					dp[i+1][p][k] %= 10000;
				}
			}
		}
	}
	
	/*
	puts("--0--  --1--  --2-- <<=bef");
	puts("0 1 2  0 1 2  0 1 2 <<=bef bef");
	puts("");
	
	reps(i,1,n+1){
		rep(j,3){
			rep(k,3){
				printf("%d ",dp[i][j][k]);
			}printf(" ");
		}puts("");
	}*/
	
	int ans=0;
	rep(j,3){
		rep(k,3){
			ans += dp[n][j][k];
			ans %= 10000;
		}
	}
	
	printf("%d\n",ans);
}

C++: #include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pb push_back

using namespace std;

int N, K;
int t[101];
bool b[101];
int nCount = 0;

void fill(int i) {
	if (i > 1) { if (((t[i] == t[i - 1]) && t[i] == t[i - 2])) return; }
	if (b[i]) { fill(i + 1); return; }
	if (i == N) {
		nCount++;
		//cout << t[0] << t[1] << t[2] << t[3] << t[4] << endl;
		return;
	}
	loop(k, 1, 4) {
		t[i] = k;
		if (i > 1) { if (!((t[i] == t[i - 1]) && t[i] == t[i - 2])) fill(i + 1); }
		else fill(i + 1);
	}
}

int main() {
	//freopen("0568.inp", "r", stdin);
	cin >> N >> K;
	memset(b, 0, sizeof(b));
	loop(i, 0, K) {
		int A, B; cin >> A >> B;
		t[A - 1] = B;
		b[A - 1] = true;
	}
	fill(0);
	cout << nCount;
}