akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void){
  char a[3];
  scanf("%s",a);
  if((a[0]=='A' &&a[1]=='A' && a[2]=='A')||(a[0]=='B' && a[1]=='B' && a[2]=='B'))
    printf("No");
  else{
    printf("Yes");
  }
  return 0;
}


Measured memory_bytes: 128
/*#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <stdlib.h>
#define ll long long
using namespace std;
const int NUM=100010;
int pa[NUM];
int Find(int x);
void Union(int x,int y);
int main()
{
    int n,m,x;
    char c;
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while(~scanf("%d %d",&n,&m)&&n+m)
    {
        pa[1]=1;
        for(int i=1; i<=n-1; i++)
        {
            scanf("%d",&x);
            pa[i+1]=x;
        }
        ll ans=0;
        for (int i=0; i<m; i++)
        {
            scanf(" %c %d",&c,&x);
            if (c=='M'&&pa[x]!=x)
                pa[x]=x;
            if (c=='Q')
                ans+=Find(x);
        }
        printf("%lld\n",ans);
    }
    return 0;
}
int Find(int x)
{
    return pa[x]==x?x:Find(pa[x]);
}
*/
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <stdlib.h>
using namespace std;
const int NUM=100010;
int pa[NUM];
vector<int> G[NUM];
void init(int n);
int Find(int x);
void Union(int x,int y);
void dfs(int start,int x);
int main()
{
    int n,m,x;
    char c;
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
     int size = 256 << 20; //256M
    char * p = (char *)malloc(size) + size;
#if (defined _WIN64) or (defined __unix)
    __asm__("movq %0, %%rsp\n" :: "r"(p));
#else
    __asm__("movl %0, %%esp\n" :: "r"(p));
#endif

    while(~scanf("%d %d",&n,&m)&&n+m)
    {
        for (int i=1;i<=n;i++)
        {
            G[i].clear();
        }
        for(int i=1;i<=n-1;i++)
        {
            scanf("%d",&x);
            G[x].push_back(i+1);
        }
        init(n);
       long long ans=0;
        for (int i=0;i<m;i++)
        {
            scanf(" %c %d",&c,&x);
            if (c=='M'&&pa[x]!=x)
            {
                pa[x]=x;
                dfs(x,x);
            }
            if (c=='Q')
            {
                ans+=pa[x];
            }
        }
        printf("%lld\n",ans);
    }
    exit(0);
}
void init(int n)
{
    for (int i=1; i<=n; i++)
        pa[i]=1;
}
void dfs(int start,int x)
{
    for (int i=0;i<G[start].size();i++)
    {
        if (pa[G[start][i]]!=G[start][i])
        {
            pa[G[start][i]]=x;
            dfs(G[start][i],x);
        }

    }
}



Measured memory_bytes: 11848
# AOJ ITP1_8_D

def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    string = input()
    string += string
    p = input()
    # 文字列を2倍してその中から探す。
    # 1≦pの長さ≦sの長さなのでこれでいい。
    # 文字列含有には「文字列」.find(「探したい文字列」)を使う。
    if string.find(p) >= 0: print("Yes")
    else: print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 5564
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define input_i(x) scanf("%d", &x)
#define input_lli(x) scanf("%lld", &x)
#define input_s(x) scanf("%s", x)

#define BUFSIZE 1001

int main(int argc, char const *argv[]) {
    int N, i, j, buf= 0, ans= 0;
    input_i(N);
    int A[N][N - 1], next[BUFSIZE]= {}, end_f= 0;
    for(i= 0; i < N; i++) {
        for(j= 0; j < N - 1; j++) {
            input_i(A[i][j]);
            A[i][j]--;
        }
    }
    while(1) {
        int flag[BUFSIZE]= {}, imp= 0;
        end_f= 0;
        ans++;
        for(i= 0; i < N; i++) {
            if(next[i] == N - 1)
                end_f++;
            else {
                int target= A[i][next[i]];
                if(A[target][next[target]] == i && flag[i] + flag[target] == 0) {
                    next[i]++;
                    next[target]++;
                    flag[i]= 1;
                    flag[target]= 1;
                }
            }
            imp+= flag[i];
        }
        if(end_f == N) break;
        if(imp == 0) {
            ans= 0;
            break;
        }
    }
    ans--;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int h,w,k;
	cin >> h >> w >> k;
	vector<string> s(h);
	for(int i=0;i<h;i++) cin >> s[i];
	int ans = 0;
	for(int is = 0;is < 1<<h;is++){
		for(int js = 0;js < 1<<w;js++){
			int cnt = 0;
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					if(is>>i & 1) continue;
					if(js>>j & 1) continue;
					if(s[i][j] == '#') cnt++;
				}
			}
			if(cnt == k) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  while (a != b || b != c || c != a)
  {
    if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)
      break;
    int ta = a;
    int tb = b;
    int tc = c;
    a = tb / 2 + tc / 2;
    b = ta / 2 + tc / 2;
    c = ta / 2 + tb / 2;
    ans++;
  }
  if (a == b && b == c && a % 2 == 0)
  {
    cout << -1 << endl;
  }
  else
  {
    cout << ans << endl;
  }
}


