akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(ll key, ll value){
      this->key = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

void calc_dp(const int start, const vector<double>& p, vector<double>& dp){
  if(start==p.size()-1){
    dp[0] = 1.0-p[start];
    dp[1] = p[start];
    return;
  }
  calc_dp(start+1, p, dp);
  dp[p.size()-start] = dp[p.size()-start-1]*p[start];
  for(int i=p.size()-start-1; i>0; --i){
    dp[i] = dp[i]*(1.0-p[start]) + dp[i-1]*p[start];
  }
  dp[0] = dp[0]*(1.0-p[start]);
  return;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  // ans 1
  /* 
  vector<double> p(N);
  rep(i, 0, N){
    cin >> p[i];
  }
  vector<double> dp(N+1, 0.0);
  calc_dp(0, p, dp);
  */

  //ans 2
  vector<double> dp(N+1, 0.0);
  double tmp;
  cin >> tmp;
  dp[1] = tmp;
  dp[0] = 1.0-tmp;
  rep(i, 1, N/2+1){
    cin >> tmp;
    dp[i+1] = dp[i]*tmp;
    for(int j=i; j>0; --j){
      dp[j] = dp[j]*(1.0-tmp) + dp[j-1]*tmp;
    }
    dp[0] = dp[0]*(1.0-tmp);
  }
  rep(i, N/2+1, N){
    cin >> tmp;
    dp[i+1] = dp[i]*tmp;
    for(int j=i; j>i-N/2; --j){
      dp[j] = dp[j]*(1.0-tmp) + dp[j-1]*tmp;
    }
  }

  double ans=0.0;
  rep(i, N/2+1, N+1){
    ans += dp[i];
  }

  printf("%.10lf\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int INF = 1e9;

int main(){
  int N, Z, W; cin >> N >> Z >> W;
	vector<int> a(N);
	for(int i = 0; i < N; i++) cin >> a[i];
	if(N == 1) cout << abs(a[0] - W) << endl;
	else cout << max(abs(a[N - 1] - a[N - 2]), abs(a[N - 1] - W)) << endl;
}

Measured memory_bytes: 256
def sum_price(i, j, k):
    return i*500 + j*100 + k*50


if __name__ == '__main__':
    li = []
    for i in range(4):
        li.append(int(input()))

    goal_price = li[3]
    cnt = 0
    for i in range(li[0]+1):
        for j in range(li[1]+1):
            for k in range(li[2]+1):
                if sum_price(i, j, k) == goal_price:
                    cnt += 1

    ans = cnt
    print(ans)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
 
  int n;
  cin >> n;
  int ans = 0;
  while(n > 0){
    if(n > 2){
      n -= 3;
      ans++;
    }else{
      n = 0;
    }
  }
  cout << ans << endl;
  return 0;
 
}

Measured memory_bytes: 256
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}

void main() {
    int h,w,k;
    R(h,w,k);
    VI X(h), Y(w);
    unordered_map<int,set<int>> mp;
    REP(i,k) {
        int a,b;
        R(a,b);
        --a; --b;
        mp[a].insert(b);
        X[a]++; Y[b]++;
    }
    vector<PII> xs,ys;
    REP(i,h) xs.push_back({X[i],i});
    REP(i,w) ys.push_back({Y[i],i});
    sort(RALL(xs));
    sort(RALL(ys));
    LL ans=0;
    for ( int i=0; i<h; i++ ) {
        for ( int j=0; j<w; j++ ) {
            LL me=xs[i].first+ys[j].first;
            if ( mp[xs[i].second].count(ys[j].second) ) {
                me--;
                chmax(ans,me);
            } else {
                chmax(ans,me);
                break;
            }
        }
    }
    W(ans);
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}


Measured memory_bytes: 55648
#include <iostream>
#include <string>
#include <vector>
#include <climits>
using namespace std;

int A[2097152], V[2097152];
int num, head;

void init(int n) {
    num = 1;
    while (num < n) num *= 2;
    head = num - 1;
    num *= 2;
    int l = head + n;
    for (int i=0; i<=l; ++i) {
        A[i] = (i < head ? 1 : i - head);
        V[i] = 0;
    }
    for (int i=l+1; i<num; ++i) {
        A[i] = INT_MAX;
        V[i] = -INT_MAX;
    }
}

void update(int a, int v) {
    int k = head + a;
    V[k] += v;
    while (k) {
        k = (k - 1) / 2;
        int l = 2*k+1, r = 2*k+2;
        int tv = V[k], ta = A[k];
        if (V[l] < V[r] || (V[l] == V[r] && A[l] > A[r])) {
            V[k] = V[r];
            A[k] = A[r];
        } else {
            V[k] = V[l];
            A[k] = A[l];
        }
        if (tv == V[k] && ta == A[k]) {
            break;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    init(n);
    int a, v;
    for (int i=0; i<q; ++i) {
        cin >> a >> v;
        update(a, v);
        cout << A[0] << " " << V[0] << endl;
    }
    return 0;
}

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

void printA(int a[], int n){
    int i;
    for(i=0;i<n;i++){
        cout << a[i];
        if(i!=n-1) cout << " ";
    }
    cout << endl;
}

void insertionSort(int a[], int n){
    int i,j,v;
    for(i=1;i<n;i++){
        v = a[i];
        j = i - 1;
        while(j >= 0 && a[j] > v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        printA(a, n);
    }
}

int main(){
    int i,n;
    cin >> n;
    int a[n];
    for(i=0;i<n;i++) cin >> a[i];
    printA(a, n);
    insertionSort(a, n);

    return 0;
}



Measured memory_bytes: 3092
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        Map<Integer, Integer> map = new HashMap<>();

        for (int i=0; i<m; i++) {
            int keta = sc.nextInt();
            int num = sc.nextInt();

            if (keta == 1 && num == 0 && n >= 2) {
                System.out.println(-1);
                return;
            }

            if (map.containsKey(keta)) {
                if (!map.get(keta).equals(num)) {
                    System.out.println(-1);
                    return;
                }
            }

            map.put(keta, num);
        }

        StringBuilder sb = new StringBuilder();
        for (int i=1; i<=n; i++) {
            if (map.containsKey(i)) {
                sb.append(map.get(i));
            } else {
                if (i == 1 && n >= 2) {
                    sb.append(1);
                } else {
                    sb.append(0);
                }
            }
        }

        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 23124
import Control.Monad
import Text.Printf
import Control.Applicative

main :: IO()
main = do
  [a, b, k] <- words <$> getLine
  printf "%s" $ slv (read a :: Int) (read b :: Int) (read k :: Int)

slv :: Int -> Int -> Int -> String
slv a b k | (b - a + 1) > 2 * k = unlines $ map show anslist
          | otherwise = unlines $ map show [a..b]
  where anslist = ls ++ rls
        ls = [a..(a + k - 1)]
        rls = [(b - k + 1)..b]



Measured memory_bytes: 892
#include<stdio.h>
main()
{
  int i,j,v,n,a[1000];
  scanf("%d",&n);
  for(i=0; i<n; i++){
  scanf("%d",&a[i]);
  }
  for(i=0; i<=n-1; i++){
    v = a[i];
    j = i - 1;
    while(j >= 0 && a[j] > v){
      a[j+1] = a[j];
      j--;
      a[j+1] = v;
    }
    for(j=0; j<n; j++){
    printf("%d",a[j]);
    if(a[j+1] == '\0')printf("\n");
    else printf(" ");
    }
  }
  return 0;
}

Measured memory_bytes: 604
//By UditDesai
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define trav(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define nl cout<<'\n'
#define sp <<' '<<
#define sz(a) (int)(a.size())
#define check(x) cout << #x << " : " << (x) << endl
#define show(a) for(auto i:a) cout<<i<<" ";cout<<endl//By UditDesai
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int N=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;
 
 
int main()
{
	fastio;
	ll i,n,j,ans;
	cin>>n;
	ll a[n+1],b[n+1],c[n+1],dp[n+1][3];
	forsn(i,1,n+1) cin>>a[i]>>b[i]>>c[i];
	dp[1][0] = a[1];
	dp[1][1] = b[1];
	dp[1][2] = c[1];
	for(i=2;i<=n;i++)
	{
		dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i];
		dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b[i];
		dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c[i];
	}
	cout<<max({dp[n][0],dp[n][1],dp[n][2]});
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int l,r,d;
    cin>>l>>r>>d;
    int count=0;
    for (int i=l;i<=r;i++) {
        if (i%d==0) {
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3628
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 1/13/2019, 9:02:15 PM
# Powered by Visual Studio Code
#

s = gets.chomp

for i in 0...s.size
  for j in i...s.size
    if s[0...i] + s[j...s.size] == 'keyence'
      puts "YES"
      exit
    end
  end
end

puts "NO"

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_output(v) for(auto it=v.begin();it!=v.end();it++){if(it!=v.begin())cout<<" ";cout<<*it;}cout<<endl;
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);
long long int combination(long long int,long long int);
long long int series_sum(long long int);

int main(){
    int n,m,d;
    cin>>n;
    unordered_map<int,int> map1;
    rep(i,n){
        cin>>d;
        if(map1.count(d)){
            map1[d]++;
        }else{
            map1[d]=1;
        }
    }
    cin>>m;
    unordered_set<int> set;
    unordered_map<int,int> map2;
    rep(i,m){
        cin>>d;
        if(map2.count(d)){
            map2[d]++;
        }else{
            set.insert(d);
            map2[d]=1;
        }
    }
    int ans=1;
    for (auto value : set) {
        if(map1[value]<map2[value]){
            ans=0;
            break;
        }
    }
    YN(ans);
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    int N, X, Y;
    cin >> N >> X >> Y;
    --X, --Y;

    Vi ans(N);

    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            int d1 = j - i;
            int d2 = abs(i - X) + abs(j - Y) + 1;
            ++ans[min(d1, d2)];
        }
    }

    for (int i = 1; i < N; i++) {
        cout << ans[i] << '\n';
    }

    return 0;
}

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

int main(){
  char s[258] = {}, tmp[258] = {};
  int m, h, i, l;
  while(scanf("%s", s) && s[0] != '-'){
    scanf("%d", &m);
    while(m--){
      scanf("%d", &h);
      strcpy(tmp, s + h);
      s[h] = '\0';
      strcat(tmp, s);
      strcpy(s, tmp);
    }
    puts(s);
  }
  return 0;
}




Measured memory_bytes: 2068
#include <iostream>
using namespace std;
int main(){
  	string s;cin >> s;
  	if(s.size()!=6){
      	cout << "No" << endl;
      	return 0;
    }if((s[2]==s[3])&&(s[4]==s[5])){
      	cout << "Yes" << endl;
    }else cout << "No" << endl;
  	return 0;
}

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

typedef long long ll;
ll S, x;
int main()
{
	cin >> S;
	x = sqrt(S);
	if (x * x == S) cout << "0 0 " << x << " 0 0 " << x;
	else cout << "0 0 " << (x + 1) << " 1 " << (x + 1) * (x + 1) - S << " " << (x + 1);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin>>S;
  int ans=0,ans2=0;
  REP(i,S.size()){
    if(i%2==0 && S[i]!='0')ans++;
    else if(i%2==1 && S[i]!='1')ans++;
  }
  REP(i,S.size()){
    if(i%2==0 && S[i]!='1')ans2++;
    else if(i%2==1 && S[i]!='0')ans2++;
  }
  cout<<min(ans,ans2);
  
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;

int main() {
    ll H, W;
    cin >> H >> W;
    ll sh, sw, gh, gw;
    cin >> sh >> sw;
    cin >> gh >> gw;
    sh--;
    sw--;
    gh--;
    gw--;

    // 道の一覧
    vector<vector<bool>> roads(H, vector<bool>(W, false));
    for (ll h = 0; h < H; h++) {
        for (ll w = 0; w < W; w++) {
            char c;
            cin >> c;
            while (c != '.' && c != '#') {
                cin >> c;
            }
            if (c == '.') {
                roads[h][w] = true;
            }
        }
    }

    vector<vector<bool>> done(H, vector<bool>(W, false));
    vector<stack<pair<ll, ll>>> diststack(2);
    ll d = 0;
    diststack[0].push(make_pair(sh, sw));
    while (d <= H * W + 2) {
        if (diststack[d % 2].empty()) {
            d++;
            continue;
        }
        auto src = diststack[d % 2].top();
        diststack[d % 2].pop();
        ll h = src.first;
        ll w = src.second;
        if (h == gh && w == gw) {
            cout << d << endl;
            return 0;
        }
        if (done[h][w]) {
            continue;
        }
        done[h][w] = true;
        for (ll y = h - 2; y <= h + 2; y++) {
            for (ll x = w - 2; x <= w + 2; x++) {
                if (y >= 0 && y < H && x >= 0 && x < W && roads[y][x] && !done[y][x]) {
                    if (abs(x - w) + abs(y - h) == 1) {
                        diststack[d % 2].push(make_pair(y, x));
                    } else {
                        diststack[1 - (d % 2)].push(make_pair(y, x));
                    }
                }
            }
        }
    }
    cout << -1 << endl;
}


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

using namespace std;

using int64 = long long;

vector< vector< int64_t > > get_combination(int N)
{
  vector< vector< int64_t > > mat(N + 1, vector< int64_t >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return (mat);
}


int main()
{
  int N, A, B;
  auto table = get_combination(51);

  cin >> N >> A >> B;
  vector< int64 > v(N);
  map< int64, int > mp;
  for(int i = 0; i < N; i++) {
    cin >> v[i];
    ++mp[v[i]];
  }
  sort(v.rbegin(), v.rend());

  int64 sum = 0, ret = 0;
  int select = 0;
  for(int i = 0; i < B; i++) {
    if(i >= A && v[0] != v[i]) {
      break;
    } else if(v[A - 1] == v[i]) {
      ++select;
    }
    if(i < A) {
      sum += v[i];
    }
    if(i + 1 >= A) {
      ret += table[mp[v[A - 1]]][select];
    }
  }

  cout << fixed << setprecision(10) << 1.0 * sum / A << endl;
  cout << ret << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    string s,t; cin>>s>>t;
    int n = s.length(); int m = t.length();

    int ans = INF;
    rep(i,n-m+1) {
        int tmp = 0;
        rep(j,m) {
            if (s[i+j] != t[j]) tmp++;
        }
        chmin(ans,tmp);
    }

    cout << ans << '\n';
    return 0;
}

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


const int INF = 1e+9;

int main()
{
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> a(N+1), b(N+1), c(N+1);
    for( int i = 1; i <= N; ++i ) cin >> a[i] >> b[i] >> c[i];


    int maxA = 0, maxB = 0;
    for( int i = 1; i <= N; ++i ){
        maxA += a[i];
        maxB += b[i];
    } 

    // dp[i][A][B]: i 番目までの薬品を選び終わった時に a の重さが A, b の重さが B になる
    //            　組み合わせを作るのに必要な最小のコスト
    int dp[41][401][401];

   for( int n = 0; n <= N; ++n ){ 
        for( int i = 0; i <= maxA; ++i ){
            for( int j = 0; j <= maxB; ++j ){
                dp[n][i][j] = INF;
            } 
        }
    }
    dp[0][0][0] = 0; 
    for( int n = 1; n <= N; ++n ){ 
        for( int i = 0; i <= maxA; ++i ){
            for( int j = 0; j <= maxB; ++j ){
                if( dp[n-1][i][j] == INF ) continue;
                dp[n][i][j] = min( dp[n][i][j], dp[n-1][i][j] );  // n 番目の薬品を買わない場合
                dp[n][i+a[n]][j+b[n]] = min( dp[n][i+a[n]][j+b[n]], dp[n-1][i][j] + c[n] );  // n 番目の薬品を買う場合
            } 
        }
    }

    int ans = INF;
    for( int i = 1; i <= maxA; ++i ){
        for( int j = 1; j <= maxB; ++j ){
            if( Ma*j == Mb*i ) ans = min( ans, dp[N][i][j] );
        }
    } 
    if( ans == INF ) cout << "-1" << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 25600
using System;

namespace C_sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var items = Console.ReadLine().Split(' ');

            var a = int.Parse(items[0]);
            var b = int.Parse(items[1]);
            
            var d = a / b;
            var r = a % b;
            var f = (decimal)a / b;

            Console.WriteLine($"{d} {r} {f}");
        }
    }
}



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

#define int long long
const int mod = 1e9 + 7;
map < pair < pair < int, int > , int > , int > memo;
map < int, set < int > > g;
int n;

int dp(int i, int par, int black){
    int ans = 1, nokids = 1;
    if(memo.count({{i, par}, black})) return memo[{{i, par}, black}];
    if (black){
        for(auto j : g[i]){
            if (j != par){
                nokids = 0;
                ans = ans * dp(j, i, 0) % mod;
            }
        }
    }
    else{
        for(auto j : g[i]){
            if (j != par){
                nokids = 0;
                ans = ans * ( dp(j, i, 0) + dp(j, i, 1) ) % mod;
            }
        }
    }

    if (nokids) ans = 1;
    memo[{{i, par}, black}] = ans;
    return ans;
}

signed main(){

    
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    int a, b;
    for(int i = 0;i < n - 1; ++i){
        cin >> a >> b;
        g[a].insert(b);
        g[b].insert(a);
    }

    cout << (dp(1, -1, 0) + dp(1, -1, 1)) % mod << endl;

}

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

int main(){
	int n,k;
	long long candles[100000];
	cin>>n>>k;
	int ydrs=-1;
	for(int i=0;i<n;i++){
		cin>>candles[i];
		if(candles!=0 && candles[i-1]<0 && candles[i]>=0)ydrs=i;
	}
	if(ydrs==-1){
	    if(candles[n-1]>0)
	        cout<<candles[k-1]<<endl;
        else cout<<-candles[n-k]<<endl;
        return 0;
	}
	long long minn=10E14;
	long long l=ydrs-k+1,r=ydrs;
	if(l<0)l=0,r=k-1;
	for(;candles[l]<=0 && r<n;l++,r++){
		minn=min(minn,0-2*candles[l]+candles[r]);
		minn=min(minn,0-candles[l]+2*candles[r]);
	}
	cout<<minn<<endl;
	return 0;
}

Measured memory_bytes: 1024
h, w = map(int, input().split())
s = [[]for _ in range(h)]
for i in range(h):
    s[i] = list(input())

ans = [["." for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            if i != 0:
                if s[i-1][j] == "#":
                    ans[i-1][j] = "#"
            if i != h-1:
                if s[i+1][j] == "#":
                    ans[i+1][j] = "#"
            if j != 0:
                if s[i][j-1] == "#":
                    ans[i][j-1] = "#"
            if j != w-1:
                if s[i][j+1] == "#":
                    ans[i][j+1] = "#"
print("Yes" if s == ans else "No")


Measured memory_bytes: 9056
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  string s;
  cin >> s;
  rep(i,3)cout<<s[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 3652
#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 pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
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;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n;cin>>n;
    REP(i,n,inf){
        bool b=true;
        REP(j,2,sqrt(i)+1){
            if(i%j==0){
                b=false;
                break;
            }
        }
        if(b){
            cout<<i<<endl;
            return 0;
        }
    }
}

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
typedef long long ll;

int main() {
  int n;
  cin >> n;
  if(n == 1) {
    printf("Yes\n");
    return 0;
  } else if(n > 81) {
    printf("No\n");
    return 0;
  }
  for(int i = 2; i < 10; i++) {
    if(n % i == 0) {
      if(n / i < 10) {
        printf("Yes\n");
        return 0;
      }
    }
  }
  printf("No\n");
  return 0;
}

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

typedef long long ll;
const int EMPTY = 0;
const int VERT = 1;
const int HORI = 2;
const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  string s1, s2;
  cin >> s1;
  cin >> s2;

  ll ans = 1;
  int type = EMPTY;
  int pos = 0;
  int pos_bef;
  while (pos < n) {
    pos_bef = pos;
    if (s1[pos] == s2[pos]) {
      ans *= (3-type);
      type = VERT;
      ++pos;
    }
    else {
      if (type == HORI) { 
        ans *= 3;
      }
      else {
        ans *= (3-type) * (2-type);
      }
      type = HORI;
      pos += 2;
    }
    // cout << s1[pos_bef] << " " << ans << endl;
    ans %= MOD;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

  int a;
  cin >> a;
  if ((a == 7) || (a == 5) || (a == 3)){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int cnt{0}, size{0}, ans{0};
  for(char c; ~scanf("%c", &c) && c != '\n'; size++) {
    if(c == 'S') cnt++;
    else if(cnt > 0) cnt--, ans++;
  }
  cout << size - 2 * ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	ll x;
	cin >> x;
	ll kyori = 0;
	for (int i = 1; i <= x; i++) {
		kyori += i;
		if (kyori == x) {
			cout << i << endl;
			return 0;
		}
		if (kyori > x) {
			if (kyori - x<=i) {
				cout << i << endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Maxn 4000007
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
void foo(){
    int k;
    cin>>k;
    vi 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];
}
int main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)foo();
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r;};

Node T[MAX];
int n, D[MAX];

void print(int u){
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    
    if( T[u].p == NIL ) cout << "root, ";
    else if ( T[u].l == NIL ) cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    for( i = 0, c = T[u].l; c != NIL; i++ ,c = T[c].r){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

int rec(int u, int p) {
    D[u] = p;
    if( T[u].r != NIL) rec( T[u].r , p ) ;
    if( T[u].l != NIL) rec( T[u].l , p + 1);
}

int main()
{
    int i, j, d, v, c, l, r;
    cin >> n;
    for( i = 0; i < n; i++) T[i].l = T[i].p = T[i].r = NIL;
    
    for( i = 0; i < n; i++){
        cin >> v >> d;
        for( j = 0 ; j < d; j++){
            cin >> c;
            if( j == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;  
        }
    }
    
    for( i = 0; i < n; i++)
        if( T[i].p == NIL )
            r = i;
    
    rec(r , 0);
    
    for( i = 0; i < n; i++) print(i);
    
    return 0;
}



Measured memory_bytes: 7772
N,Y=map(int,input().split())
a=Y//10000
flag=0
for i in range(a+1):
  for j in range(N-i+1):
    if Y==i*10000+j*5000+(N-i-j)*1000:
      if flag==0:
        print(i,j,(N-i-j))
        flag=1
if flag==0:
  print("-1 -1 -1")

Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
 
typedef struct{
  double x;
  double y;
}Hirasawa;
  
void Ryoma(int n, Hirasawa p1, Hirasawa p2){

  if(n==0) return;
  Hirasawa s,t,u;
 
  s.x = (p2.x-p1.x)/3+p1.x;
  s.y = (p2.y-p1.y)/3+p1.y;
  t.x = 2*(p2.x-p1.x)/3+p1.x;
  t.y = 2*(p2.y-p1.y)/3+p1.y;
  u.x = (t.x-s.x)/2-sqrt(3)/2*(t.y-s.y)+s.x;
  u.y = (t.y-s.y)/2+sqrt(3)/2*(t.x-s.x)+s.y;
 
  Ryoma(n-1,p1,s);
  printf("%f %f\n",s.x,s.y);
   
  Ryoma(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
   
  Ryoma(n-1,u,t);
  printf("%f %f\n",t.x,t.y);
 
  Ryoma(n-1,t,p2);
}

int main(){
 
  Hirasawa p1,p2;
  int n;
 
  p1.x = 0;
  p2.x = 100;
  p1.y = 0;
  p2.y = 0;
 
  scanf("%d",&n);
 
  printf("%f %f\n",p1.x,p1.y);
  Ryoma(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);
 
  return 0;
}

Measured memory_bytes: 636
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,M;
	vint adj[100001];
	scan(N);scan(M);
	rep(i,M){
		int a,b;
		scan(a);scan(b);
		a--; b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	deque<int> path;
	bool pathexist[100001]={};
	path.push_front(0),path.push_back(adj[0][0]);
	pathexist[0]=pathexist[adj[0][0]]=true;
	while(1){
		int flag=1;
		int fr=path.front(),ba=path.back();
		rep(i,adj[fr].size()){
			if(pathexist[adj[fr][i]]==false){
				flag=0;
				path.push_front(adj[fr][i]);
				pathexist[adj[fr][i]]=true;
				break;
			}
		}
		if(flag==0) continue;
		rep(i,adj[ba].size()){
			if(pathexist[adj[ba][i]]==false){
				flag=0;
				path.push_back(adj[ba][i]);
				pathexist[adj[ba][i]]=true;
				break;
			}
		}
		if(flag==0) continue;
		else break;
	}
	prin(path.size());
	rep(i,path.size()){
		printf("%d ",path[i]+1);
	}
	kaigyo;
	return 0;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll k;
    cin >> k;
    ll ans = 0;
    set<ll> lis;
    vector<ll> sev0;
    sev0.push_back(7);
    ll sept = 7;
    for (int i = 0;; i++) {
        if (i != 0) {
            sev0.push_back((sev0[i - 1] * 10) % k);
            sept += sev0[i];
        }
        sept %= k;
        if (sept == 0) {
            ans = i + 1;
            break;
        } else if (lis.find(sept) != lis.end()) {
            ans = -1;
            break;
        }
        lis.insert(sept);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 57872
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(k: usize);
    let n = 50;
    let mut b = vec![k / n; n];
    for i in 0..(k % n) {
        b[i] += 1;
    }

    assert_eq!(b.iter().sum::<usize>(), k);
    let mut upper_a = vec![0; n];
    for i in 0..n {
        upper_a[i] = (n + 1) * b[i] + (n - 1) - k;
    }
    println!("{}", n);
    for i in 0..n {
        if i > 0 {
            print!(" ");
        }
        print!("{}", upper_a[i]);
    }
    println!();
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int n;
      cin >> n;
      bool flag=false;
      rep(i,100){
       rep(j,100){
        if(4*i+7*j==n)flag=true; 
       }
      }
      if(flag)cout << "Yes" << endl;
      else cout << "No" << endl;
      return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll MOD = 1e9+7;

int main(){
  int d,w;
  while(cin>>d>>w,d){
	int e[11][11];
	int ans=0;
	for(int i=0;i<d;i++)
	  for(int j=0;j<w;j++)
		cin>>e[i][j];
	
	for(int i=0;i<d-2;i++)
	  for(int j=0;j<w-2;j++)
		for(int x=i+2;x<d;x++)
		  for(int y=j+2;y<w;y++){
			int wl=11;
			int ik=0;
			for(int k=i;k<=x;k++){
			  wl=min(wl,e[k][j]);
			  wl=min(wl,e[k][y]);
			}

			for(int k=j;k<=y;k++){
			  wl=min(wl,e[i][k]);
			  wl=min(wl,e[x][k]);
			}

			int sum=0;
			for(int k=i+1;k<x;k++)
			  for(int l=j+1;l<y;l++){
				ik=max(ik,e[k][l]);
				sum+=e[k][l];
			  }
		  
			if(wl<=ik)continue;
			ans=max(ans,wl*(x-i-1)*(y-j-1)-sum);
		  }
	cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 2984
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(input.readLine());
        int N = Integer.parseInt(st.nextToken());
        int W = Integer.parseInt(st.nextToken());
        int[] weights = new int[N];
        long[] values = new long[N];
        for(int n = 0; n<N; n++){
            st = new StringTokenizer(input.readLine());
            weights[n] = Integer.parseInt(st.nextToken());
            values[n] = Integer.parseInt(st.nextToken());
        }
        long[] dp = new long[W+1];
        for(int i = 0; i<N; i++){
            for(int j = W; j>=0; j--){
                if(j+weights[i]<=W) dp[j+weights[i]] = Math.max(dp[j] + values[i], dp[j+weights[i]]);
            }
        }
        
        output.println(dp[W]);
        output.close();
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N, K[3]; cin >> N >> K[0] >> K[1] >> K[2];

    vector<int> L(N);
    REP(i, 0, N) cin >> L[i];

    vector<vector<int>> cost(3, vector<int>(1 << N, 0));
    REP(i, 0, 3) {
        for (int bit = 1; bit < (1 << N); bit++) {
            int sum = 0, cnt = 0;
            REP(j, 0, N) if (bit & (1 << j)) {
                sum += L[j]; cnt++;
            }
            cost[i][bit] = abs(K[i] - sum) + 10 * (cnt - 1);
        }
    }

    int ans = 1 << 30;
    REP(i, 1, 1 << N) {
        REP(j, 1, 1 << N) {
            REP(k, 1, 1 << N) {
                if ((i & j) || (j & k) || (i & k)) continue;
                // cout << "###" << endl;
                // cout << bitset<8>(i) << " : " << cost[0][i] << endl;
                // cout << bitset<8>(j) << " : " << cost[1][j] << endl;
                // cout << bitset<8>(k) << " : " << cost[2][k] << endl;
                ans = min(ans, cost[0][i] + cost[1][j] + cost[2][k]);
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
/*test*/
#include<bits/stdc++.h>

using namespace std;

int main() {
    int i = 0, bko = 0;
    long long int sum = 0, b=0;
    string s;
    cin >> s;
    for (i = 0; i < s.size(); i++) {
        if (s[i] == 'B') {
            b += bko;
            bko += 1;
            sum += s.size() - 1 - i;
        }
    }
    cout << sum - b << endl;
    return 0;
}

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

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

  for(int i=0;i<s.size();i++){
    s[i] =(s[i] -'A'+n)%26 +'A';
  }
  cout<<s<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int findsum(int n)
{
    int sum = 0;
    while(n > 0){
        sum += n%10;
        n /= 10;
    }
    return sum;
}

int main(void)
{
    int N, A, B;
    scanf("%d%d%d", &N, &A, &B);
    int total = 0;
    for(int i=1;i<=N;i++){
        int sum = findsum(i);
        if(A <= sum && sum <= B) total += i;
    }
    printf("%d\n", total);
    return 0;
}


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

const ll MAXN = 200000;

ll N, ans=0, tmp=0;
vector<ll> A(MAXN, 0);

void yakusuu(ll n) {
    for(int i=1;i*i<=n;i++) {
        if(n%i==0) {
            if(abs(i-n/i)>=2) {
                if(i>n/i) ans += i-1;
                else ans += n/i-1;
            }
        }
    }
}

signed main(){
    cin >> N;
    yakusuu(N);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    try(Scanner sc = new Scanner(System.in)) {
      int N = sc.nextInt();
      String S = sc.next();
      char[] s = S.toCharArray();
      int answer = Integer.MAX_VALUE;
      int count0 = 0;
      for ( int i = 1; i < N; i++ ) {
        if ( s[i] == 'E' ) {
          count0++;
        }
      }
      if ( count0 < answer ) {
        answer = count0;
      }
      int prev = count0;
      for ( int i = 1; i < N; i++ ) {
        int count = prev + ( s[i-1] == 'W' ? 1 : 0 ) - ( s[i] == 'E' ? 1 : 0 );         
        if ( count < answer ) {
          answer = count;
        }
        prev = count;
      }
      System.out.println(answer);
    }
  }
  
}

Measured memory_bytes: 28696
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    X, N = read_values()
    if N == 0:
        input()
        print(X)
    else:
        P = set(read_list())
        for d in range(10000):
            if X - d not in P:
                print(X - d)
                return
            elif X + d not in P:
                print(X + d)
                return
        

if __name__ == "__main__":
    main()



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

string words[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string S;
    cin >> S;
    reverse(S.begin(), S.end());

    for(int i=0; i<4; i++) reverse(words[i].begin(), words[i].end());

    bool cut = true;
    for (int i=0; i < S.size(); ) {
        // 文字列Sをすべて舐めて調べる
        bool cut2 = false;
        for (int j = 0; j < 4; j++ ) {
            // wordsの単語に一致するか調べてみる
            string d = words[j];
            // 文字列Sのi文字目から words[j] の長さだけ調べる(※1)
            if (S.substr(i, d.size()) == d) {
                // (※1)が一致したら カットできるのでフラグ立てる
                cut2 = true;
                i += d.size();
                // 次の文字を調べる
            }
        }

        if (!cut2) {
            cut = false;
            break;
        }
    }

    if (cut) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 512
#include"bits/stdc++.h"
using namespace std;

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

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

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();
LL ave(LL, LL);
bool isMultiOf(LL, LL);

int main() {
	string a, b, c; cin >> a >> b >> c;
	if (a.back() == b[0] && b.back() == c[0])cout << "YES";
	else cout << "NO";
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}
LL ave(LL a, LL b) {
	return (a + b) / 2;
}
bool isMultiOf(LL a, LL b) {
	return a % b == 0;
}

Measured memory_bytes: 256