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

int main(void) {
	int Q, H, S, D;
	long long N, L[4];
	scanf("%d%d%d%d%lld", &Q, &H, &S, &D, &N);
	L[3] = N / 2LL;
	L[2] = (N % 2LL);
	L[0] = 0LL; L[1] = 0LL;
	if (Q*8 < D) {
		L[0] += L[3]*8LL;
		L[3] = 0LL;
	} else if (H*4 < D) {
		L[1] += L[3]*4LL;
		L[3] = 0LL;
	} else if (S*2 < D) {
		L[2] += L[3]*2LL;
		L[3] = 0LL;
	}
	if (Q*4 < S) {
		L[0] += L[2]*4LL;
		L[2] = 0LL;
	} else if (H*2 < S) {
		L[1] += L[2]*2LL;
		L[2] = 0LL;
	}
	if (Q*2 < H) {
		L[0] += L[1]*2LL;
		L[1] = 0LL;
	}

	printf("%lld\n", Q*L[0]+H*L[1]+S*L[2]+D*L[3]);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int k, t;
	cin >> k >> t;
	int a;
	int mx = 0;
	for (int i = 0; i < t; i++) {
		cin >> a;
		mx = max(mx, a);
	}

	if (mx > (k + 1) / 2) {
		if (k % 2 == 1) {
			cout << (mx - (k + 1) / 2) * 2 << endl;
		} else {
			cout << (mx - k / 2 - 1) * 2 + 1 << endl;
		}
	} else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// 19:03

// constexpr inline ll mod = 1'000'000'007;
// constexpr int max_n = 200'000 + 5;

int h,w;
vector<vector<bool>> mvbl(55, vector<bool>(55)); // y,x = i,j = h,w
vector<vector<bool>> used(55, vector<bool>(55));
queue<tuple<int, int, int>> nxts;
vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};
int res_dist, mvbls, res;

bool is_mvbl(int y, int x) {
    return 0 <= y && y < h && 0 <= x && x < w && mvbl[y][x];
}

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(10); // 浮動小数の表示の精度

    // 19:07
    cin>>h>>w;
    rep(i, h) {
        rep(j, w) {
            char s; cin >> s;
            mvbl[i][j] = (s == '.');
            mvbls += (s == '.');
        }
    }

    // bfs
    res_dist = -1;
    used[0][0] = true;
    nxts.push({0, 0, 0});
    while (!nxts.empty()) {
        auto tup = nxts.front(); nxts.pop();
        int dist, cur_y, cur_x; tie(dist, cur_y, cur_x) = tup;
        if (cur_y == h-1 && cur_x == w-1)
        {
            res_dist = dist;
            break;
        }
        rep(i, 4) {
            int ny = cur_y + dy[i], nx = cur_x + dx[i];
            if (is_mvbl(ny,nx) && !used[ny][nx])
            {
                used[ny][nx] = true;
                nxts.push({dist + 1, ny, nx});
            }
        }
    }
    if (res_dist != -1) {res = mvbls - res_dist - 1;}
    else {res = -1;}
    cout<<res<<'\n';
    // 19:20

    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
long long n,m,a[200001],cnt[200001];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
    cin>>n;
    for (int i=1;i<n;i++) { cin>>a[i]; cnt[a[i]]++;}
    for (int i=1;i<=n;i++) cout<<cnt[i]<<endl;
}

Measured memory_bytes: 6728
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n;
	multiset<int, greater<int>> rem;
	cin >> n;
	rep(i,1<<n) {
		int a;
		cin >> a;
		rem.insert(a);
	}

	multiset<int, greater<int>> now;
	now.insert(*rem.begin());
	rem.erase(*rem.begin());
	rep(i,n) {
		multiset<int, greater<int>> nxt;
		bool ok = true;
		for (int a : now) {
			auto it = rem.upper_bound(a);
			if (it == rem.end()) {
				ok = false;
				break;
			}
			nxt.insert(*it);
			rem.erase(it);
		}
		if (!ok)break;

		now.insert(all(nxt));
	}

	cout << (now.size() == (1 << n) ? "Yes" : "No") << endl;


	return 0;
}

Measured memory_bytes: 18688
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue<int>
#define PQR priority_queue<int,VE,greater<int>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, 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;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;
// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int s; cin >> s;
	int x = ceil(sqrt(s));
	cout << 0 << " " << 0 << " " << x << " " << 1 << " " << x * x - s << " " << x << endl;
	
	return 0;
}

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

int main(){
	int N;
	cin >> N;
  	int a,b,c,d;
  	a = N/1000;
  	b= (N-a*1000)/100;
  	c =(N-a*1000-b*100)/10;
  	d =(N-a*1000-b*100-c*10);      
	if((a == b && b==c)||(b==c && c==d)){
  		cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
	}
	return 0;
}

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

