akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
using namespace std;
struct Data{
    int x;
    int y;
    int t;
};
bool vis[1005][1005];
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
int main(){
    int h,w,n;
    cin>>h>>w>>n;
    string fi[1020];
    Data init;
    for(int i = 0;i < h;i++){
        cin>>fi[i];
        for(int j = 0;j < w;j++){
            if(fi[i][j] == 'S'){
                init.x = j;
                init.y = i;
            }
        }
    }
    init.t = 0;

    queue<Data> Q;
    Q.push(init);
    int now = 1;
    while(!Q.empty()){
        Data D = Q.front();
        Q.pop();
        D.t++;
        if(vis[D.y][D.x])continue;
        if(fi[D.y][D.x] == now + '0'){
            now++;
            for(int i = 0;i < h;i++){
                for(int j = 0;j < w;j++){
                    vis[i][j] = false;
                }
            }
            Q = queue<Data>();
            Q.push(D);
        }
        vis[D.y][D.x] = true;
        if(now == n+1){
            cout<<D.t-1<<endl;
            return 0;
        }
        for(int i = 0;i < 4;i++){
            int x = D.x + dx[i];
            int y = D.y + dy[i];
            if(0 <= x&&x < w&&0 <= y&& y < h){
                if(fi[y][x] == 'X')continue;
                if(vis[y][x])continue;
                Data E = D;
                E.x = x, E.y = y;
                Q.push(E);
            }
        }
    }
}

Measured memory_bytes: 3260
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            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<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let mut s = get!(String).chars().collect::<VecDeque<_>>();
    let q = get!(usize);
    let mut rev = false;
    for _ in 0..q {
        let query = get!(String);
        if query.chars().next().unwrap() == '1' {
            rev = !rev;
            continue;
        }
        let query = query.split_whitespace().collect::<Vec<_>>();
        let f = query[1].chars().next().unwrap();
        let c = query[2].chars().next().unwrap();

        if (f == '1') ^ rev {
            s.push_front(c);
        } else {
            s.push_back(c);
        }
    }
    if rev {
        for c in s.into_iter().rev() {
            print!("{}", c);
        }
    } else{
        for c in s {
            print!("{}", c);
        }
    }
    println!("");
}


Measured memory_bytes: 10876
#include <stdio.h>

int main(void) {
	
	int x,y,z,m;
	scanf("%d",&x);
	scanf("%d",&y);
	
	z=x*y;
	m=2*x+2*y;
	
	
	printf("%d %d\n",z,m);
	// your code goes here
	return 0;
}



Measured memory_bytes: 2060
#include<iostream>
#include <cstdio>
#include<cstring>
#include<string>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define LEN 100005
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpc[10000][10000];

bool chsK(string s) {
	int n = s.length();
	if (n % 2 == 0) {
		for (int i = 0;i <= n / 2;i++) {
			if (s[i] != s[n - i - 1])return false;
		}
	}
	else {
		for (int i = 0;i <= n / 2;i++) {
			if (s[i] != s[n - i - 1])return false;
		}
	}
	return true;
}

int check(int X, int Y, int K, int J) {
	int t;
	if (K >= Y && J <= X)t = X - J + K - Y + 1;
	else if (K <= X || J >= Y) t = K - J;
	else if (J >= X && K <= Y)t = min(K - J, J - X + Y - K + 1);
	else if (K >= X && K <= Y)t = min(K - J, X - J + Y - K + 1);
	else if (J >= X && J <= Y)t = min(K - J, J - X + K - Y + 1);
	return t;
}

ll func(ll n,ll k){
	if (k > n) { if (k - n > 0)return min(n,k-n);
	else return min(n, n - k); };
	ll t = n / k;
	n =min( n - t * k,-(n-(t+1)*k));
	if (n >=0&& n <= k / 2 )return n;
	else {
		func(n, k);
	}
}

//void nCr(ll n, ll r) {
//	ll ans = 1;
//	for (int i = n; i > n - r; --i) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; ++i) {
//		ans = ans / i;
//	}
//	printf("%d",ans);
//}

ll combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else if (dpc[n][r]) { return dpc[n][r]; }
	else { return dpc[n][r] = combination(n - 1, r - 1) + combination(n - 1, r); }
}



