akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
//	"sort"
)

type E struct {
	a, b, c int
}

const INF = 10000000000000

func main() {
	var nNode, nEdge int
	fmt.Scan(&nNode, &nEdge)

	g := make([][]E, nNode, nNode)
	for i := 0; i < nNode; i++ {
		g[i] = make([]E, 0, nNode)
	}

	for i := 0; i < nEdge; i++ {
		var e E
		fmt.Scan(&e.a, &e.b, &e.c)
		e.a--
		e.b--
		e.c = -e.c
		g[e.a] = append(g[e.a], e)
	}

	// for i := 0; i < nNode; i++ {
	// 	for j := 0; j < len(g[i]); j++ {
	// 		e := g[i][j]
	// 		fmt.Printf("{%d,%d,%d} ", e.a, e.b, e.c)
	// 	}
	// 	fmt.Println("")
	// }

	dist := make([]int, nNode, nNode)
	for i := 0; i < nNode; i++ {
		dist[i] = INF + INF
	}
	dist[0] = 0

	// for k := 0; k < nNode; k++ {
	// 	for i := 0; i < nNode; i++ {
	// 		for j := 0; j < len(g[i]); j++ {
	// 			e := g[i][j]
	// 			if dist[e.a] + e.c < dist[e.b] {
	// 				dist[e.b] = dist[e.a] + e.c
	// 			}
	// 		}
	// 	}
	// }
	// mini := dist[nNode-1]
	// for k := 0; k < nNode; k++ {
	// 	for i := 0; i < nNode; i++ {
	// 		for j := 0; j < len(g[i]); j++ {
	// 			e := g[i][j]
	// 			if dist[e.a] + e.c < dist[e.b] {
	// 				dist[e.b] = dist[e.a] + e.c
	// 			}
	// 		}
	// 	}
	// }
	// if dist[nNode-1] < mini {
	// 	fmt.Println("inf")
	// } else {
	// 	fmt.Printf("%d\n", -mini)
	// }

	for k := 0; k < nNode; k++ {
		for i := 0; i < nNode; i++ {
			for j := 0; j < len(g[i]); j++ {
				e := g[i][j]
				if dist[e.a] + e.c < dist[e.b] {
					dist[e.b] = dist[e.a] + e.c
					// fmt.Printf("%d,%d\n", e.b, dist[e.b])
					if k == nNode-1 {
						dist[e.b] = -INF
					}
				}
			}
		}
	}

	// for i := 0; i < nNode; i++ {
	// 	fmt.Printf("> %d\n", dist[i])
	// }

	if dist[nNode-1] == -INF {
		fmt.Println("inf")
	} else {
		fmt.Printf("%d\n", -dist[nNode-1])
	}
}


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

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

using namespace std;

using pii = pair<int, int>;
using tri = tuple<int, int, int>;

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    constexpr int INF = INT_MAX;

    int H, W, K, x1, y1, x2, y2;
    cin >> H >> W >> K >> x1 >> y1 >> x2 >> y2;
    --x1; --y1; --x2; --y2;
    vector<string> c(H);
    REP(i, H) cin >> c[i];

    vector<set<int>> s_h(H), s_v(W);
    REP(i, H) REP(j, W) {
        if (c[i][j] == '.') {
            s_h[i].insert(j);
            s_v[j].insert(i);
        }
    }

    vector<vector<int>> at_h(H, vector<int>(W + 1, 0)), at_v(W, vector<int>(H + 1, 0));
    REP(i, H) REP(j, W) {
        at_h[i][j + 1] = at_h[i][j] + (c[i][j] == '@');
    }
    REP(j, W) REP(i, H) {
        at_v[j][i + 1] = at_v[j][i] + (c[i][j] == '@');
    }

    vector<vector<int>> dp(H, vector<int>(W, INF));
    queue<pii> q;

    function<void(int, int, int)> update = [&](int x, int y, int d) {
        dp[x][y] = d;
        q.emplace(x, y);
        s_h[x].erase(y);
        s_v[y].erase(x);
    };

    update(x1, y1, 0);

    while (!q.empty()) {

        auto [x0, y0] = q.front();
        q.pop();
        int dn = dp[x0][y0] + 1;
        int x, y;

        // left
        x = x0;
        y = y0;
        while (true) {
            auto it = s_h[x].lower_bound(y);
            if (it == s_h[x].begin()) break;
            --it;
            y = *it;
            if (abs(y0 - y) > K || at_h[x][y0] != at_h[x][y]) break;
            update(x, y, dn);
        }

        // right
        x = x0;
        y = y0;
        while (true) {
            auto it = s_h[x].upper_bound(y);
            if (it == s_h[x].end()) break;
            y = *it;
            if (abs(y0 - y) > K || at_h[x][y0] != at_h[x][y]) break;
            update(x, y, dn);
        }

        // up
        x = x0;
        y = y0;
        while (true) {
            auto it = s_v[y].lower_bound(x);
            if (it == s_v[y].begin()) break;
            --it;
            x = *it;
            if (abs(x0 - x) > K || at_v[y][x0] != at_v[y][x]) break;
            update(x, y, dn);
        }

        // right
        x = x0;
        y = y0;
        while (true) {
            auto it = s_v[y].upper_bound(x);
            if (it == s_v[y].end()) break;
            x = *it;
            if (abs(x0 - x) > K || at_v[y][x0] != at_v[y][x]) break;
            update(x, y, dn);
        }
    }

    if (dp[x2][y2] == INF) {
        cout << (-1) << endl;
    } else {
        cout << dp[x2][y2] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 210612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  vector<int> pasta(3);
  vector<int> jus(2);
  rep(i,3)cin>>pasta[i];
  rep(i,2)cin>>jus[i];
  sort(all(pasta));
  sort(all(jus));
  cout<<pasta[0]+jus[0]-50<<endl;

}

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

