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

int main() {
long w=1;
long h=1;
scanf("%ld %ld",&w,&h);
if (w==1 || h==1)
printf("1");
else
printf("%ld",(w/2+w%2)*(h/2+h%2)+(w/2)*(h/2));
return 0;
}

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

using std::cout;
using std::cin;
using std::endl;

/*  テンプレここから */
typedef long long ll;

#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int n;
    cin >> n;
    char* slime = (char*)malloc(n+1);
    cin >> slime;

    char now = 0;
    int ans = 0;
    for(int i = 0; i < n; ++ i){
        if(now != slime[i]){
            ++ ans;
            now = slime[i];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>

int main() {
    int i,a,b;
    char str[4];
    a=0; b=0;
    scanf("%s",str);
    for(i=0;i<3;i++) {
        if(str[i]=='A')
            a++;
        if(str[i]=='B')
            b++;
    }
    if(a==3 || b==3)
        printf("No\n");
    else
        printf("Yes\n");


    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>

using namespace std;

int v,e,f;
unordered_map<int,unordered_map<int,int> > g,costs,inv_costs;
queue<pair<int,int> > nodes;
int cost = 0;

int dfs(int now, int flow, vector<bool> &arrived, vector<int> &dp) {
	if(now==0||flow==0) return flow;
	arrived[now] = true;
	for(pair<int,int> p : inv_costs[now]) {
		int next = p.first;
		int next_cost = p.second;
		if(arrived[next]) continue;
		if(dp[now]-dp[next]==next_cost) {
			int res = dfs(next,min(flow,g[next][now]),arrived,dp);
			if(res>0) {
				g[next][now] -= res;
				g[now][next] += res;
				costs[now][next] = -costs[next][now];
				inv_costs[next][now] = -inv_costs[now][next];
				if(g[next][now]==0) {
					costs[next].erase(now);
					inv_costs[now].erase(next);
				}
				cost += res*next_cost;
				return res;
			}
		}
	}
	return 0;
}

int calc(vector<int> &dp, int flow) {
	vector<int> vf(v,1<<30);
	for(int loop = 0; loop < v; loop++) {
		for(int now = 0; now < v; now++) {
			if(dp[now]==1<<30) continue;
			vf[now] = min(vf[now],dp[now]);
			for(pair<int,int> p : costs[now]) {
				int next = p.first;
				int next_cost = p.second;
				vf[next] = min(vf[next],dp[now]+next_cost);
			}
		}
		dp.swap(vf);
	}

	vector<bool> arrived(v);
	return dfs(v-1,flow,arrived,dp);
}

int main() {
	cin >> v >> e >> f;
	for(int i = 0; i < e; i++) {
		int u,v2,c,d;
		cin >> u >> v2 >> c >> d;
		if(c<=0) continue;
		g[u][v2] = c;
		costs[u][v2] = d;
		inv_costs[v2][u] = d;
	}
	int ans = 0;
	while(ans<f) {
		vector<int> dp(v,1<<30);
		dp[0] = 0;
		int flow = calc(dp,f-ans);
		if(flow<=0) break;
		else ans += flow;
	}
	cout << ((ans>=f)?cost:-1) << endl;
}



Measured memory_bytes: 3264
num = int(input())
line = list(map(int,input().split()))
count = True
count_num = 0
while count:
    for i in range(num):
        if line[i] % 2 != 0:
            count = False
    if count:
        for i in range(num):
            line[i] /= 2
    count_num += 1
print(count_num-1)

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

int main() {
	long k,a,b,x=0;
  	cin >> k >> a >> b;
  	for(long i = a; i<=b; i++){
      if(i%k==0){
        cout << "OK" << endl;
        x++;
        break;
      }
    }
  if(x==0){
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    int n, q, t;
    string name;
    queue<pair<string, int> > Q;
    
    cin >> n >> q;
    
    for(int i = 0; i < n; i++){
        cin >> name >> t;
        Q.push(make_pair(name, t));
    }
    
    pair<string, int> u;
    int a, elps = 0;
    
    while(!Q.empty()){
        u = Q.front();
        Q.pop();
        a = min(q, u.second);
        elps += a;
        u.second -= a;
        
        if(u.second > 0) Q.push(u);
        else cout << u.first << " " << elps << endl;
    }
    
    return 0;
}


Measured memory_bytes: 6340
import numpy as np
kn = list(map(int,input().split()))
K = kn[0]
N = kn[1]
As = list(map(int,input().split()))

subtract_list_r = np.array([])
subtract_list_l = np.array([])
subtract_list_r = list(subtract_list_r)
subtract_list_l = list(subtract_list_l)

subtract_value_r = 0
subtract_value_l = 0
for i in range(1,N-1):
    subtract_value_r = K-(As[i]-As[i-1])
    subtract_value_l = K-(As[i+1]-As[i])
    subtract_list_r.append(subtract_value_r)
    subtract_list_l.append(subtract_value_l)


subtract_list_r.append(As[N-1]-As[0])
subtract_list_l.append(K-(As[1]-As[0]))
subtract_list_r.append(K-(As[N-1]-As[N-2]))
subtract_list_l.append(abs(As[0]-As[N-1]))
r_min = min(subtract_list_r)
l_min = min(subtract_list_l)

print("{}".format(int(min([r_min,l_min]))))


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

int n;
vector<vector<int>> edge;
vector<int> par;
vector<int> h;
int geth(int p, int pr) {
    par[p] = pr;
    int ma = 0;
    for (int i : edge[p]) {
        if (i == pr) continue;
        ma = max(ma, geth(i, p) + 1);
    }
    return h[p] = ma;
}

int main() {
    long long M = 1000007;
    cin >> n;
    edge.resize(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    h.resize(n, -1);
    par.resize(n, -1);
    geth(0, -1);
    vector<vector<int>> lis(n);
    for (int i = 0; i < n; ++i) {
        lis[h[i]].push_back(i);
    }
    vector<long long> hsh(n, 0);
    vector<map<long long, long long>> hsmp(n);
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j : lis[i]) {
            hsh[j] = 1;
            for (int k : edge[j]) {
                if (par[j] == k) continue;
                hsh[j] += hsh[k] * M;
            }
            if (hsmp[i].count(hsh[j]))
                ++hsmp[i][hsh[j]];
            else
                hsmp[i][hsh[j]] = 1;
        }
        for (auto& j : hsmp[i]) {
            ans += j.second * (j.second - 1) / 2;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 32396
#include<bits/stdc++.h>
using namespace std;
long long a,b[55],c[55];
bool yes()
{
	for(int x=1;x<=a;x++) if(c[x]<c[x-1]) return false;
	return true;
}
int main()
{
	cin>>a;
	for(int i=1;i<=a;i++) cin>>b[i];
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<a;j++)
		{
			for(int k=1;k<=a;k++) c[k]=b[k];
			swap(c[i],c[j]);
			if(yes()) {cout<<"YES";return 0;}
		}
	}
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define mod (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}

// https://atcoder.jp/contests/keyence2020/submissions/9584617
using pll = pair<ll, ll>;
void solve() {
    int n;
    cin >> n;
    vector<pll> itv(n);
    rep(i, n) {
        int x, l;
        cin >> x >> l;
        // 端の値は含んでないから被ってok
        itv[i] = pll(1LL * x + l, 1LL * x - l);
    }
    sort(all(itv));
    // rep(i, n) cout << itv[i].F << " " << itv[i].S << endl;
    int ans = 1;
    ll t = itv[0].F;
    rep3(i, 1, n) {
        if (itv[i].S < t) continue; // 被ってok
        
        ans++;
        t = itv[i].F;
    }
    cout << ans << endl;
}



Measured memory_bytes: 1792
#include <iostream>
#include <stack>

using namespace std;

int main()
{
	int a;
	
	stack<int> syaryo;	
	
	while(cin >> a)
	{
		
		if(a != 0)
		{
			syaryo.push(a);
		}
		
		else 
		{
			cout << syaryo.top() << endl;
			syaryo.pop();
		}
	}
	
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    int money1;
    if(min(X,Y) == X) money1 = C*2*X + (Y-X)*B;
    else money1 = C*2*Y + (X-Y)*A;
    int money2 = C*2*max(X,Y);
    int money3 = A*X + B*Y;
    
    cout << min(money1, min(money2,money3)) << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;
 
int main() {
	int K;
    cin >> K;
  	int a=0;
    if(K%2 == 0) a = K/2;
    else a = K/2 + 1;
    
  	cout << K/2 * a;

}

Measured memory_bytes: 256
#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 RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

int n, rev;
deque<int> b;

int main(){
	cin >> n;
	REP(i, 1, n){
		int x;
		cin >> x;
		if (!rev) b.push_back(x);
		else b.push_front(x);
		rev ^= 1;
	}
	if (!rev){
		while (!b.empty()) printf("%d ", b.front()), b.pop_front();
		puts("");
	}
	else{
		while (!b.empty()) printf("%d ", b.back()), b.pop_back();
		puts("");
	}
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

int main() {
  while(true) {
    int a,b,ans = 0;
    char op;
    cin >> a >> op >> b;
    if(op == '?') break;
    if(op == '+') ans = a+b;
    if(op == '-') ans = a-b;
    if(op == '*') ans = a*b;
    if(op == '/') ans = a/b;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>

#define N 102
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
int color[N], d[N], f[N], time, M[N][N];

void visit(int u){
  int i;
  color[u] = GRAY;
  d[u] = ++time;
  for(i=1; i <= n; i++){
    if(color[i] == WHITE && M[u][i] == 1) visit(i);
  }
  color[u] = BLACK;
  f[u] = ++time;
}

void DFS(){
  int i;
  for(i=1; i <= n; i++){
    color[i] = WHITE;
  }
  time = 0;
  for(i=1; i <= n; i++){
    if(color[i] == WHITE) visit(i);
  }
}

int main(){
  int x, i, j, y, num;
  scanf("%d",&n);
  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      M[i][j] = 0;
    }
    scanf("%d",&num);
    scanf("%d",&x);
    if(x != 0){
      for(j = 1; j <= x; j++){
	scanf("%d",&y);
	M[num][y] = 1;
      }
    }
  }
  DFS();
  for(i=1; i <= n; i++){
    printf("%d %d %d\n", i, d[i], f[i]);
  }
  return 0;
}

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

int main(){
    string n;
    cin >> n;
    if (n[0] == n[1]){
        if (n[2] == n[3] && n[0] != n[2]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else if (n[0] == n[2]){
        if (n[1] == n[3] && n[0] != n[1]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else if (n[0] == n[3]){
        if (n[1] == n[2] && n[0] != n[1]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
int y[8][4]={
	{0,1,2,3},
	{1,0,5,4},
	{2,0,4,6},
	{3,0,6,5},
	{4,7,2,1},
	{5,7,1,3},
	{6,7,3,2},
	{7,4,5,6}
};
set<int> st;
int main(){
	string s[8];
	while(cin>>s[0]>>s[1]>>s[2]>>s[3]>>s[4]>>s[5]>>s[6]>>s[7]){
		st.clear();
		vector<string> ash;
		rep(i,8) ash.pb(s[i]);
		sort(all(ash));
		ash.erase(unique(all(ash)),ash.end());
		int x[8];
		rep(i,8) x[i]=lower_bound(all(ash),s[i])-ash.begin();
		sort(x,x+8);
		do{
			int mn=1e9;
			rep(i,8){
				rep(j,3){
					int z[8];
					z[0]=x[y[i][0]];
					z[1]=x[y[i][(j)%3+1]];
					z[2]=x[y[i][(j+1)%3+1]];
					z[3]=x[y[i][(j+2)%3+1]];
					z[4]=x[7-y[i][(j+2)%3+1]];
					z[5]=x[7-y[i][(j+1)%3+1]];
					z[6]=x[7-y[i][(j)%3+1]];
					z[7]=x[7-y[i][0]];
					int sum=0;
					rep(k,8) sum+=(z[k]<<(3*k));
					mn=min(mn,sum);
				}
			}
			st.insert(mn);
		}while(next_permutation(x,x+8));
		cout<<st.size()<<endl;
	}
}

Measured memory_bytes: 1288
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a,b,c,d = map(int, input().split())
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    a -= 1
    x = a - a//c - 1 - a//d - 1 + a//lcm(c, d) + 1
    y = b - b//c - 1 - b//d - 1 + b//lcm(c, d) + 1
    print(y-x)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 1e16;
    for (ll i = -100; i <= 100; ++i) {
        ll tmp = 0;
        rep(j, n) {
            tmp += (a[j] - i) * (a[j] - i);
        }
        ans = min(tmp, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(args...) do { cout << "DEBUG: " << #args << " -> "; err(args); } while (0)
#else
#define dbg(...)
#endif
void err() { cout << endl; }
template<template<typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); }
template<typename T, typename... Args>
void err(T a, Args... args) { cout << a << ' '; err(args...); }
// -----------------------------------------------------------------------------
const int N = 1E5 + 100;

vector<int> V;
int a[N];
struct P { int idx, c; };
bool operator < (const P& a, const P& b) { return a.c > b.c; }
P cnt[N];
pair<P, P> go() {
    memset(cnt, 0, sizeof cnt);
    FOR (i, 0, N) cnt[i].idx = i;
    for (int& x: V) ++cnt[x].c;
    sort(cnt, cnt + N);
    return {cnt[0], cnt[1]};
}

int main() {
    int n; cin >> n;
    FOR (i, 0, n) cin >> a[i];
    FOR (i, 0, n) if (i & 1) V.push_back(a[i]);
    auto t1 = go();

    V.clear();
    FOR (i, 0, n) if (!(i & 1)) V.push_back(a[i]);
    auto t2 = go();

    int ans = t1.first.idx == t2.first.idx ?
            max(t1.first.c + t2.second.c, t1.second.c + t2.first.c) :
            t1.first.c + t2.first.c;
    cout << n - ans << endl;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9+1)
#define MAXX (int)1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (ll)(1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
//printf("myco\n");//for debug
/*--------------------------------------------*/

int main(){
    int n,W;cin>>n>>W;
    V w(n),v(n);
    rep(i,n){
        cin>>w[i]>>v[i];
    }
    const int Max=100001;
    vector<vector<int>> dp(n+1,vector<int>(Max,INF));
    //dp[i][j]:i-1番目までの商品から価値がj以上なるときの重さの最小値
    dp[0][0]=0;
    rep(i,n){//i番の商品を使うのか？
        rep(j,Max){
            int remain=j-v[i];
            if(j<v[i])dp[i+1][j]=dp[i][j];//価値がv[i]未満のはとりま引き継ぎ
            else dp[i+1][j]=min(dp[i][j],dp[i][remain]+w[i]);
            //printf("dp[%d][%d]=%lld\n",i+1,j,dp[i+1][j]);
        }
    }
    int ans;
    rep(i,Max){
        if(W>=dp[n][i])ans=i;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 40192
//I Guds namn
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

vector<int> unq, v;

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n; cin >> n;
	for(int i = 0;i < n;i++)
	{
		int a; cin >> a;
		unq.push_back(a), v.push_back(a);
	}
	sort(unq.begin(), unq.end()), sort(v.begin(), v.end());
	unq.resize(unique(unq.begin(), unq.end()) - unq.begin());
	if(unq.size() > 2)
	{
		cout << "No" << endl;
		return 0;
	}
	if(unq.size() == 1)
	{
		if(unq[0] == n - 1)
			cout << "Yes";
		else if(unq[0] > n / 2)
			cout << "No";
		else
			cout << "Yes";
		cout << endl;
		return 0;
	}
	if(unq[1] - unq[0] > 1)
	{
		cout << "No" << endl;
		return 0;
	}
	int sz1 = upper_bound(v.begin(), v.end(), v[0]) - v.begin(), sz2 = n - sz1;
	int cl2 = max(1, unq[0] - sz1 + 1);
	if(cl2 > (sz2 / 2) or (cl2 + sz1 != unq[1]))
		cout << "No";
	else
		cout << "Yes";
	cout << endl;
	return 0;
}

Measured memory_bytes: 1276
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
import Data.Maybe
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
	n <- readLn
	xs <- map strToInt . words <$> getLine
	let ys = zipWith (-) xs [0..]
	let y = (sort ys)!!(n `div` 2)

	putStrLn . show . sum $ map (\x -> abs (x - y)) ys


Measured memory_bytes: 110588
#include <bits/stdc++.h>
using namespace std;
int main() {
  string A;
   cin >>A;
  if(A=="000"){
    cout<<"0"<< endl;
    }
  if(A=="100")
    {
  cout <<"1"<< endl;
  }
  if(A=="010")
    {
  cout <<"1"<<endl;
  }
  if(A=="001")
    {
  cout <<"1"<<endl;
  }
  if(A=="110")
    {
  cout <<"2"<<endl;
  }
  if(A=="101")
    {
  cout <<"2"<<endl;
  }
  if(A=="011")
    {
  cout <<"2"<<endl;
  }
  if(A=="111")
    {
  cout <<"3"<<endl;
  }
}

Measured memory_bytes: 256
# include <stdio.h>

void outputArray(int *A, int N) {
    printf("%d", A[0]);
    for(int i=1; i<N; i++) {
        printf(" %d", A[i]);
    }
    printf("\n");
}

void insertionSort(int *A, int N) {
    for(int i=1; i<N; i++) {
        int v = A[i];
        int j = i - 1;
        while(j>=0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        outputArray(A, N);
    }
}

int main() {
    int n;
    scanf("%d", &n);
    
    int a[n];
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    
    outputArray(a, n);
    insertionSort(a, n);
    
    return 0;
}



Measured memory_bytes: 2608
#include <stdio.h>

int main(void)
{
	int score;
	int ave = 0;
	int i;
	
	for (i = 0; i < 5; i++){
		scanf("%d", &score);
		
		if (score < 40){
			score = 40;
		}
		
		ave += score;
	}
	
	printf("%d\n", ave / 5);
	
	return (0);
}

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

int main(){
  int n,b;
  cin >> n;
  if(n==1){
    cout << "Yes" << endl;
    return 0;
  }
  vector<int>a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  for(int i=n-2;i>=0;i--){
    if(a.at(i)>a.at(i+1))
      a.at(i)--;
  }
  bool ans=true;
  for(int i=0;i<n-1;i++)
    if(a.at(i)>a.at(i+1))
      ans=false;
  cout << (ans?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 3780
// OPTIMIZATIONS
//#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
//#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
// OPTIMIZATIONS
#include "bits/stdc++.h"
typedef long long ll;
typedef unsigned long long uu;
typedef long long int lll;
typedef unsigned long long int uuu;
using namespace std;

#if defined(DEBUG)
#include "prettyprint.hpp"
#define _GLIBCXX_DEBUG
#define dbga(x, n) cerr << "\n" \
                        << (#x) << " is " << pretty_print_array(x, n) << endl
#define dbg(x) cerr << "\n" \
                    << (#x) << " is " << x << endl
#endif

#if !defined(DEBUG)
#define dbga(x, n)
#define dbg(x)
#endif

#define cel(x, y) 1 + ((x - 1) / y)
const double PI = 3.141592653589793238463;
const int MOD = 1000000007;
const long long int INF = 0x3f3f3f3f3f3f3f3f;

/*
$alil03

URL: url

Solution Begins here
*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // freopen("file.in", "r", stdin);
    // freopen("file.out", "w", stdout);
    lll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d});
}

Measured memory_bytes: 3648
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    threshold = sum(A) / (4 * M)
    if sorted(A, reverse=True)[M-1] >= threshold:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61820
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if (a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if (b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if (b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if (c <= a && a <= b)
        cout << c << " " << a << " " << b << endl;
    else 
        cout << c << " " << b << " " << a << endl;
}


Measured memory_bytes: 3116
A, B, C, X, Y = map(int,input().split())
if A + B <= 2 * C:
    ans = A * X + B * Y
elif 2 * C <= A and 2 * C <= B:
    ans = 2 * C * max(X, Y)
elif 2 * C <= A:
    ans = 2 * C * X + B * max(0, Y - X)
elif 2 * C <= B:
    ans = 2 * C * Y + A * max(0, X - Y)
else:
    if X < Y:
        ans = 2 * C * X + B * (Y - X)
    else:
        ans = 2 * C * Y + A * (X - Y)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    long double a, b, h, m;
    cin >> a >> b >> h >> m;
    if (m == 0)
    {
        cout << setprecision(10) << sqrt(a * a + b * b - 2 * a * b * cos(30 * h* 3.14159265359 / 180)) << endl;
    }
    if (m != 0)
    {
        long double hour = 30 * h + 0.5 * m;
        long double minute = 6 * m;
        cout << setprecision(10) << sqrt(a * a + b * b - 2 * a * b * cos(abs(hour - minute) * 3.14159265359 / 180)) << endl;
    }
}

Measured memory_bytes: 4180
#include <iostream>
using namespace std;
int main()
{
	int a, b, c, d, e, f;
	int res[3];
	int k = 0;
	while (cin >> a >> b >> c >> d >> e >> f) {
		res[k++] = (d * 60 + e) * 60 + f - ((a * 60 + b) * 60 + c);
	}
	for (int i=0; i<3; ++i)
		cout << res[i]/3600 << " "
			 << res[i]/60%60 << " "
			 << res[i]%60 << endl;
	return 0;
}

Measured memory_bytes: 0
from collections import defaultdict
strings = raw_input().split()
# a, b, c = int(strings[0]), int(strings[1]), int(strings[2])
cand = {
    '5': 2,
    '7': 1
}
source = defaultdict(int)
for i in range(len(strings)):
    if strings[i] == '5':
        if source[strings[i]]:
            source[strings[i]] += 1
        else:
            source[strings[i]] = 1
    elif strings[i] == '7':
        if source[strings[i]]:
            source[strings[i]] += 1
        else:
            source[strings[i]] = 1
if source == cand:
    print "YES"
else:
    print "NO"


Measured memory_bytes: 2812
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
map<char,bool> mp;
int main(){
  string s;
  cin>>s;
  int cnt=0;
  for(int i=0;i<s.size();i++){
       if(!mp[s[i]])cnt++;
       mp[s[i]]=1;
  }
 if(cnt==2){
     cout<<"Second"<<endl;
 }
 else{
     if(s.size()%2==1){
         if(s[0]==s[s.size()-1])cout<<"Second"<<endl;
         else cout<<"First"<<endl;
     }
     else{
         if(s[0]==s[s.size()-1])cout<<"First"<<endl;
         else cout<<"Second"<<endl;
     }
 }
}


Measured memory_bytes: 512
def m(L,R):
 global c;c+=len(L)+len(R)
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]
def d(A):s=len(A)//2;return m(d(A[:s]),d(A[s:])) if len(A)>1 else A
c=0
input()
print(*d(list(map(int,input().split()))))
print(c)


Measured memory_bytes: 63652
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
  cin>>n;
  vector<long long> a(n);
  vector<vector<long long>> b(2,vector<long long>(200000,0));
  for(long long i=0;i<n;i++){
    cin>>a[i];
    if(i+a[i]<200000) b[0][i+a[i]]++;
    if(i-a[i]>0) b[1][i-a[i]]++;
  }
  long long ans=0;
  for(long long i=0;i<n;i++){
    ans+=b[0][i]*b[1][i];
  }
  cout<<ans<<endl;
}

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

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int xmax = x;
    int ymin = y;
    for (int i = 0; i < n; i++) {
        int xi;
        cin >> xi;
        xmax = max(xmax, xi);
    }
    for (int i = 0; i < m; i++) {
        int yi;
        cin >> yi;
        ymin = min(ymin, yi);
    }
    if (xmax < ymin) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import collections
N=int(input())
xy=[tuple([int(i) for i in input().split()])  for j in range(N)]
dist = []
if N!=1:
    for n,(x,y) in enumerate(xy):
        for m,(gx,gy) in enumerate(xy):
            if n==m:continue
            dx,dy = gx-x,gy-y
            dist.append((dx,dy))
    zerocost = max(collections.Counter(dist).values())
    print(N-zerocost)
else:
    print(1)

Measured memory_bytes: 3828
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
ll N;
  cin >>N;
  vl a(N);
  rep(i,N) {
cin >>a.at(i);
  }
  
  sort(all(a));
  map<ll ,ll> mp;
  
  rep(i,N) {
    mp[a.at(i)]++;
  }
  ll ans=0;
  for(auto p:mp) {
    ll x=p.first;
    ll y=p.second;
    if(y<x) {
      ans+=y;
    }
    if(y>=x) {
      ans+=(y-x);
    }
  }
  cout<<ans<<endl;
}
  
  
  
 

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

int main(){
    int A[5];
    for(int i=0; i<5; i++){
        cin >> A[i];
        if(A[i]>40) continue;
        else A[i] = 40;
    }
    
    int sum=0;
    for(int j=0; j<5; j++){
        sum += A[j];
    }
    
    cout << sum/5 << endl;
}

Measured memory_bytes: 3080
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, K;
vector<int> G[2000];
void distribute(int num, int step) {
  if (step == -1) {
    rep(i, K-1) {
      rep(j, K-1) G[i*(K-1)+j].pb(num + i);
    }
    return;
  }
  assert(0 <= step && step < K-1);
  rep(i, K-1) {
    int h = i*step;
    rep(j, K-1) {
      G[i*(K-1)+j].pb(num + (h+j)%(K-1));
    }
  }
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  K = 38;
  N = K*(K-1)+1;
  cout<< N << " " << K << "\n";
  int num = 2, s = -1;
  for (int g=N-K; g<N; g++) {
    G[g].pb(1);
    rep(i, K-1) G[g].pb(num+i);
    distribute(num, s);
    num += K-1;
    s++;
  }
  rep(i, N) {
    for (int x : G[i]) cout << x << " ";
    cout << "\n";
  }
  /*
  rep(i, N) sort(all(G[i])), assert(G[i].size() == K);
  rep(i, N) rep(j, i) {
    vector<int> ret;
    set_intersection(all(G[i]), all(G[j]), back_inserter(ret));
    assert(ret.size() == 1);
  }
  */
  return 0;
}


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

int main() {
  int N,D,ans=0;cin>>N>>D;
  int X[N][D];
  rep(i,N)rep(j,D) cin>>X[i][j];
  
  for(int i=0;i<N;i++){
	for(int j=i+1;j<N;j++){
      int d2=0;
      rep(k,D) d2+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
      int d=sqrt(d2);
      if(d*d==d2) ans++;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef multiset<ll> S;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
int main(){
    int n,q=0;cin>>n;
    string s;cin>>s;
    rep(i,n*2){
        ll p=0;
        if(s[i]=='B')p=1;
        if((i%2+p)==1){
            s[i]='L';
            q++;
        }
        else s[i]='R';
    }
    ll ans=1;
    if(q!=n)ans=0;
    ll k=0;
    rep(i,n*2){
        if(s[i]=='L')k++;
        else {
            ans*=k;
          	ans%=mod;
            k--;
        }
    }
  	rep(i,n)ans=ans*(i+1)%mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 640
N = int(input())
T,A = map(int, input().split()) 
H = list(map(int, input().split()))

ans=[]


for i in range(len(H)):
    relay=(abs(A-(T-H[i]*0.006)))
    ans.append([i+1,relay])
    ans=sorted(ans,key=lambda x:x[1])
    
print(ans[0][0])


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define pi 3.14159265358979323846264338
#define pb push_back
#define mp make_pair
#define inf 10000
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;

ll divisor=1000000007;

int main(){
	int n;
	cin>>n;
	int a[n];
	rep(i,n)cin>>a[i];
	int x[3]={};
	ll ans=1;
	rep(i,n){
		int count=0;
		rep(j,3){
			if(a[i]==x[j])count++;
		}
		ans*=count;
		ans%=divisor;
		rep(j,3){
			if(a[i]==x[j]){
				x[j]++;
				break;
			}
		}
	}
	puts(ans);
	
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef unsigned long long ull;
typedef set <int> si;
typedef multiset<int>msi;
typedef pair<int,int> pi;
typedef vector <int> vi;
string read (char x[]){
    scanf ("%s",x);
    return x;
}
const int N = 1e5+3;
int n, a[N], dp[N];
int rec (int i) {
    int &res = dp[i];
    if (dp[i] != -1) return dp[i];
    if (i==0) return 0;
    int t = rec(i-1) + abs(a[i]-a[i-1]);
    if (i>1) t = min(t,rec(i-2)+abs(a[i]-a[i-2]));
    return res= t;
}
void solve () {
    scanf("%d",&n);
    memset(dp, -1, sizeof dp);
    for (int i=0;i<n;i++) scanf("%d",a+i);
    /*dp [1] =   abs (a[1]-a[0]);
    dp [0] = 0;
    for (int i=2;i<n;i++) {
        dp [i] = dp[i-2] + abs(a[i-2] - a[i]);
        dp [i] = min (dp[i] , dp[i-1] + abs(a[i]-a[i-1]));
    }
    printf ("%d",dp[n-1]);*/
    printf ("%d",rec(n-1));
 }
int main () {
    solve();
}


Measured memory_bytes: 4096
#include<stdio.h>
#include<string.h>

int main() {
	
	int N, D, A, i = 1;
	int ans = 0;

	scanf("%d %d", &N, &D);
	A = D * 2 + 1;

	while (ans == 0) {
		
		if (A * i >= N) {
			ans = i;
		}
		i += 1;
	}

	printf("%d", ans);

	return 0;
}



Measured memory_bytes: 128
//メモリ数確認したか?
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long int ll;

int main()
{
    int n;
	string ss;
	cin >> n >> ss;
	const int MAX_N=1000;
	const int mod=10007;
	int dp[MAX_N+1][7];
	for(int j=0;j<7;j++){
		dp[0][j]=0;
		if(j==0)dp[0][j]=1;
	}
	int ans[MAX_N+1];
	ans[0]=1;
	for(int i=1;i<=n;i++){
		ans[i]=0;
		if(ss[i-1]=='J'){
			dp[i][0]=dp[i-1][0]+dp[i-1][3]+dp[i-1][4]+dp[i-1][6];
			dp[i][1]=0;
			dp[i][2]=0;
			dp[i][3]=ans[i-1]-dp[i-1][2];
			dp[i][4]=ans[i-1]-dp[i-1][1];
			dp[i][5]=0;
			dp[i][6]=ans[i-1];
		}
		if(ss[i-1]=='O'){
			dp[i][0]=0;
			dp[i][1]=dp[i-1][1]+dp[i-1][3]+dp[i-1][5]+dp[i-1][6];
			dp[i][2]=0;
			dp[i][3]=ans[i-1]-dp[i-1][2];
			dp[i][4]=0;
			dp[i][5]=ans[i-1]-dp[i-1][0];
			dp[i][6]=ans[i-1];
		}
		if(ss[i-1]=='I'){
			dp[i][0]=0;
			dp[i][1]=0;
			dp[i][2]=dp[i-1][2]+dp[i-1][4]+dp[i-1][5]+dp[i-1][6];
			dp[i][3]=0;
			dp[i][4]=ans[i-1]-dp[i-1][1];
			dp[i][5]=ans[i-1]-dp[i-1][0];
			dp[i][6]=ans[i-1];
		}
		for(int j=0;j<7;j++){
			ans[i]+=dp[i][j];
			dp[i][j]+=mod;
			dp[i][j]%=mod;
		}
		ans[i]%=mod;
	}
	printf("%d\n",ans[n]);
    return 0;
}
//メモリ数確認したか?

Measured memory_bytes: 1228
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-16 07:23:09
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int k; cin >> k;
  vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  cout << v[k - 1] << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	int p = c - a - b;
	if (p < 0)puts("No");
	else if (4 * a * b < p * p)puts("Yes");
	else puts("No");
	ggr
}


Measured memory_bytes: 256
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let h: usize = itr.next().unwrap().parse().unwrap();
    let w: usize = itr.next().unwrap().parse().unwrap();
    let g: Vec<Vec<char>> = (0..h)
        .map(|_| itr.next().unwrap().chars().collect())
        .collect();
    let dx: Vec<isize> = [0, -1, 0, 1].to_vec();
    let dy: Vec<isize> = [1, 0, -1, 0].to_vec();

    let mut used = vec![vec![false; w]; h];
    let mut ans = 0u64;
    for i in 0..h {
        for j in 0..w {
            if !used[i][j] {
                let mut q = std::collections::VecDeque::new();
                q.push_back((i, j));
                used[i][j] = true;

                let mut white = 0;
                let mut black = 0;
                while let Some((y, x)) = q.pop_front() {
                    if g[y][x] == '.' {
                        white += 1;
                    } else {
                        black += 1;
                    }
                    for k in 0..4 {
                        let nx = x as isize + dx[k];
                        let ny = y as isize + dy[k];
                        if 0 <= nx
                            && nx < w as isize
                            && 0 <= ny
                            && ny < h as isize
                            && g[y][x] != g[ny as usize][nx as usize]
                            && !used[ny as usize][nx as usize]
                        {
                            q.push_back((ny as usize, nx as usize));
                            used[ny as usize][nx as usize] = true;
                        }
                    }
                }
                ans += white * black;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for (size_t i = 0; i <= n; i++) if(GetDigit(i)%2 == 1) ans++;
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n;
  cin >> n;

  int s = 0;
  re(i, 9) {
    int a = n / pow(10, i);
    if(a > 0) s += a % 10;
    else break;
  }

  if(n % s == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

int N;
string S[100001];

int main(void){
    cin >> N;
    for(int i=0;i<N;i++)    cin >> S[i];
    
    if(N < 3){
        cout << 0 << endl;
        return 0;
    }
    
    map<char, int> m;
    for(int i=0;i<N;i++){
        char initial = S[i][0];
        m[initial]++;
    }
    
    char cList[] = {'M', 'A', 'R', 'C', 'H'};
    ll ans = 0;
    for(int i=0;i<3;i++){
        for(int j=i+1;j<4;j++){
            for(int k=j+1;k<5;k++){
                ans += (ll)m[cList[i]] * m[cList[j]] * m[cList[k]];
            }
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 6144
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, x: "List[int]", y: "List[int]", h: "List[int]"):
    # mountain = np.zeros(101, 101)
    # for i in range(N):
    #     for j in range(101):
    #         for k in range(101):
    #             mountain[j][k] = max(h[i] - abs(x[i]-j) - abs(y[i]-k))
    # highest = np.argmax(mountain)
    candi = 0
    for i in range(N):
        if h[i] == 0:
            continue
        else:
            candi = i
    for i in range(101):
        for j in range(101):
            flag = 1
            candh = h[candi] + abs(x[candi]-i) + abs(y[candi]-j)
            # print(i, j, candh)
            for xx, yy, hh in zip(x, y, h):
                # print(hh, max(candh-abs(xx-i)-abs(yy-j), 0))
                if hh != max(candh-abs(xx-i)-abs(yy-j), 0):
                    flag = 0
                    break
            if flag == 1:
                # print("!!")
                break
        if flag == 1:
            break
    trueh = h[candi] + abs(x[candi]-i) + abs(y[candi]-j)
    print(i, j, trueh)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    h = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        h[i] = int(next(tokens))
    solve(N, x, y, h)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12456
#include<iostream>
using namespace std;
static const int N=100;
int M[N+1][N+1];
int main(){
    int n,u,k,v;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>u>>k;
        for(int j=1;j<=k;j++){
            cin>>v;
            M[u][v]=1;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)
            cout<<(j>1?" ":"")<<M[i][j];
        cout<<"\n";
    }
    return 0;

}


Measured memory_bytes: 3092