akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		final int DICE = 6;
		int dice[] = new int[DICE];
		int dice2[] = new int[DICE];
		int dice22[] = new int[DICE];
		boolean perfect = false;
		
		for (int i = 0; i < DICE; i++) {
			dice[i] = scan.nextInt();
		}
		
		for (int i = 0; i < DICE; i++) {
			dice2[i] = scan.nextInt();
		}
		dice22 = dice2;
		
		for (int i = 0; i < DICE; i++) {
			dice2 = dice22;
			if (dice[1] == dice2[i]) {
				switch (i) {
				case 0:
					dice2 = Move("S", dice2);
					break;
				case 2:
					dice2 = Move("EN", dice2);
					break;
				case 3:
					dice2 = Move("ES", dice2);
					break;
				case 4:
					dice2 = Move("NN", dice2);
					break;
				case 5:
					dice2 = Move("N", dice2);
					break;
				default:
					break;
				}
			}
			
			perfect = Judge(dice, dice2);
			
			if (perfect == true) break;
		}
		scan.close();
		
		if (perfect == true) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
	
	public static int [] Move ( String direction, int str[]) {
		String dir = direction;
		int pro_dice[] = new int[6];
		
		for (int i = 0; i < dir.length(); i++) {
			switch(dir.charAt(i)) {
			case 'N':
				pro_dice[0] = str[1];
				pro_dice[1] = str[5];
				pro_dice[2] = str[2];
				pro_dice[3] = str[3];
				pro_dice[4] = str[0];
				pro_dice[5] = str[4];
				break;
			case 'E':
				pro_dice[0] = str[3];
				pro_dice[1] = str[1];
				pro_dice[2] = str[0];
				pro_dice[3] = str[5];
				pro_dice[4] = str[4];
				pro_dice[5] = str[2];
				break;
			case 'S':
				pro_dice[0] = str[4];
				pro_dice[1] = str[0];
				pro_dice[2] = str[2];
				pro_dice[3] = str[3];
				pro_dice[4] = str[5];
				pro_dice[5] = str[1];
				break;
			case 'W':
				pro_dice[0] = str[2];
				pro_dice[1] = str[1];
				pro_dice[2] = str[5];
				pro_dice[3] = str[0];
				pro_dice[4] = str[4];
				pro_dice[5] = str[3];
				break;
			default:
				break;
			}
			
			for ( int j = 0; j < 6; j++) {
				str[j] = pro_dice[j];
			}
		
		}
		
		return str;
	}
	
	public static boolean Judge (int str1[], int str2[]) {
		boolean judge = true;
		
		for (int i = 0; i < 4; i++) {
			judge = true;
			for (int j = 0; j < 6; j++) {
				if (str1[j] != str2[j]) {
					judge = false;
				}
			}
			if (judge == true) break;
			str2 = Move("E",str2);
		}
		
		return judge;
	}
}


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

using namespace std;
typedef long long ll;

int main()
{
    int n, k;
    cin >> n >> k;
    int a[n];

    ll s = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a,a+n);

    for (int i = 0; i < k; i++)
        s+=a[i];

    cout << s;

    return 0;
}


Measured memory_bytes: 3600
s = input()
t = input()
 
ans = 0
 
for i in range(len(s) - len(t) + 1):
  cnt = 0
  for j in range(len(t)):
    if s[i+j] == t[j]:
      cnt += 1
  ans = max(cnt, ans)
  
print(len(t)-ans)

Measured memory_bytes: 9028
//
//	Created by shamim_nik
//

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,
		tree_order_statistics_node_update> indexed_set;

#define br printf("\n")
#define pi acos(-1)

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

//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int t;
	cin >> t;
	map<string, int> doc;
	while(t--) {
		string str;
		 cin >> str;
		 doc[str]++;
	 }
	 cout << doc.size() << endl;
	return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> ans(n - 1);
  std::cin >> ans;

  int64_t s = ans[0];
  for (int64_t i = 1; i < n - 1; i++) {
    s += std::min(ans[i - 1], ans[i]);
  }
  s += ans.back();

  std::cout << s << std::endl;
  return 0;
}

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

int flag=0;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  int ans=abs(A.at(0)-A.at(N-1));
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>
#include <numeric>
#include <iomanip>
 
using namespace std;
 
#define int long long
 
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define rrep(i, n) for (int i=(int)n-1;i>=0;--i)
#define rrep1(i, n) for (int i=n;i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define rrange(i, l, r) for (int i=(int)r-1;i>=(int)l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back
 
using vi=vector<int>;
using pii=pair<int, int>;
 
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}
constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}
 
int f(int a, int b)
{
	return a / b;
}
 
signed main()
{
	int A, B, N; cin >> A >> B >> N;
	int m = min(B - 1, N);
 
	cout << A * m / B - A * (m / B) << endl;
}


Measured memory_bytes: 3568
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    double r; cin >> r;
    printf("%.16lf\n", r * 2.0 * 3.1415926535898);
    return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
const int N = 3e5 + 5;

int a, b, c;