int main(){
    // 入力
    char x, y;
    cin >> x >> y;

    // 処理
    // アルファベットの場合は、数字と同じように比較できる
    // 順序はアルファベット順(ABC...Z)に従う
    if(x == y){
        cout << "=" << endl;
    }else if(x < y){
        cout << "<" << endl;
    }else{
        cout << ">" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string>
#include <math.h>
using namespace std;
int main(void){
    float N, K;
    int ans;
    cin >> N >> K;
    
    ans = ceil((N-K)/(K-1)) + 1;
    
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

int dp[100010][4];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  cin >> s;
  int n = s.size();

  dp[0][0] = 1;
  dp[0][1] = dp[0][2] = dp[0][3] = 0;
  // dp[i][j] = (i番目まででj個使用)
  REP(i, n) {
    dp[i+1][0] = dp[i][0];
    dp[i+1][1] = dp[i][1];
    dp[i+1][2] = dp[i][2];
    dp[i+1][3] = dp[i][3];
    if(s[i] == 'A') (dp[i+1][1] += dp[i][0]) %= MOD;
    else if(s[i] == 'B') (dp[i+1][2] += dp[i][1]) %= MOD;
    else if(s[i] == 'C') (dp[i+1][3] += dp[i][2]) %= MOD;
    else {
      (dp[i+1][0] += dp[i][0]*2 % MOD) %= MOD;
      (dp[i+1][1] += dp[i][1]*2 % MOD + dp[i][0] % MOD) %= MOD;
      (dp[i+1][2] += dp[i][2]*2 % MOD + dp[i][1] % MOD) %= MOD;
      (dp[i+1][3] += dp[i][3]*2 % MOD + dp[i][2] % MOD) %= MOD;
    }
  }
  cout << dp[n][3] << endl;
  
  // REP(i, n+1) {
  //   REP(j, 4) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  uint64_t N;
  string S;
  cin >> N >> S;

  for (auto itr = S.begin(); itr != S.end(); itr++) {
    *itr += N;
    if (*itr > 'Z') {
      *itr -= 26;
    }
  }
  cout << S << endl;
  return 0;
}


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

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> dp(k+1);
	vector<int> a(n);
	for(auto &i:a)cin >> i;
	for(int i = 1;i<=k;i++)
	{
		bool flg = false;
		for(int j = 0;j<n;j++)
		{
			if(i-a[j]<0)break;
			if(dp[i-a[j]]==0)
			{
				flg = 1;
			}
		}
		if(flg)dp[i]=1;
	}
	cout << (dp[k]?"First":"Second") << endl;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<vector<ll> > AdjMat;

#define INF (ll)1e+18


AdjMat Warshall_Floyd(AdjMat& Gin){

	  AdjMat G = Gin;
	  int V = G.size();
	  for(int k=0; k<V; k++)
			for(int j=0; j<V; j++)
				  for(int i=0; i<V; i++)
						G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
	  return G;
}



int main(){

	  int V,E; cin >> V >> E;

	  AdjMat G(V,vector<ll>(V,INF));
	  for(int i=0; i<E; i++){
			ll s,t,d; cin >> s >> t >> d;
			G[s][t] = d;
	  }
	  for(int i=0; i<V; i++) G[i][i] = 0;

	  G = Warshall_Floyd(G);

	  for(int i=0; i<V; i++)
			if(G[i][i] != 0){	  cout << "NEGATIVE CYCLE" << endl;	  return 0;			}

	  for(int i=0; i<V; i++){
			for(int j=0; j<V; j++){
				  if(G[i][j] >= INF/10) cout << "INF";
				  else cout << G[i][j];
				  if(j==V-1) cout << endl;
				  else cout << " ";
			}
	  }
}
			
	  
			   

Measured memory_bytes: 1352
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
//#define int long long
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 && i % 5) ans += i;
	}
	cout << ans << '\n';
}

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

