akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int A,B;
    cin >> A >> B;
    int hordeng = 2 * B;
    int ans = A - hordeng;

    if(ans < 0){
        ans = 0;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

    int N;
    cin >> N;
    int A[N];
    map<ll, ll> m;
    m[0]++;
    ll sum = 0;
    rep(i, 0, N) {
        cin >> A[i];
        sum += A[i];
        m[sum]++;
    }

    ll rsl = 0;
    for(auto it = m.begin(); it != m.end(); it++) {
        rsl += (it->second * (it->second - 1)) / 2;
    }

    cout << rsl << endl;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

int n;  cin>>n;

  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(i*j==n){
        cout<<"Yes"<<endl;
        return 0;

      }
    }
  }
        cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <cstring>
using namespace std;


char s[200010];
int main(){
    scanf("%s",s);
    int len=strlen(s);
    int sum=0;
    for(int i=0;i<len;i++)sum+=s[i]-'0';
    if(sum%9==0){
        puts("Yes");
    }else{
        puts("No");
    }
}


Measured memory_bytes: 3848
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		int ans;
		
		int a = K - 1;
		int b = N - 1;
		
		ans = power(a, b);
		
		System.out.println(K * ans);
	}
	
	static int power(int a, int b) {
		int c = 1;
		if(1 <= b) {
			for(int i = 0; i < b; ++i) {
				c = c * a;
			}
		}
		return c;
	}
}

Measured memory_bytes: 35656
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll A,B,C;
    cin >> A >> B >> C;
    if(A + B >= C - 1){
        cout << B + C << endl;
    }else{
        cout << A + 2 * (B) + 1 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  string S, T;
  cin >> S >> T;

  int ans = T.size();

  for (int start = 0; start <=S.size() - T.size(); start++)
  {
    int diff = 0;
    for (int i = 0; i < T.size(); i++)
    {
      if (T[i] != S[start + i])
      {
        diff ++;
      }
    }
    ans = min(ans, diff);
  }

  cout << ans << endl;

}


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

#define pb push_back

typedef long long ll;

char asd[10]={'.','.','#','#'};
char dsa[10]={'.','#','.','#'};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int r;
	cin>>r;
	string a="";
	string s="";
	string z,x;
	char c;
	bool cek=false;
	for(int q=1;q<420;q++)
	{
		if(a.size()==r)break;
		
		if(!cek)
		{
			int cnt=0;
			for(int q=0;q<4;q++)
			{
				z=a;
				x=s;
				z+=asd[q];
				x+=dsa[q];
				cout<<z<<endl;
				cout<<x<<endl;
				cin>>c;
				if(c=='T')
				{
					a=z;
					s=x;
					break;
				}
				cnt++;
				
			}
			if(cnt==4)
			cek=true;
		}
		if(cek)
		{
			for(int q=0;q<4;q++)
			{
				z=asd[q]+a;
				x=dsa[q]+s;
				cout<<z<<endl;
				cout<<x<<endl;
				cin>>c;
				if(c=='T')
				{
					a=z;
					s=x;
					break;
				}
			}
		}
			
	}
	cout<<a<<endl;
	cout<<s<<endl;
	string d;
	cin>>d;
	
}

Measured memory_bytes: 724
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;

static const llong NIL =-1;

int main(void) {
  llong N, M;
  cin >> N >> M;

  vector<pair<llong, llong>> AB(N);
  vector<int> done(N);
  priority_queue<llong> PQ;

  for(llong i=0;i<N;i++) {
    cin >> AB.at(i).first >> AB.at(i).second;
  }

  llong ans = 0, begin = 0;
  sort(AB.begin(), AB.end());

  for(llong i=M-1;i>=0;i--) {
    for(llong j=begin;j<N;j++) {
      if(AB.at(j).first==M-i) {
        PQ.push(AB.at(j).second);
        begin++;
      }
      else break;
    }
    if(!PQ.empty()) { 
      ans += PQ.top(); PQ.pop();
    }
  }

  cout << ans << endl;

  return (0);
}


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