int main() {
	cin>>a>>b>>c;
	cout<<(a + b - 1)/b*c<<endl;
}

Measured memory_bytes: 3616
#include <stdio.h>
 
int main(){
    int x, n;
    scanf("%d%d", &x, &n);
    int p[102] = {0};
    int i = 0, j;
    for(i = 0; i < n; i++){
        scanf("%d", &j);
        p[j]++;
    }
    for(i = 0; i <= n; i++){
        if(p[x - i] == 0 && x - i >= 0){
           
            printf("%d\n", x - i);
            return 0;
            
        }
        if(p[x + i] == 0 && x + i <= 101){
            
            printf("%d\n", x + i);
            return 0;
            
        }
    }
    printf("%d\n", x);
    return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    int t;
    cin >> t;
    set<string> st;
    w(t){
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << sz(st) << '\n';
    //cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}   

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

int n, m, q;
int a[55], b[55], c[55], d[55];
int A[15];
int ans = 0;

void dfs(int len, int num) {
  if (len == n) {
    int total = 0;
    for (int i = 0; i < q; i++) {
      if (A[b[i]] - A[a[i]] == c[i]) {
        total += d[i];
      }
    }
    ans = max(ans, total);
  } else {
    A[len + 1] = num;
    for (int i = num; i <= m; i++) dfs(len + 1, i);
  }
}

int main() {
  cin >> n >> m >> q;
  for (int i = 0; i < q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
  dfs(0, 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
pair<int, int> a[234567];
int n;
signed main() {
	cin >> n; for (int i = 0; i < n; i++)cin >> a[i].second >> a[i].first; sort(a, a + n);
	int s = 0;
	for (int i = 0; i < n; i++) {
		s += a[i].second;
		if (s > a[i].first) { cout << "No\n"; return 0; }
	}
	cout << "Yes\n";
	cin >> n;
}

Measured memory_bytes: 3328
N = int(input())
A = list(map(int,input().split()))
cnt2 = 0
cnt4 = 0
for a in A:
    if a % 4 == 0:
        cnt4 += 1
    elif a % 2 == 0:
        cnt2 += 1
N -= max(cnt2 - 1 , 0)
print("Yes" if N // 2 <= cnt4 else "No")

Measured memory_bytes: 14252
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, x;
  std::cin >> N >> x;
  std::vector< ll > va(N+2, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i+1];
  }

  ll ans = 0LL;
  for (ll i = 1; i <= N; i++) {
    if (va[i-1] + va[i] > x && va[i] + va[i+1] > x) {
      ll cnt = minimum(va[i-1] + va[i] - x, va[i] + va[i+1] - x, va[i]);
      va[i] -= cnt;
      ans += cnt;
    }
  }

  for (ll i = 1; i <= N; i++) {
    if (va[i-1] + va[i] > x || va[i] + va[i+1] > x) {
      ll cnt = std::min(std::max(va[i-1] + va[i] - x, va[i] + va[i+1] - x), va[i]);
      va[i] -= cnt;
      ans += cnt;
    }
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
vector<int> v(n);
for(int i=0;i<n;i++)
    cin>>v[i];
int dp[k+1][n];
int mn=*min_element(v.begin(),v.end());
for(int i=0;i<mn;i++)
{
    for(int j=0;j<n;j++)
    {
        dp[i][j]=0;
    }
}
for(int i=mn;i<=k;i++)
{
    for(int j=0;j<n;j++)
    {
        if(i>=v[j])
        {
            int k;
        for(k=0;k<n;k++)
        {
            if(dp[i-v[j]][k]==1)
                break;
        }
        if(k==n)
            dp[i][j]=1;
        else
            dp[i][j]=0;
        }
        else
            dp[i][j]=0;
    }
}
int i;
for(i=0;i<n;i++)
{
    if(dp[k][i]==1)
        break;
}
    if(i==n)
        cout<<"Second"<<endl;
    else
        cout<<"First"<<endl;
    return 0;
}



Measured memory_bytes: 39296
n,k = gets.split.map(&:to_i)
h = []
n.times do
  h << gets.to_i
end
 
h.sort!
ans = h.max-h.min
(0..n-k).each do |i|
  ans = [ans,h[i+k-1]-h[i]].min
end
puts ans

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

int main(){
  long long x,y;
  cin >> x >> y;
  int cnt=2;
  long long  kari=0;
  long long tmp=x;
  if(x!=y){
    for(long long i=0;true;i++){
      kari=cnt*tmp;
      if(kari>=100000000000000){
        puts("-1\n");
        break;
      }
      if(kari%y!=0){
        cout << kari << endl;
        break;
      }
      cnt++;
    }
  }
  else if(x==y) puts("-1\n");
  return 0;
}

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

using namespace std ;

#define ll long long

map<pair<int,int>,int>mp;

int h , w , n , cnt[ 10 ] ;

int main(){
	scanf( "%d%d%d" , &h , &w , &n ) ;
	while( n -- ) {
		int x , y ;
		scanf( "%d%d" , &x , &y ) ;
		for( int i = max( 1 , x - 2 ) ; i <= min( h - 2 , x ) ; i ++ ) {
			for( int j = max( 1 , y - 2 ) ; j <= min( w - 2 , y ) ; j ++ ) {
				mp[ pair<int,int>(i,j) ] ++ ;
			}
		}
	}
	map< pair<int,int> , int > :: iterator iter ;
	iter = mp.begin() ;
	while( iter != mp.end() ) {
		cnt[ iter -> second ] ++ ;
		iter ++ ; 
		n ++ ;
	}
	ll ans = 1ll * ( h - 2 ) * ( w - 2 ) ;
	printf( "%lld\n" , ans - n - 1 ) ;
	for( int i = 1 ; i <= 9 ; i ++ ) {
		printf( "%d\n" , cnt[ i ] ) ;
	}
	return 0 ;
}

Measured memory_bytes: 56448
#include<stdio.h>
#include<string.h>
int main(void){
    char s[105],p[105],temp[210];
 
    scanf("%s",s);
    scanf("%s",p);
 
    strcpy(temp,s);
    strcat(temp,s);
 
    if(strstr(temp,p)!=NULL){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
 
    return 0;
}


Measured memory_bytes: 2148
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here

        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        String t = sc.next();

        int[][] dp = new int[s.length() + 1][t.length() + 1];
        for (int i = 0; i < s.length(); i++) {
            for (int j = 0; j < t.length(); j++) {
                if (s.charAt(i) == t.charAt(j)) {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                } else {
                    dp[i + 1][j + 1] = Math.max(dp[i][j + 1], dp[i + 1][j]);
                }
            }
        }

        int sI = s.length();
        int tI = t.length();

        StringBuilder builder = new StringBuilder(dp[sI][tI]);

        while (dp[sI][tI] > 0) {
            if (dp[sI][tI] == dp[sI - 1][tI]) {
                sI--;
            } else if (dp[sI][tI] == dp[sI][tI - 1]) {
                tI--;
            } else {
                builder.insert(0, t.charAt(tI - 1));
                tI--;
                sI--;
            }
        }

        System.out.println(builder);
    }
}

Measured memory_bytes: 81100
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
using namespace std;
typedef long long ll;
int n, a[200010], b[200010];
int main() {
	scanf("%d",&n);
	int i,j;
	for(i=1;i<=n;i++) scanf("%d",a+i);
	for(i=n;i>=1;i--) {
		int cnt=0;
		for(j=i+i;j<=n;j+=i)cnt+=b[j];
		b[i]=a[i]^(cnt%2);
	}
	vector<int> lst;
	for(int i=1; i<=n; i++)if(b[i])lst.push_back(i);
	printf("%d\n",lst.size());
for(auto& it:lst) printf("%d ", it);
	return 0;
}

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vl v(n);
	REP(i, n)cin >> v[i];
	ll sum = 0;
	ll ans = 0, cmin = INF*INF;
	if (v[0] <= 0) {
		sum = 1;
		ans += abs(1 - v[0]);
	}
	else sum = v[0];
	REP(i, n - 1) {

		if (i % 2 == 0 ){
			if (v[i + 1] >= -sum) {
				ans += abs(-1 - sum - v[i + 1]);
				sum = -1;
			}
			else {
				sum = sum + v[i + 1];
			}
		}
		else {
			if (v[i + 1] <= -sum) {
				ans += abs(1 - sum - v[i + 1]);
				sum = 1;
			}
			else {
				sum = sum + v[i + 1];
			}
		}
	}
	cmin = min(cmin, ans);
	ans = 0; sum = 0;
	if (v[0] >= 0) {
		sum = -1;
		ans += abs(-1 - v[0]);
	}
	else sum = v[0];
	REP(i, n - 1) {

		if (i % 2 == 1) {
			if (v[i + 1] >= -sum) {
				ans += abs(-1 - sum - v[i + 1]);
				sum = -1;
			}
			else {
				sum = sum + v[i + 1];
			}
		}
		else {
			if (v[i + 1] <= -sum) {
				ans += abs(1 - sum - v[i + 1]);
				sum = 1;
			}
			else {
				sum = sum + v[i + 1];
			}
		}
	}
	cmin = min(ans, cmin);
	cout << cmin << endl;
	return 0;
}


Measured memory_bytes: 1024
// #include <bits/stdc++.h>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
// #include <deque>
// #include <queue>
// #include <array>
// #include <ctime>
// #include <list>
#include <map>
#include <set>
// #include <complex>
// #include <cassert>
// #include <sstream>
// #include <forward_list>
// #include <unordered_set>
// #include <unordered_map> 
// #include <ctime>
 
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace __gnu_pbds;  

// Declaring ordered_set 
typedef tree<int, 
    null_type, 
    less<int>, 
    rb_tree_tag, 
    tree_order_statistics_node_update>  
    ordered_set;  
 
#define int long long
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define scani(n) scanf("%d",&n);
#define EPS 1e-9
#define arrinput for(int i=0; i<n; i++) cin>>arr[i];
#define sumarr for(int i=0; i<n; i++) sum+=arr[i];
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,n) for(int i=n-1; i>=0; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
 
typedef long long ll;  
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
 
const int MOD = 1e9+7;
const int n_ = 1e5+1000;
const long double PI = acos(-1.0);
 
ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, k;
	cin>>n>>k;
	vi v(n), dp(n, 0);
	for0(i,n) cin>>v[i];
	for(int i = 1; i < n; i++) {
		dp[i] = MOD;
		for(int j = 1; j <= min(i,k); j++) {
			dp[i] = min(dp[i], dp[i-j] + abs(v[i] - v[i-j]));
		}
		// dp[i] = min(dp[i-1] + abs(v[i] - v[i-1]), dp[i-2] + abs(v[i] - v[i-2]));
	}
	cout<<dp[n-1];

	return 0;
}

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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int main(){
	int a,b,p,q,r;cin>>a>>b>>p>>q>>r;
	int x=p*b-q*(b-a);
	printf("%.12lf\n",b+x/(double)(q+r));
}


Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

ll gcd(ll n, ll m){
    ll maxn = max(n,m);
    ll minn = min(n,m);
    ll r = 1;
    while(r!=0){
      r = maxn % minn;
      maxn = minn;
      minn = r;
    }
    return maxn;
}
int main(int argc, char const *argv[]) {
  ll N, M;
  std::cin >> N >> M;
  string S, T;
  std::cin >> S;
  std::cin >> T;
  ll lcm = (N * M)/gcd(N, M);
  int s=0, t=0;
  bool flag = 1;
  while(true){
    if(s>=N||t>=M) break;
    if(S[s] != T[t]) flag = false;
    s+=lcm/M;
    t+=lcm/N;
  }
  if(flag) std::cout << lcm << '\n';
  else std::cout << -1 << '\n';
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll n,a,b,c,d;
map<ll,ll> dp;
ll ans(ll x){
    if(x==0) return 0;
    if(dp[x]) return dp[x];
    ll res=1e18;
    res=min(res,ans(x/5)+c+x%5*d);
    if(x>1) res=min(res,ans(x/5+1)+c+(5-x%5)*d);
    res=min(res,ans(x/3)+b+x%3*d);
    if(x>1) res=min(res,ans(x/3+1)+b+(3-x%3)*d);
    res=min(res,ans(x/2)+a+x%2*d);
    if(x>2) res=min(res,ans(x/2+1)+a+(2-x%2)*d);
    if(log10(d)+log10(x)<18) res=min(res,d*x);
    return dp[x]=res;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    rep(test,t){
        dp.clear();
        cin>>n>>a>>b>>c>>d;
        cout<<ans(n)<<"\n";
    }
}

Measured memory_bytes: 5064
n = int(input())
s = []
t = []
for i in range(n):
    S,T = map(str,input().split())
    s.append(S)
    t.append(int(T))
x = str(input())
Sum = 0
for i in range(n):
    if s[i] == x:
        ind = i
for i in range(ind+1,n):
    Sum += t[i]
print(Sum)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
  
using namespace std;

int main()
{
	int n, m;
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		bool isinfected[20000];
		for(int i = 0; i < n; i++){
			if(i == 0) isinfected[i] = true;
			else isinfected[i] = false;
		}
		vector<pair<int, pair<int, int> > > records(20000);
		int t, s, d;
		for(int i = 0; i < m; i++){
			cin >> t >> s >> d;
			records[i].first = t;
			(records[i].second).first = s;
			(records[i].second).second = d;
		}
		sort(records.begin(), records.begin() + m);
		int ans = 1;
		for(int i = 0; i < m; i++){
			int sender = (records[i].second).first - 1;
			int receiver = (records[i].second).second - 1;
			if(isinfected[sender] && !isinfected[receiver]){
				isinfected[receiver] = true;
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1452
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
struct edge { int to, cap, rev; };//ikisaki youryou gyakuhen
#define MAX 1010
vector<vector<edge> >G(MAX);//[MAX];
vector<bool>used(MAX);//[MAX];
void add_edge(int from, int to, int cap){
	edge q={to,cap,int(G[to].size())};
    G[from].push_back(q);
	q={from,0,int(G[from].size()-1)};
    G[to].push_back(q);
}

int dfs(int v, int t, int f) {
    if(v == t) return f;
    used[v] = 1;
    for(int i = 0 ; i < G[v].size(); i++){
        edge &e = G[v][i];
        if(used[e.to] || e.cap <= 0) continue;
        int d = dfs(e.to, t, min(f, e.cap));
        if(d > 0){
            e.cap -= d;
            G[e.to][e.rev].cap += d;
            return d;
        }
    }
    return 0;
}
int ford_fulkerson(int s, int t) {//from s to t
    int flow = 0, f;
    while(1){
		used=vector<bool>(MAX,false);
        f = dfs(s, t, inf);
        if(f == 0) return flow;
        flow += f;
    }
}
int gcd(int a,int b){
	if(a<b)swap(a,b);
	if(b==0)return a;
	return gcd(b,a%b);
}
int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vi a(n);
		vi b(m);
		rep(i,MAX)G[i].clear();
		used=vector<bool>(MAX,false);
		rep(i,n)cin>>a[i];
		rep(i,m)cin>>b[i];
		int s=n+m;int t=s+1;
		rep(i,n)rep(j,m)if(gcd(a[i],b[j])!=1)add_edge(i,n+j,1);
		rep(i,n)add_edge(s,i,1);
		rep(i,m)add_edge(n+i,t,1);
		cout<<ford_fulkerson(s,t)<<endl;
	}
}

Measured memory_bytes: 7676
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
    
    
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Data[] AX = new Data[n];
		HashMap<String,Integer> map = new HashMap<String,Integer>();
		for(int i = 0; i < n; i++) {
			AX[i] = new Data(sc.next(),sc.nextInt());
			map.put(AX[i].name, i);
		}
		int m = sc.nextInt();
		for(int i = 0; i < m; i++) {
			String s = sc.next();
			String t = sc.next();
			int idA = map.get(s).intValue();
			int idB = map.get(t).intValue();
			
			if(AX[idA].x < AX[idB].x) {
				dfs(AX[idB],AX[idA].x,AX[idA].c);
			}
			else if(AX[idA].x > AX[idB].x) {
				dfs(AX[idA],AX[idB].x,AX[idB].c);
			}
			else if(AX[idA].c == AX[idB].c) continue;
			else 
			dfs(AX[idA],AX[idB].x,AX[idB].c);
			
			AX[idA].ar.add(AX[idB]);
			AX[idB].ar.add(AX[idA]);
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			count += AX[i].x;
		}
		System.out.println(count);
		
	}
	static void dfs(Data a, int B, int C) {
		if(a.x == B && a.c == C) return;
		a.x = B;
		a.c = C;
		for(int i = 0; i < a.ar.size(); i++) {
			dfs(a.ar.get(i),B,C);
		}
	}
	
	static class Data {
		static int C = 0;
		
		String name;
		int    x;
		int    c;
		ArrayList<Data> ar = new ArrayList<Data>();
		Data(String a, int b) {
			name = a;
			x = b;
			c = C++;
		}
	}
}

Measured memory_bytes: 44328
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x)-'0')
//#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

