akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll  = long long;
template <typename T> T In() {
    T t;
    cin >> t;
    return t;
}
template <typename T> vector<T> ReadVec1(int N) {
    vector<T> vec(N);
    for(int i = 0; i < N; i++)
        vec[i] = In<T>();
    return move(vec);
}
template <typename T> vector<vector<T>> Vec2(int i, int j, T ini = 0) {
    vector<vector<T>> vec(i, vector<T>(j, ini));
    return move(vec);
}
template <typename T> vector<vector<vector<T>>> Vec3(int i, int j, int k, T ini = 0) {
    vector<vector<vector<T>>> vec(i, vector<vector<T>>(j, vector<T>(k, ini)));
    return move(vec);
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(N*A, B) << endl;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

Alice_point = 0
Bob_point = 0

for i, value in enumerate(a):
    if i % 2 == 0:
        Alice_point += value
    else:
        Bob_point += value

print(Alice_point - Bob_point)


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

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

const int mod = 1000000007;

struct mint {
    ll x;
    mint(ll x=0):x(x%mod){}

    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 = (x * a.x) % mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
};

mint dp[100005][13];

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

  int n, x;
  cin >> n >> x;

  vector<long> v(n);
  fillLong(v, n);

  long res = 0;

  rep(i, x) { // 戻す数
    int toru = min(x-i, n);
    rep(j, toru+1) { // 左から取る数
      vector<long> fk;
      long tmp = 0;
      rep(k, j) {
        long r = v[k];
        tmp += r;
        if (r < 0) {
          fk.push_back(r);
        }
      }
      rep(k, toru - j) {
        long r = v[n-k-1];
        tmp += r;
        if (r < 0) {
          fk.push_back(r);
        }
      }
      sortv(fk);
      rep(k, min(i, (int)fk.size())) {
        tmp -= fk[k];
      }
      res = max(res, tmp);
    }
  } 

  cout << res << endl;
}


