stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int n,a,b,ans;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++)

    {

    	scanf("%d%d",&a,&b);

    	ans+=b-a+1;

	}

	cout<<ans<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.206263379627134x):
#include<stdio.h>

int n,r,l,lhy,i;//lhy，最新防伪标识!（不是刘浩宇！！！）

int main()

{

    scanf("%d",&n);

    for(i=1;i<=n;i++)

    {scanf("%d%d",&l,&r);//l代表左边，r代表右边

    lhy+=r-l+1;}//加一个，头尾都有

    printf("%d\n",lhy);//回车别忘了

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,l,r,ans;

int main()

{

	cin>>n;

	for(int i=1;i<=n;i++) 

	{

		cin>>l>>r;

		ans+=r-l+1;

	}

	cout<<ans;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.245596442433846x):
#include<stdio.h>

int n,r,l,lhy,i;//lhy，最新防伪标识!（不是刘浩宇！！！）

int main()

{

    scanf("%d",&n);

    for(i=1;i<=n;i++)

    {scanf("%d%d",&l,&r);//l代表左边，r代表右边

    lhy+=r-l+1;}//加一个，头尾都有

    printf("%d\n",lhy);//回车别忘了

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int m,x,y,ans;

int main(){

	scanf("%d",&m);

	for(int i=1;i<=m;i++){

		scanf("%d%d",&x,&y);

		ans+=(y-x+1);

	}

	printf("%d",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.186082823416592x):
#include<stdio.h>

int n,r,l,lhy,i;//lhy，最新防伪标识!（不是刘浩宇！！！）

int main()

{

    scanf("%d",&n);

    for(i=1;i<=n;i++)

    {scanf("%d%d",&l,&r);//l代表左边，r代表右边

    lhy+=r-l+1;}//加一个，头尾都有

    printf("%d\n",lhy);//回车别忘了

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main(){

    int n,l,r,s=0;

    cin>>n;

    while(n--){

    cin>>l>>r;

    s+=r-l+1;

    }

    cout<<s<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.252107893632444x):
#include<stdio.h>

int n,r,l,lhy,i;//lhy，最新防伪标识!（不是刘浩宇！！！）

int main()

{

    scanf("%d",&n);

    for(i=1;i<=n;i++)

    {scanf("%d%d",&l,&r);//l代表左边，r代表右边

    lhy+=r-l+1;}//加一个，头尾都有

    printf("%d\n",lhy);//回车别忘了

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main(){

    int n,l,r,a;

    cin>>n;

    for(int i=1;i<=n;i++){

        cin>>l>>r;

        a+=r-l+1;

    }

    cout<<a<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.252156876879476x):
#include<stdio.h>

int n,r,l,lhy,i;//lhy，最新防伪标识!（不是刘浩宇！！！）

int main()

{

    scanf("%d",&n);

    for(i=1;i<=n;i++)

    {scanf("%d%d",&l,&r);//l代表左边，r代表右边

    lhy+=r-l+1;}//加一个，头尾都有

    printf("%d\n",lhy);//回车别忘了

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n;

int sum;

int main(){

	scanf("%d",&n);

	int l,r;

	while(n--){

		scanf("%d%d",&l,&r);

		sum+=r-l+1;

	}

	printf("%d",sum);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.185229414683547x):
#include<stdio.h>

int n,r,l,lhy,i;//lhy，最新防伪标识!（不是刘浩宇！！！）

int main()

{

    scanf("%d",&n);

    for(i=1;i<=n;i++)

    {scanf("%d%d",&l,&r);//l代表左边，r代表右边

    lhy+=r-l+1;}//加一个，头尾都有

    printf("%d\n",lhy);//回车别忘了

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main()

{

    int n;

    int l,r,ans=0;

    cin>>n;

    for (int i=1;i<=n;i++)

    {

        cin>>l>>r;

        ans+=r-l+1;

    }

    cout<<ans<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.252031646797525x):
#include<stdio.h>

int n,r,l,lhy,i;//lhy，最新防伪标识!（不是刘浩宇！！！）

int main()

{

    scanf("%d",&n);

    for(i=1;i<=n;i++)

    {scanf("%d%d",&l,&r);//l代表左边，r代表右边

    lhy+=r-l+1;}//加一个，头尾都有

    printf("%d\n",lhy);//回车别忘了

    return 0;

}
// Slower C++ solution:
#include <iostream>



int main()

{

    int n, ans = 0;

    std::cin >> n;

    for (int i = 0; i < n; ++i) {

        int l, r;

        std::cin >> l >> r;

        ans += (r - l + 1);

    }

    std::cout << ans << std::endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.244579038716788x):
#include <cstdio>



int main()

{

    int n, ans = 0;

    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {

        int l, r;

        scanf("%d%d", &l, &r);

        ans += (r - l + 1);

    }

    printf("%d\n", ans);

}
// Slower C++ solution:
#include "bits/stdc++.h"

 

typedef long long ll;

#define int ll

#define fi first

#define se second

#define SORT(a) sort(a.begin(),a.end())

#define rep(i,n) for(int i = 0;i < (n) ; i++) 

#define REP(i,n) for(int i = 0;i < (n) ; i++) 

#define MP(a,b) make_pair(a,b)

#define pb(a) push_back(a)

#define INF LLONG_MAX/2

#define all(x) (x).begin(),(x).end()

#define debug(x) cerr<<#x<<": "<<x<<endl

#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl

using namespace std;

int MOD = 1000000007;

vector<int> G[100100];



signed main(){

    string s;

    cin >> s;

    int mx = 0;

    int cnt = 0;

    rep(i,s.size()){

        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){

            cnt++;

            mx = max(mx,cnt);

        }else{

            cnt = 0;

        }

    }

    cout << mx << endl;

    

    return 0; 

}



// g++ -std=c++14 code1.cpp

// rm -r -f test;oj dl https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_d

// rm -r -f test;oj dl http://abc122.contest.atcoder.jp/tasks/abc122_a

// Faster C++ solution for the same problem (measured speedup: 3.545107893804326x):
#include "bits/stdc++.h"

 

using namespace std;

typedef long long ll;

typedef vector<ll> vll;

#define int ll

#define fi first

#define se second

#define SORT(a) sort(a.begin(),a.end())

#define rep(i,n) for(int i = 0;i < (n) ; i++) 

#define REP(i,n) for(int i = 0;i < (n) ; i++) 

#define MP(a,b) make_pair(a,b)

#define pb(a) push_back(a)

#define INF LLONG_MAX/2

#define all(x) (x).begin(),(x).end()

#define debug(x) cerr<<#x<<": "<<x<<endl

#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl

/*----------------------------------------------------------------*/



// int MOD = 998244353;

int MOD = 1000000007;





/*----------------------------------------------------------------*/

signed main(){



    string s;

    cin >> s;

    

    int mx = 0;

    int a,b;

    for(int i = 0;i < s.size();i++){

        int cnt = 0;

        rep(j,s.size()){

            if(i+j >= s.size() || (s[i+j] != 'A' && s[i+j] != 'T' && s[i+j] != 'C' && s[i+j] != 'G'))break;

            cnt++;

        }

        mx = max(mx,cnt);

    }

    cout << mx << endl;

    



	return 0;

}

/*----------------------------------------------------------------*/



// g++ -std=c++14 code1.cpp

// sudo pip3 install --upgrade online-judge-tools

// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c

// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b

// rm -r -f test;oj dl https://abc122.contest.atcoder.jp/tasks/abc122_b
// Slower C++ solution:
#include <iostream>

#include <regex>



using namespace std;

int main() {

    string s;

    cin >> s;

    int len=0;

    regex re(R"([ACGT]+)");

    sregex_iterator iter(s.cbegin(), s.cend(), re);

    sregex_iterator end;

    for(;iter!=end;++iter) {

        string m = iter->str();

        if (m.length()>len) len = m.length();

    }

    cout << len << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1384258133557341x):
#include <iostream>

using namespace std;

int main() {

    string s;

    cin >> s;

    int slen=s.length(), len=0;

    int l=0;

    for(int i=0;i<slen;i++) {

        char c = s[i];

        if (c=='A' || c=='C' || c=='G' || c=='T') {

            l++;

            if (l>len) len = l;

        } else {

            l = 0;

        }

    }

    cout << len << endl;

    return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

struct vec{

	int x,nx;

}e[5000001];

int h[200001],p,cnt,co[200001];

void ae(int fr,int to){

	e[++p]=(vec){to,h[fr]};h[fr]=p; 

}

int mi[200001<<2];

int n,f[200001],q;

int Min(int p,int q){

	return p<q?p:q;

}

int Max(int p,int q){

	return p>q?p:q;

}

int ask(int i,int l,int r,int ql,int qr){

	if(r<ql||l>qr) return 2147483647;

	if(ql<=l&&r<=qr) return mi[i];

	int m=(l+r)>>1;

	return Min(ask(i<<1,l,m,ql,qr),ask(i<<1|1,m+1,r,ql,qr));

}

void upd(int i,int l,int r,int k,int pos){

	if(r<pos||l>pos) return;

	if(l==r&&r==pos){

		mi[i]=Min(mi[i],k);return;

	}

	int m=(l+r)>>1;

	upd(i<<1,l,m,k,pos);upd(i<<1|1,m+1,r,k,pos);

	mi[i]=Min(mi[i<<1],mi[i<<1|1]);

}

int main(){

	scanf("%d",&n);

	for(int i=1,a;i<=n;i++){

		scanf("%d",&a);

		cnt+=!a;

		co[i]=a?1:-1;

	}

	scanf("%d",&q);

	for(int i=1,l,r;i<=q;i++){

		scanf("%d%d",&l,&r);

		ae(l,r);

	}

	memset(mi,0x3f,sizeof(mi));

	memset(f,0x3f,sizeof(f));

	f[0]=0;

	for(int i=1;i<=n;i++){

		for(int j=h[i];j;j=e[j].nx){

			int mi=f[i-1];

			mi=Min(mi,ask(1,1,n,Max(i-1,1),e[j].x));

			if(mi<f[e[j].x]){

				f[e[j].x]=mi;

				upd(1,1,n,mi,e[j].x);

			}

		}

		f[i]=Min(f[i],f[i-1]+co[i]);

	}

	printf("%d\n",f[n]+cnt);

}

// Faster C++ solution for the same problem (measured speedup: 1.8550267217875431x):
#include <cstdio>

#include <cstring>

#include <algorithm>

#define MN 262150

using namespace std;

struct node{int x,y;}b[MN];

int t[MN<<1],a[MN];

int MQ,INF,n,m,ans,f0;



inline int read()

{

	int n=0,f=1; char c=getchar();

	while (c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();}

	while (c>='0' && c<='9') {n=n*10+c-'0'; c=getchar();}

	return n*f;

}



inline void grw(int x,int y) {for (x+=MQ;x;x>>=1) if (t[x]>y) t[x]=y; else return;}

inline int gmn(int x,int y)

{

	int sm=INF;

	for (x+=MQ,y+=MQ;x<=y;x>>=1,y>>=1)

	{

		if ( x&1) sm=min(sm,t[x++]);

		if (~y&1) sm=min(sm,t[y--]);

	}

	return sm;

}

bool cmp(const node& a,const node& b) {return a.x<b.x || a.x==b.x && a.y>b.y;}



int main()

{

	register int i,j;

	n=read(); for (i=1;i<=n;++i) a[i]=read(),ans+=(a[i]==0),a[i]=a[i]?1:-1;

	m=read(); for (i=1;i<=m;++i) b[i].x=read(),b[i].y=read();

	sort(b+1,b+m+1,cmp); memset(t,100,sizeof(t)); INF=t[0]; f0=0;

	for (MQ=1;MQ<n;MQ<<=1); --MQ;

	for (i=j=1;i<=n;f0=min(f0+a[i],t[i+MQ]),++i)

		for (;j<=m&&b[j].x==i;++j)

			grw(b[j].y,min(gmn(i,b[j].y),f0));

	printf("%d",ans+f0);

}
// Slower C++ solution:
#include <vector>

#include <stdio.h>

#include <string.h>

#include <iostream>

#include <algorithm>

#define R register

typedef long long ll;

inline int read(){

	R int x; R bool f; R char c;

	for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');

	for (x=c^'0'; (c=getchar())>='0'&&c<='9'; x=(x<<1)+(x<<3)+(c^'0'));

	return f?-x:x;

}

#define M (1<<18)

#define MN 200005

int T[M<<1],n,q,cost[MN],cnt;

std::vector<int> rang[MN];

inline void rw(int k,int v){for (k+=M; k; k>>=1) if (T[k]<=v) return; else T[k]=v;}

inline int query(int l,int r){

	R int res=0x3f3f3f3f;

	for (l+=M-1,r+=M+1; l^r^1; l>>=1,r>>=1){

		if (~l&1) res=std::min(T[l^1],res);

		if ( r&1) res=std::min(T[r^1],res);

	}return res;

}

int main(){

	n=read();for (R int i=1; i<=n; ++i)

		cost[i]=read()?1:-1,cnt+=(bool)(!(~cost[i]));

	q=read();for (R int i=1,x,y; i<=q; ++i)

		x=read(),y=read(),rang[x].push_back(y);

	memset(T,0x3f,sizeof(T));rw(0,0);

	for (R int i=1; i<=n; ++i){

		for (auto j : rang[i]){

			R int res = T[i+M-1];

			res=std::min(res,query(std::max(i-1,1),j));

			rw(j,res);

		}rw(i,T[i+M-1]+cost[i]);

	}printf("%d\n",T[n+M]+cnt);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.8894243522711247x):
#include <cstdio>

#include <cstring>

#include <algorithm>

#define MN 262150

using namespace std;

struct node{int x,y;}b[MN];

int t[MN<<1],a[MN];

int MQ,INF,n,m,ans,f0;



inline int read()

{

	int n=0,f=1; char c=getchar();

	while (c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();}

	while (c>='0' && c<='9') {n=n*10+c-'0'; c=getchar();}

	return n*f;

}



inline void grw(int x,int y) {for (x+=MQ;x;x>>=1) if (t[x]>y) t[x]=y; else return;}

inline int gmn(int x,int y)

{

	int sm=INF;

	for (x+=MQ,y+=MQ;x<=y;x>>=1,y>>=1)

	{

		if ( x&1) sm=min(sm,t[x++]);

		if (~y&1) sm=min(sm,t[y--]);

	}

	return sm;

}

bool cmp(const node& a,const node& b) {return a.x<b.x || a.x==b.x && a.y>b.y;}



int main()

{

	register int i,j;

	n=read(); for (i=1;i<=n;++i) a[i]=read(),ans+=(a[i]==0),a[i]=a[i]?1:-1;

	m=read(); for (i=1;i<=m;++i) b[i].x=read(),b[i].y=read();

	sort(b+1,b+m+1,cmp); memset(t,100,sizeof(t)); INF=t[0]; f0=0;

	for (MQ=1;MQ<n;MQ<<=1); --MQ;

	for (i=j=1;i<=n;f0=min(f0+a[i],t[i+MQ]),++i)

		for (;j<=m&&b[j].x==i;++j)

			grw(b[j].y,min(gmn(i,b[j].y),f0));

	printf("%d",ans+f0);

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <algorithm>

#include <cstring>



using namespace std;



const int MOD = 1000000007;



int main(){

	int N, W;

	static int dp[201][10001];

	while(cin >> N >> W){

		vector<int> w(N);

		for(int i=0;i<N;i++) cin >> w[i];

		sort(w.begin(), w.end());

		memset(dp, 0, sizeof(dp));

		dp[N][0] = 1;

		for(int i=N-1;i>=0;i--){

			for(int j=i+1;j<=N;j++){

				for(int k=W;k>=0;k--){

					dp[i][k] = (dp[i][k]+dp[j][k])%MOD;

					if(k+w[i]<=W) dp[j][k+w[i]] = (dp[j][k+w[i]]+dp[j][k])%MOD;

					dp[j][k] = 0;

				}

			}

		}

		int res = 0;

		for(int i=0;i<=N;i++){

			for(int j=0;j<=W;j++){

				if(i==N || j+w[i] > W) res = (res+dp[i][j])%MOD;

			}

		}

		cout << res << endl;

	}

}

// Faster C++ solution for the same problem (measured speedup: 9.335618112436993x):
#include <iostream>

#include <vector>

#include <numeric>

#include <algorithm>



using namespace std;



const int MOD = 1000000007;



int solve(const vector<int>& w, int W){

    if(w.back() > W || w.size() == 1) return 1;

    int sum = accumulate(w.begin(), w.end(), 0);

    if(sum <= W) return 1;

    vector<int> dp(W+1, 0);

    dp[0] = 1;

    int res = 0;

    for(int i=0;i<w.size();i++){

        for(int j=W-w[i];j>=0;j--){

            dp[j+w[i]] += dp[j];

            dp[j+w[i]] %= MOD;

        }

        sum -= w[i];

        for(int j=max(0, W-sum-w[i]+1);j<=W-sum-(i==w.size()-1?0:w[i+1]);j++){

            res = (res + dp[j]) % MOD;

        }

    }

    return res;

}



int main(){

    int N, W;

    while(cin >> N >> W){

        vector<int> w(N);

        for(auto& t : w) cin >> t;

        sort(w.rbegin(), w.rend());

        cout << solve(w, W) << endl;

    }

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <cstring>



using namespace std;

typedef long long ll;



const int mod=1000000007;

int N,W;

int w[201];

ll dp[2][10001][202];



int main(){



	cin>>N>>W;

	for(int i=0;i<N;i++)cin>>w[i];

	for(int j=0;j<10001;j++){

		for(int k=0;k<=N;k++){

			if(j<=W&&(k==N||w[k]+j>W))dp[N%2][j][k]=1;

			else dp[N%2][j][k]=0;

		}

	}



	for(int i=N-1;i>=0;i--){

		int cur=(i+1)%2;

		int nxt=(i)%2;

		for(int j=0;j<10001;j++){

			for(int k=0;k<=N;k++){

				dp[nxt][j][k]=0;

				int nmwidx=k;

				if(k==N||w[k]>w[i])nmwidx=i;

				dp[nxt][j][k]+=dp[cur][j][nmwidx];

				if(j+w[i]<=W)dp[nxt][j][k]+=dp[cur][j+w[i]][k];

				dp[nxt][j][k]%=mod;

			}

		}

	}

	cout<<dp[0][0][N]<<endl;



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.828421296680102x):
#include <iostream>

#include <algorithm>

#include <cstring>



using namespace std;

typedef long long ll;



const int mod=1000000007;

int N,W;

int w[201];

ll dp[2][10001][202];



int main(){



	cin>>N>>W;

	for(int i=0;i<N;i++)cin>>w[i];

	for(int j=0;j<=W;j++){

		for(int k=0;k<=N;k++){

			if(j<=W&&(k==N||w[k]+j>W))dp[N%2][j][k]=1;

			else dp[N%2][j][k]=0;

		}

	}



	for(int i=N-1;i>=0;i--){

		int cur=(i+1)%2;

		int nxt=(i)%2;

		for(int j=0;j<=W;j++){

			for(int k=0;k<=N;k++){

				dp[nxt][j][k]=0;

				int nmwidx=k;

				if(k==N||w[k]>w[i])nmwidx=i;

				dp[nxt][j][k]+=dp[cur][j][nmwidx];

				if(j+w[i]<=W)dp[nxt][j][k]+=dp[cur][j+w[i]][k];

				dp[nxt][j][k]%=mod;

			}

		}

	}

	cout<<dp[0][0][N]<<endl;



	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define F(i,a,b) for(int i=(a);i<=(b);++i)

#define F2(i,a,b) for(int i=(a);i<(b);++i)

#define dF(i,a,b) for(int i=(a);i>=(b);--i)

#define dF2(i,a,b) for(int i=(a);i>(b);--i)

#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)

using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;



int n;

int t[4001],a[4001];

int b[4001];

int f[2001][2001];

int bit[4001];

inline void Add(int p,int x){for(;p<=n+n;p+=p&-p)bit[p]+=x;}

inline int Qur(int p){int A=0;for(;p;p-=p&-p)A+=bit[p];return A;}



int main(){ char s[3];

	scanf("%d",&n);

	F(i,1,n+n) scanf("%s%d",s,a+i), t[i]=*s=='B', b[t[i]*n+a[i]]=i;

	f[0][0]=0;

	F(i,0,n){

		memset(bit,0,sizeof bit);

		F(j,1,n+n) Add(j,1);

		F(j,1,i) Add(b[j],-1);

		F(j,i?0:1,n){

			if(j) Add(b[n+j],-1);

			f[i][j]=INF;

			if(i) f[i][j]=min(f[i][j],f[i-1][j]+Qur(b[i]));

			if(j) f[i][j]=min(f[i][j],f[i][j-1]+Qur(b[n+j]));

		}

	} printf("%d",f[n][n]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.311395568693794x):
#include<cstdio>

#include<cstring>

#include<cctype>

#include<cmath>

#include<algorithm>

#define reg register

#define max(a,b) (a>b?a:b)

#define min(a,b) (a<b?a:b)

typedef long long ll;

template<typename T>inline T read(){

    reg T x=0,f=1;reg char ch=getchar();

    for(;!isdigit(ch);f=ch=='-'?-1:1,ch=getchar());

    for(;isdigit(ch);x=(x*10)+(ch^48),ch=getchar());

    return x*f;

}

char buf[15];

inline void write(int v){

	if(!v){puts("0");return;}

	reg int cnt=0;

	while(v)buf[++cnt]=v%10+'0',v/=10;

	for(reg int i=cnt;i;i--)putchar(buf[i]);

	putchar('\n');

}

const int maxn=2005;

const int inf=0x7fffffff;

int f[maxn][maxn],col[maxn<<1],a[maxn<<1],p[2][maxn],c[2][maxn<<1][maxn];

char ch[10];

int main(){

	reg int n=read<int>();

	for(reg int i=1;i<=n*2;i++){

		scanf("%s",ch);a[i]=read<int>();col[i]=ch[0]=='B'?1:0;

		p[col[i]][a[i]]=i;

	}

	for(reg int i=1;i<=n*2;i++)

		for(reg int j=0;j<=n;j++)

			c[0][i][j]=c[0][i-1][j]+(a[i-1]>j&&!col[i-1]),

			c[1][i][j]=c[1][i-1][j]+(a[i-1]>j&&col[i-1]);

	for(reg int i=0;i<=n;i++)

		for(reg int j=0;j<=n;j++){

			if(!(i|j))continue;

			f[i][j]=inf;

			if(i)f[i][j]=min(f[i][j],f[i-1][j]+c[0][p[0][i]][i-1]+c[1][p[0][i]][j]);

			if(j)f[i][j]=min(f[i][j],f[i][j-1]+c[1][p[1][j]][j-1]+c[0][p[1][j]][i]);

		}

	write(f[n][n]);

    return 0;

}
// Slower C++ solution:
#include "bits/stdc++.h"

#include <random>



using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)

#define ll long long

#define MOD 1000000007LL

#define llMAX 9223372036854775807LL

#define llMIN -9223372036854775808LL

using vi = vector<ll>; // intの1次元の型に vi という別名をつける

using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける



ll n,k,x,y;



int main(){

  ll ans=0;

  ll D=365;

  cin>>ans;

  vi c(26);

  vi last(26);

  vvi data(D, vi(26));  // N * M の2次元配列

  for(ll i=0;i<26;i++){

    cin>>c[i];

  }

  for(ll i=0;i<D;i++){

    for(ll j=0;j<26;j++){

      cin>>data[i][j];

    }

  }





  ll sc=0;

  ll sct=0;

  ll maxid=-1;

  for(ll i=0;i<D;i++){

    sc=-922337203685477580LL;

    maxid=0;

    for(ll j=0;j<26;j++){

      ll l=i-last[j];

      sct=data[i][j]-(l*l-l)/2*c[j];

      if (sc<sct){

        sc=sct;

        maxid=j;

      }

    }

    last[maxid]=i;

    cout<<(maxid+1)<<endl;

  }









  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3861106361357936x):
#include "bits/stdc++.h"

#include <random>



using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)

#define ll long long

#define MOD 1000000007LL

#define llMAX 9223372036854775807LL

#define llMIN -9223372036854775808LL

using vi = vector<ll>; // intの1次元の型に vi という別名をつける

using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける



ll n,k,x,y;



int main(){

  ll ans=0;

  ll D=5;

  cin>>D;

  vi c(26);

  vi last(26,-1);

  vvi data(D, vi(26));  // N * M の2次元配列

  ll factscore=0;





  for(ll i=0;i<26;i++){

    cin>>c[i];

  }

  for(ll i=0;i<D;i++){

    for(ll j=0;j<26;j++){

      cin>>data[i][j];

    }

  }





  ll sc=0;

  ll sct=0;

  ll maxid=-1;

  for(ll i=0;i<D;i++){

    sc=-922337203685477580LL;

    maxid=0;

    

    for(ll j=0;j<26;j++){

      ll l=i-last[j];

      sct=(l*l-l)/2*c[j];

      factscore-=sct;

      sct=data[i][j]+sct;

      if (sc<sct){

        sc=sct;

        maxid=j;

      }

    }

    factscore+=sc;

    last[maxid]=i;

    cout<<(maxid+1)<<endl;

  }



  //cout<<factscore<<endl;





  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string.h>

#include <stdio.h>

#include <queue>

#include <vector>

#include <algorithm>

using namespace std;

const int Max=3e5+100;

char str[Max];

int main(){

    scanf("%s", str);

    int len=strlen(str);

    if(str[len-1]!=str[0]){

        if(len%2)printf("First\n");

        else printf("Second\n");

    }

    else {

        int num=0, ans=0;

        char pos=str[0];

        for(int a=0; a<len; a++){

            if(str[a]==pos)ans+=max(0, num-1), num=0;

            else num++;

        }

        //printf("%d\n", ans);

        if(ans%2==0)printf("Second\n");

        else printf("First\n");

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.298729318660799x):
#include <string.h>

#include <stdio.h>

#include <stdlib.h>

using namespace std;

struct node

{

    char data;

    struct node *next, *last;

};

char ch[100100];

int main()

{

    scanf("%s",ch);

   int len=strlen(ch);

   struct node *head,*tail;

   head=(struct node *)malloc(sizeof(struct node ));

   head->data='0';

   head->next=NULL;

   head->last=NULL;

   tail=head;

   struct node *p;

   for(int i=0;i<len;i++)

   {

       p=(struct node *)malloc(sizeof(struct node ));

       p->next=NULL;

       p->last=NULL;

       p->data=ch[i];

       tail->next=p;

       p->last=tail;

       tail=p;

   }

   p=head->next->next;

   int k=0;

   while(p->next&&p)

   {

       if(p==head)

       {

           p=p->next->next;

           if(p==tail)

           {

               break;

           }

       }

       if(p==head->next)

       {

           p=p->next;

           if(p==tail)

           {

               break;

           }

       }

       if(p->last->data!=p->next->data)

       {

           struct node *z=(struct node *)malloc(sizeof(struct node));

           z=p->next;

           struct node *zz=(struct node *)malloc(sizeof(struct node ));

           zz=p->last;

           zz->next=z;

           z->last=zz;

           p=zz->last;

           k++;

       }

       if(p==tail)

       {

           break;

       }

       p=p->next;

   }

   if(k%2==1)

   {

       printf("First\n");

   }

   else

   {

       printf("Second\n");

   }

    return 0;

}