akhauriyash/Code-Regression huggingface dataset:
module Main (main) where

import qualified Data.ByteString.Char8     as C8
import           Data.Maybe

main :: IO ()
main = do
  [x,t] <- readInts
  print . showAnswer $ solve (x,t)

type Input  = (Int, Int)
type Output = Int

solve :: Input -> Output
solve (x,t) = if y < 0 then 0 else y
  where
    y = x-t

showAnswer :: Output -> Answer
showAnswer = Number

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | AB Bool
  | Number Int

instance Show Answer where
  show (YesNo b)  = if b then "Yes" else "No"
  show (AB b)     = if b then "A"   else "B"
  show (Number i) = show i

Measured memory_bytes: 380
#include<bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second

using namespace std;

const int N = 702;
int n, m, vis[N], cnt[N][3], cmpcnt, dp[N][N], mat[N][N], mn=1e6;
vector<int> g[N];
bool ret=true;
void dfs(int u, int col)
{
	//cout << u << " - " << col << endl;
	cnt[cmpcnt][col]++;
	vis[u]=col;
	for(auto v: g[u])
	{
		if(vis[v]==col)
		{
		//	cout << v << endl;
			ret=false;
		}
		else if(!vis[v]) dfs(v, 3-col);
	}
}
int main()
{
	cin >> n >> m;
	for(int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		mat[x][y]=mat[y][x]=1;
	}	
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			if(!mat[i][j] && i!=j) g[i].pb(j);
		}
	}
	for(int i = 1; i <= n; i++)
	{
		if(!vis[i])
		{	
			cmpcnt++;
			cnt[cmpcnt][1]=0;
			cnt[cmpcnt][2]=0;
			dfs(i, 1);
		}
	}
	if(!ret)
	{
		cout << -1;
		return 0;
	}
	dp[0][0]=1;
	for(int i = 1; i <= cmpcnt; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			dp[i][j]|=dp[i-1][j-cnt[i][1]];
			dp[i][j]|=dp[i-1][j-cnt[i][2]];
		}
	}
	for(int i = 1; i <= n; i++)
	{
		if(dp[cmpcnt][i])
		{
			int curr = (i*(i-1))/2 + ((n-i)*(n-i-1))/2;
			mn = min(mn, curr);
		}
	}	
	cout << mn;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

struct nod
{
    ll a,b,c,d;
};

ll brute(ll i, vector<ll> &v, nod arr[], ll q, ll n, ll m, ll prev)
{
    if(i == n)
    {
        ll ans = 0;
        repi(j,q)
        {
            if(v[arr[j].b] - v[arr[j].a] == arr[j].c)
                ans+=arr[j].d;
        }
        return ans;
    }
    ll mans = 0;
    for(ll j=prev;j<=m;j++)
    {
        v.pb(j);
        mans = max(brute(i+1,v,arr,q,n,m,j),mans);
        v.pop_back();
    }
    return mans;
}

int main()
{
   FAST/**/
   
   ll n,m,q;
   cin>>n>>m>>q;
   
   nod arr[q];
   rep(q)
       cin>>arr[i].a>>arr[i].b>>arr[i].c>>arr[i].d, arr[i].a--, arr[i].b--;
   vector<ll> v;
   cout<<brute(0,v,arr,q,n,m,1);
   
   
   return 0;        
}  
  
   

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> h(n);
    REP(i,n) cin>>h[i];
    int dp[n];
    dp[0] = 0;
    REP(i,n-1){
        if(i==0) dp[i+1] = abs(h[i+1]-h[i]);
        else if(i<=n-2&&i>=1) dp[i+1] = min(dp[i]+abs(h[i+1]-h[i]), dp[i-1]+abs(h[i+1]-h[i-1]));
    }
    print(dp[n-1]);
    return 0;
}

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

namespace IO {
    template <typename Tp>
    inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp>
    inline bool read(Tp& x) {
        x = input<Tp>();
    }
};  // namespace IO
using namespace IO;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int& x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1) ans = mul(ans, x);
        return ans;
    }
};  // namespace modular

#define reg register
#define MAX_N 3007
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
typedef long long ll;

int N;
double L, a[MAX_N], PI = acos(-1);