const int MOD = 1000000007;
const int MAX =200000;


int main() {
  int n;
  cin >> n;
  cout << (n % 2 == 0? n / 2: n / 2 + 1) << endl;
  return 0;
}

Measured memory_bytes: 256
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

n = inp[0]
t = inp
h = Hash.new(0)
t.each do |d|
  h[d] += 1
end
t = t.uniq.sort.reverse
f = true
if(h[t[0]] != 1)
  f = false
end
tree = na(n)
max = []
n.times{|i|max[i] = 2**i}
t.shift
t.each do |d|
  able = 1
  stock = h[d]
  n.times do |i|
    plable = tree[i]
    if(tree[i]<max[i])
      note = [[max[i]-tree[i], able-tree[i], stock].min, 0].max
      tree[i] += note
      stock -= note
    end
    able += plable
  end
  f = false if(stock != 0)
end
puts (f)? "Yes" : "No"


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

using namespace std;
using ll = long long;

#define INF (1LL << 60)

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll N;
    cin >> N;
    vector<vector<ll>> a(N, vector<ll>(3));
    REP(i,0,N) cin >> a[i][0] >> a[i][1] >> a[i][2];

    vector<vector<ll>> dp(N+1, vector<ll>(3, 0));

    REP(i,0,N) {
        REP(j,0,3) {
            REP(k,0,3) {
                if (j == k) continue;
                dp[i+1][k] = MAX(dp[i+1][k],dp[i][j]+a[i][k]);
            }
        }
    }

    ll M = 0;
    REP(i,0,3) {
        M = MAX(M,dp[N][i]);
    }

    _PR(M);

    return 0;
}

/*



*/

Measured memory_bytes: 11136
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int K = sc.nextInt();
    	String S = sc.next();
    	sc.close();
    	String S1,S2,S3;
    	if(K > 1) {
    		S1 = S.substring(0,K-1);
    	}else {
    		S1 = "";
    	}
    	S2 = S.substring(K-1,K);
    	if(K < N) {
    		S3 = S.substring(K,N);
    	}else {
    		S3 = "";
    	}
    	if(S2.equals("A")) {
    		S2 = "a";
    	}else if(S2.equals("B")) {
    		S2 = "b";
    	}else{
    		S2 = "c";
    	}
    	S = S1 + S2 + S3;
    	System.out.println(S);
    }
}

Measured memory_bytes: 23252
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        //Solve();
        return;
    }

    public static string Solve()
    {
        long N = ReadLong();
        long[] D = ReadLongs();
        long mod = 998244353;
        long ans = 1;
        long target = 1;
        long cnt = 0;

        if (D[0] != 0)
        {
            return "0";
        }
        Array.Sort(D);
        if (D[1] != 1)
        {
            return "0";
        }
        List<long> Dc = new List<long>();
        for (int i = 1; i < N; i++)
        {
            if (D[i] == target)
            {
                cnt++;
            }
            else if (D[i] == target + 1)
            {
                Dc.Add(cnt);
                target++;
                cnt = 1;
            }
            else
            {
                return "0";
            }
        }
        Dc.Add(cnt);
        for (int i = 0; i < Dc.Count - 1; i++)
        {
            ans = (ans * Pow(Dc[i], Dc[i + 1])) % mod;
        }
        return ans.ToString();
    }

    private static long Pow(long a, long b)
    {
        long mod = 998244353;
        long res = 1;
        for (long i = 0; i < b; i++)
        {
            res = (res * a) % mod;
        }
        return res;
    }


    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 19296
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
int N;
ll K;
ll C[100001]; // 0から10000とする

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

  cin >> N >> K;
  int a;
  ll b;
  rep(i, N){
    cin >> a >> b;
    C[a]+=b;
  }

  int ans = 0;
  rep(i, 100001){
    K-=C[i];
    if (K<=0){
      ans = i;
      break; 
    }
  }

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

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		double p = Math.log10(n);
		
		for(int i = 0 ; i < k ;i++) {
			int a = sc.nextInt();
			list.add(a);
		}
		int ans = n;
		
		while(true) {
			int temp = ans;
			int cnt = -1;
			while(temp > 0) {
				int x = temp % 10;
				if(list.contains(x)) {
					cnt = 0;
					break;
				}
				temp = temp/10;
			}
			if(cnt == -1) {
				break;
			}
			ans++;
		}
		
		System.out.println(ans);
	}	
}




