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 <algorithm>
using namespace std;
int main(){
	int a[101] = { 0 };
	int n;
	int i;
	cin >> n >> i;
	for (int v = 0; v < i; v++){
		int y, x;
		cin >> y >> x;
		a[y] = { x };

	}
	int f;
	if (a[1] = a[2] != a[3]){
		if (a[1] != 0){
			f = 2;
		}
		if (a[1] = 0){
			f = 8;
		}
	}
	if (a[1] = a[3] != a[2]){
		if (a[1] != 0)
			f = 2;
		if (a[1] = 0){
			f = 8;
		}
	}
	if (a[3] = a[2] != a[1]){
		if (a[2] != 0)
			f = 2;
		if (a[2] = 0){
			f = 8;
		}
	}
	if (a[1] = a[2] = a[3]){
		if (a[1] = 0){
			f = 24;
		}
		if (a[1] != 0){
			f = 1;
		}

	}

	for (int v = 4; v <= n; v++){
		if (a[v] = 0){
			if (a[v - 2] = a[v - 1] != 0){
				f = f * 2;
			}
			if (a[v - 2] != a[v - 1] != 0){
				f = f * 3;
			}
			if (a[v - 2] = 0 != a[v - 1]){
				f = f * 3 -1;
			}
			if (a[v - 1] = 0 != a[v - 2]){
				f = f * 3 -1;
			}
		
		}
	}
	        cout << f << endl;
        	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>

using namespace std;

#define sz			size()
#define lgt			length()
#define rep(i,n)	for (int i = 0; i < n; i++)
#define ALL(X)		(X).begin(),(X).end()
#define RALL(X)		(X).rbegin(),(X).rend()
#define pb			push_back
#define SORT(a)		sort(ALL(a));
#define RSORT(a)	sort(RALL(a));
#define mp			make_pair
#define dump(x)		cerr<<#x<<" = "<<(x)<<endl;
#define fir			first
#define sec			second

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<string> vs;

int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
vs form(string a,char s){vs v;string b;rep(i,a.lgt){if(a[i]==s){v.pb(b);b="";}else b+=a[i];}v.pb(b);return v;}
vi formint(string a,char s){vi v;string b;rep(i,a.lgt){if(a[i]==s){v.pb(toInt(b));b="";}else b+=a[i];}v.pb(toInt(b));return v;}

const double EPS=1e-10,PI=acos(-1.0);
const int INF=2100000000;

int dp[128][4][4];
int s[128];

int main(void)
{
	rep(i,128){
		s[i]=-1;
		rep(j,4)rep(k,4)dp[i][j][k]=0;
	}
	int n,k,a,b;
	cin>>n>>k;
	rep(i,k){
		cin>>a>>b;
		s[a]=b-1;
	}
	
	for(int i=1;i<=n;i++){
		if(i==1){
			rep(j,3){
				if(s[i]!=-1&&s[i]!=j)continue;
				dp[1][j][0]=1;
			}
		}
		else if(i==2){
			rep(j,3){
				if(s[i]!=-1&&s[i]!=j)continue;
				rep(k,3)dp[2][j][k]+=dp[1][k][0];
			}
		}
		else
		rep(j,3){
			if(s[i]!=-1&&s[i]!=j)continue;
			rep(k,3){
				rep(m,3)dp[i][j][k]+=dp[i-1][k][m];
				if(j==k)dp[i][j][k]-=dp[i-1][j][k];
				dp[i][j][k]%=10000;
			}
		}
	}
	
	int res=0;
	rep(i,9)res+=dp[n][i/3][i%3];
	cout<<res%10000<<endl;
	//rep(j,9){for(int i=1;i<=n;i++)cout<<dp[i][j/3][j%3]<<" ";cout<<endl;}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<int,int> P;
int n,k;
P a[1000];
int i,j,l,m;
long long int dp[1000][4][4],cnt=0;
int flg1=0,flg2=0;
void func();
int main(void){
	scanf("%d %d",&n,&k);
	for(i=1;i<=k;i++){
		scanf("%d %d",&a[i].first,&a[i].second);
	}
	sort(a,a+k+1);
	for(i=1;i<=n+1;i++){
		for(j=1;j<=3;j++){
			for(l=1;l<=3;l++){
				dp[i][j][l]=0;
			}
		}
	}
	for(i=3;i<=n+1;i++){
		for(m=1;m<=k;m++){
			if(a[m].first==i-2){//もしi-2日目に設定があったら
				for(j=1;j<=3;j++){
					for(l=1;l<=3;l++){
						if(l!=a[m].second){
							dp[i][j][l]=-1;
						}
					}
				}
			}
			if(a[m].first==i-1){
				for(l=1;l<=3;l++){
					for(j=1;j<=3;j++){
						if(j!=a[m].second){
							dp[i][j][l]=-1;
						}
					}
				}
			}
		}
	}
	for(j=1;j<=3;j++){
		for(l=1;l<=3;l++){
			if(dp[3][j][l]!=-1){
				dp[3][j][l]=1;
			}
		}
	}
	for(i=3;i<=n+1;i++){
		for(j=1;j<=3;j++){
			for(l=1;l<=3;l++){
				if(dp[i][j][l]>-1){
					for(m=1;m<=3;m++){
						if(dp[i+1][m][j]>-1){
							if(m==j && j==l);
							else {
								dp[i+1][m][j]+=dp[i][j][l];
							}
						}
					}
				}
			}
		}
	}
	
	/*for(i=3;i<=n+1;i++){
		for(j=1;j<=3;j++){
			for(l=1;l<=3;l++){
				printf("%lld ",dp[i][j][l]);
			}
			printf("\n");
		}
		printf("\n");
	}*/
	long long int cnt=0;
	for(j=1;j<=3;j++){
		for(l=1;l<=3;l++){
			if(dp[n+1][j][l]>-1){
				cnt+=dp[n+1][j][l];
				cnt%=10000;
			}
		}
	}
	printf("%lld\n",cnt);
	return 0;
}

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

int main(){
  int n,k,s[100];
  scanf("%d %d",&n,&k);
  fill(s,s+n,0);
  for(int i=0;i<k;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    s[a-1] = b;
  }
  int dp[n][27];
  fill(dp[0],dp[0]+27*n,0);
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if((i!=j||j!=k)&&(s[0]==0||(i-s[0])%3==0)&&(s[1]==0||(j-s[1])%3==0)&&(s[2]==0||(k-s[2])%3==0)){
          dp[2][9*i+3*j+k] = 1;
        }
      }
    }
  }

  for(int i=3;i<n;i++){
    for(int j=0;j<27;j++){
      if(j%13==0||(s[i]>0&&(j-s[i])%3!=0)) dp[i][j] = 0;
      else{
        int x = j%3;
        int y = j/3;
        for(int k=0;k<3;k++) dp[i][j]+=dp[i-1][9*k+y];
        dp[i][j]%=10000;
      }
    }
  }
  int ans = 0;
  for(int i=0;i<27;i++) ans+=dp[n-1][i];
  printf("%d\n",ans%10000);
  return 0;
}