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 <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

// dp[i][j][k] := i日目の、i-1日目にパスタj、i-2日目にパスタkを食べた時の場合の数
int dp[101][3][3];
const int mod = 10000;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> mp(n + 1, INF);
    for (int i = 0; i < k; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        mp[a] = b;
    }

    dp[0][0][0] = 1;
    
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 3; k++)
            {
                for (int t = 0; t < 3; t++)
                {
                    if (i > 1 && j == k && k == t)
                    {
                        continue;
                    }
                    if (mp[i] != INF && mp[i] != t)
                    {
                        continue;
                    }
                    (dp[i + 1][k][t] += dp[i][j][k]) %= mod;
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            (ans += dp[n][i][j]) %= mod;
        }
    }
    cout << ans << endl;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

int def[110];
// dp[i][j][k] ???i??\??????j,i-1??\??????k????????¶??????????????????????????????
int dp[110][4][4];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;

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

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

	for(int i = 1; i < n; ++i){
		if(def[i] != 0){
			for(int k = 1; k <= 3; ++k){
				for(int l = 0; l <= 3; ++l){
					if(def[i] != k || def[i] != l){
						dp[i][def[i]][k] += dp[i - 1][k][l];
						dp[i][def[i]][k] %= 10000;
					}
				}
			}
		}
		else {
			for(int j = 1; j <= 3; ++j){
				for(int k = 1; k <= 3; ++k){
					for(int l = 0; l <= 3; ++l){
						if(j != k || j != l){
							dp[i][j][k] += dp[i - 1][k][l];
							dp[i][j][k] %= 10000;
						}
					}
				}
			}
		}
	}
	
	//for(int i = 0; i < n; ++i){
		int sum = 0;
		for(int j = 1; j <= 3; ++j){
			for(int k = 1; k <= 3; ++k){
				sum += dp[n - 1][j][k];
				sum %= 10000;
			}
		}
		cout << sum << endl;
	//}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int N,K,num;
int day[101];
int a[101][4][3];

long long int dp(int d,int k,int n){
	if(n == 3)return 0;

	if(d == N)return a[d][k][n] = 1;

	long long int b = 0; 
	if(day[d+1] != -1){
		if(day[d+1] == k){
			b += dp(d+1, day[d+1], n+1) % 10000;
		}else{
			b += dp(d+1, day[d+1], 1) % 10000;
		}
	}else{
		for(int i = 1;i <= 3;i++){
			if(i == k){
				b += dp(d+1, i, n+1) % 10000;
			}else{
				b += dp(d+1, i, 1) % 10000;
			}
		}
	}
	return a[d][k][n] = b % 10000;
}

int main(){
	fill_n(**a,101*4*3,-1);
	fill_n(day,101,-1);
	cin >>N >> K;
	for(int i = 0;i<K;i++){
		cin >> num;
		cin >> day[num];
	}
	cout <<dp(0,0,0)<<endl; 
}

C++: #include <stdio.h>
int N,k;
int day[101]={0};
int tem[101][4][3]={0};

int cal(int n,int p,int d ){
		if(tem[n][p][d]>0)
			return tem[n][p][d];
		else if(d>=3)
			return 0;
		else if(n>=N)
			return 1;
		else if(day[n+1]>0){
			tem[n][p][d] =cal(n+1,day[n+1],(p==day[n+1])?d+1:1);
			return tem[n][p][d];
		}else{
			tem[n][p][d]= cal(n+1,1,(p==1)?d+1:1)+cal(n+1,2,(p==2)?d+1:1)+cal(n+1,3,(p==3)?d+1:1);
			return tem[n][p][d];
		}
}

int main(void){
	int a,b;
	int total;
	scanf("%d %d",&N,&k);
	for(int i=0;i<k;i++){
		scanf("%d %d",&a,&b);
		day[a]=b;
	}
	total=cal(0,0,0);
	total %=10000;
	printf("%d\n",total);
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n;
cin >>n;
int k;
cin >>k;
int a[n][3][3];//n+1個の最後から2番目-1,1番目-1
int b[n];
int c;
c=0;
while(c<n){
b[c]=-1;
c=c+1;}
int d;
int e;
c=0;
while(c<k){
cin >>d;
cin >>e;
b[d-1]=e-1;
c=c+1;}
int f;
int h;
c=0;
while(c<3){
f=0;
while(f<3){
h=0;
if(b[0]!=c){if(b[0]!=-1){h=1;}}
if(b[1]!=f){if(b[1]!=-1){h=1;}}
if(h==1){a[1][c][f]=0;}
if(h==0){a[1][c][f]=1;}
f=f+1;}
c=c+1;}
int g;
c=2;
while(c<n){
f=0;
while(f<3){
g=0;
while(g<3){
a[c][f][g]=a[c-1][0][f]+a[c-1][1][f]+a[c-1][2][f];
if(f==g){a[c][f][g]=a[c][f][g]-a[c-1][f][f];}
if(b[c]!=g){if(b[c]!=-1){a[c][f][g]=0;}}
a[c][f][g]=a[c][f][g]%10000;
g=g+1;}
f=f+1;}
c=c+1;}
int i;
i=a[n-1][0][0]+a[n-1][0][1]+a[n-1][0][2]+a[n-1][1][0]+a[n-1][1][1]+a[n-1][1][2]+a[n-1][2][0]+a[n-1][2][1]+a[n-1][2][2];
cout << i%10000<<endl;
}