Measured memory_bytes: 21844
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	var sum int
	for i := 0; i < n; i++ {
		sum += nextInt()
	}

	if sum%2 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 2176
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();
        if(a > 9 || b > 9){
            System.out.println(-1);
        }else{
            System.out.println(a * b);
        }
        sc.close();
    }
}

Measured memory_bytes: 35992
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
  long int n,k;
  long int i,j;
  long int sum=0;
  long int mod=1000000007;

  scanf("%ld %ld",&n,&k);

  for(i=k;i<=n+1;i++)
  {
    sum+=i*(n-i+1)+1;
    sum%=mod;
  }

  printf("%ld\n",sum);

  return 0;
}

Measured memory_bytes: 1720
#include<bits/stdc++.h>
using namespace std;
int dp[100001];
int solve(vector<int>&v,int n,int start)
{
if(start==n)
return 0;
if(start==n-1)
return abs(v[start-1]-v[n-1]);
if(dp[start]!=-1)
return dp[start];
int a=abs(v[start-1]-v[start+1]);
int b=abs(v[start-1]-v[start]);
if(dp[start+2]==-1)
a+=solve(v,n,start+2);
else
a+=dp[start+2];
if(dp[start+1]==-1)
b+=solve(v,n,start+1);
else
b+=dp[start+1];
int j= min(a,b);
dp[start]=j;
return j;
}
int main(){
   int n;
   cin>>n;
   vector<int>v(n);
   for (int i = 0; i < n; i++) {
      cin>>v[i];
   }
   memset(dp,-1,sizeof(dp));
   int r=solve(v,n,1);
   cout<<r<<endl;
   return 0;
}

Measured memory_bytes: 7980
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(__,v.size()){rep(_,v[__].size())cout<<" "<<v[__][_];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

signed main(){
	int n;
	cin>>n;
	vvi in(n,vi(2));
	rep(i,n)rep(j,2)cin>>in[i][j];
	sort(all(in),[](vi a,vi b){
		return a[0]+a[1]<b[0]+b[1];
	});
	vi dp(n+1,inf);
	dp[0]=0;
	rep(i,n){
		vi ndp=dp;
		rep(j,n){
			if(dp[j]<=in[i][0])
				cmin(ndp[j+1],dp[j]+in[i][1]);
		}
		dp=ndp;
	}
	int out=inf;
	rep(i,n+1)if(dp[i]-inf)out=i;
	cout<<out<<endl;
}
















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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }


