akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define es cout<<" "
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;
template<class T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts> 
auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

int main(void) {
    int N; cin >> N;
    
    // T=0, A=1, G=2, C=3
    // "AGC, ACG, GAC, AXGC, AGXC" はダメ
    auto ng = [](int a, int b, int c) -> bool {
        return (a == 1 and b == 2 and c == 3);
    };
    
    auto dp = make_vec<int>(N + 1, 4, 4, 4);
    dp[0][0][0][0] = 1;
    const int MOD = 1e9 + 7;
    
    repeat (n, N) repeat (a, 4) repeat (b, 4) repeat (c, 4) repeat (d, 4) {
        if (ng(b, c, d) or ng(c, b, d) or ng(b, d, c)) continue;
        if (ng(a, c, d) or ng(a, b, d)) continue;
        dp[n+1][b][c][d] += dp[n][a][b][c];
        dp[n+1][b][c][d] %= MOD;
    }
    
    int ans = 0;
    repeat (a, 4) repeat (b, 4) repeat (c, 4) {
        ans += dp[N][a][b][c];
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5005;
ll c[maxn], p[maxn], b[maxn], n, k, ans = -999999999999, t, cnt, vis[maxn], inf = 0;
int main()
{

    //freopen("input.in", "r", stdin);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> p[i];
    for (int i = 1; i <= n; i++)
        cin >> c[i];
    ll temp;
    for (int i = 1; i <= n; i++)
    {
        memset(b, 0, sizeof(b));
        memset(vis, 0, sizeof(vis));
        cnt = 0, temp = 0, t = i, inf = 0;
        while (vis[p[t]] == 0)
            b[cnt + 1] = c[p[t]], inf += c[p[t]], cnt++, vis[p[t]] = 1, t = p[t];
        if (k <= cnt )
        {
            ll ab = 0;
            for (int j = 1; j <= k; j++)
            {   
                ab+=b[j];
                ans = max(ans, ab);
            }
            continue;
        }
        if( inf<=0)
         {
              ll ab = 0;
            for (int j = 1; j <= cnt; j++)
            {   
                ab+=b[j];
                ans = max(ans, ab);
            }
         }
        {
            int kk = k / cnt;
            kk--;
            temp = (kk * inf);
            ans = max(temp, ans);
            for (int j = 1; j <= cnt; j++)
            {
                temp = temp + b[j];
                ans = max(temp, ans);
            }
            kk++;
            for (int j = 1; j <= k - kk * cnt; j++)
            {
                temp = temp + b[j];
                ans = max(temp, ans);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N, K; cin >> N >> K;
    string S; cin >> S;
    vector<int> A;
    if (S[0] == '0') A.push_back(0);
    int cnt = 0;
    char ch = S[0];
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == ch) cnt++;
        if (S[i] != ch) A.push_back(cnt), cnt = 1, ch = S[i];
    }
    A.push_back(cnt);
    if (S.back() == '0') A.push_back(0);
    vector<int> B(A.size()+1);
    for (int i = 0; i < A.size(); i++) B[i+1] = A[i] + B[i];
    int ans = 0;
    for (int i = 0; i + K*2 < A.size(); i+=2) {
        ans = max(ans, B[i+K*2+1] - B[i]);
    }
    if (ans == 0) ans = N;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1272
use proconio::marker::Usize1;
fn main() {
    proconio::input! {
        n: usize,
        q: usize,
        c: [Usize1;n],
        lr: [(Usize1,usize);q],
    }
    let mut k: Vec<_>=(0..q).collect();
    k.sort_unstable_by_key(|k|lr[*k].1);
    let mut a=vec![0;q];
    let mut rm=0;
    let mut t=vec![0;n+1];
    let mut p=vec![n;n];
    for k in k {
        let (l,r)=lr[k];
        while rm<r {
            let c=c[rm];
            if p[c]<n {
                let mut i=p[c]+1;
                while i<=n {
                    t[i]-=1;
                    i+=i&i.wrapping_neg();
                }
            }
            p[c]=rm;
            let mut i=rm+1;
            while i<=n {
                t[i]+=1;
                i+=i&i.wrapping_neg();
            }
            rm+=1;
        }
        let mut s=0;
        let mut i=r;
        while i>0 {
            s+=t[i];
            i-=i&i.wrapping_neg();
        }
        let mut i=l;
        while i>0 {
            s-=t[i];
            i-=i&i.wrapping_neg();
        }
        a[k]=s;
    }
    for a in a {
        println!("{}",a);
    }
}

Measured memory_bytes: 35220
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  vector<pair<double, string>> v;
  v.pb(mp(48.0, "light fly"));
  v.pb(mp(51.0, "fly"));
  v.pb(mp(54.0, "bantam"));
  v.pb(mp(57.0, "feather"));
  v.pb(mp(60.0, "light"));
  v.pb(mp(64.0, "light welter"));
  v.pb(mp(69.0, "welter"));
  v.pb(mp(75.0, "light middle"));
  v.pb(mp(81.0, "middle"));
  v.pb(mp(91.0, "light heavy"));
  v.pb(mp(INF, "heavy"));
  double w;
  while (cin >> w) {
    for (auto p : v) {
      if (w <= p.first) {
        cout << p.second << endl;
        break;
      }
    }
  }
}

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


int main(){

    
    char b, k;


    cin >> b;


    if( b == 'A' ) k = 'T';

    if( b == 'T' ) k = 'A';

    if( b == 'C' ) k = 'G';

    if( b == 'G' ) k = 'C';


    cout << k << endl;


    return 0;

    }


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int H, W, K;
	cin >> H >> W >> K;
	char s[310][310];
	REP(i, H) {
		REP(j, W) {
			cin >> s[i][j];
		}
	}
	int cnt = 1;
	int ans[310][310];
	bool dis[310];
	REP(i, 310)dis[i] = false;
	REP(i, H) {
		REP(j, W) {
			if (s[i][j] == '#') {
				dis[i] = true;
			}
		}
	}
	REP(i, H) {
		bool change = false;
		if (!dis[i])continue;
		REP(j, W) {
			if (s[i][j] == '#') {
				dis[i] = true;
				if (change) {
					cnt++;
				}
				change = true;
			}
			ans[i][j] = cnt;
		}
		if (change)cnt++;
	}
	REP(i, H-1) {
		if (dis[i])continue;
		int x = i;
		bool can = false;
		while (x < H-1) {
			x++;
			if (dis[x]) {
				can = true;
				break;
			}
		}
		if (can) {
			REP(j, W) {
				ans[i][j] = ans[x][j];
			}
			dis[x] = true;
		}
	}
	for (int i = H - 1; i > 0; --i) {
		if (dis[i])continue;
		int x = i;
		bool can = false;
		while (x > 0) {
			x--;
			if (dis[x]) {
				can = true;
				break;
			}
		}
		if (can) {
			REP(j, W) {
				ans[i][j] = ans[x][j];
			}
		}
	}
	REP(i, H) {
		REP(j, W) {
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 1280
N=int(input())
X=list(map(int,input().split()))
def D(x,a):
	ans=0
	for i in range(len(a)):
		ans+=(x-a[i])**2
	return ans
for i in range(0,101):
	if D(i,X)<D(i+1,X):
		print(D(i,X))
		break


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

#define ll long long int
#define vi vector<int>

int main() {

    int K;
    string S;

    cin >> K >> S;

    if (S.length() <= K) {
        cout << S << endl;
    }
    else {
        for (int i = 0; i < K; ++i) {
            cout << S[i];
        }

        cout << "..." << endl;
    }

    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
 
  int n,k;
  cin >> n >> k;
  n++;

  int ans = 1;
  while(n > pow(k, ans)) {
    ans++;
  }

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define all(x) (x).begin(), (x).end()

using namespace __gnu_pbds;
using namespace std;

using ull = unsigned long long;
using ll = long long;
using ld = long double;
template <typename T> using ordered_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod = 1e9 + 7;
const int inf = INT_MAX;
const int N = 5e5 + 5;

template <typename T> class FenwickTree {
public:
    #define F function<T(const T&, const T&)>

    int n;
    vector<T> bit;
    F f;

    FenwickTree(): n(), bit(), f() {}
    explicit FenwickTree(int n, F func = plus<T>()): n(n), bit(n + 1, 0), f(func) {}

    void add(int i, int val) {
        while (i <= n) {
            bit[i] = f(bit[i], val);
            i += i & -i;
        }
    }
    T query(int i) {
        T ans = T();
        while (i > 0) {
            ans = f(ans, bit[i]);
            i -= i & -i;
        }
        return ans;
    }
};

int n, q, a[N], pos[N], ans[N];
vector<pair<int, int>> q1[N];

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

    cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;

        q1[r].emplace_back(l, i);
    }

    FenwickTree<int> ft(n);

    for (int i = 1; i <= n; i++) {
        if (!pos[a[i]]) {
            ft.add(i, 1);
        }
        else {
            ft.add(pos[a[i]], -1);
            ft.add(i, 1);
        }

        pos[a[i]] = i;
        for (auto &[l, id] : q1[i]) {
            ans[id] = ft.query(i) - ft.query(l - 1);
        }
    }

    for (int i = 0; i < q; i++) cout << ans[i] << "\n";
    return 0;
}

Measured memory_bytes: 33152
# C - Energy Drink cntlector
import heapq

N, M = map(int, input().split())
AB = []
for i in range(N):
    heapq.heappush(AB, list(map(int, input().split())))

cnt = 0
ans = 0
for i in range(N):
    price, bottles = heapq.heappop(AB)
    cnt = min(M, bottles)
    M -= cnt
    ans += price * cnt
    if M==0:
        break

print(ans)

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

map<int32,int32> primeFactors;

int32 cnt(int32 x){
    int32 retval = 0;
    for(auto p : primeFactors){
        if(p.second >= x)retval++;
    }
    return retval;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    FOR(i,2,n+1){
        int32 x = i;
        int32 p = 2;
        while(x >= 2){
            if(x % p == 0){
                x /= p;
                primeFactors[p]++;
            }else{
                p++;
            }
        }
    }
    cout << cnt(74) + cnt(24) * (cnt(2) - 1) + (cnt(4) * (cnt(4) - 1) / 2) * (cnt(2) - 2) + cnt(14) * (cnt(4) - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    int ans = 0;
    vector<int> diff;

    cin >> n;
    diff.resize(n);

    for (int i = 0; i < n; i++) {
        cin >> diff[i];
    }
    for (int j = 0; j < n; j++) {
        int tmp;
        cin >> tmp;
        diff[j] -= tmp;
    }

    sort(diff.begin(), diff.end(), greater<int>());

    int k = 0;
    while (true) {
        if (diff[k] <= 0 || k == n) {
            break;
        }
        ans += diff[k];
        k++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//library zone!!!!!
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ld mod_pow(ld x, ll n, ll p) {
	ld res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1)*(n - w + 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    rep(i,n)cin>>h[i];
    
    int dp[100001];
    dp[0]=0;
    rep2(1,i,n){
        if(i==1){
            dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        }else{
            dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        }
    }
    cout<<dp[n-1]<<endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
ll s, c; cin >> s >> c;
ll ans=0;
ll tmp = min(s, c/2);
ans += tmp;
s -= tmp; c -= 2*tmp;
if(c >= 2){
ans += c/4;
}
cout << ans;
return 0;
}

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

/*
  // Overview

  // Time complexity

  // Initialization
*/
struct Dijkstra {
    struct edge{
        int to;
        long long cost;
        edge(int to, long long cost) : to(to), cost(cost) { }
    };
    typedef pair< long long, int > P;
    const long long INF = 1LL<<60;
    int v;
    int s;
    vector< vector < edge > > g;
    vector< long long > dist;
    priority_queue< P, vector< P >, greater< P > > que;
    Dijkstra(int v, int s) : v(v), s(s), g(v), dist(v, INF) {
        dist[s] = 0;
        que.push(P(0, s));
    }
    void add_edge(int start, int to, long long cost) {
        g[start].emplace_back(to, cost);
    }
    void build() {
        while (!que.empty()) {
            P p = que.top(); que.pop();
            int current = p.second;
            if (dist[current] < p.first) continue;
            for (edge& e : g[current]) {
                if (dist[e.to] > dist[current] + e.cost) {
                    dist[e.to] = dist[current] + e.cost;
                    que.push(P(dist[e.to], e.to));
                }
            }
        }
    }
    long long shortest_path_value(int t) {
        return dist[t];
    }
};

/*
    verified https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_1_A
*/
int main() {
    int V, E, r; cin >> V >> E >> r;
    Dijkstra dijkstra(V, r);
    for (int i = 0; i < E; ++i) {
        int s, t, d; cin >> s >> t >> d;
        dijkstra.add_edge(s, t, d);
    }
    dijkstra.build();
    for (int i = 0; i < V; ++i) {
        long long val = dijkstra.shortest_path_value(i);
        if (val == dijkstra.INF) cout << "INF" << endl;
        else cout << val << endl;
    }
}



Measured memory_bytes: 19316
#include <bits/stdc++.h>
#define hell 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long 
#define pi 3.1415926536
using namespace std;
const ll N=1e6;
void solve()
{ll n,k,h,x,y,z,w,a,b,c,d,mini,maxi=INT_MAX,prev;
  cin>>x;
 double ans=1.0;
 y=1;
 z=100;
 while(1)
 { ans*=1.01;
 	z=(z*1.01);
 	if(z>=x)
 	{
 		cout<<y;
 		break;
 		return;
	}
	ans=floor(ans);
	 y++;
 }
}
  
int main()
{
  fast
  //for(ll i=0;i<=9;i++)
  //cal(1,3234566667,i);
  //sort(v.begin(),v.end());
  //pre();
ll t=1;
//cin>>t;
//SieveOfEratosthenes();
//cout<<"ok";
while(t--)
{ //cout<<"ok";

solve();
 //cout<<ma<<endl;
}
return 0;}
/*
ll pr(ll a,ll b,ll c)
{
	if(b==0)
	return 1LL;
	ll ans=1;
	while(b>0)
	{
		if(b%2)
		ans=((ans%c)*(a%c))%c;
		a=((a%c)*(a%c))%c;
		b/=2;
		a%=c;
		ans%=c;
	}
	return ans;
}
vector<ll> fact(N+1);
void pre()
{
	fact[0]=1;
	for(ll i=1;i<=N;i++)
	fact[i]=fact[i-1]*i,fact[i]%=hell;
	
}
*/

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

ll dp[55][55][2600];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, a;
    cin >> n >> a;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    dp[0][0][0] = 1;
    rep1(i, n) {
        for (int j=0; j<=i; j++) {
            for (int k=0; k<2600; k++) {
                dp[i][j][k] += dp[i-1][j][k];
                if (j>0 && k-x[i-1]>=0) {
                    dp[i][j][k] += dp[i-1][j-1][k-x[i-1]];
                }
            }
        }
    }
    ll ans = 0;
    for (int i=1; i<=n; i++) {
        int sum = a*i;
        ans += dp[n][i][sum];
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 30724
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <limits>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <iterator>
#include <functional>

using namespace std;

typedef unsigned                    ui;
typedef int                         si;
typedef long                        sl;
typedef long long                   ll;
typedef unsigned long long          ull;

#ifdef LOCALHOST
std::ifstream in("input.txt", std::ifstream::in);
#endif // LOCALHOST

#ifdef LOCALHOST
#define is in
#else
#define is cin
#endif // LOCALHOST

int main(int argc, char *argv[])
{
    std::ios_base::sync_with_stdio(false);

    ll n, W;
    cin >> n >> W;

    vector<ll> w(n + 1, 0);
    vector<ll> v(n + 1, 0);

    for (int i = 1; i <= n; ++i) {
        cin >> w[i] >> v[i];
    }

    ll answer = 0;
    vector<vector<ll>> dp(W + 1, vector<ll>(n + 1, 0));
    for (int item = 1; item <= n; ++item) {
        // cerr << "item = " << item << endl;
        for (int weight = W; weight >= 0; --weight) {
            dp[weight][item] = dp[weight][item - 1];
            if (w[item] + weight <= W) {
                dp[weight + w[item]][item] = max(dp[weight + w[item]][item - 1], dp[weight][item - 1] + v[item]);
            }
            // cerr << item << " " << weight  << ", ";
        }
        // cerr << endl;
    }

    for (int item = 1; item <= n; ++item) {
        for (int weight = 1; weight <= W; ++weight) {
            answer = max(answer, dp[weight][item]);
            // cerr << dp[weight][item] << " ";
        }
        // cerr << endl;
    }

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 84096
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;

int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};


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



int a,b;
cin>>a>>b;

for(int i=1;i<=1000;i++)
{
  int x=i*0.08,y=i*0.1;
  if(x==a&&y==b)
  {
    cout<<i<<"\n"; return 0;
  }
}
cout<<-1<<"\n";


  
}



Measured memory_bytes: 256
#include<bits/stdc++.h>  
using namespace std;
double dp[3000][3000];
int main()
{
    int n;
    cin>>n;
    vector<double> a(n+1);
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=i;j++)
        {
            if(i==0&&j==0)dp[i][j]=1;
            else if(i==0)dp[i][j]=0;
            else if(j==0)dp[i][j]=dp[i-1][j]*(1-a[i]);
            else
            {
                dp[i][j]=(a[i]*dp[i-1][j-1])+((1-a[i])*dp[i-1][j]);
            }
        }
    }
    double sum=0;
    for(int i=n/2+1;i<=n;i++)
        sum+=dp[n][i];
    cout<< fixed << setprecision(10)<<sum;
}


Measured memory_bytes: 68864
n = int(input())
ss = [[int(i) for i in input().split()] for i in range(n)]

ss = sorted(ss, key=lambda x: x[2], reverse=True)


cx, cy, ch = ss[0]
if len(ss) == 1:
    print(cx, cy, ch)
else:
    for a in range(101):
        for b in range(101):
            H = ch + abs(cx-a) + abs(cy - b)
            for x, y, h in ss[1:]:
                if h != max(H - abs(x-a) - abs(y - b), 0):
                    break
            else:
                print(a, b, H)
                flg = True


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll b[100005];
ll rui[100005];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, x, m;
	cin >> n >> x >> m;
	ll idx = 0;
	ll cur = x, sum = 0;
	memset(b, 0, sizeof(b));
	while(b[cur] == 0 && idx < n){
		++idx;
		sum += cur;
		rui[idx] = sum;
		b[cur] = idx;
		cur = (cur * cur) % m;
		if(cur == 0){
			cout << sum << endl;
			return 0;
		}
	}
	if(idx == n){
		cout << sum << endl;
		return 0;
	}
	ll idx2 = b[cur] - 1;
	n -= idx2;
	ll ans = (sum - rui[idx2]) * (n / (idx - idx2));
	//cout << ans << endl;
	n %= (idx - idx2);
	ans += rui[idx2 + n];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4736
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int intA = scan.nextInt();
		int intB = scan.nextInt();
		int d = intA / intB;
		int r = intA % intB;
		double f = (intA/(double)intB);
		BigDecimal x = new BigDecimal(f);
		x = x.setScale(6, BigDecimal.ROUND_HALF_UP);

		System.out.println(d + " " + r + " " + x);
	}
}

Measured memory_bytes: 17412
N = input()

data = map(int,raw_input().split())
data.sort()

count = []
num = []
pnum = -1
counter = -1

for i in data:
    if pnum != i:
        pnum = i
        num.append(i)
        count.append(1)
        counter += 1
    else:
        count[counter] += 1

ans = 0

for i in range(len(num)):
    if count[i] < num[i]:
        ans += count[i]
    else:
        ans += count[i]-num[i]

print ans

Measured memory_bytes: 11348
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,m,n) for(int i=m;i<n;i++)
#define endre getchar(); getchar();return 0;
int a[200010];
int sa[200010];
signed main() {
	int n;
	cin >> n;
	int s=0, d=0;
	rep(i, n) {
		cin >> a[i];
		d += a[i];
	}
	rep(i, n-1) {
		s += a[i];
		d -= a[i];
		sa[i] = abs(s - d);
	}
	sort(sa, sa + n-1);
	cout << sa[0] << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int V = 1e5 + 100;
int n, we, w[N], v[N];
long long dp[V];

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

	cin >> n >> we;

	for (int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}

	for (int j = 0; j < V; j++) {
		dp[j] = LLONG_MAX;
	}

	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = V - 1; j >= 0; j--) {
			if (dp[j] == LLONG_MAX) continue;
			dp[j + v[i]] = min(dp[j + v[i]], dp[j] + (long long) w[i]);
		}
	}

	int ans = 0 ;
	for (int i = V - 1; i > 0; i--) {
		if (dp[i] > we) continue;
		ans = i;
		break;
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 4408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int k,a,b;cin>>k>>a>>b;
    int cur=b/k-(a-1)/k;
    if(cur==0)cout<<"NG";
    else cout<<"OK";
    
}


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

using namespace std;

int main() {
	bool x=1,y=1;
	bool a=0,b=0,c=0,d=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='N'){
			a=1;
		}
		else if(s[i]=='S'){
			b=1;
		}
		else if(s[i]=='W'){
			c=1;
		}
		else if(s[i]=='E'){
			d=1;
		}
		if((a==0&&b==1)||(a==1&&b==0)){
			x=0;
		}
		else if((a==1&&b==1)||(a==0&&b==0)){
			x=1;
		}
		if((c==0&&d==1)||(c==1&&d==0)){
			y=0;
		}
		else if((c==1&&d==1)||(c==0&&d==0)){
			y=1;
		}
	}
	if(x==1&&y==1){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,m;
  cin >> n>> m;
  vi a(n);
  rep(i,n)cin >> a[i];
  int sum = 0;
  rep(i,n)sum+=a[i];
  int cnt = 0;
  rep(i,n){
    if(a[i] >= (double)sum/(double)(4.0*m))cnt++;
  }
  if(cnt>=m){
  print("Yes");
  }
  else print("No");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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 (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e9;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    rep(a,-1001,1001){
        rep(b,-1001,1001){
            ll i = a*a*a*a*a;
            ll j = b*b*b*b*b;
            if (i-j == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3624
#include <iostream>                                                                                                       

int main(){
   int N;
   std::cin >> N;
   int C[N-1], S[N-1], F[N-1];
   for(int i=0; i<N-1; ++i)
      std::cin >> C[i] >> S[i] >> F[i];

   for(int i=0; i<N; ++i){
      int t = 0;
      for(int j=i; j<N-1; ++j){
         if(t==S[j]) t += C[j];
         else if(t>S[j]) t += C[j] + ((t-S[j])%F[j]==0 ? 0 : F[j] - (t-S[j])%F[j]); 
         else t += C[j] + S[j] - t;
      }   
      std::cout << t << std::endl;
   }   
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9 + 5;
constexpr long long INFLL = 1LL << 62;
constexpr double eps = (1e-9);

class UnionFind {
public:
  // 親の番号を格納する。親だった場合は-(その集合のサイズ)
  vector<int> parent;

  // 作るときは parent の値を全て -1 にする
  // こうすると全てバラバラになる
  UnionFind(const int& n = 0) : parent(n, -1) {}

  // x がどのグループに属しているか調べる
  int find(const int& x) {
    if (parent[x] < 0) return x;
    return parent[x] = find(parent[x]);
  }

  // x と y をくっつける  O(log n)
  bool unite(int x, int y) {
    // x と y を直接くっつけるのではなく，root(x) に root(y) をくっつける
    x = find(x);
    y = find(y);
    if (x == y) return false;  // すでにくっついているからくっつけない

    // 大きい方(x) に小さい方(y)をくっつけたい 大小が逆だったらひっくり返す
    if (size(x) < size(y)) swap(x, y);

    parent[x] += parent[y];  // x のサイズを更新する
    parent[y] = x;  // y の親を x に変更する
    return true;
  }

  // 自分のいるグループの頂点数を調べる
  int size(const int& x) { return -parent[find(x)]; }

  // x と y が同じグループに属しているか否か
  bool same(const int& x, const int& y) { return find(x) == find(y); }
};

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

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

  UnionFind uf(m);

  vector<int> ml(n);

  rep(i, n) {
    int k;
    cin >> k;
    vector<int> l(k);
    rep(j, k) {
      cin >> l[j];
      l[j]--;
    }
    ml[i] = l[0];
    for (int j = 1; j < k; j++) {
      uf.unite(l[j-1], l[j]);
    }
  }

  int p = uf.find(ml[0]);
  for (auto& x : ml) {
    if (p != uf.find(x)) {
      puts("NO");
      return 0;
    }
  }

  puts("YES");

  return 0;
}


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

int main() {
	string x;

	for (;;) {

		int ans=0;

		cin >> x;
		if (x == "0")break;

		for (int i = 0; i < x.size(); i++) {
			ans += x[i]-'0';
		}
		cout << ans << endl;
	}
	return 0;
}

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

long long int N, a, b, c, C, I;
pair<long long, long long> r[33];
vector<pair<pair<long long, long long>, long long>> p;

int main(){
    scanf("%lld%lld", &N, &C);
    for(int i = 0; i < N; ++i){
        scanf("%lld%lld%lld", &a, &b, &c);
        p.push_back({{a, b}, c});
    }
    for(int i = 0; i < 33; ++i)r[i] = make_pair(-1, -1);
    sort(p.begin(), p.end());
    for(auto A : p){
        I = -1;
        for(int i = 0; i < 33; ++i){
            if((r[i].first < A.first.first || r[i].second == A.second) && (I < 0 || r[I].first < r[i].first)){
                I = i;
            }
        }
        r[I].first = A.first.second;
        r[I].second = A.second;
    }
    a = 0;
    for(int i = 0; i < 33; ++i){
        if(r[i].first >= 0)++a;
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 4852
import sys
sys.setrecursionlimit(10**7)

n, m, q = map(int, input().split())
abcd = [tuple(map(int, input().split())) for _ in range(q)]
ans = 0

def dfs(s):
    if len(s) == n:
        global ans
        cnt = 0
        for a, b, c, d in abcd:
            a -= 1; b -= 1
            if s[b] - s[a] == c: cnt += d
        ans = max(ans, cnt)
        return
    for i in range(s[-1], m+1):
        dfs(s + [i])

for i in range(1, m+1):
    dfs([i])

print(ans)


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

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void)
{
	int w, a, b;
	cin >> w >> a >> b;
	int ab = a - b;
	if(ab < 0) ab *= -1;
	ab -= w;
	PrintLn((ab < 0 ? 0 : ab));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pi;


int main(){
    int T = 1; //cin>>T;
    for(int t = 1; t <= T; t++){
    	ll n, d;
    	 cin >> n >> d;
    	 ll count = 0;
    	 for(ll i = 0; i < n; i++){
    	 	ll x, y; cin >>x >> y;
    	 	if((x*x)+(y*y) <= d*d) count++;
    	 }
    	 cout<<count<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
bool second(int p[],int i){
	if(p[i] < max(p[i-1],p[i+1]) && p[i] > min(p[i-1],p[i+1])){
		return true;
	}else{
		return false;
	}
}
int main(){
	int n; cin >> n;
	int p[n];
	for(int i=0;i<n;i++){
		cin >> p[i];
	}
	int count = 0;
	for(int i=1;i<n-1;i++){
		if(second(p,i)){
			count++;
		}
	}
	//cout << second(p,1) << second(p,2) << second(p,3) << endl;
	cout << count <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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 ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    int answer = 0;
    for (int i = 0; i < n; i++)
    {
        if ((i + 1) % 2 == 1)
        {
            if (a.at(i) % 2 == 1)
                answer++;
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
using namespace std;
map<string, int> str;

int dig[10];

bool solve(int x) {
	int num = 0;
	while(x) {
		dig[++num] = x % 10;
		x /= 10;
	}
	for(int i = 1; i <= num/2; i++) 
		if(dig[i] != dig[num+1-i]) return 0;
	return 1;
}
int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	int ans = 0;
	for(int i = a; i <= b; i++) 
		if(solve(i)) ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if( (b*10+c)%4==0 ) cout<<"YES" << endl;
  else cout<<"NO"<<endl;


  return 0;
}


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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define lp(i, a, b) for (int i=a; i<(b); i++)
#define lpd(i,a,b) for (int i = (b)-1; i >= a; i--)
	
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

bool cmp(pl a, pl b){
    return (a.first < b.first);
}

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

    int n;
    ll m, a, b;
    cin>>n>>m;

    vector<pair<ll ,ll> > v(n);
    lp(i, 0, n){
        cin>>a>>b;
        v[i] = mp(a, b);
    }
    sort(all(v), cmp);

    ll sum = 0, price = 0;
    int i = 0;
    while(sum+v[i].second <= m){
        sum += v[i].second;
        price += (v[i].first*v[i].second);
        i++;
    }
    price += (v[i].first*(m-sum));

    cout<<price<<endl;

    return 0;
}

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

using namespace std;

int main(void){
  int n, k;
  cin >> n >> k;
  vector<int> v, l;
  for(int i = 0; i < n; ++i){
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
    if (tmp < 0)
      tmp = -tmp;
    l.push_back(tmp);
  }
  int left = 0;
  for(int i = 0; i < n; ++i){
    if (v[i] < 0)
      ++left;
    else
      break;
  }
  int right = n - left;
  int maxlen = 1000000000;
  /* l2r */
  for(int i = 0; i < left; ++i){
    if (left - i >= k){
      int len = l[i];
      if (maxlen > len)
        maxlen = len;
    }else if (left - i + right < k){
      break;
    }else{
      int len = l[i]*2 + l[i+k-1];
      if (maxlen > len)
        maxlen = len;
    }
  }
  /* r2l */
  for(int i = 0; i < n/2; ++i){
    int swp = l[i];
    l[i] = l[n-i-1];
    l[n-i-1] = swp;
  }
  left = right;
  right = n - left;
  for(int i = 0; i < left; ++i){
    if (left - i >= k){
      int len = l[i];
      if (maxlen > len)
        maxlen = len;
    }else if (left - i + right < k){
      break;
    }else{
      int len = l[i]*2 + l[i+k-1];
      if (maxlen > len)
        maxlen = len;
    }
  }
  cout << maxlen << endl;
  return 0;
}


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

int main(){
  int H,W;
  int dx[4] = {1,0,-1,0};
  int dy[4] = {0,1,0,-1};
  cin >> H >> W;
  string board[H];
  for(int i = 0; i < H; i++){
      cin >> board[i];
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(board[i][j] == '.') continue;
      bool flag = false;
      for(int k = 0; k < 4; k++){
          int nx = j + dx[k];
          int ny = i + dy[k];
          if( nx >= 0 && ny >= 0 && nx < W && ny < H && board[ny][nx] == '#') flag = true;
      }
       if(flag) continue;
       else{
         cout << "No" << endl;
         return 0;
       }
    }
  }

  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define inf 100000000
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, limit;
    //n個の帰宅経路がある
    //i番目の経路を使うと時間tで帰宅する
    //コストcかけて
    //limit時間以内に帰宅しなければならない
    cin>>n>>limit;
    int i;
    vector<int> c(n),t(n);
    for (int i=0; i<n; i++){
        cin>>c[i]>>t[i];          
    }
    int ans = inf;
    for (int i=0; i<n; ++i){
        if (limit>=t[i]){
            if (c[i]<ans){
                ans = c[i];
            }        
        }
    }
    if (ans == inf){
        cout << "TLE" << endl;
    }
    else {
        cout<<ans<<endl;    
    }
}

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

int main()
{
  int64_t N, K, a;
  cin >> N >> K;
  vector<int64_t> A(200100, 0);
  for (int i = 0; i < N; i++)
  {
    cin >> a;
    A.at(a)++;
  }
  priority_queue<int64_t, vector<int64_t>, greater<int64_t>> que;
  for (int i = 0; i < 200100; i++)
  {
    if (A.at(i) == 0)
      continue;
    que.push(A.at(i));
  }
  int64_t k = que.size(), ans = 0;
  while (k > K)
  {
    ans += que.top();
    que.pop();
    k--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6764
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int A, B; cin >> A >> B;
  string num; cin >> num;

  bool flag = true;
  for (int i = 0; i < A; i++) {
    if (!isdigit(num[i])) flag = false;
  }
  if (num[A] != '-') flag = false;
  for (int i = A + 1; i < A + B + 1; i++) {
    if (!isdigit(num[i])) flag = false;
  }

  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}



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

typedef long long ll;

int main(){
    int N;
    cin >> N;
    int dp[N+1];
    for(int i = 0; i <= N; i++){
        dp[i] = i;
    }
    for(int i = 0; i <= N; i++){
        dp[i+1] = min(dp[i]+1, dp[i+1]);

        // 6
        int add;
        add = 6;
        while(i + add <= N){
            dp[i+add] = min(dp[i]+1, dp[i+add]);
            add *= 6;
        }
        add = 9;
        while(i + add <= N){
            dp[i+add] = min(dp[i]+1, dp[i+add]);
            add *= 9;
        }
    }
    cout << dp[N] << endl;
} 

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String strArray[] = str.split(" ");
		int a = 0;
		int b = 0;
		while(!strArray[1].equals("?")){
			a = Integer.parseInt(strArray[0]);
			b = Integer.parseInt(strArray[2]);
			if(strArray[1].equals("+")){
				System.out.println(a + b);
			}else if(strArray[1].equals("-")){
				System.out.println(a - b);
			}else if(strArray[1].equals("*")){
				System.out.println(a * b);
			}else{
				System.out.println((int)(a / b));
			}
			str = br.readLine();
			strArray = str.split(" ");
			a = Integer.parseInt(strArray[0]);
			b = Integer.parseInt(strArray[2]);
		}
	}
}

Measured memory_bytes: 24120