akhauriyash/Code-Regression huggingface dataset:
/*input
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
*/
#include "bits/stdc++.h"
using namespace std;

long long n, a, b, c;
string s[100005];

map<char, int> mp[100005], have;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> have['A'] >> have['B'] >> have['C'];

	for(int i = 1; i <= n; ++i){
		cin >> s[i];
	}
	for(int i = n; i >= 0; --i){
		for(auto c: {'A', 'B', 'C'})
			mp[i][c] = count(s[i].begin(), s[i].end(), c) + mp[i][c];
	}
	vector<char> RES;
	for(int i = 1; i <= n; ++i){
		char c, d;
		string s = ::s[i];
		if(have[s[0]] + have[s[1]] == 0)
			return cout << "No\n", 0;
		else if(have[s[0]] == 0)
			c = s[1], d = s[0];
		else if(have[s[1]] == 0 || i == n)
			c = s[0], d = s[1];
		else {
			if(count(::s[i+1].begin(),::s[i+1].end(),s[0]))
				c = s[1], d = s[0];
			else
				c = s[0], d = s[1];
		}
		RES.push_back(d);
		--have[c];
		++have[d];
	}
	cout << "Yes\n";
	for(auto i: RES) cout << i << '\n';
}

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

int main() {
    string c, ans;
    cin >> c;

    if (c == "a" || c == "e" || c == "i" || c == "o" || c == "u") ans = "vowel";
    else ans = "consonant";

    cout << ans << endl;
}

Measured memory_bytes: 256
n = gets.to_i
s = readlines
count = 0
s_hash = Hash.new
s.each do |line|
  l = line.chars.sort.join.to_sym
  if s_hash.include? l
    count += s_hash[l]
    s_hash[l] += 1
  else
    s_hash[l] = 1
  end
end
puts count


Measured memory_bytes: 49772
def dfs(seq):
    # 返り値は、すべての数列の得点の最大値 ans です。
    ans = 0
    if len(seq) == n:
        # 数列が完成したので、得点を計算します
        score_ret = 0
        for a, b, c, d in req:
            if seq[b-1] - seq[a-1] == c:
                score_ret += d
        return score_ret  # この数列の得点を返します
    else:
        # まだ数列が完成していません
        for i in range(seq[-1], m + 1):
            seq_next = seq + (i,)  # 長さ1のタプル(i,)を連結します
            score = dfs(seq_next)  # seq_nextから派生するすベての数列の中での、得点の最大値が返ってきます
            ans = max(ans, score)  # 最大の得点を更新します
 
    # すべてが終わったので、得点の最大値を返します
    return ans
 
 
n, m, q = list(map(int, input().split()))
# reqは[[a1,b1,c1,d1],[a2,b2,c2,d2]……]が入ったリストのリストです
req = [list(map(int, input().split())) for _ in range(q)]
 
# 最終的に答えが返ってくるようにします。処理はすべてdfsメソッドでやってもらいます。
# リストだとどこかで間違えて値を書き換えそうで怖いので、タプルにしておきます
# 1番目が1の場合以外は考えなくていいので、(1,)だけやります
ans = 0
score = dfs((1,))
ans = max(ans, score)
print(ans)

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

