akhauriyash/Code-Regression huggingface dataset:
from copy import deepcopy
from itertools import product
h, w, k = map(int, input().split())
C = []
for i in range(h):
    C.append(list(input()))

"""
for i in range(h):
    print(C[i])
"""

def count(C):
    ans = 0
    for i in range(h):
        for j in range(w):
            #rint(i, j)
            #print(C[i][j])
            if C[i][j] == "#":
                ans += 1
    return ans

#print(count(C))

def rewrite(C, h_pat, w_pat):
    ans = deepcopy(C)
    for i, is_write in enumerate(h_pat):
        if is_write == True:
            for j in range(w):
                ans[i][j] = 0
    for j, is_write in enumerate(w_pat):
        if is_write == True:
            for i in range(h):
                ans[i][j] = 0
    return ans

counter = 0
for h_pat in product([0, 1], repeat=h):
    for w_pat in product([0, 1], repeat=w):
        r = rewrite(C, h_pat, w_pat)
        if count(r) == k:
           counter += 1
print(counter)

Measured memory_bytes: 78688
#include <cstdio>
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  long ans = 0;
  for(int b=1; b<=n; b++) {
    int r = n%b;
    int d = n/b;
    if(b-1>=k) ans += (b-k)*d;
    //printf("%d %d %ld\n", b, r, ans);
    if(r>=k) ans += r-k+1;
    //    printf("%d %d %ld\n", b, r, ans);
    if(k==0) ans--;
  }
  printf("%ld\n", ans);
}


Measured memory_bytes: 128
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;
use std::collections::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        a: [usize;n],
    }
    let mut b: VecDeque<usize> = VecDeque::new();
    for i in 0..n {
        if i%2==0 {
            b.push_back(a[i]);
        } else {
            b.push_front(a[i]);
        }
    }
    if n%2!=0 {
        for i in 0..n {
            print!("{} ", b[n-i-1]);
        }
    } else {
        for i in 0..n {
            print!("{} ", b[i]);
        }
    }
    print!("\n");
}


Measured memory_bytes: 7768
magic = 10**4
N,a,b,c = map(int,input().split())
src = [int(input()) for _ in range(N)]
count = [0]*N

for i in range(4**N):
    a_num = [0,0]
    b_num = [0,0]
    c_num = [0,0]
    tmpi = i
    for j in range(N)[::-1]:
        num = src[j]
        abc = tmpi//(4**j)
        tmpi %= 4**j
        if abc == 0:
            a_num[0] += num
            a_num[1] += 1
        elif abc == 1:
            b_num[0] += num
            b_num[1] += 1
        elif abc == 2:
            c_num[0] += num
            c_num[1] += 1
    if a_num[1] > 0 and b_num[1] > 0 and c_num[1] > 0:
        magic = min(abs(a-a_num[0]) + abs(b-b_num[0]) + abs(c-c_num[0]) + (a_num[1]+b_num[1]+c_num[1]-3)*10,magic)
        
print(magic)

Measured memory_bytes: 3064
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int x, y = 0;
        for(int i = 0; i<str.length(); i++) {
            x = -1;
            y = -1;
            boolean isR = true;
            while(i<str.length()) {
                char c = str.charAt(i);
                if(c=='R' && !isR) {
                    i--;
                    break;
                }
                if(c=='L') {
                    isR = false;
                    y++;
                }
                if(c=='R') {
                    x++;
                }
                i++;
            }
            for(int j = 0; j<x; j++) System.out.print("0 ");
            System.out.print((1+x/2+(int)Math.ceil((double)y/(double)2))+" "+(1+y/2+(int)Math.ceil((double)x/(double)2))+" ");
            for(int j = 0; j<y; j++) System.out.print("0 ");
        }
        System.out.println();

    }
}

Measured memory_bytes: 31124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

string S;