int main() {
	ll n, k;
	cin >> n >> k;
	ll t = func(n, k);
	cout << t << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000






int main() {
	long long a[N];
	long long x;
	int n;
	long long ans;
	ans = 0;
	scanf("%d", &n);
	f(i, n+1) {
		scanf("%lld", &a[i]);
	}
	f(i, n) {
		scanf("%lld", &x);
		if (a[i] >= x) {
			ans += x;
			a[i] -= x;
		}
		else {
			ans += a[i];
          	x -= a[i];
			a[i] = 0;
			x = min(x, a[i + 1]);
			ans += x;
			a[i + 1] -= x;
		}
	}
	printf("%lld\n",ans);



	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int S; cin >> S;
	int s = S % 60;
	S /= 60;
	int m = S % 60;
	S /= 60;
	int h = S % 60;
	S /= 60;
	printf("%d:%d:%d\n", h, m, s);
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}



Measured memory_bytes: 3248
/*
Written By mafailure
*/
//In the name of God
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long 
// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
const long long mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
#define w(t) int t;cin>>t; while(t--)
#define takeInp(n) int n;cin>>n;
#define fr(i,init,final) for(int i=init;i<final;i++)
#define frr(i,init,final) for(int i=init;i>=final;i--)
#define Fr(i,final) for(int i=0;i<final;i++)
#define Frr(i,first) for(int i=first;i>=0;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;
#define setb __builtin_popcount
#define lsone(n) (n&(-n))
#define rlsone(n) (n&(n-1))

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  nds; 
vi init(string s)
{
	istringstream sin(s);
	int n;
	vi arr;
	while(sin>>n)arr.push_back(n);
	return arr;
}
int power(int x, int y)
{ 
	if(y==0)return 1;
	int u=power(x,y/2);
	u=(u*u)%mod;
	if(y%2)u=(x*u)%mod;
	return u;
    
}
int gcd(int a,int b)
{
	if(a<b)return gcd(b,a);
	return (b==0?a:(a%b?gcd(b,a%b):b));
}
int gcd_e(int a,int b,int &x,int &y)
{
	
	if(b==0){x=1; y=0; return a;}
	int x1,y1;
	int p=gcd_e(b,a%b,x1,y1);
	x=y1;
	y=x1-(a/b)*y1;
	return p;
}
signed main()
{
	IOS
	int x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	if(k<=x/d)cout<<x-(k)*d<<endl;
	else 
	{
		k-=x/d;
		int pos_side=x-(x/d)*d;
		int neg_side=d-(x%d);
		if(k%2)cout<<neg_side<<endl;
		else cout<<pos_side<<endl;
	}
	
	
}



Measured memory_bytes: 3648
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <climits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define pii pair<long long,long long>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15)

namespace {
	struct input_returnner {
		int N; input_returnner(int N_ = 0) :N(N_) {}
		template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
		template<typename T> operator T() const { T res; cin >> res; return res; }
		template<typename T> T operator - (T right) { return T(input_returnner()) - right; }
		template<typename T> T operator + (T right) { return T(input_returnner()) + right; }
		template<typename T> T operator * (T right) { return T(input_returnner()) * right; }
		template<typename T> T operator / (T right) { return T(input_returnner()) / right; }
		template<typename T> T operator << (T right) { return T(input_returnner()) << right; }
		template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; }
	};
	template<typename T> input_returnner in() { return in<T>(); }
	input_returnner in() { return input_returnner(); }
	input_returnner in(int N) { return std::move(input_returnner(N)); }
}

void solve();
/// ---template---
signed main(void) {
	SETUP;
	solve();
	return 0;
}