inline void solve() {
    double ax = 0, ay = 0;
    rep(i, 1, N) {
        lep(j, 1, i) {
            int cnt = i - j - 1;
            if (cnt) {
                ax += -cos((a[i] + a[j]) * PI / 2.0) * cnt;
                ay += -sin((a[i] + a[j]) * PI / 2.0) * cnt;
            }
            cnt = N - i + j - 1;
            if (cnt) {
                ax += cos((a[i] + a[j]) * PI / 2.0) * cnt;
                ay += sin((a[i] + a[j]) * PI / 2.0) * cnt;
            }
        }
    }
    double tot = 1.0 * N * (N - 1) * (N - 2) / 6.0;
    printf("%.10lf %.10lf\n", ax / tot, ay / tot);
}

int main() {
#ifdef LOCAL
    FIN("in");
#endif
    read(N), read(L);
    PI = PI * 2.0 / L;
    rep(i, 1, N) read(a[i]);
    solve();
    return 0;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
sum = 0
ans = 0
mod = 1000000007
for i in range(n):
    sum+=a[i]
for i in range(n):
    sum-=a[i]
    ans+=(a[i]*(sum%mod))
    ans%=mod
print(int(ans))


Measured memory_bytes: 31400
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
	int n;
	cin>>n;
	int l,m=0,s=0,i;
	for(i=0;i<n;i++){
		cin>>l;
		s+=l;
		m=max(m,l);
	}
	if(m<s-m)cout<<"Yes\n";
	else cout<<"No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstdio>
#include <vector>
typedef long long      ll;
using namespace std;
const int maxn = 1e5 + 10;
typedef pair<ll, ll>   pil;
typedef vector<pil>    vil;
#define pb    push_back
#define mp    make_pair
ll       n, m, dis[maxn], vis[maxn];
const ll inf = 0x3f3f3f3f3f3f3f3f;
struct node
{
    ll d, id;
};
vector<pil> V[maxn];
void init()
{
    for (ll i = 2; i <= n; i++)
        V[i].pb(mp(i - 1, 0));
}
priority_queue<pil, vil, greater<pil> > q;
void solve()
{
    int s = 1;
    for (int i = 1; i <= n; i++)
        dis[i] = inf;
    dis[s] = 0;
    q.push(mp(dis[s], s));
    while (!q.empty())
    {
        pil p   = q.top(); q.pop();
        int mid = p.second;
        if (vis[mid])
            continue;
        vis[mid] = 1;
        for (int i = 0; i < V[mid].size(); i++)
        {
            int y = V[mid][i].first, d = V[mid][i].second;
            if (!vis[y] && dis[mid] + d < dis[y])
            {
                dis[y] = dis[mid] + d;
                q.push(mp(dis[y], y));
            }
        }
    }
    // for (int i = 1; i <= n; i++)
    //     cout << dis[i] << endl;
    if (dis[n] != inf)
        cout << dis[n] << endl;
    else
        cout << "-1\n";
}

int main()
{
    ios::sync_with_stdio(0);
    cin >> n >> m;
    init();
    for (ll i = 0, u, v, w; i < m; i++)
    {
        cin >> u >> v >> w;
        V[u].pb(mp(v, w));
    }
    // for (int i = 1; i <= n; i++)
    // {
    //     for (int j = 0; j < V[i].size(); j++)
    //     {
    //         cout << i << endl;
    //         cout << V[i][j].first << " " << V[i][j].second << endl;
    //     }
    // }
    solve();
}


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

using namespace std;

int kMinimum( int* arr, int* min, int n, int k, int index){
    int limit, k1 = 0;
    vector<int> a;
    if(index + k >= n){
        limit = n-1;
    }
    else{
        limit = index + k;
    }
    for(int i = limit; i > index; i--){
        a.push_back(abs(arr[i] - arr[index]) + min[i]);
    }
    return *min_element( a.begin(), a.end());
}

int solve(int* a, int n, int k){
    int min[n];
  	min[n-1] = 0;
  	min[n-2] = abs( a[n-1] - a[n-2]);
  	for (int i = n-3; i >= 0; i--){
    	min[i] = kMinimum( a, min, n, k, i);
    }
    return min[0];
}

int main(){
    int n,k;
    cin >> n >> k;
    int arr[n];
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    cout<<solve(arr, n, k);
 	return 0;
}


Measured memory_bytes: 1024
p=int(input())
A=list(map(int,input().split()))
cmb=[0]*p
cmb[0]=1
for i in range(1,p):
  cmb[i]=cmb[i-1]*(p-i)*pow(i,p-2,p)%p
ans=[0]*p
for i in range(p):
  if A[i]==1:
    b=1
    ans[0]=ans[0]+1
    for j in range(p):
      ans[p-j-1]=(ans[p-j-1]-cmb[j]*b)%p
      b=b*(-i)%p
for i in range(p-1):
  print(ans[i],end=" ")
print(ans[p-1])

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase(unique(all(v)), v.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 (a>b) { a = b; return 1; } return 0; }
const ll inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);

