1 // PROBLEMITA DE LAS CANICAS....: UNO CLKW y el otro ANTICLOCK.... :)
9 ll
distd(int k
, int ind
){
10 if( ind
> k
) return ind
-k
;
13 ll
disti(int k
, int ind
){
14 if( k
> ind
) return k
-ind
;
19 int i
,j
,k
, ind
, vaux
;;
20 int casos
;scanf("%i", &casos
);
21 ll sumi
, sumd
, a1
[50001], a2
[50001];
22 for(int h
=0;h
<casos
;h
++){
24 for(i
=0;i
<n
;i
++) scanf("%lld", &arr
[i
]);
25 sumi
=0, sumd
=0, ind
= 0, vaux
= 0;
27 for(i
=1;i
<n
;i
++) a1
[i
] = arr
[i
]*i
+a1
[i
-1];
29 for(i
=n
-2;i
>=0;i
--) a2
[i
] = arr
[i
]*(n
-i
)+a2
[i
+1];
31 ll canicasd
=0, canicasi
=0;
33 while(a1
[(ind
+1)%n
] < a2
[(ind
+2)%n
])ind
=(ind
+1)%n
;
35 if( a1
[ind
] != a2
[(ind
+1)%n
]){
38 ll p
= (b
+(arr
[ind
]*disti(0,ind
))-a
)/n
;
39 for(i
=1;i
<ind
;i
++) canicasd
+=arr
[i
];
41 sumd
= a1
[ind
-1]+p
*ind
;
42 for(i
=n
-1;i
>ind
;i
--)canicasi
+=arr
[i
];
43 canicasi
+=(arr
[ind
]-p
);
44 sumi
= a2
[(ind
+1)%n
]+(arr
[ind
]-p
)*disti(0,ind
);
48 for(i
=1;i
<=ind
;i
++) canicasd
+=arr
[i
];
50 for(i
=n
-1;i
>ind
;i
--)canicasi
+=arr
[i
];
54 if( sumi
== sumd
) res
+=sumi
, nsol
++;
66 canicasi
-=(arr
[k
]-vaux
);
67 sumi
-=(arr
[k
]-vaux
)*n
;
71 canicasd
+=(arr
[ind
]-vaux
);
72 sumd
+=(arr
[ind
]-vaux
)*distd(k
,ind
);
73 canicasi
-=(arr
[ind
]-vaux
);
74 sumi
-=(arr
[ind
]-vaux
)*disti(k
,ind
);
78 sumd
+=arr
[ind
]*distd(k
,ind
);
80 sumi
-=arr
[ind
]*disti(k
,ind
);
85 sumd
-=arr
[ind
]*distd(k
,ind
);
89 ll p
= (b
+(arr
[ind
]*disti(k
, ind
))-a
)/n
;
93 sumi
+=(arr
[ind
]-p
)*disti(k
,ind
);
100 printf("%lld %lld\n", nsol
, res
);