voidsolve(){ int T; cin >> T; while (T--) { string t; cin >> t; string s; cin >> s; vector<int> pos(100); for (int i = 0; i < t.size(); i++) { pos[t[i]-'a'] = i; } int ans = 0, now = pos[s[0]-'a']; for (int i = 1; i < s.size(); i++) { ans += abs(pos[s[i]-'a'] - now); now = pos[s[i]-'a']; } cout << ans << endl; } }
voidsolve(){ int T; cin >> T; while (T--) { ll x, n; cin >> x >> n; if (x % 2 == 0) { ll tmp = n / 4 * 4; ll now = 0; for (ll i = tmp+1; i <= n; i++) { if (now % 2 == 0) now -= i; else now += i; } cout << now + x << endl; } else { if (n <= 2) { for (int i = 1; i <= n; i++) { if (x % 2 == 0) x -= i; else x += i; } cout << x << endl; } else { for (int i = 1; i <= 2; i++) { if (x % 2 == 0) x -= i; else x += i; } ll tmp = (n-2)/4*4+2; for (ll i = tmp+1; i <= n; i++) { if (x % 2 == 0) x -= i; else x += i; } cout << x << endl; } } } }