int main(){
    int h,w;cin>>h>>w;
    string a[h];

    for(int i=0;i<h;i++){
        cin>>a[i];
    }

    for(int i=0;i<w+2;i++){
        cout<<"#";
    }
    cout<<endl;

    for(int i=0;i<h;i++){
        cout<<"#";
        cout<<a[i];
        cout<<"#"<<endl;
    }

    for(int i=0;i<w+2;i++){
        cout<<"#";
    }
    cout<<endl;
}

Measured memory_bytes: 256
box={}
n=int(input())
for i in range(n):
    v=input()
    if v in box:
        box[v]+=1
    else:
        box[v]=1
m=max(box.values())
f=[k for k,v in box.items() if v==m]
f.sort()
print('\n'.join(f))

Measured memory_bytes: 36692
def main():
    n = int(input())
    p_lst = list(map(int, input().split()))
    count = 0

    tmp = 0
    for i in range(n):
        p = p_lst[i]

        if p == (i + 1):
            if tmp == 1:
                tmp = 0
            else:
                count += 1
                tmp += 1
        else:
            tmp = 0

    print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 20652
//#define ONLINE_JUDGE
#define rush()        \
    int MYTESTNUM;    \
    cin >> MYTESTNUM; \
    while (MYTESTNUM--)
#define FOR(i, s, t) for (int i = (s); i <= (t); ++i)
#define mem(a, b) memset(a, b, sizeof(a))
#define pi acos(-1)
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1 << 30;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 10;
int n, num[maxn];
vector<int> a;
bool cmp(int a, int b)
{
    return a < b;
}
ll modl(ll a, ll b) //快速幂取余a^b%c
{
    ll res, t;
    res = 1 % MOD;
    t = a % MOD;
    while (b) {
        if (b & 1) {
            res = res * t % MOD;
        }
        t = t * t % MOD;
        b >>= 1;
    }
    return res;
}
int main()
{
#ifndef ONLINE_JUDGE
//freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n;
    a.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        num[a[i]]++;
    }
    if (n % 2 == 1) {
        if (num[0] != 1) {
            cout << 0;
            return 0;
        }
        for (int i = 1; i <= n - 1; i++) {
            if (i % 2 == 1) {
                if (num[i] != 0) {
                    cout << 0;
                    return 0;
                }
            } else {
                if (num[i] != 2) {
                    cout << 0;
                    return 0;
                }
            }
        }
    } else {
        if (num[0] != 0) {
            cout << 0;
            return 0;
        }
        for (int i = 1; i <= n - 1; i++) {
            if (i % 2 == 1) {
                if (num[i] != 2) {
                    cout << 0;
                    return 0;
                }
            } else {
                if (num[i] != 0) {
                    cout << 0;
                    return 0;
                }
            }
        }
    }
    cout << modl(2, n / 2);
}

Measured memory_bytes: 1024
class UnionFind:
    V = -1
    par, rnk, sz = [], [], []
    def __init__(self, V):
        import sys
        sys.setrecursionlimit(1000000000)
        self.V = V;
        self.par = [i for i in range(V)]
        self.rnk = [0] * V
        self.sz = [1] * V
        
    def find(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]
    
    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.rnk[x] < self.rnk[y]:
            self.par[x], self.sz[y] = y, self.sz[y] + self.sz[x] 
        else:
            self.par[y], self.sz[x] = x, self.sz[x] + self.sz[y]
            if self.rnk[x] == self.rnk[y]:
                self.rnk[x] = self.rnk[x] + 1
                
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return self.sz[self.find(x)]

n, q = list(map(int, input().split()))
uf = UnionFind(n)
for _ in range(q):
    com, x, y = list(map(int, input().split()))
    if com == 0:
        uf.unite(x, y)
    else:
        print(int(uf.same(x, y)))



Measured memory_bytes: 6120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		while(true) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			int co = 0;

			if(n == 0 && x == 0) break;

			for(int i=1; i<=n-2; i++) {
				for(int j=i+1; j<=n-1; j++) {
					for(int k=j+1; k<=n; k++) {
						if(i + j + k == x) co++;
						
						if(i == n-2 && j == n-1 && k == n) {
							System.out.println(String.format("%d",co));
						}
					}
				}
			}
		}
	}
}