LL mul_arr[400005];
// 插入此處
namespace Number {
    typedef long long int LL;
    // 求取 a, b 的最大公因數
    LL gcd(LL a, LL b) {
        if (a % b == 0) {
            return b;
        }
        return gcd(b, a % b);
    }
    // 求取 a, b 的最大公因數 gcd
    // 以及 x, y 使得 a*x + b*y = gcd
    LL gcd_extend(LL a, LL b, LL *x, LL *y) { 
        if (a == 0) { 
            *x = 0, *y = 1; 
            return b; 
        } 
    
        LL x1, y1; // To store results of recursive call 
        LL gcd = gcd_extend(b%a, a, &x1, &y1); 
    
        *x = y1 - (b/a) * x1; 
        *y = x1; 
    
        return gcd; 
    }
    // 求 a_inv 使得 (a * a_inv) % m = gcd(a, m)
    // 若 a, m 互質，即求 a 在 mod m 群的反元素 a_inv 
    LL mod_inv(LL a, LL m) { 
        LL x, y; 
        LL g = gcd_extend(a, m, &x, &y); 
        // 處理 x 爲負的情形 
        LL a_inv = (x%m + m) % m; 
        return a_inv;
    }
    // 求 x^n % m
    LL mod_pow(LL x, LL n, LL m) {
        if (n == 0) {
            return 1;
        } else if (n & 1) {
            LL half = mod_pow(x, n/2, m);
            return (half * half % m) * x % m;
        } else {
            LL half = mod_pow(x, n/2, m);
            return half * half % m;
        }
    }
    // 連乘
    LL mul(LL from, LL to, LL m) {
        // printf("from = %lld, to = %lld\n", from, to);
        LL ans = (mul_arr[to] * mod_inv(mul_arr[from-1], m)) % m;
        // printf("mul_arr[to] = %lld, mul_arr[from] = %lld, mul = %lld\n", mul_arr[to], mul_arr[from-1], ans);
        return ans;
    }
    // 求 (C n 取 k) % m
    LL mod_comb(LL n, LL k, LL m) {
        // printf("n = %lld, k = %lld\n", n, k);
        if (n < k) {
            return 0;
        }
        LL mi = k < n-k ? k : n-k;
        LL up = mul(n - mi + 1, n, m);
        LL down = mul(1, mi, m);
        // printf("up = %lld, down = %lld\n", up, down);
        return (up * mod_inv(down, m)) % m;
    }
}
  
using namespace Number;

// n 個槽， m 顆球
LL h(LL n, LL m, LL mod) {
    return mod_comb(n + m - 1, m, mod);
}

int main() {
    const LL mod = 1000000007;
    LL n, k;
    scanf("%lld%lld", &n, &k);
    mul_arr[0] = 1;
    for (LL i = 1; i <= n * 2; i++) {
        mul_arr[i] = mul_arr[i-1] * i % mod;
        // printf("%lld\n", mul_arr[i]);
    }
    LL all = h(n, n, mod);
    // printf("all = %lld\n", all);
    LL ret = all;
    for (LL i = n - k - 1; i >= 1; i--) {
        ret -= (h(i, n - i, mod) * mod_comb(n, i, mod) % mod);
        ret = (ret + mod) % mod;
    }
    printf("%lld\n", ret);
}


Measured memory_bytes: 3456
#include <stdio.h>
#include <inttypes.h>

int N, M, K;
int A[20000];

uint64_t memo[20000];

uint64_t search(int idx) {
	uint64_t ret, candidate;
	int min, max;
	int i;
	if (idx >= N) return 0;
	if (memo[idx]) return ~memo[idx];
	ret = K + search(idx + 1);
	min = max = A[idx];
	for (i = 1; i + 1 <= M && idx + i < N; i++) {
		if (A[idx + i] < min) min = A[idx + i];
		if (A[idx + i] > max) max = A[idx + i];
		candidate = K + (uint64_t)(i + 1) * (max - min) + search(idx + i + 1);
		if (candidate < ret) ret = candidate;
	}
	return ~(memo[idx] = ~ret);
}

int main(void) {
	int i;
	if (scanf("%d%d%d", &N, &M, &K) != 3) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
	}
	printf("%"PRIu64"\n", search(0));
	return 0;
}

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

using namespace std;

int N;

string S1, S2;

long long int b[55];

int main(void) {

	cin >> N;

	cin >> S1;
	cin >> S2;

	if (S1[0] == S2[0]) { b[0] = 3; }
	else { b[0] = 6; }

	for (int i = 1; i <= N - 1; i++) {

		if (S1[i] == S2[i]) {
			if (S1[i - 1] == S2[i - 1]) { b[i] = 2 * b[i - 1]; }// case 1
			else { b[i] = b[i - 1];  } //case 2

		}
		else {
			if (S1[i - 1] == S2[i - 1]) { b[i] = 2 * b[i - 1]; } //case 3
			else if (S1[i - 1] == S1[i] && S2[i - 1] == S2[i]) { b[i] = b[i - 1];  } // case 4
			else { b[i] = 3 * b[i - 1]; }
		}
		b[i] %= 1000000007;
	}

	cout << b[N - 1] << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#a=int(input())
#b,c=int(input()),int(input())
# c=[]
#  for i in b:
#     c.append(i)
#e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
K=int(input())
#j = [input() for _ in range(a)]
# h = []
# for i in range(e1):
#     h.append(list(map(int,input().split())))
f.sort(reverse=True)
for i in range(K):
    f[0]*=2
print(sum(f))

Measured memory_bytes: 61680
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
    initScanner()

    s := readString()
    ans := make([]int, len(s) + 1)

    for i, c := range s {
        if c == '<' {
            ans[i+1] = ans[i] + 1
        }
    }

    for i := range s {
        i = len(s) - i - 1
        c := s[i]
        if c == '>' {
            ans[i] = max(ans[i], ans[i+1] + 1)
        }
    }

    var sum int64 = 0
    for _, e := range ans {
        sum += int64(e)
    }

    fmt.Println(sum)
}

