akhauriyash/Code-Regression huggingface dataset:
def main():
    n, m, *l = map(int, open(0).read().split())
    ab = list(zip(l[::2], l[1::2]))
    ab.sort(key = lambda x: x[0])
    sum = 0
    ans = 0
    for i, j in ab:
        if sum + j < m:
            sum += j
            ans += i * j
        else:
            ans += (m - sum) * i
            break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25828
s=input()
t=input()
sl = [s[i] for i in range(len(s))]
tl = [t[i] for i in range(len(t))]
n = len(sl)
m = len(tl)
sl.sort()
tl.sort(reverse=True)
s_ans = ''.join(sl)
t_ans = ''.join(tl)
if s_ans < t_ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

typedef long long ll;
ll mod = 1e9 + 7;

int main(int argc, char *argv[])
{
	int N;
	string s;
	ll from[3005], to[3005];
	ll S[3005];

	cin >> N >> s;

	for (int i = 0; i < N; i++) {
		from[i] = 1;
	}

	for (int i = 0; i < N - 1; i++) {
		for (int i = 0; i < N; i++) {
			to[i] = 0;
		}
		for (int x = 0; x < N + 1; x++) {
			S[x] = ((x ? S[x - 1] : 0) + from[x]) % mod;
		}
		for (int x = 0; x < N - 1 - i; x++) {
			if (s[i] == '>') {
				to[x] = (S[N] + mod - S[x]) % mod;
			} else {
				to[x] = S[x];
			}
		}
		swap(from, to);
	}

	cout << from[0] << endl;

	return 0;
}