const int MAX = 1e3;
int n, m, x, y, x1, y1, x2, y2;
vvi dp(MAX, vi(MAX, INF));
string v[MAX];
priority_queue<iii, vector<iii>, greater<iii>> Q;

int main() {
	fastio;
	cin >> n >> m >> x1 >> y1 >> x2 >> y2;
	x1--; y1--; x2--; y2--;
	FOR(i, n) cin >> v[i];
	dp[x1][y1] = 0;
	Q.push(mp(0, mp(x1, y1)));
	while (!Q.empty()) {
		auto t = Q.top(); Q.pop();
		x = t.se.fi, y = t.se.se;
		FOR(i, 4) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (0 <= nx && nx < n && 0 <= ny && ny < m && v[nx][ny] == '.' && dp[nx][ny] > dp[x][y]) {
				dp[nx][ny] = dp[x][y];
				Q.push(mp(dp[x][y], mp(nx, ny)));
			}
		}
		for (int i = -2; i <= 2; i++) for (int j = -2; j <= 2; j++) {
			int nx = x + i;
			int ny = y + j;
			if (0 <= nx && nx < n && 0 <= ny && ny < m && v[nx][ny] == '.' && dp[nx][ny] > dp[x][y] + 1) {
				dp[nx][ny] = dp[x][y] + 1;
				Q.push(mp(dp[nx][ny], mp(nx, ny)));
			}
		}
	}
	cout << (dp[x2][y2] == INF ? -1 : dp[x2][y2]);
}