func initScanner() {
    buf := make([]byte, 5 * 1e5)
    sc.Buffer(buf, 0)
}

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

func max(a, b int) int {
    if a > b {
        return a
    } else {
        return b
    }
}


Measured memory_bytes: 5632
AB = list(map(int, input().split()))
A = AB[0]
B = AB[1]
#
# n = pow(10,9)
# t = True
#
# for k in range(n):
#     if abs(A-k) == abs(B-k):
#         print(k)
#         t = False
#         break
#
# if t:
#     print("IMPOSSIBLE")


K = 0.1

if not(A-B == 0):
    K = (pow(A,2) - pow(B,2)) / (2*(A-B))

if K % 1 == 0:
    print(int(K))
else:
    print("IMPOSSIBLE")


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

using namespace std;

int n;
int a[101];
int aa=0,bb=9999999;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		aa=max(aa,a[i]);
		bb=min(bb,a[i]);
	}

	cout<<aa-bb<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int n; bool ok[1028]; string s;
int main() {
	while (cin >> n, n) {
		cin >> s;
		bool flag = false;
		for (int i = 1; i < 1024; i++) {
			for (int j = 0; j < 1024; j++) ok[j] = false;
			int bit = 0;
			for (int j = 0; j < s.size(); j++) {
				if (s[j] == 'u') bit = 0;
				else {
					if (i & (1 << (s[j] - 48))) ok[bit] = true;
					bit |= 1 << (s[j] - 48);
				}
			}
			for (int j = 1; j <= i; j++) {
				for (int k = j; k > 0; k = (k - 1) & j) {
					if ((j & k) == k && ok[j - k] && ok[k]) ok[j] = true;
				}
			}
			if (ok[i]) flag = true;
		}
		cout << (flag ? "UNSAFE" : "SAFE") << endl;
	}
	return 0;
}


Measured memory_bytes: 3168
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int A[1000000], n;

int main(){
  int q, k, sum = 0;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> A[i];
  }
  cin >> q;
  for(int i = 0; i < q; i++){
    cin >> k;
    if( *lower_bound(A,A+n,k) == k) sum++;
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 3464
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

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

  if(s=="SUN") cout<<7<<endl;
  if(s=="MON") cout<<6<<endl;
  if(s=="TUE") cout<<5<<endl;
  if(s=="WED") cout<<4<<endl;
  if(s=="THU") cout<<3<<endl;
  if(s=="FRI") cout<<2<<endl;
  if(s=="SAT") cout<<1<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;

    for (int i = 0; i < n; i++)
    {
        if (s[i] == '?')
        {
            s[i] = 'D';
        }
    }
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;

class Prime {
// n以下の素数を列挙する
public:
  const int n;
  vector<bool> is_prime;
  vector<int> primes;
  Prime(int size) : n(size), is_prime(n+1, true) {
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i <= n; ++i) {
      if (!is_prime[i]) continue;
      primes.push_back(i);
      int tmp = 2*i;
      while (tmp <= n) {
        is_prime[tmp] = false;
        tmp += i;
      }
    }
  }

  bool check(int x) { return is_prime[x]; }
};

struct PrimeFactorization {
  // n*n以下の数についての素因数分解
  const int n;
  Prime p;
  PrimeFactorization(int n) : n(n), p(n) {}

  map<ll, int> calc(ll a) {
    map<ll, int> ret;
    ll tmp = a;
    for (int i: p.primes) {
      if (i > tmp) break;
      int count = 0;
      while (tmp % i == 0) {
        ++count;
        tmp /= i;
      }
      if (count > 0) ret[i] = count;
    }
    if (tmp > 1) ret[tmp] = 1;
    return ret;
  }
};

int main() {
  PrimeFactorization pf(100000);
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    map<ll, int> factors = pf.calc(x);
    if (factors.size() > 1) continue;
    auto it = factors.begin();
    if (it->second == 1) ++ans;
  }
  cout << ans << endl;
}




