44 lines
2 KiB
C
44 lines
2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <inttypes.h>
|
|
|
|
typedef unsigned __int128 u;int X
|
|
[]={3,57,1197,25137};void O(u n){if(n
|
|
#define P10uI64 10000000000000000000ULL
|
|
>UINT64_MAX ) { O(n/P10uI64);n%=P10uI64;}
|
|
printf("%"PRIu64,(uint64_t)n);}int Q(const
|
|
void* A , const void*B){u a=*(u*)A,b=*(u*)B;
|
|
return a>b?a<b?-1:
|
|
0: 1 ;}char C[]={
|
|
'(', ')','[',']',
|
|
'{','}','<','>'};
|
|
int main(){char*
|
|
p, * s , * P,*B;
|
|
size_t L=0,i,U=0
|
|
,g = 1000 ; u *G=
|
|
malloc(sizeof(u)
|
|
*g ) , S =0;while(
|
|
scanf("%ms",&p)==1){s
|
|
=p ; B=s;for(P=p;*P;P++)for(i=0;i<
|
|
sizeof(C);i+=2)if(*P==C[i])*B++=
|
|
C[i+1];else if(*P==C[i+1])if(
|
|
B==s||*(B-1)!=*P){S+=X[i/2
|
|
]; goto N;}else B--;
|
|
if(B!=s){G[L]=0;
|
|
for(B--;B>=s;B--
|
|
)for ( i = 0 ;i<
|
|
sizeof( C);i+=2)
|
|
|
|
|
|
if(*B==C[
|
|
i+1]){G[L]=G[L]*5
|
|
+i/2+1;break;}U++;L++
|
|
;if (L+1>g)G=realloc(G,
|
|
sizeof( u)*(g+=1000));}N:
|
|
free(p);}qsort(G,L,sizeof
|
|
(u),Q); printf("\xe2\x98"
|
|
"\x86");O(S);printf("\n"
|
|
"\xe2\x98\x85");O (G[
|
|
U/ 2]); free(G);
|
|
puts("");}
|