int main() {
	cin >> S;
	int c = 0;
	for (int i = 0; i < S.size(); i++) {
		c += (S[i] != S[S.size() - i - 1]);
	}
	cout << c / 2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<char,int>m,check;
int main(){
    int n;
    string s;
    cin>>n;
    cin>>s;
    for(int i=0;i<s.size();i++){
        m[s[i]]++;
    }

    int target=0;
    int res=0;
    for(int i=0;i<s.size();i++){
        if(check[s[i]]==1){
            m[s[i]]--;
            if(m[s[i]]==0)
                res--;
        }
        else{
            if(check[s[i]]==0){
                check[s[i]]=1;
                m[s[i]]--;
                if(m[s[i]]>=1)
                    res++;
                target=max(target,res);
            }
        }
      
    }
    cout<<target;
}

Measured memory_bytes: 256
N, A, B, C, D = map(int, input().split())
S = input()

if "##" in S[A:max(C,D)]:
  ans = "No"
elif C < D:
  ans = "Yes"
else:
  if "..." in S[B-2:D+1]:
    ans = "Yes"
  else:
    ans = "No"

print(ans)


Measured memory_bytes: 3572
def reconstruction(l, r, pre, _in, result):
    if l >= r:
        return
    c = pre[0]
    del pre[0]
    m = _in.index(c)
    reconstruction(l, m, pre, _in, result)
    reconstruction(m+1, r, pre, _in, result)
    result.append(str(c))


def main():
    n = int(input())
    pre_order = list(map(int, input().split(' ')))
    in_order = list(map(int, input().split(' ')))
    ans = []
    reconstruction(0, n, pre_order, in_order, ans)
    print(' '.join(ans))


if __name__ == '__main__':
    main()



Measured memory_bytes: 5600
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

sys.setrecursionlimit(10**6)

def main():
  n, m = na()
  graph = [[] for _ in range(n + 1)]
  for _ in range(m):
    a, b = na()
    graph[a] += [b]
    graph[b] += [a]
  
  def dfs(e, reach):
    if all(reach):
      return True

    ret = 0
    for e in graph[e]:
      if reach[e - 1]:
        continue
      reach[e - 1] = True
      ret += dfs(e, reach)
      reach[e - 1] = False
    return ret

  reach = [False] * n
  reach[0] = True
  print(dfs(1, reach))

main()

Measured memory_bytes: 3064
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();

    if(s.equals("hi") || s.equals("hihi") || s.equals("hihihi") || s.equals("hihihihi") || s.equals("hihihihihi")){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
    
  }
}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}

bool cmp(pii& a, pii& b) {
  return a.second < b.second;
}
int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  ll n, k;
  cin >> n >> k;
  // ll n, m, k;
  // cin >> n >> m >> k;
  map<int, int> m;
  int x;
  fi(0, n) {
    cin >> x;
    m[x]++;
  }
  vector<pii> v;
  for(pii p: m)
    v.push_back(p);
  if(v.size() <= k) {
    cout << "0\n";
    return 0;
  }

  sort(all(v), cmp);
  // fi(0, v.size())
  //   cout << v[i].first << ": " << v[i].second << endl;
  fi(0, v.size() - k)
    ans += v[i].second;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 11768
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] A_B = Console.ReadLine().Split(' ');
            int a = int.Parse(A_B[0]);
            int b = int.Parse(A_B[1]);

            int S = (a - 1) * (b - 1);

            Console.WriteLine(S);


        }
    }
}


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

#define rep(i, a, b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= int(b); --i)
#define trav(it, v) for(auto &it : (v))
#define all(v) (v).begin(), (v).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define sz(x) (int)(x).size()

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

map<int, int> dp;

int main(){
	ios::sync_with_stdio(0);
	string s;
	cin >> s;
	dp[0] = 0;
	int n = sz(s);
	int b = 0;
	rep(i,0,n) {
		int ind = s[i]-'a';
		b ^= (1<<ind);
		if(!dp.count(b)) {
			dp[b] = n;
		}
		rep(j,0,28) {
			int c = b^(1<<j);
			if(!dp.count(c))
				continue;
			dp[b] = min(dp[b], dp[c]+1);
		}
	}
	int num =  dp[b];
	if(num == 0)
		cout << 1 << endl;
	else
		cout << num << endl;
}

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

int main(){
    int m,f,b;
    cin >> m >> f >> b;
    if(m>=b){
        cout << "0" <<endl;
    }else{
        if((m+f)>=b){
            cout << b-m << endl;
        }else{
            cout << "NA" << endl;
        }
    }
}