Measured memory_bytes: 3280
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e5,MAX_M=1e5;
int N,M;
ll X[MAX_N];
struct edge{
	int s,t;
	ll cst;
	int inx;
	edge(int s=-1,int t=-1,ll c=0,int i=-1):s(s),t(t),cst(c),inx(i){}
	bool operator < (const edge &e)const{
		return cst<e.cst;
	}
};
struct edge2{
	int to;
	ll cst;
	int inx;
	edge2(int t=-1,ll c=0,int i=-1):to(t),cst(c),inx(i){}
};
edge E[MAX_M];
vector<edge2> G[MAX_N];
int used[MAX_M];
bool koho[MAX_M];
//bool visit[MAX_N];
int par[MAX_N];
ll sm[MAX_N];
int fndpar(int v){
	if(par[v]==v){
		return v;
	}
	return par[v]=fndpar(par[v]);
}
void unite(int s,int t){
	s=fndpar(s);
	t=fndpar(t);
	par[t]=s;
	sm[s]+=sm[t];
}
void dfs(int v,ll c){
//	visit[v]=true;
	for(auto e:G[v]){
		if(e.cst<=c && used[e.inx]==-1){
			used[e.inx]=1;
			dfs(e.to,c);
		}
	}
}
int main(){
	cin>>N>>M;
	REP(i,N)cin>>X[i];
	REP(i,M){
		int a,b;
		ll y;
		cin>>a>>b>>y;
		a--;
		b--;
		E[i]=edge(a,b,y,i);
		G[a].push_back(edge2(b,y,i));
		G[b].push_back(edge2(a,y,i));
	}
	sort(E,E+M);
	REP(i,N){
		par[i]=i;
		sm[i]=X[i];
	}
	REP(i,M){
		auto e=E[i];
		if(fndpar(e.s)!=fndpar(e.t)){
			unite(e.s,e.t);
		}
		if(sm[fndpar(e.s)]>=e.cst){
			koho[e.inx]=true;
		}
	}
	reverse(E,E+M);
	int ans=0;
	memset(used,-1,sizeof(used));
	REP(i,M){
		auto e=E[i];
		if(used[e.inx]!=-1)continue;
		if(koho[e.inx]){
			dfs(e.s,e.cst);
		}else{
			used[e.inx]=0;
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 17024
#include <iostream>
#include <algorithm> // next_permutation
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate
//#include <unordered_map> //???????????\??¢??°
#include <fstream> //ifstream, ofstream


using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
#define TEST //*******************************************************************************************************************************************
//?????????????????¨??§?????\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
//??????????????????????????????????????????????????????????§?CPU???????£??????????????????§???TLE?????????????????????????????????????????§????????¨???
#ifdef TEST
#define dout cout
#else
stringstream dummy; //???????????°??????dout?????????????????????????????????
#define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummy?????????????????????????????????????????¨?????¢?????¢???????????????
//???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§???????????????????????????????????? http://d.hatena.ne.jp/linden/20060427/p1
#endif

//?¨??????????????????????????????????????????????????????´??????OUTPUT2TEXTFILE????????????????????¬???????????????????????????????????¢????????????
//#define OUTPUT2TEXTFILE //*******************************************************************************************************************************************
#ifdef OUTPUT2TEXTFILE
#define dout outputfile //??¨????????????TLE????????§?????????dout?????¨??¨??????????????¢????????????????????????????????????????????§????¨????????????´??????????????£??????????????????????¨?????????????????????????????????????????????§?????????????????????
//TEST??????????????????????????¨???outputfile??????????????????????????????
#define OUTPUTFILENAME "output.txt"
ofstream outputfile(OUTPUTFILENAME);
#define OutputFilePath "/Users/Nag/Documents/Prgm/Test/DerivedData/Test/Build/Products/Debug/output.txt"
#endif



#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << (A) << " "
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl


const int INF = 2e9-1;

int main(){
    int x;
    cin >> x;
   
    cout << x/30 << " " << x%30*2 << endl;
    
    
#ifdef OUTPUT2TEXTFILE
    outputfile.close();
    cout << "\"" << OutputFilePath << "\"" << endl;
#endif
    
    return 0;
}

Measured memory_bytes: 3112
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	/** 平均気温の係数 */
	private static final double D = 0.006d;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), t = scanner.nextInt(), a = scanner.nextInt();
			Queue<Data> queue = new PriorityQueue<>();
			IntStream.range(0, n).forEach(i -> {
				int h = scanner.nextInt();
				queue.add(new Data(i + 1, Math.abs(t - h * D - a)));
			});
			System.out.println(queue.peek().index);
		}
	}

	/**
	 * 番号と平均気温を表すクラス
	 */
	private static class Data implements Comparable<Data> {
		/** 番号 */
		int index;
		/** 平均気温 */
		double t;

		Data(int index, double t) {
			super();
			this.index = index;
			this.t = t;
		}

		@Override
		public int compareTo(Data data) {
			return Double.compare(t, data.t);
		}
	}
}


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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	string s;
	
	cin >> s;
	
	int n = s.size();
	
	int ans = 0;
	
	for(int i = 0; i < n/2; ++i) {
		ans += (s[i] != s[n-i-1]);
	}
	
	cout << ans;
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int count;
  double ans;
 
  for (int i = 1; i <= N; i++) {
 	if(i%2 != 0){
     count = count+1;
    }
  }
 ans = (double)count/N;
cout << ans << endl;
  
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define MAX 100005
#define NIL -1

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r){
	if(l >= 0) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	
}