void seethis(vector<ll>vect)
{
    for(ll x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / __gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

int main()
{
	FASTIO;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ll n;
	 cin>>n;
	 ll ans=0;
	 for(ll i=1;i<=n;i++)
	 {
	 	ll num= ((i)*(n/i)*(1+ (n/i)))/2;
	 	ans+=num;
	 }
	 cout<<ans<<"\n";




	return 0;
}

Measured memory_bytes: 3584
//In the name of God
#include<bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
string s;
int n, cnt;

int main(){
	cin >> s;	n = s.size();
	for(auto c : s){
		if(c == 'S')
			cnt++;
		else if(cnt){
			cnt--;
			n -= 2;
		}
	}
	cout << n;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin>>s;
  string t;
  cin>>t;
  int count=0;
  for(int i=0;i<s.length();i++){
    if(t[i]!=s[i])
      count++;
  }
  cout<<count;
}

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

main()
{
    int n; cin>>n;
    int k; cin>>k;
    vector<int> a(n);
    for(int&x:a) cin>>x;
    int ok=1e9; int ng=0;
    while(ok>ng+1)
    {
        int mid=(ok+ng)/2;
        int cnt=0;
        for(int x:a)
        {
            if(x>mid) cnt+=(mid+x-1)/mid-1;
        }
        if(cnt>k) ng=mid;
        else ok=mid;
    }
    cout<<ok<<endl;
}

Measured memory_bytes: 3932
#include<bits/stdc++.h>
#define N 100005
#define LL long long
#define INF (1LL<<60)
using namespace std;
int n,m; LL a[N],b[N],sum,ans=-INF;
int main()
{
	int i,x; char op;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		if(i==1) op='+'; else scanf("%c",&op);
		scanf("%d ",&x),sum+=x;
		if(op=='-') a[++m]=x; else b[m]+=x;
	  }
	if(!m) ans=sum;
	for(i=1;i<=m;i++){
		ans=max(ans,sum-2*(a[i]+b[i]));
		sum-=2*a[i];
	  }
	cout<<ans;
	return 0;
}


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

int main() {
    int N ;
    int a[120];
    cin >> N;
    for (int i = 0;i < N; i++){
        cin >> a[i];
    }
    int p = 0; 
    sort(a,a + N, greater<int>());
    for (int i = 0; i < N; i++){
        if(i % 2 == 0){
            p = p + a[i];
        } 
        else{
            p = p - a[i];
        }

    }
    cout << p << endl;

}

Measured memory_bytes: 256
N=int(input())
p=list(map(int, input().split()))
import copy
new_p=sorted(p)
cnt=0
a=[]
for i in range(N):
    if p[i]==new_p[i]:
        pass
    else: 
        cnt+=1
        a.append(i)
if cnt==2:
    newnew_p=copy.copy(p)
    newnew_p[a[0]]=p[a[1]]
    newnew_p[a[1]]=p[a[0]]
    if newnew_p==new_p:
        print("YES")
    else: print("NO")
elif cnt==0:
    print("YES")
else: print("NO")

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

using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;

int SZ;
int A[1010];
int B[1010];
int X[1010];
int TC[1010][5010], ST =0;
int ME[1010][5010];
int dpMax(int id, int X){
	if(id == SZ)return 0;
	if(TC[id][X] == ST)return ME[id][X];
	int w = 0;
	if(A[id] <= X){
		w = max(w, dpMax(id+1, X-A[id]) + A[id]);
	}
	if(B[id] <= X){
		w = max(w, dpMax(id+1, X-B[id]) + B[id]);
	}
	TC[id][X] = ST;
	return ME[id][X] = w;
}

VVI adj;
int POS = 1;
int dfs(int u, int p = -1){
	VI TA, TB;
	for(int v : adj[u]){
		int t = dfs(v, u);
		if(POS == 0)return 0;
		TA.push_back(X[v]);
		TB.push_back(t);
	}
	int SU = 0;
	int MIS = 0;
	for (int i = 0; i < TA.size(); ++i) {
		MIS += min(TA[i], TB[i]);
		SU += TA[i] + TB[i];
	}
	if(MIS > X[u]){
		POS = 0;
		return 0;
	}
	SZ = TA.size();
	for (int i = 0; i < SZ; ++i) {
		A[i] = TA[i];
		B[i] = TB[i];
	}
	ST++;
	int an = dpMax(0, X[u]);
	return SU - an;
	
}

int main(int argc,char *argv[]) {

	int N;
	cin >> N;
	adj = VVI(N);
	for (int i = 0; i < N-1; ++i) {
		int p;
		cin >> p;
		adj[p-1].push_back(i+1);
	}
	for (int i = 0; i < N; ++i) {
		cin >> X[i];
	}
	dfs(0);
	cout << (POS ? "POSSIBLE" : "IMPOSSIBLE") << endl;
	
	
}
	


Measured memory_bytes: 37760
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){

  int N, M; cin >> N >> M;
  priority_queue <ll> que;
  for (int i = 0; i < N; i++){
    ll A; cin >> A;
    que.push(A);
  }

  for (int i = 0; i < M; i++){
    ll now = que.top(); que.pop();
    que.push(now / 2);
  }
  
  ll ans = 0;
  while (!que.empty()){
    ans += que.top(); que.pop();
  }
  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 1400
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

int main() {
    int N, W; cin >> N >> W;
    vector<int> v(N), w(N);
    REP(i, N) {
        cin >> v[i] >> w[i];
    }
    // dp[i][j] : i番目までで重さjを作るときの価値の最大
    vector<ll> dp(W + 1, 0);
    REP(i, N) {
        REP(j, W + 1) {
            if (W - j - w[i] >= 0) {
                dp[W - j] = max(dp[W - j], dp[W - j - w[i]] + v[i]);
            }
        }
    }
    cout << dp[W] << endl;
    return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<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> 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);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


ll T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    while(cin >> n >> s){
        s = "B" + s;
        int p = 0; // 1 == '('
        ll ans = 1;
        ll lv = 0;
        REPS(i, 2 * n) {
            int x = p ^ (s[i - 1] == s[i]);
            if (x) {
                lv ++;
            } else {
                ans = ans * lv % MOD;
                lv --;
            }
            p = x;
        }
        if (lv != 0) ans = 0;
        REPS(i, n) ans = ans * i % MOD;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 788
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	vector<string>s(10);
	string h; cin >> h;

	for (int i = 0; i < 10; i++) {
		s[i] = h[i];
	}
	s[3] = "8";
	for (int i = 0; i < 10; i++) {
		cout << s[i];
	}


	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String s = scanner.nextLine().toLowerCase();
        int a = s.length();
        boolean flag = false;

            for (int i = 3; i < a; i+=2) {
                if (s.charAt(i)==s.charAt(i-1)) {
                    flag = true;
                }else {
                    flag = false;
                    break;
                }
            }

        if (flag==false){
            System.out.println("No");
        }else {
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 23636
#include <iostream>

using namespace std;

int N;
unsigned long long int L[87];


unsigned long long int calc(int x) 
{
	return L[x] ? L[x] : L[x] = calc(x - 1) + calc(x - 2);
}

void solve()
{
	L[0] = 2;
	L[1] = 1;
	cout << calc(N) << endl;
}


int main()
{
	cin >> N;
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int d[31][31];
int g[3][31];

int main(){
    int n, c;
    cin >> n >> c;
    rep(i, c){
        rep(j, c) cin >> d[i][j];
    }
    rep(i, n){
        rep(j, n){
            int col;
            cin >> col;
            g[(i+j)%3][col-1]++;
        } 
    }

    int ans = 1e9;

    rep(i, c){
        rep(j, c){
            rep(k, c){
                if(i != j && j != k && i != k){
                    int sum = 0;
                    rep(l, c) sum += g[0][l] * d[l][i];
                    rep(l, c) sum += g[1][l] * d[l][j];
                    rep(l, c) sum += g[2][l] * d[l][k];
                    ans = min(ans, sum);
                }
            }
        }
    }

    cout << ans << endl;
}

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

int n;
char c[101];
int g[101][101];
int t = 0;
int visit[101];
int finish[101];
int d[101];
int dist = 0;

void bfs(int start) {
    t++;
    queue<int> q;
    q.push(start);
    c[start] = 'g';
    visit[start] = t;
    while(!q.empty()) {
        t ++;
        int now = q.front();
        dist ++;
        for (int i = 1; i <= n ; ++i) {
            if(g[now][i] && c[i] == 'w') {
                q.push(i);
                c[i] = 'g';
                visit[i] = t;
                d[i] = d[now] + 1;
            }
        }
        q.pop();
        c[now] = 'b';
        finish[now] = t;
    }
}
int main() {
    cin >> n;
    for (int i = 1; i <= n ; ++i) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v;
            cin >> v;
            g[u][v] = 1;
        }
    }

    for (int l = 0; l < n; ++l) {
        c[l+1] = 'w';
    }

    for (int i1 = 1; i1 <=n ; ++i1) {
        d[i1] = -1;
    }
    for (int m = 1; m <= n ; ++m) {
        d[1] = 0;
        if(c[m] == 'w') bfs(m);
        break;

    }
    for (int j1 = 1; j1 <=n ; ++j1) {
        cout << j1 << " " << d[j1] << endl;
    }

    return 0;
}



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

int main()

{
	char a[1000], b[1000], c[1000];
	scanf("%s%s%s", a, b, c);
	int l1=strlen(a), l2=strlen(b);
	if(a[l1-1]==b[0]&&b[l2-1]==c[0])
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}



Measured memory_bytes: 128
#include <stdio.h>

int main() {
  int data[101][1001];
  int n,m,a;
  int h,p,q;
  int i,j;
  int hmax;
  int flag;

  hmax = 0;
  while(1){
    for(i = 0;i < 101; i++){
      for(j = 0; j < 1001;j++){
	data[i][j] = 0;
      }
    }
    scanf("%d %d %d",&n,&m,&a);  
    if(n == 0 && m == 0 && a == 0) break; 
    for(i = 0; i < m; i++){
      scanf("%d %d %d",&h,&p,&q); 
    if(p > q){
      p--;
      q++;
    }
    data[p][h] = 1;
    data[q][h] = -1;
    if(hmax < h)
      hmax = h;
    }
  
  h = hmax;
 flag = a;
  while(1){
    if(h == 0)
      break;
    flag = flag + data[flag][h];
    h--;
  }
  printf("%d\n",flag);
  }
  return 0;
}

 

Measured memory_bytes: 800
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <map>
using namespace std;

int main(){
    int N; int64_t K;
    cin>>N>>K;
    vector<int> A(N);
    for(auto &a:A) cin>>a;
    map<int,int> M;
    vector<int> memo(2*N,-1);
    for(int i=0;i<2*N;i++){
        int a=A[i%N];
        if(M.find(a)!=M.end()){
            memo[M[a]]=i;
        }
        M[a]=i;
    }
    vector<int> R(2*N+1);
    R[2*N]=2*N;
    for(int i=2*N-1;i>=0;i--){
        if(memo[i]==-1){
            R[i]=i;
        }else{
            R[i]=R[memo[i]+1];
        }
    }
    for(int i=0;i<N;i++) R[i]%=N;
    if(K==1){
        int l=0;
        while(memo[l]!=-1&&memo[l]<N) l=memo[l]+1;
        for(int i=l;i<N;i++){
            if(memo[i]==-1||memo[i]>=N){
                cout<<A[i]<<' ';
            }else{
                i=memo[i];
            }
        }
        return 0;
    }else{
        for(int k=2,l=0;true;k++){
            l=R[l];
            if(l==0){
                K%=k;
                break;
            }
        }
        int l=0;
        for(int k=2;k<=K;k++){
            l=R[l];
        }
        for(int i=l;i<N;i++){
            if(memo[i]==-1||memo[i]>=N){
                cout<<A[i]<<' ';
            }else{
                i=memo[i];
            }
        }
        cout<<endl;
        return 0;
    }

    return 0;
}

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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	int arr[n] ;
	for(int i = 0 ; i < n ; ++i)
		cin>>arr[i] ;
	int pref[n], suff[n] ;
	suff[n-1] = abs(arr[n-1] - 0) ;
	for(int i = n-2 ; i >= 0 ; --i)
		suff[i] = abs(arr[i] - arr[i+1]) + suff[i+1] ;
	pref[0] = abs(0 - arr[0]) ;
	for(int i = 1 ; i < n ; ++i)
		pref[i] = abs(arr[i] - arr[i-1]) + pref[i-1] ;
	int prv = 0 , cost = 0;
	for(int i = 0 ; i < n ; ++i)
	{
		if(i == n-1)
			return cout<<pref[n-2] + abs(arr[n-2] - 0)<<"\n" , 0 ;
		cout<<abs(arr[i+1] - prv) + suff[i+1] + cost<<"\n";
		prv = arr[i] ;
		cost = pref[i] ;
	}
	return 0 ;
}

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

int main(){
	long long  Q,H,S,D;
	int N;
	cin>>Q>>H>>S>>D>>N;
	int min1=S,min2=D;
	if(8*Q<D)
		min2=8*Q;
	if(4*H<min2)
		min2=4*H;
	if(2*S<min2)
		min2=2*S;
	if(2*H<min1)
		min1=2*H;
	if(4*Q<min1)
		min1=4*Q;
	if(N%2==0){
		long p=N/2;
		p=p*(long)min2;
		cout<<p<<endl;
	}
	else{
		long p=N/2;
		p=p*(long)min2;
		p=p+(long)min1;
		cout<<p<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;


int main()
{
    int A,B;
    cin >> A >> B;
    if(A > B)    cout << 2*A -1;
    else if(A == B) cout << 2*A;
    else cout << 2*B -1;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=205;
const int MOD=998244353;

int n,bin[N],b[N];
bool vis[N][N];
struct data{int x,y;}a[N];

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 cross(int k,int i,int j)
{
	return (a[i].x-a[k].x)*(a[j].y-a[k].y)-(a[i].y-a[k].y)*(a[j].x-a[k].x);
}

int main()
{
	n=read();
	bin[0]=1;
	for (int i=1;i<=n;i++) bin[i]=bin[i-1]*2%MOD;
	for (int i=1;i<=n;i++) a[i].x=read(),a[i].y=read();
	int ans=bin[n];
	for (int i=1;i<n;i++)
		for (int j=i+1;j<=n;j++)
			if (!vis[i][j])
			{
				int tot=0;
				b[++tot]=i;b[++tot]=j;
				for (int k=j+1;k<=n;k++) if (!cross(i,j,k)) b[++tot]=k;
				for (int k=1;k<tot;k++)
					for (int l=k+1;l<=tot;l++)
						vis[b[k]][b[l]]=1;
				(ans-=bin[tot]-tot-1)%=MOD;
			}
	(ans-=n+1)%=MOD;
	ans+=ans<0?MOD:0;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <queue>
#include <tuple>
#include <cmath>
#include <map>
#include <cstring>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++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 arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	int a, b;
	cin >> a >> b;

	cout << ( ( ( a * b ) % 2 ) ? "Odd" : "Even" ) << endl;

	return ( 0 );
}


Measured memory_bytes: 384
//
//AtCoder Beginner Contest 118
//C
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<int> a(n);
    REP(i, n) cin >> a[i];

    int ans = gcd(a[0], a[1]);
    REP(i,n){
        ans = gcd(ans, a[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3732
#include <stdio.h>

//w回だけ＃を入力し改行、これをh回繰り返す関数を作成
void rectangle(int h, int w)
{
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            putchar('#');
        }
        printf("\n");
    }
}
//縦：Hと横：Wをスキャン
int main(void)
{
    int h;
    int w;

    while (1)
    {
        scanf("%d", &h);
        scanf("%d", &w);

        if (h == 0 && w == 0)
        {
            break;
        }
        //関数にHとWを入力
        rectangle(h, w);
        printf("\n");

    }

    return 0;
}


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

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

	int n;
	while(cin >> n && n){

		int cnt = 0;
		while(n != 6174){
			cnt++;
			int a[4];
			for(int i = 0; i < 4; ++i){
				a[i] = n % 10;
				n /= 10;
			}

			sort(a, a + 4);
			if(a[0] == a[3]){
				cout << "NA" << endl;
				cnt = -1;
				break;
			}

			int l = 0;
			for(int i = 3; i >= 0; --i){
				l *= 10;
				l += a[i];
			}
			//cout << l << endl;

			int s = 0;
			for(int i = 0; i < 4; ++i){
				s *= 10;
				s += a[i];
			}
			//cout << s << endl;

			n = l - s;

			//cout << n << endl;
		}

		if(cnt != -1) cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
package main

import (
	"fmt"
)

func main() {
	var n, y int
	fmt.Scan(&n, &y)

	for i := 0; i <= n; i++ {
		for j := 0; j <= n-i; j++ {
			k := n - i - j
			if 10000*i+5000*j+1000*k == y {
				fmt.Println(i, j, k)
				return
			}
		}
	}
	fmt.Println(-1, -1, -1)
}


Measured memory_bytes: 512
#include <stdio.h>
#define N 500000

void max(int);
void build(void);
void printout(void);
int count,i;
int A[N];

int main() {
  int i;

  scanf("%d",&count);
  for(i = 0 ; i < count ; i++) scanf("%d",&A[i]);
  
  build();
  printout();
  return 0;
}

void max(int j){
  int largest,small;    
    if(2*j+1 <= count && A[2*j+1] > A[j]){
      largest = 2*j+1;
    }
    else largest = j;
  
    if(2*j+2 <= count && A[2*j+2] > A[largest]){
      largest = 2*j+2;
    }

    if(largest != j){
      small = A[largest];
      A[largest] = A[j];
      A[j] = small;
      max(largest);
    }
}

void build(){
  int j;
  for(j = count/2-1 ; j >= 0 ; j--){
    max(j);  
  }
}
void printout(){
  for(i = 0 ; i < count ; i++)
    printf(" %d",A[i]);
  printf("\n");
}

Measured memory_bytes: 2552
def together(xs)
  xs.sort!
  ans = [[xs[0]]]
  j = 0
  for i in 1..(xs.length - 1)
    if xs[i] == xs[i - 1]
      ans[j] << xs[i]
    else
      ans << [xs[i]]
      j += 1
    end
  end
  ans
end

def count2(xs)
  xs = together(xs)
  ans = []
  for x in xs
    ans << [x[0], x.length]
  end
  ans
end

n, k = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
as = count2(as).sort{|a, b| a[1] <=> b[1]}
ans = 0
until as.length <= k
  ans += as[0][1]
  as.shift
end
puts ans

Measured memory_bytes: 39020
import math
while(1):
    n = int(input())
    if (n == 0):
        break
    a = [int(input()) for i in range(n)]

    a.sort()
    del a[0]
    del a[-1]
    sum = 0
    for i in range(n-2):
        sum += a[i]
    sum = math.floor(sum / (n-2))

    print("%d" % sum)

Measured memory_bytes: 7652