int main()
{
    int n, a, cnt = 0;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> a;
        if( a % 2 == 0 )
            cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3100
from collections import defaultdict
N = int(input())
edge = []
relation = defaultdict(set)
for i in range(N - 1):
    a, b = map(lambda x: x - 1, map(int, input().split()))
    edge.append((a,b))
    relation[a].add(b)
    relation[b].add(a)

print(max(map(lambda x: len(relation[x]), relation)))
answer = {}
queue = []
queue.append((0, 0)) # (node_id, color_id)
already = set()
counter = 0
already.add(0)
while counter < len(queue):
    node, color = queue[counter]
    c = 1 if color != 1 else 2
    for n in relation[node]:
        if n not in already:
            queue.append((n, c))
            already.add(n)
            answer[(node, n)] = c
            c += 1
            if c == color:
                c += 1
    counter += 1
for e in edge:
    print(answer[e])

Measured memory_bytes: 81496
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int t;
LL n, a, b, c, d;
map<LL, LL> mp;
LL chk(LL x) {
	if (x == 0) return 0;
	if (mp.count(x)) return mp[x];
	
	if (x == 1) return mp[x] = d;
	LL ans = 1e18;
	if (x <= (ans + d - 1) / d) ans = min(ans, x * d);


	for (LL i = max(x - 4, 0LL); i <= x + 4; i ++) {
		if (i % 2 && i % 3 && i % 5) continue; 
		if (i % 2 == 0 && i / 2 < x) ans = min(ans, chk(i / 2) + a + abs(i - x) * d);
		if (i % 3 == 0 && i / 3 < x) ans = min(ans, chk(i / 3) + b + abs(i - x) * d);
		if (i % 5 == 0 && i / 5 < x) ans = min(ans, chk(i / 5) + c + abs(i - x) * d);

	}	
	return mp[x] = ans;

}
int main() {
	cin >> t;
	while (t --) {
		cin >> n >> a >> b >> c >> d;
		LL ans = 1e18;
		mp.clear();
		cout << chk(n) << endl;
	}
}

Measured memory_bytes: 6428
#include <iostream>
#include <string>
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <stack>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
using namespace std;
typedef long long ll;

int V, Mod;
vector<vector<int>*> *es;
vector<int> *par;
vector<ll> *dp0, *dp1;

void dfs1(int u, int p)
{
	par->at(u) = p;
	if (p >= 0) es->at(u)->erase(find(es->at(u)->begin(), es->at(u)->end(), p));
	for (auto v : *(es->at(u))) dfs1(v, u);
}
ll dfs2(int u)
{
	dp0->at(u) = 1L;
	for (auto v : *(es->at(u))) dp0->at(u) = dp0->at(u) * (dfs2(v) + 1) % Mod;
	return dp0->at(u);
}
void dfs3(int u)
{
	auto W = es->at(u)->size();
	auto x = new vector<ll>(W + 1, 1); // x[i] = t[0]*...*t[i-1], x[i+1]=x[i]*t[i]
	auto y = new vector<ll>(W + 1, 1); // y[i] = t[i]*...*t[W-1], y[i]=y[i+1]*t[i]
	for (int i = 0; i < W; i++) x->at(i + 1) = x->at(i) * (dp0->at(es->at(u)->at(i)) + 1) % Mod;
	for (int i = W - 1; i >= 0; i--) y->at(i) = y->at(i + 1) * (dp0->at(es->at(u)->at(i)) + 1) % Mod;
	for (int i = 0; i < W; i++) dp1->at(es->at(u)->at(i)) = (dp1->at(u) + 1) * x->at(i) % Mod * y->at(i + 1) % Mod;
	for (int v : *(es->at(u))) dfs3(v);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> V >> Mod;
	es = new vector<vector<int>*>();
	par = new vector<int>(V, 0);
	dp0 = new vector<ll>(V, 0);
	dp1 = new vector<ll>(V, 0);
	for (size_t i = 0; i < V; i++) es->push_back(new vector<int>());
	for (size_t i = 0; i < V - 1; i++)
	{
		int x, y; cin >> x >> y;
		es->at(x - 1)->push_back(y - 1);
		es->at(y - 1)->push_back(x - 1);
	}
	dfs1(0, -1);
	dfs2(0);
	dfs3(0);
	for (size_t u = 0; u < V; u++) cout << dp0->at(u) * (dp1->at(u) + 1) % Mod << endl;
    return 0;
}


Measured memory_bytes: 31476
#include<bits/stdc++.h>
#define maxl 100010

using namespace std;

const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;

int n,m,rt,cnt;
int ehead[maxl],rudu[maxl],fa[maxl];
struct ed
{
	int to,nxt;
}e[maxl];

inline void prework()
{
	scanf("%d%d",&n,&m);
	int u,v;cnt=0;
	for(int i=1;i<=n-1+m;i++)
	{
		scanf("%d%d",&u,&v);rudu[v]++;
		e[++cnt].to=v;e[cnt].nxt=ehead[u];ehead[u]=cnt;
	}
	for(int i=1;i<=n;i++)
	if(rudu[i]==0)
		rt=i;
}

queue <int>q;

inline void mainwork()
{
	q.push(rt);
	int u,v;
	while(!q.empty())
	{
		u=q.front();q.pop();
		for(int i=ehead[u];i;i=e[i].nxt)
		{
			v=e[i].to;
			rudu[v]--;
			if(rudu[v]==0)
			{
				fa[v]=u;
				q.push(v);
			}
		}
	}
}

inline void print()
{
	for(int i=1;i<=n;i++)
		printf("%d\n",fa[i]);
}

int main()
{
	prework();
	mainwork();
	print();
	return 0;
}

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

int main() {
	int n, m, c, ans = 0, count = 0;
	cin >> n >> m >> c;
	int a[21][21], b[21];
	for (int i = 1;i <= m;++i)cin >> b[i];
	for (int i = 1;i <= n;++i) {
		for (int j = 1;j <= m;++j) {
			cin >> a[i][j];
			ans += a[i][j] * b[j];
		}if (ans + c > 0) {
			++count; 
		}ans = 0;
	}cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
/*ID:PROG:LANG:*/
#include<bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 998244353
#define MAXN 105
using namespace std;
int n,m,mp[MAXN][MAXN],dp[MAXN][MAXN];
char s[MAXN];
int rd(){
	int x=0,tp=1;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')tp=-1;c=getchar();}
	while(c>='0' && c<='9'){x=(x*10+c-'0');c=getchar();}
	return x*tp;
}
int main(){
	// freopen("testdata.in","r",stdin);
	// freopen("1.out","w",stdout);
	n=rd(),m=rd();
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		for(int j=1;j<=m;j++)mp[i][j]=(s[j]=='#');
	}
	memset(dp,INF,sizeof(dp));
	dp[1][1]=(mp[1][1]==1);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]+(mp[i+1][j]==1 && mp[i][j]==0));
			dp[i][j+1]=min(dp[i][j+1],dp[i][j]+(mp[i][j+1]==1 && mp[i][j]==0));
		}
	}
	printf("%d\n",dp[n][m]);
	// printf("%.2lf\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>
