akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline void goodbye(const T& val) { cout << val << endl; exit(0); }

const int MAXN = 543;

int A[MAXN][MAXN][2];
int P[MAXN][MAXN];
int H, W;

void enable(int i, int j, int t) {
	A[i][j][t] = 1;
}

void solve() {
	cin >> H >> W;

	for(int i = 0; i < H; ++i) {
		string line;
		cin >> line;

		for(int j = 0; j < W; ++j) {
			P[i][j] = (line[j] == '#');
		}
	}

	for(int i = 0; i < H; ++i) {
		for(int j = 0; j < W; ++j) {
			if(i == 0 && j != 0) {
				enable(i, j, 0);
			} else if(i != 0 && j == 0) {
				enable(i, j, 1);
			} else {
				int t = max(i, j) & 1;
				t ^= 1;

				enable(i, j, t);
			}

			if(P[i][j]) {
				enable(i, j, 0);
				enable(i, j, 1);
			}
		}
	}

	for(int t = 0; t < 2; ++t) {
		cout << '\n';

		for(int i = 0; i < H; ++i) {
			for(int j = 0; j < W; ++j) {
				cout << (A[i][j][t] ? '#' : '.');
			}

			cout << '\n';
		}
	}

#ifdef __LOCAL
	for(int i = 0; i < H; ++i) {
		for(int j = 0; j < W; ++j) {
			if(P[i][j] != (A[i][j][0] && A[i][j][1])) {
				cout << "BAD: " << i << ' ' << j << '\n';
			}
		}
	}
#endif
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
#define test ll t;cin >> t; while(t--)
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"

    
int main()
{
   std::ios::sync_with_stdio(false);
   ll n,k;
   cin>>n>>k;
   ll a[n];
   rep(i,n)cin>>a[i];
   ll dp[n+1]={0};
   dp[0]=0;
   dp[1]=abs(a[0]-a[1]);
   f(i,2,n)
   {
       dp[i]=1e10;
       for(ll j=i-1;j>=0;--j)
       {
           if(j<i-k)break;
           dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
       }
   }
   
   
   cout<<dp[n-1];
}







Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.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>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string S;
        cin >> S;
        vector<char> oddlist = {'R', 'U', 'D'};
        vector<char> evenlist = {'L', 'U', 'D'};

        ll N = len(S);
        bool ans = true;
        rep(i, 0, N) {
                if (not isin(S[i], oddlist)) ans = false; 
                ++i;
        }

        rep(i, 1, N) {
                if (not isin(S[i], evenlist)) ans = false; 
                ++i;
        }

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

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const double INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const ll MAX_N = 3010;
double dp[MAX_N][MAX_N];

void init() {
	for (ll i = 0; i < MAX_N; i++) {
		for (ll j = 0; j < MAX_N; j++) {
			dp[i][j] = 0;
		}
	}
}

int main() {
	ll N;
	cin >> N;
	vector<double> P(N);
	for (auto& e : P)cin >> e;
	ll i, j;
	init();

	// dp[i][j]: i+1回目までで表がj回出る確率
	dp[0][0] = 1 - P[0];
	dp[0][1] = P[0];
	for (i = 1; i < N; i++) {
		dp[i][0] = dp[i - 1][0] * (1 - P[i]);
		for (j = 1; j <= N; j++) {
			dp[i][j] = dp[i - 1][j - 1] * P[i] + dp[i - 1][j] * (1 - P[i]);
		}
	}
	double ans = 0;
	for (i = (N + 1) / 2; i <= N; i++) {
		ans += dp[N - 1][i];
	}
	cout << setprecision(10) << ans << endl;

	return 0;
}


Measured memory_bytes: 71168
import java.util.Scanner;

public class Main {
    static final Scanner sc = new Scanner(System.in);
    static final int MOD = (int) 1E9 + 7;
    
    public static void main(String[] args) {
        int N = nint();
        int[] B = nints(N-1, 1, 0);
        B[0] = Integer.MAX_VALUE;
        
        int ans = B[N-1];
        
        for (int i = N-2; i >= 0; i--) {
            if (B[i] > B[i+1]) {
                ans += B[i+1];
            } else {
                ans += B[i];
            }
        }
        System.out.println(ans);
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0);
    }

    private static char[][] nchars2(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}


Measured memory_bytes: 23764
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {
    
    int N,K;
    cin >> N >> K;
    int p[N];
    long long max = 0;
    for(int i=0;i<N;i++){
        cin >> p[i];
        if(i < K) max += p[i];
    }
    int num = 0;
    long long sum = max;
    for(int i=0;i<N-K;i++){
        sum = sum-p[i]+p[i+K];
        if(sum > max){
            max = sum;
            num = i+1;
        }
    }
    double out = 0;
    for(int i=0;i<K;i++) out += (1+(double)p[num+i])/2;
    cout << fixed << setprecision(6) << out << endl;
    return 0;
}


Measured memory_bytes: 1024
import scala.io.StdIn.readInt
import scala.annotation.tailrec

object Main {
  @tailrec def fib(a:Int, b:Int, c:Int, n:Int):Int = {
    n match {
      case 0 => a
      case n => fib(a+b, a, b, n-1)
    }
  }

  def main(args: Array[String]) = {
    val n = readInt()
    println(fib(1, 0, 0, n))
  }
}

Measured memory_bytes: 43644
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;	cin >> n;
  string s;	cin >> s;
  for(int i=0;i<n;i++){
    for(int j=0;j<s.size();j++){
      if(s[j]=='Z')	s[j]='A';
      else	s[j]=(char)(s[j]+1);
    }
  }
  cout << s;
}