void solve(){
	pos = 0;
	rec(0, pre.size());
	for (int  i = 0; i < n; i++)
	{
		if(i) cout << " ";
		cout << post[i];
	}
	cout << endl;
}

int main(){
	int a, p;
	cin >> a >> p;
	int cnt = a*3 + p;
	int ans = cnt / 2;
	cout << ans << endl;
	return 0;	 
}

Measured memory_bytes: 256
function longAngle(m) {
  // 1時間で360度, 12時間で12 * 360度
  // s = 6度/m
  return m * 6
}

function shortAngle(h, m) {
  // 1時間で360 /12 =30度
  // 12時間で360
  return 30 * (h + m/60)
}

function cosTheo(a, b, A) {
  return Math.sqrt(Math.abs(a * a + b * b - 2 * Math.cos(A) * a * b))
}

function main(input) {
  const inputs = input.split(' ')
  const a = Number(inputs[0])
  const b = Number(inputs[1])
  const h = Number(inputs[2])
  const m = Number(inputs[3])

  let angle = (Math.abs(longAngle(m) - shortAngle(h, m))) * Math.PI / 180
  let rad = Math.PI * 2 * (h / 12.0 + (m / 60.0) / 12.0 - m / 60.0)

  // if (angle === 0) {
  //   console.log(Math.abs(a - b))
  // } else if (angle === Math.PI) {
  //   console.log(Math.abs(a + b))
  // } else {
    console.log(cosTheo(a, b, angle))
  // }
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));



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

string s;

int main(){
	cin>>s;
	int res=0;
	s="A"+s;
	for(int i=1;i<s.size();i++){
		if(s[i]<=s[i-1]) res++;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 3160
import java.util.Scanner;
import java.util.Arrays;

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

	int[] price = new int[3];
	for(int i = 0; i < 3; i++){
	    price[i] = scan.nextInt();
	}

	Arrays.sort(price);
	System.out.println(price[0]+price[1]);
    }
}


Measured memory_bytes: 22612
x=int(input())
if x == 0:
    print(0)
elif x == 1:
    print(1)
elif x == 10:
    print(1)
elif x == 100:
    print(1)
elif x == 11:
    print(2)
elif x == 101:
    print(2)
elif x == 110:
    print(2)
else:
    print(3)



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

int main(){

    int n, m;
    cin >> n >> m;

    int isEnable[n][m];

    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            isEnable[j][i] = 0;
        }
    }

    for(int i=0; i<m; i++){
        int k;
        cin >> k;
        for(int j=0; j<k; j++){
            int s;
            cin >> s;
            isEnable[s-1][i] = 1;
        }
    }

    int p[m];
    for(int i=0; i<m; i++){
        cin >> p[i];
    }

    int ceil = pow(2, n);
    int sw[n] = {0};
    int isLampOn[m] = {0};
    int count = 0;
    for(int i=0; i<ceil; i++){
        int temp = i;
        for(int j=0; j<n; j++){
            sw[j] = temp%2;
            temp /= 2;
        }
        // cout << "swInput " << sw[0] << " " << sw[1] << endl;

        for(int k=0; k<m; k++){
            
            int swTotal = 0;
            for(int j=0; j<n; j++){
                // cout <<"s: " << j << " L: " << k << " Enable?:" << isEnable[j][k] << endl;
                swTotal = (swTotal + (isEnable[j][k] * sw[j])) % 2;  
            }
            
            // cout << "lamp:" << k << ": " << swTotal << " " << p[k] << endl;
            if(swTotal == p[k]){
                isLampOn[k] = 1;
            }
            else{
                isLampOn[k] = 0;
            }
        }

        int checkAllLamp = 1;
        for(int k=0; k<m; k++){
            checkAllLamp *= isLampOn[k];
        }
        if(checkAllLamp == 1){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

int n; cin >> n;
vector<int> A(n+1);
rep(i,n+1) cin >> A[i];

ll ans = 0;

rep(j,n){
    int b;
    cin >> b;
    if(b <= A[j]) ans += b;
    else {
        int c = b - A[j];
        ans += A[j];
        if(c <= A[j+1]){
            ans += c;
            A[j+1] -= c;
        }else {
            ans += A[j+1];
            A[j+1] = 0;
        }
    }
}

cout << ans << endl;


return 0;
}

Measured memory_bytes: 640
m = input()
for cnt in range(m):
  mem = {}
  s = raw_input()
  for i in range(1, len(s)):
    s1 = s[:i]
    s2 = s[i:]
    mem[s1 + s2] = True
    mem[s1[::-1] + s2] = True
    mem[s1 + s2[::-1]] = True
    mem[s1[::-1] + s2[::-1]] = True
    mem[s2 + s1] = True
    mem[s2 + s1[::-1]] = True
    mem[s2[::-1] + s1] = True
    mem[s2[::-1] + s1[::-1]] = True
  print len(mem)

Measured memory_bytes: 4288
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N, K; cin >> N >> K;
  int result = K * pow(K-1,N-1);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
K,N = map(int,input().split())
A = [int(i) for i in input().split()]

diffA = [0 for _ in range(N)]
for i in range(N-1):
    diffA[i+1] = A[i+1] - A[i]
diffA[0] = A[0] + K - A[N-1]

print(K-max(diffA))

Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int a,b;
  	cin>>a >> b;
  	string ans="";
  	REP(i,max(a,b)){
      string d = to_string(min(a,b));
      ans+=d;
    }
  	cout << ans << endl;
}
    

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#define ll long long int
using namespace std;

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	string s, t;
	cin >> s >> t;

	int n = s.size();
	int m = t.size();
	s += t[m - 1];
	if (n + 1 == m && t == s)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
	return 0;

}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#define EPS 1e-10
using namespace std;