Measured memory_bytes: 768
#include<cstdio>
int main()
{
	int N;
	scanf("%d", &N);
	while(N--)
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		if(a > b)
		{
			a = a ^ b;
			b = a ^ b;
			a = a ^ b;
		}
		if(a > c)
		{
			a = a ^ c;
			c = a ^ c;
			a = a ^ c;
		}
		if(b > c)
		{
			b = b ^ c;
			c = b ^ c;
			b = b ^ c;
		}
		if(a + b > c && a * a + b * b == c * c)
		{
			printf("YES\n");
		}
		else printf("NO\n");
	}
	return 0;
}

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

int main() {
	long long A, V, B, W, T;
	cin >> A >> V >> B >> W >> T;
	if (W >= V)
		cout << "NO" << endl;
	else {
		if (abs(A - B) > T * abs(V - W))
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
	}
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC075_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var n = nm[0];
            var m = nm[1];
            var gra = new int[n, n];
            for (var i=0;i<m;i++)
            {
                var hen = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
                gra[hen[0] - 1, hen[1] - 1] = 1;
                gra[hen[1] - 1, hen[0] - 1] = 1;
            }
            var ans = 0;
            for(var i=0;i<n;i++)
            {
                for(var j=i+1;j<n;j++)
                {
                    if(gra[i,j] == 1)
                    {
                        var meiz = gra.Clone() as int[,];
                        meiz[i, j] = 0;
                        if(!(dfs(i,n,meiz)))
                        {
                            ans++;
                        }
                    }
                }
            }
            Console.WriteLine(ans);
        }
        static bool dfs(int v,int a,int[,] mmm)
        {
            var bo = new bool[a];
            bo[v] = true;
            var s = new Stack<int>();
            s.Push(v);
            while(s.Count() != 0)
            {
                var c = s.Pop();
                for (var i = 0; i<a;i++)
                {
                    if(mmm[c,i] == 1 && bo[i] == false)
                    {
                        s.Push(i);
                        bo[i] = true;
                    }
                }
            }
            foreach(var ch in bo)
            {
                if(ch == false)
                {
                    return false;
                }
            }
            return true;
        }
    }
}


Measured memory_bytes: 11616
#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>

using namespace std;

int main(void)
{
    int N, i, j, d[9], div=1;
    double sum=0, x[9], y[9];

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> x[i] >> y[i];

        div *= i;
    }

    for(i=1; i<=N; i++){
        d[i] = i;
    }

    do{
        for(i=1; i<=N-1; i++){
            sum += sqrt(pow(x[d[i]]-x[d[i+1]],2)+pow(y[d[i]]-y[d[i+1]],2));
        }
    }while(next_permutation(d+1, d+N+1));

    cout << setprecision(10) << sum/(double)div << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int gcd(int a, int b) {
  return (!a || !b) ? 0 : ((a % b == 0) ? b : gcd(b, a % b));
}

int main() {
  ll n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n - 1; i++) {
    v[i + 1] = gcd(v[i], v[i + 1]);
  }
  cout << v[n - 1] << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define inf (long long)(1e16)
#define lim 2550
using namespace std;

struct dat {
  long long n, c, t;
  bool operator<(const dat &r) const { return t > r.t; }
};

struct edge {
  long long to, cos, time;
};

long long n, m, s;
vector<vector<edge>> g;
vector<long long> c, d, res;
vector<vector<long long>> dis;
priority_queue<dat> pq;

void solve();

int main() {
  cin >> n >> m >> s;
  s = min(s, (long long)lim);
  g.resize(n);
  c.resize(n);
  d.resize(n);
  res.assign(n, inf);
  dis.assign(n, vector<long long>(2600, inf));
  for (int i = 0; i < m; ++i) {
    int x, y, cost, time;
    cin >> x >> y >> cost >> time;
    --x, --y;
    g[x].push_back({y, cost, time});
    g[y].push_back({x, cost, time});
  }
  for (int i = 0; i < n; ++i) cin >> c[i] >> d[i];
  solve();
  for (int i = 1; i < n; ++i) cout << res[i] << endl;
  return 0;
}

void solve() {
  dis[0][s] = 0;
  pq.push({0, s, 0});
  while (pq.size()) {
    dat now = pq.top();
    pq.pop();
    if (now.t != dis[now.n][now.c]) continue;
    dat nextp = now;
    nextp.t += d[nextp.n];
    nextp.c += c[nextp.n];
    while (nextp.c <= lim && nextp.t < dis[nextp.n][nextp.c]) {
      dis[nextp.n][nextp.c] = nextp.t;
      pq.push(nextp);
      nextp.t += d[nextp.n];
      nextp.c += c[nextp.n];
    }
    for (auto to : g[now.n]) {
      nextp = now;
      nextp.n = to.to;
      nextp.t += to.time;
      nextp.c -= to.cos;
      if (nextp.c < 0 || nextp.t >= dis[nextp.n][nextp.c]) continue;
      pq.push(nextp);
      dis[nextp.n][nextp.c] = nextp.t;
      res[nextp.n] = min(res[nextp.n], nextp.t);
    }
  }
}