Measured memory_bytes: 8780
main :: IO ()
main = do
    [n,yen] <- readInts
    putStrLn $ solve n yen

readInts :: IO [Int]
readInts = map read . words <$> getLine

solve :: Int -> Int -> String
solve n = format . find n

format :: (Int,Int,Int) -> String
format = unwords . map show . toList
  where
    toList (x,y,z) = [x,y,z]

find :: Int -> Int -> (Int,Int,Int)
find n yen
  | null xyzs = (-1,-1,-1)
  | otherwise = head xyzs
  where
    xyzs = numBills n yen

numBills :: Int -> Int -> [(Int,Int,Int)]
numBills n yen = [(x,y,z) | x <- [0..n]
                          , y <- [0..n-x]
                          , let z = n-x-y
                          , amount x y z == yen]

amount :: Int -> Int -> Int -> Int
amount x y z = 10000 * x + 5000 * y + 1000 * z


Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;string S[999],a;int P,M[999],O[999],c,C,n,m,i;main(){cin>>n>>m;for(i=0;i<n;i++){cin>>S[i]>>O[i];}for(i=0;i<n;i++){P=0;while(P!=S[i].size()){cout<<"? "<<S[i]<<endl;cin>>a;C++;if(tolower(a[0])==tolower(S[i][P])){ S[i][P]='_';P++;c++; }else{M[i]++;if(M[i]>O[i]){m--;break;}}}if(m<=0){ cout<<"! Game Over"<<endl;return 0; }}cout<<fixed<<setprecision(1)<<"! Game Clear "<<(double)((int)(1000*c/C)/10.0)<<endl;}

