# include <iostream>
# include <cstring>
# include <algorithm>
using namespace std;
const int N = 100010 ;
int n;
int a[ N] ;
int main ( )
{
scanf ( "%d" , & n) ;
for ( int i = 1 ; i <= n; i ++ ) scanf ( "%d" , & a[ i] ) ;
for ( int i = 1 ; i <= n; i ++ )
{
int b;
scanf ( "%d" , & b) ;
a[ i] -= b;
}
for ( int i = n; i; i -- ) a[ i] -= a[ i - 1 ] ;
int pos = 0 , neg = 0 ;
for ( int i = 1 ; i <= n; i ++ )
if ( a[ i] > 0 ) pos += a[ i] ;
else neg -= a[ i] ;
printf ( "%d\n" , max ( pos, neg) ) ;
return 0 ;
}
# include <iostream>
# include <algorithm>
# include <cstring>
# define x first
# define y second
using namespace std;
const int N= 1010 ;
pair< int , char > a[ N] ;
int s[ N] , r[ N] ;
int main ( ) {
int n;
cin >> n;
for ( int i= 1 ; i<= n; i++ ) {
cin >> a[ i] . y >> a[ i] . x ;
}
sort ( a+ 1 , a+ n+ 1 ) ;
for ( int i= 1 ; i<= n; i++ ) {
s[ i] = s[ i- 1 ] ;
if ( a[ i] . y== 'L' ) s[ i] ++ ;
}
for ( int i= n; i; i-- ) {
r[ i] = r[ i+ 1 ] ;
if ( a[ i] . y== 'G' ) r[ i] ++ ;
}
int res= n;
for ( int i= 1 ; i<= n; i++ ) {
res= min ( res, s[ i] + r[ i] - 1 ) ;
}
cout << res << endl;
return 0 ;
}
# include <iostream>
# include <cstring>
# include <algorithm>
# include <queue>
# include <map>
using namespace std;
const int N= 1e5 + 10 ;
struct Node {
int a, b, c, id;
} goods[ N] ;
map< int , int > mp;
int n, x;
bool cmp1 ( Node a, Node b) {
return a. b> b. b;
}
struct cmp2 {
bool operator ( ) ( const Node & p, const Node & q) {
return p. a> q. a;
}
} ;
int main ( ) {
cin >> x >> n;
for ( int i= 1 ; i<= n; i++ ) {
cin >> goods[ i] . a >> goods[ i] . b >> goods[ i] . c ;
goods[ i] . id= i;
}
sort ( goods+ 1 , goods+ 1 + n, cmp1) ;
priority_queue< Node, vector< Node> , cmp2> q;
int j= 1 ;
int res= 0 ;
for ( int i= x; i>= 1 ; i-- ) {
while ( goods[ j] . b>= i&& j<= n) {
q. push ( goods[ j] ) ;
j++ ;
}
if ( ! q. size ( ) )
{
cout<< "-1" << endl;
return 0 ;
}
auto tmp= q. top ( ) ;
res+= tmp. a;
mp[ tmp. id] ++ ;
if ( mp[ tmp. id] == tmp. c) {
q. pop ( ) ;
}
}
cout << res;
return 0 ;
}
# include <iostream>
# include <cstring>
# include <algorithm>
# define x first
# define y second
using namespace std;
const int N= 12 ;
pair< int , int > p[ N] ;
int q[ N] ;
int n;
int get ( pair< int , int > a, pair< int , int > b) {
if ( a. x!= b. x&& a. y!= b. y) return - 1 ;
if ( a. x== b. x) {
if ( a. y< b. y) return 0 ;
else return 2 ;
}
if ( a. y== b. y) {
if ( a. x< b. x) return 1 ;
else return 3 ;
}
return - 1 ;
}
int main ( ) {
cin >> n;
int res= 0 ;
for ( int i= 1 ; i<= n; i++ ) cin >> p[ i] . x >> p[ i] . y;
for ( int i = 1 ; i <= n; i ++ ) q[ i] = i;
do {
int tmp, last, flag= 0 ;
for ( int i= 1 ; i<= n+ 1 ; i++ ) {
tmp= get ( p[ q[ i] ] , p[ q[ i- 1 ] ] ) ;
if ( tmp== - 1 || tmp== last) {
last= - 1 ;
break ;
}
last= tmp;
}
if ( last!= - 1 ) res++ ;
} while ( next_permutation ( q+ 1 , q+ n+ 1 ) ) ;
cout << res << endl;
return 0 ;
}
# include <iostream>
# include <cstring>
# include <algorithm>
using namespace std;
int l, r;
int main ( ) {
string s;
cin >> s;
for ( auto c: s) {
if ( c== '(' ) {
l++ ;
}
else r++ ;
}
int a= 0 , b= 0 ;
int cnt= 0 ;
if ( l== r) {
cout << 0 ;
}
else if ( r> l) {
for ( auto c: s) {
if ( c== '(' ) a++ ;
else {
b++ ;
}
if ( a< b) {
cout << b;
break ;
}
}
}
else {
reverse ( s. begin ( ) , s. end ( ) ) ;
for ( auto c: s) {
cnt++ ;
if ( c== '(' ) a++ ;
else {
b++ ;
}
if ( b< a) {
cout << a;
break ;
}
}
}
return 0 ;
}