#include <cstring>

using namespace std;

#define ll long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());


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

    if (A < C&&C < B)cout << "Yes" << endl;
    else if (B < C&&C < A)cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

std::pair<int64_t, int64_t> solve(int64_t a, int64_t b, int64_t c, int64_t d,
                                  int64_t e, int64_t f) {
  std::set<int64_t> waters;
  for (int i = 0;; ++i) {
    int64_t const waterA = a * 100 * i;
    if (waterA > f) {
      break;
    }
    for (int j = 0;; ++j) {
      int64_t const waterAB = waterA + b * 100 * j;
      if (waterAB > f) {
        break;
      }
      waters.insert(waterAB);
    }
  }
  double density = -1;
  std::pair<int64_t, int64_t> ret(0, 0);
  for (auto const water : waters) {
    int64_t const maxSugar = water / 100 * e;
    for (int i = 0;; ++i) {
      int64_t const sugarC = c * i;
      if (sugarC > maxSugar) {
        break;
      }
      if (sugarC + water > f) {
        break;
      }
      for (int j = 0;; ++j) {
        int64_t const sugarCD = sugarC + d * j;
        if (sugarCD > maxSugar) {
          break;
        }
        if (sugarCD + water > f) {
          break;
        }
        double const thisDensity = 1.0 * sugarCD / (water + sugarCD);
        if (thisDensity > density) {
          ret.first = water + sugarCD;
          ret.second = sugarCD;
          density = thisDensity;
        }
      }
    }
  }

  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t a;
  std::cin >> a;
  int64_t b;
  std::cin >> b;
  int64_t c;
  std::cin >> c;
  int64_t d;
  std::cin >> d;
  int64_t e;
  std::cin >> e;
  int64_t f;
  std::cin >> f;
  auto const res = solve(a, b, c, d, e, f);
  std::cout << res.first << " " << res.second << std::endl;
  return 0;
}


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

int main()
{
	set<string> dictionary;

	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		string instruction, data;
		cin >> instruction >> data;

		if (instruction[0] == 'i')
			dictionary.insert(data);
		else if (instruction[0] == 'f')
		{
			if (dictionary.find(data) != dictionary.end())
				cout << "yes" << endl;
			else
				cout << "no" << endl;
		}

	}

	return 0;
}


Measured memory_bytes: 32192
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define ll long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        
        ll T,a,sum=0;
        vector<ll> v;

        cin>>T;

        for (int i = 0; i < T; ++i)
        {
            cin>>a;
            v.push_back(a);
        }

        for (int i = 0; i < T; ++i)
        {
           sum+= (accumulate(v.begin(), v.end(), 0)-v[i])*v[i];

        }
        
        cout<<sum/2;


        
        return 0;
    }


Measured memory_bytes: 256
// G++ MACRO.CPP -STD=C++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>

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