Measured memory_bytes: 3092
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
long long sum;
int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) cin >> c[i];
    sort(a.begin(),a.begin()+n);
    sort(c.begin(),c.begin()+n);
    ll cnt = 0;
    for (int i = 0; i < n; i++)
	{
        ll A = lower_bound(a.begin(), a.begin()+n, b[i]) - a.begin();
        ll B = c.end() - upper_bound(c.begin(), c.begin()+n, b[i]);
        cnt += A * B;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define pb push_back
using namespace std;
typedef long long ll;
const int mod = 998244353;
const int N = 200010;
int n, a[N], ans, mu[N], tx[N];
char s[N];
bool p[N];

int calc(int x) {
	int res = 0, j = 1;
	rep(i, 1, x) res = (res * 2 + a[i]) % mod;
	rep(i, 1, n) {
		tx[i] = (j <= x ? a[j] : (a[j - x] ^ 1));
		++j; if(j > x + x) j -= x + x;
	}
	rep(i, 1, n) if(a[i] != tx[i]) return tx[i] < a[i] ? (res + 1) % mod : res;
	return (res + 1) % mod;
}
int main() {
	scanf("%d%s", &n, s + 1); rep(i, 1, n) a[i] = s[i] - '0';
	rep(i, 1, n) if(n % i == 0 && (n / i) % 2) p[i] = 1;
	ans = 1ll * calc(n) * 2 * n % mod;
	per(i, n - 1, 1) if(p[i]) {
		int w = n + n;
		for(int j = i; j <= n; j += i) if(p[j]) w = (w + mu[j]) % mod;
		mu[i] = (i + i - w + mod) % mod;
		ans = (ans + 1ll * calc(i) * mu[i] % mod) % mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int N;

int main() {
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int maxscore = a[N-1];
    int m = 0;
    for (int cur = maxscore; cur > 0; cur--) {
        int count = 0;
        for (int j = 0; j < N; j++) {
            if (cur <= a[j]) {
                count++;
            }
        }
        if (cur <= count) {
            m = max(m, cur);
        }
    }

    cout << m << endl;
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> edge;
typedef pair<edge,int> state;

const ll INF = 1e9;

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

  int n,t;
  cin >> n >> t;

  map<string, vector<int> > id;
  int v = 0;
  string A,B;
  cin >> A >> B;

  vector<string> name;
  vector< vector<int> > c(n);

  for(int i=0;i<n;i++){
    int a; cin >> a;
    for(int j=0;j<a;j++){
      string tmp;
      cin >> tmp;
      id[tmp].push_back(v+j);
      name.push_back(tmp);
    }
    for(int j=0;j<a-1;j++){
      int tmp;
      cin >> tmp;
      c[i].push_back(tmp);
    }
    v += a;
  }

  vector< vector<edge> > g(v);
  v = 0;
  for(int i=0;i<n;i++){
    for(int j=0;j<(int)c[i].size();j++){
      g[v].push_back(edge(c[i][j],v+1));
      g[v+1].push_back(edge(c[i][j],v));
      v++;
    }
    v++;
  }

  priority_queue<state,vector<state>,greater<state> > q;
  vector<edge> d(v,edge(INF,INF));
  for(int u : id[A]){
    q.push(state(edge(0,0),u));
    d[u] = edge(0,0);
  }
  set<string> use;

  while(q.size()){
    state s = q.top(); q.pop();
    int u = s.second;
    edge cost = s.first;
    if(d[u] < cost)continue;

    for(edge nxt : g[u]){
      edge nxtc = edge(nxt.first + cost.first, cost.second);
      int nxtu = nxt.second;
      if(d[nxtu] > nxtc){
	d[nxtu] = nxtc;
	q.push(state(nxtc,nxtu));
      }
    }

    if(use.count(name[u])==0){
      use.insert(name[u]);
      edge nxtc = edge(cost.first + t, cost.second + 1);
      for(int nxtu : id[name[u]]){
	if(d[nxtu] > nxtc){
	  d[nxtu] = nxtc;
	  q.push(state(nxtc,nxtu));
	}
      }
    }
  }


  edge ans = edge(INF,INF);
  for(int u : id[B]){
    ans = min(ans, d[u]);
  }

  if(ans == edge(INF,INF)) cout << -1 << endl;
  else cout << ans.first << " " << ans.second << endl;
}

Measured memory_bytes: 26252
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

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

  int n;
  cin >> n;
  vector<int> b;
  for(int i = 0;i < n;i++)
  {
    int B;
    cin >> B;
    b.push_back(B);
  }
  int ans[4][4] = {0};
  for(int l = 0;l < n;l++)
  {
    for(int i = 0;i < 3;i++)
    {
      for(int j = 0;j < 3;j++)
      {
        if(a[i][j] == b[l])
        {
          ans[i][j] = 1;
          // break;
        }

      }
    }
  }
  for(int i = 0;i < 3;i++)
  {
    for(int j = 0;j < 3;j++)
    {
      if(i == j)
      {
        ans[3][3] += ans[i][j];
      }
      ans[i][3] += ans[i][j];
      ans[3][j] += ans[i][j];
    }
  }
  int c = ans[2][0]+ans[1][1]+ans[0][2];
  if(c == 3)
  {
      cout << "Yes" << endl;
      return 0;
  }
  for(int i = 0;i <= 3;i++)
  {
    if(ans[i][3] == 3 || ans[3][i] == 3)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(W<x+r||H<y+r||0>x-r||0>y-r){
	cout<<"No"<<endl;
	}else{
	cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll n,m,x;
    cin>>n>>m>>x;
    vector<ll> c(n);
    ll a[n][m];
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        for(int j=0;j<m;j++) cin>>a[i][j];
    }
    ll maxi=(1<<n)-1,ans=1e17;
    for(ll i=1;i<=maxi;i++)
    {
        vector<ll> curr(m);
        ll cost=0;
        for(int j=0;j<n;j++){
            ll ch=(1<<j);
            if((i&ch)){
                cost+=c[j];
                for(int k=0;k<m;k++) curr[k]+=a[j][k];
            }
        }
        int no=0;
        for(auto j:curr){
            if(j<x){
                no=1;
                break;
            }
        }
        if(no) continue;
        //cout<<cost<<" "<<i<<" \n";
        ans=min(ans,cost);
    }
    ll inf=1e17;
    if(ans==inf){
        cout<<"-1";
        return 0;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define ll         	long long int
#define pb          push_back
#define ar 			array
#define mp 			make_pair
#define f(i,n)   	for(ll i =0;i<n;i++)
#define inf 		INT_MAX
#define pll 		pair<ll, pair<ll,ll>>
const ll INF = 1e18;
void init(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE 
		freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
}
void solve(){
	
	int H1,H2,M1,M2,K;
	cin>>H1>>M1>>H2>>M2>>K;
	int time = (H2 - H1) * 60;
	if(H2 < H1){
		time += 24*60;
	}
	
	time += M2 - M1;

	cout<<time - K<<endl;

}
int main(){
	init();
	ll t = 1;
	//cin>>t;
	for(ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}


Measured memory_bytes: 3636
import math
length = int(input())
targ = []
cnt = 0
mcnt = 1
for l in range(length):
    targ.append(int(input()))
m = 1
mlist = [1]
while True:
    m = math.ceil(2.25 * m + 1)
    if length <= m:
        break
    mcnt += 1
    mlist.append(m)
print(mcnt)
print(' '.join([str(n) for n in reversed(mlist)]))
mlength = mcnt - 1
while mlength >= 0:
    m = mlist[mlength]
    divided = length // m
    for inh in range(m,length):
        inlength = inh - m
        temp = targ[inh]
        while inlength >= 0 and temp < targ[inlength]:
            targ[inlength + m] = targ[inlength]
            cnt += 1
            inlength -= m
        targ[inlength + m] = temp
    mlength -= 1
print(cnt)
for l in range(length):
    print(targ[l])

Measured memory_bytes: 47592
#E問題
N, M, K = map(int, input().split())
MOD = 998244353

P = MOD
Y = max(N, M)
inv_t = [0]+[1]
for i in range(2, Y):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]
#print(inv_t)
          
if K == N - 1:
  ans = 1
  for i in range(N):
    ans = ans * M % MOD
  print(ans % MOD)
  quit()
  
#if M == 1:
  #if 
  #print("1")
 # quit()
  
# M * ((M - 1) ** (N - L - 1)) * combination(N-1, L)のLを0からKまで足した総和が答え
B = [1] * N
ans1 = 1
for i in range(1, N):
  ans1 = (ans1 * (M - 1)) % MOD
  B[i] = (ans1 * M) % MOD
  
ans = 0
ans2 = 1
#X = 1
for i in range(K + 1):
  if i == 0:
    X = 1
  else:
    X = (X * (N - i) * inv_t[i]) % MOD
  ans2 = X * B[N - 1 - i] % MOD 
  ans += ans2
  ans = ans % MOD
      
print(ans)



Measured memory_bytes: 24912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  rep(i,0,s.size()){
    if(i%2==0){
      cout<<s[i];
    }
  }
  cout<<endl;
}

Measured memory_bytes: 512
# 入力の受け取り
input_line = readlines
input_line_first = input_line[0].split(" ")
input_line_second = input_line[1].split(" ")

# 受け取るパラメータ
children_num = input_line_first[0].to_i
candy_num = input_line_first[1].to_i
children_want_candy_num_array = input_line_second.map(&:to_i)

# 欲しいお菓子の数配列を昇順にソー１ト
children_want_candy_num_array.sort!

# 喜ぶ子供の人数を最大化
happy_children_count = 0
children_want_candy_num_array.each do |want_candy_num|
  candy_num = candy_num - want_candy_num
  if candy_num < 0
    break
  end
  happy_children_count += 1
end

if candy_num > 0
  happy_children_count -= 1
end

# 喜ぶ人数の最大値を出力
p happy_children_count


Measured memory_bytes: 1788
from operator import itemgetter

n = int(input())
ab = sorted([list(map(int, input().split())) for _ in range(n)], key=itemgetter(1))

t = 0
for i, j in ab:
    t += i
    if t <= j:
        ans = "Yes"
    else:
        ans = "No"
        break

print(ans)


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

namespace ConsoleApp1 {
    public class Class {
        static void Main(string[] args) {
            var NK = RL<int>();
            var p = RL<int>();

            Array.Sort(p);

            var ans = p.Take(NK[1]).Sum();

            Console.Write(ans);
        }

        static T[] RL<T>() where T : IComparable {
            if (typeof(T) == typeof(int)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
            }
            if (typeof(T) == typeof(long)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();
            }
            if (typeof(T) == typeof(double)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(double.Parse).ToArray();
            }
            if (typeof(T) == typeof(decimal)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(decimal.Parse).ToArray();
            }
            return (T[])(object)Console.ReadLine().Trim().Split().ToArray();
        }
    }
}

Measured memory_bytes: 28620
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x   = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1)) 

using namespace std;

#define MAX_N 10001
#define MAX_X 100000001
Int N;
vector<bool> isPrime(MAX_X, true);


void eratosthenes(Int x) {
  Int x_sqrt = int(sqrt(x));
  isPrime[0] = isPrime[1] = false;
  loop(i,2,x_sqrt+1) {
    if (isPrime[i]) {
      for(Int j = i*2; j <= x; j += i) {
        isPrime[j] = false;
      }
    }
  }
}


void input() {
  cin >> N;
}

void solve() {
  Int x, count = 0;
  eratosthenes(pow(10, 8));
  while (cin >> x) count += isPrime[x];
  cout << count << endl;
}

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


Measured memory_bytes: 14812
import sys
import queue
input = sys.stdin.readline

while True:
    w,h = map(int,input().split())
    if w == 0 and h == 0:
        break
    h_wall =[]
    v_wall =[]
    for i in range(h):
        h_wall.append(list(map(int,input().split())))
        if i < h-1 :
            v_wall.append(list(map(int,input().split())))
    maze = [[0 for _ in range(w)] for _ in range(h)]

    q = queue.Queue()
    q.put((0,0))
    maze[0][0] = 1
    while not q.empty():
        y, x = q.get()
        for dx, dy in ((1,0),(0,1),(-1,0),(0,-1)):
            ny = y + dy
            nx = x + dx
            if 0 <= ny < h and 0 <= nx < w:
                if dx == 0 and v_wall[min(y,ny)][x] == 1:
                    continue
                if dy == 0 and h_wall[y][min(x,nx)] == 1:
                    continue
                if maze[ny][nx] == 0:
                    maze[ny][nx] = maze[y][x] + 1
                    q.put((ny,nx))
    print (maze[h-1][w-1])


Measured memory_bytes: 6888
import Control.Applicative
import Control.Monad
import Data.Char
import Text.Printf

main :: IO () 
main = do
      [a,b] <- map read . words <$> getLine 
      let  d = (truncate(a::Double)) `div` (truncate(b::Double))  
           r = (truncate(a::Double)) `mod` (truncate(b::Double)) 
           f = a / b 
      putStr $ show d
      putStr " "
      putStr $ show r
      putStr " "
      printf "%.5f" (f :: Double)


Measured memory_bytes: 3980
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;

const int MaxN = 200000;
int n, a[MaxN + 5];
map <int, int> cnt;

int main()
{
	while (~scanf("%d", &n)) {
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
		sort(a + 1, a + n + 1); cnt.clear();
		pair <int, int> ans; ans.first = ans.second = -1;
		for (int i = n; i >= 1; i--) {
			cnt[a[i]]++;
			if (cnt[a[i]] == 2) {
				if (ans.first == -1) ans.first = a[i];
				else ans.second = a[i];
				if (ans.second != -1) break;
				cnt[a[i]] = 0;
			}
		}
		if (ans.second != -1) printf("%lld\n", (LL)ans.first * ans.second);
		else printf("0\n");
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    vector<string> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        for (int j = i + 1; j < n; ++j) cnt += a[i][j] == 'Y';
    }
    if (n & 1) {
        cout << ((n % 4 == 1) == (cnt & 1) ? "Taro\n" : "Hanako\n");
        return 0;
    }
    vector<bool> vis(n);
    int oc = 0, ec = 0;
    for (int i = 0; i < n; ++i) {
        if (!vis[i]) {
            vis[i] = 1;
            int c = 1;
            queue<int> q;
            q.push(i);
            while (!q.empty()) {
                int p = q.front();
                q.pop();
                for (int j = 0; j < n; ++j) {
                    if (a[p][j] == 'Y' && !vis[j]) {
                        vis[j] = 1;
                        q.push(j);
                        ++c;
                    }
                }
            }
            if (c & 1) ++oc;
            else ++ec;
        }
    }
    if ((n % 4 == 0) == (cnt & 1))
        cout << (ec ? "Taro\n" : "Hanako\n");
    else
        cout << (ec == 1 || oc == 2 && ec == 0 ? "Taro\n" : "Hanako\n");

    return 0;
}



Measured memory_bytes: 3968
#include<iostream>
#include<string>
#include<vector>

using namespace std;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

int main() {
	int db[50];
	for (int i = 0; i < 50; i++)
	{
		db[i] = 50;
	}
	int n;
	cin >> n;
	vector<string> s(n);
	cin >> s;
	for (int i = 0; i < n; i++)
	{
		int buf[50] = { 0 };

		for (int j = 0; j < s[i].length(); j++)
		{
			buf[s[i][j] - 'a']++;
		}
		for (int j = 0; j < 50; j++)
		{
			if (buf[j] < db[j])
				db[j] = buf[j];
		}
	}
	for (int i = 0; i < 50; i++)
	{
		if (db[i] > 0)
		{
			for (int j = 0; j < db[i]; j++)
			{
				cout << char(i + 'a');
			}
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what

using namespace std;
 
const int N = (int) 2e5 + 10;
const int M = (int) 2e6 + 10;
const ll big =  (1LL << 51);
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const double EPS = (double) 1e-6;
const double PI =  3.14159265359;

string st;
int ans = INF;

void do_it(char same) {
    string cur = st;
    int cnt = 0;
    for (;;) {
        bool ok = 1;
        for (auto it : cur) 
            if (it != same) 
                ok = 0;
        if (ok) {
            ans = min(ans, cnt);
            break;
        }
        cnt++;
        string go = "";
        for (int j = 0; j < sz(cur) - 1; j++) {
            if (cur[j] == same || cur[j + 1] == same) {
                go += same;
            } else {
                go += cur[j];
            }
        }
        cur = go;
    }
}

int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> st;
    for (int i = 'a'; i <= 'z'; i++) {
        do_it(i);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
    int n,k;cin>>n>>k;
    cout<<k*(int)pow(k-1,n-1)<<endl;
    return 0;
}


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

template<class c> auto try_out(c a) -> decltype(cerr << a, 0);
char try_out(...);

struct debug {
#ifdef LOCAL
template<class c, class d> debug& operator << (pair<c, d> e) {
	return *this << "(" << e.first << ", " << e.second << ")";
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) != 1, debug&>::type operator << (c a) {
	cerr << boolalpha << a;
	return *this;
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) == 1, debug&>::type operator << (c a) {
	*this << "[";
	for (auto it = a.begin(); it != a.end(); ++it)
		*this << ","[1 - (it != a.begin())] << *it;
	return *this << "]";
}
#else
template<class c> debug& operator << (c) {
	return *this;
}
#endif
};

#define aty(x) " [" << #x ": " << x << "] "

using ll = long long;






int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int x = b / a;
    if (x > c) x = c;
    cout << x << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>


class Solver {
public:
    void solve();
};


void Solver::solve() {
    // 入力
    int a, b, c, d, e;

    std::cin >> a >> b >> c >> d >> e;

    int min = 10;
    min = a % 10 <= min && a % 10 != 0 ? a % 10 : min;
    min = b % 10 <= min && b % 10 != 0 ? b % 10 : min;
    min = c % 10 <= min && c % 10 != 0 ? c % 10 : min;
    min = d % 10 <= min && d % 10 != 0 ? d % 10 : min;
    min = e % 10 <= min && e % 10 != 0 ? e % 10 : min;

    
    a = a % 10 == 0 ? a / 10 * 10 :(a / 10 + 1) * 10;
    b = b % 10 == 0 ? b / 10 * 10 : (b / 10 + 1 )* 10;
    c = c % 10 == 0 ? c / 10 * 10  : (c / 10 + 1 ) * 10;
    d = d % 10 == 0 ? d / 10 * 10 :(d / 10 + 1) * 10;
    e = e % 10 == 0 ? e / 10 * 10 :(e / 10 + 1) * 10;
    int ans = a + b + c + d + e - 10 + min;
    std::cout << ans << std::endl;    
}

int main() {
    Solver solver = Solver();
    solver.solve();
    return 0;
}

Measured memory_bytes: 256
N = int(input())

cnt = [0 for _ in range(5)]
ch = "MARCH"

for _ in range(N):
    S = input()
    for i in range(5):
        if S[0] == ch[i]:
            cnt[i] += 1

ans = 0
ans += cnt[0]*cnt[1]*cnt[2]
ans += cnt[0]*cnt[1]*cnt[3]
ans += cnt[0]*cnt[1]*cnt[4]
ans += cnt[0]*cnt[2]*cnt[3]
ans += cnt[0]*cnt[2]*cnt[4]
ans += cnt[0]*cnt[3]*cnt[4]

ans += cnt[1]*cnt[2]*cnt[3]
ans += cnt[1]*cnt[2]*cnt[4]
ans += cnt[1]*cnt[3]*cnt[4]

ans += cnt[2]*cnt[3]*cnt[4]

print(ans)

Measured memory_bytes: 3064
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
int binomialCoeff(int n, int k) 
{ 
	int C[n + 1][k + 1]; 
	int i, j; 


	for (i = 0; i <= n; i++) 
	{ 
		for (j = 0; j <= min(i, k); j++) 
		{ 
			
			if (j == 0 || j == i) 
				C[i][j] = 1; 

			else
				C[i][j] = C[i - 1][j - 1] + 
						C[i - 1][j]; 
		} 
	} 

	return C[n][k]; 
}
 
void solve()
{
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    int s[n];
    ll sum = 0;
    rep(i, n) {
        cin >> s[i];
        sum += s[i];
    }

    bitset<10001> b = {};
    b[0] = true;
    rep(i, n) { b = b | (b << s[i]); }

    int ans;

    rep(i, sum+1) {
        if (b[i] && i % 10 != 0) {
            ans = i;
        }
    }

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

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int compare(const void* a,const void* b){
    return *(int*)b-*(int*)a;
}

int main(void){
    int i;
    int N,K;
    long ans=0;
    scanf("%d %d",&N,&K);
    int H[N];
    for(i=0;i<N;i++){
        scanf("%d",&H[i]);
    }
    
    qsort(H,N,sizeof(int),compare);
    for(i=K;i<N;i++){
        ans+=H[i];
    }
    printf("%ld\n",ans);

    return 0;
}

Measured memory_bytes: 1788
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main()
{
  ll x = 0;
  ll k = 0;
  ll d = 0;
  cin >> x >> k >> d;
  x = abs(x);

  ll ans = 0;

  if (k < x / d) {

    ans = x - d * k;

  } else {

    k -= x / d;
    x -= x / d * d;

    if (k % 2 != 0) {

      x -= d;
    }

    ans = x;
  }
  cout << abs(ans) << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
const ll inf = (ll)1e9 + 7;
int main()
{
    ll i, j, k, n, m, t;
    cin >> n >> m;
    cout << ((n * (n - 1) / 2) + (m * (m - 1) / 2));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int H, W, A, B;
	cin >> H >> W >> A >> B;
	vector<vector<int>> v(H, vector<int>(W, 0));
	for(int i=0; i<H; ++i){
	    if(i<B){
	        for(int j=0; j<A; ++j) v[i][j]=1;
	    }
	    else{
	        for(int j=A; j<W; ++j) v[i][j]=1;
	    }
	}
	for(int i=0; i<H; ++i){
	    for(int j=0; j<W; ++j) cout << v[i][j];
	    cout << endl;
	}
	return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  string A, B; cin >> A >> B;
  int na = A.size(), nb = B.size();
  string ans;
  if (na == nb) {
    if (A == B) { ans = "EQUAL"; }
    else {
      ans = (A < B) ? "LESS" : "GREATER";
    }
  }
  else if (na > nb) { ans = "GREATER"; }
  else { ans = "LESS"; }
  printf("%s\n", ans.c_str());
  return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


class UnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        self.parents = [-1] * n_nodes

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def check(self, x, y):
        return self.find(x) == self.find(y)


def main():
    N = int(input())
    coord = {}
    for i in range(N):
        x, y = map(int, input().split())
        coord[i] = (x, y)

    coord_x_sort = sorted(coord.items(), key=lambda x: x[1][0])
    coord_y_sort = sorted(coord.items(), key=lambda x: x[1][1])
    dist = []
    for i in range(N - 1):
        dx = abs(coord_x_sort[i][1][0] - coord_x_sort[i + 1][1][0])
        c1 = coord_x_sort[i][0]
        c2 = coord_x_sort[i + 1][0]
        dist.append((dx, c1, c2))

        dy = abs(coord_y_sort[i][1][1] - coord_y_sort[i + 1][1][1])
        c1 = coord_y_sort[i][0]
        c2 = coord_y_sort[i + 1][0]
        dist.append((dy, c1, c2))

    dist.sort(key=lambda x: x[0])

    tree = UnionFind(N)

    ans = 0
    for d, i, j in dist:
        if not tree.check(i, j):
            ans += d
            tree.unite(i, j)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 66728
// 参考:http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2069485#1
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

int main(){
	int dp[100][200],row = 0,tmp,index,width[100],maxWidth = 0, maxRowWidth;
	char buf[200];

	while(scanf("%s",buf)!=EOF){
		index = tmp = 0;
		for(int i=0;buf[i] != '\0'; i++){
			if(buf[i] >= '0' && buf[i] <= '9'){
				tmp = tmp*10 + (buf[i] - '0');
				if(buf[i+1] == '\0'){
					dp[row][index++] = tmp;
				}
			}else{
				dp[row][index++] = tmp;
				tmp = 0;
			}
		}
		if(maxWidth < index){
			maxWidth = index;
			maxRowWidth = row;
		}

		width[row] = index;
		row++;
	}

	for(int i=1; i <= maxRowWidth; i++){
		for(int k=0; k < width[i]; k++){
			if(k == 0){
				dp[i][0] += dp[i-1][0];
			}else if(k == width[i]-1){
				dp[i][k] += dp[i-1][width[i-1]-1];
			}else{
				dp[i][k] += max(dp[i-1][k-1],dp[i-1][k]);
			}
		}
	}

	for(int i = maxRowWidth+1;i < row; i++){
		for(int k=0; k < width[i]; k++){
			dp[i][k] += max(dp[i-1][k],dp[i-1][k+1]);
		}
	}
	printf("%d\n",dp[row-1][0]);
}



Measured memory_bytes: 2756
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

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

    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int ans=0;
    for(int i=0;i<n;i++){
        if(i%2==0&&a[i]&1)ans++;
    }
    cout<<ans<<endl;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int res = 0;
    int n, D;
    cin >> n >> D;
    while (n--) {
        long long a, b;
        cin >> a >> b;
        double dis = sqrt(a * a + b * b);
        if (dis <= D)
            res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <stdexcept>

using namespace std;
enum class Pict { heart = 'h', diamond = 'd', club = 'c', spade = 's' };
struct Card {
    Pict p;
    int value;

    Card() : p {Pict::heart}, value {} {}
    Card(char ch, int v) : p {static_cast<Pict>(ch)} , value {v} {};
    Card(string str){
        if(str.size() != 2){
            throw invalid_argument("String length must be 2.");
        }
        p = static_cast<Pict>(str.at(0));
        value = str.at(1)-'0';
    };
};
ostream& operator<<(ostream& out, const Card& card){
    return out << static_cast<char>(card.p) << card.value;
};
const bool operator>(const Card& x, const Card& y){
    return x.value > y.value;
}

const bool operator<(const Card& x, const Card& y){
    return x.value < y.value;
}

const bool operator==(const Card& x, const Card& y){
    return x.p == y.p && x.value == y.value;
}

const bool operator!=(const Card& x, const Card& y){
    return !(x == y);
}

template<class T>
int selection_sort(T xs[], int n){
    int cnt = 0;
    for(int i = 0; i < n; ++i){
        int mini = i;
        for(int j = i; j < n; ++j){
            if(xs[j] < xs[mini]){
                mini = j;
            }
        }
        if(mini != i){
            ++cnt;
            swap(xs[mini], xs[i]);
        }
    }
    return cnt;
}

template <class T>
int bubble_sort(T xs[], int n){
    int cnt = 0;
    for(int i = 0; i < n; ++i){
        for(int j = n-1; j > i; --j){
            if(xs[j] < xs[j-1]){
                ++cnt;
                swap(xs[j], xs[j-1]);
            }
        }
    }
    return cnt;
}

template <class T>
void print_array(T xs[], int n){
    for(int i = 0; i < n-1; ++i){
        cout << xs[i] << ' ';
    }
    cout << xs[n-1] << '\n';
}

template<class T>
bool eq_array(T xs[], T ys[], int n){
    for(int i = 0; i < n; ++i){
        if(xs[i] != ys[i]){
            return false;
        }
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    Card xs[n];
    Card ys[n];
    string temp;
    for(int i = 0; i < n; ++i){
        cin >> temp;
        xs[i] = Card(temp);
        ys[i] = xs[i];
    }
    bubble_sort(xs, n);
    print_array(xs, n);
    cout << "Stable\n";
    selection_sort(ys, n);
    print_array(ys, n);
    if(!eq_array(xs, ys, n)){
        cout << "Not stable\n";
    } else {
        cout << "Stable\n";
    }
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <vector>
#define int long long
using namespace std;
signed main(){
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a*n, b) << endl;
}

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

int main(){
	int n;
	unordered_map<int, int> m;
	cin >> n;
	for(int i=0; i < n; i++){
		int a;
		cin >> a;
		m[a]++;
	}
	if(n%2){
		for (int i = 0; i<n; i++) {
			if(i == 0) {
				if(m[i] != 1) {
					cout << 0;
					return 0;
				}
			} else if(i%2) {
				if(m[i] != 0) {
					cout << 0;
					return 0;
				}
			} else {
				if(m[i] != 2) {
					cout << 0;
					return 0;
				}
			}
		}
	} else {
		for (int i = 0; i<n; i++) {
			if(i%2) {
				if(m[i] != 2) {
					cout << 0;
					return 0;
				}
			} else {
				if(m[i] != 0) {
					cout << 0;
					return 0;
				}
			}
		}
	}
	long ans = 1;
	for (int i = 0; i<n/2; i++) {
		ans = ans * 2 % 1000000007;
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 4388
#include <stdio.h>

int main(void) {
  int w = 0;
  int h = 0;
  int i = 0;
  int j = 0;

  scanf("%d", &h);
  scanf("%d", &w);

  while(!((h == 0) && (w == 0))) {
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
	printf("#");
      }
      printf("\n");
    }

    printf("\n");

    scanf("%d", &h);
    scanf("%d", &w);    
  }
  
  return 0;
}

Measured memory_bytes: 572
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define TRACE(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << endl;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "[" << *it << " = " << a << "]";
	err(++it, args...);
}

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define LOG(x) if(DEBUG) cerr << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

int n,m,k;
int ans;
char c[8][8];

void check(int x)
{
	int count = 0;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			if(c[i][j] == '#')
				count += !(x&(1<<i)) and !(x&(1<<(j+n)));

	ans += (count == k);
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> m >> k;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			cin >> c[i][j];

	for (int i = 0; i < (1<<(n+m)); ++i)
		check(i);

	cout << ans << endl;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

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

using namespace std;

const long long MOD=1e9+7;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int a,b;
    cin>>a>>b;
    if(a+b>=10) cout<<"error";
    else cout<<a+b;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N,K;
	cin>>N>>K;
	vector<int> H(N);
	fore(H,&i) cin>>i;
	sort(H.rbegin(),H.rend());

	ll res=accumulate(H.begin()+min(N,K),H.end(),0ll);
	cout<<res<<'\n';
}


Measured memory_bytes: 1024
n,k = map(int,input().split())
ans = 0
h = list(map(int,input().split()))
h.sort()
if h[n-1] < k:
    print(0)
    exit()
while True:
  if h[ans] >= k:
    break
  else:
    ans += 1
print(len(h[ans:]))

Measured memory_bytes: 18412