akhauriyash/Code-Regression huggingface dataset:
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
string s;
int main()
{
	cin>>s;
	for(int i=0;i+1<s.size();i++)
	{
		if(s.substr(i,2)=="AC")
		{
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <iomanip>
#include <limits>
#include <vector>
#include <algorithm>
#include <functional>

typedef long long lint;

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
lint* array(lint x) {
	lint *array = new lint[x];
	return array;
};
lint** array2(lint x, lint y) {
	lint **array = new lint*[x];
	rep(i, x)array[i] = new lint[y];
	rep(i, x)rep(j, y)array[i][j] = 0;
	return array;
}
int main() {
	int m, n;
	cin >> m >> n;
	lint** arr = array2(m+1,n+1);
	rep(i, m)rep(j, n)cin >> arr[i][j];
	rep(i, m)rep(j, n) {
		arr[i][n] += arr[i][j];
		arr[m][j] += arr[i][j];
		arr[m][n] += arr[i][j];
	}
	rep(i, m + 1) {
		rep(j, n + 1) {
			cout << (j ? " " : "")<< arr[i][j];
		}
		cout << "\n";
	}
}


Measured memory_bytes: 3160
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

void prim(int s,int[s][s], int[]);

int main(int argc, char** argv) {
    int size;
    scanf("%d", &size);
    int edges[size][size], nodeVal[size];
    for(int i = 0; i < size; i++)
        for(int j = 0; j < size; j++)
            scanf("%d", &edges[i][j]);
    prim(size,edges,nodeVal);
    int weight = 0;
    for(int i = 0; i < size; i++)
        weight += nodeVal[i];
    printf("%d\n",weight);
    return (EXIT_SUCCESS);
}

void prim(int size, int edges[size][size], int nodeVal[size]){
    int parentNode[size], check[size];
    for(int i = 0; i < size; i++){
        nodeVal[i] = INT_MAX;
        parentNode[i] = -1;
        check[i] = 0;
    }
    nodeVal[0] = 0;
    int mincost;
    int currentNode;
    while(1){
        mincost = INT_MAX;
        for(int i = 0; i < size; i++)
            if(!check[i] && nodeVal[i] < mincost){
                mincost = nodeVal[i];
                currentNode = i;
            }
        if(mincost == INT_MAX)
            break;
        check[currentNode] = 1;
        
        for(int i = 0; i < size; i++)
            if(!check[i] && edges[currentNode][i] < nodeVal[i] && edges[currentNode][i] != -1){
                parentNode[i] = currentNode;
                nodeVal[i] = edges[currentNode][i];
            }
    }
    
}



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

struct Node {
    int H, P, Q;
    Node(int h, int p, int q) : H(h), P(p), Q(q) {}

    bool operator <(const Node &t) const {
        return H < t.H;
    }
};

int main() {
    for(int N, M, A; cin >> N >> M >> A, N || M || A; ) {
        vector<Node> v;
        for(int i = 0; i < M; i++) {
            int h, p, q; cin >> h >> p >> q;
            v.push_back(Node(h, p, q));
        }

        sort(v.rbegin(), v.rend());

        int cur = A;

        for(auto it : v) {
            if(it.P == cur) {
                cur = it.Q;
            }
            else if(it.Q == cur) {
                cur = it.P;
            }
        }
        cout << cur << endl;
    }
}

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

using namespace std;
#define INFS (1LL<<28)
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
#define all(n) n.begin(),n.end()

signed main(){
	int n;
	cin>>n;
	vector<int> v,c;
	lp(i,n){
		int a;
		cin>>a;
		v.push_back(a);
		c.push_back(a);
	}
	sort(all(c));
	int cnt=0;
	lp(i,n){
		if(v[i]!=c[i])cnt++;
	}
	if(cnt==2||cnt==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
const ll MAX = 1e7;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int x, y;
	cin >> x >> y;
	if ((x + y) % 3 != 0) {
	  cout << 0 << endl;
	  return 0;
	}
	int t = (x + y) / 3;
	x -= t, y -= t;
	COMinit();
	cout << COM(x + y, x) << endl;
    
    return 0;
}



Measured memory_bytes: 238020
// https://beta.atcoder.jp/contests/abc111

#define SUBMIT

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

pair<int, int> find_max(map<int, int>& m) {
    auto max_v = -1, max_count = -1;
    for (auto p : m) {
        if (max_count < p.second) {
            max_v = p.first;
            max_count = p.second;
        }
    }

    return {max_v, max_count};
}

int compute_cost(int n, pair<int, int>& even_max_p, pair<int, int>& odd_max_p) {
    auto half = n / 2;
    return (half - even_max_p.second) + (half - odd_max_p.second);
}

int main() {
#ifdef SUBMIT
    auto& in = cin;
#else
    stringstream in(R"(4
1 1 1 1
apple
)");
#endif
    map<int, int> even_count, odd_count;

    // dummy
    even_count[0] = 0, odd_count[0] = 0;

    int n;
    in >> n;
    int v;
    for (int i = 0; i < n; ++i) {
        in >> v;
        if (i % 2 == 0) even_count[v]++;
        else odd_count[v]++;
    }

    int ans = 0;
    auto even_max_p = find_max(even_count);
    auto odd_max_p = find_max(odd_count);

    if (even_max_p.first != odd_max_p.first) ans = compute_cost(n, even_max_p, odd_max_p);
    else {
        even_count.erase(even_max_p.first);
        auto next_even_max_p = find_max(even_count);
        auto even_erase_cost = compute_cost(n, next_even_max_p, odd_max_p);

        odd_count.erase(odd_max_p.first);
        auto next_odd_max_p = find_max(odd_count);
        auto odd_erase_cost = compute_cost(n, even_max_p, next_odd_max_p);

        ans = min(even_erase_cost, odd_erase_cost);
    }

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

Measured memory_bytes: 4992
/* be name khoda */

// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl

const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

// -----------------------------------------------------------------------

const ll maxn = 100010;

ll n;

ll query(ll x) {
    string s;
    cout << x << endl;
    cin >> s;
    if (s == "Vacant") exit(0);
    else return (s == "Male");
}

// when r - l is odd a == b, when even a != b
void solve(ll l, ll r, ll a, ll b) {
    ll mid = (l + r) / 2;
    ll x = query(mid);
    if (((mid - l) % 2) ^ (a != x)) solve(l, mid, a, x);
    else solve(mid, r, x, b);
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    // ifstream cin(".in");

    cin >> n;
    ll x = query(0);
    solve(0, n, x, x);

}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
const int N=200005;
int l[N][20],r[N][20],dpl[1<<18],dpr[1<<18],f[N],x[N],a[N];
int main(){
	int n,v,m=0;
	scanf("%d%d",&n,&v);
	for (;1<<m<=v;m++);
	for (int i=m;i;i--,v>>=1) a[i]=v;
	for (int i=1;i<=n;i++) scanf("%d",&x[i]);
	for (int i=0;i<=m;i++) l[0][i]=0,r[n+1][i]=n+1;
	for (int i=1;i<=n;i++)
		for (int j=0;j<=m;j++)
		if (x[i]-x[i-1]<=a[j]) l[i][j]=l[i-1][j];
			else l[i][j]=i-1;
	for (int i=n;i;i--)
		for (int j=0;j<=m;j++)
		if (x[i+1]-x[i]<=a[j]) r[i][j]=r[i+1][j];
			else r[i][j]=i+1;
	int L=1<<m;
	for (int i=0;i<L;i++){
		dpl[i]=1;dpr[i]=n;
		for (int j=0;j<m;j++)
		if ((i>>j)&1){
			dpl[i]=max(dpl[i],r[dpl[i^1<<j]][j]);
			dpr[i]=min(dpr[i],l[dpr[i^1<<j]][j]);
		}
	}
	for (int i=0;i<L;i++)
		f[dpr[i]]=max(f[dpr[i]],dpl[(L-1)^i]);
	for (int i=1;i<=n;i++) f[i]=max(f[i],f[i-1]);
	for (int i=1;i<=n;i++)
		if (f[r[i][m]-1]>l[i][m]) printf("Possible\n");
			else printf("Impossible\n");
}

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

int N,D,T[205],C[205][3],i,t,r,dp[205][105];

int dfs(int d,int c)
{
	int t=0,r=0,i;
	if(dp[d][c]!=-1)return dp[d][c];
	if(d==D)return 0;
	for(i=0;i<N;i++)
	{
		if(C[i][0]<=T[d]&&T[d]<=C[i][1])
		{
			t=dfs(d+1,C[i][2])+abs(c-C[i][2]);
			r=t>r?t:r;
		}
	}
	return dp[d][c]=r;
}

int main()
{
	memset(dp,-1,sizeof(dp));
	scanf("%d%d",&D,&N);
	for(i=0;i<D;i++)scanf("%d",T+i);
	for(i=0;i<N;i++)scanf("%d%d%d",&C[i][0],&C[i][1],&C[i][2]);
	for(i=0;i<N;i++)
	{
		if(C[i][0]<=T[0]&&T[0]<=C[i][1])
		{
			t=dfs(1,C[i][2]);
			r=r<t?t:r;
		}
	}
	printf("%d\n",r);
	return 0;
}

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

int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;
    if (S.at(K-1) == 'A') S.at(K-1) = 'a';
    if (S.at(K-1) == 'B') S.at(K-1) = 'b';
    if (S.at(K-1) == 'C') S.at(K-1) = 'c';
    cout << S << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  rep(i, n) cin >> a[i] >> b[i] >> c[i];
  vector<ll> dp(3, 0);
  rep(i, n) {
    vector<ll> p(3);
    swap(dp, p);
    dp[0] = max(p[1] + a[i], p[2] + a[i]);
    dp[1] = max(p[2] + b[i], p[0] + b[i]);
    dp[2] = max(p[0] + c[i], p[1] + c[i]);
  }
  cout << max({dp[0], dp[1], dp[2]}) << endl;
  return 0;
}

Measured memory_bytes: 4304
N, M, R = map(int, raw_input().split(' '))
rs = map(int, raw_input().split(' '))

edge = {}
for m in xrange(M):
  a, b, c = map(int, raw_input().split(' '))
  if a not in edge: edge[a] = {}
  if b not in edge: edge[b] = {}
  edge[a][b] = edge[b][a] = c

dist = {}
for r in rs:
  if r not in dist: dist[r] = {}
  dist[r][r] = 0
  fixed = {}
  while True:
    min_idx = None
    min_dist = float('inf')
    for i, d in dist[r].iteritems():
      if i not in fixed and d < min_dist:
        min_idx = i
        min_dist = d
    if min_idx is None: break
    fixed[min_idx] = True
    current = min_idx

    for i, d in edge[current].iteritems():
      if i in fixed: continue
      total = min_dist + d
      dist[r][i] = min(total, dist[r].get(i, float('inf')))

def process(now, rs, R, arrived):
  if len(arrived) == R:
    return 0
  min_dist = float('inf')
  for r in rs:
    if r in arrived: continue
    min_dist = min(min_dist, process(r, rs, R, arrived+[r]) + dist[now][r])
  return min_dist

print min(process(r, rs, R, [r]) for r in rs)

Measured memory_bytes: 5764
#include<iostream>
#include<cstdio>
#include<algorithm>
using std::max;
inline void umx(int &a,int b){a=max(a,b);}
using std::min;
inline void umn(int &a,int b){a=min(a,b);}
const int MAXN=2e5+5,MAXS=3e5+5;
 
int n,V,K,v[MAXN];int na[MAXN];
int L[MAXN][20],R[MAXN][20];
int f[MAXS],g[MAXS];
int seq[MAXN];
 
int main()
{
	int i,k,x;scanf("%d%d",&n,&V);
	for(i=1;i<=n;i++) scanf("%d",na+i);
 
	v[0]=V;while(v[K]) v[++K]=v[K-1]>>1;
 
	for(k=0;k<=K;k++)
	{
		for(i=x=1;i<=n;i++)
			L[i][k]=x=(i>1&&na[i]-na[i-1]>v[k])?i:x;
		for(i=x=n;i;i--)
			R[i][k]=x=(i<n&&na[i+1]-na[i]>v[k])?i:x;
		R[n+1][k]=n+1;
	}
 
	std::fill(g,g+(1<<K),n+1);
	for(int S=1;S<1<<K;S++)
		for(i=1;i<=K;i++)
			if((S>>i-1)&1)
				umx(f[S],R[f[S^(1<<i-1)]+1][i]),
				umn(g[S],L[g[S^(1<<i-1)]-1][i]);
 
	for(int S=0,msk=(1<<K)-1;S<1<<K;S++)
	{
		int l=L[g[S]-1][0],r=R[f[msk^S]+1][0];
		if(l<=r) seq[l]++,seq[r+1]--;
	}
 
	for(i=1;i<=n;i++) seq[i]+=seq[i-1];
	for(i=1;i<=n;i++) puts(seq[i]?"Possible":"Impossible");
	return 0;
}

Measured memory_bytes: 37376
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;

	vector<vector<int>> edges(n, vector<int>());	
	for(int i = 0; i < m; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		edges[x - 1].push_back(y - 1);
		edges[y - 1].push_back(x - 1);
	}

	bool checked[100000];
	for(int i = 0; i < n; i++) checked[i] = false;

	int ans = 0;
	for(int i = 0; i < n; i++) {
		if(!checked[i]) {
			checked[i] = true;
			ans++;
			stack<int> stack;
			stack.push(i);
			while(!stack.empty()) {
				int s = stack.top();
				stack.pop();

				for(int t : edges[s]) {
					if(!checked[t]) {
						checked[t] = true;
						stack.push(t);
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main()
{
	int n; cin >> n;
	
	int ans = 0;
	
	for (int i = 0; i < n; i++) {
		ans += (i + 1);
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;


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

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };


using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////


void solve(std::string S){
  if(S[1]=='B') S = "ARC";
  else S = "ABC";  
  cout << S << endl;

}

int main(){ 
    cout << setprecision(10);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

#define OnlineJudge1

#define loop(x,a,n) for(int x = a;x < n;x++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

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

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )

void init(){
    cin.tie(0);
    ios::sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}

int main(){
    init();
    int x, a;   cin >> x >> a;
    if( x < a)
        cout << 0;
    else
        cout << 10;
}


Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

const int Rk = 0;
const int Sc = 1;
const int Pp = 2;

int main() {
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;

    auto total = 0;
    for (int i0 = 0; i0 < k; ++i0) {
        auto cnt = 1 + (n - 1 - i0) / k;
        if (cnt == 0)
            break;

        auto dp = vector<array<int, 3>>(cnt + 1);
        auto i = i0;

        for (auto j = 0; j < cnt; ++j, i += k) {
            if (t[i] == 'r') {
                dp[j + 1][Pp] = p + max(dp[j][Rk], dp[j][Sc]);
                dp[j + 1][Sc] = max(dp[j][Rk], dp[j][Pp]);
                dp[j + 1][Rk] = max(dp[j][Sc], dp[j][Pp]);
            }
            if (t[i] == 's') {
                dp[j + 1][Rk] = r + max(dp[j][Pp], dp[j][Sc]);
                dp[j + 1][Sc] = max(dp[j][Rk], dp[j][Pp]);
                dp[j + 1][Pp] = max(dp[j][Sc], dp[j][Rk]);
            }
            if (t[i] == 'p') {
                dp[j + 1][Sc] = s + max(dp[j][Rk], dp[j][Pp]);
                dp[j + 1][Pp] = max(dp[j][Rk], dp[j][Sc]);
                dp[j + 1][Rk] = max(dp[j][Sc], dp[j][Pp]);
            }
        }

        total += *max_element(dp[cnt].begin(), dp[cnt].end());
    }
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 4572
#include <bits/stdc++.h>
    #include<iterator>
    #define HAR BAR LAGTA HAI APUN HI J BHAGWAAN HAI!!
    #define ll long long int
    #define MAX 1e9
    #define MIN -1e9
    #define mod 1000000007
    #define pb push_back
    #define all(x) (x).begin(), (x).end()
    #define debug(x) cerr<<#x<<'='<<(x)<<endl;
    #define output(x) cout << ( x ? "YES" : "NO" ) << '\n' ;
    #define mxn 100005
    using namespace std;
    int main()
    {
       ll n;
       cin>>n;
       ll a[n];
       ll ans =0;
       cin>>a[0];
       for(int i=1;i<n;i++){
           cin>>a[i];
           if(a[i]<a[i-1]){
                ans = ans + a[i-1] - a[i];
                a[i] = a[i-1];
           }
           
       }
       cout<<ans;
        return 0;
    }

Measured memory_bytes: 5152
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define ll long long
using namespace std;
ll M=1000000007;
int n;
int c[210000];
ll f1[210000];
ll f2[210000];
ll ans=0;

int nxt[210000];
int nxt2[210000];
int loc[210000];
int flag[210000];


int main()
{
    cin>>n;
    for (int i=1; i<=n; ++i)
    {
        scanf("%d",&c[i]);
    }
    memset(loc,0,sizeof(loc));
    for (int i=n; i>=1; --i)
    {
        nxt[i]=loc[c[i]];
        loc[c[i]]=i;
    }
    memset(loc,0,sizeof(loc));
    for (int i=1; i<=n; ++i)
    {
        nxt2[i]=loc[c[i]];
        loc[c[i]]=i;
    }
    f1[0]=1;
    for (int i=1; i<=n; ++i)
    {
        f1[i]=f1[i-1];
        if (nxt2[i]>0 && nxt2[i]!=i-1)
            f1[i]+=f1[nxt2[i]];
        f1[i]%=M;
    }
    cout<<f1[n]<<endl;
    //f2[n+1]=1;
    //for (int i=n; i>=1; --i)
    //{
    //    f2[i]=f2[i+1];
    //    if (nxt[i]>0 && nxt[i]!=i+1)
    //        f2[i]+=f2[nxt[i]];
    //    f2[i]%=M;
    //}
    ////for (int i=1; i<=n; ++i)
    ////    cout<<i<<' '<<f2[i]<<endl;
    //for (int i=1; i<=n; ++i)
    //{
    //    int j=nxt[i];
    //    if (j==i+1) continue;
    //    if (j==0) continue;

    //    if (j>0)
    //    {
    //        cout<<i<<' '<<j<<' '<<f1[i]<<' '<<f2[j]<<endl;
    //        ans+=f1[i]*f2[j];
    //    }
    //    if (flag[i]==0)
    //    {
    //        //cout<<"there "<<i<<endl;
    //        //ans+=1;
    //    //    ans+=f1[i]*f2[i];
    //        for (int k=i; k<=j; ++k)
    //            flag[k]=1;
    //    }
    //    ans%=M;
    //} 
    //cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 6656
import sys
input=sys.stdin.readline

import collections
def main():
    N,W = map(int, input().split())
    I = collections.deque()
    for _ in range(N):
        I.append(tuple(map(int, input().split())))

    dp = [0]*(W+1)
    while I:
        w,v = I.popleft()
        for j in range(W, w-1, -1):
            x = dp[j-w] + v
            if x > dp[j]:
                dp[j] = x

    print(dp[W])

if __name__ == '__main__':
    main()


Measured memory_bytes: 8052
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    int ans;
    string s,t,u,sr,tr,ur;
    cin >> s;

    t = s.substr(0,(s.size() - 1) / 2);
    u = s.substr((s.size() + 3) / 2 - 1, (s.size() - 1) / 2);

    sr = s;
    tr = t;
    ur = u;

    reverse(all(s));
    reverse(all(t));
    reverse(all(u));

    if(s == sr && t == tr && u == ur){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	string s; cin >> s;
	FOR(i, 0, SZ(s) - 2) {
		set<char>se;
		FOR(j, 0, 3) {
			se.insert(s[i + j]);
		}
		if (SZ(se) <= 2) {
			cout << i + 1 << " " << i + 1 + 2 << endl;
			return 0;
		}
	}
	FOR(i, 0, SZ(s) - 1) {
		set<char>se;
		FOR(j, 0, 2) {
			se.insert(s[i + j]);
		}
		if (SZ(se) <= 1) {
			cout << i + 1 << " " << i + 1 + 1 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>	
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;

const int inf = int(2e9);
const int mod = inf + 7;
using namespace std;

const int N = 100000;

void solve(){
	int n, m;
	cin >> n >> m;
	int x[m];
	n--;
	rep(i, m) cin >> x[i];
	sort(x, x + m);
	vector<int> v;
	for(int i = 1; i < m; ++i){
		v.pb(x[i] - x[i - 1]);
	}
	sort(all(v));
	while(v.size() && n){
		n--;
		v.pop_back();
	}
	ll sum = 0;
	rep(i, v.size()){
		sum += v[i];
	}
	cout << sum;


}

int main() {
	Red;
	solve();
	return 0;
}

Measured memory_bytes: 1276
#include<iostream>
using namespace std;
int main(){
int n, pmax, p[10];
cin >> n;
cin >> p[0];
pmax=0;
for(int i=1; i<n; i++){
cin >> p[i];
if(p[i] > p[pmax])
pmax = i;
}
int sum=0;
for(int i=0; i<n; i++)
if(i == pmax)
sum += p[i]/2;
else
sum += p[i];
cout << sum;
return 0;
}

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

int main() {
	
	int N = 100000;
	
	bool a[100000];
	
	for(int i = 0; i < N; i++){
		a[i] = true;
	}
	
	a[0] = false;
	a[1] = false;
	
	for(int i = 2; i < N; i++){
		if(a[i]){
			for(int j = i * 2; j < N; j += i){
				a[j] = false;
			}
		}
	}
	
	cin >> N;
	
	int cnt = 0;
	
	for(int i = 1; i < 100000; i += 5){
		if(a[i]){
			cout << i;
			cnt++;
			if(cnt == N){
				break;
			}else{
				cout << " ";
			}
		}
	}
	
	return 0;
}



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

#define ll long long int
#define ull unsigned long long int
#define ms(a) memset(a, -1, sizeof(a))
#define Size(Array) sizeof(Array)/sizeof(Array[0])
#define s(a) sizeof(a)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define bk back
#define ed endl
#define en cout << endl
#define mod (ll)(1e9 + 7)
#define f(i, a, b) for(ll i = a; i < b; i++)
#define cin(a, n) for(ll i = 0; i < n; i++) cin >> a[i]
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MAX 100005

using namespace std;

ll dp[MAX][3];

ll ans(vector<vector<ll>> v, ll n)
{
    dp[0][0] = v[0][0];
    dp[0][1] = v[0][1];
    dp[0][2] = v[0][2];
   f(x, 1, n)
   {
       f(y, 0, 3)
       {
           dp[x][y] = v[x][y] + max(dp[x-1][(y+1)%3], dp[x-1][(y+2)%3]);
       }
   }

   return max( {dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}

int main()
{
    FAST;

    ll n, a, b, c;
    cin >> n;
    vector<vector<ll>> v(n);

    ms(dp);

    f(i, 0, n)
    {
        cin >> a >> b >> c;
        v[i].pb(a);
        v[i].pb(b);
        v[i].pb(c);

    }

    cout << ans(v, n) << ed;



    return 0;
}



Measured memory_bytes: 15104
#include <bits/stdc++.h>
#define Maxn 1007
using namespace std;
int n,m,a,b;
int ans[Maxn][Maxn];
void deal(int x)
{
	if (x==1) printf("<");
	if (x==2) printf(">");
	if (x==3) printf("^");
	if (x==4) printf("v");
	if (x==0) printf(".");
}
int main()
{
	scanf("%d%d%d%d",&n,&m,&a,&b);
	if (n%2==1)
	{
		for (int i=1;i<m;i+=2)
			if (a>0)
			{
				ans[n][i]=1;
				ans[n][i+1]=2;
				--a;
			}
	}
	if (m%2==1)
	{
		for (int i=1;i<n;i+=2)
			if (b>0)
			{
				ans[i][m]=3;
				ans[i+1][m]=4;
				--b;
			}
	}
	for (int i=1;i<n;i+=2)
		for (int j=1;j<m;j+=2)
			if (a>=2)
			{
				ans[i][j]=1,ans[i][j+1]=2;
				ans[i+1][j]=1,ans[i+1][j+1]=2;
				a-=2;
			} else if (b>=2)
			{
				ans[i][j]=3,ans[i+1][j]=4;
				ans[i][j+1]=3,ans[i+1][j+1]=4;
				b-=2;
			} else if (a==1&&b==1&&n%2==1&&m%2==1&&n>=3&&m>=3&&i+2>=n&&j+2>=m)
			{
				--a;
				--b;
				ans[i][j]=3,ans[i+1][j]=4;
				ans[i][j+1]=1,ans[i][j+2]=2;
				ans[i+1][j+2]=3,ans[i+2][j+2]=4;
			} else if (a==1)
			{
				ans[i][j]=1,ans[i][j+1]=2;
				--a;
			} else if (b==1)
			{
				ans[i][j]=3,ans[i+1][j]=4;
				--b;
			}
	if (a!=0||b!=0) printf("NO\n");
	else
	{
		printf("YES\n");
		for (int i=1;i<=n;i++)
		{
			for (int j=1;j<=m;j++)
				deal(ans[i][j]);
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 5120
import java.util.*;
import java.io.*;
import java.math.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
    static long mod=1000000007;
    // static int dx[]={1,-1,0,0};
    // static int dy[]={0,0,1,-1};
    // static int dx[]={1,-1,0,0,1,1,-1,-1};
    // static int dy[]={0,0,1,-1,1,-1,1,-1};
    // PriorityQueue<Integer> que = new PriorityQueue<Integer>(); 
    //HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
    //ArrayList<Integer> lis = new ArrayList<Integer>();
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        long s=0,ss=0,min;
        int d[]=new int[n];
        for( int i=0; i<n; i++ ){
            d[i]=sc.nextInt();
            s+=d[i];
        }
        ss=d[0];
        s-=d[0];
        min=abs(s-ss);

        for( int i=1; i<n-1; i++ ){
            ss+=d[i];
            s-=d[i];
            min=min(abs(s-ss),min);
        }


        out.println(min);       
        out.flush();
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }

    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
     
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }
}

class Pair implements Comparable<Pair>{
    int x,y;
    Pair(int x, int y) {
        this.x=x;
        this.y=y;
    } 
    public int compareTo(Pair p){//descend
        return p.x - x;
    } 

}

class P implements Comparable<P>{
    int diff,id1,id2;
    P(int diff, int id1,int id2) {
        this.diff=diff;
        this.id1=id1;
        this.id2=id2;
    } 
      
    public int compareTo(P p){//ascend
        return diff - p.diff;
    } 
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 46520
#include <stdio.h>

int main()
{
    int n, a[200010], a_[200010] = {0};
    scanf("%d", &n);
    for (int i = 1; i < n; i++)
        scanf("%d", &a[i]);

    for (int i = 0; i < n; i++)
    {
        a_[a[i] - 1]++;
    }

    for (int i = 0; i < n; i++)
    {
        printf("%d\n",a_[i]);
    }

    return 0;
}

Measured memory_bytes: 3260
import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop
INF = float("inf")
def MAIN():
    n = int(input())
    adj = [[]] * n
    for _ in range(0, n):
        U = list(map(int, input().split()))
        adj[U[0]] = zip(U[2::2], U[3::2])
    def dijkstra():
        d = [INF] * n
        d[0] = 0
        hq = [(0, 0)]
        while hq:
            u = heappop(hq)[1]
            for v, c in adj[u]:
                alt = d[u] + c
                if d[v] > alt:
                    d[v] = alt
                    heappush(hq, (alt, v))
        print("\n".join(f"{i} {c}" for i, c in enumerate(d)))
    dijkstra()
MAIN()



Measured memory_bytes: 40036
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  string s;std::cin >> s;
  set<ll>num;
  std::vector<bool> ok(10,false), ok2(100, false), ok3(1000, false);
  for(int i=0;i<n;i++){
    int now = s[i]-'0';
    for(int j=0;j<100;j++){
      if(ok2[j]) ok3[j*10+now] = true;
    }
    for(int j=0;j<10;j++){
      if(ok[j]) ok2[j*10+now] = true;
    }
    ok[now] = true;
  }
  ll c = 0;
  for(int i=0;i<1000;i++) if(ok3[i]) c++;
  std::cout << c << '\n';
  return 0;
}


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

int max(int a,int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

#define PI 3.14159265358979323846264338327950

int main(){

  int a,b,h,m;
  scanf("%d%d%d%d",&a, &b, &h, &m);

/*  double angle = abs( ((double)h + (double)m/60.0) * 30.0 - (double)m * 6.0 );

  double rad = (angle /180.0)* PI;*/

  double rad = (( ((double)h + (double)m/60.0) * 30.0 - (double)m * 6.0 ) / 180.0) * M_PI;

  //printf("%.10f ",h);
  double ans = sqrt((double)a*a + (double)b*b -(double)2*a*b*cos(rad));
  printf("%.11f",ans);

  return 0;
}


Measured memory_bytes: 2608
#include<cstdio>
long long const p=1000000007;
long long inv(long long n){
    long long r0=n,r1=p,r2,a0=1,a1=0,a2,b0=0,b1=1,b2,q1;
    while(r1>0){
        q1=r0/r1;
        r2=r0%r1;
        a2=a0-q1*a1;
        b2=b0-q1*b1;
        r0=r1;
        r1=r2;
        a0=a1;
        a1=a2;
        b0=b1;
        b1=b2;
    }
    while(a0<0)a0+=p;
    return a0%p;
}
long long ncr(long long n,long long r){
    if(r<0||r>n)return 0;
    else if(r==0||r==n)return 1;
    else return (n*ncr(n-1,r-1))%p*inv(r)%p;
}
int main(){
    long long n,m,tmp,ans=1;
    scanf("%lld%lld",&n,&m);
    tmp=m;
    for(long long l=2;l*l<=m;l++){
        if(tmp%l==0){
            int i=0;
            while(tmp%l==0){
                i++;
                tmp/=l;
            }
            ans=(ans*ncr(n+i-1,i))%p;
        }
    }
    if(tmp>1)ans=(ans*n)%p;
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n+1];
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextLong();
        }
        long ans = 0L;
        for (int i = 1; i <= n; i++) {
            long t = Math.min(a[i-1], a[i]);
            ans += t;
            a[i] -= t;
            long t2 = a[i]/2;
            ans += t2;
            a[i] -= t2*2;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 61324
N = int(input())
arr = [int(s) for s in input().split()]
F = dict()
for i in range(N-1):
    if arr[i] in F.keys():
        F[arr[i]] += 1
    else:
        F[arr[i]] = 1
for i in range(1, N+1):
    if i in F:
        print(F[i])
    else:
        print(0)


Measured memory_bytes: 118760
#include<bits/stdc++.h>
#include<ext/pb_ds/priority_queue.hpp>
#define For(i,a,b) for(i=(a);i<=(b);++i)
#define Forward(i,a,b) for(i=(a);i>=(b);--i)
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define Chkmin(a,b) a=a<b?a:b
#define Chkmax(a,b) a=a>b?a:b
using namespace std;
using namespace __gnu_pbds;
template<typename T>inline void read(T &x)
{
    T s=0,f=1;char k=getchar();
    while(!isdigit(k)&&(k^'-'))k=getchar();
    if(!isdigit(k)){f=-1;k=getchar();}
    while(isdigit(k)){s=s*10+(k^48);k=getchar();}
    x=s*f;
}

typedef long long ll;

static int a,b;

inline void solve()
{
	read(a);read(b);
	if(a+b==15)puts("+");
	else if(a*b==15)puts("*");
	else puts("x");
}

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


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	var tr [5]int
	fmt.Scanln(&N)

	mini := -1
	minv := math.MaxInt64
	for i := 0; i < 5; i++ {
		fmt.Scanln(&tr[i])
		if tr[i] < minv {
			minv = tr[i]
			mini = i
		}
	}

	t := 0
	t += mini

	groups := 0
	if N <= minv {
		groups = 1
	} else if N%minv == 0 {
		groups = N / minv
	} else {
		groups = N/minv + 1
	}

	t += (5 - mini) + groups - 1
	fmt.Println(t)
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define int long long
string s;
signed main(){
	cin >> s;

	int tmp_1 = 0, tmp_2 = 0, tmp_3 = 0;
	int m = 0;
	int tmp = 0;
	int flag = 0;
	for (int i = 0; i < s.length(); i++){
		if (s[i] == 'J'){
			if (flag == 3){
				if (tmp_2 <= tmp_3) m = max(m, tmp_2);
				flag = 0;
				tmp_1 = 0; tmp_2 = 0; tmp_3 = 0;
			}
			if (flag == 1){
				tmp_1++;
			}
			else{
				flag = 1;
				tmp_1 = 1;
			}
		}
		else if (s[i] == 'O'){
			if (flag == 3){
				if (tmp_2 <= tmp_3) m = max(m, tmp_2);
				flag = 0;
				tmp_1 = 0; tmp_2 = 0; tmp_3 = 0;
			}
			if (flag == 1){
				tmp_2 = 1;
				flag = 2;
			}
			else if (flag == 2) tmp_2++;
		}
		else if (s[i] == 'I'){
			if (flag == 2){
				if (tmp_1 < tmp_2){
					flag = 0;
				}
				else{
					tmp_3 = 1;
					flag = 3;
				}
			}
			else if (flag == 3) tmp_3++;
			else{
				flag = 0;
				tmp_1 = 0; tmp_2 = 0; tmp_3 = 0;
			}
		}
	}
	if (flag == 3){
		if (tmp_2 <= tmp_3) m = max(m, tmp_2);
	}
	cout << m << endl;
}
//JJJIIIIIOOOIIII

Measured memory_bytes: 3988
#include <iostream>

using namespace std;

int main(int argc, const char *argv[]) {
  int N;
  double X, sum = 0.0;
  cin >> N;
  string U;

  for (int i = 0; i < N; i++) {
    cin >> X >> U;
    if(U == "JPY"){
      sum += X;
    }else{
      sum += X * 380000.0;
    }
  }
  printf("%f\n", sum);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
template <typename T> 
using lim = numeric_limits<T>;
template <typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a) cout << k << "\n";
    else if (a+b >= k) cout << a << "\n";
    else cout << a-(k-(a+b)) << "\n";
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

typedef long long ll;

inline ll read()
{
	ll x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}
inline void chkmax(ll &a,ll b){if(a<b)a=b;}
inline void Return(){puts("NO");exit(0);}

const int N=1e5+9;

ll n,a[N],rt;
vector<int> e[N];

inline void dfs(int u,int fa)
{
	if(u!=rt && e[u].size()==1)
		return;

	ll mx=0,sum=0;
	for(int i=0,v;i<e[u].size();i++)
		if((v=e[u][i])!=fa)
		{
			dfs(v,u);
			sum+=a[v];
			chkmax(mx,a[v]);
		}

	if(sum<a[u] || sum>a[u]*2 || (mx*2>sum?sum-mx:sum/2)<sum-a[u])
		Return();
	a[u]=a[u]*2-sum;
}

int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1,u,v;i<n;i++)
	{
		u=read();v=read();
		e[u].push_back(v);
		e[v].push_back(u);
	}
	
	rt=1;
	while(e[rt].size()!=1)rt++;

	ll val=a[rt];
	dfs(rt,0);
	if(a[rt]!=val)
		Return();

	puts("YES");
	return 0;
}


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

int main(){
  int N;cin >> N;
  int A[200000];
  for(int i = 0;i < N;++i)
    cin >> A[i];
  sort(A, A + N);
  for(int i = 0;i < N-1;++i){
    if(A[i] == A[i + 1]){
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}


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

#define F first
#define S second

using namespace std;
typedef long double ld;
typedef long long ll;

const int max_n = 111, inf = 1000111222;
const ll inff = 1000111222333444;

int a, n, b;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++) 
#define fr(i,a,b) for(int i=a;i<b;i++) 
#define F first 
#define S second 
#define mp make_pair 
#define pb push_back 
#define ll long long 
using namespace std;

void test(){
	ll n,r;
	cin>>n>>r;
	if(n>=10)cout<<r<<"\n";
	else{
		ll ans = r + 100*(10-n);
		cout<<ans<<"\n";
	}
}

int main(){
	int t=1;
//	cin>>t;
	while(t--){
		test();
	}
}

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

vector<vector<ll>>dp;
vector<ll>w, v;
ll n;

ll F(ll idx, ll W)
{
	if (idx == n)
		return 0;
	if (dp[idx][W] != -1)
		return dp[idx][W];
	ll ans = F(idx + 1, W);
	if (w[idx] <= W)
		ans = max(ans, F(idx + 1, W - w[idx]) + v[idx]);
	return (dp[idx][W] = ans);
}

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

	ll W; cin >> n >> W;
	dp = vector<vector<ll>>(n, vector<ll>(W + 1, -1));
	w = v = vector<ll>(n);
	for (ll i = 0; i < n; i++)
		cin >> w[i] >> v[i];
	cout << F(0, W);

	return 0;
}

Measured memory_bytes: 82336
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	a := make([]int, 0)
	for i := 1; i <= 100000; i++ {
		if n%i == 0 {
			p := strconv.Itoa(i)
			q := strconv.Itoa(n / i)
			a = append(a, max(len(p), len(q)))
		}
	}
	fmt.Println(min(a))
}
func max(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#define	MM 2000000000
using namespace std;

int main(void)
{
	int w,h,i,j,k,ii,jj,a[31][31],x,y,xx,yy,flg;
	int ue[31][31],yoko[31][31];
	while(1)	{
		scanf("%d %d",&w,&h);
		if(w==0 && h==0)	break;
		for(i=0;i<h;i++)	{
			for(j=0;j<w-1;j++)	{
				scanf("%d",&yoko[i][j]);
			}
			if(i!=h-1)	{
				for(j=0;j<w;j++)	{
					scanf("%d",&ue[i][j]);
				}
			}
		}
		for(i=0;i<h;i++)	{
			for(j=0;j<w;j++)	{
				a[i][j]=MM;
			}
		}
		a[0][0]=1;
		for(i=1;i<=w*h;i++)	{
			flg=0;
			for(j=0;j<h;j++)	{
				for(k=0;k<w;k++)	{
					if(a[j][k]==i)	{
						flg=1;
						if(j>0 && ue[j-1][k]==0 && a[j-1][k]==MM)	{
							a[j-1][k]=i+1;
						}
						if(j<h-1 && ue[j][k]==0 && a[j+1][k]==MM)	{
							a[j+1][k]=i+1;
						}
						if(k>0 && yoko[j][k-1]==0 && a[j][k-1]==MM)	{
							a[j][k-1]=i+1;
						}
						if(k<w-1 && yoko[j][k]==0 && a[j][k+1]==MM)	{
							a[j][k+1]=i+1;
						}
					}
				}
			}
			if(flg==0)	break;
			if(a[h-1][w-1]==i+1)	break;
		}
		if(flg==0)	printf("0\n");
		else 	printf("%d\n",i+1);
	}
	return 0;
}


Measured memory_bytes: 1048
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };


vector<int>list(200005, 0);

signed main() {
	int x, y, z;

	cin >> x >> y >> z;

	swap(x, y);
	swap(x, z);

	cout << x << " " << y << " " << z << endl;


	return 0;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var A int
	var B int
	var C int

	fmt.Scanf("%d %d %d", &A, &B, &C)

	n := C - A + B
	if (n >= 0) {
		fmt.Printf("%d", n)
	} else {
		fmt.Printf("%d", 0)
	}
}


Measured memory_bytes: 512
import java.util.*;
import java.util.function.ToDoubleFunction;


public class Main {
    private static final String ex = "3 4";

    public static void main(String[] args) {
        solve(new Scanner(System.in));
//        solve(new Scanner(ex));
    }

    private static void solve(Scanner scanner) {
        String[] split = scanner.nextLine().split(" ");

        int N = Integer.parseInt(split[0]);
        int M = Integer.parseInt(split[1]);

        System.out.println((N - 1) * (M - 1));
    }
}


Measured memory_bytes: 21716
fun main(array: Array<String>) {
    val n = readLine()!!.toInt()
    val list = readLine()!!.split(" ").map { it.toInt() }
    var cnt = 0
    var flag = true
    repeat(n) {
        var num = list[it]
        flag = true
        while (flag) {
            if(num % 2 == 0) {
                num /=  2
                cnt++
            }
            else {
                flag = false
            }
        }
    }
    print(cnt)
}

Measured memory_bytes: 41768
#include<stdio.h>

int fibonacci(int);

int abc[45];

int main()
{
  int n;
  int i;
  for(i=0;i<45;i++) abc[i]=-1;
  
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));

  return 0;
}

int fibonacci(int n)
{
  if(n==0 || n==1) return abc[n]=1;
  if(abc[n] != -1) return abc[n];

  return abc[n]=fibonacci(n-1)+fibonacci(n-2);
}



Measured memory_bytes: 2108