akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"unsafe"
)

var (
	sc scanner
)

func main() {
	_, m := sc.nextInt(), sc.nextInt()
	a := sc.nextInts()

	sum := 0
	for _, e := range a {
		sum += e
	}

	border := sum / (4 * m)
	if sum%(4*m) != 0 {
		border = sum/(4*m) + 1
	}

	cnt := 0
	for _, e := range a {
		if e >= border {
			cnt++
		}
	}

	if cnt >= m {
		yes()
	} else {
		no()
	}
}

/* template functions */

func init() {
	sc = scanner{
		buf: make([]string, 0, 10000),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 100)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}

func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}

func (s *scanner) resetCur() {
	s.cur = 0
}

func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}

func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}

func (s *scanner) nextByte() byte {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur][0]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}

func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}

func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i, _ := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}

func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur], 64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}

func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i, _ := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i], 64)
	}
	s.resetCur()
	return res
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

// Searchable
// idx := lower_bound([]int{-199, -1, 0, 2, 4, 67, 100, 8435}, 60)
// => idx = 5
//
// No present
// idx := lower_bound([]int{-199, -1, 0, 2, 4, 67, 100, 8435}, 10000)
// => idx = 8

func lower_bound(a []int, x int) int {
	return sort.SearchInts(a, x)
}

func dump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}

func yes() {
	fmt.Println("Yes")
}

func no() {
	fmt.Println("No")
}


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

struct SegmentTree {
private:
    int n;
    vector<int> node;
public:
    SegmentTree(int N) {
        n = 1;
        while(n < N) n *= 2;
        node.resize(2 * n - 1, 0);
    }

    void update(int k, int x) {
        k += (n - 1);
        node[k] = x;
        while (k > 0) {
            k = (k - 1) / 2;
            node[k] = max(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    int query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return node[k];
        int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
};

const int MAX = 600001;
int main() {
    int N, K;
    cin >> N >> K;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] += K;
    }
    SegmentTree st(MAX);
    for (int i = 0; i < N; i++) {
        int v = st.query(A[i] - K, A[i] + K + 1);
        st.update(A[i], v + 1);
    }
    cout << st.query(0, MAX) << "\n";
    return 0;
}

Measured memory_bytes: 12776
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    vector<P> pos(s.size(),P(-1,0));
    vector<ll> v(s.size());
    FOR(i,0,s.size()-1)if(s[i] == 'R' && s[i+1] == 'L'){
      pos[i] = P(i,0);
      pos[i+1] = P(i+1,1);
    }
    FORr(i,0,s.size()-2){
      if(s[i]=='R' && s[i+1] == 'R'){
        if(pos[i+1].second == 0) pos[i]=P(pos[i+1].first+1,1);
        else pos[i] = P(pos[i+1].first-1,0);
      }
    }
    FOR(i,0,s.size()-1){
      if(s[i]=='L' && s[i+1] == 'L'){
        if(pos[i].second == 0) pos[i+1]=P(pos[i].first+1,1);
        else pos[i+1] = P(pos[i].first-1,0);
      }
    }

    FOR(i,0,s.size()){
      v[pos[i].first]++;
    }
    FOR(i,0,s.size()){
      cout<<v[i];
      if(i != s.size()-1) cout<<" ";
      else cout<<endl;
    }
}


Measured memory_bytes: 3024
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int ans = 0;
            for (int i = 1; i <= 40; i++)
                for (int j = 2; j <= 10; j++)
                    if (Math.Pow(i, j) <= n) ans = Math.Max(ans,(int)Math.Pow(i, j));
            Console.WriteLine(ans);

        }
    }
}

Measured memory_bytes: 11348
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication30
{
    class Program
    {
        static void Main()
        {
            List<int> R = new List<int>();
            int A = int.Parse(Console.ReadLine()), S = int.MinValue;int U = int.MinValue;
            for (int B = 0; B < A; B++)
            {
                int L = int.Parse(Console.ReadLine());
                R.Add(L);
            }
            for (int C = R.Count - 1; C > -1; C--)
            {
                    if (S >= R[C]||U>=R[C]) continue;
                    for (int D = C - 1; D > -1; D--)
                    {
                        if (R[C] - R[D] > S) { S = R[C] - R[D]; if (R[D] == 0) { break; } U = R[C]; }
                    }
            }
            Console.WriteLine(S);
            }
        }
    }

