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>
using namespace std;
long long int unco[105][4][4];
int deta[10125];
int main() {
	int n, k;
	long long int unchi = 0;
	cin >> n >> k;
	for (int i = 0; i < k; i++){
		int x, y;
		cin >> x >> y;
		deta[x] = y;
	}
	unco[0][0][0] = 1;
	for(int hi = 0; hi <= n; hi++) {
		for(int one = 0; one <= 3; one++){
			for(int two = 0; two <= 3; two++) {
				if(deta[hi]) {
					if(!(deta[hi] == one && one == two)) {
						unco[hi][deta[hi]][one] += unco [hi - 1][one][two];
						unco[hi][deta[hi]][one] %= 10000;
					}
				}
				else {
					for(int l = 1; l <= 3; l++) {
						if(!(l == one && one == two)) {
							unco[hi][l][one] += unco[hi - 1][one][two];
							unco[hi][l][one] %= 10000;
						}
					}
				}
			}
		}
	}
	for(int i = 1; i<=3; i++){
		for(int j = 1; j<=3; j++){
			unchi += unco[n][i][j];
			unchi %= 10000;
		}
	}
	cout << unchi % 10000<<endl;
	return 0;
}

C++: #include <iostream>
#include <string.h>
using namespace std;

int dp[101][4][4];//何日目から、どのぱすたを、何日連続で食べているか
int plan[101];//先に決められている予定　要素：日付

#define MOD 10000;

int main(void)
{
		int day;
		int k;
		cin >> day >> k;
		memset(plan,0,sizeof(plan));
		for(int i=0;i<k;++i){
			int d,p;
			cin >> d >> p;
			plan[d] = p;
		}
		memset(dp,0,sizeof(dp));

		for(int i=1;i<=3;++i){
			if(plan[1] != 0)
				dp[1][plan[1]][1] = 1;
			else
				dp[1][i][1] = 1;
		}

		for(int d=2;d<=day;++d){//どの日から？
			for(int p=1;p<=3;++p){//どのパスタを？
				if(plan[d]){
					dp[d][plan[d]][1] = (dp[d-1][(plan[d]+1)%3+1][1] + dp[d-1][(plan[d]+1)%3+1][2] + dp[d-1][plan[d]%3+1][1] + dp[d-1][plan[d]%3+1][2])%MOD;
					dp[d][plan[d]][2] = dp[d-1][plan[d]][1] % MOD;
				}
				else{
					dp[d][p][1] = (dp[d-1][(p+1)%3+1][1] + dp[d-1][(p+1)%3+1][2] + dp[d-1][p%3+1][1] + dp[d-1][p%3+1][2])%MOD;
					dp[d][p][2] = dp[d-1][p][1] % MOD;
				}
			}
		}
		int ans = (dp[day][1][1] + dp[day][2][1] + dp[day][3][1] + dp[day][1][2] + dp[day][2][2] + dp[day][3][2])%MOD;
		cout << ans << endl;
	return 0;
}

C++: #include<iostream>
using namespace std;

#define f1 for(int x1=0;x1<3;x1++)
#define f2 for(int x2=0;x2<3;x2++)
#define f3 for(int x3=0;x3<3;x3++)

int main()
{
	int n, k, a, b, p[100];
	int c1[3][3][3], c2[3][3][3];

	cin >> n >> k;
	for (int i = 0; i < n; i++){
		p[i] = 0;
	}
	for (int i = 0; i < k; i++){
		cin >> a >> b;
		p[a - 1] = b;
	}

	for (int i = 0; i < n - 2; i++){
		if (!i){
			f1{ f2{ f3{
				c1[x1][x2][x3] = 1;
			} } }
		}
		else{
			int sum = 0;
			f1{ f2{
				f3{ sum +=c2[x3][x1][x2]; }
				f3{ c1[x1][x2][x3] = sum; }
				sum = 0;
			} }
		}

		f1{ c1[x1][x1][x1] = 0; }

		if (p[i]){
			f1{ f2{ f3{
				if (p[i] != x1+1){ c1[x1][x2][x3] = 0; }
			} } }
		}
		if (p[i + 1]){
			f1{ f2{ f3{
				if (p[i + 1] != x2+1){ c1[x1][x2][x3] = 0; }
			} } }
		}
		if (p[i + 2]){
			f1{ f2{ f3{
				if (p[i + 2] != x3+1){ c1[x1][x2][x3] = 0; }
			} } }
		}

		f1{ f2{ f3{
			c2[x1][x2][x3] = c1[x1][x2][x3];
			c2[x1][x2][x3] %= 10000;
		} } }
	}

	int total=0;

	f1{ f2{ f3{
		total += c2[x1][x2][x3];
	} } }

	cout << total%10000<< endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int dp[101][5][5][5],b[101],x,y,ans,n,m;
main(){
	cin>>n>>m;
	r(i,m){
		cin>>x>>y;
		b[x-1]=y;
	}
	dp[0][0][0][0]=1;
	r(i,n){
		if(b[i]){
			r(j,3)r(k,3)r(l,3)if(dp[i][j][k][l])
				if(b[i]==1)dp[i+1][j+1][0][0]+=dp[i][j][k][l];
				else if(b[i]==2)dp[i+1][0][k+1][0]+=dp[i][j][k][l];
				else dp[i+1][0][0][l+1]+=dp[i][j][k][l];
		}
		else{
			r(j,3)r(k,3)r(l,3)if(dp[i][j][k][l])
				dp[i+1][j+1][0][0]+=dp[i][j][k][l],
				dp[i+1][0][k+1][0]+=dp[i][j][k][l],
				dp[i+1][0][0][l+1]+=dp[i][j][k][l];
		}
		r(j,3)r(k,3)r(l,3)dp[i+1][j][k][l]%=10000;
	}
	r(j,3)r(k,3)r(l,3)ans+=dp[n][j][k][l];
	cout<<ans%10000<<endl;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
	int N,K,A,B[101];
	int dp[101][7]={},ans=0;
	memset(B,-1,sizeof(B));
	cin>>N>>K;
	for(int i=0;i<K;i++){
		cin>>A;
		cin>>B[A];
	}

	dp[0][0]=1;
	for(int i=0;i<N;i++){
		for(int j=0;j<=6;j++){
			dp[i][j]%=10000;
			//printf("%d ",dp[i][j]);
			if(B[i]!=-1 && (j!=B[i] && j!=B[i]+3)) continue;
			else{
				for(int k=1;k<=3;k++){
					if(j-3==k) continue;
					else if(j==k) dp[i+1][j+3] += dp[i][j]%10000;
					else dp[i+1][k] += dp[i][j]%10000;
				}
			}
		}//puts("");
	}
	for(int i=0;i<=6;i++){
		//printf("%d ",dp[N][i]);
		ans += dp[N][i]%10000;
	}//puts("");
	printf("%d\n",ans%10000);
	return 0;
}