Measured memory_bytes: 26908
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int llu;

int dp[3001][3001];
/*  Memoized LCS
int lcs(string a,string b,int n,int m){
	if(n==0 || m==0){
		return 0;
	}
	if(dp[n][m]!= (-1)){
		return dp[n][m];
	}
	if(a[n-1]==b[m-1]){
		return dp[n][m]=1+lcs(a,b,n-1,m-1);
	}
	else{
		return dp[n][m] =  max(lcs(a,b,n-1,m),lcs(a,b,n,m-1));
	}
}
*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b;
    cin>>a>>b;
    int n,m;
    n=a.length();
    m=b.length();
    for(int i=0;i<=n;i++){
    	for(int j=0;j<=m;j++){
    		if(i==0 || j==0){
    			dp[i][j]=0;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i-1]==b[j-1]){
				dp[i][j] = 1 + dp[i-1][j-1];
			}
			else{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
    //cout<<lcs(a,b,a.size(),b.size());
    //length of lcs
    //cout<<dp[n][m]<<"\n";
    //Printing lcs
    int i=n,j=m;
    string res="";
    while(i>0 && j>0){
    	if(a[i-1]==b[j-1]){
    		res.push_back(a[i-1]);
    		i--,j--;
		}
		else{
			if(dp[i][j-1] >= dp[i-1][j]){
				j--;
			}
			else{
				i--;
			}
		}
	}
	reverse(res.begin(),res.end());
	cout<<res;
    return 0;
}


Measured memory_bytes: 38844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        int x = Integer.parseInt(tokenizer.nextToken());
        int y = Integer.parseInt(tokenizer.nextToken());
        int max = x * 4;
        int min = x * 2;
        if (min <= y && y <= max && y % 2 == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 32632
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define fore(e, u, v) for (int p = e(u), v = e[p].y; p; v = e[p = e[p].nxt].y)
#define ri rd<int>
using namespace std;
const int maxN = 1e3 + 7;
const int maxV = 5e3 + 7;
const int INF = 1e9 + 7;
const int V = 5000;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

inline bool NIE() { puts("IMPOSSIBLE"); exit(0); }
inline bool TAK() { puts("POSSIBLE"); exit(0); }

int n, val[maxN], els[maxN];
int dp[maxN][maxV];

struct vec {
	static const int maxE = maxN;
	int g[maxN], te;
	struct edge {int y, nxt;} e[maxE];
	inline void push(int x, int y) { e[++te] = (edge){y, g[x]}; g[x] = te; }
	inline int& operator () (int x) { return g[x]; }
	inline edge& operator [] (int x) { return e[x]; }
}e;

inline void Min(int &x, int y) {
	(x == -1 || x > y) ? x = y : 0;
}

void dfs(int x) {
	int f[maxV], g[maxV];
	dp[x][0] = 0; rep (i, 1, V) dp[x][i] = -1;
	fore (e, x, y) {
		dfs(y);
		rep (i, 0, V) f[i] = g[i] = -1;
		int v = val[y], w = els[y];
		per (i, V, v) if (~dp[x][i-v]) Min(f[i], dp[x][i-v] + w);
		v = els[y], w = val[y];
		per (i, V, v) if (~dp[x][i-v]) Min(g[i], dp[x][i-v] + w);
		rep (i, 0, V) dp[x][i] = f[i];
		rep (i, 0, V) if (~g[i]) Min(dp[x][i], g[i]);
	}
	els[x] = INF;
	rep (i, 0, val[x]) if (~dp[x][i]) els[x] = min(els[x], dp[x][i]);
	if (els[x] == INF) NIE();
}

int main() {

	n = ri(); rep (i, 2, n) e.push(ri(), i);
	rep (i, 1, n) val[i] = ri();

	dfs(1);

	TAK();
	return 0;
}

Measured memory_bytes: 36480
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int L, R; cin >> L >> R;
    int M = 2019;
    if (L / 2019 == R / 2019 && L % 2019 != 0) {
        for (int X = L % 2019; X < R % 2019; X++) {
            for (int Y = X+ 1; Y <= R % 2019; Y++) {
                if ((X * Y) % 2019 < M) {
                    M = (X * Y) % 2019;
                }
            }
        }
            cout << M << endl;
        
    }
    else {
        cout << 0 << endl;
    }
}

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

using namespace std;

#define MAX_N 1010
#define MAX_M 1010
#define INF 1e9

int main(){
  int N,M,D[MAX_N],C[MAX_M];
  cin >> N >> M;
  for(int i = 0 ; i < N ; i++){
    cin >> D[i];
  }
  for(int i = 0 ; i < M ; i++){
    cin >> C[i];
  }
  int dp[MAX_N][MAX_M];
  fill(dp[0],dp[0]+MAX_N*MAX_M,INF);
  dp[0][0] = 0;
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < M ; j++){
      dp[i][j+1] = min(dp[i][j+1],dp[i][j]);
      dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+D[i]*C[j]);
    }
  }
  cout << *min_element(dp[N],dp[N]+M+1) << endl;
  return 0;
}

Measured memory_bytes: 5152
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    int sum = 0,mini = INF;
    cin >> N;
    for(int i = 0;i < N;i++){
        int a;
        cin >> a;
        sum += a;
        if(a % 10)mini = min(mini, a);
    }
    if(sum % 10 == 0){
        if(mini == INF)sum = 0;
        else sum -= mini;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 805
using namespace std;
queue<int> P,Q,D;
int n,m,k,u,v,B[N][N],ans=(1<<30); char A[N][N];
void ins(int x,int y,int z){ if(z>k||B[x][y]) return ; P.push(x),Q.push(y),D.push(z),B[x][y]=1;}
void flood()
{
	int x,y,z;
	P.push(u),Q.push(v),D.push(0),B[u][v]=1;
	while(!P.empty()){
		x=P.front(),y=Q.front(),z=D.front();
		P.pop(),Q.pop(),D.pop();
		if(x>1&&!B[x-1][y]&&A[x-1][y]!='#') ins(x-1,y,z+1);
		if(y>1&&!B[x][y-1]&&A[x][y-1]!='#') ins(x,y-1,z+1);
		if(x<n&&!B[x+1][y]&&A[x+1][y]!='#') ins(x+1,y,z+1);
		if(y<m&&!B[x][y+1]&&A[x][y+1]!='#') ins(x,y+1,z+1);
	  }
}
int main()
{
	int i,j;
	scanf("%d %d %d\n",&n,&m,&k);
	for(i=1;i<=n;i++) scanf("%s",A[i]+1);
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			if(A[i][j]=='S') u=i,v=j;
	flood();
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			if(B[i][j])
				ans=min((min(min(j-1,m-j),min(i-1,n-i))+k-1)/k+1,ans);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < N; i++) {
			int a = sc.nextInt();
			if (i % 2 == 0 && a % 2 == 1) {
				ans++;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 35592
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};

int main(){
  int N;  cin>>N;
  vector<set<ll> > se;
  vector<ll> v(N), a(N);
  map<ll, ll> ma;
  ll ans = 0;
  rep(i,0,N){
    ll A; cin>>A;
    ans += ma[i-A];
    ma[i+A]++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 28972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        sum += x;
    }

    int ans = n - sum;

    if (ans < 0) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void) {
    int h, m, s;
    scanf("%d", &s);
    h = s / 3600;
    s -= h * 3600;
    m = s / 60;
    s -= m * 60;
    printf("%d:%d:%d\n", h, m, s);

    return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define dd(x) cout<<#x<<" = "<<x<<" "
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define sz(x) int(x.size())
#define All(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef priority_queue<int> BQ;
typedef priority_queue<int,vector<int>,greater<int> > SQ;
const int maxn=3e5+10,mod=1e9+7,INF=0x3f3f3f3f;
char s[maxn];
int main()
{
	scanf("%s",s);
	for (int i=0;s[i];++i)
		if (s[i]=='?')
			s[i]='D';
	printf("%s",s);
	return 0;
}


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

vector <int> V;
int n,x,y;
int dp[100010];

int main()
{
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> x;
        V.push_back(x);
    }

    for (int i=1;i<n;i++){
        dp[i]=INT_MAX;
        x=V[i];
        for (int j=1;j<=2;j++){
            if (i-j<0) break;
            y=V[i-j];
            dp[i]=min(dp[i],dp[i-j]+abs(x-y));
        }
    }
    cout << dp[n-1];
}


Measured memory_bytes: 4092
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
  string a, b, c, d;
  cin >> a >> b >> c >> d;
  string e = a + b + c + d;
  sort(e.begin(), e.end());
  if (e == "1479") {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n,d,x,a[200],y,z,sum=0;

    scanf(" %d %d %d",&n,&d,&x);
    for(y=0;y<n;y++)
        scanf(" %d",&a[y]);

    for(y=0;y<n;y++){
        for(z=1;z<=d;z+=a[y]){
            sum++;
        }
    }

    printf("%d\n",sum+x);



    return 0;
}


Measured memory_bytes: 128
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();
    let c: usize = iterator.next().unwrap().parse().unwrap();

    return if a + b >= c {
        "Yes".to_string()
    } else {
        "No".to_string()
    };
}


Measured memory_bytes: 2108
// Author : Abhisar Singhal
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>   
#include <map>
#include <string>  
#include <climits> 
#include <set>
#include <string>    
#include <sstream>
#include <utility>   
#include <ctime>
#include <cassert>
#include <fstream>
#include <iomanip>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> II;
typedef vector<long long> VLL;
typedef vector<bool> VB;

#define SZ(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MAX(a,b) ((a >= b) ? (a) : (b))
#define MIN(a,b) ((a >= b) ? (b) : (a))
#define ABS(a) (((a) > 0) ? (a) : (-a))
#define MP make_pair
#define X first
#define Y second
#define PB push_back
#define FOUND(A, x) (A.find(x) != A.end())
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12

#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define clrbit(s, b) (s &= ~(1<<b))

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REV(i, a, n) for(int i = a; i > n; i--)
#define FORALL(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define ALL(A) A.begin(), A.end()
#define LLA(A) A.rbegin(), A.rend()
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {1, 1, 1, 0, 0, -1, -1, -1}, dy[] = {1, 0, -1, 1, -1, 1, 0, -1};
inline void inp( int &n ) {
	n=0; int ch = getcx(); int sign = 1;
	while(ch < '0' || ch > '9') { if(ch == '-') sign=-1; ch = getcx(); }
	while(ch >= '0' && ch <= '9') { n = (n << 3) + (n << 1) + ch - '0', ch = getcx(); }
	n = n * sign;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
    int n;
	cin >> n;
	VI A(n);
	REP (i, n) cin >> A[i];
	VI dp(10, 0), cur(10, 0);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cur[j] = 0;
		}
		for (int j = 0; j < 10; j++) {
			if (dp[j] || (j == 0)) cur[(j + (A[i] % 10)) % 10] += dp[j] + A[i];
		}
		for (int j = 0; j < 10; j++) {
			dp[j] = max(dp[j], cur[j]);
		}
	}
	int ans = 0;
	for (int i = 1; i < 10; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};

ll N, H, W;
int x[40000], y[40000];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> W >> H;
    UnionFind uni(N);
    for(int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            if(x[i] == x[j] or y[i] == y[j]) uni.merge(i, j);
        }
    }
    int rest = 0;
    for(int i = 0; i < N; i++) {
        if(uni.root(i) == i) rest++;
    }
    if(rest == 1) {
        cout << N - 1 << endl;
        return 0;
    }
    int ans = N - rest;
    bool edge = false;
    for(int i = 0; i < N; i++) {
        if(x[i] == 1 or x[i] == W or y[i] == 1 or y[i] == H) edge = true;
    }
    if(!edge) ans++;
    ans += 2 * (rest - 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3888
import java.io.*;

public class Main {

  static int n, pos, ansInp;
  static int[] pre, inp, post;

  
  public static void main(String[] args) throws Exception {
    
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    Tree t = new Tree();

    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);

    for(int i = 0; i < n; i++){
      in = br.readLine().split(" ");
      if(in[0].equals("insert")){
        t.insert(new Node(Integer.parseInt(in[1])));
      }else{
        t.print();
      }
    }

    br.close();

  }
}


class Node {
  int v;
  Node p, l, r;

  Node(int v){
    this.v = v;
  }
}

class Tree {

  Node root;

  public Node insert(Node node){
    Node par = null;
    Node now = root;

    while(now != null){
      par = now;
      if(node.v > now.v) now = now.r;
      else now = now.l;
    }
    node.p = par;

    if(par == null) {
      this.root = node;
    }else if(node.v < par.v) {
      par.l = node;
    }else {
      par.r = node;
    }
    return node;
  }

  void print(){
    inorderPrint(this.root);
    System.out.println();
    preorderPrint(this.root);
    System.out.println();
  }

  void preorderPrint(Node node){
    System.out.print(' ');
    System.out.print(node.v);
    if(node.l != null)
      preorderPrint(node.l);
    if(node.r != null)
      preorderPrint(node.r);
    return;
  }

  void inorderPrint(Node node){
    if(node.l != null)
      inorderPrint(node.l);
    System.out.print(' ');
    System.out.print(node.v);
    if(node.r != null)
      inorderPrint(node.r);
    return;
  }
}


Measured memory_bytes: 180984
A=[]
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))
#A00,A01,A02 = map(int, input().split())
#A10,A11,A12 = map(int, input().split())
#A20,A21,A22 = map(int, input().split())
N=int(input())
b=[int(input()) for i in range(N)]

#print(A)
#print(b)

for k in range(3):
    if A[0][k] in b and A[1][k] in b and A[2][k] in b:
        print('Yes')
        exit()
    elif A[k][0] in b and A[k][1] in b and A[k][2] in b:
        print('Yes')
        exit()
if A[0][0] in b and A[1][1] in b and A[2][2] in b:
    print('Yes')
    exit()
elif A[0][2] in b and A[1][1] in b and A[0][2] in b:
    print('Yes')
    exit()

print('No')



Measured memory_bytes: 38256
def main():

    k = int(input())

    result = -1
    m = 7
    for i in range(1,k+1):
        check = m % k
        if check == 0:
            result = i
            break
        m = (10*m + 7) % k
    
    print(result)

if __name__ == '__main__':
    main()

Measured memory_bytes: 8944
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int x, y;
  cin >> x >> y;
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> p(a);
  rep(i, a) cin >> p.at(i);
  vector<int> q(b);
  rep(i, b) cin >> q.at(i);
  vector<int> r(c);
  rep(i, c) cin >> r.at(i);
  sort(ALL(p), greater<int>());
  sort(ALL(q), greater<int>());

  priority_queue<int> que;
  rep(i, x) que.push(p.at(i));
  rep(i, y) que.push(q.at(i));
  rep(i, c) que.push(r.at(i));

  ll ans = 0;
  rep(i, x+y){
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6484
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
double Pi = 3.1415926535897932384626;
 
vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 998244353;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[800005],rfact[800005];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[800000] = rui(fact[800000],mod - 2);
    for(ll i=800000; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k,ans;
ll x[500005],y[500005],z[500005];
bool used[500005];
char s[500005];

int main(){
    cin >> n >> s;
    for(int i=0;i<n;i++){
    	x[i] = s[i];
    }
    x[n] = 10000;
    for(int i=0;i<n;i++){
    	if(x[i] != x[i+1]){
    		ans ++;
    	}
    }
    p(ans);
    return 0;
}











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

const int MAXN = 5123;

int n, k;
int v[MAXN];
bool memo[MAXN];

bool solve (int x) {
	memset (memo, 0, sizeof memo);
	memo[0] = true;

	for (int i = 0; i < n; ++i) {
		if (i == x) continue;
		for (int j = k; j >= v[i]; --j)
			memo[j] |= memo[j - v[i]];
	}

	for (int i = max (k - v[x], 0); i < k; ++i)
		if (memo[i]) return false;

	return true;
}

int main () {

	cin >> n >> k;

	int ans = 0;
	for (int i = 0; i < n; ++i)
		scanf ("%d", v + i);

	sort (v, v + n);

	if (!solve (0)) {
		cout << ans << endl;
		return 0;
	}

	int l = 0, r = n;
	while (r - l > 1) {
		int mid = (l + r) >> 1;
		if (solve (mid))
			l = mid;
		else
			r = mid;
	}

	cout << ans + l + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF 1000000000000000007 

int main(){
  int n,w;
  cin>>n>>w;
  vector<ll>weight(n);
  vector<ll>value(n);
  for(int i=0;i<n;i++){
    cin>>weight[i]>>value[i];
  }
  ll sum=0;
  for(int i=0;i<n;i++){
    sum+=value[i];
  }
  vector<ll>dp(sum+1,INF);
  dp[0]=0;
  for(int i=0;i<n;i++){
   	for(int j=sum-value[i];j>=0;j--){
    	dp[value[i]+j]=min(dp[value[i]+j],dp[j]+weight[i]); 
    }
  }
  for(int i=sum;i>=0;i--){
    if(dp[i]<=w){
      cout<<i<<endl;
      break;
    }
  }
}


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

template <typename T>
T gcd(T a, T b)
{
    return (b == 0 ? a : gcd(b, a % b));
}

template <typename T>
T lcm(T a, T b)
{
    return a / (gcd(a, b)) * b;
}

ll N, ans = 1, t;

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;
}

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

int main()
{
    int n;double d,x;
    cin>>n>>d>>x;
    double ans=0;
    for(;n;--n)
    {
        ans+=d+(n-0.5)*x;
        d=((2*n+2)*d+5*x)/(2*n);
        x=(2*n+4)*x/(2*n);
    }
    printf("%.9f\n",ans);
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int a, b, t;
    cin >> a >> b >> t;
    int ans = t / a * b;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*

 Remember, Hope is a good thing... May be the best of things... and No Good thing ever Dies !!!

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
#define endl "\n"
#define MOD 1000000007
#define MOD1 1e18
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
typedef long double ld;
const ll inf=(1LL<<60)-1;
const ll mxn=1e5;
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
long long ans,a[100005];
ll mod(ll x)
{
    ll res=x%MOD;
    while(res<0)
        res+=MOD;
    return res;
}
ll bigmod(ll x,ll n)
{
    ll res=1;
    while(n>0)
    {
        if(n&1)
            res=(res*x)%MOD;
        x=(x*x)%MOD;
        n>>=1;
    }
    return res;
}
/*
sort(v.begin(),v.end(),[&](const pair<ll,ll>&a,const pair<ll,ll>&b)
   {
       if(a.first==b.first)
           return a.second<b.second;
       else
           return a.first>b.first;
   });
   */