Measured memory_bytes: 52404
a,b,c = map(int, input().split())
ans = a**2 + b**2 + c**2 - 2*(a*b + b*c + a*c)
if(c-a-b < 0):
    print('No')
    exit()

if(ans > 0):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

x = iinput()
ans = 0
ans += (x//500)*1000
x -= (x//500)*500
ans += (x//5)*5
print(ans)


Measured memory_bytes: 15500
#include <bits/stdc++.h>
#define dbg(x) cerr<<#x<<" = "<<x<<endl;
#define dbg_v(v,n) {cerr<<#v<<" = [";for(int III=0;III<=n;III++)cerr<<v[III]<<(III!=n?",":"]\n");}
#define ll long long
#define ld long double
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define Nmax 100006
using namespace std;
int n,A[Nmax],B[Nmax],C[Nmax],fr[Nmax];
int main(){
    ios::sync_with_stdio(false);
    cin >> n;

    ll s = 0;
    for (int i=1;i<n;i++){
        cin >> A[i];
    }
    s += A[n-1];
    for (int i=1;i<n-1;i++) s += min(A[i+1], A[i]);
    s += A[1];
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  IN3(x,y,z);
  OUT(x*y/2);
}

Measured memory_bytes: 256
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

n = int(input())
enemy = list(set(map(int,input().split())))
if len(enemy)==1:
    print(enemy[0])
else:
    enemy.sort()
    min_n = 10**10
    for i in range(len(enemy)-1):
        min_n = min(min_n,gcd(enemy[i],enemy[i+1]))
    print(min_n)

Measured memory_bytes: 19728
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

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

  map<int,ll>m;


  int n;
  cin>>n;
  int a[n];
  ll res=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    m[a[i]]++;
  }

  for(auto it:m){
 
      res+=(it.second*(it.second-1))/2;
    
  }


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

    temp=temp+1-m[a[i]];

    cout<<temp<<endl;

  }

    
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int get_root(int i, int wood[])
{
    // depth = 0;
    while (wood[i] != i)
    {
        wood[i];
        i = wood[i];
        // depth++;
    }
    return i;
}

int main()
{
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    int wood[n];
    int depth[n]{1};
    rep(i, n) wood[i] = i;
    int a, b;
    int ra, rb;
    int friends[n] = {0};
    rep(i, m)
    {
        scanf("%d%d", &a, &b);
        a--;
        b--;
        friends[a]++;
        friends[b]++;
        ra = get_root(a, wood);
        rb = get_root(b, wood);
        if (depth[ra] > depth[rb])
        {
            depth[ra] = depth[ra] > depth[rb] + 1 ? depth[ra] : depth[rb] + 1;
            wood[rb] = ra;
        }
        else
        {
            depth[rb] = depth[rb] > depth[ra] + 1 ? depth[rb] : depth[ra] + 1;
            wood[ra] = rb;
        }
    }
    int group_num[n] = {0};
    rep(i, n)
    {
        int idx = get_root(i, wood);
        group_num[idx]++;
    }
    int ans[n] = {0};
    rep(i, k)
    {
        scanf("%d%d", &a, &b);
        a--;
        b--;
        if (get_root(a, wood) == get_root(b, wood))
        {
            ans[a]--;
            ans[b]--;
        }
    }
    rep(i, n)
    {
        printf("%d ", ans[i] + group_num[get_root(i, wood)] - friends[i] - 1);
    }
    printf("\n");
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define esort(s) sort((s).begin(),(s).end())

typedef long long ll;
typedef pair<int,int> ipair;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

ll N,M,a[100010],sum;

ll bs(ll x){
    ll num=0,y=N-1;
    rep(i,N){
        while(y>=0&&a[i]+a[y]>=x){
            sum+=a[y]*(N-i);
            y--;
            // cout<<a[y]*(N-i)<<" ";
        }
        sum+=(N-y-1)*a[i];
        num+=N-y-1;
    }
    // cout<<"\n";
    return num;
}

void solve(){
    cin>>N>>M;
    rep(i,N) cin>>a[i];

    sort(a,a+N);

    ll l=0,r=1e18;
    while(l+1<r){
        ll mid=(l+r)/2;      // midが幸福度
        if(bs(mid)<M) r=mid; // bs(mid)で幸福度がmid以上となる握手の回数を返す．=> midは握手の回数がM以上となる最小の幸福度．これがMとならないのはa[i]に重複があるとき．
        else l=mid;
        // cout<<l<<" "<<r<<"\n";
        // cout<<sum<<"\n";
    }
    // sum=0ll;
    // cout<<l<<" "<<bs(l+1)<<" "<<sum<<"\n";
    sum=0ll;                 // sumの初期化
    cout<<l*(M-bs(l))+sum<<endl; // bs(l)がMより大きいときはM回での最大値を出すので，bs(l)のsumの中で最小である重複を削る．

    return;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
	int mofu = -1;
	int X;
	if (scanf("%d", &X) != 1) return 1;
	if (X < 400) {
		puts("fuck");
		return 0;
	} else if (X < 600) mofu = 8;
	else if (X < 800) mofu = 7;
	else if (X < 1000) mofu = 6;
	else if (X < 1200) mofu = 5;
	else if (X < 1400) mofu = 4;
	else if (X < 1600) mofu = 3;
	else if (X < 1800) mofu = 2;
	else if (X <= 1999) mofu = 1;
	else {
		puts("fuck");
		return 0;
	}
	printf("%d\n", mofu);
	return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N,M;
  cin >> N >> M;
  vector<pair<long, long>> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i].first >> A[i].second;
  }
  sort(A.begin(), A.end());
  long sum=0;
  long mon=0;
  int i=0;
  while(sum<M){
    sum+=A[i].second;
    mon+=A[i].first*A[i].second;
    i++;
  }
  mon-=A[i-1].first*(sum-M);
  cout << mon << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

int main()
{
  int N,X;
  cin >> N >> X;
  int result;
  REP(i,N){
    int a;
    cin >> a;

    if(i == 0){
      result = abs(a-X);
    }
    else{
      result = gcd(abs(a-X),result);
    }

  }

  cout << result;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
const int maxn = 300 + 5;
const int mod = 998244353; 

int a[maxn];
int dp[maxn][maxn][maxn], dp1[maxn][maxn][maxn], dp2[maxn][maxn][maxn];

int main(){
	ios_base::sync_with_stdio(false);
	string s;
	int K;
	cin >> s >> K;
	int n = 0;
	int cnt = 0;
	for (int i = 0; i < (int)s.size(); i++){
		if (s[i] == '0'){
			a[n++] = cnt;
			cnt = 0;
		}
		else
			cnt ++;
	}
	a[n++] = cnt;
	int sum = 0;
	for (int i = n; i >= 0; i--){
		for (int j = 0; j <= 300; j++){
			for (int k = 0; k <= 300; k++){
				if (k > sum or k < j)
					dp[i][j][k] = 0;
				else if (i == n)
					dp[i][j][k] = (j == 0 and k == 0);
				else{
					dp[i][j][k] = (0ll + dp[i][j][k] + dp1[i+1][j-1][j-k+300] - (j-a[i+1] > 0 ? dp1[i+1][j-a[i+1]-1][j-k+300] : 0) + mod) % mod;
					dp[i][j][k] = (0ll + dp[i][j][k] + dp2[i+1][300][k] - (j > 0 ? dp2[i+1][j-1][k] : 0) + mod) % mod;
					dp[i][j][k] = (0ll + dp[i][j][k] + mod) % mod;
				}

				if (j){
					dp1[i][j][j-k+300] = (dp1[i][j-1][j-k+300] + dp[i][j][k]) % mod;
					dp2[i][j][k] = (dp2[i][j-1][k] + dp[i][j][k]) % mod;
				}
				else{
					dp1[i][j][j-k+300] = dp[i][j][k];
					dp2[i][j][k] = dp[i][j][k];
				}
			}
		}
		sum += a[i];
	}
	int answer = 0;
	for (int j = 0; j <= 300; j++)
		for (int k = 0; k <= min(300, K); k++)
			answer = (answer + dp[0][j][k]) % mod;
	cout << answer << endl;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> c(N+1);
    for(int i = 1; i <= N; i++)
    {
        cin >> c.at(i);
    }

    vector<unsigned int> dp(N+1);
    dp.at(0) = 1;
    vector<unsigned int> colour(200010);
    colour.at(c.at(1)) = dp.at(0);

    for(int i = 1; i <= N; i++)
    {
        if (i == 1) {
          dp.at(i) = dp.at(0);
        }
        else
        {
            dp.at(i) = colour.at(c.at(i)) % 1000000007;
        }
        
        if(i < N && c.at(i) != c.at(i+1)){
            colour.at(c.at(i+1)) = (colour.at(c.at(i+1)) + dp.at(i)) % 1000000007;
    }
    }
    
    cout << dp.at(N) << endl;   
}

Measured memory_bytes: 2560
// A - Addition and Subtraction Easy

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

int main() {
	int A, B;
	char op;
	cin >> A >> op >> B;

	int ans;

	if (op == '+') ans = A + B;
	else ans = A - B;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Read();
            var yy = s[0] +""+ s[1];
            var mm = s[2] +""+ s[3];
            var y = int.Parse(yy);
            var m = int.Parse(mm);
            if (y>=1&&y<=12&& m >= 1 && m <= 12)
            {
                WriteLine("AMBIGUOUS");
            }
            else if (y >= 0 && y <= 99 && m >= 1 && m <= 12)
            {
                WriteLine("YYMM");
            }
            else if (y >= 1 && y <= 12 && m >= 0 && m <= 99)
            {
                WriteLine("MMYY");
            }
            else
            {
                WriteLine("NA");
            }
        }
       

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

    }
}


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

