akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i = 0; i < h; i++) cin >> s[i];

    string ans = "Yes";
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == '.') continue;
            bool isok = false;
            for(int k = 0; k < 4; k++){
                if(i+dx[k] >= 0 && i+dx[k] < h && j+dy[k] >= 0 && j+dy[k] < w){
                    if(s[i+dx[k]][j+dy[k]] == '#') isok = true;
                }
            }
            if(!isok) ans = "No";
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3516
fun main(args : Array<String>) {
    var (a, b, c, d) = readLine()!!.split(" ").map { it.toInt() }

    while (true) {
        c -= b
        if (c <= 0) {
            println("Yes")
            return
        }

        a -= d
        if (a <= 0) {
            println("No")
            return
        }
    }
}

Measured memory_bytes: 36416
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

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

int main(){
    string s, t;
    cin >> s >> t;

    bool flag = false;
    REP(i, s.length()){
        if (s.compare(t) == 0){
            flag = true;
        }
        char fw = s[s.size()-1];
        s = s.substr(0, s.size()-1);
        s = fw + s;
    }
    
    if (flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
from collections import deque

s = input()

que = deque(s)
ans = 0
while que.__len__() > 1:
    if que[0] == que[-1]:
        que.popleft()
        que.pop()
    elif que[0] == 'x' and que[-1] != 'x':
        que.append('x')
        ans += 1
    elif que[0] != 'x' and que[-1] == 'x':
        que.appendleft('x')
        ans += 1
    else:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 10144
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int count = 0;
    if(a>b) {
        count+=b;
    } else {
        count+=a;
    }

    if(c>d) {
        count+=d;
    } else {
        count+=c;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;

const long long int mod=1000000007;
const long long int INF=99999999999999999;


long long int n,k,m,a[300000],b[300000],c[300000],now=0,res=0,cou=1;
string str;
int main() {
	cout << fixed << setprecision(10);
	cin>>n>>k>>str;
	for(int i=1;i<n;i++){
		if(str[i]!=str[i-1]){
			a[now]=cou;
			res+=cou-1;
			cou=1;
			now++;
			
		}else
		{
			cou++;
		}
		//cout<<res<<endl;
	}
	a[now]=cou;
	res+=cou-1;
	cou=1;
	now++;
	cout<<min(2*k+res,n-1)<<endl;
} 


Measured memory_bytes: 2560
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vll vector<ll>
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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

map<ll, ll> yaku_factor(ll N) {
	map<ll, ll> ret;
	ret[1] = 1;

	for (ll i = 2; i * i <= N; i++) {
		if (N % i == 0) {
			ret[i] = 1;
			if (i != N / i) {
				ret[N / i] = 1;
			}
		}
	}
	if (N != 1)ret[N] = 1;
	return ret;

}

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


	ll N;
	cin >> N;

	ll ret = 0;

	auto yaku = yaku_factor(N);

	for (auto y : yaku) {
		if (y.first == 1)continue;
		if ((ll)(N / (y.first-1)) == N % (y.first-1)) {
			ret += y.first-1;
		}
	}


	cout << ret << endl;




	return 0;
}


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

using namespace std;

int main()
{
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	vector<vector<int>> ans(h, vector<int>(w));
	for (int i = 0; i < b; i++) {
		for (int j = 0; j < w; j++) {
			ans[i][j] = j < a ? 0 : 1;
		}
	}
	for (int i = b; i < h; i++) {
		for (int j = 0; j < w; j++) {
			ans[i][j] = j < a ? 1 : 0;
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << ans[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 5120
#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 110
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n;
char s[N];
signed main()
{
	n=read();
	scanf("%s",s+1);
	int cnt1=0,cnt2=0;
	for (int i=1;i<=n;i++)
	if (s[i]=='R') cnt1++;else cnt2++;
	if (cnt1>cnt2) cout<<"Yes";
	else cout<<"No";
	return 0;
	//NOTICE LONG LONG!!!!!
}

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

const int maxn = 1e5 + 50;
char str[maxn];
int ans[maxn];

int main(void) {
    scanf("%s", str);
    int len = strlen(str);
    for (int i = 0; i < len; i++) {
        if (str[i] == 'R') {
            if (str[i + 1] == 'L') { ans[i] += 1; ans[i + 1] += 1; i += 1; }
            else {
                int tmp = 1, pos = i + 1;
                while (str[pos] == 'R') {
                    tmp++; pos += 1;
                }
                tmp--;
                ans[pos - 1] += tmp / 2;
                ans[pos] += tmp - tmp / 2;
                i += tmp - 1;
            }
        } else {
            int tmp = 1, pos = i + 1;
            while (str[pos] == 'L') {
                tmp++; pos += 1;
            }
            ans[i - 1] += tmp / 2;
            ans[i - 2] += tmp - tmp / 2;
            i += tmp - 1;
        }
    }
    for (int i = 0; i < len; i++) printf("%d%s", ans[i], i == len - 1 ? "\n" : " ");

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5+10;
int H,W,m;
int r[maxn], c[maxn];
int X[maxn], Y[maxn];
int idc[maxn], idr[maxn];
bool cmpc(int a,int b){return c[a] > c[b];}
bool cmpr(int a,int b){return r[a] > r[b];}
inline void MAX(int &x,int y) {if (y>x) x=y;}
int work(){
    for (int i=1;i<=W;i++) idc[i] = i;
    sort(idc+1,idc+1+W,cmpc);
    for (int i=1;i<=H;i++) idr[i] = i;
    sort(idr+1,idr+1+H,cmpr);
    int tmpx = 0;
    for (int i=1;i<=H;i++) if (r[idr[i]] == r[idr[1]]) tmpx++; else break;
    int tmpy = 0;
    for (int j=1;j<=W;j++) if (c[idc[j]] == c[idc[1]]) tmpy++;else break;
    int ans = tmpx * tmpy;

    for (int i=1;i<=m;i++){
        int rr = r[X[i]];
        int cc = c[Y[i]];
        if (rr == r[idr[1]] && cc == c[idc[1]]) ans--;
    }
    return r[idr[1]] + c[idc[1]] - (ans == 0);
}
int main(){
    scanf("%d%d%d",&H,&W,&m);
    for (int i=1,x,y;i<=m;i++){
        scanf("%d%d",&X[i],&Y[i]);
        r[X[i]]++;
        c[Y[i]]++;
    }
    printf("%d\n",work());
    return 0;
}


Measured memory_bytes: 10808
#pragma GCC optimize("O2")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<limits.h>
#include<ctime>
#define N 100001
typedef long long ll;
const int inf=0x3fffffff;
const int maxn=2017;
using namespace std;
inline int read()
{
    int f=1,x=0;char ch=getchar();
    while(ch>'9'|ch<'0')
    {
        if(ch=='-')
        f=-1;
        ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return f*x;
}
int main()
{
	int n=read(),k=read();
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int a=read();
		int tem=min(k-a,a);
		ans+=2*tem;
	}
	cout<<ans;
}

Measured memory_bytes: 256
n, m = list(map(int, input().split() ))
broken = [int(input()) for _ in range(m)]
broken.append(-1) #番兵
broken_idx = 0

mod = 10**9+7

num_way = [0] * (n+1)
num_way[0] = 1
if broken[broken_idx] == 1:
	num_way[1] = 0
	broken_idx += 1
else:
	num_way[1] = 1

for i in range(2, (n+1)):
	if broken[broken_idx] == i:
		num_way[i] = 0
		broken_idx += 1
	else:
		num_way[i] = (num_way[i-1] + num_way[i-2]) % mod

print (num_way[n])

Measured memory_bytes: 7824
from collections import deque
N,M=map(int,input().split())
S=[[] for _ in range(N)]
#隣接リスト生成
for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    S[a].append(b)
    S[b].append(a)
q=deque()
dist=[-1]*N
dist[0]=0
q.append(0)
while q:
    now=q.popleft()
    for j in S[now]:
        if dist[j] != -1:continue 
        dist[j]=now+1
        q.append(j)
print('Yes')
[print(dist[i]) for i in range(1,N)]

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

string divide[4]={"dream","dreamer","erase","eraser"};



int main(){
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  for(int i=0;i<4;i++) reverse(divide[i].begin(),divide[i].end());
  
  bool can=true;
  for(int i=0;i<s.size();){
    bool can2=false;
    for(int j=0;j<4;j++){
      string d=divide[j];
      if(s.substr(i,d.size())==d){
        can2=true;
        i+=d.size();
      }
    }
    if(!can2){
      can=false;
      break;
    }
  }
  
  if(can) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n,k;
double mid,Left,Right,len[200005];
const double eps=1e-6;
bool Judge(double lim)
{
	int cnt=0;
	for(int i=1;i<=n;i++) cnt+=ceil(len[i]/lim)-1;
	return cnt<=k;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%lf",&len[i]),Right=max(Right,len[i]);
	while(abs(Left-Right)>eps)
	{
		mid=(Left+Right)/2.0;
		if(Judge(mid)) Right=mid;
		else Left=mid;
	}
	printf("%.0lf\n",ceil(Left));
	return 0;
}


Measured memory_bytes: 5260
#include <iostream>
#include <vector>
#define ll long long
using namespace std;

bool check(ll t, const vector<ll> &h, ll n, ll a, ll b) {
    ll num = 0;
    for (int i = 0; i < n; i++) {
        ll rest;
        rest = h[i] - b * t;
        if (rest > 0) {
            num = num + (rest + (a - b - 1)) / (a - b);
        }
    }
    return (t >= num);
}

int main() {
    ll n, a, b;
    ll max = 0;
    cin >> n >> a >> b;
    vector<ll> h(n);
    for (ll i = 0; i < n; i++) {
        cin >> h[i];
        if (h[i] > max) {
            max = h[i];
        }
    }

    ll min = 0;
    while ((max - min) > 1) {
        if (check(((min + max) / 2), h, n, a, b)) {
            max = (min + max) / 2;
        } else {
            min = (min + max) / 2;
        }
    }

    cout << max << endl;
    return 0;
}



Measured memory_bytes: 1024
A = list(map(int, input().split()))
k = int(input())

ans = 0
for i in range(k):
    ptn = [
        A[0]*2+A[1]+A[2],
        A[0]+A[1]*2+A[2],
        A[0]+A[1]+A[2]*2,
    ]
    idx = ptn.index(max(ptn))
    if idx == 0:
        A = [A[0]*2, A[1], A[2]]
    elif idx == 1:
        A = [A[0], A[1]*2, A[2]]
    else:
        A = [A[0], A[1], A[2]*2]

    ans = max(ptn)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T=ll>
using v =vector<T>;
template<typename T=ll>
using vv = vector<v<T>>;
template<typename T=ll,typename U=ll> using p = pair<T,U>;
const ll INF = (ll)1e9;
template<typename T> T chmin(T &a,T b){a=min(a,b);}
template<typename T> T chmax(T &a,T b){a=max(a,b);}

void a(){
    ll n,r; cin >> n >> r;
    cout << (n>=10?r:100*(10-n)+r);
}

void b(){
    ll n,k; cin >> n >>k;
    ll ans=0;
    for(int i=0;n!=0;i++){
        ans=i;
        n/=k;
    }
    cout << ans+1 << endl;
}

void c(){
    ll n; cin >> n;
    auto x=v<>(n,0);
    rep(i,n) cin >> x[i];
    ll ans = INF;
  	rep(i,100){
      	ll k = 0;
      	rep(j,n){
        	k += (x[j]-(i+1))*(x[j]-(i+1)); 
        }
      chmin(ans,k);
    }
    cout << ans;
}

int main(){
    c();
    return 0;
}

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

using namespace std;

int main( ) {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,a,b,c;
	t = 1;
	while(t--) {
	 cin >> a >> b >> c;
	 if(a == b && b == c )
	  cout << 1 << endl;
	 else if(a == b || b == c || c == a)
	  cout << 2 << endl;
	 else
	  cout << 3 << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define pi 3.1415926535897932384
#define INF 2147483647
#define MOD 1000000007
#define MAX 200005
using namespace std;

typedef long long ll;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    double arr[105];

    cin>>n;
    double sum = 0;
    for(int i = 0; i < n; i++){
        cin>>arr[i];
        sum += (1 / arr[i]);
    }

    double res = 1 / sum;
    cout<<setiosflags(ios::fixed)<<setprecision(10);
    cout<<res<<endl;

    return 0;
}



Measured memory_bytes: 256
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    d, t, s = map(int, input().split())
    p = s * t
    if d > p:
        return "No"
    return "Yes"


def main():
    print(solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 9156
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<long long> leaf(n + 1);
  for (int i = 0; i <= n; i++) {
    cin >> leaf[i];
  }
  vector<long long> max_node(n + 1), min_node(n + 1);
  if (leaf[0] > 1) {
    cout << -1 << endl;
    return 0;
  }
  max_node[0] = 1 - leaf[0];
  min_node[0] = 1 - leaf[0];
  cerr << 0 << " " << max_node[0] << " " << min_node[0] << endl;
  for (int i = 1; i <= n; i++) {
    long long mx = min((long long) 1e18, max_node[i - 1] * 2);
    long long mi = min((long long) 1e18, min_node[i - 1]);
    if (leaf[i] > mx) {
      cout << -1 << endl;
      return 0;
    }
    max_node[i] = mx - leaf[i];
    min_node[i] = max(0LL, mi - leaf[i]);
    //cerr << i << " " << max_node[i] << " " << min_node[i] << endl;
  }
  vector<long long> non_leaf(n + 1);
  non_leaf[n] = 0;
  for (int i = n - 1; i >= 0; i--) {
    long long need = non_leaf[i + 1] + leaf[i + 1];
    if ((need + 1) / 2 > max_node[i] || min_node[i] > need) {
      cout << -1 << endl;
      return 0;
    }
    non_leaf[i] = min(max_node[i], need);
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans += non_leaf[i] + leaf[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6388
import numpy as np

h, w = map(int, input().split())

board = np.array([list(input()) for i in range(h)])

t_h = []
t_w = []
for i in range(h):
    if np.count_nonzero(board[i] == ".") != w:
        t_h.append(i)
for i in range(w):
    if np.count_nonzero(board[:,i] == ".") != h:
        t_w.append(i)

for y in t_h:
    for x in t_w:
        print(board[y][x],end="")
    print()


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

int d[3][33333];
int main() {
    int n, r = 0;
    string s;
    cin >> n >> s;
    for(int i = 0; i < n; i++) {
        for(int x = 0; x < 100; x++)
            if(d[1][x])
                d[2][x * 10 + s[i] - '0'] = 1;
        for(int x = 0; x < 10; x++)
            if(d[0][x])
                d[1][x * 10 + s[i] - '0'] = 1;
        d[0][s[i] - '0'] = 1;
    }
    for(int x = 0; x < 1000; x++)
        r += d[2][x];
    cout << r << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

int main() {
    ll n;
    cin >> n;
    vector<ll>v;
    ll s = 1;
    set<ll>se;
    for (ll i = 0; i < n; i++) {
        ll x;
        cin >> x;
        v.push_back(x);
        se.insert(x);
    }
    if(se.count(0) == 1) {
        cout << 0 << endl;
        return 0;
    }
    for (ll i = 0; i < n; i++) {
       if (1000000000000000000/s >= v[i]) {
        s = s * v[i];
       }
       else {
        cout << -1 << endl;
        return 0;
       }
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 8732
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

int r, p, s;

int opnum(char x) {
    if (x == 's') {
        return (r);
    }
    if (x == 'r') {
        return (p);
    }
    if (x == 'p') {
        return (s);
    }
    return 0;
}
char op(char x) {
    if (x == 's') {
        return ('r');
    }
    if (x == 'r') {
        return ('p');
    }
    if (x == 'p') {
        return ('s');
    }
    return 0;
}

int main() {
    long a, n, ans = 0;
    string s;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        a = i;
        s = to_string(a);
        if (s.size() % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
S = input()

FA = False
FB = False
FC = True
BC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

if S[0] == "A":
    FA = True

cnum = 0

for i in range(len(S)):

    if ( 2 <= i ) and ( i <= len(S)-2 ) and S[i] == "C" :
        cnum += 1

    elif i != 0 and ( S[i] in BC ):

        FC = False


if cnum == 1:
    FB = True


if FA and FB and FC:
    print ("AC")

else:
    print ("WA")


Measured memory_bytes: 3064
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b ] <- readInts
	print $ which ( a + b ) ( b - a ) $ b `mod` a == 0

Measured memory_bytes: 380
N = int(input())
S = input()

List = list(S)
length = len(List)
cnt  = 0

for i in range(length):
  a = List[i]
  if a == "A" and i < length-2:
    if List[i+1] == "B" and List[i+2] == "C":
      cnt = cnt + 1
      
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define pi 3.141592653589793238462643383279502884197
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	int a=0,b=0,ab=0;
	cin>>n;
	int ans = 0;
	for(int i=0;i<n;i++){
		string st;
		cin>>st;
		if( st[0] == 'B' && st[st.size()-1] == 'A' )ab++;
		else if( st[0] == 'B' ) b++;
		else if( st[st.size()-1] == 'A' ) a++;
		for(int j=0;j<st.size()-1;j++){
			if( st[j] == 'A' && st[j+1] =='B' ) ans++;
		}
	}
	//cout<<a<<b<<ab<<endl;
	if( a > 0 && b > 0 ){
		ans += ab+1;
		a--; b--;
	}
	else if( a > 0 ){
		ans += ab;
		a--;
	}
	else if( b > 0 ){
		ans += ab;
		b--;
	}
	else {
		ans += max( ab-1, 0LL );
	}
	ans += min(a,b);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n,x = map(int, input().split())
a = []
cnt = 0
for i in map(int, input().split()):
    if x < i:
        cnt += i-x
        i = x
    a.append(i)

for i in range(1,n):
    if a[i-1] + a[i] > x:
        tmp = a[i] - (x - a[i-1])
        cnt += tmp
        a[i] -= tmp
print(cnt)

# print(a)

Measured memory_bytes: 14020
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1LL << 60;

ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }
    else{
        return gcd(b,a%b);
    }
}

int main() {
    
    ll A,B;
    cin >> A >> B;

    ll ans;
    ll c = gcd(A,B);
    ans = A / c * B;

    cout << ans << endl;

}

Measured memory_bytes: 3576
import numpy as np


def gcd(a, b):
    c = max(a,b)
    d = min(a,b)
    r = c % d
    if r == 0:
        return d
    else:
        return gcd(d, r)


monsterNum = int(input())
monsterHPArray = np.array(list(map(int, input().split())))
a = monsterHPArray[0]
for i in range(1, monsterNum):
    b = monsterHPArray[i]
    # print(a)
    # print(b)
    a = gcd(a, b)

print(a)


Measured memory_bytes: 23116
#
# 6d
#


def main():
    n, m = map(int, input().split())
    A = [[0 for i in range(m)] for j in range(n)]
    B = [0 for i in range(m)]
    C = [0 for i in range(n)]
    for i in range(n):
        A[i] = list(map(int, input().split()))
    for i in range(m):
        B[i] = int(input())

    for i in range(n):
        for j in range(m):
            C[i] += A[i][j] * B[j]
        print(C[i])


if __name__ == '__main__':
    main()


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

int main()  {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int cnt = 0;
  for (int a = 0; a <= A; a++) { 
    for (int b = 0; b <= B; b++) {
      for (int c = 0; c <= C; c++) {
        int total = 500*a + 100*b + 50*c;
        if (total == X) cnt++;
      }
    }
  }
  cout << cnt << endl;
  
}



Measured memory_bytes: 256
/*  ex3_4
    hangan2020 */
 
#include <stdio.h>
int main(void){
    int number, divider;
    scanf("%d", &number);
 
    //Devide the input number by 1,2,3..,10
    for (divider = 1; divider <= 10; ++divider){
    //If there exist a number in 1,2,3..,10 that is divisble and the quotient is smaller than 10, print Yes
    if ((number % divider == 0) && (number / divider < 10) && (divider < 10)){
        printf("Yes\n");
        break;
    }
    //If there exist no number that satisfy the upper condition, print No
    else if(divider >= 10) {
        printf("No\n");
    }
    else{}
    }
    return 0;
}

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

int main() {
	// your code goes here
	string s;
	cin>>s;
	int mx =0;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='+') mx++;
		else mx--;
	}
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>

using namespace std;
typedef long long li;

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

    li n;
    cin >> n;
    vector<li> xs(n);

    for (int i = 0; i < n; ++i) {
        cin >> xs[i];
    }
    reverse(xs.begin(), xs.end());

    bool ok = true;
    li prev = xs[0];
    for (int i = 0; i < n; ++i) {
        if (xs[i] <= prev) {
            prev = xs[i];
        } else if (xs[i] == prev + 1) {
            continue;
        } else {
            ok = false;
            break;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


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


int main(void) {
    int L, R;
    cin >> L >> R;

    R = min(R,L+4038);
    int res = 100000;
    bool flag = false;
    for(long long i = L;i < R;i++){
        for(long long j = i+1;j <= R;j++){
            int ans = i * j % 2019;
            if(ans < res)res = ans;
        }
    }
    cout << res << endl;

}


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

using namespace std;
using ll = long long;


int main()
{
    int n, m; cin >> n >> m;
    vector<int> cnt(n);
    for(int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        cnt[a - 1]++;
        cnt[b - 1]++;
        cnt[a - 1] %= 2;
        cnt[b - 1] %= 2;
    }
    cout << (count(cnt.begin(), cnt.end(), 1) ? "NO" : "YES") << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int prime[1000000];
int main() {
	prime[0] = -1;
	prime[1] = -1;
	for (int i = 2; i<1000000; i++) {
		if (prime[i] == 0) {
			prime[i] = 1;
			for (int j = i * 2; j<1000000; j += i)prime[j] = -1;
		}
	}
	int now;
	while (~scanf("%d", &now)) {
		int ans = 0;
		for (int i = 1; i<now + 1; i++)if (prime[i] == 1)ans++;
		printf("%d\n", ans);
	}
}


Measured memory_bytes: 6484
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long int ll;
ll n,ans;
 
int main(){
	cin>>n;
	for(ll i=2;i*i<=n;i++){
		int cnt=0;
		while(n%i==0){
			n/=i;
			cnt++;
		}
		int x=1;
		while(cnt>=x){
			ans++;
			cnt-=x;
			x++;
		}
	}
	if(n>1)ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3636
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {

int n,m,c=0;double tot=0.0;cin>>n>>m;
int arr[102];
for(int i=1;i<=n;++i)
{
	cin>>arr[i];

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

	tot+=arr[j];
	}
for(int y=1;y<=n;y++)
{
   if(arr[y]>=(tot/(4*m)))
   {
	c++;
   }


}if(c>=m)
	cout<<"Yes"<<endl;
else
	cout<<"No"<<endl;















    return 0;
}


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

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(3);

	constexpr double EPS = 1e-7;

	for(double a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;) {
		double x, y;
		if(abs(e) < EPS) {
			x = (f - c * e / b) / (d - a * e / b);
			y = (c - a * x) / b;
		}
		else {
			x = (c - f * b / e) / (a - d * b / e);
			y = (f - d * x) / e;
		}

		cout << x << " " << y << endl;
	}

	return EXIT_SUCCESS;
}

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

using namespace std;

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    if((N-1)%(K-1)==0)
        cout<<(N-1)/(K-1);
    else
        cout<<(N-1)/(K-1)+1;
    
}

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


using namespace std;


using ull = unsigned long long;


int main()
{
    ull N;
    map<ull, ull> cnt;

    cin >> N;

    for (ull i = 0; i < N; i++) {
        ull tmp;
        cin >> tmp;
        if (cnt.find(tmp) == cnt.end())
            cnt[tmp] = 1;
        else
            cnt[tmp]++;
    }

    vector<pair<ull, ull>> a;
    for (auto e : cnt) {
        a.push_back(make_pair(e.first, e.second));
    }
    sort(a.begin(), a.end(), [](auto &l, auto &r) { return l.first > r.first; });

    ull ans = 0;
    ull x, y;
    x = y = 0;
    for (auto &e : a) {
        if (e.second >= 2) {
            e.second -= 2;
            x = e.first;
            break;
        }
    }
    for (auto &e : a) {
        if (e.second >= 2) {
            e.second -= 2;
            y = e.first;
            break;
        }
    }

    // cout << "x: " << x << ", y: " << y << endl;
    cout << x * y << endl;
}


Measured memory_bytes: 8696
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::map;
using std::stoi;
using std::string;

int main() {
  map<bool, string> ops;
  ops[true]  = "+";
  ops[false] = "-";
  string s;
  cin >> s;
  int A, B, C, D;
  A = stoi(s.substr(0, 1));
  B = stoi(s.substr(1, 1));
  C = stoi(s.substr(2, 1));
  D = stoi(s.substr(3, 1));
  for (int bits = 0; bits <= 7; ++bits) {
    int sum = A;
    bool op1 = bits >> 0 & 1;
    bool op2 = bits >> 1 & 1;
    bool op3 = bits >> 2 & 1;
    sum += op1 ? B : -B;
    sum += op2 ? C : -C;
    sum += op3 ? D : -D;
    if (sum == 7) {
      cout << A << ops[op1] << B << ops[op2] <<
              C << ops[op3] << D << "=7" << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        // 1-origin index0は使わない
        int[] five = new int[20001];
        int[] two = new int[20001];

        for (int i = 5; i <= 20000; i *= 5) {
            for (int j = i; j <= 20000; j += i) {
                five[j]++;
            }
        }

        for (int i = 2; i <= 20000; i *= 2) {
            for (int j = i; j <= 20000; j += i) {
                two[j]++;
            }
        }

        String line;

        while (!(line = br.readLine()).equals("0")) {
            int n = Integer.parseInt(line);

            int twoNum = 0;
            int fiveNum = 0;

            for (int i = 0; i <= n; i++) {
                twoNum += two[i];
                fiveNum += five[i];
            }

            System.out.println(Math.min(twoNum, fiveNum));
        }
    }
}


Measured memory_bytes: 24268
#include<iostream>
#include<string>
using namespace std;
int main(){
  string w,t;
  cin >> w;
  for(int i=0;i<w.size();i++) {
    if('A'<=w[i]&&w[i]<='Z') w[i]+='a'-'A';
  }
  int ans=0;
  cin >> t;
  while(t!="END_OF_TEXT"){
    for(int i=0;i<t.size();i++) {
      if('A'<=t[i]&&t[i]<='Z') t[i]+='a'-'A';
    }
    if(w==t) ans++;
    cin >> t;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3152
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    if a + b == 15:
        print("+")
    elif a * b == 15:
        print("*")
    else:
        print("x")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
int main()
{
ll n,k;
cin>>n>>k;
ll a[n];
for(ll i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
if(k>=n)
{
cout<<0<<endl;
}
else
{
ll ans=0;
for(ll i=0;i<n-k;i++)
{
ans+=a[i];
}
cout<<ans<<endl;
}
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		if(s.equals("ABC")){
			System.out.println("ARC");
		}else{
			System.out.println("ABC");
		}
	}
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

const ll mod = 1e9 + 7;

const ll INF = 1e15;

int main() {
	string s, t;
	cin >> s >> t;
	for (char c = 'a'; c <= 'z'; c++) {
		string ss = s + c;
		if(ss == t) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3628
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	double a, b, h, m; cin >> a >> b >> h >> m;
	//角度をラジアンで求める必要がある。
	//(h/12)*2pi,(m/60)*2pi

	long double ang1 = ((long double)(h*60.0+m) / (long double)720) * (long double)2 * (long double)PI;
	long double ang2 = ((long double)m / (long double)60) * (long double)2 * (long double)PI;

	long double ang = ang1 - ang2;

	long double base = a * a + b * b - (long double)2 * a*b*cos(ang);

	long double ans = sqrt(base);

	cout << fixed << setprecision(20) << ans << endl;

	return 0;

}

Measured memory_bytes: 4096
n, l = [int(e) for e in input().split()]
if l < 0 and n + l - 1 > 0:
  print(sum(range(l, n + l)))
else:
  if abs(l) > abs(n + l - 1):
    print(sum(range(l, n + l)) - (n + l - 1))
  else:
    print(sum(range(l, n + l)) - l)

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    int t = n * 800;
    t -= n / 15 * 200;
    cout << t << endl;
    return 0;
}



Measured memory_bytes: 256
n_m = input().rstrip().split(' ')

n = int(n_m[0])
m = int(n_m[1])

a_i = input().rstrip().split(' ')
a_i_list = [int(i) for i in a_i[:m]]

finish_day = sum(a_i_list)

if n >= finish_day:
  ans = n - finish_day
  print(ans)
else:
  print('-1')


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;

  rep(i,s.size()){
    s[i] += n;
    if(s[i] > 'Z') s[i] -= 26;
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<deque>
using namespace std;

string convert(int x){
	stringstream buf;
	buf<<x;
	while(buf.str().size()<5){
		string tmp = buf.str();
		buf.str("");
		buf<<" "<<tmp;
	}
	return buf.str();
}

int main(){
	int n;
	cin>>n;
	stringstream buf;
	while(n!=0){
		vector< vector<int> > table;
		for(int x=0;x<n;++x){
			vector<int> tmp;
			int sum = 0;
			for(int i=0;i<n;++i){
				int j;cin>>j;
				tmp.push_back(j);
				sum +=j;
			}
			tmp.push_back(sum);
			table.push_back(tmp);	
		}
		vector<int> tmp;
		for(int x=0;x<table[0].size();++x){
			int sum = 0;
			for(int y=0;y<table.size();++y){
				sum += table[y][x];
			}
			tmp.push_back(sum);
		}
		table.push_back(tmp);

		for(int x=0;x<table.size();++x){
			for(int y=0;y<table[x].size();++y){
				buf<<convert(table[x][y]);
			}
			buf<<"\n";
		}
		cin>>n;
	}
	cout<<buf.str();
	return 0;
}

Measured memory_bytes: 1276
def solve(times)
  ok, ng = [0] * 3, [0] * 3
  times.each do |t|
    a, b = t.split
    h = a.split(':')[0].to_i
    m = (b.to_i - a.split(':')[1].to_i + 60) % 60
    if 11 <= h && h <= 14
      m > 8 ? ng[0] += 1 : ok[0] += 1
    elsif 18 <= h && h <= 20
      m > 8 ? ng[1] += 1 : ok[1] += 1
    elsif 0 <= h && h < 2 || 21 <= h && h <= 23
      m > 8 ? ng[2] += 1 : ok[2] += 1
    end
  end
  [ok, ng]
end

while n = gets.to_i
  break if n == 0
  ok, ng = solve(n.times.map{ gets.chomp })
  sum = ok.zip(ng).map{ |t| t.reduce(:+) }
  dish = ['lunch ', 'dinner ', 'midnight ']
  3.times do |i|
    puts dish[i] + (sum[i] == 0 ? 'no guest' : (ok[i] * 100 / sum[i]).to_s)
  end
end

Measured memory_bytes: 8772
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }


main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k, a[3];
    cin >> n >> k;
    cin >> a[0] >> a[1] >> a[2];
    string s;
    cin >> s;
    int ans = 0;
    auto wins = [&] (int x, int y) {
        if (x == y) return 0;
        if (x == 0) {
            return y == 1 ? a[0] : 0;
        }
        if (x == 1) {
            return y == 2 ? a[1] : 0;
        }
        return y == 0 ? a[2] : 0;
    };
    map<char, int> to;
    to['r'] = 0;
    to['s'] = 1;
    to['p'] = 2;
    for (int i = 0; i < k; i++) {
        vector <int> dp(3, 0);
        vector <int> new_dp(3, 0);
        for (int j = i; j < n; j += k) {
            for (int last = 0; last < 3; last++) {
                for (int cur = 0; cur < 3; cur++) {
                    if (cur == last) continue;
                    umax(new_dp[cur], dp[last] + wins(cur, to[s[j]]));
                }
            }
            swap(dp, new_dp);
            new_dp.assign(3, 0);
        }
        ans += *max_element(all(dp));
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
#define f first
#define s second
#define pb push_back
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

ll n, m, a, b, c, dp[305][305][305], mm = 1e9+7, ans;
vector<pi> v[305];
bool ok[305][305][305];

void add(ll &a, ll b) {
	b %= mm;
	a += b;
	a %= mm;
}

int main() {
	fastio;
	cin >> n >> m;
	memset(ok, 1, sizeof ok);
	FOR(k, 1, m) {
		cin >> a >> b >> c;
		FOR(i, 0, b-1) FOR(j, 0, b-1) {
			if ((i == b and i) or (j == b and j)) {
				ok[i][j][b] = false; ok[j][i][b] = false;
				ok[i][b][j] = false; ok[j][b][i] = false;
				ok[b][i][j] = false; ok[b][j][i] = false;
				continue;
			}
			int cc = 1;
			if (i >= a) cc++;
			if (j >= a) cc++;
			if (cc != c) {
				ok[i][j][b] = false; ok[j][i][b] = false;
				ok[i][b][j] = false; ok[j][b][i] = false;
				ok[b][i][j] = false; ok[b][j][i] = false;
			}
		}
    }
	dp[0][0][0]  = 1;
	FOR(i, 0, n) {
		FOR(j, 0, n) {
			FOR(k, 0, n) {
				if (!ok[i][j][k]) continue;
				int ma = max({i, j, k});
				if (ma == n) add(ans, dp[i][j][k]);
				add(dp[ma+1][j][k], dp[i][j][k]);
				add(dp[i][ma+1][k], dp[i][j][k]);
				add(dp[i][j][ma+1], dp[i][j][k]);
			}
		}
	}
	cout << ans;
}


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

int main(int argc, char const *argv[])
{
	long long n,m;
	cin>>n>>m;
	if (n==1LL&&m==1LL)
	{
		cout<<"1\n";
	}
	else if (n==1LL||m==1LL)
	{
		cout<<max(n,m)-2LL<<endl;
	}
	else
	{
		cout<<(n-2LL)*(m-2LL)<<endl;
	}
	return 0;
}


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

int main(){
	string a,b;
  cin>>a>>b;
  
  int l=0;
  if(a.length()>b.length()) {
  	cout<<"GREATER\n";
  
  	return 0;
  }
  else if(a.length()<b.length()) {
  	cout<<"LESS\n";
  
  	return 0;
  }
  while(l!=a.length()&& a[l]==b[l]) l++;
  if(l==a.length()) {
  	cout<<"EQUAL\n";
  
  	return 0;
  }
  else if(a[l]>b[l]) {
  	cout<<"GREATER\n";
  
  	return 0;
  }
  else cout<<"LESS\n";
}

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,c;
    cin >> a >> b >> c;
    int ans = 0;
    int ma = max(max(a,b),c);
    int dif = ma*3 - a- b- c;
    if(dif%2 == 0) ans = dif/2;
    else ans = (dif+3)/2;
    cout << ans << endl;
}

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

using namespace std;

char s[1000000];

int main() {
    cin >> s;
    int len = strlen(s), flag = 0;
    for (int i = 0; i < len; ++i)
    if (s[i] == 'C' && !flag) flag = 1;
    else if (s[i] == 'F' && flag == 1) flag = 2;
    if (flag == 2) puts("Yes");
    else puts("No");
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;

typedef long long LL;
const int Maxn=1e5+5;
char a[Maxn+5];

int main(){
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
	int sum=0;
	for(int i=1;i<=n;i++){
		int t=i,cnt=0;
		while(t){
			cnt+=t%10;
			t/=10;
		}
		if(a<=cnt && cnt<=b){
			sum+=i;
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,Q;
    cin >> N >> Q;
    string s;
    cin >> s;
    int r[Q],l[Q];
    for(int i=0;i<Q;i++){
        cin >> r[i] >> l[i];
    }
    int count[N];
    for(int i=0;i<N;i++)count[i] = 0;

    for(int i=0;i<N;i++){
        if(s[i]=='A'&&s[i+1]=='C'){
            count[i+1]++;
        }
    }
    for(int i=1;i<N;i++){
        count[i+1] = count[i]+count[i+1];
    }
    for(int i=0;i<Q;i++){
        cout << count[l[i]-1]-count[r[i]-1] << endl;
    }
}

Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int N, K;
ll a[101010];
ll sum[101010];
ll sum1[101010];

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

	cin >> N >> K;
	for (int i = 0; i < N; i++)cin >> a[i];
	for (int i = 0; i < N; i++)sum[i + 1] += sum[i] + a[i];
	for (int i = 0; i < N; i++)sum1[i + 1] += sum1[i] + max(0LL, a[i]);

	ll ans = 0;
	for (int i = 0; i <= N - K; i++) {
		ans = max(ans,max(sum[i+K]-sum[i],0LL) + (sum1[i]-sum1[0]) + (sum1[N] - sum1[i+K]));
	}
	puts(ans);

	return 0;
}

Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
 
 
public class Main {

	static long MOD = 1_000_000_007;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		int INF = Integer.MAX_VALUE;
		Scanner sc = new Scanner(System.in);
		//char[] c = sc.next().toCharArray();
		//int N = A.length;
		int N = Integer.parseInt(sc.next());
		int[] P = new int[N];
		for(int i=0; i<N; i++){
			P[i] = Integer.parseInt(sc.next());
		}
		
		int ans = 0;
		
		for(int i=1;i<N-1;i++){
			if((P[i-1]>P[i] && P[i]>P[i+1])||(P[i-1]<P[i] && P[i]<P[i+1]))ans++;
		}
		
		System.out.println(ans);
		
	}
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (c/b);
	}
}



Measured memory_bytes: 23764