QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#703884 | #407. Toilets | TheZone | 100 ✓ | 8ms | 4080kb | C++20 | 79.9kb | 2024-11-02 18:47:13 | 2024-11-02 18:47:13 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}
/*#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
else --cnt;
mx=max(mx,cnt);
}
if(cnt>=0)Mx=max(Mx,cur+mx+1ll*cnt*(k-1));
else Mx=max(Mx,cur+mx);
cur+=cnt*k;
}
if(cur<0)return puts("-1"),0;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5;
ll n,m,k,cur,Mx;
char s[N];
int main(){
n=read(),m=read();
while(m--){
scanf("%s",s+1);
k=read();
int len=strlen(s+1);
int mx=0,cnt=0;
rep(i,1,len){
if(s[i]=='F')cnt++;
printf("%lld\n",max(0ll,Mx-cur-1));
return 0;
}*/
详细
Subtask #1:
score: 14
Accepted
Test #1:
score: 14
Accepted
time: 0ms
memory: 3948kb
input:
10 1 FMFFFFFFMFFFMMMMMFMM 1
output:
5
result:
ok single line: '5'
Test #2:
score: 14
Accepted
time: 0ms
memory: 3944kb
input:
10 1 FFMFMMFFFFMMMFMMMMFF 1
output:
3
result:
ok single line: '3'
Test #3:
score: 14
Accepted
time: 0ms
memory: 3872kb
input:
10 1 MFMMFFFMMFFMMMMFFFFF 1
output:
0
result:
ok single line: '0'
Test #4:
score: 14
Accepted
time: 0ms
memory: 3752kb
input:
10 1 FMFMFFMFMFMMFFMFMFMM 1
output:
1
result:
ok single line: '1'
Test #5:
score: 14
Accepted
time: 0ms
memory: 3536kb
input:
10 1 MFFFMFMMMMMMMMMFMFFM 1
output:
-1
result:
ok single line: '-1'
Test #6:
score: 14
Accepted
time: 0ms
memory: 3880kb
input:
10 1 FFFFFFFMMFMFMMMMFFMF 1
output:
2
result:
ok single line: '2'
Test #7:
score: 14
Accepted
time: 0ms
memory: 3860kb
input:
10 1 FMFFFFFMMMFFFMMMFMMF 1
output:
2
result:
ok single line: '2'
Test #8:
score: 14
Accepted
time: 0ms
memory: 3884kb
input:
10 1 MFFMMMMMFFFFMMFFMMFF 1
output:
0
result:
ok single line: '0'
Test #9:
score: 14
Accepted
time: 0ms
memory: 3824kb
input:
10 1 MMMMMMFMFMMMFFMFMFMM 1
output:
-1
result:
ok single line: '-1'
Test #10:
score: 14
Accepted
time: 0ms
memory: 3756kb
input:
10 1 FFFFFFFFFFFFFFFFFFFF 1
output:
0
result:
ok single line: '0'
Test #11:
score: 14
Accepted
time: 0ms
memory: 3744kb
input:
10 1 MMMMMMMMMMMMMMMMMMMM 1
output:
-1
result:
ok single line: '-1'
Test #12:
score: 14
Accepted
time: 0ms
memory: 3872kb
input:
10 1 FFFFFFFFFFFFFFFMMMMM 1
output:
4
result:
ok single line: '4'
Test #13:
score: 14
Accepted
time: 0ms
memory: 3808kb
input:
10 1 FFFFFFFFFFMMMMMMMMMM 1
output:
9
result:
ok single line: '9'
Test #14:
score: 14
Accepted
time: 0ms
memory: 3948kb
input:
10 1 FMFMFMMFFFMFFMMMFMMF 1
output:
2
result:
ok single line: '2'
Test #15:
score: 14
Accepted
time: 0ms
memory: 3948kb
input:
10 1 FFFFFFFFFFFFFMMFMMMF 1
output:
2
result:
ok single line: '2'
Test #16:
score: 14
Accepted
time: 0ms
memory: 3876kb
input:
10 1 MMMMFMFFMFMFFFFMMFFM 1
output:
0
result:
ok single line: '0'
Test #17:
score: 14
Accepted
time: 0ms
memory: 3756kb
input:
10 1 MFMMFFFMMMMFFMMFFFMF 1
output:
0
result:
ok single line: '0'
Test #18:
score: 14
Accepted
time: 0ms
memory: 3876kb
input:
10 1 MFFFFMFMFFMMFMMFMFFM 1
output:
1
result:
ok single line: '1'
Test #19:
score: 14
Accepted
time: 0ms
memory: 3868kb
input:
10 1 MFFFFFFFFFFFFMFFFFFF 1
output:
0
result:
ok single line: '0'
Test #20:
score: 14
Accepted
time: 0ms
memory: 3868kb
input:
10 1 FFFMFFMFMMFFMMMMMFMF 1
output:
3
result:
ok single line: '3'
Test #21:
score: 14
Accepted
time: 0ms
memory: 3948kb
input:
10 1 MMFMFFFMFMMMFFMFMFFM 1
output:
0
result:
ok single line: '0'
Test #22:
score: 14
Accepted
time: 0ms
memory: 3792kb
input:
10 1 FFFFFFFFFFFMFFFFMFMM 1
output:
1
result:
ok single line: '1'
Subtask #2:
score: 22
Accepted
Dependency #1:
100%
Accepted
Test #23:
score: 22
Accepted
time: 1ms
memory: 4048kb
input:
100000 1 FFFFMMMFMFFMMMFFMFFFMFFFFFMMFFMMFMFFMFFFFMFFMMFFFFFFFFMFFMFMFMFFMFMFFFFFFMFMMFMMFMFFFFFFFFFMFMFFMFFMMFMFFFMFMFFFFFFMFMFFFFMFFMFMFMFFFMFFMFFFFFMMMFFMMFFFFFFFFFFFFMFFFFMFFFFFMMMFMFFFMMFFFMFMFFMMFFFFFMFFMFFFMFFFMFFMFFMFFFMFFMMFFFFFFFMFFFFFFFFFMFFFFFFFFFFFFFFFMMFFFFFMMMMFFFFMFMMFFMFFFFFMMMMFFFF...
output:
31813
result:
ok single line: '31813'
Test #24:
score: 22
Accepted
time: 2ms
memory: 4080kb
input:
100000 1 FMFFFMFMFFMMFFMMFFMMMFMMMFMMFFMMFFFFFFMFFMFFFFMFMFFMMFMFMMMFMFMFFFMFFFFFMFFFMFFMFMMMMMFMMFMFMMMFMFMMMFFMFMMFFMMFFFMMMFFFFFFMFFFMFFMMFFFFMFFMFFFFFMMFMFFFFMMFFMMFFMMFMMMMFMFFMMMFFMMMFFMFMFFMFMFFFFMFFFFMFFMFFFFFMMMFFFMFFMFFFFFFMFFFFFMMMFMFMFFMMMMMMFFMFMMFFFFFFFMFMFFFMMFMMFMFFMMFFMMFFMMFFMMFFMM...
output:
13113
result:
ok single line: '13113'
Test #25:
score: 22
Accepted
time: 1ms
memory: 3944kb
input:
100000 1 FFFFFFMFMFFFMFFFFFFFFFFFMMMFFFMFMMFMFFFMFMMFFFMFFMFFFFMFFFMMFMMFFMFMFFMMMFFMMFFFFFMMFMFFMFMMMFFFFFFFMMFFFFFFFFFFFMFMMFMMFFFMFFFFFFFFFFFFMFMFFFFFMMFFMFMFFFFFFFFFFFMMFFFFMFFFFFMMFFFFMFMMMMFFMFMFMMFFMFMFFFMFMFMFFMFFMMFFFFFFFMFFMMFFMFMFFFFMMMMMFFFMMFFMFFFFFMFFFFFFFFFFFFFFFFFMFFMFFFFFMFFFMFFFFFF...
output:
2798
result:
ok single line: '2798'
Test #26:
score: 22
Accepted
time: 1ms
memory: 3948kb
input:
100000 1 FFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...
output:
6652
result:
ok single line: '6652'
Test #27:
score: 22
Accepted
time: 1ms
memory: 3944kb
input:
100000 1 MMMMFMMMMMMMMMMMMMMMMMMFMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMFMMMMFFMMMMMMMMMMMMMMMFMMMMMMMMMMMMFMMMMMMMMMMMMMMMMMMMMMMMMMMFMMMMMMMMMMMMMMMMMMMMMMFMMMMMFMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMFMMMMFMMMMMMMMMMMMMMMMMMMMMMMMMMM...
output:
-1
result:
ok single line: '-1'
Test #28:
score: 22
Accepted
time: 1ms
memory: 3984kb
input:
100000 1 FFFFFFFFMMFFFMMFFMFMFFFFMFMFMMMFFFFFMFMMMMFMFFMMFMFMMFFFFMFMFFFFFMFFFFFFMMFMMMMMFFFMFMFFFMMMMMMMFMMMFFFMFFFMMFMMFMFFMFFMMMFFFFMMFMMFFMFFFFMMFFFFFFFMFMFFFFFFMMMFMMFFMFMFMFMFFFFFMMFMMFMFMMFMFFMFFMFFFFFFMFFMFFFFFFFMMMFMFMMMMFFFFFFFMMFMMFFMMMFMFFFFFMMFFMFMMMMFFFMFMFMFMFFFMMMMFMMFMFFMFMMMFFMMMMM...
output:
0
result:
ok single line: '0'
Test #29:
score: 22
Accepted
time: 1ms
memory: 3980kb
input:
100000 1 FFFFFMMMFFMFFMFFFFFFMFFMFMFMMMFFFMMFFFFFFMFMFFMFFMFFFFFFFFMFMMFMFFFFFFFFFMFMFFFFFFMFFFFFMFFMFFMMMFFFFFMMMFFMFFMFMMFFFFFMFFMMFFFMMFFFFFFMMMFFFMFFMMMFFMFFFFFFMFFFMMMFFFFMFFMFFFFFFFFMFMFFMFFFFFFMFFFFFFMMFFMFMFFFFFFMFFFFMMFMFFFFFMFFMMFFMFMFFFFFFFMMFMMMFFFFFFMFFMMMFFFFFFFMFFMFFFFMMFFFFMMFFFMFMMF...
output:
0
result:
ok single line: '0'
Test #30:
score: 22
Accepted
time: 1ms
memory: 4068kb
input:
100000 1 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...
output:
39879
result:
ok single line: '39879'
Test #31:
score: 22
Accepted
time: 2ms
memory: 3944kb
input:
100000 1 FMFFMMMFMFMMMMMFMMMMMFMFMMFFMMMMMFMMMMMMMFMFFMMMFMFFFMMFFMMMFMMMMMFMMMMMMMMMMMMMMMMMFMFMFMFFFMMMFMMFFFMMMFMMFMMMMMMFMMFMMMMMMFMMMMFMMMMMMFMMFMMMFMMFMMFMMMFMFFMMMMMMMFMMMFMMMMMFMFMMFFMMFFFFFMMMMFMMFMMMMMMMFFMFFFMMMMMFMMMMMFFMMMFMFMMMFMMMMMMMMMFMMFMMMMFMMFMMMMMMMMMMMFMMMMFMFMMFMFMFMFMFMFFMMFM...
output:
0
result:
ok single line: '0'
Test #32:
score: 22
Accepted
time: 2ms
memory: 4068kb
input:
100000 1 MFMFFFFFFFFFFMFFFFFFFFMFFFFFFMMFMFFMFMFFFMFFFFMFFMFFFFFFMFFFFFFMFMFFMMFFMFMMMMMFMFFFFMFMFFMFFFMMMMFMFMMFFMMMFFFFFFMFFFMFMFFMFMFMFFFFFFFFFMFFMFMFFFFFMFMFFMFFFFMFFFFFFMFFFFFFFFFMFFMFFFMMFMFFFFMFFMMFFFFMMFFFMFFMFMFFMFMMFFMFMFFMFMFFFFFMMFFMFFMFFFFFMMFFMMFFMMFMMFFFFFFFFFFFFFFFMFFFFFMMFFFFFFMMMMF...
output:
16534
result:
ok single line: '16534'
Test #33:
score: 22
Accepted
time: 0ms
memory: 4008kb
input:
100000 1 MMMMMMMMMMMMMFMMMMMMMMFFFFMMMMMMMMMMMMMMMMMMMMMFMMMMMMMMMMMMMMMMMMMMMMMMMMMFMMMMMMMMMMMMMMMMMMMMMMMMFMMMFMMMMMMMMMMMMMFFMMMMMMFMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMFMMMMMFMMFMMMFMMMMMMMMMFMMMMMMFMMMMMMMMMMMFMFMFMMMMMMMMMMMMMMFMMMMMMMFMMMMMMMMMMMMMMMMMMMMMMFMMMMMMMMMMMMMMMMMMFMMMFMMMMMMMMMMMMMMMM...
output:
-1
result:
ok single line: '-1'
Test #34:
score: 22
Accepted
time: 1ms
memory: 4072kb
input:
100000 1 FFFFFFFFMFFFFMFFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFFMFFMFMFFFFMFMFFFFFMFFFFFFFMFFMFMFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFMFMFFFFFFFFFFFFFFFFMFFFFFMFFFFFFFFFFFFMFFFFFFFFFFMFFMFFMFMFMFFFMFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFFMFMFFMFMFFFFFFFFMFFFMFFFFFFFMMFFFMFFFFFFFFMMMFMMFFFFFFMMFFFFFFFFFFFF...
output:
1
result:
ok single line: '1'
Test #35:
score: 22
Accepted
time: 2ms
memory: 4000kb
input:
100000 1 MMMFFMFFMFFFMFMFFMMMFFFFMFMMMMFMMMFMFMMFMMFFMFFMMFMFMMMFFFMMFMMMFMMFFFMFMFMMMMFMMMMMFFFFFMFMMFMFFFFFFFMFMFFFMFMFFFFMFMFFFFMMFMMMFMMFMMFMFFMFMMMFFFFMFMMFMMMMMFMFMFFMMFFMFFMFFMFMMMFFMMFMMMFFMMMMMFMFMMMMFMMFFFMMMMMFMFMFFMFFMFMMFFMMFMMFMMFFMMFMMFFMMFMFMMMFFFMMFMFMMFFMMMFMMFMFMMFMFMMFFMMMMMMMMMF...
output:
47
result:
ok single line: '47'
Test #36:
score: 22
Accepted
time: 2ms
memory: 4072kb
input:
100000 1 MMMMFMFFMFMMFFMFFMMMFFFMFFMMMMFFFFFMMFFFFMMMFMMFFFMMFMFMMMMFMMFMMMMMFFFFMMFFMFMMFFMFFMFMFMMFFFFMMFFFMFMMFMMFMMFMFFMFFMMMMMMFMMFMFMMFFMMMFFFFMMFMFFFFMMMMMFMMMMFFMMFFFFMFMFMMFFFMFFMMFMMFMFMMFFFMMMMFMMMMFFFFFFMMMFFFMMMFMMFMFFFMFMMFFFFFFMFFFMFMFFMFMFMMMFFMMMMFFMMFMMMMFMFMFFMMMMFFMFFMFMFFFFFFFFF...
output:
29
result:
ok single line: '29'
Test #37:
score: 22
Accepted
time: 1ms
memory: 3944kb
input:
100000 1 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFMFFFFFMFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFMFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFMFFF...
output:
0
result:
ok single line: '0'
Test #38:
score: 22
Accepted
time: 1ms
memory: 3916kb
input:
100000 1 FFFFMMMFFFMFMFMFMMFFFFMMMFMFFFFFMFMMFMMMMFFFMMFMMFFMFFFFMFMFFFFMMFMMFFMFMMMFFFMMFMFFMFMFMFMFMFFMFMFFMMMFFFFMMMFFMFFFFMFFFMFMMMFFFFMFFFFMMFMFMFMFMMMMFMFMMMFMMMMFMFFFFFFMMFMMFFMFMFMFMMFMFMFFFFMMMFMMMFMMFFFMMFFMFMFMFFFMMMMFMMMFMFFMMFFMFMMFFFMFFFMFFFMFMMFMFFMMMMFMMMFFMFFFMFMMMMFFMMFMFMMMFFMFFFM...
output:
-1
result:
ok single line: '-1'
Test #39:
score: 22
Accepted
time: 1ms
memory: 4068kb
input:
100000 1 FFMMFMMMMMMFMMMFMMMMFFMMMFFMMMFFFMMFFFMMFMFMMMFFFFMFMMMMFMFMFFMMMFMMMMMFFMMFMFMMFMMMMMMMMMMMFMMMFFMMMMMFMMMMFMFFMMMMMMMFFMMMFFMMMFMMMMFMMMFFMMMFMFMMMFMMMMFMMMMFMMFFMMFMMFMMMMMMFFFMMMMMFMMFFMMMMMFMMFMMFFMMFMMMMMMMMMFMMMMFFMFMFMFMMMMMFMMMFFMFMMMFFMMMFMMMFMMMMFFMMMFFMMFMFFMMFFFMFMFMMMMMMMMMFMF...
output:
0
result:
ok single line: '0'
Test #40:
score: 22
Accepted
time: 1ms
memory: 4056kb
input:
100000 1 MFFFFFFFFFFFFFFMMFFFMFFFFFFFFFFFFFFFMFFFFFMFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFMFMFMFFFFFFMMFFFFMFFFFFFFFMFFMFMMFFFFFFFMFMMFFFFFMMFMFMMFFFFFFFFFFFFFFFFMFFFFFFFMFFFFFMFFMFFFFFFFFFMMFFFFFFFFFFFFFMFFFFFMFFMFFFFFFFMFFMFFFFMFMMFMFFMFFFMFFMFFFMFFFFFFMFMFFFFFFFFFFFMFFFFFFFFFFFMFFFFFFF...
output:
4355
result:
ok single line: '4355'
Subtask #3:
score: 64
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #41:
score: 64
Accepted
time: 8ms
memory: 3756kb
input:
1000000000000000000 100000 M 9816839753426 F 32891239202155 M 3269965263224 F 2229727361723 M 30485569651326 F 21959175763651 M 2701631477059 F 8659750955926 M 9425320424984 F 2510850084526 M 3240680154707 F 27272737860189 M 16804398749196 F 37559052071696 M 21024350278786 F 27634028774163 M 7449319...
output:
-1
result:
ok single line: '-1'
Test #42:
score: 64
Accepted
time: 8ms
memory: 3864kb
input:
1000000000000000000 100000 F 431871849268 M 59443702951207 F 16627010076045 M 15723099181340 F 1016212562479 M 18624381071488 F 23939085970272 M 15802149922508 F 17781355525450 M 60220772608868 F 2334436410290 M 65424478775450 F 6659821791902 M 37792526394974 F 1904215213263 M 6902431170813 F 306640...
output:
4564625175693371
result:
ok single line: '4564625175693371'
Test #43:
score: 64
Accepted
time: 0ms
memory: 3808kb
input:
1000000000000000000 2 F 1000000000000000000 M 1000000000000000000
output:
999999999999999999
result:
ok single line: '999999999999999999'
Test #44:
score: 64
Accepted
time: 0ms
memory: 3684kb
input:
1000000000000000000 1 M 2000000000000000000
output:
-1
result:
ok single line: '-1'
Test #45:
score: 64
Accepted
time: 0ms
memory: 3804kb
input:
1000000000000000000 1 F 2000000000000000000
output:
0
result:
ok single line: '0'
Test #46:
score: 64
Accepted
time: 0ms
memory: 3868kb
input:
999999999999625897 10000 MFFFFFFMMFFFFFFFFMMMFFMFMMFMMFFFFM 9481463695402 FFMMFFMMMFFFMMFFFFFFMMF 13845416629548 FFMMFMFFFFMMFFFMFFMFMFF 1127248235004 FFFMFMFMFF 51190587403270 M 28469634773721 FFFMFFF 58171136154277 MFMFFFFFMMFMMFFFMMFMM 702235518736 MFMFMMFMMMMFFMMFMFMF 5663028596847 FMFFFFF 98854...
output:
48756342765404973
result:
ok single line: '48756342765404973'
Test #47:
score: 64
Accepted
time: 2ms
memory: 3872kb
input:
999999999999595809 1000 FFFMFFMMFFFFMMFMFFFFMFFFMFFFMFMMFFMFFFFMFFFFMMMFMFFMMFFFFFFMMFFFFFMFFMFFFFMFFMMFFMFFFFFFFFMFMMFMFMFMFMMMFMFFMMMMMFMFFMMFMFMFFFMMFFFFFFMMMFFMFMFFFFMFFFFFMFMFFFFFFFFMFMFFFFFFFM 20644211690572 MFFMFFMFFMMMFMMMFFFFFMFMFMMFFFFMMFFFFMMFFMFMFFMFFMFMMFMFMFMFMFFFMFMFMFFMFMFMFMFMFMFFFF...
output:
43361855843647617
result:
ok single line: '43361855843647617'
Test #48:
score: 64
Accepted
time: 1ms
memory: 3816kb
input:
999999999999629923 100 FFFFFFMFMMMFFMFFMFFMMMMFFFMFFMFFMFFFFFFFFMFMFFFMMMMFFMFMFMFFMMFMMFMMFFFMFFFMMFFFMFFFFMFFMMMFFMFFFFFFFFFFFFFFFFFMFMFMMFFFFFFMFFFMMFFMMMMFFMFMFFFMMMFFMFFMMFFFMFMMFMFFMMFFMMMFFFFFFMMFFMFFMFFMFFMFFFMMFMFMMMMMMFMMMFMFMMFMFFFFFMFFMFFMMMMMMFMFFFFMFFFFFFFFFFFMFMMMFMFFFMFMMFFFFMFFFMMFF...
output:
116105901030068011
result:
ok single line: '116105901030068011'
Test #49:
score: 64
Accepted
time: 1ms
memory: 3792kb
input:
999999999999596429 1000 FFFFFFFMFFFMFFFMFFFFFMFFFFFFFFFFFFFMFFFFFFMFFMFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFMFFFFFFFFFFFFFFFFFFFFFFFF 5623186358382 FFFFFMFFFFFFFFFFFMFFFFFFFMFMFFFMFFFFFMFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFMFFFMFFFFFFFFFFFFFFFFFFFFFMFFFFFMFFFFFFFFFFFFFFFFFFFFMFFFFFFF...
output:
2
result:
ok single line: '2'
Test #50:
score: 64
Accepted
time: 1ms
memory: 3884kb
input:
999999999999600528 1000 MFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFMFMFFMFFFFFFFFFFFFFFFFFFFFFF 18080341569562 FFMFFFFFFFMFFFFFFFFFFFFFFFFFFMFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFMFFFFMFFFFFFMFFFMFFFFFFFFFFFFFFFFF 7272784578791 FFFFFFFFFFFFFFFF...
output:
0
result:
ok single line: '0'
Test #51:
score: 64
Accepted
time: 2ms
memory: 3792kb
input:
999999999999621111 10000 FFFMFFFMMMFMFMFFMFMMFMFMMFMMFFMFFFFF 10628277271023 MFMFFFFMFFMFFF 8887492969135 MMMFFFF 2644586272990 FFFFMMFMFMFFMFFMFMFF 2496144364789 M 291909886513338 F 291524001456242 FM 164405418919932 FFFFFFF 9074905740751 FFFFMMFFFMFFMFFFMFMFMMFFFFMMMFFFFFFMFFFFFFMFFF 136878159958 ...
output:
37812597593056801
result:
ok single line: '37812597593056801'
Test #52:
score: 64
Accepted
time: 7ms
memory: 3880kb
input:
1000000000000000000 100000 M 4336 F 87574242481537 M 6779118333 F 758 M 5655569015 F 234 M 1064257327 F 118182247866685 M 5 F 2191 M 393765582 F 49003480338384 M 5632535733 F 879 M 18717 F 157893 M 14 F 3390 M 11270546525108 F 302908536980945 M 122391 F 21713 M 82741927729194 F 327135083 M 1613 F 23...
output:
2552498555010739
result:
ok single line: '2552498555010739'
Test #53:
score: 64
Accepted
time: 7ms
memory: 3948kb
input:
1000000000000000000 100000 M 22306455433028 F 251664388752 M 422986735965 F 1386307 M 85742056929 F 172613196433 M 4521031117757 F 464787 M 193246 F 39855514818587 M 7 F 136254754 M 7400882520003 F 15485154 M 153940617237 F 364722 M 22316289680963 F 11976 M 1079491 F 13014001135 M 483238979363371 F ...
output:
9477487698491205
result:
ok single line: '9477487698491205'
Test #54:
score: 64
Accepted
time: 3ms
memory: 3888kb
input:
1000000000000000000 100000 F 1 M 81368184 F 7372821556 M 3511423502754 F 36990939673346 M 27275118471340 F 1036159525229 M 103517874556 F 10277806 M 215077210182670 F 990007 M 9729675541 F 143611913794622 M 331465549 F 5 M 2567195356782 F 1325115392406 M 3238481450038 F 1628627 M 3413022661677 F 233...
output:
13014205031347945
result:
ok single line: '13014205031347945'
Test #55:
score: 64
Accepted
time: 1ms
memory: 3944kb
input:
999999999999602859 494 FFFMFMFMFFFFFFFFFFFFFFF 41040784738747 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFMFFFFFFFFFFFMFFFFFFFFFFFFFFFFFMFFFFFFFFMFFFFFFFFFFFFFMFFFFFFFFFFFFFFFMFFFFMFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFFMFFFFFFF...
output:
0
result:
ok single line: '0'
Test #56:
score: 64
Accepted
time: 1ms
memory: 3800kb
input:
999999999999599725 496 FFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFMFFMFFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFMFFFFFFFFFFFFFFFFFFFFFFMFFFFFFFFFFMFFFFFFFFFFFFMFFFFFFFFFFF 85083186667613 FFFFFFFFFFFFFFFFFFFMFFFFFFFFF...
output:
34240214643235
result:
ok single line: '34240214643235'
Extra Test:
score: 0
Extra Test Passed