Measured memory_bytes: 3612
import java.util.*;

public class Main {
    public static void main(String[] args){
         Scanner sc = new Scanner(System.in);
        int num =sc.nextInt();
        int i =1;
        while(num>0){
            System.out.println("Case " + i +": " + num);
            i++;
            num =sc.nextInt();
        }
        
    }
}


Measured memory_bytes: 42832
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <deque>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_backx
#define mp make_pair
#define pi pair<int,int>
#define pii pair<pi,int>
#define sqr(x) ((x)*(x))
#define FOR for(int int i=0;i<n;i++)for(int j=0;j<m;j++)
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int n,k;
int asd[100100],cnt;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>k;
    if(k==0)return cout<<"0\n",0;
    for(int i=0;i<n;i++)cin>>asd[i];
    cnt=n;
    for(int i=0;i<n;i++)if(asd[i]>=0){cnt=i;break;}
    int ans=1844674407;
    if(n-cnt>=k)ans=min(ans,asd[cnt+k-1]);
    if(cnt>=k)ans=min(ans,-asd[cnt-k]);
    for(int i=max(1,k-(n-cnt));i<=min(k-1,cnt);i++)
        ans=min(ans,-asd[cnt-i]+asd[cnt+k-i-1]+min(-asd[cnt-i],asd[cnt+k-i-1]));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
bool ispal(string a)
{
    long long int n=a.length();
    if(n==1)
        return true;
    else{
    int i=0,j;
    j=n-1;
    while(1)
    {
        if(a[i]!=a[j])
        {
            cout<<i<<" "<<j;
           return false;
        }
        i++,j--;
        if(i==j)
         {
        //     cout<<i<<" ";
             break;
        }
    }
    return true;
}}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  //cin>>t;
  t=1;
  while(t--){
  ll n;
  cin>>n;
  if(n>=30)
  {
      cout<<"Yes";
  }
  else
    cout<<"No";
  }
}

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

class Main {
	static PrintStream out = System.out;
	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		String s = in.nextLine().trim();
		String p = in.nextLine().trim();
		s += s;
		if (s.indexOf(p) < 0) {
			out.println("No");
		} else {
			out.println("Yes");
		}
	}
}

Measured memory_bytes: 17284
#include <cstdio>
#include <functional>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;