int main(){
  CIN(n);vector<string> s(n);
  VECCIN(s);CIN(m2);
  vector<string> t(m2);
  VECCIN(t);
  map <string,int> m;
  REP(i,n)m[s[i]]++;
  REP(i,m2)m[t[i]]--;
  int a = 0;
  FOREACH(xx,m)
    a = max(a,xx.second);
  COUT(a);


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    char a[2][3];
    cin>>a[0];
    cin>>a[1];
    if(a[0][0]==a[1][2]&&a[0][2]==a[1][0]&&a[0][1]==a[1][1]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,k;
  int h[100005];
  
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  
  sort(h,h+n);
  int min=999999999;
  for(int i=k-1;i<n;i++){
    if(min>h[i]-h[i-k+1])min=h[i]-h[i-k+1];
  }
  
  cout<<min<<"\n";
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define pii pair<int,int>
#define INF (int)1e9
#define MOD (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	
	int tmp=max(a,b);
	tmp=max(tmp,c);
	
	cout<<a+b+c-tmp<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

main(){
  int data[2][12];
  int i, j, ans, f, n, temp;


  while(1){
    scanf("%d", &n);
    if(n==0) break;

    for(i=0;i<n;i++){
      scanf("%d", &data[0][i]);
    }

    ans=0;
    while(1){
      if((ans%2)==0){
	for(i=0;i<n;i++){
	  data[1][i]=0;
	}
	for(i=0;i<n;i++){
	  temp=data[0][i];
	  for(j=0;j<n;j++){
	    if(temp==data[0][j]) data[1][i]++;
	  }
	}
      }
      else{
	for(i=0;i<n;i++){
	  data[0][i]=0;
	}
	for(i=0;i<n;i++){
	  temp=data[1][i];
	  for(j=0;j<n;j++){
	    if(temp==data[1][j]) data[0][i]++;
	  }
	}
      }

      f=0;

      for(i=0;i<n;i++){
	if(data[0][i]!=data[1][i]) f=1;
      }

      if(f==0){
	printf("%d\n", ans);
	printf("%d", data[0][0]);
	for(i=1;i<n;i++){
	  printf(" %d", data[0][i]);
	}
	printf("\n");
	break;
      }
      ans++;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 123;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int a[N];

void solve(){
    int n, m;
    cin >> n >> m;
    int s = 0;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        s += a[i];
    }
    int cnt = m;
    m *= 4;
    for (int i = 1; i <= n; i++){
        if (a[i] * m >= s) cnt--;
    }
    if (cnt <= 0){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++){
        //cout << "case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
  int x,y,sum;
  bool flag=false;
  cin >> x >> y;
  for(int i=0;i<=x;i++){
    sum = 2*i + 4*(x-i);
    if(sum == y){
      flag = true;
      break;
    }
  }
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3656
//
//  atcoder_abc173_b.cpp
//  CF-1
//
//  Created by Avaneendra Alugupalli on 8/3/20.
//  Copyright © 2020 Avaneendra Alugupalli. All rights reserved.
// https://atcoder.jp/contests/abc173/tasks/abc173_b
//
#include <iostream>
#include <vector>
#include <bits/stdc++.h>

using namespace std;

int main () {
    
    vector<pair<string, int>> j_vector = {{"AC", 0}, {"WA", 0}, {"TLE", 0}, {"RE", 0}};
    int n;
    string j_str;
    cin  >> n;
    
    while (n--) {
        cin >>  j_str;
        for (int i = 0; i < j_vector.size(); i++) {
            if (j_vector[i].first == j_str)
                j_vector[i].second++;
        }
    }
    for (int i = 0; i < j_vector.size(); i++) {
        cout <<j_vector[i].first << " x " << j_vector[i].second << endl;
    }
    
    return 0;
}


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

int ac,wa,tle,re;


int main(){
    int n;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        if(s=="AC") ac++;
        else if(s=="WA") wa++;
        else if(s=="TLE") tle++;
        else if(s=="RE") re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3628
a, b, c, x, y = gets.chomp.split(' ').map(&:to_i)

arr = []
arr << a*x + b*y
arr << 2*c*[x,y].max

if x > y
  arr << 2*c*[x,y].min + (x-y) * a
else
  arr << 2*c*[x,y].min + (y-x) * b
end

puts arr.min

Measured memory_bytes: 1788
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var s string
    fmt.Scan(&s)
    ans := 4 - strings.Count(s,"-")*2
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func SortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}


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

signed main(void)
{
	int h,n;
	int i;
	cin >> h >> n;

	i = 0;
	while (n > i)
	{
		int a;
		cin >> a;
		h -= a;
		i++;
	}
	if (h <= 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int K;
ll sum;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> K;
    for(int i = 1; i <= K; i++){
        for(int j = 1; j <= K; j++){
            for(int k = 1; k <= K; k++){
                int g = __gcd(i, j);
                g = __gcd(g, k);
                sum += g;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_N (1<<19)
#define INF 100000000
#define MOD 1000000007
#define RANK 1000000000
#define EPS 1e-10
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> IP;

ll fib(ll x){
    x--;
    ll f1 = 1,f = 1;
    ll r1 = 1,r = 1;
    ll tmp;
    while(x){
        if(x&1){
            tmp = r1;
            r1 = (f1*r1+f*r)%MOD;
            r = (f1*r+f*(tmp-r+5LL*MOD))%MOD;
        }
        tmp = f1;
        f1 = (f1*f1+f*f)%MOD;
        f = f*(2*tmp-f+5LL*MOD)%MOD;
        x >>= 1;
    }
    return r;
}

ll k, sqk;
ll now = 0;
ll sum = 0;

int main(){
    cin >> k;
    if(k == 1){
        cout << 1 << endl;
        return 0;
    }
    if(k == 2){
        cout << 2 << endl;
        return 0;
    }
    sqk = (ll)sqrt(k);
    for(ll i = max(1LL,sqk-10); i < sqk+10; i++){
        if(i*(i+1) < k){
            continue;
        }
        now = i;
        break;
    }
    sum = now*(now-1);
    if(sum+now >= k){
        ll gu = (now*2-2)/4;
        if(sum+gu+1 >= k){
            now *= 2;
            cout << (fib(now-(k-sum-1)*2)*fib(2+(k-sum-1)*2))%MOD << endl;
        } else{
            ll ki = sum+now-k;
            now = now*2+1;
            cout << (fib(now-2*(ki+1))*fib(1+2*(ki+1)))%MOD << endl;
        }
    } else{
        sum += now;
        now *= 2;
        cout << (fib(now+1-(k-sum-1)*2)*fib(2+(k-sum-1)*2))%MOD << endl;
    }
}

Measured memory_bytes: 3016
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            var n = inputLongArray[0];
            var m = inputLongArray[1];
            var k = inputLongArray[2];

            var a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            var b = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            var aa = new long[n + 1];
            var bb = new long[m + 1];

            for (int i = 1; i <= n; i++)
            {
                aa[i] = aa[i - 1] + a[i - 1];
            }
            for (int i = 1; i <= m; i++)
            {
                bb[i] = bb[i - 1] + b[i - 1];
            }

            long ans = 0;
            for (int i = 0; i <= n; i++)
            {
                var tmp = k - aa[i];
                if (tmp < 0) break;
                var ans_b = BinarySearch(x => bb[x] <= tmp, 0, bb.Length);
                if (i + ans_b > ans)
                {
                    ans = i + ans_b;
                }
            }

            Console.WriteLine(ans);
            Console.Out.Flush();
        }
        public static int BinarySearch(Predicate<int> predicate, int ok, int ng)
        {
            while (Math.Abs(ok - ng) > 1)
            {
                int mid = (ok + ng) / 2;
                if (predicate(mid))
                {
                    ok = mid;
                }
                else
                {
                    ng = mid;
                }
            }
            return ok;
        }
    }
}


Measured memory_bytes: 78456
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("atcoder");
            //acdr
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("aaaa");
            //aa
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("z");
            //z
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("fukuokayamaguchi");
            //fkoaaauh
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string s = InputList[0];

        var sb = new System.Text.StringBuilder();

        for (int I = 0; I <= s.Length - 1; I += 2) {
            sb.Append(s[I]);
        }
        Console.WriteLine(sb.ToString());
    }
}


Measured memory_bytes: 11616
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <fstream>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <assert.h>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 998244353LL 
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
 
 
#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
 
//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)
 
struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
 
};
typedef vector<vector<Edge>> Graph;
typedef unsigned long long ull;
 
pii updtp2(pii p, int nw){
  if(p.first == -1) p.first = nw;
  else if(p.second == -1) p.second = nw;
  else if(p.first >= nw) {
    p.second = p.first;
    p.first = nw;
  }
  else if(p.second >= nw) p.second = nw;
  return p;
}
 
#define isValid(y,x) (y >=0 && y < n && x >= 0 && x < m)

const pii Dir[4] = {{-1,0}, {0,1}, {1,0}, {0,-1}};

int main(){
  int t;
  cin >> t;
  REP(_,t){
    ll n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;

    map<ll,ll> memo;
    
    memo[0] = 0;
    memo[1] = d;
    
    function<ll(ll)> func = [&](ll x){
      if(memo.count(x)) return memo[x];

      memo[x] = min({func(x/2) + x%2*d + a,func((x+1)/2) + (2-x%2)*d + a, func(x/3) + x%3*d + b,func((x+2)/3) + (3-x%3)*d + b,func(x/5) + x%5*d + c,func((x+4)/5) + (5-x%5)*d + c});
      
      if(1e11/d > x)
        memo[x] = min(memo[x], d * x);
      return memo[x];
    };
    
    cout << func(n) << endl;
  }
	return 0;
} 

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

	int a, b;
	int d, r, t=1000000000;
	double f;


	scanf("%d %d\n", &a, &b);

	if (1<=a && a<=t && 1<=b && b<=t) {
		d = a / b;
		r = a % b;
		f = (double)a / (double)b;

		printf("%d %d %f\n", d, r, f);
	}

	return 0;
}

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

struct node {
  struct node *right;
  struct node *left;
  int val;
};

typedef struct node Node;

Node *root;

void insert(Node *cur, int curVal) {
  if (cur->val == -1) {
    cur->val = curVal;
  }
  else if (curVal < cur->val) {
    if(cur->left == NULL) {
      Node *new = malloc(sizeof(Node));
      new->val = -1;
      new->left = NULL;
      new->right = NULL;
      //      printf("allocated a node\n");
      cur->left = new;
    }
    insert(cur->left, curVal);
  } else {
    if(cur->right == NULL) {
      Node *new = malloc(sizeof(Node));
      new->val = -1;
      new->left = NULL;
      new->right = NULL;
      //printf("allocated a node\n");
      cur->right = new;
    }
    insert(cur->right, curVal);
  }
}

void inorder(Node *cur){
  if (cur == NULL)
    return;

  inorder(cur->left);
  printf(" %d", cur->val);
  inorder(cur->right);
}

void preorder(Node *cur){
  if (cur == NULL)
    return;

  printf(" %d", cur->val);
  preorder(cur->left);
  preorder(cur->right);
}

int main() {
  int commands, i, num;
  char com[20];

  root = malloc(sizeof(Node));
  root->val = -1;
  root->left = NULL;
  root->right = NULL;

  scanf("%d", &commands);

  for (i = 0; i < commands; i++) {
    scanf("%s", &com);
    if (!strcmp(com, "insert")) {
      scanf("%d", &num);
      insert(root, num);
      //printf("inserted!\n");
    } else if (!strcmp(com, "print")) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
}



Measured memory_bytes: 17468
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
  int path[4]={};
  int a,b;
  bool judge=true;
  for(int i=0;i<3;i++){
    cin>>a>>b;
    path[a-1]+=1;
    path[b-1]+=1;
  }
  for(int i=0;i<4;i++){
    if(path[i]!=1 && path[i]!=2){
      judge=false;
    }
  }
  if(judge){
    cout<<"YES"<<"\n";
  }
  else{
    cout<<"NO"<<"\n";
  }
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    int dp[n+1][4];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(int i=1;i<=n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    int ans=INT_MIN;
    for(int i=0;i<3;i++){
        ans=max(ans,dp[n-1][i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    char p = '\0';
    int ans = 0;
    for (auto &c:s) {
        if (c != p) ans++;
        p = c;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 512
import java.util.*;

class Main
{
  	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      String as= sc.next();
      char[] s = as.toCharArray();
      int k = sc.nextInt();
      for(int i=0; i<n; i++){
          if(s[i] != s[k-1]){
            s[i]='*';		
          }
          System.out.print(s[i]);
      }
    }
	
}


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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
 ll gcd(ll a,ll b){
 if(b == 0) return a;
 return gcd(b,a%b);
 }

//最小公倍数
 ll lcm(ll a,ll b){
 ll g = gcd(a,b);
 return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 

#define INF 1LL<<60



  int main(){
    int N;
    cin >> N;
    REP(i, 9)REP(j ,9){
      if((i + 1) * (j + 1) == N){
        yes;
        return 0;
      }
    }
  no;
  }


Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
	static void Main()
	{
		var input = Console.ReadLine().Split();
		var a = int.Parse(input[0]);
		var b = int.Parse(input[1]);
		var c = int.Parse(input[2]);

		int count = 0;
		Enumerable.Range(a, b - a + 1).ToList().ForEach(x => { if (c % x == 0) count++; });
		Console.WriteLine(count);
	}
}

Measured memory_bytes: 9628
#define _GLIBCXX_DEBUG
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

void solve() {
    string S;
    cin >> S;
    int ans = 0;
    rep(i, S.size()) {
        for (int j = i; j < S.size(); j++) {
            string T = S.substr(i, j - i + 1);
            int cur = 0;
            for (auto &e : T) {
                if (e != 'A' && e != 'G' && e != 'C' && e != 'T') {
                    cur = 0;
                    break;
                }
                cur++;
            }
            ans = max(ans, cur);
        }
    }
    cout << ans << "\n";
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
int main() {
    
    
    long long n,m,a,b;
    cin>>n>>m;

    vector<vector<long long>> adj(n,vector<long long>());
    while(m--)
    {
        cin>>a>>b;
        a--;
        b--;

        adj[a].push_back(b);
        adj[b].push_back(a);
    }

        vector<int> d(n,INT_MAX),vis(n,0),p(n,-1);

        queue<int> q;
        q.push(0);
        vis[0] = 1;
        
        d[0] = 0;
        
        while(!q.empty())
        {
            int v = q.front();
            q.pop();

            for(auto u:adj[v])
            {
                if(!vis[u])
                {
                    vis[u]=1;
                    q.push(u);
                    d[u] = d[v]+1;
                    p[u] = v;
                }
            }
        }

        if(count(vis.begin(),vis.end(),0)==0)
        {
            cout<<"Yes"<<endl;
            for(int v=1;v<n;v++) cout<<p[v]+1<<endl;
        }

        else cout<<"No"<<endl;
    
	return 0;
}

Measured memory_bytes: 13232
# https://atcoder.jp/contests/abc127/tasks/abc127_d
# 難しいこと考えすぎないこと。数字を書き換えるとは言ってるけどCjをBj枚追加して大きい方からN枚取るのが最適
# 具体的にBj枚追加していくと死ぬので、枚数はタプルでその数とともに保持しておく


import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


from collections import Counter

N, M = read_ints()
A = read_ints()
BC = read_tuple(M)


cnter = Counter(A)
for b, c in BC:
    cnter[c] += b

num_and_cnt = list(cnter.items())
num_and_cnt.sort(reverse=True)

ans = 0
total = 0
for num, cnt in num_and_cnt:
    if total + cnt <= N:
        total += cnt
        ans += num * cnt
    else:
        while total < N:
            ans += num
            total += 1

print(ans)


Measured memory_bytes: 51476
#include<stdio.h>
int num(int a)
{
	int sum;
	if(a>0)
	{	
		sum=a%10;
		sum+=num(a/10);
	}
	else
		return 0;
	return sum;
}
int main()
{
	int n,t;
	scanf("%d",&n);
	t=num(n);
	if(n%t==0)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
N,A,B = map(int,input().split())
ans = 0
for i in range(1,N+1):
  K = str(i)
  if len(K) == 1:
    if A<=int(K[0])<=B:
      ans += i
  elif len(K) == 2:
    if A<=int(K[0])+int(K[1])<=B:
      ans += i
  elif len(K) == 3:
    if A<=int(K[0])+int(K[1])+int(K[2])<=B:
      ans += i
  elif len(K) == 4:
    if A<=int(K[0])+int(K[1])+int(K[2])+int(K[3])<=B:
      ans += i
  elif len(K) == 5:
    if A<=int(K[0])+int(K[1])+int(K[2])+int(K[3])+int(K[4])<=B:
      ans += i
print(ans)


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

using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    int pcnt,rcnt,ocnt;
    pcnt = rcnt = ocnt = 0;
    while(ocnt < 3){
      char order[100];
      cin>>order;
      switch (order[1]){
      case 'I' : rcnt ++;break;
      case 'U' : ocnt ++;break;
      case 'O' : pcnt += rcnt + 1; rcnt = 0;break;
      }
      if(rcnt==4){
        rcnt --;
        pcnt ++;
      } 
//    cout<<pcnt<<" "<<rcnt<<endl;
    }
    cout<<pcnt<<endl;
  }
}

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

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; }

constexpr int MAX_N = 1e5;
constexpr int INF = 1e9+9;


int h[MAX_N];
int dp[MAX_N+1];

int main() {
  int N; cin >> N;
  for (int i{}; i < N; ++i) cin >> h[i];

  fill_n(dp, MAX_N+1, INF);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for (int i{2}; i < N; ++i) {
    chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
  }

  cout << dp[N-1] << endl;
  return 0;
}


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

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> vec(N);
  
  for (int i = 0; i < N; i++)
    cin >> vec.at(i);
  
  sort(vec.begin(), vec.end());
  
  string sum;
  for (int i = 0; i < N; i++)
    sum += vec.at(i);
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<vector>
#include<set>
#define mxn 100010
#define LL long long
using namespace std;
const int M=1e5;
int n,sl,fh,fa[mxn];
LL ans;
set<int> st[mxn];
vector<int> vt[mxn];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int getfa(int x)
{
	if(fa[x]!=x) fa[x]=getfa(fa[x]);
	return fa[x];
}
int main()
{
	n=rd();int x,y,fx;
	for(int i=1;i<=n;++i) x=rd(),y=rd(),vt[x].push_back(y);
	for(int i=1;i<=M;++i) fa[i]=i;
	for(int sz,i=1;i<=M;++i)
	{
		sz=vt[i].size();if(sz) fx=getfa(vt[i][0]);
		for(int j=1;j<sz;++j) fa[getfa(vt[i][j])]=fx;
	}
	for(int sz,i=1;i<=M;++i)
	{
		sz=vt[i].size();
		for(int j=0;j<sz;++j) st[getfa(vt[i][j])].insert(i);
	}
	for(int i=1;i<=M;++i) ans+=st[getfa(i)].size();
	printf("%lld\n",ans-n);
	return 0;
}

Measured memory_bytes: 11520
def solve():
    def max2(x, y): return x if x >= y else y
    def min2(x, y): return x if x <= y else y

    N = int(input())
    As = list(map(int, input().split()))

    dp = [[0]*(N) for _ in range(N)]

    if N%2 == 1:
        for i, A in enumerate(As):
            dp[i][i] = A
    else:
        for i, A in enumerate(As):
            dp[i][i] = -A

    for W in range(2, N+1):
        if (N-W)%2 == 0:
            for L in range(N-W+1):
                R = L+W-1
                dp[L][R] = max2(As[L]+dp[L+1][R], As[R]+dp[L][R-1])
        else:
            for L in range(N-W+1):
                R = L+W-1
                dp[L][R] = min2(-As[L]+dp[L+1][R], -As[R]+dp[L][R-1])

    print(dp[0][N-1])


solve()


Measured memory_bytes: 112988
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
//10の1/2乗（ルート）pow(10, 0.5)
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string s;
  cin >> s;
  if(49<=s.at(0)-'0'&&s.at(0)-'0'<=74) cout<<"a"<<endl;
  else cout<<"A"<<endl;
}

Measured memory_bytes: 3616
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ch getchar
#define pc putchar
template<typename T>void read(T&x){
	x=0;char c=ch();int f=1;
	for(;c<'0'||c>'9';c=ch())if(c=='-')f=-f;
	for(;c>='0'&&c<='9';c=ch())x=x*10+(c-'0');
	x*=f;
}
template<typename T>void write(T x){
	static char q[64];int cnt=0;
	if(x<0)pc('-'),x=-x;
	q[cnt++]=x%10+'0',x/=10;
	while(x)q[cnt++]=x%10+'0',x/=10;
	while(cnt--)pc(q[cnt]);
}
int main(){
	int T=1;
	while(T--){
		int n=2;long long l,r,ans;
		read(l),read(r);
		if(n==1)ans=(r-l+1);
		else{
			if(l==r)ans=(1);
			else{
				int no=63;
				while(((l>>no)&1)==((r>>no)&1))
					--no;
				l=l&((1ll<<(no+1))-1);
				r=r&((1ll<<(no+1))-1);
				long long tmp=r^(1ll<<no);int cnt=0;
				while(tmp>>=1)++cnt;r|=(1ll<<cnt)-1;
				long long l0=l,r0=r;
				l+=1ll<<no,r=(1ll<<(no+1))-1;
				if(l<=r0)ans=(r-l0+1);
				else ans=(r-l+1+r0-l0+1);
			}
		}
		write(ans);
		pc('\n');
	}
	return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,d;
const ll big = 1000000007;

vl A;
vl B;

ll solve(ll t, ll ans){
    if(t == -1)return ans;
    ll ans2 = (ans | (1ll << t));

    ll f = 0;
    for(int c1 = 0; c1 < sz(B); c1++){
        if((ans2&B[c1]) == ans2)f++;
    }

    if(f >= k)return solve(t-1,ans2);
    return solve(t-1,ans);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;
    cin >> n >> k;

    for(int c1 = 0; c1 < n; c1++){
        cin >> a;
        A.push_back(a);
    }
    for(int c1 = 0; c1 < n; c1++){
        a = 0;
        for(int c2 = c1; c2 < n; c2++){
            a += A[c2];
            B.push_back(a);
        }
    }
    sort(all(B));
    ll ans = solve(50,0);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 5872
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
 
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    mp[a] += b;
  }
  long long ans = 0;
  for (auto e : mp) {
    int u = min(m, e.second);
    m -= u;
    ans += (long long)u * e.first;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4992
use std::io::prelude::*;
use std::str::FromStr;
pub struct Scanner<R: Read>(R);
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self(reader)
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| (b as char).is_whitespace())
            .take_while(|&b| !(b as char).is_whitespace())
            .collect::<Vec<u8>>();
        unsafe { std::str::from_utf8_unchecked(token.as_slice()) }
            .parse()
            .ok()
            .expect("Can't parse it.")
    }
    pub fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut sc = Scanner::new(stdin.lock());
    let mut out = std::io::BufWriter::new(stdout.lock());
    solve(&mut sc, &mut out);
    out.flush().ok().unwrap();
}
fn solve(sc: &mut Scanner<std::io::StdinLock>, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let N: usize = sc.read();
    let mut A = Vec::new();
    for _ in 0..N {
        let tup: (i32, i32, i32) = (sc.read(), sc.read(), sc.read());
        A.push(tup);
    }

    let mut ans = true;
    let mut ct = 0;
    let mut cx = 0;
    let mut cy = 0;
    for &(t, x, y) in A.iter() {
        let dist = (x - cx).abs() + (y - cy).abs();
        ans &= dist <= t - ct && ((t - ct) & 1) == (dist & 1);
        ct = t;
        cx = x;
        cy = y;
    }
    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 3204