const int NOT_FOUND=-1;

int binarySearch(int key, int A[],int n){
	int left=0;
	int right =n;

	while(left<right){
		int mid=(left+right)/2;
		if(A[mid]==key)
			return mid;

		else if(key<A[mid])
			right =mid;
		else
			left =mid+1;
	}

	return NOT_FOUND;
}


int main(){
	int n,q;

	cin >>n;
	int S[n+1];
	for(int i=0; i<n; i++)
		cin>>S[i];

	cin >>q;
	int T[q+1];
	for(int i=0; i<q; i++)
		cin>>T[i];

	int C=0;
	for(int i=0; i<q; i++){
		if(binarySearch(T[i], S,n)!=NOT_FOUND)
			C++;
	}

	cout<<C<<endl;

	return 0;
}

Measured memory_bytes: 1744
#include<bits/stdc++.h>
#define pb push_back
#define ll long long int
#define pp pair<int,int>
#define pl pair<ll,ll>
#define fi first
#define si second
using namespace std;
int main() {
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]){
		cout<<"Yes\n";
	}else{
		cout<<"No\n";
	}
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

 
void solve()
{
    int n,d;cin>>n>>d;
    d=2*d+1;
    cout<<(n+d-1)/d<<endl;
}

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

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	long m;
	int n;
	long t;
	m=100000;
	
	scanf("%d",&n);
	
	for(;n>0;n--){
		m=m*1.05;
		t=m;
		if(t%1000!=0)m=m-t%1000+1000;
		
	}
	
	printf("%ld\n",m);
	
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a)-1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a)-1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<< C <<endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define FORE(a,b) for(auto &&a:b)

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF+7;
const LL LLINF = 1e18;
#define int LL
signed main(void) {
    int N, x;
    cin >> N >> x;
    VL a(N);
    REP (i, N) cin >> a[i];
    LL ans = accumulate(ALL(a), 0LL);
    VL b(a);
    FOR (k, 1, N) {
        LL sum = k*x;
        REP (i, N) {
            int id = (i-k+N)%N;
            b[i] = min(b[i], a[id]);
            sum += b[i];
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
use std::cmp::*;
use std::io::Read;
use std::collections::{BTreeMap, BinaryHeap};

#[derive(PartialEq, Eq, Debug, Copy, Clone, Default, Hash)]
pub struct Reverse<T>(pub T);

impl<T: PartialOrd> PartialOrd for Reverse<T> {
    #[inline]
    fn partial_cmp(&self, other: &Reverse<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }

    #[inline]
    fn lt(&self, other: &Self) -> bool {
        other.0 < self.0
    }
    #[inline]
    fn le(&self, other: &Self) -> bool {
        other.0 <= self.0
    }
    #[inline]
    fn gt(&self, other: &Self) -> bool {
        other.0 > self.0
    }
    #[inline]
    fn ge(&self, other: &Self) -> bool {
        other.0 >= self.0
    }
}

impl<T: Ord> Ord for Reverse<T> {
    #[inline]
    fn cmp(&self, other: &Reverse<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

#[derive(PartialEq, PartialOrd, Copy, Clone)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

fn prim<T: Ord + Copy>(g: &[BTreeMap<usize, T>]) -> Vec<(usize, usize, T)> {
    let nv = g.len();
    let v = 0;
    let mut vis = vec![false; nv];
    vis[v] = true;
    let mut h = g[v].iter().map(|(&t, &w)| Reverse((w, v, t))).collect::<BinaryHeap<_>>();
    let mut e = Vec::new();
    while let Some(Reverse((w, s, t))) = h.pop() {
        if vis[s] && !vis[t] {
            e.push((s, t, w));
            vis[t] = true;
            for (&u, &w) in g[t].iter() {
                if !vis[u] {
                    h.push(Reverse((w, t, u)));
                }
            }
        }
    }
    e
}

type Sphere = (f64, f64, f64, f64);

fn corridor_cost(s1: &Sphere, s2: &Sphere) -> f64 {
    let dx = s1.0 - s2.0;
    let dy = s1.1 - s2.1;
    let dz = s1.2 - s2.2;
    let dist = (dx * dx + dy * dy + dz * dz).sqrt();
    (dist - (s1.3 + s2.3)).max(0.0)
}

fn solve(n: usize, s: &[Sphere]) -> f64 {
    let mut g = vec![BTreeMap::new(); n];
    for i in 0..n {
        for j in 0..i {
            let c = corridor_cost(&s[j], &s[i]);
            g[j].insert(i, Total(c));
            g[i].insert(j, Total(c));
        }
    }
    let e = prim(&g);
    e.iter().map(|&(_, _, c)| c.0).sum::<f64>()
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    loop {
        let n: usize = iter.next().unwrap().parse().unwrap();
        if n == 0 {
            break;
        }
        let s = (0..n)
            .map(|_| {
                let x: f64 = iter.next().unwrap().parse().unwrap();
                let y: f64 = iter.next().unwrap().parse().unwrap();
                let z: f64 = iter.next().unwrap().parse().unwrap();
                let r: f64 = iter.next().unwrap().parse().unwrap();
                (x, y, z, r)
            })
            .collect::<Vec<_>>();
        let w = solve(n, &s);
        println!("{:.3}", w);
    }
}



Measured memory_bytes: 5188
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int n,x,y;  cin >> n >> x >> y;
    vector<int>k(n);
    for(int i = 1; i < n; i++){
        k[i] = n-i;
    }
    /*
     * i <= x || y <= j
     */
    for(int i = 1; i <= x; i++){
        for(int j = y; j <= n; j++){
            k[j-i]--;
            k[j-i-(y-x-1)]++;
        }
    }
    /*
     * i <= x || x < j < y
     */
    for(int i = 1; i <= x; i++){
        for(int j = x+1; j < y; j++){
            if(y-j+1 < j-x){
                k[j-i]--;
                k[x-i+y-j+1]++;
            }
        }
    }
    /*
     * x < i < j < y
     */
    for(int i = x+1; i < y; i++){
        for(int j = i+1; j < y; j++){
            if(i >= j)  continue;
            if(i-x + y-j + 1 < j-i){
                k[j-i]--;
                k[i-x + y-j + 1]++;
            }
        }
    }
    /*
     * x < i < y || y <= j
     */
    for(int i = x+1; i < y; i++){
        for(int j = y; j <= n; j++){
            if(i-x+1 + j-y < j-i){
                k[j-i]--;
                k[i-x+1 + j-y]++;
            }
        }
    }
    for(int i = 1; i < n; i++){
        cout << k[i] << endl;
    }
}


Measured memory_bytes: 3636
#include <stdio.h>

int main()
{
    char N[3];
    scanf("%s", N);
    if (N[0] == '7' || N[1] == '7' || N[2] == '7')
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 1712
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/
 
int main() {
    cin >> n >> s;
    FOR(i,1,n){
        if (s[i] == 'E') {
            cnt++;
        }
    }
    vi v;
    v.push_back(cnt);
    FOR(i, 1, n) {
        if (s[i] == 'E') {
            cnt--;
        }
        v.push_back(cnt);
    }
    ans = v[0];
    FOR(i, 1, n) {
        if (s[i-1] == 'W') {
            sum++;
        }
        chmin(ans, v[i] + sum);
    }
    cout << ans << Endl;
}

Measured memory_bytes: 6904
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    int n;
    cin >> n;
    string s;
    cin >> s;

    int count=0;
    for (int i=0;i<=n-3;i++)
    {
        if ((s[i]=='A')&&(s[i+1]=='B')&&(s[i+2]=='C'))
        {
            count++;
        }
    }

    cout << count << endl;
    return 0;
}


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

int numac[200005];

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

    int n, q;
    cin >> n >> q;
    string str;
    cin >> str;

    for(int i = 1; i < n; ++i){
        numac[i] = numac[i - 1];
        if(str[i] == 'C' && str[i - 1] == 'A'){
            numac[i]++;
        }
    }

    while(q--){
        int l, r;
        cin >> l >> r;
        --l;--r;
        cout << numac[r] - (l == 0 ? 0 : numac[l - 1]) - (l > 0 && str[l] == 'C' && str[l - 1] == 'A' ? 1 : 0) << "\n";
    }

    return 0;
}


Measured memory_bytes: 1488
import java.io.*;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
int a=0;
int b=0;
int ab=0;
int o=0;
while((line=br.readLine())!=null){
String str=line.substring(line.indexOf(",")+1);
if(str.equals("A")){
a++;
}
if(str.equals("B")){
b++;
}
if(str.equals("AB")){
ab++;
}
if(str.equals("O")){
o++;
}
}
System.out.printf("%d\n%d\n%d\n%d\n",a,b,ab,o);
}
}

Measured memory_bytes: 15068
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[10000];
    for (int i = 0; i < n; i++)
    {
        int m;
        cin >> m;
        a[i] = m;
    }
   if( prev_permutation(a, a + n)!=false)
    for (int i = 0; i < n; i++)
    {
        cout << a[i];
        if (i == n - 1)cout << endl;
        if (i != n - 1)cout << " ";
    }

   next_permutation(a, a + n);
        for (int i = 0; i < n; i++)
        {
            cout << a[i];
            if (i == n - 1)cout << endl;
            if (i != n - 1)cout << " ";
       }
       if( next_permutation(a, a + n)!=false)
        for (int i = 0; i < n; i++)
        {
            cout << a[i];
            if (i == n - 1)cout << endl;
            if (i != n - 1)cout << " ";
        }
}