int main() {
	// input
	int n; scanf("%d", &n);
	vector<vector<int> > g(n);
	repeat (i, n - 1) {
		int a, b; scanf("%d%d", &a, &b); -- a; -- b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	// solve
	function<int (int, int)> go = [&](int i, int parent) {
		int cnt1 = 0, cnt2 = 0;
		for (int j : g[i]) if (j != parent) {
			int q = go(j, i);
			cnt2 |= cnt1 & q;
			cnt1 |= q;
		}
		int p = 1;
		while (p <= cnt2 or cnt1 & p) p <<= 1;
		return (cnt1 & ~ (p - 1)) | p;
	};
	int p = go(0, -1);
	int k = 31 - __builtin_clz(p);
	// output
	printf("%d\n", k);
	return 0;
}


Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111




	void solve(){


		ini(n);
		ini(k);
		int morty[n];
		FOR(i,0,n)in(morty[i]);
		set<int> set1;
		int j = 1;
		int tmp = 0;
		int pos = -1;
		int tmp1= 0;
		int morty1[n];
		FOR(i,0,n-k+1){
			while(j!=i+k){
				if(morty[j-1]>morty[j])tmp++;
				j++;
			}
			morty1[i] = tmp;
			if(morty[i]>morty[i+1])tmp--;
		}
		j = 0;
		tmp = 0;
		vi morty2(n,0);
		FOR(i,0,n-k){
			while(j!=i+k+1){
				set1.insert(morty[j]);
				j++;
			}
			if(morty[i] == *set1.begin() and morty[j-1] == *prev(set1.end())){
				//out("i",i,"j",j);
				morty2[i+1] = 1;
				//if(pos == -1){
				//	pos = i+k-1;
				//}
				//if(i>pos){}
			}
			set1.erase(morty[i]);
		}
		FOR(i,0,n-k+1){
			if(morty2[i] == 0){
				if(morty1[i])tmp++;
				else tmp1++;
			}
		}
		out(tmp+bool(tmp1));







	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
int main()
{
    ll n,m;cin>>n>>m;vector<vector<char>>grid(n,vector<char>(m));
    vector<vector<ll>>dp(n,vector<ll>(m,0));
    for (int i = 0;i<n;i++)for (int j = 0;j<m;j++)cin>>grid[i][j];
    for (int i = 0;i<n;i++){
        if (grid[i][0]=='#')break;
        dp[i][0] = 1;
    }
    for (int j = 0;j<m;j++){
        if (grid[0][j]=='#')break;
        dp[0][j] = 1;
    }
    for (int i = 1;i<n;i++){
        for (int j = 1;j<m;j++){
            if (grid[i][j]=='#')dp[i][j] = 0;
            else dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD;
        }
    }
    cout<<dp[n-1][m-1]<<endl;
    return 0;
}

Measured memory_bytes: 12140
#!/usr/bin/env python
import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (
    acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians,
    sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


def inlist():
    return(list(map(int, input().split())))


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))

# For getting input from input.txt file
#sys.stdin = open('input.txt', 'r')

# Printing the Output to output.txt file
#sys.stdout = open('output.txt', 'w')


def main():
    t = inp()
    print("Yes" if t >= 30 else "No")


# region fastio
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")

# endregion


if __name__ == "__main__":
    main()


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

int INF = 1e9;
 
int main(void){
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<pair<int, int> > v(n);
    int nowr = 0;
    int noww = 0;
    rep(i, n){
        if(s[i] == 'W') noww++;
        else nowr++;
        v[i] = make_pair(nowr, noww);
    }
    int ans = INF;
    rep(i, n){
        int w = v[i].second;
        int r = v[n-1].first-v[i].first;
        ans = min(max(r, w), ans);
    }
    if(v[n-1].second == n) ans = 0; 
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5244
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007
//#define DEBUG

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine e(seed);
std::mt19937 rng((int) seed);

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    int ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if(i%2 == 0) {
            ans += x & 1;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3648
#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;

ll n;
vector<ll> ans;

void solve(ll x) {
    if (x > n) return;
    ans.push_back(x);
    for (int i = 3; i <= 7; i+=2) solve(10*x+i);
    return;
}

ll judge() {
    ll cnt = 0;
    REP(i,ans.size()) {
        vector<bool> bu(10, false);
        string tmp = to_string(ans[i]);
        REP(j,tmp.size()) bu[tmp[j]-'0'] = true;
        if (bu[3] && bu[5] && bu[7]) cnt++;
    }
    return cnt;
}

int main(int argc, char const *argv[]) {
    cin >> n;
    solve(0);
    cout << judge() << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int n;
ll arr[400100];
int ord[400100];
int rrd[400100];
int col[400100];
ll maxi[400100];

bool cmp(int a, int b) {return arr[a]<arr[b];}

int main() {
    int i;

    scanf("%d",&n);
    for (i=0;i<n;i++) scanf("%lld%lld",&arr[i*2],&arr[i*2+1]);
    for (i=0;i<2*n;i++) ord[i] = i;
    sort(ord,ord+2*n,cmp);
    for (i=0;i<2*n;i++) rrd[ord[i]] = i;
    maxi[0] = 987654321;
    for (i=1;i<2*n;i++) {
        maxi[i] = maxi[i-1];
        if (rrd[ord[i-1]]>rrd[ord[i-1]^1]) continue;
        maxi[i] = min(maxi[i],1LL*rrd[ord[i-1]^1]);
    }
    //for (i=0;i<2*n;i++) printf("%lld ",maxi[i]);
    ll res = 1LL<<60;
    ll mi = rrd[ord[2*n-1]^1];
    for (i=2*n-1;i>0;i--) {
        if (!mi) break;
        if (col[ord[i]]) break;
        res = min(res,((arr[ord[2*n-1]]-arr[ord[0]])*(arr[ord[i-1]]-arr[ord[min(mi,maxi[mi])]])));
        col[ord[i]] = 1;
        col[ord[i]^1] = 2;
        mi = min(mi,1LL*rrd[ord[i-1]^1]);
    }

    for (i=0;i<2*n;i++) col[i] = 0;
    for (i=2*n-1;i>=0;i--) {
        if (col[ord[i]]) continue;
        col[ord[i]] = 1;
        col[ord[i]^1] = 2;
    }

    ll B[2] = {1987654321,0}, R[2] = {1987654321,0};
    for (i=0;i<2*n;i++) {
        if (col[i]==1) {
            B[0] = min(B[0],arr[i]);
            B[1] = max(B[1],arr[i]);
        }
        else {
            R[0] = min(R[0],arr[i]);
            R[1] = max(R[1],arr[i]);
        }
    }
    res = min(res,(B[1]-B[0])*(R[1]-R[0]));
    printf("%lld\n",res);

    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}
const string NO = "Impossible";

const ll N=100005;
ll par[N];

ll find(ll x){
    if(par[x]<0)return x;
    return par[x]=find(par[x]);
}

void unite(ll x,ll y){
    x=find(x),y=find(y);
    if(x==y)return;
    par[x]+=par[y];
    par[y]=x;
}

void solve(){
    ll n,m;cin>>n>>m;
    vl a(n);rep(i,n)cin>>a[i];
    vl x(m),y(m);
    rep(i,m)cin>>x[i]>>y[i];

    memset(par,-1,sizeof(par));
    rep(i,m){
        unite(x[i],y[i]);
    }

    vvl g(n);
    vector<bool> used(n);
    ll cnt=0;
    rep(i,n){
        if(!used[find(i)]){
            cnt++;
            used[find(i)]=1;
        }
        g[find(i)].push_back(a[i]);
    }

    if(cnt==1){
        cout<<0<<endl;
        return;
    }

    ll ans=0;
    vl ot;
    rep(i,n){
        if(!g[i].size())continue;
        sort(all(g[i]));
        ans+=g[i][0];
        fore(j,1,min(cnt-2,(ll)g[i].size()-1)){
            ot.push_back(g[i][j]);
        }
    }

    if((ll)ot.size()<cnt-2){
        cout<<NO<<endl;
        return;
    }

    sort(all(ot));
    rep(i,cnt-2){
        ans+=ot[i];
    }
    cout<<ans<<endl;
}

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


Measured memory_bytes: 7680
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct node{
    int key;
    node* right;
    node* left;
    node* parent;
};

node *root;
node *NIL;

//??????x??\???????°????
node* treeMinimum(node* x){
    while (x->left!=NIL)
        x=x->left;
    return x;
}

node* treeSuccessor(node* x){
    if(x->right!=NIL)
        return treeMinimum(x->right);
    node* y=x->parent;
    while(y!=NIL&&x==y->right){
        x=y;
        y=y->parent;
    }
    return y;
}

void treeDelete(node* z){
    //????????????????±?
    node* y;
    //y????????????
    node* x;

    //????????????????????????
    if(z->left==NIL||z->right==NIL)
        y=z;
    else
        y=treeSuccessor(z);

    //??????y????????????x
    if(y->left!=NIL)
        x=y->left;
    else
        x=y->right;

    if(x!=NIL)
        x->parent=y->parent;
    if(y->parent==NIL)
        root=x;
    else if(y==y->parent->left)
        y->parent->left=x;
    else
        y->parent->right=x;
    if(y!=z)
        z->key=y->key;
    delete y;

}

//?????\
void insert(int k){
    node *y = NIL;
    node *x = root;
    node *z;

    z = new node;
    z->key=k;
    z->left=NIL;
    z->right=NIL;

    while(x!=NIL){
        y=x;
        if(z->key<x->key)
            x=x->left;
        else
            x=x->right;
    }

    z->parent=y;
    if(y==NIL)
        root=z;
    else{
        if(z->key<y->key)
            y->left=z;
        else
            y->right=z;
    }

}

//????´¢
node* find(node* u,int k){
    while(u!=NIL&&k!=u->key){
        if(k<u->key)
            u=u->left;
        else
            u=u->right;
    }
    return u;
}

void inorder(node* u){
    if(u==NIL)
        return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(node* u){
    if(u==NIL)
        return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n,i,x;
    string com;

    scanf("%d",&n);

    for(i=0;i<n;i++){
        cin>>com;
        if(com[0]=='f'){
            scanf("%d",&x);
            node* t=find(root,x);
            if(t!=NIL)
                printf("yes\n");
            else
                printf("no\n");
        }
        else if(com=="insert"){
            scanf("%d",&x);
            insert(x);
        }
        else if(com=="print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if(com=="delete"){
            scanf("%d",&x);
            treeDelete(find(root,x));
        }
    }
}

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

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

Measured memory_bytes: 1024
N, K = map(int, raw_input().split())
DP = [[0] * (K + 1) for i in range(K + 1)]
bias = 0

for i in range(N):
    x, y, c = raw_input().split()
    x, y, c = int(x), int(y), (c == 'W')
    p = (x / K + y / K + c) % 2
    DP[y % K + 1][x % K + 1] += 1 - 2 * p
    bias += p

for i in range(K):
    for j in range(K + 1):
        DP[i + 1][j] += DP[i][j]

for i in range(K + 1):
    for j in range(K):
        DP[i][j + 1] += DP[i][j]

ans = 0

for i in range(K + 1):
    for j in range(K + 1):
        S = DP[i][K] + DP[K][j] - DP[i][j] * 2
        ans = max(ans, S, DP[K][K] - S)

print ans + bias

Measured memory_bytes: 23028
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <utility>
using namespace std;

int main() {
	long long N,M;
	cin>>N>>M;
	long long ans=0;
	if(N*2>M){
		ans=M/2;
	}
	else if(N*2<=M){
		ans=N;
		M-=2*N;
		ans+=M/4;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

int main(){

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

    int swap_count = 0;
    for (int i = 0; i < n; i++) {
        for (int j = n - 1; i < j; j--) {
            if (A[j] < A[j - 1]) {
                int tmp = A[j];
                A[j] = A[j - 1];
                A[j - 1] = tmp;
                swap_count++;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        if (i != n - 1) {
            cout << A[i] << " ";
        } else {
            cout << A[i] << endl;
        }        
    }
    cout << swap_count << endl;

    return 0;
}



Measured memory_bytes: 3104
#include <stdio.h>
void shellSort(int*,int);
void insertionSort(int*,int,int);
int cnt = 0;

int main(){
  int i,A[1000000],n;
    scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  shellSort(A,n);
  for(i = 0; i < n; i++){
    printf("%d\n",A[i]);
  }
  return 0;
}

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

void shellSort(int* A, int n){
  int m=1,i,G[1000000];
  G[0] = 1;
  for(i = 0;;i++){
    G[i+1] = 3*G[i] + 1;
    if(G[i+1] > n) break;
    m++;
  }
  for(i = m-1; i >= 0; i--){
    insertionSort(A,n,G[i]);
  }
  printf("%d\n",m);
  for(i = m-1; i > 0; i--){
    printf("%d ",G[i]);
  }
  printf("%d\n",G[i]);
  printf("%d\n",cnt);
}

Measured memory_bytes: 4512
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define rep1(i, n) for(int i=1;i<=(int)(n);i++)
 
int main() {
  int n, m;
  cin >> n >> m;
  int a[51],b[51],c[51],d[51];
  rep (i,n) {
    cin >> a[i] >> b[i];
  }
  rep1 (i,m) {
    cin >> c[i] >> d[i];
  }
  rep (i,n) {
    int ans = 0;
    int nem = 2*1000000000;
    rep1 (j,m){
      int x = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if(x < nem) {
        nem = x;
        ans = j;
      }
    }
    cout<< ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int R, C, N;

bool judge(int x, int y){
    return (x == 0 || x == R || y == 0 || y == C);
}

int culc_dist(int x, int y){
    if(x == 0) return y;
    if(y == C) return x + C;
    if(x == R) return R + C + (C - y);
    if(y == 0) return R * 2 + C * 2 - x;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> R >> C >> N;
    vector<pii> dat;
    for(int i = 0; i < N; i++){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if(judge(x1, y1) && judge(x2, y2)){
            dat.emplace_back(pii{culc_dist(x1, y1), i});
            dat.emplace_back(pii{culc_dist(x2, y2), i});
        }
    }
    sort(dat.begin(), dat.end());
    stack<int> st;
    st.push(dat[0].second);
    for(int i = 1; i < dat.size(); i++){
        if(st.empty() || st.top() != dat[i].second) st.push(dat[i].second);
        else st.pop();
    }
    cout << (st.empty() ? "YES" : "NO") << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    string S; cin >> S;
    int lenS; lenS = S.length();
    int ans = 0;
    for(int i = 1; i <= S.length(); i++){
        string pr = S.substr(0, i);
        string sf = S.substr(i);
        //cout << pr << " " << sf << endl;
        if(pr.length() >= sf.length()) break;
        bool ok = true;
        rep(j, pr.length()){
            if(pr[j] != sf[j]) ok = false;
        }
        if(ok) ans = i;
    }
    cout << ans*2 << endl;
    return 0;
}

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

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;
using ll=long long;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 998244353;

    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    vector<int> memo1(n+1),memo2(n+1);
    memo1[0]=0;
    memo2[n]=0;
    rep(i,n){
        memo1[i+1]=memo1[i]^a[i];
        memo2[n-i-1]=memo2[n-i]^a[n-i-1];
    }
    rep(i,n){
        cout<<(memo1[i]^memo2[i+1])<<endl;
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  int minus_count = 0;
  priority_queue<ll, vector<ll>, greater<ll>> que;
  ll ans = 0;
  rep(i,n) {
    cin >> a[i];
    if(a[i] < 0) minus_count++;
    que.push(abs(a[i]));
    ans += abs(a[i]);
  }
  if(minus_count % 2 != 0){
    ans -= que.top() * 2;
  }
  cout << ans << endl;
}

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

void solve(int N, vector<int> A, int Q, vector<int> B, vector<int> C)
{
    vector<int64_t> cnt((int)1e5 + 1);
    int64_t res = 0;
    for (int i = 0; i < N; i++)
    {
        cnt.at(A.at(i))++;
        res += A.at(i);
    }
    for (int iq = 0; iq < Q; iq++)
    {
        res -= cnt.at(B.at(iq)) * B.at(iq);
        res += cnt.at(B.at(iq)) * C.at(iq);
        cnt.at(C.at(iq)) += cnt.at(B.at(iq));
        cnt.at(B.at(iq)) = 0;
        cout << res << endl;
    }
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    int Q;
    cin >> Q;
    vector<int> B(Q);
    vector<int> C(Q);
    for (int i = 0; i < Q; i++)
    {
        cin >> B.at(i);
        cin >> C.at(i);
    }
    solve(N, move(A), Q, move(B), move(C));
    return 0;
}


Measured memory_bytes: 5048
#include<stdio.h>
int gcd(int a,int b){
    if(a<b){
        int t=b;
        b=a;
        a=t;
    }
    int c=1;
    while(c!=0){
        c=a%b;
        a=b;
        b=c;
    }
    return a;
}
int main(void){
    int w,h,c,g;
    scanf("%d %d %d",&w,&h,&c);
    g=gcd(w,h);
    printf("%d\n",(w/g)*(h/g)*c);
	return 0;		
}


Measured memory_bytes: 2148
from copy import deepcopy
def main():
    global flags, edges
    n, m = map(int, input().split())

    flags = {e:[n+1, n+1] for e in range(1, n + 1)}
    flags[1][1] = 0
    edges = {e:set() for e in range(1, n + 1)}
    edge_list = []
    for _ in range(m):
        a, b = map(int, input().split())
        edges[a].add(b)
        edges[b].add(a)
        edge_list.append((a, b))

    distance = 1
    node_next = list(edges[1])
    node_next_next = []
    while node_next:
        for next in node_next:
            if flags[next][1] > distance:
                flags[next][1] = distance
                node_next_next += edges[next]
        node_next = deepcopy(node_next_next)
        node_next_next = []
        distance += 1
    for edge in edge_list:
        e1 = edge[0]
        e2 = edge[1]
        if flags[e1][1] == flags[e2][1]:
            pass
        elif flags[e1][1] > flags[e2][1]:
            flags[e1][0] = min(flags[e1][0], e2)
        else:
            flags[e2][0] = min(flags[e2][0], e1)
    result = [flags[f][1] < (n + 1) for f in flags if f > 1]
    if not all(result):
        print('No')
    else:
        print('Yes')
        for i1 in range(2, n + 1):
            print(flags[i1][0])
            
if __name__ == '__main__':
    main()


Measured memory_bytes: 110420
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const ll INF = 1e18;
const int MAX = 1e6;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

// struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visited[MAX]; // 訪問状況

int gcd(int a, int b) { // aとbの最大公約数（ユークリッドの互除法）
    if (b == 0) return a;
    return gcd(b, a % b);
}

int gcd(vector<int> &a) { //  配列a[i]の最大公約数
    int r;
    rep(i, (int)a.size()) {
        if (i == 0) r = a[i];
        r = gcd(r, a[i]);
    }
    return r;
}

int main() {
    // input
    int n, x;
    cin >> n >> x;
    vi a(n);
    vi b(n);
    rep(i, n) {
        cin >> a[i];
        b[i] = abs(x-a[i]);
    }
    // solve
    // int prev = abs(x-a[0]);
    // rep(i, n) { // |x-a[i]|のgcdを求める
    //     if (i == 0) continue;
    //     prev = gcd(prev, abs(x-a[i]));
    // }
    int ans = gcd(b);
    // output
    cout << ans << "\n";
}

Measured memory_bytes: 3996
import java.util.*;

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

        System.out.println(Math.abs(x-a) < Math.abs(x-b) ? "A" : "B");
    }
}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i ++ ) {
            A[i] = sc.nextInt();
        }

        Arrays.sort(A);
        int res = 0;
        for (int i = 0; i < K; i ++ ) {
            res += A[i];
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 38812
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,x,n) for(int i=x;i<n;++i)

int main()
{
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> ans_cnt(n, 0);
    rep(i,q)
    {
        int ai;
        cin >> ai;
        ans_cnt[ai-1]++;
    }

    rep(i,n)
    {
        if(k-(q-ans_cnt[i]) > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }    
    return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null)
                br.close();
        }

        public String next() throws IOException {
            if (i < s.length)
                return s[i++];
            String st = br.readLine();
            while (st == "")
                st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }

    private void solve() {
        try {
            int a, b, c, d, e;
            a = sc.nextInt(); // a = 2
            b = sc.nextInt(); // b = 3
            c = sc.nextInt(); // c = 4
            d = sc.nextInt(); // a = 2
            e = sc.nextInt(); // b = 3

            int before = a * 60 + b;
            int after = c * 60 + d;
            if(after-before>=e)System.out.println(after-before-e);
            else System.out.println("0");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

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

typedef long long ll;

int main(void) {
	int Q, H, S, D, N;
	ll ans;

	cin >> Q >> H >> S >> D >> N;
	int min1 = min(4 * Q, 2 * H);
	min1 = min(S, min1);
	if (min1 * 2 <= D)
		ans = (ll)N * min1;
	else {
		int d = N % 2;
		ans = (ll)N / 2 * D + (ll)min1 * d;
	}

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


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	char s[1000];
	int i,n;
	scanf("%s",s);
	n=strlen(s);
	for(i=0;i<n;i++){	
		if(s[i]=='A')	s[i]='X';
		else if(s[i]=='B')	s[i]='Y';
		else if(s[i]=='C')	s[i]='Z';
		else	s[i]-=3;
	}
	for(i=0;i<n;i++){
		printf("%c",s[i]);
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    string s;
    cin >> s;
    if (s == "A" || s == "T")
    {
        cout << (s == "A" ? "T" : "A") << endl;
    }
    else
    {
        cout << (s == "G" ? "C" : "G") << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll a,b;
    cin >>a>>b;
    
    cout << (a+b+1)/2 << endl;


    return 0;
    

}

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


int main(){
    int h,w;
    cin >> h >> w;
    int a[h][w];
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> a[i][j];
        }
    }
    int n = 0;
    string ans = "";
    for(int i=0; i<h; i++){
        for(int j=0; j<w-1; j++){
            if(a[i][j]%2){
                ans += to_string(i+1) + ' ' + to_string(j+1) + ' ' 
                    + to_string(i+1) + ' ' + to_string(j+2) + '\n';
                n++;
                a[i][j+1]++;
            }
        }
    }
    for(int i=0; i<h-1; i++){
        if(a[i][w-1]%2){
            ans += to_string(i+1) + ' ' + to_string(w) + ' '
                + to_string(i+2) + ' ' + to_string(w) + '\n';
            n++;
            a[i+1][w-1]++;
        }
    }
    cout << n << endl;
    cout << ans;
    return 0;
}


Measured memory_bytes: 5124
#include <stdio.h>
#define MAX 2000001
int A[MAX],B[MAX],C[MAX];

int main(){
  int n,i,j,k=0;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
    if(k < A[i]) k = A[i];
  }

  for(i=0;i<=k;i++){
    C[i] = 0;
  }

    for(j=1;j<=n;j++){
      C[A[j]]++;
    }

  for(i=1;i<=k;i++){
    C[i] += C[i-1];
  }

  for(j=n;j>=1;j--){     
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }

  for(i=1;i<n;i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[n]);
  return 0;
}

Measured memory_bytes: 17892
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pii pair<int,int>
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int n,m=0,c=0; cin>>n;
  vector<int> col(8);
  rep(i,0,n){
    int a;
    cin>>a;
    if(a<3200) col[a/400]++;
    else m++;
  }
  rep(i,0,8) if(col[i]>0) c++;
  if(c>0) co(c<<" "<<c+m);
  else if(m>0) co(1<<" "<<m);
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e4 + 5;
long double ans[N][N];
ll mod = 1e9 + 7;
int main() {
	IO
	int n;
	cin >> n;
	long double arr[n + 1];
	for (int i = 1; i <= n; i++)
		cin >> arr[i];
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= n; j++)
			ans[i][j] = 0;
	ans[1][1] = arr[1];
	ans[1][0] = 1 - arr[1];
	for (int i = 2; i <= n; i++){
		for (int j = 0; j <= i; j++){
			ans[i][j] += ans[i - 1][j] * (1 - arr[i]);
			if (j)
				ans[i][j] += ans[i - 1][j - 1] * arr[i];
		}
	}
	long double final = 0;
	for (int i = (n +1 ) / 2; i <= n; i++)
		final += ans[n][i];
	cout << fixed << setprecision(12) << final;
	return 0;
}


Measured memory_bytes: 467840
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

li med(vector<li>& a){
  int n=a.size();
  sort(a.begin(),a.end());
  return a[n/2];
}
li med2(vector<li>& a){
  int n=a.size();
  sort(a.begin(),a.end());
  return a[n/2]+a[n/2-1];
}

int main(){
  int n; cin >>n;
  vector<li> a(n),b(n);
  rep(i,n) cin >>a[i] >>b[i];
  li m1,m2;
  if(n%2){
    m1=med(a);
    m2=med(b);
    print(m2-m1+1);
  }else{
    m1=med2(a);
    m2=med2(b);
    print(m2-m1+1);
  }
}


Measured memory_bytes: 6376
S = str(input())
T = str(input())
lenS = len(S)
lenT = len(T)
max_match = 0
for idx in range(lenS - lenT + 1):
    cnt_match = 0
    for i in range(lenT):
        if S[idx + i] == T[i]:
            cnt_match += 1
    if cnt_match > max_match:
        max_match = cnt_match
print(lenT - max_match)



Measured memory_bytes: 9052
#include <cstdio>
#include <bitset>
using namespace std;

bitset<400> u[400];
bitset<400> die;
int x[100005], y[100005];
int n,m;

int main()
{
  scanf("%d%d", &n, &m);  
  for (int i = 0; i < m;i++) {
    scanf("%d%d", x+i, y+i);
  }

  for (int i = 0; i < n;i++) u[i].set(i);

  for (int i = m-1; i>=0; i--) {
    int p = x[i] - 1, q = y[i] - 1;
    die |= (u[p] & u[q]);
    u[p] |= u[q];
    u[q] |= u[p];
  }

  int ans = 0;
  for (int i = 0; i < n; i++)
  for (int j = i+1; j < n; j++) if (!die.test(i) && !die.test(j)) {
    ans++;
    for (int k = 0; k < n; k++) if (u[k].test(i) && u[k].test(j)) {
      ans--;
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1024