void solve()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ll x,n,sum=0,mn=MOD;
    cin>>n;
    vector<ll>inp;
    for(ll i=0;i<n;i++)
    {
        cin>>x;
        inp.push_back(x);
    }
    sort(inp.begin(),inp.end());
    for(ll i=inp[0];i<=inp[n-1];i++)
    {
        sum=0;
        for(ll j=0;j<n;j++)
        {
            sum+=((inp[j]-i)*(inp[j]-i));
        }
        //cout<<sum<<endl;
        mn=min(mn,sum);
    }
    cout<<mn<<endl;
}
int main()
{
    IOS;
    //ll t;
    //cin>>t;
    //while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int Z = 8003;
const int N = 2 * Z + 1;
bool dp[2][2][N];
int X, Y;
char s[N];
int n;
int t;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	dp[0][0][Z] = dp[1][0][Z] = 1;
	scanf("%s", s);
	n = strlen(s);
	scanf("%d%d", &X, &Y);
	int pos = 0;
	while(pos < n && s[pos] == 'F') {
		pos++;
		X--;
	}
	t = 0;
	while(pos < n) {
		pos++;
		t ^= 1;
		int L = 0;
		while(pos < n && s[pos] == 'F') {
			pos++;
			L++;
		}
		for (int i = 0; i < N; i++)
			dp[t][1][i] = 0;
		for (int i = 0; i < N; i++) {
			if (!dp[t][0][i]) continue;
			dp[t][1][i - L] = dp[t][1][i + L] = 1;
		}
		for (int i = 0; i < N; i++)
			dp[t][0][i] = dp[t][1][i];
	}
	if (dp[0][0][Z + X] && dp[1][0][Z + Y])
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    string s; cin >> s;
    ll n = s.size();
    
    cout << ((s.front() == s.back()) != !!(n % 2) ? "First" : "Second") << endl;
    
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  int n;
  cin >> n;
  vector<ll> a(n + 1),b(n);
  rep(i,n+1){
    cin >> a[i];
  }
  rep(i,n){
    cin >> b[i];
  }
  ll ans = 0;
  rep(i, n)
  {
    ans += max(0ll,min(b[i],a[i]));//maxいらんかも
    b[i] -= max(0ll,a[i]);
    ans += max(0ll, min(b[i], a[i + 1]));
    a[i + 1] -= max(0ll,b[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1920
n,a,b,c = map(int,input().split())
abc = {'A': a, 'B': b, 'C': c}
s = [input() for _ in range(n)]
ans = []
for i in range(n):
    s1, s2 = s[i][0], s[i][1]

    if abc[s1] == abc[s2] == 0:
        print('No')
        exit()
    elif abc[s1] == abc[s2] == 1 and i < n-1:
        if s[i+1] == s1 + s2:
            ans += [s1]
            abc[s1] += 1
            abc[s2] -= 1
        elif s1 in s[i+1]:
            ans += [s1]
            abc[s1] += 1
            abc[s2] -= 1
        else:
            ans += [s2]
            abc[s2] += 1
            abc[s1] -= 1
    else:
        if abc[s1] <= abc[s2]:
            ans += [s1]
            abc[s1] += 1
            abc[s2] -= 1
        else:
            ans += [s2]
            abc[s2] += 1
            abc[s1] -= 1

print('Yes')
for x in ans:
    print(x)

Measured memory_bytes: 17104
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string a;
  	cin >> a;
  	int ans;
  	char m = a[0];
  	for(int i = 0; i < 2; i++){
      if(a[i] < a[i+1]){
        m += 1;
        break;
      }
      else if(a[i] > a[i+1]){
        break;
      }
    }
  	for(int i = 0; i < 3; i++){
      a[i] = m;
    }
  	ans = atoi(a.c_str());
    cout << ans << endl;
}

Measured memory_bytes: 256
object Main extends App {
  val scanner = new java.util.Scanner(System.in)
  val a = scanner.nextInt
  val b = scanner.nextInt
  val c = scanner.nextInt

  val result =
    if(a < b) {
      if(b < c) {
        "Yes"
      } else {
        "No"
      }
    } else {
      "No"
    }

  println(result)
}

Measured memory_bytes: 45004
N = int(input())
 
a = 0
b = 0
c = 0
count = 0
for i in range(N):
    s = input()
    count += len([1 for j in range(len(s)) if s[j:j+2] == "AB"])
    if s[-1] == "A":
        a += 1
    if s[0] == "B":
        b += 1
    if s[0] == "B" and s[-1] == "A":
        c += 1

if a == b and b == c and c != 0:
    print(count + c - 1)
else:
    print(count + min([a, b, N-1]))

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int t , n , x;
int a[MAXX];

int main()
{
    _FastIO;
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB"){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;
  string ans="Yes";
  for (int i=0; i<A; i++) {
    if (S[i]=='-') {
      ans="No";
    }
  }
  
  if (S[A]!='-') {
    ans="No";
  }
  
  for (int i=A+1; i<A+B+1; i++) {
    if (S[i]=='-') {
      ans="No";
    }
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 3592
n = int(input())
A = {}
a = list(map(int,input().split()))
for i in a:
    if not i in A:
        A[i] = 1
    else:
        A[i] += 1

s = 0
for k,v in A.items():
    s += k*v

Q = int(input())
for _ in range(Q):
    b,c = map(int,input().split())
    if b in A:
        s = s-(b-c)*A[b]
        if not c in A:
            A[c] = A[b]
        else:
            A[c] += A[b]
        A[b] = 0

    print (s)


Measured memory_bytes: 20808
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    vi vec(3);
    REP(i,3){
        cin>>vec[i];
    }
    sort(all(vec));
    int ans=0;
    REP(i,2){
        ans+=vec[i+1]-vec[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  for (int i = 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256