Measured memory_bytes: 3364
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n; 
    vector<int> list(4);
    for (int i = 0; i < n; i++ ){
        cin >> s;
        if (s == "AC"){
            list.at(0)++;
        }
        if (s == "WA"){
            list.at(1)++;
        }
        if (s == "TLE"){
            list.at(2)++;
        }
        if (s == "RE"){
            list.at(3)++;
        }
    }
    cout << "AC x " << list.at(0) << endl;
    cout << "WA x " << list.at(1) << endl;
    cout << "TLE x " << list.at(2) << endl;
    cout << "RE x " << list.at(3) << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fo(i,n) for(ll i=0;i<n;i++)
#define fok(i,k,n) for(ll i=k;i<n;i++)
#define ci(x) cin>>x
#define ci2(x,y) cin>>x>>y
#define co(x) cout<<x<<"\n"
#define co2(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define deb1(x) cout<<#x<<" "<<x<<endl
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n"
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;	


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	string s;
	ci2(n,s);
	vi h[2];
	unordered_map<int ,bool> B;
	fo(i,n){
		if(s[i]=='R'){
			h[0].pb(i);
		}
		else if(s[i]=='G'){
			h[1].pb(i);
		}
		else{
			B[i]=true;
		}
	}
	int m =B.size();
	ll cnt=(h[0].size())*(h[1].size())*m;
	for(auto r: h[0]){
		for(auto g: h[1]){
			if((r+g)%2==0 && B[(r+g)/2]){
				cnt--;
			}
			int diff= abs(r-g);
			if(B[r+diff] == true){
				cnt--;
			}
			if(B[r-diff]==true){
				cnt--;
			}
			if(B[g+diff] == true){
				cnt--;
			}
			if(B[g-diff]==true){
				cnt--;
			}
		}
	}
	co(cnt);
}


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