Measured memory_bytes: 12140
#include <bits/stdc++.h>
using namespace std;
 
#define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int  long long

int32_t main()
{	
	IOS
	int n, k;
	cin >> n >> k;
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
		sort(a, a + n);
	int ans = 0;
	for(int i = 0; i < k; i++) ans += a[i];
		cout << ans << endl;
    return 0;
}

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

int main(int argc, char *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<int> arr(n);
    for(int& x : arr) cin >> x;

    int sum = 0;
    for(int x : arr)
    {
        if(x % 2 == 0) 
        {
            for(int i = 1; i <= 32; ++i)
            {
                if((1 << i) & x)
                {
                    sum += i;
                    break;
                }
            }
        }
    }

    cout << sum << endl;
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	vector<int> input;
	vector<pair<long long int, long long int>> tree(n + 1);

	rep(i, n + 1){
		int a;
		cin >> a;
		input.push_back(a);
	}

	tree[n] = make_pair(input[n], input[n]);

	for(int i = n - 1; 0 <= i; i--){
		if(input[i] == 0){
			tree[i] = make_pair((tree[i + 1].first + 1) / 2, tree[i + 1].second);
		}
		else{
			tree[i] = make_pair((tree[i + 1].first + 1) / 2 + input[i], tree[i + 1].second + input[i]);
		}
	}
	/*
	rep(i, n + 1){
		cout << i << " : " << tree[i].first << " , " << tree[i].second << endl;
	}
	*/
	
	if(1 < tree[0].first || tree[0].second < 1){
		cout << -1;
		return 0;
	}

	if(tree[0].second != 1){
		tree[0].second = 1;

		REP(i, 1, n){
			long long int t = tree[i - 1].second - input[i - 1];

			if(t * 2 < tree[i].second){
				tree[i].second = t * 2;
			}
		}
	}
	/*
	cout << endl;
	rep(i, n + 1){
		cout << i << " : " << tree[i].first << " , " << tree[i].second << endl;
	}
	*/

	long long int ans = 0;
	rep(i, n + 1){
		ans += tree[i].second;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 5492
#include <iostream>
using namespace std;
string S;
void eraseAll (string str) {
    while (true) {
        int pos = S.find(str);
        if (pos == -1) {
            break;
        }
        S.erase(S.begin() + pos, S.begin() + pos + str.length());
    }
}
int main (void) {
    cin >> S;

    eraseAll("eraser");
    eraseAll("erase");
    eraseAll("dreamer");
    eraseAll("dream");

    if (S.size() == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 640
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, mut y) = get!(usize, usize);
    y /= 1000;
    for a in 0..n+1 {
        for b in 0..n+1 {
            if a+b > n { break; }
            let c = n - (a+b);
            if a*10 + b*5 + c == y {
                println!("{} {} {}", a, b, c);
                return;
            }
        }
    }
    println!("-1 -1 -1");
}

Measured memory_bytes: 2160
#include<iostream>
#include<stdio.h>
#include<fstream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<set>
#include<string>
#include<queue>
#include<map>
#include<iomanip>
#include<cassert>
#include<complex>
#include<functional>
#include<list>
#include<cmath>
#include<stack>
#include<assert.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MAXN 100001
using namespace std;
int n,m,ans,last;
struct pos
{
	int a,b;
}p[MAXN];
bool cmp(pos x,pos y)
{
	return x.b<y.b;
}
int main()
{
	cin>>n>>m;
	for (int i=0;i<m;i++) cin>>p[i].a>>p[i].b;
	sort(p,p+m,cmp);
	last=-1;
	for (int i=0;i<m;i++)
		if (p[i].a>=last)
			last=p[i].b,ans++;
	cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
string s;
int sz, a[2020], u, t = 1;
long long ans;
int main(){
	cin >> s;
	a[0] = 1;
	for(int i=s.size()-1; i>=0; i--){
		ans += a[(u += t*(s[i]-'0')) %= 2019]++;
		t = t * 10 % 2019;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3892
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

// ?§?????????¨????????¨???????????????????¨???????????§???????
template <typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int s, T d) : to(s), cost(d) {}
    Edge(int f, int s, T d) : from(f), to(s), cost(d) {}

    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
    bool operator>(const Edge &e) const {
        return cost > e.cost;
    }
};
#define Graph(type) vector< vector< Edge<type> > >

template <typename T>
vector<T> dijkstra(vector< vector< Edge<T> > > &G, int s) {
    int V = G.size();
    vector<T> d(V); fill(d.begin(), d.end(), INF);
    priority_queue<pii, vector<pii>, greater<pii> > que;
    d[s] = 0;
    que.push(pii(0,s));

    while(!que.empty()) {
        pii p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i=0; i<G[v].size(); i++) {
            Edge<T> e = G[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(pii(d[e.to], e.to));
            }
        }
    }
    return d;
}

template <typename T>
vector<T> treeHeight(vector< vector< Edge<T> > > &G) {
    int n = G.size();
    vector<T> v1, v2, v3, ret(n);
    int p1, p2;
    v1 = dijkstra<T>(G, 0);
    p1 = max_element(v1.begin(), v1.end()) - v1.begin();

    v2 = dijkstra<T>(G, p1);
    p2 = max_element(v2.begin(), v2.end()) - v2.begin();

    v3 = dijkstra<T>(G, p2);
    for(int i=0; i<n; i++) ret[i] = max(v2[i], v3[i]);
    return ret;
}

signed main() {
    int n; cin >> n;
    Graph(int) G(n);
    int s, t, w;
    rep(i,0,n-1) {
        cin >> s >> t >> w;
        G[s].pb(Edge<int>(t,w));
        G[t].pb(Edge<int>(s,w));
    }

    vector<int> ans = treeHeight<int> (G);
    rep(i,0,ans.size()) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 4004
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0

for i in range(n):
    left = min(A[i], B[i])
    A[i] -= left
    B[i] -= left
    ans += left

    right = min(A[i + 1], B[i])
    A[i + 1] -= right
    B[i] -= right
    ans += right

print(ans)


Measured memory_bytes: 18624
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
var n= arr.shift()-0;
var p = arr.shift().split(" ").map(Number);
var ans = 0;
for(var i=1;i<=100;i++){
   var cnt = 0;
   p.forEach(v=>{
      if(v>=i)cnt++;
   });
   if(cnt>=i)ans=i;
}
console.log(ans);


Measured memory_bytes: 17200
const main = (inputs) => {

  const word = inputs[0];
  var count = 0;
  if (word.indexOf('A') !== -1) {
    count = count + 1;
  }
  if (word.indexOf('B') !== -1) {
    count = count + 1;
  }
  if (count >= 2) {
    console.log('Yes');
  } else {
    console.log('No');
  }
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));

Measured memory_bytes: 9420
function Main(input) {
    var A = parseInt(input[0], 10);
    var B = parseInt(input[1], 10);

    var sum = 0;

    if (A > B) {
        sum += A;
        A--;
    } else {
        sum += B;
        B--;
    }

    if (A > B) {
        sum += A;
    } else {
        sum += B;
    }


    console.log(sum);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 21064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N;
int a[110], b[110], c[110], d[110];
pair<int,int> red[110], blue[110];

/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N;
    REP(i,0,N){
        //cin>>a[i]>>b[i];
        int x, y;
        cin>>x>>y;
        red[i] = make_pair(x, y);
    }
    REP(i,0,N){
        //cin>>c[i]>>d[i];
        int x, y;
        cin>>x>>y;
        blue[i] = make_pair(x, y);
    }

    sort(blue, blue+N);
    sort(red, red+N);

    set<int> usedr;

    REP(i,0,N){
        int miny = 210;
        int tj = -1;
        RREP(j,0,N){
            if(usedr.find(j) != usedr.end()) continue;
            if(blue[i].F < red[j].F || blue[i].S < red[j].S) continue;
            if(miny > blue[i].S - red[j].S){
                miny = blue[i].S - red[j].S;
                tj = j;
            }
        }
        if(tj != -1){
            usedr.insert(tj);
        }
    }

    cout<<usedr.size()<<endl;

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+3;
string s[N];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;cin >> n;
	for(int i=0;i<n;i++) cin >> s[i];
	sort(s,s+n);
	int sz = n;
	for(int i=1;i<n;i++) if(s[i] == s[i-1]) sz--;
	cout << sz << '\n';
}

Measured memory_bytes: 9848
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000LL;
constexpr auto MOD = 1000000007;

int main() {
	
	int h, w;
	cin >> h >> w;
	if (h == 1 || w == 1)cout << 1 << endl;
	else cout << ((ll)h * w + 1) / 2 << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long gcd(long long a, long long b){
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
set<long long> st;
int main() {
	long long a, b;
	cin >> a >> b;
	long long g = gcd(b, a);
	long long g1 = g;
	int co = 0;
	st.insert(1);
	for (long long i = 2; i * i < g1; i++) {
		if (g % i == 0) {
			while (1) {
				if (g % i != 0) {
					break;
				}
				g /= i;
			}
			co++;
			st.insert(i);
		}
	}
	st.insert(g);
	cout << st.size() << endl;
	return 0;
}

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

using namespace std;

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

int W, H;
int A[22][22];
int sx, sy, gx, gy;
void dfs(int x, int y, int cnt, int &ans, vector<vector<int>> maze) {
    if (cnt > 10) return;
    if (cnt > ans) return;
    // cout << x << " " << y << endl;
    if (x == gx && y == gy) {
        ans = min(ans, cnt);
        return;
    }
    int nx = x, ny = y;
    if (nx + 1 < H && maze[nx + 1][y] != 1) {
        while (nx < H && maze[nx][y] != 1) {
            // cout << "!" << maze[nx][y] << endl;
            if (nx == gx && y == gy) ans = min(ans, cnt + 1);
            nx++;
        }
        // cout << "!" << nx << " " << y << endl;
        vector<vector<int>> tmp = maze;
        if (nx != H) {
            tmp[nx][y] = 0;
            dfs(nx - 1, y, cnt + 1, ans, tmp);
        }
    }

    nx = x;
    if (nx - 1 >= 0 && maze[nx - 1][y] != 1) {
        while (nx >= 0 && maze[nx][y] != 1) {
            if (nx == gx && y == gy) ans = min(ans, cnt + 1);
            nx--;
        }
        vector<vector<int>> tmp = maze;
        if (nx != -1) {
            tmp[nx][y] = 0;
            dfs(nx + 1, y, cnt + 1, ans, tmp);
        }
    }

    ny = y;
    if (ny + 1 < W && maze[x][ny + 1] != 1) {
        while (ny < W && maze[x][ny] != 1) {
            if (x == gx && ny == gy) ans = min(ans, cnt + 1);
            ny++;
        }
        vector<vector<int>> tmp = maze;
        if (ny != W) {
            tmp[x][ny] = 0;
            dfs(x, ny - 1, cnt + 1, ans, tmp);
        }
    }

    ny = y;
    if (ny - 1 >= 0 && maze[x][ny - 1] != 1) {
        while (ny >= 0 && maze[x][ny] != 1) {
            if (x == gx && ny == gy) ans = min(ans, cnt + 1);
            ny--;
        }
        vector<vector<int>> tmp = maze;
        if (ny != -1) {
            tmp[x][ny] = 0;
            dfs(x, ny + 1, cnt + 1, ans, tmp);
        }
    }
}
bool solve() {
    cin >> W >> H;
    if (W == 0) return false;
    vector<vector<int>> maze(H, vector<int>(W));
    REP(i, H) {
        REP(j, W) {
            cin >> A[i][j];
            maze[i][j] = A[i][j];
            if (A[i][j] == 2) {
                sx = i;
                sy = j;
            }
            if (A[i][j] == 3) {
                gx = i;
                gy = j;
            }
        }
    }
    int ans = 100;
    dfs(sx, sy, 0, ans, maze);
    if (ans <= 10)
        cout << ans << endl;
    else
        cout << -1 << endl;
    return true;
}
signed main() {
    while (solve())
        ;
}



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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int n;
  scanf("%d", &n);
  map<ll, int> freqs;
  for (int i = 0; i < n; ++i) {
    ll val = 0;
    scanf("%lld", &val);
    ++freqs[val];
  }

  int ans = 0;
  for (map<ll, int>::iterator iter = freqs.begin(); iter != freqs.end(); ++iter) {
    ll val = iter->first;
    int cnt = iter->second;
    if (cnt == val) { continue; }
    if (cnt > val) {
      ans += cnt - val;
    }
    else {
      ans += cnt;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 6272
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void ABC152E();

int main()
{
	ABC152E();
	fflush(stdout);
	return 0;
}

template <class _T> void tp_getPrimes(_T targ, std::map<_T, _T>& primes)
{
	_T target = targ;
	_T i = 2;
	while ((i * i) <= target) {
		if ((target % i) == 0) {
			target /= i;
			primes[i]++;
		}
		else {
			i++;
		}
	}
	if (target > 1) {
		primes[target]++;
	}
}
template <class _T> static _T tp_modpow(_T a, _T n, _T mod = (_T)1) {
	_T ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans = ans * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
template <class _T> static _T tp_modinv(_T a, _T mod) {
	return tp_modpow<_T>(a, mod - 2, mod);
}

static void ABC152E()
{
	int N;
	getint(N);

	std::vector<LLONG> ai(N, 0);
	for (int i = 0; i < N; i++) {
		getint(ai[i]);
	}

	std::vector<std::map<LLONG, LLONG>> prime;
	std::map<LLONG, LLONG> lcm;
	lcm[1] = 1;
	for (int i = 0; i < N; i++) {
		std::map<LLONG, LLONG> pr;
		tp_getPrimes(ai[i], pr);
		//	おぼえとく
		prime.push_back(pr);

		for (auto it = pr.begin(); it != pr.end(); it++) {
			lcm[it->first] = std::max(lcm[it->first], it->second);
		}
	}

	LLONG ans = 0;

	LLONG lcmValue = 1;
	for (auto it = lcm.begin(); it != lcm.end(); it++) {
		for (int i = 0; i < it->second; i++) {
			lcmValue = lcmValue * it->first % MOD_NUM;
		}
	}

	for (int i = 0; i < N; i++) {
		LLONG bi = lcmValue * tp_modinv(ai[i],MOD_NUM) % MOD_NUM;
		ans = (ans + bi) % MOD_NUM;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3896
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int D;
	long long G;
	cin >> D >> G;
	G /= 100;

	vector<int> p(D), c(D);;
	
	for (int i = 0; i < D; i++)
	{
		cin >> p[i] >> c[i];
		c[i] /= 100;
	}

	int ans = 1000000;
	for (int mask = 0; mask < pow(2, D); mask++)
	{
		int sum = 0;
		int count = 0;

		for (int i = 0; i < D; i++)
		{
			if (mask & (1 << i))
			{
				sum += c[i] + p[i] * (i + 1);
				count += p[i];
			}
		}

		if (sum < G)
		{
			for (int i = D - 1; i >= 0; i--)
			{
				if (mask & (1 << i))
				{ }
				else
				{
					for (int k = 0; k < p[i]; k++)
					{
						sum += (i + 1);
						count++;

						if (sum >= G)
						{
							break;
						}
					}

					break;
				}
			}
		}

		if (sum >= G)
		{
			ans = min(ans, count);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define R register int
#define mm make_pair
using namespace std;
const int manx=300;
#define LL long long
int a[10];
int main()
{
    LL n; cin >> n;
    cout << (n/500) *1000 + (n- (n/500)*500)/5*5;
    return 0;
}


Measured memory_bytes: 256
#define FOR(i,a,b) for(int i=a;i<b;i++)
#include <cstdio>
int main(){
	int n,a[200002];
	scanf("%d",&n);
	int f=n/2,b=n/2+1;
	FOR(i,0,n){
		if((n-i)%2 == 0) scanf("%d",&a[b++]);
		else scanf("%d",&a[f--]);
	}
	FOR(i,f+1,b) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 2816
import java.util.Scanner;


public class Main {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		String s = sc.next();
		int result = 0;
		if (s.contains("R")) {
			result = 1;
		}
		if (s.contains("RR")) {
			result = 2;
		}
		if (s.contains("RRR")) {
			result = 3;
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 35620
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    if a[i]>i+1:
        print(-1)
        exit()
def order(a):
    if a == [1]:
        return [1]
    else:
        x = order(a[:-1])
        y = a[-1]
        x.insert(y-1,y)
        return x
print(*order(a),sep="\n")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,m,x,tmp;
	int r[2] = {};
	cin >> n >> m >> x;
	int* a = new int[n+1];
	fill(a,a+m,0);
	for(int i = 0;i < n+1;i++){
		cin >> tmp;
		a[tmp] = 1;
	}
	for(int i = x;i < n+1;i++){
		if(a[i] == 1)
			r[0]++;
	}
	for(int i = x;i >= 0;i--){
		if(a[i] == 1)
			r[1]++;
	}
	if(r[0] <= r[1])
		cout << r[0];
	else
		cout << r[1];
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

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

    vector<int> dp(n + 1);
    dp[1] = 1;
    for (int i = 2; i <= n; i++) {
        dp[i] = dp[i - 1] + 1;
        for (int j = 0; i - pow(6, j) >= 0; j++) {
            dp[i] = min(dp[i], dp[i - pow(6, j)] + 1);
        }
        for (int j = 0; i - pow(9, j) >= 0; j++) {
            dp[i] = min(dp[i], dp[i - pow(9, j)] + 1);
        }
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 4200
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include<unordered_map>
using namespace std;
const long long int mod1=1000000007;
const long long int mod2 = -1;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define inf mod1
#define all(x) x.begin(),x.end()
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
    fast;
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        ll n;
        cin >> n;
        ll a[n + 1] = {};
        for(int i = 1; i < n; i++){
            ll x;
            cin >> x;
            a[x]++;
        }
        for(int i = 1; i<= n; i++){
            cout << a[i] << endl;
        }
    }
}

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

using namespace std;
const long long mod=1e9+7L;
long long ans=1L;

int N;

int main(){

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

cin>>N;

for(int i=1; i<=N; i++){
  ans=(ans*i)%mod;
}

cout<<ans<<endl;

}



Measured memory_bytes: 256
H,W = map(int, input().split())
a = [input() for _ in range(H)]

del_lst = []
# 横の削除
for i in range(H):
  for j in range(W):
    if a[i][j] == '#':
      break
  else:
    del_lst.append(i)

# 削除
for i in sorted(del_lst,reverse=True):
  a.pop(i)

# 列の削除
del_lst = []
for i in range(len(a[0])):
  for j in range(len(a)):
    if a[j][i] == '#':
      break
  else:
    del_lst.append(i)

# 削除
for i in sorted(del_lst,reverse=True):
  for j in range(len(a)):
    str = list(a[j])
    str.pop(i)
    a[j] = ''.join(str)

for _a in a:
  print(_a)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;
	set<int> s;
	s.insert(A);
	s.insert(B);
	for (auto i = 1; i <= 3; ++i)
	{
		if (s.find(i) == s.end())
		{
			cout << i << endl;
			break;
		}
	}

	return 0;
}

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

// AtCoder
// Submit via the browser!
#include <atcoder/all>
using namespace atcoder;

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

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

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

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll t; cin >> t;
    rep (_, t) {
        ll n, m, a, b; cin >> n >> m >> a >> b;
        cout << floor_sum(n, m, a, b) << "\n";
    }
    return 0;
}

Measured memory_bytes: 3712
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
struct edge {
    int to, cost;
};
double n, m, d;
int a[10000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m>>d;
    double one;
    if(d==0){
        one=double(1/n);
    }
    else if((n-2*d)>=0)
    one=(2*(n-d))/(n*n);
    else{
        one=double(1/n);
    }

    cout << setprecision(12)<<one*(m-1) << "\n";
}


Measured memory_bytes: 256
def longest_common_subsequence(X, Y):
    X = " " + X
    Y = " " + Y

    length_X = len(X)
    length_Y = len(Y)

    c = [0] * length_Y

    for i in range(1, length_X):
        
        c_ = c[:]

        for j in range(1, length_Y):
            if X[i] == Y[j]:
                c[j] = c_[j - 1] + 1
            elif c_[j] < c[j - 1]:
                c[j] = c[j - 1]

    return c[-1]


q = int(input())


for _ in range(q):

    X = input()
    Y = input()

    print(longest_common_subsequence(X, Y))



Measured memory_bytes: 5628
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define MOD 1000000007
using ll = long long;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who forgive themselves, and are able to accept their true nature...THEY ARE THE STRONG ONES

    long long a;
    cin >> a;
    int counter = 0;
    long long curr = 100;
    while(curr < a) {
        curr = curr + curr / 100ll;
        counter++;
    }
    cout << counter;
    return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int main() {
    int a, b, t;
    cin >> a >> b >> t;
    cout << (t/a) * b << endl;
    return 0;
}

Measured memory_bytes: 3640
import math
def main():
    N = int(input())
    t = 1
    l = []
    while len(l) < N:
        x = t * 10 + 1
        d = int(math.sqrt(x))
        for i in range(2, d+1):
            if x % i == 0:
                break
        else:
            l.append(x)
        t += 1
    print(' '.join(str(i) for i in l))
main()


Measured memory_bytes: 3060
#include <algorithm>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define int long long
#define double long double
#define INF LLONG_MAX/1000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
signed main() {
	int n, l;
	cin >> n >> l;
	int sum = l * n + n * (n - 1) / 2, ans = INF, res;
	REP(i, n) {
		if (ans > abs(sum - (sum - (l + i - 1)))) {
			ans = abs(sum - (sum - (l + i - 1)));
			res = sum - (l + i - 1);
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


int main() {
    long long n, k, s; cin >> n >> k >> s;

    vector<long long> a(n, s);
    for (int i=0; i<n-k; i++) {
        if (s == 1e9) {
            a[i]--;
        }
        else {
            a[i]++;
        }
    }

    for (auto a_i: a) cout << a_i << ' '; cout << endl;

    return 0;
}



Measured memory_bytes: 2176
#include<stdio.h>
#include<iostream>
using namespace std;

int N;
int a[100010] = {0};
int main (){
    cin >> N;
    int cnt = 0;
    for(int i=0; i<N; i++){
        int b;
        cin >> b;
        if( b > 100000 ) cnt++;
        else a[b]++;
    }
    for(int i=1; i<100001; i++){
        int z = i;
        if( a[i] > 0 && a[i] < z ) cnt += a[i];
        else if ( a[i] > 0 && a[i] > z) cnt += a[i] - z;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define H 510
struct Ver{
    ll y,x,t;
    Ver(ll y,ll x,ll t){
	this->y=y,this->x=x,this->t=t;
    }
    bool operator<(const Ver&key)const{return 0;}
    bool operator>(const Ver&key)const{return 0;}
    bool operator==(const Ver&key)const{
	return this->y==key.y&&this->x==key.x&&this->t==key.t;
    }
    bool operator!=(const Ver&key)const{
	return !(this->operator==(key));
    }
    struct Hash{
	ll operator()(const Ver&key)const{
	    return key.t*H*H+key.y*H+key.x;
	}
    };
};
#define N 100010
ll h,w,a,b,c,n,s[N],t[N];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
ll dis[H][H];
unordered_map<Ver,ll,Ver::Hash> d;
void Dijkstra(Ver s){
    typedef pair<ll,Ver> P;
    priority_queue<P,vector<P>,greater<P> >Q;
    Q.push(make_pair(0,s));
    while(!Q.empty()){
	ll cost=Q.top().first;
	Ver key=Q.top().second;
	Q.pop();
	ll i=key.y,j=key.x,t=key.t;
	if(i<0||i==h||j<0||j==w)continue;
	if(d.find(key)!=d.end())continue;
	d[key]=cost;
	lol(r,4){
	    int xx=j+dx[r],yy=i+dy[r];
	    if(t==4){
		Q.push(make_pair(cost+b,Ver(i,j,r)));
		Q.push(make_pair(cost+c,Ver(yy,xx,4)));
	    }
	    if(t==r){
		Q.push(make_pair(cost+dis[i][j]*c,Ver(i,j,4)));
		Q.push(make_pair(cost+a,Ver(yy,xx,r)));
	    }
	}
    }
}
void BFS(){
    lol(i,h)lol(j,w)dis[i][j]=mod;
    queue<Ver> Q;
    lol(i,n)Q.push(Ver(s[i],t[i],0));
    while(!Q.empty()){
	Ver key=Q.front();
	Q.pop();
	ll y=key.y,x=key.x,t=key.t;
	if(dis[y][x]<=t)continue;
	dis[y][x]=t;
	lol(r,4){
	    int xx=x+dx[r],yy=y+dy[r];
	    if(xx<0||xx==w||yy<0||yy==h)continue;
	    Q.push(Ver(yy,xx,t+1));
	}
    }
}
int main(){
    cin>>h>>w>>a>>b>>c>>n;h++,w++;
    lol(i,n)scanf("%lld%lld",&s[i],&t[i]);BFS();
    Dijkstra(Ver(s[0],t[0],4));
    cout<<d[Ver(s[n-1],t[n-1],4)]<<endl;
    return 0;
}



Measured memory_bytes: 132492
#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 ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll n, m, a, b;
  cin >> n >> m;
  map<int, int> mp;
  rep(i, m) {
    cin >> a >> b;
    mp[a]++;
    mp[b]++;
  }

  for (auto x : mp) {
    if (x.second % 2 == 1) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 7684
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 0;										/* デバッグプリント 提出時は0 */
int main()
{
	int		i,j,k,N;
	long long ans=0;
	int		h[10000],w[10000];

	N = 0;
	while(1) {
		scanf("%d %d", &h[N], &w[N]);
		if ((h[N]==0)&&(w[N]==0)) break;
		N++;
	}
	for(k=0;k<N;k++) {
		for(i=0;i<h[k];i++) {
			for(j=0;j<w[k];j++) {
				printf("#");
			}
			ENTER;
		}
		ENTER;
	}


	return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  while(int e = getInt()){
    int m = INT_MAX;
    for(int z = 0; z * z * z <= e; z++){
      int z3 = z * z * z;
      for(int y = 0; y * y + z3 <= e; y++){
	int y2 = y * y;
	int x  = e - z3 - y2;
	m = min(m, x + y + z);
      }
    }
    print(m);
  }
  return 0;
}

Measured memory_bytes: 832
def raw_add():
    if w % 2 == 1:
        print("#."*(w//2) + "#")
    else:
        print("#."*(w//2))

def raw_even():
    if w % 2 == 1:
        print(".#"*(w//2) + ".")
    else:
        print(".#"*(w//2))

while True:
    line = input()
    if line == "0 0":
        break
    lst = list(map(int, line.split()))
    h = lst[0]
    w = lst[1]
    if h % 2 == 1:
        for i in range(h//2):
            raw_add()
            raw_even()
        raw_add()
    else:
        for i in range(h//2):
            raw_add()
            raw_even()
    print()


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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

vector < int > vl ;
int Pow( int n , int b ){
int mul = 1 ;
forn( int , i , 0 , b ){
  mul *= n ;
}
return mul ;
}

int n ;
int mem[ 20 ][ 1000002 ] ;
int solve( int i , int sum ){
if( i >= sz( vl ) ) return n ;
if( sum == n ) return 0 ;
int & ret = mem[ i ][ sum ] ;
if( ~ret ) return ret ;
ret = n ;
if( vl[ i ] + sum <= n ) ret = 1 + solve( i , vl[ i ] + sum ) ;
ret = min( ret , solve( i + 1 , sum ) ) ;
return ret ;
}

int main() {

  //pre
  vl.pb( 1 ) ;
  forn( int , i , 1 , 8 ) vl.pb( Pow( 9 , i ) ) ;
  forn( int , i , 1 , 8 ) vl.pb( Pow( 6 , i ) ) ;
  Clear( mem , -1 ) ;

  cin >> n ;
  cout << solve( 0 , 0 ) ;
  return 0 ;
}


Measured memory_bytes: 83072