fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=998244353;
  5.  
  6. void solve() {
  7. int n;
  8. string s;
  9. cin >> n >> s;
  10. ll ans =0;
  11. int cnt=0;
  12. for(int i=0;i<s.size();i++){
  13. if(s[i]=='1') cnt++;
  14. }
  15. ans=cnt;
  16. ans*=n;
  17. ans-=cnt;
  18. ans+=n-cnt;
  19. cout << ans << '\n';
  20. }
  21.  
  22. int main(){
  23. ios::sync_with_stdio(false);
  24. cin.tie(nullptr);
  25.  
  26. int t;
  27. cin >> t;
  28. while (t--) solve();
  29.  
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0.01s 5312KB
stdin
5
3
101
1
1
5
00000
2
11
3
010
stdout
5
0
5
2
4