using namespace std;

int main(){
  int N;
  cin >> N;
  int a[N],ans=0;
  for(int i = 0; i<N;++i){
  	cin >> a[i];
    while(a[i] % 2 == 0){
      a[i] /= 2;
      ++ans;
  	}
  }
  cout << ans << endl;
  return 0;
}
  
  
  


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	int x, n;
	cin >> x >> n;
	int p[110];
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int ans;
	int mi = 1000000007;
	for (int i = 0; i <= 110; i++) {
		bool b = true;
		for (int j = 0; j < n; j++) {
			if (i == p[j]) {
				b = false;
			}
		}
		if (b == true) {
			if (mi > abs(x - i)) {
				mi = abs(x - i);
				ans = i;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define las(v) v[v.size()-1]
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;

ll N,Q;
string s;
ll A[200000];
ll imos[200000];
ll ans = 0;
int main()
{
  cin>>N;
  cin>>s;
  rep(i, N){
    if(s[i]=='.') A[i] = 0;
    else A[i] = 1;
  }
  rep(i, N-1){
    A[i+1] += A[i];
  }
  ans = N - A[N-1];
  rep(i, N){ // iまでしろ
    ans = min(ans, A[i] + (N - 1 - i - (A[N-1] - A[i]) ));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2180
s = list(input())
k = int(input())
ans = 0
count = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        count += 1
    else:
        ans += count//2
        count = 1
ans += count//2
if len(set(s)) == 1:
    print(len(s)*k//2)
    exit()
if s[0] != s[-1]:
    ans *= k
else:
    left = 0
    right = 0
    index = 0
    while index < len(s) and s[0] == s[index]:
        left += 1
        index += 1
    index = len(s)-1
    while index >= 0 and s[-1] == s[index]:
        right += 1
        index -= 1
    ans *= k
    ans -= ((right//2) + (left//2) - (right + left)//2) * (k-1)
print(ans)

Measured memory_bytes: 38384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using namespace std;
int N;
int a[100001];
long long int sum[100001];
int ans=1;
int main(){
  cin >> N;
  for(int i=0;i<N;i++)cin  >> a[i];
  sort(a,a+N);
  sum[0]=a[0];
  for(int i=1;i<N;i++)sum[i]=sum[i-1]+a[i];
  
  for(int i=N-1;i>0;i--){
    if(a[i]<=2*sum[i-1])ans++;
    else break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long
#define mk make_pair
using namespace std;
const int inf = 1e9;
const int N = 5e5 + 5;
char s[N];
int n, cnt, dp[N], pre[N];
int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; i++) dp[i] = inf;
	for (int i = 1, p = 0; i <= n; i++) {
		if (s[i] == '1') cnt++;
		if (s[i] == '0') p = i;
		pre[i] = p;
	}
	for (int i = 1; i <= n; i++) {
		if (s[i] == '0') dp[i] = dp[i - 1];
		if (s[i] == '1') {
			dp[i] = dp[i - 1] + 1;
			if (s[i - 1] == '0' && i > 1) {
				dp[i] = min(dp[i], dp[pre[i - 2]] + 1);
				dp[i] = min(dp[i], dp[pre[i - 2] + 1] + 1);
			}
			if (pre[i] && s[pre[i] - 1] == '1')
				dp[i] = min(dp[i], dp[pre[i] - 2] + 1);
		}
	}
	cout << cnt - dp[n];
}

Measured memory_bytes: 4608
import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.util.Scanner;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		double x1, x2, y1, y2;
		double distance;
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		x1 = Double.parseDouble(str.split(" ")[0]);
		y1 = Double.parseDouble(str.split(" ")[1]);
		x2 = Double.parseDouble(str.split(" ")[2]);
		y2 = Double.parseDouble(str.split(" ")[3]);
		// System.out.println((y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2));
		System.out.println( Math.sqrt((y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2)));
	}
}



Measured memory_bytes: 26368
import sys
input = sys.stdin.readline


def isOk(n, D):
    while n > 0:
        if n % 10 in D:
            return False
        n //= 10
    return True


def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    ans = 0
    for i in range(N, 10**5):
        if isOk(i, D):
            print(i)
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#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 > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  ll v[4];
  ll n;
  cin>>v[0]>>v[1]>>v[2]>>v[3]>>n;
  v[0] *= 8;
  v[1] *= 4;
  v[2] *= 2;
  ll mi = v[0];
  ll md = 0;
  rep(i,4) {
    if(mi > v[i]) {
      mi = v[i];
      md = i;
    }
  }
  ll ans = 0;
  if(md == 3 && n % 2 == 1) {
    mi = v[0];
    md = 0;
    rep(i,3) {
      if(mi > v[i]) {
        mi = v[i];
        md = i;
      }
    }
    ans = n / 2 * v[3] + (mi / 2);
  } else {
    if(md != 3) {
      ans = n * (mi / 2);
    } else {
      ans = n / 2 * mi;
    }
  }
  cout << ans << endl;


  return 0;

}


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

const int Mod = 1e9 + 7;
const int N = 9e5 + 10;

int n, m, k;
long long fac[N], vfac[N];

long long mpow( long long a, int b ) {
	long long rt;
	for( rt = 1; b; b >>= 1, a = (a * a) % Mod )
		if( b & 1 ) rt = (rt * a) % Mod;
	return rt;
}
void init( int n ) {
	fac[0] = 1;
	for( int i = 1; i <= n; i++ )
		fac[i] = (fac[i-1] * i) % Mod;
	vfac[n]  = mpow( fac[n], Mod - 2 );
	for( int i = n - 1; i >= 0; i-- )
		vfac[i] = vfac[i+1] * (i + 1) % Mod;
}
long long comb( int n, int m ) {
	return fac[n] * vfac[n-m] % Mod * vfac[m] % Mod;
}
int main() {
	scanf( "%d%d%d", &n, &m, &k );
	if( m < k ) swap( m, k );
	init( m + k + n );
	long long sum = 0, ans = 0;
	for( int s = 0; s <= m + k; s++ ) {
		if( s == 0 ) 
			sum = 1;
		 else if( s <= k ) 
			sum = (sum<<1) % Mod;
	 else if( s <= m ) 
			sum = ((sum<<1) + Mod - comb(s-1,s-k-1)) % Mod;
		 else 
			sum = ((sum<<1) + Mod - comb(s-1,s-k-1) + Mod - comb(s-1,m)) % Mod;
		
		long long sub = sum * comb(n-1+s,n-1) % Mod * mpow(3,m+k-s) % Mod;
		ans = (ans + sub) % Mod;
	}
	printf( "%lld\n", ans );
}



Measured memory_bytes: 14336
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#include "bits/stdc++.h"
using namespace std;
using   ll       =    long long;
using   ld       =    long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);

typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = (int)1e6+1;
const int MOD =(ll)1e9+1147483647;
const ll INF = (ll)1e18+5;

int main()
{
    _SAD()
    int n;
    cin>>n;
    vii a(10010,0);
    for(int i=1;i<=100;i++)
    {
        for(int j=1;j<=100;j++)
        {
            for(int k=1;k<=100;k++)
            {
                ll gu=i*i+j*j+k*k+i*j+i*k+j*k;
                if(gu<=10000)
                {
                    a[gu-1]++;
                }
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        cout<<a[i]<<nl;
    }
    return 0;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define for(i,a,b) for(int i=a;i<b;i++)
#define all(a) a.begin(),a.end()
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//sort 降順
//reverse 逆順
 
int main() {
  string a;
  ci(a);
  vector<char> b(a.size());
  for(i,0,a.size())
    b[i]=a[i];
  sort(all(b));
  ll x=1;
  string d="Yes";
  if(a.size()==1)
    d="No";
  for(i,1,a.size()){
    if(b[i-1]==b[i])
      x++;
    else{
      if(x%2==0)
        x=1;
      else{
        d="No";
        break;
      }
    }
  }
  co(d);
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <cstring>
#include <cstdio>

using namespace std;

int main( void )
{
	int no, A, B, O, AB;
	char type[3];

	A = B = O = AB = 0;

	while (~scanf("%d,%s", &no, type))
	{
		if (!strcmp(type, "A"))
			++A;
		else if (!strcmp(type, "B"))
			++B;
		else if (!strcmp(type, "O"))
			++O;
		else
			++AB;
	}

	cout << A << endl
		 << B << endl
		 << AB << endl
		 << O << endl;

	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

struct COM {
    vector<ll> inv, fac, finv;
    COM(int N) : inv(N), fac(N), finv(N) {
        inv[1] = 1;
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        for (int i = 2; i < N; ++i) {
            inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
            fac[i] = fac[i - 1] * i % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    ll calc(int a, int b) {
        return (fac[a] * finv[b]) % MOD * finv[a - b] % MOD;
    }
};

ll modpow(ll a, int n) {
    ll res = 1;
    while (n) {
        if (n & 1)
            (res *= a) %= MOD;
        n >>= 1;
        (a *= a) %= MOD;
    }
    return res;
}

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

    int K;
    string S;
    cin >> K >> S;
    int N = S.length();

    COM com(N + K + 1);

    ll ans = 0;
    for (int i = 0; i <= K; ++i) {
        ans += com.calc(N + K, N + i) * modpow(25, K - i);
        ans %= MOD;
    }

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


Measured memory_bytes: 51252
#include<stdio.h>
int main(){
    int n, a[105], i;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d", &a[i]);
    }
    for(i=i-1;i>0;i--){
        printf("%d ", a[i]);
    }printf("%d\n", a[0]);
return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int A,B;
  cin >> A >> B;
  if (A < 10 && B < 10) {
    cout << A*B << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
x.sort()

if n>=m:
    print(0)
    import sys
    sys.exit()
l=[]
ans=x[-1]-x[0]
for i in range(m-1):
    l.append(abs(x[i]-x[i+1]))
l.sort()
l.reverse()
for i in range(n-1):
    ans-=l[i]
if ans>=0:
    print(ans)
else:
    print(0)

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

#define REP(i, a, b) for(int i = a; i < b; i++)

const int maxn = 100100;
const long long int inf = 1000000000000000000;

long long int rj = 0;

long long int poz = 0;

long long int suma = 0;

int n, k;

int a[maxn];

int main()
{
    scanf("%d%d", &n, &k);
    REP(i, 0, n) {scanf("%d", &a[i]); if(a[i] > 0) poz += a[i];}
    suma = poz;
    REP(i, 0, k)
    {
        if(a[i] < 0) suma += a[i];
    }
    rj = max(rj, suma);
    REP(i, 0, n - k)
    {
        if(a[i] < 0) suma -= a[i];
        if(a[i + k] < 0) suma += a[i + k];
        rj = max(rj, suma);
    }
    suma = poz;
    REP(i, 0, k)
    {
        if(a[i] > 0) suma -= a[i];
    }
    rj = max(rj, suma);
    REP(i, 0, n - k)
    {
        if(a[i] > 0) suma += a[i];
        if(a[i + k] > 0) suma -= a[i + k];
        rj = max(rj, suma);
    }
    printf("%lld\n", rj);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

struct UnionFind {
    vector<int> d ;
    UnionFind(int n = 0): d(n, -1) {} 
    int find(int x){
        if(d[x] < 0) return x ;
        return d[x] = find(d[x]) ;
    }
    bool unite(int x, int y) {
        x = find(x) ; y = find(y) ;
        if(x == y) return false ;
        if(d[x] > d[y]) swap(x, y) ;
        d[x] += d[y] ;
        d[y] = x ;
        return true ;
    }
    bool same (int x, int y){
        return find(x) == find(y) ;
    }
    int size(int x){return -d[find(x)]; }
};

int d [100005] ;
vector<int> blk [100005] ;

int main(){
    int n, m, k ;
    cin >> n >> m >> k ;
    UnionFind uf(n) ;
    rep(i, m){
        int a, b ;
        cin >> a >> b ;
        a-- ; b-- ;
        d[a]++ ; 
        d[b]++ ;
        uf.unite(a, b) ;
    }
    rep(i, k){
        int c, d ;
        cin >> c >> d ;
        c-- ; d-- ;
        blk[c].push_back(d) ;
        blk[d].push_back(c) ;
    }
    rep(i, n){
        int ans = uf.size(i) - 1 - d[i] ;
        for(int u : blk[i]){
            if(uf.same(i, u)){
                ans-- ;
            }
        }
        cout << ans << " "  ;
    }
    cout << endl ;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int> > V(N);
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		A--, B--;
		V[A].push_back(B);
		V[B].push_back(A);
	}
	queue<int> Q;
	Q.push(0);
	vector<int> ANS(N, -1);
	ANS[0] = 0;
	while (!Q.empty()) {
		int P = Q.front();
		Q.pop();
		for (int NP : V[P]) {
			if (ANS[NP] == -1) {
				ANS[NP] = P;
				Q.push(NP);
			}
		}
	}
	cout << "Yes" << endl;
	for (int i = 1; i < N; i++) cout << ANS[i]  + 1 << endl;
}

Measured memory_bytes: 10228