void solve() {
	priority_queue<pair<int, pii>, vector<pair<int, pii> >, greater<pair<int, pii> > > que;
	ll W, H; cin >> W >> H;
	REP(i, W) que.emplace(in(), pii(i, 0));
	REP(i, H) que.emplace(in(), pii(i, 1));

	ll w = W+1, h = H+1;

	ull res = 0;

	while (not que.empty()) {
		auto a = que.top(); que.pop();
		if (a.second.second == 0) {
			res += a.first*h;
			--w;
		}
		else if (a.second.second == 1	) {
			res += a.first*w;
			--h;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 6512
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  cin >> n;
  set<int> A;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    A.insert(x);
  }
  if (A.size() == n) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 9600
#include<stdio.h>

int main(void){
  int N,i,T[30001];
  char S[30001];
  scanf("%d\n",&N);
  scanf("%s",S);
  
  for(i=0;i<=N-1;i++){
    if(S[i]=='0'){
      T[i]=0;
    }else if(S[i]=='1'){
      T[i]=1;
    }else if(S[i]=='2'){
      T[i]=2;
    }else if(S[i]=='3'){
      T[i]=3;
    }else if(S[i]=='4'){
      T[i]=4;
    }else if(S[i]=='5'){
      T[i]=5;
    }else if(S[i]=='6'){
      T[i]=6;
    }else if(S[i]=='7'){
      T[i]=7;
    }else if(S[i]=='8'){
      T[i]=8;
    }else{
      T[i]=9;
    }
  }
  
  int m[10],k[10],a[30001],b[30001];
  for(i=0;i<=9;i++){
    k[i]=0;
    m[i]=0;
  }
  a[0]=0;
  for(i=1;i<=N-1;i++){
    if(k[T[i-1]]==0){
      a[i]=a[i-1]+1;
      b[i-1]=a[i-1];
    }else{
      a[i]=a[i-1];
      b[i-1]=a[i-1]-a[m[T[i-1]]];
    }
    k[T[i-1]]++;
    m[T[i-1]]=i-1;
  }
  b[N-1]=a[N-1]-a[m[T[N-1]]];
  m[T[N-1]]=N-1;
  
  int t[10],j,A;
  A=0;
  for(i=0;i<=9;i++){
    t[i]=0;
    if(m[i]!=0){
      for(j=0;j<m[i];j++){
        t[i]=t[i]+b[j];
      }
    }
    A=A+t[i];
  }
  
  printf("%d",A);
  
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    string ans = "No";
    rep(i, n){
        int a, b;
        cin >> a >> b;
        if(a == b) cnt++;
        else cnt = 0;
        if(cnt == 3){
            ans = "Yes";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<long long> H(N);
    for (int i = 0; i < N; i++) cin >> H[i];

    sort(H.begin(), H.end(), greater<int>());
    long long ans = 0;
    for (int i = K; i < N; i++) {
        ans += H[i];
    }

    cout << ans << endl;
}

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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = int.Parse(Console.ReadLine());
            Console.WriteLine(N / 2 * ((N + 1) / 2));
        }
    }
}

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

int main()
{
  long long n, m, r;
  scanf("%lld%lld%lld", &n, &m, &r);
  long long town[8];
  for (long long i = 0; i < r; ++i)
  {
    scanf("%lld", town + i);
    town[i]--;
  }
  std::sort(town, town + r);
  long long d[200][200];
  std::fill((long long*)d, (long long*)d + 40000, 1e8);
  for (long long i = 0; i < m; ++i)
  {
    long long a, b, c;
    scanf("%lld%lld%lld", &a, &b, &c);
    --a, --b;
    d[a][b] = c;
    d[b][a] = c;
  }
  
  for (long long i = 0; i < n; ++i)
  {
    for (long long j = 0; j < n; ++j)
    {
      for (long long k = 0; k < n; ++k)
      {
        d[j][k] = std::min(d[j][k], d[j][i] + d[i][k]);
      }
    }
  }
  
  long long ans = 1e10;
  do
  {
    long long sum = 0;
    for (long long i = 0; i < r - 1; ++i)
    {
      sum += d[town[i]][town[i + 1]];
    }
    if (ans > sum) ans = sum;
  } while (std::next_permutation(town, town + r));
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();
        double answer = 0;
        if(n != 100){
            answer = n*Math.pow(100,d);
        } else {
            answer = 101*Math.pow(100,d);
        }
        int answeri = (int)answer;
        System.out.print(answeri);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vi le, ge;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        if (x < 0)
            le.push_back(-x);
        else
            ge.push_back(x);
    }
    reverse(all(le));
    int sol = 1e9;
    if (ge.size() >= k)
        sol = min(sol, ge[k - 1]);
    if (le.size() >= k)
        sol = min(sol, le[k - 1]);

    for (int i = 0; i < min(k - 1, (int)ge.size()); ++i)
    {
        int l = k - i - 2;
        if (l < le.size())
            sol = min(sol, 2 * ge[i] + le[l]);
    }
    for (int i = 0; i < min(k - 1, (int)le.size()); ++i)
    {
        int l = k - i - 2;
        if (l < ge.size())
            sol = min(sol, 2 * le[i] + ge[l]);
    }
    cout << sol;
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int a;
	cin >> a;
	cout << a + a * a + a * a * a << endl;
	return 0;
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;


class Program
{
    static void Main(string[] Args) {
        var lis = new List<string>(ReadLine().Split(' ')).Select(int.Parse).ToList();

        int Result = 0;

        for (int X = 0; X <= lis[0]; X++)
            for (int Y = 0; Y <= lis[0]; Y++)
                if (0 <= lis[1] - X - Y && lis[1] - X - Y <= lis[0])
                    Result++;

        WriteLine(Result);

        ReadLine();
    }
}


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

const int MAXN = 2000 * 1000 + 3;

const ll MOD = 998244353;

ll pw(ll a, ll b = MOD - 2) {
    if (!b) {
        return 1;
    }

    ll v = pw(a, b / 2);
    v = (v * v) % MOD;
    if (b & 1) {
        v = (v * a) % MOD;
    }

    return v;
}

int n, k;
ll fact[MAXN];
ll rfact[MAXN];

ll cnk(int x, int y) {
    if (x < 0 || y < 0) {
        return 0;
    }

    return fact[x + y] * rfact[x] % MOD * rfact[y] % MOD;
}

ll calc(int r, int b, int bal) {
    ++bal;
    if (bal <= 0) {
        return 0;
    }

    ll tot = cnk(r, b);
    ll bad = cnk(b - bal, r + bal);
    return (tot + MOD - bad) % MOD;
}

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
    fact[0] = 1;
    for (int i = 1; i < MAXN; ++i) {
        fact[i] = fact[i - 1] * ll(i) % MOD;
    }

    rfact[MAXN - 1] = pw(fact[MAXN - 1]);
    for (int i = MAXN - 1; i > 0; --i) {
        rfact[i - 1] = rfact[i] * ll(i) % MOD;
    }

    cin >> n >> k;

    --k;
    --n;

    ll ans = 0;
    
    for (int r = 0; r <= k; ++r) {
        int b = k - r;

        if (r >= b) {
            int needPairs = n - (r - b);
            int worstBal = b - needPairs;
            ans += calc(r, b, worstBal);
        }

        if (r > b) {
            int needPairs = n - (r - 1 - b);
            int worstBal = b - needPairs;
            ans += calc(r, b, worstBal);
        }

        ans %= MOD;
    }

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

Measured memory_bytes: 31616
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int p[10001];

int main() {
  int n;
  p[0] = p[1] = 1;
  for (int i=4; i<=10000; i+=2) p[i] = 1;
  for (int i=3; i*i<=10000; i+=2) {
    if (p[i] == 0)
      for (int j=2; i*j<=10000; ++j) p[i*j] = 1;
  }

  int k[3];
  cin>>n;
  for (int i=0; i<n; ++i) cin>>k[i];
  set<int> s;
  for (int i=1; i<=k[0]; ++i) if (k[0]%i == 0) s.insert(i);
  for (int i=1; i<n; ++i) {
    set<int> t;
    for (set<int>::iterator it = s.begin(); it != s.end(); ++it) {
      if (k[i]%(*it) == 0) t.insert(*it);
    }
    s = t;
  }

  for (set<int>::iterator it = s.begin(); it != s.end(); ++it)
    cout<<*it<<endl;
}

Measured memory_bytes: 1240
S = input()
N = len(S)
SUM = [0] * (N + 1)
MOD = 2019

r = 1  # 10のi乗を2019で割った余り
S = S[::-1]
for i in range(N):
    A = r * int(S[i])
    SUM[i + 1] = (SUM[i] + A) % MOD
    r = r * 10 % MOD

cnt = [0] * 2019
ans = 0
for x in SUM:
    ans += cnt[x]
    cnt[x] += 1
print(ans)


Measured memory_bytes: 16140
N = int(input())
# N = int('15')
cand = []
def func(a):
    return sum([int(i) for i in str(a)])
for i in range(1, N//2 + 1):
    a = i
    b = N - i
    cand.append(func(a) + func(b))
print(min(cand))

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

int main(){
  int k,a,b; cin>>k>>a>>b;
  for(int i=a;i<=b;i++){
    if(i%k==0){
      cout<<"OK"<<endl;
      return 0;
    }
  }
  cout<<"NG"<<endl;
}

Measured memory_bytes: 3624
# from pprint import pprint
# import math
# import collections

n = int(input())
# n, k = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))
sai1 = []
sai2 = []
for i in range(n):
    _sai1, _sai2 = map(int, input().split(' '))
    sai1.append(_sai1)
    sai2.append(_sai2)

z_cnt = 0
for i in range(n):
    if sai1[i] == sai2[i]:
        z_cnt += 1
    else:
        z_cnt = 0
    if z_cnt == 3:
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 9180
import sys
input = sys.stdin.readline

n = int(input())
dp = [0]*(n+1)

for x in range(1, 100):
  for y in range(1, 100):
    for z in range(1, 100):
      tmp = x*x + y*y + z*z + x*y + y*z + z*x
      if tmp <= n:
        dp[tmp] += 1

for i in range(1, n+1):
  print(dp[i])

Measured memory_bytes: 74788
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 41;
const LL INF = 1e9;

void print_a(VI v)
{
    if(v.size()) cout<<v[0];
    loop(i,1,v.size()) cout<<' '<<v[i];
    cout<<'\n';
}

VVI init_vvi(int n, int m, int val)
{
    return VVI(n,VI(m,val));
}

VVL init_vvl(int n, int m, LL val)
{
    return VVL(n,VL(m,val));
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n;
    cin>>n;
    LL a[n];
    loop(i,0,n) cin>>a[i];

    LL s = a[0] + a[1], x = 0;
    loop(i,2,n) x = x ^ a[i];
    LL d = s - x, ans;
    if(d < 0 || d & 1) ans = -1;
    else
    {
        d /= 2;
        int f = 1;
        loop(i,0,MX)
        {
            if((d & ((LL)1 << i)) && (x & ((LL)1 << i))) {f = 0; break;}
        }

        if(f && d <= a[0])
        {
            ans = d;
            //watch(d); watch(x);
            rev_loop(i,MX-1,0)
            {
                if((x & ((LL)1 << i)) && ((ans + ((LL)1 << i)) <= a[0]))
                {
                    //watch(i); watch(ans);
                    ans += ((LL)1 << i);
                    //watch(ans);
                }
            }
            if(ans == 0) ans = -1;
            else ans = a[0] - ans;
        }
        else ans = -1;
    }

    cout<<ans<<'\n';

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n) cin>>a[i];
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n) cin>>a[i];
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 3660
#D問題
def find(A,x):
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a

def union(A, x, y):
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    A[y] = bx
    A[by] = bx

import heapq

N = int(input())

XY0 = []
XY1 = []
for i in range(N):
    x,y = map(int,input().split())
    XY0.append([x,y,i])
    XY1.append([x,y,i])

XY0.sort()
XY1 = sorted(XY1, key=lambda x: x[1])

E = []
for i,x in enumerate(XY0):
    if i == 0:
        ox = x[0]
        oi = x[2]
    else:
        dx = x[0]-ox
        ox = x[0]
        heapq.heappush(E,[dx,oi,x[2]])
        oi = x[2]

for i,y in enumerate(XY1):
    if i == 0:
        oy = y[1]
        oi = y[2]
    else:
        dy = y[1]-oy
        oy = y[1]
        heapq.heappush(E,[dy,oi,y[2]])
        oi = y[2]



V = [i for i in range(N)]
ans = 0
while E:
    w,s,t = heapq.heappop(E)
    if find(V,s) != find(V,t):
        union(V,s,t)
        ans+=w
        
print(ans)



Measured memory_bytes: 63936
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MX = 1<<18;

struct Tree{
	ll t[MX*2];
	void update(int x, ll v){
		x += MX; 
		while(x) t[x] = min(t[x], v), x /= 2;
	}
	ll read(int s, int e){
		s += MX, e += MX;
		ll r = 1e18;
		while(s <= e){
			if( s&1 ) r = min(r, t[s++]);
			if(~e&1 ) r = min(r, t[e--]);
			s /= 2, e /= 2;
		}
		return r;
	}
} t1, t2;

ll S[MX], T[MX];
int D[MX];
int N, Q;

ll abs(ll x){ return x > 0? x : -x; }

int main()
{
	for(int i = 1; i < MX*2; i++) t1.t[i] = t2.t[i] = 1e18;

	scanf("%d%d%d%d", &N, &Q, D, D+1); Q++;
	for(int i = 2; i <= Q; i++) scanf("%d", D+i);
	for(int i = 2; i <= Q; i++){
		S[i] = S[i-1] + abs(D[i] - D[i-1]);
	}
	ll ans = 1e18;
	T[1] = 0; t1.update(D[0], +D[0]); t2.update(D[0], -D[0]);
	for(int i = 2; i <= Q; i++){
		T[i] = min(t1.read(D[i], N) - D[i] + S[i-1], t2.read(1, D[i]) + D[i] + S[i-1]);
		t1.update(D[i-1], T[i] - S[i] + D[i-1]);
		t2.update(D[i-1], T[i] - S[i] - D[i-1]);
	}
	for(int i = 1; i <= Q; i++){
		ans = min(ans, T[i] + S[Q] - S[i]);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)
#define ALL(x) (x).begin(),(x).end()
template <class T> void chmin(T& a, const T& b) { if (b < a) a = b; }
const char* LF = "\n";
namespace{struct _{_(){
    cin.tie(0);
    ios::sync_with_stdio(false);
}}a;}

vector<int> C;
vector<int> memo;

int find(int n) {
    if (n <= 0) return 0;
    if (memo[n] != -1) return memo[n];

    int ret = n;
    REP(i, C.size()) {
        if (n - C[i] >= 0) chmin(ret, find(n - C[i]) + 1);
    }

    return memo[n] = ret;
}

signed main() {
    int N;
    cin >> N;
    memo.resize(N+1, -1);

    C.reserve(100);

    FOR(i, 1, 10) {
        if (pow(6, i) <= N) C.push_back(pow(6, i));
        if (pow(9, i) <= N) C.push_back(pow(9, i));
    }
    C.push_back(1);

    cout << find(N) << LF;
    return 0;
}


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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
inline void update(int& n, int m){
  n = max(n, m);
}

int main(){
  int C, N, M, X;
  while(cin>>C>>N>>M>>X && C){
    int c_s[101] = {}, e_s[101] = {};
    int c[101] = {}, e[101] = {};
    char tmp[256];
    REP(i, N){
      scanf("%s %d %d", tmp, &c_s[i], &e_s[i]);
    }
    REP(i, M){
      scanf("%s %d %d", tmp, &c[i], &e[i]);
    }
    int dp[2][101][1001] = {}; // i use money
    memset(dp, -1, sizeof(dp));
    dp[0][0][0] = 0;
    for(int i = 0; i < M; i++){
      for(int use = 0; use <= i; use++){
        for(int cost = 0; cost <= C; cost++){
          if(cost + c[i] <= C && dp[i % 2][use][cost] != -1) update(dp[(i + 1) % 2][use + 1][cost + c[i]], dp[i % 2][use][cost] + e[i]);
          update(dp[(i + 1) % 2][use][cost], dp[i % 2][use][cost]);
        }
      }
    }
    for(int use = 1; use <= M; use++){
      for(int cost = 1; cost <= C; cost++){
        update(dp[M%2][use][cost], dp[M%2][use][cost - 1]);
      }
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
      for(int j = i + 1; j <= N; j++){
        int rest = C - (c_s[i] + c_s[j]);
        if(rest <= 0) continue;
        int effect_c = e_s[i] + e_s[j];
        int effect = 0;
        for(int use = X; use <= M; use++){
          update(effect, dp[M%2][use][rest]);
        }
        ans = max(ans, effect_c + effect);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

const int MOD = int(1e9) + 7;
using lint = long long;

struct modint {
    int v;
    modint(lint v_ = 0): v(v_ % MOD) { }
    modint operator+ (const modint &m) const {
        return modint(v + m.v);
    }
    modint operator- (const modint &m) const {
        return modint(v - m.v + MOD);
    }
    modint operator* (const modint &m) const {
        return modint((lint)v * m.v);
    }
    modint operator+= (const modint &m) {
        v = (v + m.v) % MOD;
        return *this;
    }
    modint operator*= (const modint &m) {
        v = ((lint)v * m.v) % MOD;
        return *this;
    }
    modint operator-= (const modint &m) {
        v = (v - m.v + MOD) % MOD;
        return *this;
    }
    modint pow(int k) {
        modint cur(v), ret(1);
        while(k > 0) {
            if(k & 1) ret *= cur;
            cur = cur * cur;
            k >>= 1;
        }
        return ret;
    }
    modint inv() {
        return pow(MOD - 2);
    }
};

const modint INV2 = modint(2).inv();

int N, K;

modint ans;

modint ways[int(5.1e4)];

int main() {
    scanf("%d%d", &N, &K);
    
    vector<int> divs;
    for(int i = 1; i * i <= N; i++) {
        if(N % i == 0) {
            divs.push_back(i);
            if(i * i != N) divs.push_back(N/i);
        }
    }
    
    sort(divs.begin(), divs.end());
    
    for(int i = 0; i < int(divs.size()); i++) {
        // degree of freedom : divs[i]
        
        ways[i] += modint(K).pow((divs[i] + 1) / 2);
        for(int j = 0; j < i; j++) if(divs[i] % divs[j] == 0) ways[i] -= ways[j];
        
        ans += (divs[i] % 2 == 1 ? modint(1) : INV2) * ways[i] * divs[i];
    }
    
    printf("%d\n", ans.v);
    
    
    return 0;
}

/*
N이 홀수

ABCBA => A, B, C 중 하나라도 다르면 서로 다른 수열을 얻음

BCBAA -> B=A, C=A -> 전부 같아야
CBAAB -> C=B=A
BAABC -> B=C=A
AABCB -> A=B=C

염려:
DEFED
EFEDD
FEDDE
EDDEF
DDEFE


N이 짝수 -> A, B, C가 하나라도 다르면 서로 다른 palin 수열 2개가 같은 결과

ABCCBA 
BCCBAA B=A=C
CCBAAB C=B=A
CBAABC (palin!)
BAABCC B=C=A
AABCCB A=B=C
*/

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>

using namespace std;

long long a, b, x;
long long aa, bb;

int main()
{
    scanf("%lld%lld%lld", &a, &b, &x);
    aa = (a + x - 1) / x;
    bb = b / x;
    printf("%lld", bb - aa + 1);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define mp make_pair
// GCD inbuilt func: __gcd(a,b)
// LCM formula: (a*b)/__gcd(a,b)
 

ll dp[3001][3001][4];

int main(){
    int r,c,items, x, y, v;
    cin >> r >> c >> items;
    for(int i=0;i<r;i++){
    	for(int j=0;j<c;j++){
    		for(int k=0;k<4;k++) dp[i][j][k]=0;
    	}
    }
    ll a[r+1][c+1];
    for(int i=0;i<r;i++)
        for(int j=0;j<c;j++) a[i][j]=0;
    while(items--){
    	cin >> x >> y >> v;
    	a[x-1][y-1]=v;
    }
    if(r==1 && c==1){
        cout << a[r-1][c-1];
        return 0;
    }
    for(int i=0;i<r;i++){
    	for(int j=0;j<c;j++){
            for(int k=2;k>=0;k--){
                dp[i][j][k+1]=max(dp[i][j][k+1],dp[i][j][k]+a[i][j]);
            }
            for(int k=0;k<4;k++){
                if(j+1!=c) dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
                if(i+1!=r) dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
            }
    	}
    }
    ll maxi=0;
    for(int i=0;i<r;i++){
    	for(int j=0;j<c;j++){
    		for(int k=0;k<4;k++){
    			maxi=max(maxi,dp[i][j][k]);
    		}
    	}
    }
    cout << maxi;
	return 0;
}

Measured memory_bytes: 355184
a11, a12, a13 = map(int,input().split())
a21, a22, a23 = map(int,input().split())
a31, a32, a33 = map(int,input().split())
N = int(input())
blist = [int(input()) for i in range(N)]

if a11 in blist and a21 in blist and a31 in blist:
    print('Yes')
    exit(0)

if a12 in blist and a22 in blist and a32 in blist:
    print('Yes')
    exit(0)

if a13 in blist and a23 in blist and a33 in blist:
    print('Yes')
    exit(0)

if a11 in blist and a12 in blist and a13 in blist:
    print('Yes')
    exit(0)

if a21 in blist and a22 in blist and a23 in blist:
    print('Yes')
    exit(0)

if a31 in blist and a32 in blist and a33 in blist:
    print('Yes')
    exit(0)

if a11 in blist and a22 in blist and a33 in blist:
    print('Yes')
    exit(0)

if a13 in blist and a22 in blist and a31 in blist:
    print('Yes')
    exit(0)

print('No')

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

// 普通にやると、桁落ち誤差とかで落ちるらしい、、、
ll a,b,c;

void solve1() {
    if(sqrt(a) + sqrt(b) < sqrt(c)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return ;
}

void solve2() {
    ll p = 4*a*b;
    ll q = (c-a-b)*(c-a-b);
    if(p < q && c - a - b >= 0) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return ;
}

int main()
{
    cin >> a >> b >> c;
    //solve1();
    solve2();
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Programming_Education
{
    class Program
    {
        static void Main(string[] args)
        {
            int age = int.Parse(Console.ReadLine());

            switch (age)
            {
                case 1:
                    Console.WriteLine("Hello World");
                    break;
                case 2:
                    var a = int.Parse(Console.ReadLine());
                    var b = int.Parse(Console.ReadLine());

                    Console.WriteLine(a + b);
                    break;
                default:
                    break;
            }
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w;
    cin>>h>>w;
    string s[100];
    for(int i=0;i<h;i++)cin>>s[i];
    int d[30];
    for(int i=0;i<30;i++)d[i]=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            d[s[i][j]-'a']++;
        }
    }
    int one=h*w%2;
    int two=(h/2)*(w%2)+(w/2)*(h%2);
    for(int i=0;i<26;i++){
        if((d[i]%4==1||d[i]%4==3)&&(one)){
            d[i]-=1;
            one--;
        }
    }
    for(int i=0;i<26;i++){
        if(d[i]%4==2&&two){
            d[i]-=2;
            two--;
        }
    }
    for(int i=0;i<26;i++){
        if(d[i]%4==0){
            d[i]=0;
        }
    }
    bool can=true;
    for(int i=0;i<26;i++){
        if(d[i]!=0)can=false;
    }
    if(can)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 384
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val h = sc.nextLong()
    val n = sc.nextInt()
    val a = (0 until n).map { sc.next().toInt() }
    println(problem153b(h, n, a))
}

fun problem153b(h: Long, n: Int, a: List<Int>): String {
    var h = h
    for (i in 0 until n) {
        h-= a[i]
    }
    return if (h > 0) "No" else "Yes"
}

Measured memory_bytes: 51668
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct Init {
  Init() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} Init;

const int MOD = 1e9 + 7;

class Combination {
private:
  const int MOD;
  vector<int> fac, finv, inv;

  int combination(int n, int k) {
    if (n < k)
      return 0;
    if (n < 0 || k < 0)
      return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
  }

  int permutation(int n, int k) {
    if (n < k)
      return 0;
    if (n < 0 || k < 0)
      return 0;
    return fac[n] * finv[n - k] % MOD;
  }

  int homogeneousProduct(int n, int k) { return combination(n + k - 1, k); }

public:
  Combination(int MAX_N, int MOD) : MOD(MOD) {
    fac.resize(MAX_N, 1);
    finv.resize(MAX_N, 1);
    inv.resize(MAX_N, 1);
    for (int i = 2; i < MAX_N; i++) {
      fac[i] = fac[i - 1] * i % MOD;
      inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
      finv[i] = finv[i - 1] * inv[i] % MOD;
    }
  }

  int nCk(int n, int k) { return combination(n, k); }
  int nPk(int n, int k) { return permutation(n, k); }
  int nHk(int n, int k) { return homogeneousProduct(n, k); }
};

signed main() {
  int X, Y;
  cin >> X >> Y;

  if ((X + Y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }

  int x = (X + Y) / 3;

  int r = X - x, u = Y - x;

  Combination comb(10000000, MOD);

  cout << comb.nCk(r + u, r) << endl;
  return 0;
}

Measured memory_bytes: 234624
#include <cstdio>
#include <cstring>

int n;
int w[26],b[26];
bool used[26];
int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		int all=0;
		for(int i=0;i<n;i++){
			scanf("%d %d",&w[i],&b[i]);
			all+=w[i];
		}
		int i;
		memset(used,false,sizeof(used));
		for(i=0;i<n;i++){
			int j;
			for(j=0;j<n;j++){
				if(!used[j] && all<=b[j]){
					all-=w[j];
					used[j]=true;
					break;
				}
			}
			if(j==n)break;
		}
		printf("%s\n",i==n?"Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 1012
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

enum Color{WHITE, BLACK, NONE};

int n, m, p;

inline bool in_field(int x, int y, int z){
    return 0<=x&&x<n && 0<=y&&y<n && 0<=z&&z<n;
}

bool win(vector<vector<vector<Color>>> field, int x, int y, int z){
    Color color = field[x][y][z];
    
    for(int dx=-1; dx<=1; dx++){
        for(int dy=-1; dy<=1; dy++){
            for(int dz=-1; dz<=1; dz++) if(0<dx|0<dy|0<dz){
                int nx, ny, nz;
                int s = 0, t = 0;
                while(nx=x+dx*s, ny=y+dy*s, nz=z+dz*s, in_field(nx, ny, nz) && field[nx][ny][nz]==color) s--;
                while(nx=x+dx*t, ny=y+dy*t, nz=z+dz*t, in_field(nx, ny, nz) && field[nx][ny][nz]==color) t++;
                
                if(m <= t - s - 1)
                    return true;
            }
        }
    }
    
    return false;
}

void solve(){
    vector<vector<vector<Color>>> field(n, vector<vector<Color>>(n, vector<Color>(n, NONE)));
    vector<vector<int>> top(n, vector<int>(n, 0));

    vector<P> commands(p);
    for(int i=0; i<p; i++){
        int x, y; cin >> x >> y;
        x--; y--;
        commands[i] = P(x, y);
    }
    
    for(int i=0; i<p; i++){
        int x, y;
        x = commands[i].X;
        y = commands[i].Y;
        
        Color color = (i%2 == 0? BLACK: WHITE);
        field[x][y][top[x][y]] = color;
        top[x][y]++;
        
        if(win(field, x, y, top[x][y]-1)){
            cout << (color == BLACK? "Black": "White") << " " << i+1 << endl;
            return;
        }
    }
    
    cout << "Draw" << endl;
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    
    while(cin>>n>>m>>p, n|m|p){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 1240
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		String[] ab = str.split(" ");
		int a = Integer.parseInt(ab[0]);
		int b = Integer.parseInt(ab[1]);
		if (a > b) {
			System.out.println(a - 1);
		}else {
			System.out.println(a);
		}
		
		scanner.close();

	}

}


Measured memory_bytes: 21716
import java.io.*;
import java.util.*;

class Main {
    static Scanner scanner = new Scanner();

    public static void main(String[]$) throws IOException {
        char[] s = scanner.next().toCharArray();
        int n = s.length;
        char[] t = scanner.next().toCharArray();
        int m = t.length;
        List<Integer>[] list = new ArrayList[26];
        for (int i = 0; i < 26; i++) {
            list[i] = new ArrayList<>();
        }
        for (int i = 0; i < n; i++) {
            list[s[i] - 'a'].add(i);
        }
        long loop = 0;
        long lastIndex = -1;
        for (int i = 0; i < m; i++) {
            List<Integer> indexList = list[t[i] - 'a'];
            if (indexList.size() == 0) {
                System.out.println(-1);
                return;
            }

            int ok = -1, ng = indexList.size();
            while (Math.abs(ok - ng) > 1) {
                int mid = (ok + ng) / 2;

                if (lastIndex >= indexList.get(mid)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            if (ng >= indexList.size()) {
                lastIndex = indexList.get(0);
                loop++;
            } else {
                lastIndex = indexList.get(ng);
            }
        }
        System.out.println(loop * n + lastIndex + 1);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() throws IOException {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 30100
#include <stdio.h>
#include <math.h>

int main(void)
{
  double x1, x2, y1, y2;
  scanf(" %lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  printf("%lf\n", sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)));
  return 0;
}



Measured memory_bytes: 2040