double add(double a,double b){
	if(fabs(a+b)<EPS*(fabs(a)+fabs(b)))return 0.0;
	return a+b;
}

struct P{
	double x,y;
	P(double xx=0,double yy=0){
		x=xx;
		y=yy;
	}
	P operator +(P p){
		return P(add(x,p.x),add(y,p.y));
	}
	P operator -(P p){
		return P(add(x,-p.x),add(y,-p.y));
	}
	P operator *(double d){
		return P(x*d,y*d);
	}
	P operator /(double d){
		return P(x/d,y/d);
	}
	double abs(){
		return sqrt(norm());
	}
	double norm(){
		return x*x+y*y;
	}
};

struct Segment{
	P p1,p2;
	Segment(P pp1=P(),P pp2=P()){
		p1=pp1;
		p2=pp2;
	}
};

typedef P Vector;
double dot(Vector a,Vector b){
	return add(a.x*b.x,a.y*b.y);
}

double cross(Vector a,Vector b){
	return add(a.x*b.y,-a.y*b.x);
}

int ccw(P p0,P p1,P p2){
	Vector a=p1-p0;
	Vector b=p2-p0;
	if(cross(a,b)>EPS)return 1;
	if(cross(a,b)<-EPS)return -1;
	if(dot(a,b)<-EPS)return 2;
	if(a.norm()<b.norm())return -2;
	return 0;
}

bool intersect(P p1,P p2,P p3,P p4){
	return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0 && ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2){
	return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

int main(void){
	int q;
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		Segment s1,s2;
		scanf("%lf %lf",&s1.p1.x,&s1.p1.y);
		scanf("%lf %lf",&s1.p2.x,&s1.p2.y);
		scanf("%lf %lf",&s2.p1.x,&s2.p1.y);
		scanf("%lf %lf",&s2.p2.x,&s2.p2.y);
		printf("%d\n",intersect(s1,s2)?1:0);
	}
	return 0;
}

Measured memory_bytes: 1068
//Author: nimishkhurana
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(i=a;i<b;i++)
#define rrep(i,b,a) for(i=b;i>=a;i--)
#define ld long double
#define ll long long
#define umapi unordered_map<int,int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int> 
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define pb push_back
#define mk make_pair
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);

template <typename T>
ostream& operator << (ostream& stream, const pair<T,T> &p) {
    return stream<<"("<<p.first<<","<<p.second<<") ";
}


int main(){
    fastIO
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif

    int i, j, k, n;
    cin>>n;
    int a[n][3], dp[n][3];

    rep(i, 0, n){
        rep(j, 0, 3){
            cin>>a[i][j];
        }
    }

    rep(i, 0, n){
        rep(j, 0, 3){
            if(!i) {
                dp[i][j] = a[i][j];
                continue;
            }
            dp[i][j] = 0;
            rep(k, 0, 3){
                if(j==k) continue;
                dp[i][j] = max(dp[i-1][k] + a[i][j], dp[i][j]);
            }
        }
    }

    int ans = max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
    cout<<ans;
   
    return 0;
}

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