Measured memory_bytes: 384
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: i32,
        m: i32,
        k: i32,
    }

    for i in 0..n + 1 {
        for j in 0..m + 1 {
            if (m * i) + j * (n - 2 * i) == k {
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}


Measured memory_bytes: 2116
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e5 + 5;
long long int DP[MAXN];
int N, K;
long long H[MAXN];
long long rec(int idx)
{
    if(idx == (N - 1))
    {
        return 0;
    }
    if(DP[idx] != -1)
        return DP[idx];
    DP[idx] = abs(H[idx] - H[idx + 1]) + rec(idx + 1);
    for(int i = 2; i <= K; ++i)
        if((idx + i) <= (N - 1))
            DP[idx] = min(DP[idx], abs(H[idx] - H[idx + i]) + rec(idx + i));
    return DP[idx];
}

int main()
{
    cin >> N >> K;
    for(int i = 0; i < N; ++i)
        cin >> H[i];
    for(int i = 0; i < N; ++i)
        DP[i] = -1;
    cout << rec(0) << endl;
    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    while (cin >> N >> M, N) {
        int D, P, res = 0, Ps[11] = {};
        for (int i=0; i<N; ++i) {
            cin >> D >> P;
            res += D * P;
            Ps[P] += D;
        }
        for (int i=10; i>0; --i) {
            if (M <= Ps[i]) {
                res -= M * i;
                M = 0;
            } else {
                res -= Ps[i] * i;
                M -= Ps[i];
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    int arr[n+5];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    int cnt=0;
    for(int i=1; i<n-1; i++)
    {
        vector<int>v;
        for(int j=-1; j<2; j++)
            v.push_back(arr[i+j]);
        sort(all(v));
        if(arr[i]==v[1])
            cnt++;

    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>

int main(){
   int a, b, c;
   scanf("%d %d %d", &a, &b, &c);
   if( a < b ){
      if( b < c ){
         printf("%d %d %d\n", a, b, c);
      }else{
         if( c < a ){
            printf("%d %d %d\n", c, a, b);
         }else{
            printf("%d %d %d\n", a, c, b);
         }
      }
   }else{
      if( c < b ){
         printf("%d %d %d\n", c, b, a);
      }else{
         if( a < c ){
            printf("%d %d %d\n", b, a, c);
         }else{
            printf("%d %d %d\n", b, c, a);
         }
      }
   }

   return 0;

}



Measured memory_bytes: 2140
/* ?????????????????????????????????????????°?????? */

#include <stdio.h>

int main(void) {
  int i,j; // for???????????????????????¶??°???
  for(i = 1;i < 10;i++) {
    for(j = 1;j < 10;j++) {
      printf("%dx%d=%d\n", i,j,i*j);
    }
  }
  return 0;
}

Measured memory_bytes: 524
package main

import (
	"fmt"
)

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)

	counter := make([]int, N)
	for i := 0; i < N; i++ {
		counter[i] = 0
	}

	d := -1
	var a int
	for i := 0; i < K; i++ {
		fmt.Scanf("%d", &d)
		for j := 0; j < d; j++ {
			fmt.Scanf("%d", &a)
			counter[a-1]++
		}
	}

	r := 0
	for _, count := range counter {
		if count == 0 {
			r++
		}
	}
	fmt.Println(r)
}


Measured memory_bytes: 2408
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = numeric_limits<ll>::max();/* 1e+9a */
namespace utils{

    class Repeater{
        int st;
        int ed;
        int d;
    public:
        class rep_iterator{
            int i; int d;
        public:
            rep_iterator(int x, int pd) :i(x), d(pd) {}

            int& operator*(){ return i; }
            bool operator==(const rep_iterator& k) const { return i == k.i; }
            bool operator!=(const rep_iterator& k) const { return i != k.i; }
            rep_iterator& operator++(){ i+=d; return *this; }
        };

        explicit Repeater(int N) :st(0), ed(N), d(1) {}
        Repeater(int b, int e) :st(b), ed(e), d(1) {if(st > ed){ st--; ed--; d = -1; } }

        rep_iterator begin() const{ return rep_iterator(st, d); }
        rep_iterator end() const{ return rep_iterator(ed, d); }

    };

    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;

vector<ll> A;
vector<vector<ll>> dp;

ll cost(int l, int r){
    if(l == r) return 0;
    if(dp[l][r] != INF) return dp[l][r];
    
    ll sum = 0;
    for (int i = l; i <= r; ++i) {
        sum += A[i];
    } // end i
    
    ll ms = INF;
    for (int k = l; k < r; ++k) {
        ms = min(ms, cost(l, k) + cost(k+1, r) + sum);
    } // end k
    
    return dp[l][r] = ms;
}

void sub_main(istream &is) {
    ll N;
    is >> N;
    if(!is) return;
    A.resize(N);
    for (auto &&a : A) {
        is >> a;
    } // end a
    dp.clear();
    dp.resize(N, vector<ll>(N, INF));
    
    cout << cost(0, N-1) << endl;
    
    

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_N.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	int n, ans = 0;
	int n1 = 0;
	cin >> n;
	for (int i = 1;; i++) {
		n1 += i;
		ans++;
		if (n1 >= n) {
			break;
		}
	}
	for (int j = 1; j <= ans; j++) {
		if (j == n1 - n) {
			continue;
		}
		cout << j << endl;
	}
	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int X,Y;
    cin >> X >> Y;
    int s = 0;
    if(X == 1)
    {
        s += 300000;
    }
    if(Y == 1)
    {
        s += 300000;
    }
    if(X == 1 && Y == 1)
    {
        s += 400000;
    }
    if(X == 2)
    {
        s += 200000;
    }
    if(Y == 2)
    {
        s += 200000;
    }
    if(X == 3)
    {
        s += 100000;
    }
    if(Y == 3)
    {
        s += 100000;
    }
    cout << s << endl;
}

Measured memory_bytes: 256
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>
#include <limits.h>
#include <iomanip>
#include <stack>

using namespace std;
using namespace boost::multiprecision;

//重み付きグラフ
//距離の部分をテンプレートに
template<class T>
class wGraph {
public:
	int N;
	vector<multimap<int, T> >* E;
	wGraph(int n, T i) {
		N = n;
		E = new vector<multimap<int, T> >;
		E->resize(N);
		INF = i;
	}
	wGraph() {
	}
	void constructor(int n, T i) {
		N = n;
		E = new vector<multimap<int, T> >;
		E->resize(N);
		INF = i;
	}
	~wGraph() {
		delete E;
	}
	void addEdge(int a, int b, T c) {
		E->at(a).emplace(b, c);
	}
	bool isConnected(int a, int b) {
		return (E->at(a).find(b) != E->at(a).end());
	}
	T INF;
};

//ダイクストラする
//条件:重み>0
//グラフ本体、始点、保存用vector
//到達不可能はg.INF
//O(ElogV)
template<class T>
void  dijkstra(wGraph<T>& g, int s, vector<T>& v) {
	v.resize(g.N);
	for (int i = 0; i < g.N; i++) {
		v[i] = g.INF;
	}
	typedef pair<T, int> t;
	priority_queue<t, vector<t>, greater<t>> q;
	q.push(t(0, s));
	while (!q.empty()) {
		t e = q.top();
		q.pop();
		if (v[e.second] != g.INF && v[e.second] <= e.first)continue;
		v[e.second] = e.first;
		for (auto itr = g.E->at(e.second).begin(); itr != g.E->at(e.second).end(); itr++) {
			q.push(t(e.first + (*itr).second, (*itr).first));
		}
	}
	return;
}

wGraph<long long> G;
int N, K,Q;
vector<long long> vec,ans;

void solve() {
	cin >> N;
	G.constructor(N, LLONG_MAX);
	for (int n = 0; n < N-1; n++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		G.addEdge(a, b, c);
		G.addEdge(b, a, c);
	}
	cin >> Q >> K;
	K--;
	dijkstra(G, K, vec);
	for (int q = 0; q < Q; q++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		ans.push_back(vec[a]+vec[b]);
	}
	for (auto itr = ans.begin(); itr != ans.end(); itr++)cout << *itr << endl;
	return;
}

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

template <typename T>
void print(const T &v);

int main()
{
    int64_t a;
    double b;
    cin >> a >> b;

    int64_t b2 = (int64_t)llround(b * 100.0);
    cout << a * b2 / 100 << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3772
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder {

    public class Program {
        public static void Main (string[] args) {
            new Program ().Solve (new ConsoleInput (Console.In, ' '));
        }

        public void Solve (ConsoleInput cin) {
            // WriteLine ("入力");
            var NK = cin.ReadLongArray (2);
            var H = cin.ReadLongArray (NK[0]).ToList ();

            H.Sort ((a, b) => { return (int) (b - a); });

            long count = 0;

            for (int i = 0; i < H.Count; i++) {
                if (i + 1 > NK[1]) {
                    count += H[i];
                }
            }

            Console.WriteLine (count);
        }

    }

    public class ConsoleInput {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput (System.IO.TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string> ();
        }
        public string Read {
            get {
                if (inputStream.Count != 0) return inputStream.Dequeue ();
                string[] tmp = _stream.ReadLine ().Split (_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue (tmp[i]);
                return inputStream.Dequeue ();
            }
        }
        public string ReadLine { get { return _stream.ReadLine (); } }
        public int ReadInt { get { return int.Parse (Read); } }
        public long ReadLong { get { return long.Parse (Read); } }
        public double ReadDouble { get { return double.Parse (Read); } }
        public string[] ReadStrArray (long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray (long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray (long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 38460
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=12e5,mo=1e9+7;

char s[N]; 
int n;
ll gs[N];
int c[N];
ll f[N];
int ne[N],la[N];

int main()
{
	scanf("%d",&n);
	int k=n;
	fo(i,1,n){
		scanf("%d",&c[i]);
		if(c[i]==c[i-1])--i,--n;
	}
	fo(i,1,n){
		ne[la[c[i]]]=i;
		la[c[i]]=i;
	}
	f[1]=1;
	fo(i,1,n){
		f[i]=(f[i-1]+f[i])%mo;
		if(ne[i])f[ne[i]]=(f[ne[i]]+f[i])%mo;
	}
	cout<<f[n];
}

Measured memory_bytes: 9216
# coding:utf-8


INF = float('inf')


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


N, X = inpl()
A = inpl()
B = [0]
for a in A:
    B.append(B[-1] + a)

ans = INF
for k in range(1, N + 1):
    e = 5
    cur = N - k
    tmp = e * (B[N] - B[cur]) + (N + k) * X
    cur -= k
    while True:
        tmp += e * (B[cur + k] - B[max(cur, 0)])
        if cur <= 0:
            break
        e += 2
        cur -= k

    ans = min(ans, tmp)

print(ans)


Measured memory_bytes: 26020
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)



int main(){
ll K,N;
cin>>K>>N;
vector<ll> A(N);


for(ll i=0;i<N;i++){
cin>>A[i];
}
sort(ALL(A));

ll mp=-1;
ll m = (K-A[N-1])+A[0];
for(ll i=0;i<N-1;i++){
    if(A[i+1]-A[i]>m){
        m=A[i+1]-A[i];
        mp=i;
    }
}

if(mp==-1){
    cout<<A[N-1]-A[0]<<endl;
    return 0;
}

cout<<K-A[mp+1]+A[mp]<<endl;














}

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

int main(){
   int D,T,S;
   cin>>D>>T>>S;
   if((double)D/T <= S){
       cout << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }
}

Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>

using namespace std;

using llint = long long;

const int MAXN = 20;

int lim;
int a[MAXN][MAXN];
llint mem[1 << MAXN];
llint pre[1 << MAXN];
bool solved[1 << MAXN];
int n;

void print_mask(int mask) {
  for (int i = 0; i < 32; ++i) {
    printf("%d", (mask >> i) & 1);
  }
  printf("\n");
}

llint calc(int mask) {
  llint ret = 0;
  for (int i = 0; i < n; ++i) {
    if (((mask >> i) & 1) == 0) continue;
    for (int j = 0; j < n; ++j) {
      if (((mask >> j) & 1) == 0) continue;
      ret += a[i][j];
    }
  }
  return ret/2;
}


llint dp(int mask) {
  if (mask == (1 << n) - 1) return 0;
  llint &ret = mem[mask];
  if (solved[mask]) return ret;
  solved[mask] = 1;

  for (int i = ~mask & lim; true; --i) {
    i &= ~mask & lim;
    if (i == 0) break;
    ret = max(ret, dp(i | mask) + pre[i]);
  }

  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      scanf("%d", &a[i][j]);
    }
  }

  lim = (1 << n) - 1;
  for (int i = 0; i <= lim; ++i) {
    pre[i] = calc(i);
  }

  printf("%lld\n", dp(0));
  return 0;
}


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


int n,k;
long long ans;

int main()
{
    cin >> n >> k;

    for(int i=k+1;i<=n;i++)
    {
        int q = (n+1)/i-1;
        ans += (q+1) * (i-k);
        int a = (q+1) * i+k;
        if(a <= n) ans+= min(n-a+1, i-k);
    }
    if(k == 0) ans -= n;
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<
    pair<int, int>,
    null_type,
    less_equal<pair<int, int>>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define lb(v, z) lower_bound(all(v), z)
#define ub(v, z) upper_bound(all(v), z)
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rdp(i, a, b) for (int i = (a); i >= (b); i--)
#define rlt(i, a, b) for (int i = (a); i < (b); i++)
#define cns(z) cout << (z) << ' '
#define cnl(z) cout << (z) << '\n'
#define M1 1000000007
#define M2 998244353
#define MAXN 300005
#define INF (1ll << 60)
#define endl "\n"
#define garr(ip)       \
    for (auto &x : ip) \
        cin >> x;
#define parr(ip)          \
    for (auto &x : ip)    \
        cout << x << " "; \
    cout << endl;
#define nl cout << endl
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vp;

void solve(int testCaseNumber = 1)
{
    char ch;
    cin >> ch;
    if (ch >= 'a' and ch <= 'z')
        cout << 'a';
    else
        cout << 'A';
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
long long l[200003],n,d,dpl[200003],dpr[200003],ans;
int main(){
	cin>>n>>d;
	ans+=(n-1)*d;
	for(int i=0;i<n;i++)
		cin>>l[i],
		ans+=l[i];
	dpr[0]=l[0];dpl[n-1]=l[n-1];
	for(int i=1;i<n;i++)
		dpr[i]=min(l[i],dpr[i-1]+d);
	for(int i=n-2;i>=0;i--)
		dpl[i]=min(l[i],dpl[i+1]+d);
	for(int i=1;i<n-1;i++)
		ans+=min(dpl[i],dpr[i]);
	cout<<ans;
}


Measured memory_bytes: 4992
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long D, G;
    scan(D, G);
    auto P_orig = new long[](D);
    auto C = new long[](D);
    foreach (i; 0 .. D)
        scan(P_orig[i], C[i]);

    long ans = long.max;

    foreach (comp; 0 .. (1 << D))
    {
        auto P = P_orig.dup;
        long score;
        long cnt;
        foreach (i; 0 .. D)
            if (comp & (1 << i))
            {
                cnt += P[i];
                score += P[i] * 100 * (i + 1);
                score += C[i];
                P[i] = 0;
            }
        if (G <= score)
        {
            ans = ans.min(cnt);
            continue;
        }
        foreach_reverse (i; 0 .. D)
        {
            long need = (G - score + (100 * (i + 1) - 1)) / (100 * (i + 1));
            long c = min(need, P[i]);
            // writefln("%s %s %s %s %s", comp, G - score, i, need, P[i]);
            score += c * (100 * (i + 1));
            cnt += c;
            if (G <= score)
                break;
        }
        ans = ans.min(cnt);
    }
    writeln(ans);
}


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

using namespace std;

#define MAXN 100005
#define INF 1000000000000000LL
#define MOD 10007
#define pb push_back

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

int n, w;
ll dp[100005];

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

	cin >> n >> w;

	ll weight;
	int value;

	for(int i = 1; i < MAXN; i++) dp[i] = INF;

	dp[0] = 0;

	for(int i = 1; i <= n; i++){
		cin >> weight >> value;
		for(int j = MAXN - 1; j >= value; j--){
			if(dp[j - value] != INF) dp[j] = min(dp[j], dp[j - value] + weight);
		}
	}

	int res = 0;

	for(int i = MAXN - 1; i >= 0; i--){
		if(dp[i] <= w){
			res = i;
			break;
		}
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define p pair<int,int>
#define P pair<ll,ll>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define db double
#define zero(a) memset(a,0,sizeof(a))
#define inff(a,n) fill(a,a+n+1,inf)
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define write(x) printf("%d\n",x)

const int maxn=1e6;
const ll inf=1e9;
const int base1=31,base2=127;

int n,m,cnt,ans,flag=1,a[maxn];
vector<int>v[maxn];

void dfs(int u,int fa)
{
    for(auto i:v[u])
    {
        if(i==fa)continue;
        if(a[i]==-1)
        {
            a[i]=(a[u]^1);
            dfs(i,u);
        }
        else flag&=(a[i]^a[u]);
    }
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    memset(a,-1,sizeof(a));
    a[1]=0;
    dfs(1,0);
    if(flag)
    {
        for(int i=1;i<=n;i++)if(a[i])cnt++;
        cout<<1ll*cnt*(n-cnt)-m;
    }
    else
    {
        cout<<1ll*n*(n-1)/2-m;
    }
    return 0;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 1e9 + 7
#define ALL(v) v.begin(), v.end()

bool compare(P a, P b){
    return a.first > b.first;
}

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

    int N,M;
    cin >> N >> M;
    priority_queue<ll> pq;
    rep(i,N){
        ll a;
        cin >> a;
        pq.push(a);
    }
    
    rep(i,M){
        pq.push(pq.top() / 2);
        pq.pop();
    }
    
    ll ans = 0;
    while(!pq.empty()){
        ans += pq.top();
        pq.pop();
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1400
import numpy as np
import sys

def main():
    n = input()
    a = list(map(int, input().split()))

    a.sort()
    ret = (a[0] + a[1])/2

    for i in range(2, len(a)):
        ret = (ret+a[i])/2
    

    
    print(ret)
        


if __name__ == '__main__':
    main()

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

using namespace std;

int main(void)
{
	int a, b, c, x;
	cin >> a >> b >> c >> x;

	int num = 0;

	for (int i = 0; i < a + 1; i++)
	{
		for (int j = 0; j < b + 1; j++)
		{
			for (int k = 0; k < c + 1; k++)
			{
				if (i * 500 + j * 100 + k * 50 == x)
					num++;
			}
		}
	}

	cout << num << endl;

	return 0;
}

Measured memory_bytes: 256
//*******Abhijit Burman***********//
//Jalpaiguri Government Engineering College//

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define MAXX (1000000000000000000+7)
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

ll dp[100000][3];
ll a[100000][3];

ll count(int i, int j, ll n)
{
	//cout<<n<<endl;
	if(i == n)
	{
		return 0;
	}
	if(dp[i][j]!=-1)
	    return dp[i][j];
	else
	{
		ll maxi = 0;
		for(int k=0;k<3;k++)
		{
			if(k!=j || i==0)
			{
				maxi = max(a[i][k]+count(i+1,k,n),maxi);
			}
		}
		return dp[i][j] = maxi;
	}
	
}


void solve()
{
	memset(dp,-1,sizeof(dp));
	ll n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>a[i][j];
		}
	}

	ll ans = count(0,0,n);
	cout<<ans<<endl;
	
	//cout<<a<<" "<<b<<" "<<c<<endl;
}

int main()
{
	/*#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif*/

    //main code starts here//
    fio;
    ll t=1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }


    //code ends///
    /*#ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif*/
	return 0;

		
}


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

int main(void) {
  while (1) {
    int n;
    cin >> n;
    if (n == 0) break;

    map<int, int> bridge;
    bridge[-1] = 0;
    while (n--) {
      int m, a, b;
      cin >> m >> a >> b;
      if (bridge.find(a) == bridge.end()) {
        bridge[a] = m;
      } else {
        bridge[a] += m;
      }
      if (bridge.find(b) == bridge.end()) {
        bridge[b] = -m;
      } else {
        bridge[b] -= m;
      }
    }

    bool flag = false;
    map<int, int>::iterator b_iter = bridge.begin(), iter = bridge.begin();
    iter++;
    while (iter != bridge.end()) {
      iter->second += b_iter->second;
      //cout << "# bridge[" << iter->first << "]: " << iter->second << endl;
      if (iter->second > 150) {
        flag = true;
        break;
      }
      b_iter++;
      iter++;
    }

    if (flag) {
      cout << "NG" << endl;
    } else {
      cout << "OK" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1196
n = int(input())
A = [int(i) for i in input().split()]

def countingSort(A, k):
    B = [0] * len(A)
    C = [0]*(k+1)
    
    for j in range(len(A)):
        C[A[j]] += 1
    for i in range(1, k+1):
        C[i] += C[i-1]
    
    for j in range(len(A)-1, -1, -1):
#         print(B, A[j], C[A[j]])
        B[C[A[j]]-1] = A[j]
        C[A[j]] -= 1
    return B

A = countingSort(A, max(A))
print(" ".join([str(s) for s in A]))


Measured memory_bytes: 225912
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    auto R = new long[](9);
    foreach (a; A)
    {
        R[min(a / 400, 8)]++;
    }
    long cnt;
    foreach (i; 0 .. 8)
        if (R[i] != 0)
        {
            cnt++;
        }
    writefln("%s %s", max(cnt, 1), cnt + R[8]);
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define repa(i, a, b) for (auto i = (a); i <= (b); i++)
#define repd(i, a, b) for (auto i = (a); i >= (b); i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define zero(a)  memset((a), 0, sizeof (a))
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back

constexpr auto inf = numeric_limits<int>().max() - 1;
constexpr auto llinf = numeric_limits<ll>().max() - 1LL;

template<typename ForwardIterator>
void dump(ForwardIterator st, ForwardIterator en) {
  for (auto it = st; it != en; it++) {
    cout << *it << " ";
  }
  cout << endl;
}

template<typename ForwardIterator>
void dump_map(ForwardIterator st, ForwardIterator en) {
  for (auto it = st; it != en; it++) {
    cout << (*it).first << ":" << (*it).second << " ";
  }
  cout << endl;
}
template<typename T>
void debug(initializer_list<T> list) {
  for (auto el : list) {
    cout << el << " ";
  }
  cout << endl;
}

constexpr ll mod = ll(1e9 + 7);

ll mult(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }

ll power(ll a, ll b) {
  ll result = 1LL;
  while (b) {
    if (b % 2LL) result = mult(result, a);
    a = mult(a, a);
    b /= 2LL;
  }
  return result;
}

ll divide(ll a, ll b) { return mult(a, power(b, mod - 2)); }

ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }

ll subtract(ll a, ll b) { return ((a - b) % mod + mod) % mod; }

void solve() {
  int n;
  cin >> n;
  vi h(n);
  for (auto &it : h) cin >> it;
  vi memo(n, -1);
  memo[0] = 0;
  function<int(int)> dp = [&] (int i) -> int {
    if (memo[i] != -1) return memo[i];
    int val = dp(i - 1) + abs(h[i] - h[i - 1]);
    if (i > 1) val = min(val, dp(i - 2) + abs(h[i] - h[i - 2]));
    memo[i] = val;
    return val;
  };
  cout << dp(n - 1);
  cout << "\n";
}

#define REPEAT 0
#define CASE 0

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #if REPEAT
    int t;
    cin >> t;
    repa(i, 1, t) {
      #if CASE
        cout << "Case #" << i << ": ";
      #endif
      solve();
    }
  #else
    solve();
  #endif
  return 0;
}


Measured memory_bytes: 10240
#include<stdio.h>

void show(int a[], int n){
  int i;
  for(i=0; i<n-1; i++){
    printf("%d ", a[i]);
  }
  printf("%d", a[n-1]);
  printf("\n");
  return ;
}

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

int main(){
  int n, i;
  int a[101];
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &a[i]);
  }
  show(a, n);
  insertion(a, n);
  return 0;
}

Measured memory_bytes: 1812
#include <cmath>
#include <iostream>

using namespace std;
int main(){
    int R0,w0,C,R;
    while(cin>>R0>>w0>>C>>R,R0){
        if(R0>=C*w0){
            cout<<0<<endl;
        }else{
            cout<<ceil(((double)C*w0-R0)/R)<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3188
# -*- coding: utf-8 -*-


def is_prime(number):
    if number == 2:
        return True
    elif number < 2 or number % 2 == 0:
        return False
    else:
        i = 3
        while i <= pow(number, 0.5):
            if number % i == 0:
                return False
            i += 2
        return True


if __name__ == '__main__':
    N = input()
    numbers = [input() for i in xrange(N)]
    count = 0
    for i in xrange(len(numbers)):
        if is_prime(numbers[i]):
            count += 1
    print count

Measured memory_bytes: 6824
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8101145141919364364;

int main(){
	int h,w; cin>>h>>w;
	int a[h][w];
	rep(i,h)rep(j,w) cin>>a[i][j];
	vector<pair<int,int>> from;
	vector<pair<int,int>> to;
	for(int i=0;i<h;i++){
		if(i%2){
			for(int j=w-1;j>=0;j--){
				if(a[i][j]%2==1&&a[i][j]!=0){
					if(j==0){
						if(i+1<h){
							a[i+1][j]++;
							from.push_back({i,j});
							to.push_back({i+1,j});
						}
					}else{
						a[i][j-1]++;
						from.push_back({i,j});
						to.push_back({i,j-1});
					}
				}
			}
		}else{
			for(int j=0;j<w;j++){
				if(a[i][j]%2==1&&a[i][j]!=0){
					if(j==w-1){
						if(i+1<h){
							a[i+1][j]++;
							from.push_back({i,j});
							to.push_back({i+1,j});
						}
					}else{
						if(j+1<w){
							a[i][j+1]++;
							from.push_back({i,j});
							to.push_back({i,j+1});
						}
					}
				}
			}
		}
	}
	int n=from.size();
	cout<<n<<endl;
	rep(i,n){
		printf("%d %d %d %d\n",from[i].first+1,from[i].second+1,to[i].first+1,to[i].second+1);
	}
	return 0;
}


Measured memory_bytes: 5228
/* ***********************************************
Author        :yang12138
Created Time  :2017/8/8 15:54:35
File Name     :D.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;

const int N=105;
int a[N*N],ans[N][N];
int h,w,n;

int x,y;
void fuck(int val){
	ans[x][y]=val;

	if(x&1){
		if(y==w) x++;
		else y++;
	}
	else{
		if(y==1) x++;
		else y--;
	}
}

void solve(){
	scanf("%d%d%d",&h,&w,&n);
	x=y=1;
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		while(a[i]--) fuck(i);
	}

	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++) printf("%d ",ans[i][j]);
		printf("\n");
	}

}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    
	solve();
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<unordered_map>
#include<math.h>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#include<iomanip>
#include<string>
#include<map>
#define PI 3.14159265
#define mod 998244353  
#define mod1 1e9 + 7  
using namespace std;

void func(){
   int n ;
   cin >> n ; 
   long long arr[n + 1], dp[n + 1][n + 1];

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

   for(int i = 1 ; i <= n ; ++i){
       dp[i][i] = arr[i];
   } 

   for(int i = 1 ; i <= n ; ++i){
       int cnt = 1;
       for(int j = i + 1 ; j <= n ; ++j ){
           dp[cnt][j] = max(arr[cnt] - dp[cnt + 1][j], arr[j] - dp[cnt][j - 1]);
           ++cnt;
       }
   }

cout << dp[1][n];
}

int main(){
    int t = 1 , cnt = 0 ;
  //  cin >> t;
    
    while(t--){  
        func();
    }
}

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

int main(){
  string S;
  cin >> S;
  if(S=="SSS"){
    cout << 0 << endl;
  }
  else if(S=="SSR" || S=="SRS" || S=="RSS" || S=="RSR"){
    cout << 1 << endl;
  }
  else if(S=="SRR" || S=="RRS"){
    cout << 2 << endl;
  }
  else{
    cout << 3 << endl;
  }
}

Measured memory_bytes: 3620
function fillZero(l,num) {
	num = String(num)
	for (var i = num.length; i < l; i++) {
		num = "0" + num
	}
	return num
}

function Main(input) {
    input = input.split("\n");
    var N = parseInt(input[0].split(" ")[0]);
    var M = parseInt(input[0].split(" ")[1]);
    C = new Array(M);
    P = new Array(0);
    for (i = 0; i < M; i++) {
        tmp = input[i + 1].split(" ");
        Csub = [parseInt(tmp[0]), parseInt(tmp[1]), i];
        C[i] = Csub;
    }
	// console.log(JSON.stringify(C))
    C.sort(function (a, b) {
        if (a[0] < b[0]) return -1;
        if (a[0] > b[0]) return 1;
        if (a[1] < b[1]) return -1;
        if (a[1] > b[1]) return 1;
        return 0;
    });
    // console.log(JSON.stringify(C))

    for (i = 0; i < M; i++) {
		var cnt 
        if (i == 0) {
            cnt = 1;
        } else if (C[i][0] != C[i - 1][0]) {
            cnt = 1;
        } else {
            cnt++;
        }
        P.push(
			[C[i][0], cnt, C[i][2]]
		);
    }
	// console.log(JSON.stringify(P))
    P.sort(function (a, b) { return a[2] - b[2] });
	// console.log(JSON.stringify(P))

	for (var i = 0; i < P.length; i++) {
		console.log(fillZero(6, P[i][0]) + fillZero(6, P[i][1]))
	}
}
function debug() {
    var input = document.getElementById("input").value;
    Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 71888
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;



int main()
{
	int n, k, a[100010];
	while(cin >> n >> k)
	{
		if(n==0 && k==0) break;
		rep(i, n) cin >> a[i];
		int sum=0, ans;
		rep(i, k) sum+=a[i];
		ans=sum;
		rep(i, n-k)
		{
			sum+=(a[i+k]-a[i]);
			ans=max(sum, ans);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3448
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;





int main(){
    
    int N,W;
    cin >> N >> W;
    vector<int> w(N);
    vector<ll> v(N);
    
    rep(i,N) cin >> w[i] >> v[i];
    
    vector<vector<ll> > dp;
    dp.assign(N+1, vector<ll>(W+1, 0));
    
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if (j+w[i] <= W) {
                dp[i+1][j+w[i]] = max(dp[i][j]+v[i], dp[i+1][j+w[i]]);
            }
            
            
        }
        
    }
    
   
    
    cout << dp[N][W] << endl;
    
    
    return 0;
}


Measured memory_bytes: 80256
#include<stdio.h>

int main (void)
{
	int a,b;

	scanf("%d%d",&a,&b);


    if(a<b)

	{

		printf("a < b\n");

	}

	if(a>b)

	{

		printf("a > b\n");

	}

	if(a==b)

	{

		printf("a == b\n");

	}


return 0;


}

Measured memory_bytes: 580
N=int(input())
A=list(map(int, input().split()))

l = 0
r = 0
s = 0 #対象区間のAND和
res = 0
#尺取り法
for l in range(N):
    while (r<N)and(s^A[r]==s+A[r]):
        #条件を満たす限りrightを右に進める
        s += A[r]
        r += 1
    #進めた幅だけ条件を満たす区間が存在したことになる
    res += r-l
    if l == r:
        #停滞した場合、rを1つ右にずらして次のlとrを等しくする
        r += 1
    else:
        # そうでない場合、lを一つ進めるので、今のlに対応する数を
        # AND和から引いておく
        s -= A[l]
print(res)

Measured memory_bytes: 100552
// https://ynucpc.github.io/blog/2018/04/15/cp_vscode/
// http://www.atmarkit.co.jp/ait/articles/1509/08/news019.html

#include <bits/stdc++.h>
#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 rep3(i,n,m) for(ll i=(n);i<(ll)(m);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b)) 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int _stoi(string s, int tmp=10){
	istringstream stm(s);
	int res;
	stm >> res;
	return res;
}
double _stod(string s, int tmp=10){
	istringstream stm(s);
	double res;
	stm >> res;
	return res;
}
template<typename T>string to_string(const T& n){
	std::ostringstream stm;
	stm << n;
	return stm.str();
}

// 降順ソート: sort(A, A+N, greater<>());
// min: *min_element(A, A+N)
// argmin: min_element(A, A+N)-A

ll gcd(ll a, ll b){
	if (a==0){
		return b;
	}else{
		return gcd(b%a, a);
	}
}


int main(){	
	// ll A; cin >> A;
	// cout << "hello" << _stoi("14") << max({1,3}) << endl;
	ll a[5], k;
	rep(i, 5){
		cin >> a[i];
	}
	cin >> k;
	if (a[4] - a[0] > k){
		cout << ":(" << endl;
	}else{
		cout << "Yay!" << endl;
	}
}








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

signed main() {
	ll N, Z, W;
	cin >> N >> Z >> W;
	vector<ll> A(N);
	for(auto &a : A) cin >> a;
	// dp[i][j] : 山札i番目, j:0は先行, 1は後攻
	vector<vector<ll>> dp(N, vector<ll>(2));
	for(int i=0;i<N;i++) dp[i][0] = LLONG_MIN;
	for(int i=0;i<N;i++) dp[i][1] = LLONG_MAX;
	for(int i=N-1;i>=0;i--) {
		// 0のとき
		ll other = (i ? A[i-1] : W);
		dp[i][0] = max(dp[i][0], llabs(A[N-1] - other));
		for(int j=i+1;j<N;j++) dp[i][0] = max(dp[i][0], dp[j][1]);

		// 1のとき
		other = (i ? A[i-1] : Z);
		dp[i][1] = min(dp[i][1], llabs(A[N-1] - other));
		for(int j=i+1;j<N;j++) dp[i][1] = min(dp[i][1], dp[j][0]);

	}
	cout << dp[0][0] << endl;
}

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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int H1, M1, H2, M2, K;
   cin >> H1 >> M1 >> H2 >> M2 >> K;
   int Z1 = H1 * 60 + M1;
   int Z2 = H2 * 60 + M2;
   cout << max(Z2 - Z1 - K, 0);
}


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

#define M 2000000
#define L 14

char H[M][L];

int getChar( char ch )
{
	if( ch == 'A') {
		return 1;
	} else if( ch == 'C') {
		return 2;
	} else if( ch == 'G') {
		return 3;
	} else if( ch == 'T') {
		return 4;
	} else {
		return 0;
	}
}

long long getKey( char str[] )
{
	long long sum = 0, p = 1, i;
	for ( i=0; i<strlen(str); i++ ) {
		sum += p*( getChar( str[i] ) );
		p *= 5;
	}
	return sum;
}

int find( char str[] )
{
	int i, hashkey;
	for( i=0; i<M; i++  ) {
		hashkey = ( getKey( str ) + (2*i+1)*getKey( str ) )%M;
		if( '\0' == H[ hashkey ][0] ) {
			return 0;
		} else {
		    if( 0 == strcmp( H[ hashkey ], str ) ) {
		    	return 1;
		    }
		}
	}
	return 0;
}

void insert( char str[] )
{
	int i, hashkey;
	for( i=0; i<M; i++ ) {
		hashkey = ( getKey( str ) + (2*i+1)*getKey( str ) )%M;
		if( '\0' == H[ hashkey ][0] ) {
			strcpy( H[ hashkey ], str );
			break;
		}
	}
    return;
}

int main() 
{

	int i, n;
	char str[L], com[9];
	
	for ( i=0; i<M; i++ ) {
		H[i][0] = '\0';
	}
	scanf( "%d", &n );
	for ( i=0; i<n; i++ ) {
		scanf( "%s %s", com, str );
		if ( com[0] == 'i' ){
			insert( str );
		} else {
			if( find( str ) ){
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}

    return 0;
}

Measured memory_bytes: 27952
N = int(input())
a = list(map(int, input().split()))
m = 0
b = []
for i in range(N):
    if a[i]<0:
        m += 1
for i in range(N):
    b.append(abs(a[i]))
if m%2 == 0:
    print(sum(b))
else:
    print(sum(b)-2*min(b))


Measured memory_bytes: 14252
using System;
class p
{
  static void Main()
  {
    string w = Console.ReadLine();
    bool result = true;
    while (0 < w.Length) {
      int a = w.Length;
      w = w.Replace(w[0].ToString(), "");
      int b = w.Length;
      if ((a - b) % 2 == 1) {
        result = false;
        break;
      }
    }
    Console.WriteLine(result ? "Yes" : "No");
  }
}

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

int main()
{
    int n,i=0,s=1,j,m;
    cin >> n;
    string str[n];
    for (i=0;i<n;i++)
        cin >> str[i];
    m=i=1;
    while (m<=n)
    {
        if (str[i][0]==str[i-1][str[i-1].size()-1])
            i++;
        m++;
    }
    if (i+1!=m)
    {
        cout << "No";
        return 0;
    }
    else
    {
        for (i=0;i<n;i++)
            for (j=i+1;j<n;j++)
                if (str[i]==str[j])
                    s=-1;
    }
    if (s==-1)
        cout << "No";
    else
        cout << "Yes";
    return 0;
}


Measured memory_bytes: 3624
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0507

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

class SquaresManager {
public:
	map<int, vector<string>> solutions;
	vector<string> solve(int numOfsquares);
};

vector<string> SquaresManager::solve(int numOfSquares) {
	try {
		return solutions.at(numOfSquares);
	} catch (out_of_range& e) {
		vector<string> solution;
		solution.push_back(to_string(numOfSquares));
		for (int numOfFirstBlocks = numOfSquares - 1; numOfFirstBlocks >= 1; numOfFirstBlocks--) {
			vector<string> setOfSubSolution = solve(numOfSquares - numOfFirstBlocks);
			for (auto pSolution = setOfSubSolution.begin(); pSolution != setOfSubSolution.end(); ++pSolution) {
				if (numOfFirstBlocks >= atoi(&(*pSolution)[0])) {
					solution.push_back(to_string(numOfFirstBlocks) + " " + *pSolution);
				}
			}
		}
		solutions.insert({ numOfSquares, solution });
		return solution;
	}
}

int main (){
	vector<int> setOfProblems;

	while (true) {
		int input;
		cin >> input;
		if (input == 0) {
			break;
		} else {
			setOfProblems.push_back(input);
		}
	}

	SquaresManager mng;
	for (auto itProblem = setOfProblems.begin(); itProblem != setOfProblems.end(); ++itProblem) {
		vector<string> solution = mng.solve(*itProblem);
		for_each(solution.begin(), solution.end(), [](string arrangement) {cout << arrangement << endl; });
	}
}

Measured memory_bytes: 5012
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
 {
    int n,sum=0;
    cin>>n;

    ll a[n] = {0};

    for(int i=0;i<n;i++)
        cin>>a[i];
    
    for(int i=0;i<n-1;i++)
        for(int j=i+1;j<n;j++)
            sum+=a[i]*a[j];

    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  int A,B,M;
  cin>>A>>B>>M; 
  vector<int> a(A);  
  for(int j=0; j<A;j++){
    cin>>a.at(j);
  }
  vector<int> b(B);  
  for(int j=0; j<B;j++){
    cin>>b.at(j);
  }
  vector<int> x(M);  
  vector<int> y(M);  
  vector<int> c(M);  
  for(int j=0; j<M;j++){
    cin>>x.at(j)>>y.at(j)>>c.at(j);
    x.at(j)--;
    y.at(j)--;
  }
  int ans=1000000000;

  for(int i=0; i<M;i++){
    ans=min(ans,a.at(x.at(i))+b.at(y.at(i))-c.at(i));
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  ans=min(ans,a.at(0)+b.at(0));
  
  cout<<ans<<endl;
}



Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;

int main(){
  int K;
  cin >> K;
  
  vector<vector<int>> g(K+1,vector<int>(K+1,0));
  
  for(int i=1;i<=K;i++){
    for(int j=1;j<=i;j++){
      int n=j,m=i;
      while(n!=0){
	swap(n,m);
	n%=m;
      }
      g[i][j]=m;
      g[j][i]=m;
      }
  }


  ll ans=0;
  for(int i=1;i<=K;i++){
    for(int j=1;j<=K;j++){
      for(int k=1;k<=K;k++){
	ans+=g[i][g[j][k]];
      }
    }
  }

  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 3796
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;
bool CanRead(int &a)
{
	cin >> a;
	if (a == 0)
	{
		return false;
	}
	else
	{
		return true;
	}
}
int main()
{
	int a, b;
	vector<vector<int>> vect;
	while (CanRead(a)&&CanRead(b))
	{
		vector<int> tmp = { a,b };
		vect.push_back(tmp);

		string ans;

		for (size_t i = 0; i < a; i++)
		{
			for (size_t j = 0; j < b; j++)
			{
				if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1))
					ans += "#";
				else
					ans += ".";
			}
			ans += "\n";
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3200