akhauriyash/Code-Regression huggingface dataset:
while line = STDIN.gets
  cards = line.chomp.split(',').map { |item| item.to_i }
  cards.sort!
  if (cards[0] == cards[1] and cards[0] == cards[2] and cards[0] == cards[3]) or (cards[1] == cards[2] and cards[1] == cards[3] and cards[1] == cards[4]) then
    puts "four card"
  elsif (cards[0] == cards[1] and cards[0] == cards[2] and cards[3] == cards[4]) or (cards[0] == cards[1] and cards[2] == cards[3] and cards[2] == cards[4]) then   
    puts "full house"
  elsif (cards[0]+1 == cards[1] and cards[0]+2 == cards[2] and cards[0]+3 == cards[3] and cards[0]+4 == cards[4]) or (cards[0] == 1 and cards[1] == 10 and cards[2] == 11 and cards[3] == 12 and cards[4] == 13) then
    puts "straight"
  elsif (cards[0] == cards[1] and cards[0] == cards[2]) or (cards[1] == cards[2] and cards[1] == cards[3]) or (cards[2] == cards[3] and cards[2] == cards[4]) then
    puts "three card"
  elsif (cards[0] == cards[1] and cards[2] == cards[3]) or (cards[1] == cards[2] and cards[3] == cards[4]) or (cards[0] == cards[1] and cards[3] == cards[4]) then
    puts "two pair"
  elsif cards[0] == cards[1] or cards[1] == cards[2] or cards[2] == cards[3] or cards[3] == cards[4] then
    puts "one pair"
  else
    puts "null"
  end
end

Measured memory_bytes: 8632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
/* Solution by divyanshu0x16*/
#define int           long long 
#define setbits(x)    __builtin_popcountll(x)
#define zerobits(x)   __builtin_ctzll(x)
#define mod           1000000007 
#define modulo(a, b)  (a%b<0 ? a%b+b : a%b)
#define intpow(a,b)   (int)(pow(a,b) + 0.5)
#define gcd(a,b)      __gcd(a, b)
#define all(x)        (x).begin(), (x).end()
#define ps(x, y)      fixed<<setprecision(y)<<x
#define testcase(x)   int x; cin >> x; while(x--)
#define fastIO        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef stack<int> si;
typedef queue<int> qi;
typedef priority_queue<int> pqi;


int32_t main() {
    fastIO;
    int t = 1;
    while(t--){
        int x; cin >> x;
        if( x == 1) cout << 0 << "\n";
        else cout << 1 << "\n";
    }
    return 0;
}
 

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

const int N = 3e5+5;
const int MOD = 1e9+7;
int n;
LL a[N];

int pre[N], b[N];


int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for (int i=1; i<=n; ++i) scanf("%lld", &a[i]);

	LL ans = 0; LL p2 = 1;
	for (int i=0; i<60; ++i) {
		LL cal = 0;
		for (int j=1; j<=n; ++j) {
			// pre[j] = pre[j-1];
			if ((a[j] >> i) & 1) {
				b[j] = 1;
				// pre[j]++;
			} else b[j] = 0;
			pre[j] = pre[j-1] + b[j];
			// printf("%d %d\n", j, b[j]);
		}

		// int tot = pre[n];
		for (int j=1; j<=n; ++j) {
			if (b[j] == 0) {
				cal += pre[n] - pre[j];
			} else cal += n - j - (pre[n] - pre[j]);
		}
		cal = cal % MOD * p2 % MOD;
		ans = (ans + cal) % MOD;
		p2 = (p2 << 1) % MOD;
		// printf("%lld %lld\n", cal, p2);
	}
	printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 4992
def main():
    height, width = map(int, input().split())
    change_cost = [list(map(int, input().split())) for _ in range(10)]
    grid = [list(map(int, input().split())) for _ in range(height)]
    for k in range(10):
        for i in range(10):
            for j in range(10):
                change_cost[i][j] = min(change_cost[i][j], change_cost[i][k] + change_cost[k][j])
    answer = 0
    for g in grid:
        for n in g:
            if abs(n) != 1:
                answer += change_cost[n][1]
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
w , h , n = list(map(int,input().split()))

new_w = [0] * w
new_h = [0] * h



for i in range(n):
  x , y , a = list(map(int,input().split()))
  if a == 1:
    for t in range(x):
      new_w[t] = 1
  
  elif a == 2:
    for t in range(len(new_w) - x):
      new_w[-1 - t] = 1
  
  elif a == 3:
    for t in range(y):
      new_h[-1-t] = 1
  
  else:
    for t in range(len(new_h) - y):
      new_h[t] = 1

w_long = len(new_w) - sum(new_w)
h_long = len(new_h) - sum(new_h)


print(w_long * h_long)

Measured memory_bytes: 3064
#include <bits/stdc++.h>

using namespace std;

int main(){

	int A, B;
	cin >> A >> B;

	int j = 0;

	for( int i = A; i <= B ; i++){

		if( i / 10000 == i % 10 && i /1000 % 10 == i /10 %10)

				j++;

		}


	cout << j << endl;

}

Measured memory_bytes: 3572
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

