Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int m;
- cin>>m;
- vector<string> s(3);
- cin>>s[0]>>s[1]>>s[2];
- for(auto &e: s)
- e = e+e+e;
- int ans = 1e9;
- for(int i=0; i<3*m; i++)
- {
- for(int j=0; j<3*m; j++)
- {
- for(int k=0; k<3*m; k++)
- {
- if(i==j || j==k || i==k) continue;
- if(s[0][i]!=s[1][j] || s[1][j]!=s[2][k] || s[0][i]!=s[2][k]) continue;
- ans = min(ans, max({i, j, k}));
- }
- }
- }
- if(ans == 1e9) ans = -1;
- cout<<ans<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment