class Solution {
public:
int superPow(int a, vector<int>& b) {
int md = 1337;
a%=md;
int len = b.size();
int fu = a;
int ans = 1;
for(int i = len - 1; i >= 0 ; i --){
int k = 1;
for(int j = 1 ; j <=10 ; j ++){
k = k * fu;
k %= md;
if(j == b[i]){
ans *= k;
ans %= md;
}
}
fu = k;
}
return ans;
}
};