Measured memory_bytes: 10368
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: i64 = read();
    let m: i64 = read();
    let mut vec: Vec<i64> = (0..m).map(|_| read()).collect();
    vec.sort();

    let mut diff_vec: Vec<i64> = Vec::new();

    let mut before = vec[0];
    for (index, &i) in vec.iter().enumerate() {
        let diff = i - before;
        diff_vec.push(diff);
        before = i;
    }

    diff_vec.sort();
    diff_vec.reverse();

    let max = vec[vec.len()-1] - vec[0];
    let mut sum = 0;
    let mut count = 0;
    for &i in diff_vec.iter() {
        count += 1;
        sum += i;
        if count == n-1 {
            break;
        }
    }

    let mut ans = max - sum;

    if n == 1 {
        ans = max;
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 6396
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;

int const inf = 1e9;

template<class T> using PQ_G = priority_queue<T, vector<T>, greater<T>>;

ll dist[111][26];
ll bitcost[1<<8];
typedef tuple<int, int, int> state; // cost, time, pos

typedef tuple<int, ll, int, int> edge;
vector<vector<edge>> g;

int dijkstra(int start, int goal, int H, int S) {
  PQ_G<state> pq;
  pq.emplace(0, 0, start);

  while(!pq.empty()) {
    ll cost, stime; int pos; tie(cost, stime, pos) = pq.top(); pq.pop();

    if(pos == goal) return cost;

    for(auto && e: g[pos]) {
      int b, c, h, r; tie(b, c, h, r) = e;
      ll ntime = stime + h;
      if(ntime > H) continue;
      if(S >> r & 1) {
        if(dist[b][ntime] <= cost) continue;
        dist[b][ntime] = cost;
        pq.emplace(dist[b][ntime], ntime, b);
      }
      else {
        ll ncost = cost + c;
        if(dist[b][ntime] <= ncost) continue;
        dist[b][ntime] = ncost;
        pq.emplace(dist[b][ntime], ntime, b);
      }
    }
  }
  return inf;
}

signed main() {

  int N, M, H, K;
  while(cin >> N >> M >> H >> K && (N|M|H|K)) {
    g.clear();
    g.resize(N);

    rep(i, M) {
      int a, b, c, h, r; cin >> a >> b >> c >> h >> r;
      a --, b --; r --;
      g[a].emplace_back(b, c, h, r);
      g[b].emplace_back(a, c, h, r);
    }

    int start, goal; cin >> start >> goal; start --, goal --;

    rep(i, 1 << 8) bitcost[i] = inf;
    bitcost[0] = 0;

    int P; cin >> P;

    rep(i, P) {
      int l, d; cin >> l >> d;
      int S = 0;
      rep(j, l) {
        int k; cin >> k; k--;
        S |= 1 << k;
      }
      minimize(bitcost[S], d);
    }

    rep(S, 1 << K) {
      if(bitcost[S] >= inf) continue;
      rep(T, 1 << K) {
        if(bitcost[T] >= inf) continue;
        bitcost[S|T] = min(bitcost[S|T], bitcost[S] + bitcost[T]);
      }
    }

    ll ans = inf;

    rep(S, 1 << K) {
      rep(i, 111) rep(j, 26)
        dist[i][j] = inf;
      dist[start][0] = 0;
      if(bitcost[S] < inf)
        minimize(ans, dijkstra(start, goal, H, S) + bitcost[S]);
    }

    cout << (ans == inf ? -1 : ans) << endl;
    
  }
  
  return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int a, b, c;

int main() {
	cin >> a >> b >> c;
	
	int x = b * 10 + c;
	
	cout << (x % 4 == 0 ? "YES" : "NO") << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include "iostream"
using namespace std;
 
int main(){
 
  int N,M;
  int A;
  int sum=0;
  
  cin >> N >> M;
  
  for(int i=1; i<=M ;i++){
   
    cin >> A;
    
    sum+=A;
    
  }
  
  if(sum<=N) cout << N-sum;
  else cout << -1;
  
  return 0;
}

Measured memory_bytes: 3624
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::HashMap;

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    // from kenkoooooo
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let m: i64 = sc.read();
    let mut res: i64 = 0;

    let mut sum = 0;
    let mut map: HashMap<i64, i64> = HashMap::new();
    map.insert(0, 1);
    for _ in 0..n {
        let a = sc.read();
        sum += a;
        sum %= m;
        if let Some(&v) = map.get(&sum) {
            res += v;
            map.insert(sum, v + 1);
        } else {
            map.insert(sum, 1);
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 12540
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <sstream>
#include <cstring>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef long long ll;

const int MAX_SIZE = 10000;

struct edge{
	int kind;
	int number;
};

const int INF=100000000;
int main(){

	int w,h;

	// »ê¼êÌíÞÌm[hði[
	while(cin>>w>>h&&!(w==0&&h==0)){
		// dpe[u
		int dp[5][1001];
		// m[hÌÊu
		vector<edge> G[6][1001];
		char field[1001][1001];
		vector<pair<int,int> > p[6];
		pair<int,int> goal;
		pair<int,int> start;
		int minCost=INF;
		for(int i = 0; i < 5; i++){
			for(int j = 0; j < 1001; j++){
				dp[i][j]=INF;
			}
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin>>field[i][j];
				if(field[i][j]=='S'){
					start.first=i;
					start.second=j;
				}
				else if(field[i][j]=='G'){
					goal.first=i;
					goal.second=j;
				}
				else if(field[i][j]!='.'){
					int num=field[i][j]-'0'-1;
					p[num].push_back(make_pair(i,j));
				}
			}
		}

		// iªX^[gn_
		int bestIdx=-1;
		for(int i = 0; i < 5; i++){
			for(int j = 0; j < 5; j++){
				fill(dp[j],dp[j]+1001,INF);
			}
			for(int j = 0; j < p[(i+1)%5].size(); j++){
				// X^[g©çÌ£
				dp[(i+1)%5][j]=abs(start.first-p[(i+1)%5][j].first) + abs(start.second-p[(i+1)%5][j].second);
			}
			// jª¡Ìm[h
			for(int j = i+1; j < i+4; j++){
				// Ü¸æÌm[hðßA»±ÉÎµÄÚ®ðs¤B
				for(int l = 0; l < p[(j+1)%5].size(); l++){
					for(int k = 0; k < p[j%5].size(); k++){
						dp[(j+1)%5][l]=min(dp[(j+1)%5][l]
						,dp[j%5][k]+abs(p[j%5][k].first-p[(j+1)%5][l].first)+abs(p[j%5][k].second-p[(j+1)%5][l].second));
					}
				}
			}
			// ÅãÉS[ÜÅÌRXgªÅZÈàÌðßé
			for(int j = 0; j < p[(i+4)%5].size(); j++){
				if(minCost>dp[(i+4)%5][j]+abs(goal.first-p[(i+4)%5][j].first)+abs(goal.second-p[(i+4)%5][j].second)){
					minCost=dp[(i+4)%5][j]+abs(goal.first-p[(i+4)%5][j].first)+abs(goal.second-p[(i+4)%5][j].second);
					bestIdx=i+1;
				}
			}
		}
		if(bestIdx!=-1)
			cout<<bestIdx<<" "<<minCost<<endl;
		else
			cout<<"NA"<<endl;
	}
	return 0;
}

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

string s;
signed main() {
    cin >> s;
    s = 'A' + s;
    int ans = 0, cum = 0;
    reps(i, s.length()) {
        if (s[i] == 'A') {
            if (s[i - 1] == 'B') { cum = 0; }
            cum++;
        }
        if (s[i] == 'B') {
            if (s[i - 1] == 'B') { cum = 0; }
        }
        if (s[i] == 'C') {
            if (s[i - 1] == 'B') { ans += cum; }
            if (s[i - 1] == 'A' || s[i - 1] == 'C') { cum = 0; }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 772
#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>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000010;
constexpr ll INF = 1000000000000000010;
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; }

template<class T> class segtree {
	int n;
	vector<T> data;
	T id = 0;
	T operation(T a, T b) { return a + b; };
public:
	segtree(int _n) {
		n = 1;
		while (n < _n + 2) n <<= 1;
		data = vector<T>(2 * n, id);
	}
	void change(int a, int b, int x) {
		a += n; b += n;
		while (a < b) {
			if (a & 1) data[a++] = data[a] + x;
			if (b & 1) data[b] += data[b--] + x;
			a >>= 1; b >>= 1;
		}
	}
	T get(int i) {
		T ret = id;
		i += n;
		while (i > 0) {
			ret = operation(ret, data[i]);
			i >>= 1;
		}
		return ret;
	}
};

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

	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	while (k--) {
		segtree<int> seg(n + 1);
		rep(i, n) seg.change(max(0ll, i - a[i]), min(n, i + a[i] + 1), 1);
		bool flag = true;
		rep(i, n) {
			a[i] = seg.get(i);
			if (a[i] != n) flag = false;
		}
		if (flag) break;
	}
	rep(i, n) cout << a[i] << ' ';
	cout << '\n';
}

Measured memory_bytes: 6868
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void)
{
	string abc;
	vector<int> cou(1000000, 0);
	int count = 0;
	cin >> abc;

	for (int i=0;;i++)
	{
		if (i + 1 == abc.length() - 1)
		{
			//cout << cou[i - count] << endl;
			//cout << cou[i - count-1] << endl;
			//cout << count << endl;
			if (abc[i] == 'R')
			{
				cou[i] += count / 2 + 1;
				cou[i + 1] += count - count / 2 + 1;
				count = 0;
				break;
			}

			if (abc[i] == 'L')
			{
				i++;
				count++;
				cou[i - count] += count / 2;
				cou[i - (count + 1)] += count - count / 2;
				count = 0;
				break;
			}
		}

		if (abc[i] != abc[i + 1])
		{
			

			if (abc[i] == 'R')
			{
				cou[i] += count / 2 + 1;
				cou[i + 1] += count - count / 2 + 1;
				count = 0;
				continue;
			}

			if (abc[i] == 'L')
			{
				cou[i-count] += count / 2;
				cou[i - (count + 1)] += count - count / 2;
				count = 0;
				continue;
			}

		}
		count++;
	}

	for (int i = 0;i < abc.length();i++)
	{
		cout << cou[i] << ' ';
	}
	cout << endl;
}

Measured memory_bytes: 7428
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<utility>
#include<queue>
#define pi 3.14159
#define Inf (int)pow(2., 20.)

using namespace std;
typedef std::pair<int, int> mypair;
int w, h, a[59][59];
queue<mypair> qu;
void bfs(int y, int x);

int main(){
	while(1) {
		cin >> w >> h;
		if(w == 0 && h == 0) break;
		for(int i = 0; i < 2*h-1; i++) {
			for(int j = 0; j < 2*w-1; j++) {
				if(i % 2 == 0 && j % 2 == 0) a[i][j] = Inf;
				else if(i % 2 == 1 && j % 2 == 1) a[i][j] = Inf;
				else cin >> a[i][j];
			}
		}
		a[0][0] = 1;
		if(a[0][1] == 0) {
			qu.push(mypair(0, 2));
			a[0][2] = 2;
		}
		if(a[1][0] == 0) {
			qu.push(mypair(2, 0));
			a[2][0] = 2;
		}
		if(qu.empty() == false) bfs(qu.front().first, qu.front().second);
		if(a[2*h-2][2*w-2] == Inf) cout << 0 <<endl;
		else cout << a[2*h-2][2*w-2] <<endl;
		
	}
	return 0;
}

void bfs(int y, int x) {
	qu.pop();
	
	//if(y == 2*h-2 && x == 2*w-2) return;
	if(x + 1 < 2*w-1) {
		if(a[y][x+1] == 0 && a[y][x+2] > a[y][x] + 1) {
			qu.push(mypair(y, x+2));
			a[y][x+2] = a[y][x] + 1;
		}
	}
	if(y+1 < 2*h-1) { 
		if(a[y+1][x] == 0 && a[y+2][x] > a[y][x] + 1) {
			qu.push(mypair(y+2, x));
			a[y+2][x] = a[y][x] + 1;
		}
	}
	if(y - 1 >= 0) {
		if(a[y-1][x] == 0 && a[y-2][x] > a[y][x] + 1) {
			qu.push(mypair(y-2, x));
			a[y-2][x] = a[y][x] +1;
		}
	}
	if(x - 1 >= 0) {
		if(a[y][x-1] == 0 && a[y][x-2] > a[y][x] + 1) {
			qu.push(mypair(y, x-2));
			a[y][x-2] = a[y][x] + 1;
		}
	}
	if(qu.empty() == false) bfs(qu.front().first, qu.front().second);
	return;
}

Measured memory_bytes: 1228
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;

#define MAX_N 1000000
#define INF 1000000

int a[MAX_N];
int b[MAX_N];


int main() {

  // ---------------------
  // Input
  
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  int A[N];

  int vote = 0;

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

  double threshold = double(vote) / (4.0*double(M));
  //cout << threshold << endl;
  
  // ---------------------
  //

  sort(A, A+N);

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if(A[i] >= threshold) cnt++;
  }

  if(cnt >= M) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  
  return 0;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,K;
  cin>>A>>B>>K;
  if(B-K+1<=A+K-1){
  for(int i=A;i<B+1;i++)
    cout<<i<<endl;
  }
    else{
  
  for(int i=A;i<A+K;i++){
    cout<<i<<endl;
  }
  for(int i=B-K+1;i<B+1;i++)
    cout<<i<<endl;
    }
}

Measured memory_bytes: 3584
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define ld long double
#define F first
#define S second
//
#define int long long
#define ll long long
#define db(x)                cerr<<#x<<": "<<x<<endl
#define db2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define db3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define db4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define db5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define db6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
//
#define mem(x,y) memset(x,y,sizeof(x))
#define bitcount    __builtin_popcount
//
#define pii pair<int, int>
#define all(v) v.begin(),v.end()
//
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define vi vector<int>
#define vvi vector< vector<int> >
#define si set<int>
#define pb push_back
#define lp(i,a,b) for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
#define mk make_pair
const int N=100+5;
const int mod=1e9+7;
const int mod1=998244353;
const int inf=1e16+7;
using namespace std;
int  v[N];
int w[N];
int dp[N][N*N*10];
int n,C;
int  ans=inf;
int rec(int i,int val){

    if(val==0){
        return 0;
    }
    if(i==n) return inf;
    if(dp[i][val]!=-1) return dp[i][val];
    int &ans=dp[i][val];
    ans=inf;
    ans=min(ans,rec(i+1,val-v[i])+w[i]);
    ans=min(ans,rec(i+1,val));
    return ans;
}
void solve(){
    memset(dp,-1,sizeof(dp));
    cin>>n>>C;
    lp(i,0,n) cin>>w[i]>>v[i];
    //rec(0,0);
    int  ans=inf;
    for(int val=0;val<=1e5;val++){
        if(rec(0,val)<=C)
            ans=val;
    }
    cout<<ans;
    
}


int32_t main() {
    IOS;
    
    int t;
    //cin>>t;
    t=1;
    for(int i=1;i<=t;i++){
       solve();
    }
   
}

















Measured memory_bytes: 90752
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line ="";
		Stack<Integer> stack = new Stack<Integer>();
		while((line = br.readLine()) !=null){
			int input = Integer.parseInt(line);
			if(input != 0){
				stack.push(input);
			}else{
				System.out.println(stack.pop());
			}
		}
	}

}

Measured memory_bytes: 24192
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}

struct Point {
    double x, y;
};

const double eps = 1e-10;

pair<Point, double> get_circle(Point p, Point q, Point r) {
    double a = p.x - q.x,
           b = p.y - q.y,
           c = q.x - r.x,
           d = q.y - r.y;
    double det = a * d - b * c;
    if(det == 0.0) return {{0,0},-1};
    double x = p.x * p.x + p.y * p.y - q.x * q.x - q.y * q.y,
           y = q.x * q.x + q.y * q.y - r.x * r.x - r.y * r.y;
    Point center = {
        (d * x - b * y) / (2.0 * det),
        (a * y - c * x) / (2.0 * det)
    };
    double radius = hypot(p.x - center.x, p.y - center.y);
    return make_pair(center, radius);
}

int main() {
    int N;
    cin >> N;
    vector<Point> p(N);
    auto judge = [&p](Point c, double r) -> bool {
        bool ans = true;
        for(Point a : p) {
            ans &= hypot(c.x - a.x, c.y - a.y) <= r + eps;
        }
        return ans;
    };
    for(Point &a : p) {
        cin >> a.x >> a.y;
    }
    double ans = 1e7;
    for(int i = 0; i < N; i++) {
        Point center;
        double radius;
        for(int j = i + 1; j < N; j++) {
            for(int k = j + 1; k < N; k++) {
                tie(center, radius) = get_circle(p[i], p[j], p[k]);
                if(radius < 0) continue;
                if(judge(center, radius)) ans = min(ans, radius);
            }
            center = {
                (p[i].x + p[j].x) / 2.0,
                (p[i].y + p[j].y) / 2.0
            };
            radius = hypot(center.x - p[i].x, center.y - p[i].y);
            if(judge(center, radius)) ans = min(ans, radius);
        }
    }
    cout << fixprec(15) << ans << endl;
    return 0;
}



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

int main(){


  int sum;

  while(1){
    
    sum=0;
    
    int t,n;
  
    cin>>t;
    
    if(t==0) break;
    
    cin>>n;
    
    int a,b;
  
    for(int i=0;i<n;i++){
      cin>>a>>b;
      sum+=b-a;
    }
    
    if(t<=sum) cout<<"OK"<<endl;
    else cout<<t-sum<<endl;
    
  }
  return 0;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using namespace std;
using P = pair<int,int>;
using ll = long long;
int main()
{
  int n,m;
  scanf("%d %d",&n,&m);
  vector<P> p(m);
  rep(i,m) cin >> p[i].first >> p[i].second;
  
  rep(x,1000){
    vector<int> a(0);
    int keta = 1;
    int x1 = x/10;
    a.pb(x%10);
    while(x1){
      keta++;
      a.pb(x1%10);
      x1 /= 10;
    }
    if(keta != n) continue;
    bool ok=true;
    reverse(all(a));
    rep(i,m) {
      if (a[p[i].first-1] != p[i].second) ok = false;
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
  }

  printf("%d\n",-1);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

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



int main(){
  int N,K;
  cin >> N >> K ;
  vector<int> a(N);
  map<int,int>dic;


  for (auto &e : a) //参照
   cin >> e;

  for (auto e : a)
    dic[e] += 1;

  vector<int>cv;

  for(auto e : dic) cv.push_back(e.second);

  if(K >= cv.size()){
    cout << 0 << endl;
    return 0;
  }

  sort(cv.begin(),cv.end());


  int ans=0;

  REP(i,cv.size()-K) ans += cv[i];

  cout << ans<< endl;


  return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n,k;cin>>n>>k;
  vector<int >a(n);
  rep(i, n)cin>>a[i];

  ll sum=0;
  rep(i, n)sum += a[i];

  set<ll>c;
  for(ll i=1; i*i<=sum; i++){
    if(sum%i)continue;
    c.insert(i);
    c.insert(sum/i);
  }

  ll ans = 0;
  for(ll cc: c){
    vector<ll>ca(n);
    rep(i, n)ca[i] = a[i]%cc;
    sort(ca.begin(), ca.end());

    ll psum = 0, msum=0;
    rep(i, n)msum += ca[i];
    rrep(i, n){
      msum-=ca[i];
      psum += cc-ca[i];
      ll cans = max<ll>(psum, msum);
      if(cans<=k)ans = max<ll>(ans, cc);
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3672
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static double dfs (int deep, final int N, int cur, double dist, boolean[] used, int[] xs, int[] ys) {
		if(deep >= N) {
			return dist;
		}else {
			double sum = 0;
		
			for(int i = 0; i < N; i++) {
				if(used[i]) { continue; }
			
				final double xd2 = cur < 0 ? 0 : (xs[cur] - xs[i]) * (xs[cur] - xs[i]);
				final double yd2 = cur < 0 ? 0 : (ys[cur] - ys[i]) * (ys[cur] - ys[i]);
				
				used[i] = true;
				sum += dfs(deep + 1, N, i, dist + Math.sqrt(xd2 + yd2), used, xs, ys);
				used[i] = false;
			}
			
			return sum;
		}
	}
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			int[] xs = new int[N];
			int[] ys = new int[N];
			
			for(int i = 0; i < N; i++) {
				xs[i] = sc.nextInt();
				ys[i] = sc.nextInt();
			}
			
			final boolean[] used = new boolean[N];;
			
			double answer = dfs(0, N, -1, 0, used, xs, ys);
			
			for(int i = 2; i <= N; i++) {
				answer /= i;
			}
			System.out.printf("%.10f\n", answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

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

#define V vector
#define PB push_back
#define P pair
#define MP make_pair
#define F first
#define S second

#define int int32_t

int sum_digits(int n) {
    int res = 0;
    while (n > 0) {
        res += n % 10;
        n /= 10;
    }
    return res;
}


int32_t main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin >> n;
	int mini = INT_MAX;
	for (int a = 1; a <= n / 2; a++) {
	    mini = min(mini, sum_digits(a) + sum_digits(n - a));
	}
	cout << mini << "\n";
	
	
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=4005,INF=1<<30;

struct UF{
    int n;
    vector<int> par,size;
    
    void init(int n_){
        n=n_;
        par.assign(n,-1);
        size.assign(n,1);
        
        for(int i=0;i<n;i++){
            par[i]=i;
        }
    }
    
    int root(int a){
        if(par[a]==a) return a;
        else return par[a]=root(par[a]);
    }
    
    void unite(int a,int b){
        if(root(a)!=root(b)){
            size[root(a)]+=size[root(b)];
            par[root(b)]=root(a);
        }
    }
    
    bool check(int a,int b){
        return root(a)==root(b);
    }
};

struct edge{
    int from;
    int to;
    ll cost;
    int type;
};

pair<ll,ll> check(ll plus,vector<edge> S,int N,int K){
    int M=si(S);
    for(int i=0;i<M;i++){
        if(!S[i].type) S[i].cost+=plus;
    }
    
    sort(all(S),[](auto a,auto b){
        if(a.cost==b.cost) return a.type<b.type;
        return a.cost<b.cost;
    });
    
    int cnt=0;
    ll sum=0;
    
    UF uf;
    uf.init(N);
    
    for(int i=0;i<M;i++){
        int a=uf.root(S[i].from),b=uf.root(S[i].to);
        if(uf.size[a]==N) break;
        
        if(!uf.check(a,b)){
            uf.unite(a,b);
            sum+=S[i].cost;
            if(!S[i].type) cnt++;
        }
    }
    
    if(K>N){
        return mp(sum-plus*(K-N),1);
    }
    
    if(uf.size[uf.root(0)]<N) return mp(0,0);
    
    if(plus==INF){
        if(cnt>K) return mp(0,0);
    }else if(plus==-INF){
        if(cnt<K) return mp(0,0);
    }
    
    if(cnt==K){
        return mp(sum-plus*K,1);
    }else if(cnt>K){
        return mp(1,0);
    }else{
        return mp(-1,0);
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,M,K;cin>>N>>M>>K;
        if(N==0) break;
        
        vector<edge> S(M);
        for(int i=0;i<M;i++){
            int a,b,c;char d;cin>>a>>b>>c>>d;
            a--;b--;
            if(d=='A') S[i]={a,b,c,0};
            else S[i]={a,b,c,1};
        }
        if(!check(INF,S,N,K).fi||!check(-INF,S,N,K).fi){
            cout<<-1<<endl;
            continue;
        }
        
        ll left=-INF,right=INF,ans=INF;
        while(right-left>1){
            ll mid=(left+right)/2;
            auto x=check(mid,S,N,K);
            if(x.se){
                ans=x.fi;
                break;
            }
            if(x.fi==1) left=mid;
            if(x.fi==-1) right=mid;
        }
        
        if(ans==INF){
            auto x=check(left,S,N,K+N);
            ans=x.fi;
        }
        cout<<ans<<"\n";
    }
    
}



Measured memory_bytes: 3232
#include <iostream>
#include <algorithm>
using namespace std;
int V[55];
int main() {
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  for (int i=0; i<N; i++) {
    cin >> V[i];
  }
  int ret = 0;
  for (int i=0; i<K; i++) { // dispose
    // get     n = max(0,min(K-i,N)) stones
    // dispose i   stones
    int n = max(0,min(K-i,N));
    for (int j=0; j<=n; j++) { // offset
      int spos = 0;
      int neg[55];
      int nneg = 0;
      for (int k=N-j; k<N; k++) {
        if (V[k] < 0) {
          neg[nneg++] = V[k];
        } else {
          spos += V[k];
        }
      }
      for (int k=0; k<n-j; k++) {
        if (V[k] < 0) {
          neg[nneg++] = V[k];
        } else {
          spos += V[k];
        }
      }
      sort(neg, neg+nneg);
      for (int k=i; k<nneg; k++) {
        spos += neg[k];
      }
      ret = max(ret, spos);
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]

cnt = 0
X = []
for i in range(h):
    for j in range(w):
        if A[i][j]%2 ==1:
            if j != w-1:
                cnt += 1
                X.append((i+1, j+1, i+1, j+2))
                A[i][j+1] += 1
            else:
                if i != h-1:
                    cnt += 1
                    X.append((i+1, j+1, i+2, j+1))
                    A[i+1][j] += 1
print(cnt)
for x in X:
    print(*x)


Measured memory_bytes: 75484
#include<stdio.h>
int main(){
    int l[3];

    for (int i = 0; i < 4; i++)
    {
        scanf("%d",&l[i]);
    }
    int a=l[0]*l[1];
    int b=l[2]*l[3];
    if (a>b)
        printf("%d",a);
    else
        printf("%d",b);
    
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
unsigned long long int a;
unsigned long long int b;
int x,y;
int main(){
scanf("%lld",&a);
scanf("%d.%d",&x,&y);
b=100*x+y;
printf("%lld",(a*b)/100);

}

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


int main(){
    int n;
    cin >> n;
    vector <int> vec(n);
    for ( int i = 0; i < n ; i++){
        cin >> vec.at(i);
    }
    int count = 0;
    for (int j = 0; j < (n - 2); j++) {
        int k, l;
        k = vec.at( j + 2 );
        l = vec.at( j + 1 ) ;
        if ((k - l) > 0 && (vec.at(j + 1) - vec.at(j)) > 0)
            count++;
        else if((k - l) < 0 && (vec.at(j + 1) - vec.at(j)) < 0)
            count++;

    }
    cout << count << endl;
}


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

using namespace std;

int main(void) {
	double x, y;
	double a, b, c, d, e, f;
	
	while(1) {
		cin >> a >> b >> c >> d >> e >> f;
		if(cin.eof()) { break; }
		
		y = (f-d*(c/a))/(-d*(b/a)+e);
		x = (c-b*y)/a;
		cout << setiosflags(ios::fixed) << setprecision(3) << x << " " << y << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
open System

#nowarn "25"

let readLine _ = Console.In.ReadLine()
let readInt<'a> = readLine >> int
let readLong<'a> = readLine >> int64
let readFloat<'a> = readLine >> float
let readArray _ = readLine().Split ' '
let readIntArray _ = readArray() |> Array.map (int)

[<EntryPoint>]
let main _ =
    let [|a; b|] = readIntArray()
    (if a < b
        then (Seq.replicate b (string a) |> String.Concat)
        else (Seq.replicate a (string b) |> String.Concat))
    |> printfn "%s"
    0 // return an integer exit code


Measured memory_bytes: 14044
#include <cstdio>
#include <cstring>
#define N 200005
char a[N], ch[N], c;
int n, sz[N], jm[N], nx[130];
int main() {
	int i;
	scanf("%s", &a[1]);
	n = strlen(a+1);
	for(c='a'; c<='z'; c++) nx[c]=-1;
	sz[n+1] = 1;
	for(i=n; i; i--) {
		nx[a[i]] = i;
		sz[i] = N;
		for(c='a'; c<='z'; c++) {
			if(sz[nx[c]+1] + 1 < sz[i]) {
				sz[i] = sz[nx[c]+1] + 1;
				jm[i] = nx[c] + 1;
				ch[i] = c;
			}
		}
	}
	for(i=1; sz[i]; i=jm[i]) putchar(ch[i]);
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
int main() {
  int64_t H, W, N;
  cin >> H >> W >> N;
  set<P> S;
  set<P> point;
  vector<int> move = {-1,0,1};
  for(int i=0; i<N; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    P po = make_pair(a,b);
    point.insert(po);
    for(int j=0; j<3; j++){
      for(int k=0; k<3; k++){
        int na = a + move[j];
        int nb = b + move[k];
        if(na > 0 && na < H-1 && nb > 0 && nb < W-1){
          P p = make_pair(na,nb);
          S.insert(p);
        }
      }
    }
  }
  
  vector<int64_t> ans(10);
  ans.at(0) = (H-2)*(W-2);
  for(auto itr = S.begin(); itr != S.end(); itr++){
    int cnt = 0;
    P p = *itr;
    for(int i=0; i<3; i++){
      for(int j=0; j<3; j++){
        P is = make_pair(p.first + move[i], p.second + move[j]);
        if(point.count(is)){
          cnt++;
        }
      }
    }
    ans[cnt]++;
    ans[0]--;
  }
  
  for(int i=0; i<10; i++){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 47104
m, d = map(int, input().split())

ans = 0

for _m in range(m):
  _m += 1
  for _d in range(d):
    _d += 1
    if _d >= 22:
      d1 = int(str(_d)[0])
      d2 = int(str(_d)[1])
      if d2 < 2:
        continue
      if _m == d1 * d2:
        ans += 1
print(ans)

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

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define INF 1e9+2137
#define all(x) (x).begin(), (x).end()

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 1e3+1;
const int M = 1e9+7;

int h, w;

bool grid[MAX][MAX];
ll dp[MAX][MAX];
int main()
{
    _upgrade;
    cin>>h>>w;
    FOR(i, 0, h)
        FOR(j, 0, w)
        {
            char c;
            cin>>c;
            grid[i][j] = (c == '.' ? 1 : 0);
        }
    dp[0][0] = 1;
    FOR(i, 1, w)
    {
        if(!grid[0][i])
            dp[0][i] = 0;
        else
            dp[0][i] = dp[0][i-1];
    }
    FOR(i, 1, h)
    {
        if(!grid[i][0])
            dp[i][0] = 0;
        else
            dp[i][0] = dp[i-1][0];
    }

    FOR(i, 1, h)
        FOR(j, 1, w)
        {
            if(!grid[i][j])
                dp[i][j] = 0;
            else
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
            dp[i][j] %= M;
        }

    cout<<dp[h-1][w-1];
}


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

int main() {
	int n,m;
	cin >> n >> m;
	vector<ll> x(n), y(n), xs(n), ys(n);
	for(int i=0;i<n;i++) {
		cin >> x[i] >> y[i];
		xs[i] = x[i];
		ys[i] = y[i];
	}
	// 座標圧縮
	xs.push_back(-2*INF);
	ys.push_back(-2*INF);
	sort(xs.begin(),xs.end());
	sort(ys.begin(),ys.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	ys.erase(unique(ys.begin(),ys.end()),ys.end());

	for(int i=0;i<n;i++) {
		x[i] = lower_bound(xs.begin(),xs.end(),x[i]) - xs.begin();
		y[i] = lower_bound(ys.begin(),ys.end(),y[i]) - ys.begin();
		//cout << x[i] << " " << y[i] << endl;
	}
	vector<vector<ll>> sum(ys.size()+5,vector<ll>(xs.size()+5,0));
	for(int i=0;i<n;i++) {
		sum[y[i]][x[i]]++;
	}
	for(int i=1;i<=ys.size();i++) {
		for(int j=1;j<=xs.size();j++) {
			sum[i][j] = sum[i][j] + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
		}
	}
	/*
	for(int i=0;i<=ys.size();i++) {
		for(int j=0;j<=xs.size();j++) {
			cout << sum[i][j] << " ";
		}
		cout << endl;
	}
	*/
	for(int i=0;i<m;i++) {
		ll x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		x1 = lower_bound(xs.begin(),xs.end(),x1) - xs.begin();
		y1 = lower_bound(ys.begin(),ys.end(),y1) - ys.begin();
		x2 = upper_bound(xs.begin(),xs.end(),x2) - xs.begin() - 1;
		y2 = upper_bound(ys.begin(),ys.end(),y2) - ys.begin() - 1;

		ll ans = sum[y2][x2] - sum[y2][x1-1] - sum[y1-1][x2] + sum[y1-1][x1-1];
		cout << ans << endl;
	}
}


Measured memory_bytes: 199044
#include <cstdio>
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <string>

using namespace std;
using ll = long long;

ll N;
vector<ll> B;

void input() {
    cin >> N;
    B.resize(N);
    for (auto& b : B)
        cin >> b;
//    N = 10;
//    B = {1,2,2,3,5,1,6,4,7,3};
}

void solve() {
    for (ll i = 0; i < N; i++) {
        if (B[i] > i + 1) {
            cout << -1 << endl;
            return;
        }
    }

    vector<ll> ans;
    ll len = N;
    while (len) {
        for (ll i = len-1; i >= 0; i--) {
            auto b = B[i];
            if (b == i + 1) {
                ans.push_back(b);
                for (ll k = i; k < len; k++) {
                    B[k] = B[k + 1];
                }
                break;
            }
        }
        len--;
    }
    reverse(ans.begin(), ans.end());
    for (auto a : ans)
        cout << a << endl;
}

int main() {
    input();
    //    cout << solve() << endl;
    solve();

    return 0;
}



Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
using namespace std;
int main(){
	
	int a,s=0;
	
	for(int i=0;i<5;i++){
		cin>>a;
		if(a<40)
			a=40;
		s+=a;
	}
			
	cout<<s/5<<endl;

}

Measured memory_bytes: 1164
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repr(i,a,b) for (int i = a; i > b; --i)
#define mm(lamb, tttt) memset(lamb, tttt, sizeof lamb)
 
#define null NULL
#define eps 0.000000001
#define mod 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
#define _ <<" "<<
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 	//ll ans = 1;
	//freopen ("test.txt","r",stdin);
 	ll n,w;
 	cin>>n>>w;
 	ll weight[n+1];
 	ll value[n+1];
 	for (int i = 1; i <= n; ++i)
 	{
 		cin>>weight[i]>>value[i];
 	}

 	ll dp[n+1][w+1];

 	for (int i = 0; i <= n ; ++i)
 	{
 		for(int j=0;j<= w ; j++)
 		{
 			if(i==0 || j==0)
 			{
 				dp[i][j] = 0;
 			}
 			else if( j - weight[i] >= 0)
 			{
 				dp[i][j] = max( dp[i-1][j] , dp[i-1][j - weight[i]] + value[i]) ;
 			}
 			else
 			{
 				dp[i][j] = dp[i-1][j];
 			}
 		}
 	}

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

Measured memory_bytes: 79232