void solve() {
  int N;
  cin >> N;

  vector<int> A(N);
  int mask = 0;
  for (int &a:A) {
    cin >> a;
    mask = mask ^ a;
  }

  for (int a:A) {
    cout << (a^mask) << " ";
  }
  cout << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 3608
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
idx_B = 0
ma = 0
for idx_A, a in enumerate(A):
    while idx_B < N and B[idx_B] < a:
        idx_B += 1
    if ma < idx_A - idx_B:
        ma = idx_A - idx_B
Ans = (B+B)[N-ma-1:2*N-ma-1]
for a, b in zip(A, Ans):
    if a == b:
        print("No")
        exit()
print("Yes")
print(" ".join(map(str, Ans)))


Measured memory_bytes: 43012
#include <bits/stdc++.h>
#include <vector>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
 
using namespace std;
 
int main() {
  fast_io;

  int n, m, x;
  vector<int> v;

  cin >> n >> m;
	int sum=0;
	for(int i = 0; i < n; i++){
		cin >> x;
		v.push_back(x);
		sum += x;
	}
	double c = 1 / (4.0 * m) * sum;
	for (int i =0 ; i < n; i++) {
		if (v[i] >= c)
			m--;
	}
	if (m > 0){
		cout << "No";
	} else {
		cout << "Yes";
	}
 
  return 0;
}

Measured memory_bytes: 256
def main():
    N, K = (int(i) for i in input().split())
    V = [int(i) for i in input().split()]
    if 2*N <= K:
        ans = sum(v for v in V if v > 0)
        return print(ans)
    ans = 0
    R = min(N, K)
    for a in range(R+1):
        for b in range(R+1):
            if R < a+b:
                continue
            can_de = K - a - b
            cur_e = V[:a] + V[:-(b+1):-1]
            cur_e.sort(reverse=True)
            while cur_e and cur_e[-1] < 0 and 0 < can_de:
                cur_e.pop()
                can_de -= 1
            ans = max(ans, sum(cur_e))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39792
n,k=(int(i) for i in input().split())
r,s,p=(int(i) for i in input().split())
dic={'r':r,'s':s,'p':p}
wazap={'r':'p','s':'r','p':'s'}
rail=input()
l=[[] for i in range(k)]
ans=0
for i in range(len(rail)):
  l[i%k].append(wazap[rail[i]])
for i in range(k):
  flag=0
  ans+=dic[l[i][0]]
  for j in range(len(l[i])-1):
    if l[i][j+1]==l[i][j]:
      if flag==1:
        ans+=dic[l[i][j+1]]
        flag=0
      else:
        flag=1
    else:
      ans+=dic[l[i][j+1]]
      flag=0
print(ans)
        


Measured memory_bytes: 13428
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var nm=arr.shift().split(" ").map(Number);
var n=nm[0];
var m=nm[1];
var d=[];
for(var i=0;i<n;i++)d.push(arr.shift()-0);
var c=[];
for(var i=0;i<m;i++)c.push(arr.shift()-0);
var dp=[];
for(var i=0;i<=m;i++){
   dp[i]=[];
   for(var j=0;j<=n;j++){
      dp[i][j]=Infinity;
   }
}
dp[0][0]=0;
for(var i=0;i<m;i++){
   for(var j=0;j<n;j++){
      dp[i+1][j]=Math.min(dp[i+1][j],dp[i][j]);
      dp[i+1][j+1]=Math.min(dp[i+1][j+1],dp[i][j]+c[i]*d[j]);
   }
}
var min=Infinity;
for(var i=0;i<=m;i++){
   min=Math.min(min,dp[i][n]);
}
console.log(min);

Measured memory_bytes: 50368
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n;
	cin>>n;
    string a,b;
    for(int j=0;j<n;j++){
    	cin>>a;
        if(a=="0") break;
        int la=a.size();
        int c=0;
        for(int i=0;i<la;i++){
            if(a[i]=='0'){
                if(b=="1"){
                    c=c%5;
                    if(c==1) cout<<".";
                    if(c==2) cout<<",";
                    if(c==3) cout<<"!";
                    if(c==4) cout<<"?";
                    if(c==0) cout<<" "; 
                }
                if(b=="2"){
                    c=c%3;
                    if(c==1) cout<<"a";
                    if(c==2) cout<<"b";
                    if(c==0) cout<<"c";
                }
                if(b=="3"){
                    c=c%3;
                    if(c==1) cout<<"d";
                    if(c==2) cout<<"e";
                    if(c==0) cout<<"f";
                }
                if(b=="4"){
                    c=c%3;
                    if(c==1) cout<<"g";
                    if(c==2) cout<<"h";
                    if(c==0) cout<<"i";
                }
                if(b=="5"){
                    c=c%3;
                    if(c==1) cout<<"j";
                    if(c==2) cout<<"k";
                    if(c==0) cout<<"l";
                }
                if(b=="6"){
                    c=c%3;
                    if(c==1) cout<<"m";
                    if(c==2) cout<<"n";
                    if(c==0) cout<<"o";
                }
                if(b=="7"){
                    c=c%4;
                    if(c==1) cout<<"p";
                    if(c==2) cout<<"q";
                    if(c==3) cout<<"r";
                    if(c==0) cout<<"s";
                }
                if(b=="8"){
                    c=c%3;
                    if(c==1) cout<<"t";
                    if(c==2) cout<<"u";
                    if(c==0) cout<<"v";
                }
                if(b=="9"){
                    c=c%4;
                    if(c==1) cout<<"w";
                    if(c==2) cout<<"x";
                    if(c==3) cout<<"y";
                    if(c==0) cout<<"z";
                }
                c=0;
                b="0";
            }
            else{
                b=a[i];
                c++;
            }
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define M 1000000007
#define SI(x) scanf("%d", &x)
#define PI(x) printf("%d\n", x)
#define SL(x) scanf("%I64d", &x)
#define PL(x) printf("%I64d\n", x)
#define PB push_back
#define MP make_pair

using namespace std;

int main()
{

    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

   if(s1[s1.length()-1] == s2[0] && s2[s2.length()-1] == s3[0])
    cout << "YES" << endl;

   else cout << "NO" << endl;
}


Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
typedef long long ll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2;
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
// vector<vector<ll>> vec(100,vector<ll>(100));
struct Card{
  ll value;
  char kind;
};
void swap(ll *x,ll *y){
  ll tmp = *x;
  *x = *y;
  *y = tmp;
}
void bubblesort(ll num,struct Card card[]){
  rep(i,num){
    REP(j,0,num-i-1){
      if(card[j].value > card[j+1].value){
        swap(card[j].value,card[j+1].value);
        swap(card[j].kind,card[j+1].kind);
      }
    }
  }
  rep(i,num){
    if(i == num-1){cout << card[i].kind << card[i].value << endl;break;}
    cout << card[i].kind << card[i].value << " ";
  }
}
void selectionsort(ll num,struct Card card[]){
  rep(i,num){
    ll minj = i;
    REP(j,i+1,num){
      if(card[minj].value > card[j].value){
        minj = j;
      }
    }
    if(minj != i){
      swap(card[i].value,card[minj].value);
      swap(card[i].kind,card[minj].kind);
    }
  }
  rep(i,num){
    if(i == num-1){cout << card[i].kind << card[i].value << endl;break;}
    cout << card[i].kind << card[i].value << " ";
  }
}
int main(){
  ll n;
  cin >> n;
  struct Card card1[n],card2[n];
  rep(i,n){
    cin >> card1[i].kind >> card1[i].value;
  }
  rep(i,n){
    card2[i] = card1[i];
  }
  //
  // rep(i,n){
  //   if(i == n-1){cout << card1[i].kind << card1[i].value;break;}
  //   cout << card1[i].kind << card1[i].value << " ";
  // }
  bubblesort(n,card1);
  cout << "Stable" << endl;
  // rep(i,n){
  //   if(i == n-1){cout << card2[i].kind << card2[i].value;break;}
  //   cout << card2[i].kind << card2[i].value << " ";
  // }
  selectionsort(n,card2);
  bool isstable = true;
  rep(i,n){
    if(card1[i].kind == card2[i].kind){

    }else{
      isstable = false;
    }
  }
  if(isstable){
    cout << "Stable" << endl;
  }else{
    cout << "Not stable" << endl;
  }
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n; cin>>n;
  vector<int> vec(n);
  vector<int> correct(n);
  for (int i = 0; i < n; i++) {
    if(i==0) correct.at(0)=1;
    else {
      correct.at(i) = correct.at(i-1)+1;
    }
  }
  int cnt=0;
  for (int i = 0; i < n; i++) {
    cin>>vec.at(i);
    if (vec.at(i) != correct.at(i)) cnt++;
  }
  if (cnt==2 || cnt==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

// 素因数分解
vector<pll> prime_factor(ll n){
  vector<pll> res;
  for(ll i=2; i*i<=n; ++i){
    if(n%i!=0){
      continue;
    }
    ll num=0;
    while(n%i==0){
      ++num;
      n/=i;
    }
    res.push_back(pii(i, num));
  }
  if(n!=1){
    res.push_back(pii(n, 1));
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  ll n;
  cin>>n;
  vector<pll> res=prime_factor(n);
  ll ans=0;
  for(auto xy : res){
    ll x=xy.first, y=xy.second;
    // DEBUG(x);DEBUG(y);
    ll cur=1;
    while(y>0){
      if(y<cur){
        break;
      }
      ++ans;
      y-=cur;
      ++cur;
    }
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
ll N;
vector<ll> paths[100500];
ll dist[3][100500];

void dfs(int idx, int now, int from) {
    for(auto to : paths[now]) {
        if(to == from) continue;
        dist[idx][to] = dist[idx][now] + 1;
        dfs(idx, to, now);
    }
}

ll imos[100500];
ll OK[100500];

int main() {
    cin >> N;
    for(int i = 0; i < N - 1; i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        paths[a].push_back(b);
        paths[b].push_back(a);
    }
    dist[0][0] = 0;
    dfs(0, 0, -1);
    ll c[2];
    c[0] = 0;
    for(int i = 0; i < N; i++) {
        if(dist[0][i] > dist[0][c[0]]) c[0] = i;
    }
    dist[0][c[0]] = 0;
    dfs(0, c[0], -1);
    c[1] = 0;
    for(int i = 0; i < N; i++) {
        if(dist[0][i] > dist[0][c[1]]) c[1] = i;
    }
    dfs(1, c[1], -1);
    ll d = dist[1][c[0]];
    for(int i = 0; i < N; i++) {
        if(dist[0][i] + dist[1][i] == d) continue;
        //cerr << i << endl;
        vector<ll> tmp(3);
        tmp[0] = (dist[0][i] + dist[1][i] - d) / 2;
        tmp[1] = dist[0][i] - tmp[0];
        tmp[2] = dist[1][i] - tmp[0];
        sort(tmp.begin(), tmp.end());
        //cerr << tmp[0] << " " << tmp[1] << " " << tmp[2] << endl;
        do {
            ll now = min(tmp[1], tmp[2]);
            imos[tmp[0] + now]++;
            if(now == tmp[0]) {
                OK[now+tmp[0]]--;
            }
        } while(next_permutation(tmp.begin(), tmp.end()));
    }
    for(int i = 1e5; i >= 0; i--) {
        imos[i] += imos[i+1];
    }
    string ans;
    for(int i = 0; i < N; i++) ans.push_back('1');
    for(int i = 3; i <= N; i++) {
        if(imos[i] + OK[i] > 0) {
            ans[i-1] = '0';
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 18996
n = int(input())
s = input()
ans = 0
ans_list = []

R_index = []
G_index = []
B_index = []

for i in range(n):
    if s[i] == 'R':
        R_index.append(i)
    elif s[i] == 'G':
        G_index.append(i)
    elif s[i] == 'B':
        B_index.append(i)

ans = len(R_index) * len(G_index) * len(B_index)

for j in range(1, n-1):
    for i in range(min(n-j-1,j)+1):
        # print(j,i)
        # print(min(n-j-1,j))
        #
        # print(s[j-i],s[j],s[j+i])
        if s[j-i] != s[j] and s[j] != s[j+i] and s[j-i] != s[j+i]:
            # print('here')
            ans -= 1

print(ans)


Measured memory_bytes: 9264
#include <stdio.h>
 
int main()
{
    int a,b,i,sum=0;
    scanf("%d %d",&a,&b);
    char s[a+b+1];
    scanf("%s",s);
    for(i=0;i<a+b+1;i++){
        if(i!=a){
            if(s[i]>='0' && s[i]<='9')
            {sum++;}
        } else if(s[i]=='-')
        {sum++;}
    }
    (sum==a+b+1)? printf("Yes\n"): printf("No\n");
    return 0;
}

Measured memory_bytes: 2080
#include <iostream>
#include <vector>
using namespace std;
int cx[7][3]={{1,0,1}, {0,0,0}, {1,2,3}, {-1,0,-1}, {1,1,2}, {0,1,1}, {1,-1,0}};
int cy[7][3]={{0,1,1}, {1,2,3}, {0,0,0}, {1,1,2}, {0,1,1}, {1,1,2}, {0,1,1}};

int main(){
	char field[8][8];
	while(cin >> field[0][0]){
		for(int i=0; i<8; i++){
			for(int j=0; j<8; j++){
				if(i==0 && j==0) continue;
				cin >> field[i][j];
			}
		}
		int sx=-1, sy=-1;
		vector<int> x,y;
		for(int i=0; i<8; i++){
			for(int j=0; j<8; j++){
				if(field[i][j]=='1'){
					if(sx==-1){
						sx = j;
						sy = i;
					}else{
						x.push_back(j-sx);
						y.push_back(i-sy);
					}
				}
			}
		}
		
		for(int i=0; i<7; i++){
			bool flag = true;
			for(int j=0; j<3; j++){
				if(cx[i][j]!=x[j] || cy[i][j]!=y[j]){
					flag = false;
					break;
				}
			}
			if(flag){
				cout << (char)('A'+i) << endl;
				break;
			}
		}
	}
    return 0;
}

Measured memory_bytes: 3144
import java.util.*;

public class Main {
	public static void printArray(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + ", ");
		}
		System.out.println();
	}

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static class Triple implements Comparable<Triple> {
	// 	public int A, B, C;
	// 	Triple(int A, int B, int C) {
	// 		this.A = A;
	// 		this.B = B;
	// 		this.C = C;
	// 	}

	// 	@Override
	// 	public String toString() {
	// 		return String.format("(%d, %d, %d)", A, B, C);
	// 	}

	// 	@Override
	// 	public int compareTo(Triple o) {
	// 		int a = this.A - o.A;
	// 		if (a != 0) return a;
	// 		int b = this.B - o.B;
	// 		if (b != 0) return b;
	// 		return this.C - o.C;
	// 	}
	// }

	static final int MOD = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		boolean[] B = new boolean[N + 1];

		int[] A = new int[M];
		for (int i = 0; i < M; i++) {
			int n = sc.nextInt();
			B[n] = true;
		}

		int[] X = new int[N + 1];
		X[0] = 1;
		X[1] = B[1] ? 0 : 1;
		for (int i = 2; i <= N; i++) {
			if (B[i]) continue;
			X[i] = (X[i - 2] + X[i - 1]) % MOD;
		}
		// printArray(X);
		System.out.println(X[N]);
	}
}


Measured memory_bytes: 50600
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define MAX 100000
#define pb push_back
#define mp make_pair
#define INF (1LL<<62)
#define MOD 1000000007
typedef long long Int;
typedef pair<Int,Int> pii;
typedef vector<Int> vi;
typedef vector<pii> vii;
int cr,cp;
int win,los;
void check(char ch,char ch2)
{
    if (ch=='p'&&ch2=='g')
        ++win;
    if (ch=='g'&&ch2=='p')
        ++los;
}
int main()
{
    string S;
    cin>>S;
    for (int i=0;i<S.size();++i)
    {
        if (cr==cp)
        {
            ++cr;
            check('g',S[i]);
        }
        else
        {
            ++cp;
            check('p',S[i]);
        }
    }
    cout<<win-los;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int X=sc.nextInt();
        int t=sc.nextInt();
        if(X>=t){
            System.out.println(X-t);
        }else{
            System.out.println(0);
        }

        
        
        
     
    }
}

Measured memory_bytes: 19796
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

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

int main(){
    int M,N;
    cin>>N>>M;
    double total=0;
    vector<int> item;
    forn(i,N){
        int tmp;
        cin>>tmp;
        total+=tmp;
        item.push_back(tmp);
    }
    int count = 0;
    forn(i,N){
        if( item[i] >= total/(4*M) ){
            ++count;
        }
    }
    
    if(count >= M )
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
n,a,b = map(int, input().split())

minboth = 100
maxboth = 0

def ok(x):
    if x > min(a, b):
        return False
    if a + b - x > n:
        return False
    return True

for both in range(n + 1):
    if ok(both):
        minboth = min(minboth, both)
        maxboth = max(maxboth, both)
print(maxboth,minboth)
        

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

class SegTree {
public:
	enum { N = 8192 };
	SegTree() : val(2*N-1), idx(2*N-1) {}
	void init(){
		for(int i=0;i<val.size();i++){
			val[i] = idx[i] = 0;
		}
	}
	void setVal(int v, int i){
		int t = i + N - 1;
		val[t] = v;
		idx[t] = i;
		while(t){
			t = (t-1)/2;
			if(val[t] < v){
				val[t] = v;
				idx[t] = i;
			}
		}
	}
	pair<int, int> get(int l, int r, int p=0, int a=0, int b=N){
		if(b <= l || r <= a) return make_pair(-1, -1);
		if(l <= a && b <= r) return make_pair(val[p], idx[p]);
		return max(get(l, r, 2*p+1, a, (a+b)/2), get(l, r, 2*p+2, (a+b)/2, b));
	}
private:
	vector<int> val;
	vector<int> idx;
};

long long cost[5001][5001];
SegTree seg;

void update(int l, int r){
	if(l >= r) return;
	pair<int, int> p = seg.get(l, r);
	cost[l][p.second] += p.first;
	cost[l][r] -= p.first;
	cost[p.second+1][p.second] -= p.first;
	cost[p.second+1][r] += p.first;
	update(l, p.second);
	update(p.second+1, r);
}

int main(){
	int N, M;
	long long A[5000];
	static long long B[5000][200];
	while(cin >> N >> M){
		for(int i=0;i<=N;i++){
			for(int j=0;j<N;j++) cost[i][j] = 0;
		}
		A[0] = 0;
		for(int i=1;i<N;i++) cin >> A[i];
		for(int i=1;i<N;i++) A[i] += A[i-1];
		for(int i=0;i<N;i++){
			for(int j=0;j<M;j++) cin >> B[i][j];
		}
		for(int i=0;i<M;i++){
			seg.init();
			for(int j=0;j<N;j++) seg.setVal((int)B[j][i], j);
			update(0, N);
		}
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++) cost[i][j+1] += cost[i][j];
		}
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++) cost[j+1][i] += cost[j][i];
		}
		long long res = 0;
		for(int i=0;i<N;i++){
			for(int j=i;j<N;j++){
				res = max(res, cost[i][j] - A[j] + A[i]);
			}
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 203648
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std;

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"

int main()
{
	int x, y = 0;
	cin >> x >> y;

	if ((x == 2 && y == 2))
	{
		COUT("Yes");
	}
	else if ((x == 4 || x == 6 || x == 9 || x == 11) && (y == 4 || y == 6 || y == 9 || y == 11))
	{
		COUT("Yes");
	}
	else if ((x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) && (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12))
	{
		COUT("Yes");
	}
	else
	{
		COUT("No");
	}

	return 0;
}

Measured memory_bytes: 256
value = int(input())
kyu_rated = 8
lvalue = 400
rvalue = 599
for i in range(0, 8):
    if lvalue <= value <= rvalue:
        print(kyu_rated)
        flag = 1
        break
    else:
        lvalue += 200
        rvalue += 200
        kyu_rated -= 1


Measured memory_bytes: 9020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, Y;
	cin >> N >> Y;

	int x = -1;
	int y = -1;
	int z = -1;

	rep(i, N + 1) {
		for (int ii = 0; ii + i < N + 1; ii++) {
			int goukei = 10000 * i + 5000 * ii + 1000 * (N - i - ii);
			if (goukei == Y) {
				x = i;
				y = ii;
				z = N - i - ii;
			}
			if (i == 2000) ce(goukei);
		}
	}

	cosp(x);
	cosp(y);
	co(z);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ull;
typedef long long int ll;
typedef pair<ll, ll> P;

ll N;
map<ll, ll> primes;

void prime(ll n){
	for(ll p=2;p<=sqrt(n);p++){
		if(n%p==0){
			primes[p]++;
			prime(n/p);
			return;
		}
	}
	if(n>1){
		primes[n]++;
	}
}
int main()
{
	cin >> N;
	prime(N);
	ll ans = 0;
	for(ll i=2;i<=sqrt(N);i++){
		if(primes[i]>0){
			REP(j,primes[i]){
				N/=i;
			}
			ll x = floor(sqrt(2*primes[i]));
			if(x*(x+1)/2<=primes[i]){
				// cout << "i=" << i << ",ans+=" << x << endl;
				ans += x;
			}else if((x-1)*x/2<=primes[i]){
				// cout << "i=" << i << ",ans+=" << x-1 <<endl; 
				ans += x-1;
			}
		}
	}
	if(N>1){
		if (primes[N] > 0)
		{
			ll x = floor(sqrt(2 * primes[N]));
			if (x * (x + 1) / 2 <= primes[N])
			{
				// cout << "i=" << N << ",ans+=" << x << endl;
				ans += x;
			}
			else if ((x - 1) * x / 2 <= primes[N])
			{
				// cout << "i=" << N << ",ans+=" << x-1 << endl;
				ans += x - 1;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 66228
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 100;

int n, m, u, v, par[N], in[N];
vector<int> nei[N];
queue<int> q;

void del(int v) {
	for (int u: nei[v]) {
		in[u]--;
		if(in[u] == 0) {
			par[u] = v;
			q.push(u);
		}
	}
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n - 1 + m; i++) {
    	cin >> u >> v;
    	nei[u].push_back(v);
    	in[v]++;
    }
    for (int i = 1; i <= n; i++)
    	if(in[i] == 0)
    		q.push(i);
    while(q.size())
    	del(q.front()), q.pop();
    for (int i = 1; i <= n; i++)
    	cout << par[i] << ' ';
    return 0;
}

Measured memory_bytes: 7040
#include<stdio.h>
  int a[100],S[100][10000],T[50000];
int main(void){
  int i,j=0;
  int n,q,count=0;
  int t, x;
  int y=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
 	scanf("%d",&x);
	t=x%100;
	S[t][a[t]]=x;
	a[t]++;
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<q;i++){
    t=T[i]%100;
    for(j=0;j<a[t];j++){
      if(T[i]==S[t][j]){
	count++;
	break;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1344
even = input()
odd = input()
if (len(even) - len(odd)) % 2 == 0:
    for i in range(len(even)):
        print(even[i], odd[i], sep="", end="")
else:
    for i in range(len(even)-1):
        print(even[i], odd[i], sep="", end="")
    print(even[-1])

Measured memory_bytes: 3060
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int n, m;

vi adj[100010];
int in[100010];
int dp[100010];

int solve(int u) {
    if(dp[u] != -1) return dp[u];
    dp[u] = 0;
    for(int v : adj[u]) {
        dp[u] = max(dp[u], 1 + solve(v));
    }
    return dp[u];
}

int main() {
    ios_base::sync_with_stdio(false);
    memset(dp, -1, sizeof dp);
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].PB(b);
        in[b]++;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(in[i] == 0) {
            ans = max(ans, solve(i));
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 9600
#include<stdio.h>
int main(){
  int W,H,x,y,r;
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  if(x-r>=0 && y-r>=0 && x+r<=W && y+r<=H) printf("Yes\n");
  else printf("No\n");

  return 0;
}

Measured memory_bytes: 584
#include <stdio.h>

int main(void)
{
	int N;
  	scanf("%d",&N);
  	if(N%2 == 0)
    {
      //もし偶数ならばそのまま割ったやつをNで割って割合を出す
      //偶数の数÷2
      //ex) 8-> (8/2)/8 = 0.5
      double res = (N/2)/(double)N;
    	printf("%lf",res);
    }
    else
    {
      //もし奇数ならばそのまま割ったやつをNで割ってそれに1を足す割合を出す
      //偶数の数+1÷2
      //5 -> (5/2)=2
      // (2+1) / 5 = 0.6 
      double res = ((N/2)+1)/(double)N;
      	printf("%lf",res);
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<queue>
#include<string>
using namespace std;
int main(){
  int n, q;  
  cin >> n >> q;

  queue< pair<string,int> > que;
  string name;
  int time;

  for(int i = 0; i < n; i++){
    cin >> name >> time;
    que.push(make_pair<string,int>(name,time));
  }
  
  int cnt = 0;

  while(!que.empty()){
    pair<string,int> p = que.front();
    que.pop();

    if(p.second <= q){
      cnt += p.second;
      cout << p.first << " " << cnt << "\n";
    }else{
      p.second -= q;
      cnt += q;
      que.push(p);
    }
    
  }
}

Measured memory_bytes: 4404
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,W;
    cin>>n>>W;
    ll w[n+1],v[n+1];
    for(ll i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    ll a[n+1][W+1];
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=W;j++)
        {
            if(i==0 || j==0){
                a[i][j]=0;
                continue;
            }
            if(j-w[i]<0)
            {
                a[i][j] = a[i-1][j];
            }
            else{
                a[i][j] = max(a[i-1][j],v[i]+a[i-1][j-w[i]]);
            }
            
        }
    }
    cout<<a[n][W];
    return 0;
}

Measured memory_bytes: 79104
#!/usr/bin/env python3
import sys

def solve(nA: int, nB: int, M: int, A: "List[int]", B: "List[int]", x: "List[int]", y: "List[int]", c: "List[int]"):

    cheapest = -1 


    for m in range(M):
        price = A[x[m]-1] + B[y[m]-1] - c[m] 
        if cheapest == -1 or cheapest >= price:
            cheapest = price

    if cheapest >= min(A)+min(B):
        cheapest = min(A)+min(B)

    print(cheapest)
    
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(A, B, M, a, b, x, y, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 24740
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int arr[N] = {};
int vis[N] = {};
int main() {
    int n;
    long long k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    int dfn = 1, now = 1;
    while (k) {
        if (vis[now]) break;
        vis[now] = dfn++;
        now = arr[now];
        k--;
    }
    k %= (dfn - vis[now]);
    while (k--) {
        now = arr[now];
    }
    cout << now << '\n';
    return 0;
}

Measured memory_bytes: 5180
#include <stdio.h>
#include <stdlib.h>
int main(void){

  	int X;
  		scanf("%d",&X);
  	
  	int Y;
  		scanf("%d",&Y);
  
  	int Z;
  		scanf("%d",&Z);
  
  printf("%d %d %d",Z,X,Y);
  
  return 0;

}

Measured memory_bytes: 128
// In the name of God
#include <bits/stdc++.h>

using namespace std;
#define Size(x) ((int)(x).size())
#define pb push_back
#define LD_OUT setprecision(12) << fixed
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int INF = 1e9 + 10 , MOD = 1e9 + 7;
const int MN = 1e5 + 10;

struct mat{
	int a[4][4];
	mat(bool f=false){
		for(int i=0;i<4;++i)
			for(int j=0;j<4;++j)
				if(i != j) a[i][j] = 0;
				else a[i][j] = f;
	}
	void print(){
		for(int i=0;i<4;++i){
			for(int j=0;j<4;++j) cout << a[i][j] << ' ';
			cout << '\n';
		}
		cout << "======\n";
	}
}Base;

void ok(int &x){
	if(x >= MOD) x -= MOD;
}

mat operator * (const mat &A,const mat &B){
	mat ret;
	for(int i=0;i<4;++i)
		for(int j=0;j<4;++j)
			for(int l=0;l<4;++l)
				ret.a[i][j] += 1ll*A.a[i][l]*B.a[l][j]%MOD , ok(ret.a[i][j]);
	return ret;
}

mat bpw(const mat &A,int b)
{
	if(!b) return mat(1);
	mat T = bpw(A , b/2);
	T = T*T;
	if(b&1) return T*A;
	return T;
}

int n , m , arr[MN] , cur[4] , New[4];

int main()
{
	ios_base :: sync_with_stdio(false) ,cin.tie(0) , cout.tie(0);
	cin >> n >> m;
	for(int i=0;i<m;++i) cin >> arr[i];
	cur[0] = 1;
	
	Base.a[0][0] = Base.a[0][3] = 1;
	Base.a[1][0] = Base.a[1][1] = Base.a[1][3] = 1;
	Base.a[2][0] = Base.a[2][2] = Base.a[2][3] = 1;
	Base.a[3][0] = Base.a[3][1] = Base.a[3][2] = 1;
	Base.a[3][3] = 2;


	int lst = -1;
	arr[m] = n;
	for(int i=0;i<=m;++i){
		mat Me = bpw(Base , arr[i] - lst - 1);
		lst = arr[i];
		memset(New , 0 , sizeof New);
		for(int i=0;i<4;++i)
			for(int j=0;j<4;++j)
				New[i] += 1ll*Me.a[i][j]*cur[j]%MOD  , ok(New[i]);
		cur[0] = New[0];
	   	cur[1] = New[1] + New[0] , ok(cur[1]);
	   	cur[2] = New[2] + New[0] , ok(cur[2]);
	   	cur[3] = New[2] + New[1] , ok(cur[3]) , cur[3] += New[0] , ok(cur[3]);
		cur[3] += New[3] , ok(cur[3]);
	}
	cout << New[3] << '\n';
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; i++){
        cin >> L[i];
    }

    sort(L.begin(), L.end(), greater<int>());

    long long ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            for(int k = j + 1; k < N; k++){
                if(L[i] < L[j] + L[k] && L[j] < L[k] + L[i] && L[k] < L[i] + L[j]){
                    ans++;
                }else{
                    break;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

struct Edge{
	int src,dst,weight;
	Edge(){}
	Edge(int s,int d,int w):src(s),dst(d),weight(w){}
};
typedef vector<vector<Edge>> Graph;

int main()
{
	for(int n;cin>>n && n;){
		Graph g(n);
		for(int u=0;u<n;u++)
			for(int j=0;j<2;j++){
				int v,w; cin>>v>>w;
				g[u].emplace_back(u,v,w);
			}
		
		int res=1;
		vector<int> vis(n);
		for(int i=0;i<n;i++) if(!vis[i]){
			vector<int> ws;
			int p=-1,u=i;
			do{
				vis[u]=1;
				for(auto e:g[u]) if(e.dst!=p){
					ws.push_back(e.weight);
					p=u,u=e.dst;
					break;
				}
			}while(u!=i);
			(res*=count(begin(ws),end(ws),*max_element(begin(ws),end(ws))))%=10007;
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1900
#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n;
  cin >> n;
  int x;
  int arr[n];
  for(int i = 0 ; i < n ; i++) {
    cin >> x;
    arr[x - 1] = i;
  }
  if(n == 1) {
    cout << 0 << endl;
    return 0;
  }
  int mx = 0 , cur = 1;
  for(int i = 1 ; i < n ; i++) {
    if(arr[i - 1] < arr[i]) cur++;
    else cur = 1;
    mx = max(mx , cur);
  }
  cout << n - mx << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>

int main() {
	int A, B;
	std::cin >> A >> B;
	if (std::max(A, B) <= 8) {
		std::cout << "Yay!" << std::endl;
	} else {
		std::cout << ":(" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

bool dp[2][4010][20100];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  string s;
  int x, y;
  cin >> s >> x >> y;
  int n = s.size(), cnt = 0;
  rep(i, n) if (s[i] == 'F') cnt++; else break;
  x -= cnt;
  if (cnt == n) {
    if (x == 0 && y == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
  }
  vi32 op[2];
  {
    int t = 0, c = 0;
    repi(i, cnt, n) {
      if (s[i] == 'F') c++;
      else {
        op[t].push_back(c);
        c = 0; t = 1 - t;
      }
    }
    op[t].push_back(c);
  }
  dp[0][0][10000] = true;
  dp[1][0][10000] = true;
  rep(i, 2) rep(j, op[i].size()) rep(k, 20010) {
    if (!dp[i][j][k]) continue;
    dp[i][j + 1][k + op[i][j]] = true;
    dp[i][j + 1][k - op[i][j]] = true;
  }
  if (dp[0][op[0].size()][10000 + x] && dp[1][op[1].size()][10000 + y]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 154496
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s,t;
  cin >> s;
  t=s;
  reverse(all(t));
  if(s==t) pr("Yes");
  else pr("No");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();

        ArrayList<Character> cha = new ArrayList<>();
        for(char c: str.toCharArray()){
            cha.add(c);
        }

        String out = new String();
        if(cha.contains('A')&&cha.contains('B')) {
            out = "Yes";
        } else {
            out = "No";
        }

        System.out.println(out);
        sc.close();
    }
}

Measured memory_bytes: 22228
#include<bits/stdc++.h>
using namespace std;

int aidx,ah,bidx,bh;
vector<int> pile[105];
int m;

void put_floor(int x){
  
  for(int i=0;i<m;i++)
    if(!pile[i].size()){
      pile[i].push_back(x);
      return;
    }
  
}

void get_place_a(int x){
  
  for(int i=0;i<m;i++){
    for(int j=0;j<pile[i].size();j++){
      
      if(pile[i][j]==x){
	
	aidx=i;
	ah=j;
	return;
      }
      
    }
  }
  
}

void get_place_b(int x){
  
  for(int i=0;i<m;i++){
    for(int j=0;j<pile[i].size();j++){
      
      if(pile[i][j]==x){
	
	bidx=i;
	bh=j;
	return;
      }
    }
  }
  
}


int main(){

  while(1){

    cin>>m;
    if(!m)break;

    for(int i=0;i<m;i++)pile[i].clear();
    
    for(int i=0;i<m;i++) pile[i].push_back(i+1);
    
    while(1){
      
      int a,b;
      
      cin>>a>>b;
      if(!a)break;
      
      if(!b){
	
	get_place_a(a);
	
	if(ah==0)continue;
	
	for(int i=pile[aidx].size()-1;i>=ah;i--){
	  
	  put_floor(pile[aidx][i]);
	  
	  pile[aidx].erase(pile[aidx].end()-1);
	  
	}
	
      }else{
	
	get_place_a(a);
	
	get_place_b(b);
	
	if(aidx==bidx&&ah>=bh)continue;

	for(int i=pile[aidx].size()-1;i>ah;i--){
	  
	  put_floor(pile[aidx][i]);
	  
	  pile[aidx].erase(pile[aidx].end()-1);
	  
	}
	
	pile[aidx].erase(pile[aidx].end()-1);
	//pile[aidx].erase( pile[aidx].begin()+ah );
	
	get_place_b(b);
	
	pile[bidx].push_back(a);
	
      }
      
    }

    vector<int> ans;
    
    for(int i=0;i<m;i++) ans.push_back(pile[i].size());
    
    sort(ans.begin(),ans.end());
    
    for(int i=0;i<m;i++){
      if(ans[i]==0)continue;
      cout<<ans[i]<<endl;
    }
    cout<<"end"<<endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 3016
n,k = map(int,input().split())
s = list(input())
def ranl(lst):
    ans = []
    cnt = 1
    ini = lst[0]
    for i in range(1, len(lst)):
        if ini == lst[i]:
            cnt += 1
        else:
            ans.append(cnt)
            cnt = 1
            ini = lst[i]
    ans.append(cnt)
    return ans
s = ranl(s)
if len(s)//2 <= k:
    print(n-1)
else:
    cnt = 0
    cnt += sum(s[0:2*k+1]) - 1
    for i in range(2*k+1, len(s)):
        cnt += s[i]-1
    print(cnt)



Measured memory_bytes: 49804
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n;
  cin>>n;
  vector<int> t(n);
  rep(i,n) cin>>t[i];
  int m;
  cin>>m;
  vector<int> p(m);
  vector<int> x(m);
  rep(i,m) cin>>p[i]>>x[i];
  int s=accumulate(t.begin(),t.end(),0);
  rep(i,m) {
    cout << s-t[p[i]-1]+x[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  cin >>N;
  int a=0;

  for(int i=0; i<N; i++){
    int l,r;
    cin >>l >>r;
    int b=r-l+1;    
    a += b;
  }
  
  cout <<a <<endl;
}


Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  std::string s;
  std::cin>>s;

  ll ans=0;

  ll n=s.size();

  rep(i,0,n/2){
    if(s[i]!=s[n-1-i])ans++;
  }

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;

int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    
    ll ans = 0;
    for(ll i = 1; i <= N; i++){
        st i_st = to_string(i);
        ll sum = 0;
        for(auto& j : i_st){
            st j_st{j};
            sum += stoi(j_st);
        }
        if(sum >= A && sum <= B) ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] dist = new int[10][10];
		for (int i = 0; i < 10; i++) {
		    for (int j = 0; j < 10; j++) {
		        dist[i][j] = sc.nextInt();
		    }
		}
		for (int i = 0; i < 10; i++) {
		    for (int j = 0; j < 10; j++) {
		        for (int k = 0; k < 10; k++) {
		            dist[j][k] = Math.min(dist[j][k], dist[j][i] + dist[i][k]);
		        }
		    }
		}
		long total = 0;
		for (int i = 0; i < h; i++) {
		    for (int j = 0; j < w; j++) {
		        int x = sc.nextInt();
		        if (x != -1) {
		            total += dist[x][1];
		        }
		    }
		}
        System.out.println(total);
   }
}




Measured memory_bytes: 45484