it the solution of https://codeforces.me/problemset/problem/1549/B
include <bits/stdc++.h>
using namespace std; using ull = unsigned long long; using uli = unsigned long int; using ll = long long;
define pb push_back
int n; int mod = 1e9 + 7;
define yes cout << "YES" << endl
define no cout << "NO" << endl
void solve() { cin >> n; int v[2][n]; for (int i = 0; i < 2; i++) { for (int j = 0; j < n; j++) { cin >> v[i][j]; } } int ans = 0; vector check(n, false); for (int i = 0; i < n; i++) { if (v[1][i] == 1) { if (v[0][i] == 0 && check[i] == false) { ans++; check[i] = true; } if (i — 1 >= 0) { if (v[0][i — 1] == 1 && check[i — 1] == false) { ans++; check[i — 1] = true; } } if (i + 1 < n) { if (v[0][i + 1] == 1 && check[i + 1] == false) { ans++; check[i + 1] = true; } } } } cout << ans << endl; return; }
int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; }