https://www.luogu.com.cn/problem/P1563
#include<bits/stdc++.h>
using namespace std;
char s[100010][20], s1[100010], s2[100010];
int s3[100010];
int i, j, k = 0, m, n;
int main() {
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> s1[i] >> s[i];
}
for (i = 0; i < m; i++) {
cin >> s2[i] >> s3[i];
}
i = 0;
for (j = 0; j < m; j++) {
if ((s2[j]-'0') ^ (s1[i]-'0')) {
if (i + (s3[j]) < n) i = i + (s3[j]); else i = i + (s3[j]) - n;
}
else { if (i - (s3[j]) >= 0) i = i - (s3[j]); else i = n + (i - (s3[j])); }
}
cout << s[i];
}