Measured memory_bytes: 3108
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    for i in range(N):
        mn = float('inf')
        for j in range(M):
            e = abs(a[i] - c[j]) + abs(b[i] - d[j])
            if e < mn:
                ret = j + 1
                mn = e
        print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    c = [int()] * (M)  # type: "List[int]" 
    d = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, a, b, c, d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>

using namespace std;

const long long INF = 1LL<<60;
long long solve(const long long n, const long long k, const vector<long long> h) {
    vector<long long> dp(n);
    for (long long i = 0; i < n; ++i) {
        dp[i] = INF;
    }
    dp[n-1] = 0;
    for (long long i = n-1; i >= 0; --i) {
        for (long long j = 1; j <= k; ++j) {
            long long ni = i - j;
            if (ni >= 0) {
                dp[ni] = min(dp[ni], dp[i] + abs(h[ni] - h[i]));
            }
        }
    }
    return dp[0];
}

int main() {
    long long n, k; cin >> n >> k;
    vector<long long> h(n);
    for (long long i = 0; i < n; ++i) {
        cin >> h[i];
    }
    cout << solve(n, k, h) << endl;
    return 0;
}

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

int main(){ 

	int *a_heap;
	int *temp;
	int *target;
	int n = 0;
	int m = 0;
	int j=0;
	int i = 0;
	cin >> n;
//	cout << "?????°?????\????????????????????? : ";
	cin >> m;

//	cout << "?????°?????\????????????????????? : ";
	a_heap = new int[n+1]; 
	temp = new int[n+1];
	target = new int[n+m];
	for(i=0;i<=n;i++){
		a_heap[i] = 0;
		temp[i] = 0;
	}
	for(i=0;i<n+m;i++){
		target[i] = 0;
	}
	

//	cout << "??????????????????m????±???????????????????";
	for(i=1;i<=m;i++){
	cin >> target[i];
	}

//	cout << "?????????????????£???n??????m?????\?????????????????????";
	for(j=1;j<=m;j++){
		for(i=1;i<=n;i++){
			cin >> temp[i];
			if(temp[i] == target[j]){
				a_heap[i] +=1;
			}
			else a_heap[target[j]] +=1;


		}
	}
//	cout << 
		for(j=1; j<=n;j++){

	cout << a_heap[j] << endl;
		}
	delete[] a_heap;
	delete[] target;
	delete[] temp;
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
string S;
set<char> A;
int main(){
	cin>>S;
	for(int i=0;i<S.size();i++)A.insert(S[i]);
	if(A.size()==2)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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 (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n,m; cin >> n >> m;
  int ans = 1;

  for (int a=1; a*a <= m; a++) {
    if (m%a) continue; // 約数でない場合

    int b = m/a;
    if ((ll)a*n <= m) chmax(ans,a);
    if ((ll)b*n <= m) chmax(ans,b);
  }
  COUT(ans);
  return 0;
}

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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

const int N = 105;

short n, m, X, Y;
short dp[N][N][N][N], cntx[N][N], cnty[N][N];
char S[N][N];

inline void chkmax(short& x, short v){
	x = x > v ? x : v;
}

int main(){

	scanf("%hd%hd", &n, &m);
	For(i, 1, n) scanf("%s", S[i] + 1);
	For(i, 1, n) For(j, 1, m) cntx[i][j] = cntx[i][j - 1] + (S[i][j] == 'o');
	For(i, 1, m) For(j, 1, n) cnty[i][j] = cnty[i][j - 1] + (S[j][i] == 'o');
	For(i, 1, n) For(j, 1, m) if(S[i][j] == 'E') X = i, Y = j;

	short ans = 0;
	For(a, 0, n) For(b, 0, m) Forr(c, n, a) Forr(d, m, b){
		short v = dp[a][b][c][d];
		short r = min(b + Y, d), l = max(d - (m + 1 - Y), b),
			  t = min(a + X, c), s = max(c - (n + 1 - X), a);
		
	//	printf("dp[%d][%d][%d][%d] = %d [%d, %d] [%d, %d]\n", a, b, c, d, v, l, r, s, t);

		short nx = X + a + 1;
		if(l <= r && nx <= c) chkmax(dp[a + 1][b][c][d], cntx[nx][r] - cntx[nx][l] + v);
		nx = c - (n + 1 - X);
		if(l <= r && nx > a) chkmax(dp[a][b][c - 1][d], cntx[nx][r] - cntx[nx][l] + v);
		nx = Y + b + 1;
		if(s <= t && nx <= d) chkmax(dp[a][b + 1][c][d], cnty[nx][t] - cnty[nx][s] + v);
		nx = d - (m + 1 - Y);
		if(s <= t && nx > b) chkmax(dp[a][b][c][d - 1], cnty[nx][t] - cnty[nx][s] + v);
		chkmax(ans, v);
	}

	printf("%hd\n", ans);
	return 0;
}

Measured memory_bytes: 229632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B,C;
    cin >> A >> B >> C;
    if (max({A,B,C}) == A+B+C-max({A,B,C})){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define rd(x) cin >> x;
#define rda(a,n) for(int i=1;i<=n;i++) cin >> a[i];
#define wr(x) cout << x << ' ';
#define wrl(x) cout << x << '\n';
#define wra(a,n) for(int i=1;i<=n;i++) cout << a[i] << ' '; cout << '\n';
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
struct comp{
    bool operator()(int a, int b){
        return a>b;
    }
};

long long n,t,a[300005],cnt;

int main(){
    ios_base :: sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=3*n;i++) cin >> a[i];
    sort(a+1,a+3*n+1);
    for(int i=3*n-1;t<n;i-=2) t++,cnt+=a[i];
    cout << cnt;
}


Measured memory_bytes: 2560
# 2019/09/07

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[0]+list(map(int,input().split()))

cnt=sum(b)
for i in range(n-1):
    if a[i]+1==a[i+1]:
        cnt+=c[a[i]]
    
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		ll n,k;
		cin>>n>>k;
		ll h[n];
		for(ll i=0;i<n;i++)
			cin>>h[i];
		ll dp[n+1];
		memset(dp,inf,(n+1)*sizeof(dp[0]));
		dp[0]=0;
		dp[1]=0;
		for(ll i=2;i<=n;i++)
		{
			for(ll j=1;j<=k;j++)
			{
				if(i-j>=0)
					dp[i]=min(dp[i-j]+abs(h[i-1]-h[i-j-1]),dp[i]);
			}
		}
		cout<<dp[n];
		return 0;
	}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
#define all(v) v.begin(),v.end()

const int N = 200000;
int tr[4*N + 1];
int n;
int ans[N + 1], pos[N + 1], a[N + 1];
vector<int> v[N + 1];

void update(int pos, int val, int st = 0, int en = n - 1, int p = 1){
	if(st>pos || en<pos) return;
	assert(p<=4*N);
	if(st==en){
		tr[p] = val;
		return; 
	}
	int mid = (st + en) / 2;
	update(pos, val, st, mid, 2*p);
	update(pos, val, mid + 1, en, 2*p + 1);
	tr[p] = max(tr[2*p], tr[2*p + 1]);
}
int query(int l, int r, int st = 0, int en = n - 1, int p = 1){
	if(st>r || en<l) return 0;
	assert(p<=4*N);
	if(st>=l && en<=r){
		return tr[p];
	}
	int mid = (st + en) / 2;
	int left = query(l, r, st, mid, 2*p);
	int right = query(l, r, mid + 1, en, 2*p + 1);
	return max(left, right);
}

vector<int> cords;
void dfs(int u, int p = 0){
	int ns = lower_bound(all(cords), a[u]) - cords.begin();
	// cout<<u<<' '<<ns<<endl;
	int val = ((ns!=0)?(query(0, ns-1)):0) + 1;
	update(pos[u], val);
	ans[u] = query(0, n-1);
	for(auto e: v[u]){
		if(e!=p){
			dfs(e, u);
		}	
	}
	update(pos[u], 0);
}

int main() {
	
	fast();
	cin>>n; vector<pair<int, int> > b;
	for(int i = 1; i<=n; i++){
		cin>>a[i];
		b.pb({a[i], i});
	}
	sort(all(b));
	for(int i = 0; i<n; i++){
		pos[b[i].ss] = i;
		cords.pb(b[i].ff);
	}

	for(int i = 0; i<n-1; i++){
		int x, y; cin>>x>>y;
		v[x].pb(y); v[y].pb(x);
	}
	dfs(1);
	for(int i = 1; i<=n; i++){
		cout<<ans[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 35116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define INF 1000000000
#define loop(i,a,b) for(int i=a;i<b;i++)
int main()
{
    //freopen("contest.txt","r",stdin);
    //freopen("contest.txt","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,fix=1000000000000000000;
    cin>>n;
    ll a[n],mul=1,big=0;
    int flag=0;
    loop(i,0,n)
    {
        cin>>a[i];
        if(a[i]==0)
            flag=1;
        if(a[i]>=fix)
            big++;
    }
    if(flag>0)
        cout<<0<<endl;
    else
    {
        mul=1;
        if(big>1)
            cout<<-1<<endl;
        else{
        loop(i,0,n)
        {
            if(fix/mul>=a[i])
                mul*=a[i];
            else
            {
                cout<<-1<<endl;
                return 0;
            }
        }
        cout<<mul<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define t(x) cerr<<#x<<":"<<x<<'\n';
#define t2(a,n) { cerr<<#a<<" = "; for(int i=0; i<n; ++i){ cerr << a[i] << ' '; } ; cerr <<'\n'; }
#define t3(a){ cerr<<#a<<" = "; for(auto i: a){ cerr<<i<<" "; } cerr<<'\n'; }



int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	map<char,char> get;
	get['A'] = 'T';
	get['T'] = 'A';
	get['C'] = 'G';
	get['G'] = 'C';
	char x;
	cin>>x;
	cout<<get[x]<<endl;


	#ifdef LOL
	    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	#endif
	return 0;
}


Measured memory_bytes: 256
#ifdef __APPLE__
#include "bits:stdc++.h"
#else
#include <bits/stdc++.h>
#endif
#define REPP(i,j,n) for(int i=j;i<n;++i)
#define REP(i,n) REPP(i,0,n)

using namespace std;
typedef long long LL;
typedef pair<LL,LL>  PLL;
typedef complex<double> cpx;

inline LL scan(){
  static LL a ;
  scanf("%lld",&a);
  return a;
}

char s1[1000],s2[1000];
int main(){
  LL n=scan();
  scanf("%s",s1);
  scanf("%s",s2);
  LL pre=-1,vertical=1,cross=2,ans,i=0,mod = 1000000007;
  if(s1[0]==s2[0]){
    pre = vertical;
    ans=3;
    i = 1;
  }else{
    pre = cross;
    ans = 6;
    i = 2;
  }
  for(;i<n;++i){
    if(s1[i]==s2[i]){//v
      if(pre == vertical){
        ans = ans * 2 % mod;
      }
      
      
      pre = vertical;
    }
    else{//c
      if(pre == vertical){
        ans = ans * 2%mod;
      }else{
        ans = ans * 3%mod;
      }
      
      pre = cross;
      ++i;
    }
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int h,n;
    cin>>h>>n;
    int x;
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        sum+=x;
    }
    if(sum>=h)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}









Measured memory_bytes: 256