int main() {
	int n, a;
	cin >> n >> a;
	vi x(n);
	rep(i, n) {
		cin >> x[i];
		x[i] -= a;
	}
	vll dp(n + 1, vl(6000));
	dp[0][3000] = 1;
	rep(i, n) {
		rep(j, 6000) {
			if (in(j + x[i], 0, 6000)) {
				dp[i + 1][j + x[i]] += dp[i][j];
				dp[i + 1][j] += dp[i][j];
			}
		}
	}
	cout << dp[n][3000] - 1 << endl;
}

Measured memory_bytes: 2688
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card
{
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right)
{
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for (i = 0; i < n1; i++)
        L[i] = A[left + i];
    for (i = 0; i < n2; i++)
        R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for (k = left; k < right; k++)
    {
        if (L[i].value <= R[j].value)
        {
            A[k] = L[i++];
        }
        else
        {
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right)
{
    int mid;
    if (left + 1 < right)
    {
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r)
{
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for (j = p; j < r; j++)
    {
        if (A[j].value <= x.value)
        {
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i + 1];
    A[i + 1] = A[r];
    A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r)
{
    int q;
    if (p < r)
    {
        q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main()
{
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n - 1);

    for (i = 0; i < n; i++)
    {
        if (A[i].suit != B[i].suit)
            stable = 0;
    }

    if (stable == 1)
        printf("Stable\n");
    else
        printf("Not stable\n");
    for (i = 0; i < n; i++)
    {
        printf("%c %d\n", B[i].suit, B[i].value);
    }
    return 0;
}


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

#define ff first
#define ss second
#define pb push_back

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

const int N = 100005;

int main(){
	char s[40];
	scanf("%s", s);
	s[3] = 0;
	printf("%s\n", s);
	return 0;
}


Measured memory_bytes: 3692
#ABC.C152
import collections
N = int(input())
A = list(map(int,input().split()))

d = collections.Counter(A)
total = 0
for i in d.values():
    n = i*(i-1)//2
    total+=n

for m in A:
    a= total - (d[m]*(d[m]-1))//2 +((d[m]-1)* (d[m]-2))//2
    print(a)

Measured memory_bytes: 26780
/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-4-7 20:58:00
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main()
{
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  sort(A, A + 3);
  int ans = A[2] - A[1];
  if ((A[1] - A[0]) % 2 != 0)
  {
    ans += (A[1] - A[0] + 1) / 2 + 1;
  }
  else
  {
    ans += (A[1] - A[0]) / 2;
  }
  cout << ans << endl;
}

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

int main()
{
    string s;
    bool f = false,f2=false;
    int cnt=0,cnt2=0;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'A'){
            f = true;
        }
        if(f) cnt++;
        if(f){
            if(s[i] == 'Z'){
                f2 = false;
                for(int j=i+1; j<s.size(); j++){
                    if(s[j] == 'Z'){
                        f2 = true;
                        break;
                    }
                }
                if(f2 == false){
                    cout << cnt << endl;
                    return 0;
                }
            }
        }
    }
}


Measured memory_bytes: 640
N = int(input())
alpha = "abcdefghijklmnopqrstuvwxyz"
A = []
B = []

while N > 26:
    a = N
    N //= 26
    mod = a % 26
    if mod == 0:
        mod = 26
        N -= 1 
    A.append(mod)

A.append(N)
A = A[::-1]

for x in A:
    B.append(alpha[x-1])

ans = ''.join(map(str, B))

print(ans)

Measured memory_bytes: 9228
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
    	n:isize,
        m:isize
    }
    
    println!("{}", if 0<n&&n<10&&0<m&&m<10 { n*m} else {-1});
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
  int N;
  cin>>N;
  Bint A[N];
  cin>>A[0];
  Bint ans;
  ans=A[0];
  
  if(ans==0){
    cout<<0<<endl;
    return 0;
  }

  int flag=1;
  for(int i=1;i<N;i++){
    cin>>A[i];
    if(A[i]==0){
      cout<<0<<endl;
      return 0;
    }
  }
  for(int i=1;i<N;i++){
    ans*=A[i];
    if(ans>1000000000000000000){
      flag=0;
      break;
    }
  }
  if(flag==0){
    cout<<-1<<endl;
    return 0;
  }
 cout<<ans<<endl;
  return 0;
}


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

using namespace std;

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

Measured memory_bytes: 256
counts = Hash.new(0)
max = [0, nil]

$<.gets.split.map(&:downcase).each do |word|
  counts[word] += 1
  l = word.length
  max = [l, word] if l > max.first
end
h = counts.invert
puts "#{h[h.keys.max]} #{max.last}"


Measured memory_bytes: 6864
#include <bits/stdc++.h>
#define MAXN 100005

using namespace std;
using ll = long long;

int n;
ll A[MAXN];
ll dp[MAXN];

ll solve(int i) {
  if (i < 0) {
    return 1e9;
  }
  if (i == 0) {
    return 0;
  }
  ll& res = dp[i];
  if (res != -1) {
    return res;
  }
  res = 1e9;
  res = min(res, abs(A[i] - A[i - 1]) + solve(i - 1));
  res = min(res, abs(A[i] - A[i - 2]) + solve(i - 2));
  return res;
}

int main() {
  fill(dp, dp + MAXN, -1LL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  cout << solve(n - 1) << '\n';
  return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define cin1(x) scanf("%d",&x)
#define cin2(x,y) scanf("%d %d",&x,&y)
#define cin3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define rr read()
#define ll long long
#define CloseIo ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int main(){
	string s;
	cin>>s;
	int count=1;
	int ans=0;
	string temp="";
	string mark="";
	rep(i,0,s.length()){
		temp+=s[i];
		if(temp != mark){
			ans++;
			mark=temp;
			temp="";
		}
	}
	cout<<ans<<"\n";
    return 0;  
}  

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;


const long long MOD = 1000000007;

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

	int n;
	cin >> n;
	int* x;
	x = new int[n];
	rep(i, n) cin >> x[i];
	
	int minNum = MOD;
	rep(i, 101) {
		int sum = 0;
		rep(j, n) sum += (x[j] - i)*(x[j] - i);
		minNum = min(minNum, sum);
	}

	cout << minNum << "\n";

	return 0;
}
 

Measured memory_bytes: 256
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
using namespace __gnu_pbds;
const double PI=acos(-1.0);
const double eps=1e-6;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
	int n;
	while(cin>>n){
	    bool ok=0;
        for(int i=1;i<=9;i++) for(int j=1;j<=9;j++) if(i*j==n) ok=1;
        if(ok==1) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 #include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e9
// #define ll long long ll
 
typedef long long ll;
ll mod = 1e9 + 7;
 
long long fast_exp(long long a, long long b)
{
	if(b <= 0)
	   return 1;
	else
	{
	   long long res = 1;
	   res = fast_exp(a,b/2);
	   res = (res*res)%mod;
	   if(b%2 == 1)
		  res = (res*a)%mod;
	   return res;
 
	}
}
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long double ld;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
    string s;
    cin>>s;
    int n = s.size();
    int a[n+1];
    for(int i = 0; i<n ; i++)
        a[i+1] = s[i] - '0';
    a[0] = 0;
    int sum = 0;

    for(int i = n; i>=0 ; i--)
    {
        if(a[i] > 5 || (a[i] == 5 && a[i - 1] >= 5) )
        {
            sum += 10 - a[i];
            a[i - 1]++;
        }
        else
        {
            sum+=a[i];
        }
        
    }

    cout<<sum<<endl; 

    return 0; 
}

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

int main() {
  int N;
  cin >> N;
  vector<int> AA(N);
  rep(i, N) { AA.at(i) = 0; }
  rep_s(i, 1, N) {
    int A;
    cin >> A;
    AA.at(A - 1) = AA.at(A - 1) + 1;
  }
  rep(i, N) { cout << AA.at(i) << endl; }
}


Measured memory_bytes: 4044
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset> 
#include <cstdio> 
#include <vector>
using namespace std;
int N,M;//buld switch 
bitset<11> bulb[11];
int p[11];
int main(){
	cin>>N>>M;
	for(int i=1;i<=M;i++){
		int t,x;
		cin>>t;
		while(t--){
			cin>>x;
			bulb[i][x-1]=1;
		}
	}
	for(int i=1;i<=M;i++){
		cin>>p[i];
	}
	unsigned int ans=0;
	for(int i=0;i<pow(2,N);i++){
		int flag=0;
		for(int j=1;j<=M;j++){
			bulb[0]=(bulb[j].to_ulong()&i);
			if(bulb[0].count()%2!=p[j])flag=1;
		}
		if(flag==0)ans++;
	}
	cout<<ans;
	return 0;
}


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

int main(void){
    int N;
    long long a, ans = 0, s = 0;
    const long long mod = pow(10,9)+ 7;
    cin >> N;
    for( int i=0; i<N; i++){
        cin >> a;
        //cout << "(1) ans = " << ans << ", s = " << s << endl;
        ans = (ans + (a * s) % mod ) % mod;
        s = ( s + a ) % mod;
        //cout << "(2) ans = " << ans << ", s = " << s << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <map>
#include <memory.h>
#include <queue>
#include <string.h>
#include <set>
#include <bitset>
using namespace std;

#define ll long long
#define N 402
#define mod 1000000007

int add(int x,int y) {
  int ret= x+y;
  if(ret>=mod) {
    ret-=mod;
  }
  if(ret<0) {
    ret += mod;
  }
  return ret;
}
int mul(int x,int y) {
  return (ll)x*y%mod;
}

int powSum[N][N];
int dp[N],A[N],B[N];
void solve() {
  int n,c;scanf("%d %d", &n,&c);
  for(int i=1;i<=400;++i) {
    powSum[0][i] = 1;
    for(int j=1;j<=400;++j) {
      powSum[j][i] = mul(powSum[j-1][i],i);
    }
  }
  for(int row=0;row<=400;++row) {
    for(int col=1;col<=400;++col) {
      powSum[row][col] = add(powSum[row][col-1], powSum[row][col]);
    }
  }
  for(int i=1;i<=n;++i) {
    scanf("%d ", &A[i]);
  }
  for(int i=1;i<=n;++i) {
    scanf("%d ", &B[i]);
  }
  dp[0] = 1;
  for(int ele=1;ele<=n;++ele) {
    int a = A[ele],b = B[ele];
    for(int row=c;row>=0;--row) {
      for(int cc=1;row+cc<=c;++cc) {
        dp[row+cc] = add(dp[row+cc], mul(dp[row], add(powSum[cc][b],-powSum[cc][a-1])));
      }
      dp[row] = mul(dp[row],b-a+1);
    }
  }
  printf("%d\n", dp[c]);
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


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

int main(int argc, char const *argv[])
{
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	int a[n],b[m];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	for (int i = 0; i < m; ++i)
	{
		cin>>b[i];
	}
	sort(a,a+n);
	sort(b,b+m);
	reverse(a,a+n);
	for (int i = x+1; i <= y; ++i)
	{
		if (a[0]<i&&i<=b[0])
		{
			cout<<"No War\n";
			return 0;
		}
	}
	cout<<"War\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct go {
	int x,y,magic;
	bool operator < (const go &l) const{
		return magic>l.magic;
	}
};
priority_queue<go> q;
int h,w,ans=-1;
int ch,cw,dh,dw;
char s[1100][1100];
bool vis[1100][1100];
int fx[]={1,0,-1,0};
int fy[]={0,1,0,-1};
int main() {
	memset(vis,0,sizeof(vis));
	cin>>h>>w;
	cin>>ch>>cw;
	cin>>dh>>dw;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			cin>>s[i][j];
	q.push((go){ch,cw,0});
	while(!q.empty()) {
		go x=q.top();q.pop();
		if(x.x==dh && x.y==dw) {
			ans=x.magic;
			break;
		}
		if(vis[x.x][x.y]) continue; 
		for(int i=0;i<4;i++) {
			int tx=x.x+fx[i],ty=x.y+fy[i];
			if(tx<1 || ty<1 || tx>h || ty>w) continue;
			if(vis[tx][ty]==0 && s[tx][ty]=='.') 
				q.push((go){tx,ty,x.magic}); 
		}
		vis[x.x][x.y]=1;
		for(int i=max(1,x.x-2);i<=min(h,x.x+2);i++)
			for(int j=max(1,x.y-2);j<=min(w,x.y+2);j++) {
				if(vis[i][j]==0 && s[i][j]=='.') 
					q.push((go){i,j,x.magic+1});
			}
	}
	printf("%d",ans);
	return 0;
}



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

const int MXN = 1e3 + 20, MOD = 1e9 + 7;

long long h, w, tbl[MXN][MXN];

int main() {
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		string tmp;
		cin >> tmp;
		for (int j = 1; j <= w; j++)
			if (tmp[j - 1] == '#')
				tbl[i][j] = -1;
	}
	tbl[1][1] = 1;
	for (int i = 1; i <= h; i++)
		for (int j = 1; j <= w; j++)
			if (tbl[i][j] != -1) {
				if (tbl[i - 1][j] != -1)
					tbl[i][j] += tbl[i - 1][j] % MOD;
				if (tbl[i][j - 1] != -1)
					tbl[i][j] += tbl[i][j - 1] % MOD;
			}
	cout << tbl[h][w] % MOD << endl;
}


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

const int mod = 1000000007;

int main(){
  string s; cin >> s;
  int dp[100010][13];
  for (int i = 0; i < 100010; i++){
    for (int j = 0; j < 13; j++){
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  for (int i = 0; i < s.size(); i++){
    for (int j = 0; j < 13; j++){
      if (s.at(i) == '?'){
        for (int k = 0; k < 10; k++){
          dp[i + 1][(10 * j + k) % 13] += dp[i][j];
          dp[i + 1][(10 * j + k) % 13] %= mod;
        }
      }else{
        int k = s.at(i) - '0';
        dp[i + 1][(10 * j + k) % 13] += dp[i][j];
        dp[i + 1][(10 * j + k) % 13] %= mod;
      }
    }
  }
  cout << dp[s.size()][5] << endl;
}

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

void cari(string result, int rem, char next) {
	if (rem == 0) {
		cout << result << "\n";
		return;
	}
	for (char c = 'a'; c < next; c++) {
		cari(result + c, rem-1, next);
	}
	cari(result + next, rem-1, next+1);
}

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

	int N;
	cin >> N;
	cari("", N, 'a');
}

Measured memory_bytes: 1536
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner xs = new Scanner(System.in);
        int A = xs.nextInt();
        int B = xs.nextInt();
        if(A<=8 && B<=8){
        System.out.println("Yay!");
        }else{
		System.out.println(":(");        
        }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#define int long long
using namespace std;
int test[213456];
int ok[213456];
signed main() {
	int n, m, k, a, b, c, sum = 0, ans = 0; string s, t;
	cin >> s;
	for (int h = 1; h < s.size(); h++) {
		if (s[h - 1] == 'h' && s[h] == 'i') { h++; }
		else { cout << "No" << endl; return 0; }
	}
	if (s.size() % 2 == 1) { cout << "No" << endl; return 0; }
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

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

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  Sieve s(1000010);
  vector<int> cnt(1000010);

  bool pairwise = true;
  rep(i, n) {
    auto v = s.factor(a[i]);
    for (auto p : v) {
      if (cnt[p.first] > 0) {
        pairwise = false;
      }
      cnt[p.first]++;
    }
  }

  if (pairwise) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int cur = a[0];
  for (int i = 1; i < n; ++i) {
    cur = gcd(cur, a[i]);
  }
  
  if (cur == 1) {
    cout << "setwise coprime" << endl; 
  } else {
    cout << "not coprime" << endl;
  }
}

Measured memory_bytes: 15200
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int s[1000];
	int m[3];
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>m[0]>>m[1]>>m[2];
		sort(m,m+3);
		if(m[0]*m[0]+m[1]*m[1]==m[2]*m[2])
			s[i]=1;
		else
			s[i]=0;
	}
	for(int i=0;i<n;i++)
		if(s[i]==1)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    string s;
    cin >> s;

    int ans = INT_MAX;
    for (char c = 'a'; c <= 'z'; c++)
    {
        int cnt = 0;
        string tmp = s;
        while (count(all(tmp), c) != tmp.size())
        {
            int n = tmp.size();
            string t;
            for (int i = 0; i < n - 1; i++)
            {
                if (tmp[i] == c or tmp[i + 1] == c)
                    t.push_back(c);
                else
                {
                    t.push_back(tmp[i]);
                }
            }
            tmp = t;
            cnt++;
        }
        chmin(ans, cnt);
    }
    cout << ans;
    return 0;
}

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

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

using namespace std;

int main(){
  ll x,y;cin>>x>>y;
  if(x%y==0){
    cout<<-1;
  }else{
    cout<<x;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
string a;
	ll ans;
	cin >>a;
	ans=a.size()*(a.size()+1LL)/2LL+1LL;
	//clog<<ans<<endl;
	map<char,ll>dis;
	rep(i,a.size()){
		dis[a[i]]+=0;
		dis[a[i]]++;
	}
	repi(itr,dis){
		ans-=(itr->S)*((itr->S)-1LL)/2LL;
	//	clog<<(itr->S)<<endl;
	}
	ans-=a.size();
	cout<<ans<<endl;
}
/*
8=n
oooooooo
01 12 23 34 45 56 67 =n-1
02 13 24 35 46 57    =n-2 = o(n)
   03 14 25 36 47  
   04 15 26 37
      05 16 27
	  06 17=
	     07
= 28

abracadabra
   aca
     ada

abcba  3 2 2 1
bacba
cbaba
bcbaa
acbba
aabcb
abbca
ababc
abcab


abbca 4 2 2 1
babca
bbaca
cbbaa
acbba
aacbb
abcba
abacb
abbac
*/

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

using namespace std;
int standbits(int bits){
  int ret=0;
  for(;bits!=0;bits&=bits-1)ret++;
  return ret;
}
int eval(int s,vector<int> F, vector<vector<int> > P,int N){
  int ret=0;
  for (int i=0;i<N;i++){
    //cout<<bitset<10>(F[i])<<endl<<standbits(s&F[i])<<endl;;
    ret+=P[i][standbits(s&F[i])];
  }
  return ret;
}


int main(){
  //cout<<standbits(011111101LL)<<endl;
  int N;
  cin>>N;
  vector<int>F;
  for(int i=0;i<N;i++){
    F.push_back(0);
    for(int j=0;j<10;j++){
        int t;
        cin>>t;
        F[i]+=t;
        F[i]=F[i]<<1;
    }
    F[i]=F[i]>>1;
  }
  vector< vector<int> > P;
  for(int i=0;i<N;i++){
    P.push_back({});
    for(int j=0;j<11;j++){
      int t;
      cin>>t;
      P[i].push_back(t);
    }


  }
  int ans=-1000000001;
//  cout<<ans<<endl;
  for (int i=1;i<1024;i++){
    ans=max(ans,eval(i,F,P,N));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]){
    int D, G, p[11], c[11];
    cin >> D >> G;
    for(int i = 0; i < D; ++i){
        cin >> p[i] >> c[i];
    }
    
    int ans = 1e9;
    for(int mask = 0; mask < (1 << D); ++mask){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < D; ++i){
            if(mask >> i & 1){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
prices = [int(x) for x in input().split()]
sizes = [2000, 1000, 500, 250]
N = int(input()) * 1000
totalPrice = 0
remainSize = N
ratios = []

for i in range(len(prices)-1):
	if(prices[i]*2 < prices[i+1]):
		prices[i+1] = prices[i]*2

prices.reverse()

for i in range(len(prices)):
	totalPrice += remainSize//sizes[i] * prices[i]
	remainSize = remainSize%sizes[i]

print(totalPrice)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

typedef pair<int, int> P;

int main() {
  int N;
  cin >> N;
  vector<P> A(N);
  rep(i, N) {
    cin >> A[i].first;
    A[i].second = i+1;
  }
  sort(A.begin(), A.end());
  rep(i, N)
    printf("%d%c", A[i].second, i<N-1?' ':'\n');
  return 0;
}

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

int main(){
  string s,ans="";
  cin>>s;
  int i;
  for(i=0;i<s.size();i++){
    if(s[i]=='C'){
      break;
    }
    if(i==s.size()-2){
      cout<<"No"<<endl;
      return 0;
    }
  }
  for(int j=i+1;j<s.size();j++){
    if(s[j]=='F'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	string s,t;
	cin >> s >> t;
	cout << t << s << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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


Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		String[] strs = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
				.split(", ");
		Scanner sc = new Scanner(System.in);
		int i = sc.nextInt();

		System.out.println(strs[i - 1]);
	}
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>

#undef DEBUG

#ifdef DEBUG
struct testdata{
    int A;
    int B;
    int a;
} td[] = {
    {12, 4, 4},
    {20, 15, 0},
    {20, 30, 0},
};
#endif

void
solver(int a, int b)
{
    if (a>2*b)
        printf("%d\n", a-2*b);
    else
        printf("0\n");
    return;
}

int
main(int argc, char *argv[])
{
    int i;
    int A, B;
#ifdef DEBUG
    for (i=0; i<3; i++) {
        solver(td[i].A, td[i].B);
        printf("%d\n", td[i].a);
    }
#else
    scanf("%d%d", &A, &B);
    solver(A, B);
#endif

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>

using namespace std;
long long n,k,h;
int main()
{
	cin>>k>>n;
	for(int i=0;i<=k;i++)
	{
		for(int j=0;j<=k;j++)
		{
			if(n-i-j<=k&&n-i-j>=0)
			h++;
		}
	}
	cout<<h;
	return 0;
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n + 1, -1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] - a[i - 1] > 1) {
            cout << -1 << endl;
            return 0;
        }
    }

    ll c = a[n];
    for (int i = n - 1; i > 0; i--)  {
        if (a[i] >= a[i + 1]) {
            c += a[i];
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
vector<int> ans;
vector<int> h;
int frog1(int N)
{

  if(N<=0)return 0;
  if(N==1)return abs(h[1]-h[0]);
  if(ans[N]==-1)
  {
    ans[N] = min(abs(h[N]-h[N-1])+frog1(N-1),abs(h[N]-h[N-2])+frog1(N-2));
  }
  return ans[N];
}
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  ll N;
  cin>>N;
  h.resize(N);
  for(int i=0;i<N;i++){
    cin>>h[i];
  }
  ans.resize(N);
  for(int i=0;i<N;i++){
    ans[i] = -1;
  }
  
  cout<<frog1(N-1)<<endl;
  return 0;
  
}


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

int main(int argc, const char * argv[]) {
    int A, B;
    cin >> A;
    cin >> B;
    if (B == 1) {
        cout << "0" << endl;
        return 0;
    }
    
    int kuchi = A;
    int count = 1;
    while (kuchi < B) {
        kuchi -= 1;
        kuchi += A;
        count++;
    }
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int N = in.nextInt();
        int M = in.nextInt();
        ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
        for (int i=0;i<N;i++) {
            ArrayList<Integer> add = new ArrayList<Integer>();
            list.add(add);
        }
        int[] P = new int[M];
        int[] Y = new int[M];
        for (int i=0;i<M;i++) {
            P[i] = in.nextInt()-1;
            Y[i] = in.nextInt();
            list.get(P[i]).add(Y[i]);
        }
        for (int i=0;i<N;i++) {
            ArrayList<Integer> tmp = list.get(i);
            Collections.sort(tmp);
        }

        for (int i=0;i<M;i++) {
            int index = Collections.binarySearch(list.get(P[i]), Y[i]);
            out.printf("%06d", P[i]+1);
            out.printf("%06d", index+1);
            out.println("");
        }

        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


Measured memory_bytes: 127392
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

int n,m,b,a[li],k,flag,cev;
string s;
vector<int> v;

int main(void){
	scanf("%d %d %d",&a[1],&a[2],&a[3]);
	sort(a+1,a+3+1);
	if(a[1]==a[2]) cout<<a[3];
	else cout<<a[1];
	return 0;
}


Measured memory_bytes: 256
N, K = input().split()
A = [int(n) for n in input().split()]
kind = dict()

for n in A:
    if n not in kind:
        kind[n] = 0
    kind[n] += 1
diff = len(kind) - int(K)
if diff > 0:
    values = sorted(kind.values())
    print(sum(values[:diff]))
else:
    print(0)

Measured memory_bytes: 34172