#include using namespace std; int main(){cin.tie(0);ios::sync_with_stdio(false); vector>Trie(800001,vector(26)); int N;scanf("%d%*c",&N); int s=1; vector>d(N); for(int i=0;ij){ swap(i,j); }else{ ++j; } X+=D; if(X>=NN){ X-=NN; } int ok=0,ng=min(d[i].size(),d[j].size()); while(ng-ok>1){ int k=ok+ng>>1; (d[i][k]==d[j][k]?ok:ng)=k; } z+=ok; } cout<