int main() {
	int a;
    cin>>a;
    if(a>=400 && a<600){
      cout<<"8"<<endl;}
    if(a>=600 && a<800){
      cout<<"7"<<endl;}
      if(a>=800 && a<1000){
      cout<<"6"<<endl;}
      if(a>=1000 && a<1200){
      cout<<"5"<<endl;}
      if(a>=1200 && a<1400){
      cout<<"4"<<endl;}
      if(a>=1400 && a<1600){
      cout<<"3"<<endl;}
      if(a>=1600 && a<1800){
      cout<<"2"<<endl;}
      if(a>=1800 && a<2000){
      cout<<"1"<<endl;}

	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int const nax = 1e6 + 10;
int a[nax], b[nax];
int c[3];
int ncr[2][2];

int lucas (int n, int r) {
    if (r > n) return 0;
    int ret = 1;
    while (n > 0 || r > 0) {
        int x = n % 2;
        int y = r % 2;
        n >>= 1 ;
        r >>= 1;
        ret *= (ncr[x][y]);
        ret %= 2;
    }
    return ret;
}
int n;


int main () {
    ncr[0][0] = ncr[1][0] = ncr[1][1] = 1;
    scanf("%d", &n);

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

    int p = 0;
    for (int i = 0 ; i < n; ++ i) {
        int t = (a[i] % 2) * lucas(n - 1, i);
        p += t;
        p %= 2;
    }

    if (p & 1) return !printf("1");

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

    if (c[1] > 0) {
        return !printf("0");
    }

    for (int i = 0 ; i < n;  ++ i) {
        a[i] >>= 1;
    }
    p = 0;
    for (int i = 0 ; i < n; ++ i) {
        int t = (a[i] % 2) * lucas(n - 1, i);
        p += t;
        p %= 2;
    }

    printf("%d\n", (p & 1) * 2);

}


Measured memory_bytes: 8064
a = list(map(int,input().split()))
ans = 0
if a[0] == a[1] == 1:
  ans += 400000
for count in a:
  if count == 1:
    ans += 300000
  elif count == 2:
    ans += 200000
  elif count == 3:
    ans += 100000
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    string s; int w; cin >> s >> w;
    for (int i = 0; i < s.length(); i += w)cout << s[i];
    cout << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <bitset>
#include <algorithm>
#include <string>
#include <queue>

#define ll long long
#define ull unsigned long long
using namespace std;

const ll mod = 1000000007;

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

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    vector<ll> r(n + 1, 0);
    vector<ll> g(n + 1, 0);
    vector<ll> b(n + 1, 0);
    for (int i = n - 1; i >= 0; i--) {
        r[i] += r[i+1];
        g[i] += g[i+1];
        b[i] += b[i+1];
        if (s[i] == 'R') {
            r[i]++;
        } else if (s[i] == 'G') {
            g[i]++;
        } else {
            b[i]++;
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (s[i] != s[j]) {
                int d = j + (j - i);
                char color;
                if (s[i] == 'R') {
                    if (s[j] == 'G') {
                        ans += b[j+1];
                        color = 'B';
                    } else {
                        ans += g[j+1];
                        color = 'G';
                    }
                } else if (s[i] == 'G') {
                    if (s[j] == 'R') {
                        ans += b[j+1];
                        color = 'B';
                    } else {
                        ans += r[j+1];
                        color = 'R';
                    }
                } else { // B
                    if (s[j] == 'R') {
                        ans += g[j+1];
                        color = 'G';
                    } else {
                        ans += r[j+1];
                        color = 'R';
                    }
                }
                if (d < n && s[d] == color) {
                    ans--;
                }
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3720
//・同型というルールの元、同じグループの中で「最小」であることを標準形という
//・全ての文字列は、標準形であるか、標準形でないかのどちらかである。
//
//ある文字列sが標準形であるかを考える
//・まず先頭の文字は'a'でなければならない。
//・'a'でない最初の文字は'b'でなければならない。
//・'a' 'b'でない最初の文字は'c'でなければならない。
//…
//逆にこれらの条件を満たせば、sは標準形である。
//後は、重複なく列挙することだが、これは
//・'a'の位置 -> 'b'の位置 -> …の順で決めていけばできる。
//・「まだ空いてる場所があれば、最も左には必ず使う」をする。
//・辞書順列挙は、dfs内でやったら沼ったので素直にsetを使う
//計算量をf(N)とおくと f(N) = Σcomb(n - 1, i) * f(N - i) (i=0～n-1)となる。
//f(10)は多分そんなに大きくないので間に合いそう。

#include <iostream>
#include <string>
#include <vector>
#include <set>
#define rep(i, n) for(i = 0; i < n; i++)
#define rrep(i, n) for(i = n - 1; i >= 0; i--)
using namespace std;

set<string> ans;

void dfs(string s, char c) {
	int i, j;
	
	rep(i, s.length()) if (s[i] == '.') break;
	int ptr = i;
	
	if (ptr == s.length()) { ans.insert(s); return; }
	
	s[ptr] = c;
	
	vector<int> pos;
	rrep(i, s.length()) { if (s[i] == '.') pos.push_back(i); }
	
	rep(i, (1 << pos.size())) {
		string t = s;
		rep(j, pos.size()) {
			if ((i >> j) & 1) {
				t[pos[j]] = c;
			}
		}
		dfs(t, c + 1);
	}
}

int main() {
	int n;
	cin >> n;
	
	string s;
	for (int i = 0; i < n; i++) s += '.';
	dfs(s, 'a');
	
	for (set<string>::iterator it = ans.begin(); it != ans.end(); it++) {
		cout << *it << endl;
	}
	return 0;
}

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

#define MAX 199

void initialize();
int isEmpty();
int isFull();
void push( int x );
int pop();

int top;
int S[MAX];

int main( void ){
	
	int x , y;
	int n;
	char s[MAX];
	
	initialize();
	
	while( scanf( "%s" , s) != EOF ){
		
		if( s[0] == '+' ){
			x = pop();
			y = pop();
			push( x + y );
		}else if( s[0] == '-' ){
			x = pop();
			y = pop();
			push( y - x );
		}else if( s[0] == '*' ){
			x = pop();
			y = pop();
			push( x * y );
		}else{
			sscanf( s , "%d" , &n );
			push(n);
		}
	}
	
	printf( "%d\n" , pop() );
	
	return 0;
}

void initialize(){
	
	top = 0;
	
}

int isEmpty(){
	
	if( top == 0 ){
		return 1;
	}else{
		return 0;
	}
	
}

int isFull(){
	
	if( top >= MAX - 1 ){
		return 1;
	}else{
		return 0;
	}
	
}

void push( int x ){
	
	if( isFull() == 1 ){
		fprintf( stderr , "エラー(オーバーフロー)" );
	}else{
		top++;
		S[top] = x;
	}
}

int pop(){
	
	if( isEmpty() == 1 ){
		fprintf( stderr , "エラー(アンダーフロー)" );
		exit(0);
	}else{
		top--;
		return S[top+1];
	}
}




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

int main() {
	int n;
	cin >> n;
	vector<int> p(n), q(n);
	rep(i, n) cin >> p[i];
	rep(i, n) cin >> q[i];
	vector<int> v(n);
	rep(i, n) v[i] = i + 1;
	int a, b, cnt = 0;
	do {
		bool oka = true;
		bool okb = true;
		rep(i, n) {
			if (v[i] != p[i]) oka = false;
			if (v[i] != q[i]) okb = false;
		}
		if (oka) a = cnt;
		if (okb) b = cnt;
		cnt++;
	} while (next_permutation(v.begin(), v.end()));
	cout << abs(a - b) << endl;
	return 0;
}

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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll dp[125252];
bool ng[125252];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, m, a;
	cin>>n>>m;
	REP(i, m){
		cin>>a;
		ng[a]=true;
	}
	dp[0]=1;
	REP(i, n){
		if(ng[i]){
			continue;
		}
		dp[i+1]=(dp[i+1]+dp[i])%MOD;
		dp[i+2]=(dp[i+2]+dp[i])%MOD;
	}
	cout<<dp[n]<<'\n';
	return 0;
}


Measured memory_bytes: 1152
# N = gets.chomp.to_i
# N, M = gets.chomp.to_i
N, M = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars

sum = A.inject(&:+)

cnt = 0
0.upto(N-1).each do |i|
  # p A[i]
  # p M
  # p A[i] * 4 * M
  if ((A[i] * 4 * M) >= sum)
    cnt += 1
  end
end

if (cnt >= M)
  print "Yes\n"
else
  print "No\n"
end


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		for(;;){
			int H =  sc.nextInt();
		    int W =  sc.nextInt();
		    if(H==0 && W==0) break;
		    for(int i=0; i<H; i++){
		    	for(int j=0; j<W; j++){
		    		System.out.print("#");
		    	}
		    	System.out.println();
		    }
	    	System.out.println();
		}
	}
}

Measured memory_bytes: 32840
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 1; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;


int main() {
  ll X, mo=100;
  in(X);
  int ans=0;

  while(mo<X) {
    mo = mo * 1.01;
    ans++;
  }
  out(ans); 



}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int n,k;
	cin>>n>>k;
	set<int>s;
	while(k--){
		int d;
		cin>>d;
		while(d--){
			int x;
			cin>>x;
			s.insert(x);
			
		}
		
		
	}
	cout<<n-s.size();
	
	
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  int ans = 0;
  int cnt = 0;
  vector<int>H(n);
  for(int i=0;i<n;i++) cin >> H[i];
  for(int i=0;i<n-1;i++){
    if(H[i]>=H[i+1]) cnt++;
    else{
      ans=max(ans,cnt);
      cnt = 0;
    }
  }
  cout<< max(ans,cnt) <<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

const long long MAX=510000;
//階乗,逆元,逆元の階乗
long long fac[MAX],inv[MAX],finv[MAX];
//テーブルを作る前処理
void COMinit() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

int main(){
    long long n; cin>>n;
    long long a[n]; rep(i,n) cin>>a[i];
    COMinit();
    long long iinv[n]; iinv[0]=1;
    for(int i=1;i<n;i++){
        iinv[i]=(inv[i+1]+iinv[i-1])%MOD;
    }
    long long ans=0;
    for(int i=0;i<n;i++){
        ans+=a[i]*fac[n]%MOD*(iinv[i]+iinv[n-1-i]-1)%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  int N;
  cin >> N;
  int res = 0;
  bool flag = true;
  vector<int> s(N);
  int tmp = MOD;
  for(int i = 0; i < N; i++){
    cin >> s[i];
    if(s[i] % 10 == 0){
      res += s[i];
      continue;
    }else{
      flag = false;
      res += s[i];
      tmp = min(tmp, s[i]);
    }
  }
  if(flag){
    cout << 0 << endl;
  }else{
    if(res % 10 == 0){
      cout << res - tmp << endl;
    }else{
      cout << res << endl;
    }
  }
}


Measured memory_bytes: 256
n = int(input())
seq = [int(x) for x in input().split()]

if len(seq) == 1:
  if seq[0] == 1:
    print("0")
  else:
    print("1")
else:
  total = 0
  counts = {}
  for x in seq:
    if x not in counts:
      counts[x] = 1
    else:
      counts[x] += 1

  for key,val in counts.items():
    if val < key:
      total += val
    else:
      total += abs(key-val)
  print(total)
  


Measured memory_bytes: 17780