akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

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

  vector<string> s(n);
  rep(i, n) cin >> s[i];

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

  string ans = "";
  rep(i, n) ans += s[i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int q, h, s, d; //0.25 0.5 1 2
    cin >> q >> h >> s >> d;
    int n;
    cin >> n;
    int Min = q * 4;
    Min = min(Min, 2 * q + h);
    Min = min(Min, 2 * h);
    Min = min(Min, s);
    long long ans = (long long)(n / 2) * min(2 * Min, d) + (n % 2) * Min;
    cout << ans << endl;
}




Measured memory_bytes: 256
n,k = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l.sort()
a,b = [list(i) for i in zip(*l)]
p = 0
for i in range(n):
    p += b[i]
    if p >= k:
        print(a[i])
        break

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


int dp[100005];
int h[100005];

int n, k;

int f(int i)
{	
	int& x = dp[i];
	
  if(x != -1) return x;

  if(i <= 0) return 0;
  
  int ans = f(i-1)+abs(h[i]-h[i-1]);
  for(int j = 2; j <= k; ++j)
  {
    if(i-j >= 0)
      ans = min(ans, f(i-j)+abs(h[i]-h[i-j]));
  }

  return x = ans;
}

int main()
{
	cin >> n >> k;
	for(int i = 0; i <= n; ++i) { cin >> h[i]; dp[i] = -1; }

	cout << f(n-1) << endl;
}


Measured memory_bytes: 5760
/*huzaifa242 copyright*/
#include <bits/stdc++.h>
using namespace std;
#define PI 3.1415926535897932384626
#define mod 1000000007
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);  
    #endif
    int n,i,j,k;
    cin>>n>>k;
    int a[n],h[n];
    for(i=0;i<n;i++)
    {
    	cin>>h[i];
    	if(i==0)
    	a[i]=0;
    	else if(i<k)
    	a[i]=abs(h[i]-h[0]);
    	else
    	{
            a[i]=mod;
            for(j=1;j<=k;j++)
            a[i]=min(a[i],a[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout<<a[n-1]<<"\n";
    return 0;
}

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

using namespace std;
#define inf 1e16
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

struct person{
	int h,p;
	void read() {
		scanf("%d %d",&h,&p);
	}
};

bool cmp(person a, person b){
	return a.h + a.p < b.h + b.p;
}

const int maxn = 5e3 + 3;

ll dp[maxn]; //dp[i][j] menyatakan banyaknya minimal sum of p sampe idx i dengan banyaknya peserta yg ikut adalah j
ll temp[maxn];

void minim(ll &a, ll b){
	a = min(a, b);
}

int main(){
	int n,i,j;
	scanf("%d",&n);
	vector<person> a(n+1);
	for(i=1;i<=n;i++){
		a[i].read();
	}
	sort(a.begin(), a.end(), cmp);

	for(i=1;i<=n;i++){
		// printf("i: %d\n",i);
		if(i > 1){
			for(j=0;j<i;j++){
				dp[j] = temp[j];
				// printf("dp[%d]: %lld\n",j,dp[j]);
			}
			dp[j] = inf;
		}else{
			temp[0] = 0;
			for(j=1;j<=i;j++){
				dp[j] = inf;
				temp[j] = 0;
			}
		}
		
		int h = a[i].h, p = a[i].p;
		// printf("h: %d p: %d\n",h,p);
		for(j=1;j<=i;j++){
			if(h >= temp[j-1]){
				minim(dp[j], temp[j-1] + p);
				// printf("masuk sini dp[%d][%d]: %lld\n",i,j+1, dp[i][j+1]);
			}
		}

		for(j=0;j<=i;j++){
			temp[j] = dp[j];
			dp[j] = 0;
		}
	}
	int ans = 0;
	
	for(j=0;j<=n;j++){
		// printf("dp[%d]: %lld\n",j,dp[j]);
		if(temp[j] != inf){
			ans = max(ans, j);
		}
	}
	
	printf("%d\n",ans);
	return 0;
};

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int A[n+1],B[n+1],C[n+1];
    for(int i=1;i<=n;i++) cin >> A[i];
    for(int i=1;i<=n;i++) cin >> B[i];
    for(int i=1;i<n;i++) cin >> C[i];
    int ans=0;
    for(int i=1;i<=n;i++){
        ans += B[i];
        if(i<n){
            if(A[i+1] == A[i] + 1){
                ans += C[A[i]];
            }
        }
    } 
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int main()
{
	char s[110];
	gets(s);
	int flag=1;
	for(int i=0;i<strlen(s);i++)
	{
		for(int j=i+1;j<strlen(s);j++)
		{
			if(s[i]=='C' && s[j]=='F')
			{
				flag=0;
				break;	
			}
		    if(flag==0) break;
		}
		
	}
	if(flag==0)
	printf("Yes");
	else
	printf("No");
	return 0;
}

Measured memory_bytes: 256
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

long long lcm(long long a, long long b) {
	return a * b / gcd(a, b);
}

int main() {
	int N;
	cin >> N;
	cout << "ABC" << N << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;


int main(){
  int n; string s; cin >> n >> s;
  
  if(s.substr(0,n/2) == s.substr(n/2)){
    cout << "Yes" << endl;
  }else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

func nextInt() int {
	if !sc.Scan() {
		panic("failed scan int")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	s := nextString()
	w := nextInt()
	b := []byte(s)
	var buf []byte
	for i := 0; i < len(b); i += w {
		buf = append(buf, b[i])
	}
	fmt.Println(string(buf))
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<utility>
#include<sstream>
#include<cctype>
#include<cmath>
#include<algorithm>
using namespace std;

#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define rev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define repp(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define clr(a) memset((a), 0 ,sizeof(a))


typedef pair<int,int> P;
typedef vector<pair<int,int> > pii;
typedef map<string,int> mi;


int A[100];

int main(){
	int n,ans=0;
	cin >> n;
	n*=2;
	for(int i=0;i<n;i++) cin >> A[i];
	
	sort(A,A+n);
	for(int i=0;i<n;i+=2) ans+=A[i];
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	a = parseMap(split(chomp(readline()),""))
	n = length(a)
	m = 0
	for i in 1:n
		k = 0
		if a[i]!=0
			for j in 1:n
				if j<i
					k += a[j]
				elseif j==i
					k += a[j]-1
				else
					k += 9
				end
			end
		end
		m = max(m,k)
	end
	println(max(m,sum(a)))
end

main()

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

int main(){
  int n,c;
  int sum1=0,sum2=0;
  cin >> n;
  vector<vector<int>> aij(2,vector<int>(n));
  vector<int> sum(n+1);
  for(int i=0;i<n;i++){ cin >> aij.at(0).at(i); sum1+=aij.at(0).at(i);}
  for(int i=0;i<n;i++){ cin >> aij.at(1).at(i); sum2+=aij.at(1).at(i);}
  sum.at(n)=sum1+aij.at(1).at(n-1);
  sum.at(0)=sum2+aij.at(0).at(0);
  for(int i=1;i<n;i++) sum.at(i) = sum.at(i-1)+aij.at(0).at(i)-aij.at(1).at(i-1);
  int tmp = sum.at(0);
  for(int i=0;i<n+1;i++){
    if(tmp < sum.at(i)) tmp = sum.at(i);
  }
  cout << tmp << endl; 
}

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

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

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int N; cin >> N;
  if (N % 1000 == 0) cout << 0 << endl;
  else cout << 1000 - N % 1000 << endl;

  return 0;
}


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

bool comp(string a,string b){//a<bでture
  int cha,chb,p,q;
  p=a.size();
  q=b.size();
  if(p<=q){
    for(int i=0;i<p;i++){
      cha=(int)(unsigned char)a[i];
      chb=(int)(unsigned char)b[i];
      if(cha!=chb){
        if(cha<chb){
          return true;//<
        }else{
          return false;//>
        }
      }
    }
  }else{
    for(int i=0;i<q;i++){
      cha=(int)(unsigned char)a[i];
      chb=(int)(unsigned char)b[i];
      if(cha!=chb){
        if(cha<chb){
          return true;//<
        }else{
          return false;//>
        }
      }
    }
  }
  if(p<q){//長さ領域で全て一致の時ここでの判断が加わる
    return true;
  }else{
    return false;
  }
}


int main(){
  string s,t,r;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<int>());
  //cout << s << endl << t << endl;
  /*
  r=s+t;
  sort(r.begin(),r.end());
  cout << r << endl;
  r.resize(s.size());
  cout << r << endl;
  */
  if(comp(s,t)){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m), y(m);
  vector<vector<int>> y_sort(n + 1);

  rep(i, m) {
    cin >> p[i] >> y[i];
    y_sort[p[i]].push_back(y[i]);
  }

  rep(i, n) { sort(y_sort[i + 1].begin(), y_sort[i + 1].end()); }

  for (int i = 0; i < m; i++) {
    printf("%012lld\n", ll(p[i]) * 1000000 +
                            int(lower_bound(all(y_sort[p[i]]), y[i]) -
                                y_sort[p[i]].begin()) +
                            1);
  }

  return 0;
}

Measured memory_bytes: 7808
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class CClosedRooms {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int h,w,k;
        in>>h>>w>>k;
        vector<vector<char>> a(h,vector<char>(w));
        vector<vector<bool>> v(h,vector<bool>(w));
        using P=pair<int,int>;
        queue<pair<int,P>> q;
        fr(i,h) fr(j,w){
            in>>a[i][j];
            if(a[i][j]=='S') q.emplace(0,P(i,j)),v[i][j]=true;
        }
        while(!q.empty()){
            auto ip=q.front();q.pop();
            int d=ip.first,i=ip.second.first,j=ip.second.second;
            if(i==0||i==h-1||j==0||j==w-1){
                out<<1<<endl;
                return;
            }
            if(d==k) continue;
            if(!v[i-1][j]&&a[i-1][j]=='.') v[i-1][j]=true,q.emplace(d+1,P(i-1,j));
            if(!v[i+1][j]&&a[i+1][j]=='.') v[i+1][j]=true,q.emplace(d+1,P(i+1,j));
            if(!v[i][j-1]&&a[i][j-1]=='.') v[i][j-1]=true,q.emplace(d+1,P(i,j-1));
            if(!v[i][j+1]&&a[i][j+1]=='.') v[i][j+1]=true,q.emplace(d+1,P(i,j+1));
        }
        int ans=INT_MAX;
        fr(i,h) fr(j,w) if(v[i][j]) ans=min(ans,2+(min({i,j,h-1-i,w-1-j})-1)/k);
        out<<ans<<endl;
    }
};

int main() {
    CClosedRooms solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0);
using namespace std;

const long long INF = 1e7;
const long long N = 1e6 + 7;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;

ll T = 1, n, m, b, ans, y, x, c, a, cnt, mn = 1e18;
string s;
vector < ll > v, v1;
set< char > st;
int main(){
    TIME
    cin >> n;
    cout << ( n + 1 ) / 2;
}


Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Map<String, Integer> map = new TreeMap<>();
        int max = 0;
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            map.merge(s, 1, Integer::sum);
            max = Math.max(max, map.get(s));
        }
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, Integer> e : map.entrySet()) {
            if (e.getValue().equals(max)) {
                sb.append(e.getKey());
                sb.append("\n");
            }
        }
        System.out.println(sb.toString());
    }
}

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

int main(void){
  char s[200001];

  int i,j,n;

  scanf("%s",s);

  n = strlen(s);

  for(i=0;i<n;i++)
    if(s[i]=='A') break;

  for(j=n-1;j>i;j--)
    if(s[j]=='Z') break;

  printf("%d\n",j-i+1);

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <cmath>

#define PI 3.14159265359

using namespace std;
using ll = long long;
using pint = pair<int, int>;

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

	double ans = 2 * PI * R;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3756
import math
a, b, h, m = map(int, input().split())

an_a = 2/12*h + (1/6)*(m/60)
an_b = 2/60*m

angle = an_a - an_b
if angle > 1:
    angle = 2 - angle

c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(angle*math.pi))
print(c)


Measured memory_bytes: 9564
////////////////////////////////////
///     Please Give Me AC!!!     ///
////////////////////////////////////

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

const int MOD = 1000000007;

ll powmod(ll a, ll b){
    ll res = 1;
    rep(i, b) {
        res = res * a % MOD;
    }
    return res;
}

int main(){
    ll N; cin>> N;

    ll ans = powmod(10, N) - 2 * powmod(9, N) + powmod(8, N);
    ans %= MOD;
    cout<< (ans + MOD) % MOD << endl;
}


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

using ll=long long;
using P=pair<int, int>;
const ll INF=1LL<<60;
const ll MOD=1e9+7;

int main(){
    int N, K; cin >> N >> K;
    vector<int> a(N);
    for(auto &x: a) cin >> x;
    ll res=INF;
    for(int bits=0; bits<(1<<N); bits++){
        vector<int> b=a;
        int prev_i=0, cnt=0;
        bool ok=true;
        ll sum=0;
        if((~bits)>>0 & 1) continue;
        for(int i=0; i<N; i++){
            if((bits>>i) & 1){
                cnt++;
                if(i == 0) continue;
                for(int j=prev_i+1; j<i; j++){
                    if(b[prev_i] < b[j]) ok=false;
                }
                sum+=max(0, b[prev_i]-b[i]+1);
                b[i]=max(b[i], b[prev_i]+1);
                prev_i=i;
            }
        }
        if(cnt >= K && ok){
            res=min(res, sum);
        }
    }
    cout << res << endl;
    return 0;
}

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

signed main(){
  lint X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
  vector<lint> red(A), blue(B), no(C);
  for(lint i = 0; i < A; i++) cin >> red[i];
  for(lint i = 0; i < B; i++) cin >> blue[i];
  for(lint i = 0; i < C; i++) cin >> no[i];
  sort(red.begin(), red.end()); reverse(red.begin(), red.end());
  sort(blue.begin(), blue.end()); reverse(blue.begin(), blue.end());
  for(lint i = 0; i < X; i++) no.push_back(red[i]);
  for(lint i = 0; i < Y; i++) no.push_back(blue[i]);
  sort(no.begin(), no.end()); reverse(no.begin(), no.end());
  lint ans = 0;
  for(lint i = 0; i < X + Y; i++) ans += no[i];
  cout << ans << endl;
}

Measured memory_bytes: 5872
#include <stdio.h>

int main(void) {
	long long N;
	long long h, n;

	scanf("%lld", &N);

	for (h = 1; h <= 3500; h++)
		for (n = 1; n <= 3500; n++) {
			const long long a = N * h * n, b = 4 * h * n - N * n - N * h;
			if (b != 0 && a % b == 0 && a / b > 0) {
				printf("%lld %lld %lld\n", h, n, a / b);
				return 0;
			}
		}

	return 0;
}


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

ll kzyou(ll n,int k){
   if(k ==0){
     return 1;
   }
     ll a = n;
    for(int i = 0;i<k-1;i++){
      a *= n;
    }
    return a;
}

int main() {
  ll N;
  cin >> N;
  int k = 0;//5^k <= Nを満たす最大のk
  ll a = 5;

  while(a <= N){
    a *= 5;
    k++;
  }
  //cout << k << endl;
  //cout << N/(kzyou(5,2)*2) <<endl;
  if(N%2 == 1) cout << 0 << endl;
  else{
      ll ans = 0;
      for(int i = 1;i<=k;i++){
          ans += N/(kzyou(5,i)*2);
      }
      cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int in[10][10];
#define it vector<int>::iterator
bool next_combination(it first1,it last1,it first2,it last2){
	if((first1==last1)||(first2==last2))return false;
	it m1=last1,m2=last2;
	m2--;
	while(--m1!=first1&&!(*m1<*m2));
	bool result=(m1==first1)&&!(*first1<*m2);
	if(!result){
		while(first2!=m2&&!(*m1<*first2))first2++;
		first1=m1;
		iter_swap(first1,first2);
		first1++;first2++;
	}
	if((first1!=last1)&&(first2!=last2)){
		m1=last1;m2=first2;
		while((m1!=first1)&&(m2!=last2))iter_swap(--m1,m2++);
		reverse(first1,m1);
		reverse(first1,last1);
		reverse(m2,last2);
		reverse(first2,last2);
	}
	return !result;
}
bool next_combination(it first,it middle,it last){
  return next_combination (first , middle , middle , last );
}
/*
n=5,r=3;
a=0 1 1 2 3
011 012 013 023 112 113 123
*/
//combination (begin,begin+r,end)
#define int ll
ll sto_l(string s){
	ll t=0;
	rep(i,s.size()){
		t*=10;
		t+=s[i]-'0';
	}
	return t;
}
signed main(){
	string s;
	cin>>s;
	ll n=s.size();
	ll q=sto_l(s);
	vi a(10);
	rep(i,10)a[i]=i;
	ll out=-1,ans=-1;
	do{
		do{
			ll t=0;
			rep(i,n){
				t*=10;
				t+=a[i];
			}
			ll sa=min(abs(q-t),ll(pow(10,n))-abs(q-t));
			if(out<sa){
				out=sa;
				ans=t;
			}else if(out==sa)ans=min(ans,t);
		}while(next_permutation(a.begin(),a.begin()+n));
	}while(next_combination(a.begin(),a.begin()+n,a.end()));
	string b=to_string(ans);
	while(b.size()!=n)b="0"+b;
	cout<<b<<endl;
}

Measured memory_bytes: 3444
import java.lang.reflect.Array;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int E = sc.nextInt();

		List<Integer> timeList = Arrays.asList(A, B, C, D, E);

		int aGap = Math.abs(10-A%10) == 10 ? 0 : Math.abs(10-A%10);
		int bGap = Math.abs(10-B%10) == 10 ? 0 : Math.abs(10-B%10);
		int cGap = Math.abs(10-C%10) == 10 ? 0 : Math.abs(10-C%10);
		int dGap = Math.abs(10-D%10) == 10 ? 0 : Math.abs(10-D%10);
		int eGap = Math.abs(10-E%10) == 10 ? 0 : Math.abs(10-E%10);

		List<Integer> gapList = new ArrayList<>();
		gapList.add(aGap);
		gapList.add(bGap);
		gapList.add(cGap);
		gapList.add(dGap);
		gapList.add(eGap);

		Integer maxGap = gapList.stream()
                .max((a, b) -> a.compareTo(b)).get();

		int maxIndx = gapList.indexOf(maxGap);

		List<Integer> waitList = new ArrayList<>();
		waitList.add(A + aGap);
		waitList.add(B + bGap);
		waitList.add(C + cGap);
		waitList.add(D + dGap);
		waitList.add(E + eGap);

		waitList.remove(maxIndx);

		int sum = 0;

		for(int t : waitList){
			sum += t;
		}

		System.out.println(sum+timeList.get(maxIndx));

	}

}


Measured memory_bytes: 29516
fn solve() {
    let n: usize = read();
    let mut a = vec![];
    let mut m: usize = 0;
    for i in 0..n {
        let v = read();
        a.push(v);
        m = max(m, v);
    }
    // a_i ^ a_i+1 (0 <= i < n)
    // let mut xors = vec![];
    // for i in 1..n {
    //     xors.push(a[i - 1] ^ a[i]);
    // }
    // println!("{:?}", xors);
    // max bit length
    let mut l = 0;
    while m > 0 {
        m >>= 1;
        l += 1;
    }

    let mut ans = vec![0; n];
    for b in 0..l {
        let mut parity = 0;
        for i in 0..n {
            parity ^= a[i] >> b & 1;
        }
        if parity == 1 {
            for i in 0..n {
                ans[i] |= !a[i] & (1 << b);
            }
        } else {
            for i in 0..n {
                ans[i] |= a[i] & (1 << b);
            }
        }
    }
    for i in 0..n {
        println!("{}", ans[i]);
        // let mut check = 0;
        // for j in 0..n {
        //     if j == i {
        //         continue;
        //     }
        //     // println!("xor{}", ans[j]);
        //     check ^= ans[j];
        // }
        // println!("{}", check);
    }
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::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")
}

// =========


Measured memory_bytes: 5756
/*
    Auther: ghoshashis545 Ashis Ghosh
    College: Jalpaiguri Govt Enggineering College
*/
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
using namespace std;
#define ll int
#define int long long
#define ld long double
#define ff first
#define ss string 
#define se second
#define endl "\n"
#define alt(v) v.begin(),v.end()
#define ralt(v) v.rbegin(),v.rend()
#define pb emplace_back
#define mp make_pair
#define fab(i,a,b) for(int i=(a);i<(b);i++)
#define fba(i,a,b) for(int i=(b);i>=(a);i--)
int mod=1000000007;
// int mod=998244353;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};

bool test  = 0;
const int N = 1e3+5;
const int inf = 1e18;
int n,m,x1,x2,d1,d2;
void solve()
{
	
    cin>>n>>m;
    cin >>x1>>x2;
    cin >>d1 >>d2;

    x1--,x2--,d1--,d2--;

	vector<string>maze(n);
    for(int i = 0; i<n;++i)
        cin >>maze[i];

    int dis[n][m];
    for(int i=0;i<n;++i)
        for(int j =0;j<m;++j)
            dis[i][j]=inf;

    priority_queue< pair<int, pair<int, int> >, vector< pair<int, pair<int, int> > >, greater< pair<int, pair<int, int> > > > q;
    q.push({0,{x1,x2}});
    dis[x1][x2] = 0;
    while(!q.empty())
    {
        int x = q.top().se.ff;
        int y = q.top().se.se;
        q.pop();
        for(int i = -2;i <= 2;++i)
            for(int j = -2;j<=2;++j)
            {
                int p1 = x+i;
                int p2 = y+j;
                if(p1<0 or p2<0 or p1>=n or p2>=m or maze[p1][p2]=='#')
                    continue;
                int f = (abs(i)+abs(j)>1);
                if(dis[p1][p2] > dis[x][y]+f)
                {
                    dis[p1][p2] = dis[x][y]+f;
                    q.push({dis[p1][p2],{p1,p2}});
                }
            }
    }

    if(dis[d1][d2] == inf)
        dis[d1][d2] = -1;

    cout<<dis[d1][d2];

}




    

















signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    if(test)
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 12688
module Main where

import           Control.Monad
import           Data.List

readInt :: String -> Int
readInt = read

main :: IO()
main = do
  [a, b, c] <- map readInt . words <$> getLine
  print $ solve a b c

solve :: Int -> Int -> Int -> Int
solve a b c =  (\nums -> head nums * 10 + foldl1' (+) (tail nums)) (sortBy (flip compare) [a, b, c])


Measured memory_bytes: 508
#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;

int main(void) {

	int n, a[200], b[200], k;

	cin >> n;

	for (k = 0; k < n; k++)cin >> a[k];

	for (k = 0; k < n; k++) {
		b[k] = 0;
		while (a[k] % 2 == 0) {
			a[k] = a[k] / 2;
			b[k]++;
		}
	}

	sort(b, b + n);

	cout << b[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i = 0;i < n;i++)
#define PRN(n) printf("%d\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(s) printf("%c",s)
int main(void){
  int n;
  scanf("%d",&n);
  int i=1;
  while(n>=i){
    i*=2;
  }
  PRN(i/2);
  return 0;
}
/*
scanf("%d",&n);
scanf("%d %d",&a,&b);
*/

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

int main(){
  string s;
  cin >> s;
  if(s== "Sunny") cout << "Cloudy" << endl;
  else if(s== "Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s)
{
	return '"' + s + '"';
}

string to_string(const char *s)
{
	return to_string((string)s);
}

string to_string(bool b)
{
	return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++)
	{
		if (!first)
		{
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
	string res = "";
	for (size_t i = 0; i < N; i++)
	{
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v)
{
	bool first = true;
	string res = "{";
	for (const auto &x : v)
	{
		if (!first)
		{
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
	int X;
	cin >> X;
	int ans = 0, d = 0;

	for (int i = 0; i <= 700; i++)
	{
		d += X;
		if (d % 360 == 0)
		{
			cout << i + 1 << "\n";
			return 0;
		}
	}
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int height = Integer.parseInt(sc.next());
        int width = Integer.parseInt(sc.next());

        StringBuilder sb = new StringBuilder();
        sb.append(height * width);
        sb.append(" ");
        sb.append(height * 2 + width * 2);
        System.out.println(sb.toString());
    }
}



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

int main () {
  int N,K;
  cin >> N >> K;
  vector<int>D(K);
  for (int i = 0; i < K; i++) {
    cin >> D.at(i);
  }
  
  for (int i = N; i < 10; i++) {
    int M = i;
    for (int j = 0; j < K; j++) {
      if (M % 10 == D.at(j)){
        break;
      }
      else if (j == K-1){
        M /= 10;
        if (M == 0){
          cout << i << endl;
          return 0;
        }
      }
    }
  }
  for (int i = N; i < 100; i++) {
    int M = i;
    for (int k = 0; k < 2; k++) {
    for (int j = 0; j < K; j++) {
      if (M % 10 == D.at(j)){
        break;
      }
      else if (j == K-1){
        M /= 10;
        if (M == 0){
          cout << i << endl;
          return 0;
        }
      }
    }
    }
  }
  for (int i = N; i < 1000; i++) {
    int M = i;
    for (int k = 0; k < 3; k++) {
    for (int j = 0; j < K; j++) {
      if (M % 10 == D.at(j)){
        break;
      }
      else if (j == K-1){
        M /= 10;
        if (M == 0){
          cout << i << endl;
          return 0;
        }
      }
    }
    }
  }
  for (int i = N; i < 10000; i++) {
    int M = i;
    for (int k = 0; k < 4; k++) {
    for (int j = 0; j < K; j++) {
      if (M % 10 == D.at(j)){
        break;
      }
      else if (j == K-1){
        M /= 10;
        if (M == 0){
          cout << i << endl;
          return 0;
        }
      }
    }
    }
  }
  for (int i = N; i < 100000; i++) {
    int M = i;
    for (int k = 0; k < 5; k++) {
    for (int j = 0; j < K; j++) {
      if (M % 10 == D.at(j)){
        break;
      }
      else if (j == K-1){
        M /= 10;
        if (M == 0){
          cout << i << endl;
          return 0;
        }
      }
    }
    }
  }
  cout << 100000 << endl;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main(void){
    int a[3];
    for(int i = 0;i < 3; i++){
        cin >> a[i];
    }
    if(a[0] == a[1] + a[2] || a[1] == a[0] + a[2] || a[2] == a[0] + a[1])
        cout <<"Yes" << endl;
    else    cout <<"No" << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define INF 2147483647
using namespace std;
using Graph=vector<vector<int>>;

ll RepSq(ll a,ll n,ll mod){
  if(n==0){
    return 1;
  }else if(n%2!=0){
    return (a*RepSq(a,n-1,mod))%mod;
  }else{
    ll x=RepSq(a,n/2,mod);
    return (x*x)%mod;
  }
}

int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  ll mod=1000000007;
  ll comb[400000],inv[400000];
  comb[0]=1; inv[1]=1; comb[1]=n%mod;
  for(int i=2;i<300000+1;i++){
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    comb[i]=(comb[i-1]*(n+1-i))%mod;
    comb[i]=(comb[i]*inv[i])%mod;
  }
  cout<<(3*mod+RepSq(2,n,mod)-1-comb[a]-comb[b])%mod;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;

int main(int argc, char *argv[])
{
    int A, B;
    std::cin >> A >> B;

    int ans = 0;
    if (A + B >= 24) {
        ans = A + B - 24;
    } else {
        ans = A + B;
    }

    std::cout << ans << std::endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(int argc, char const *argv[]) {
  int n;
  cin>>n;
  cout<<n*n*n;
  return 0;
}


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

using namespace std;
#define int long long
int MOD = 1000000007;

signed main(){
    string S;
    cin >> S;
    
    int A[4];
    A[0] = stoi(S)/1000;
    A[1] = stoi(S)/100%10;
    A[2] = stoi(S)/10%10;
    A[3] = stoi(S)%10;
    
    for(int bit=0;bit<(1<<3);bit++){
        int tmp = A[0];
        for(int i=0;i<3;i++){
            if(bit&(1<<i))tmp += A[i+1];
            else tmp -= A[i+1];
        }
        if(tmp == 7){
            cout << A[0];
            for(int i=0;i<3;i++){
                if(bit&(1<<i)) cout << "+";
                else cout << "-";
                cout << A[i+1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
}


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

using namespace std;

int N;
string S[100005];

int C[5];

int main(void) {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> S[i];
		if (S[i] == "AC") { C[0]++; }
		else if (S[i] == "WA") { C[1]++; }
		else if (S[i] == "TLE") { C[2]++; }
		else { C[3]++; }
	}


	cout << "AC x " << C[0] << endl;
	cout << "WA x " << C[1] << endl;
	cout << "TLE x " << C[2] << endl;
	cout << "RE x " << C[3] << endl;

	return 0;
}

Measured memory_bytes: 6772
#include<iostream>
#include<algorithm>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define NMAX 100000
#define INF 1e+6
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
typedef map<char,int> mci;
int n;
char s[101];
mci r,l;
int main(){
  scan(n);
  rep(i,n)scan(s[i]);
  rep(i,n)r[s[i]]++;
  int res=0,num=0;
  rep(i,n){
    char c=s[i];
    if(l[c]==0&&r[c]>1) num++;
    if(l[c]>0&&r[c]==1) num--;
    res=max(res,num);
    l[c]++;r[c]--;
  }
  prin(res);
  
  return 0;
}


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

    public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
      
      //入力
      long X = sc.nextLong();//目標額
      long money = 100;
      long year =0; 
      
      //預金額が目標額以上になるまで
      while(money<X){
       money *= 1.01;
       year =year+1;
      }
      System.out.println(year);
    }
}

Measured memory_bytes: 35788
#include<bits/stdc++.h>
#define NMAX 15005
#define VMAX 200000
#define inf 2000000005

using namespace std;
ifstream f("date.in");
ofstream g("date.out");
long long int n,sum=0;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
    if(i%3!=0&&i%5!=0)
    {
        sum=sum+1LL*i;
    }
}
cout<<sum;


}


Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;

ll mpow(ll a, ll b) {
	ll res = 1;
	a %= mod;
	while (b) {
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}
vector<int> fac, finv;
void factor(int N) {
	fac.resize(N); finv.resize(N);
	fac[0] = finv[0] = 1;
	rep(i, 1, N)fac[i] = 1LL * fac[i - 1] * i % mod;
	finv[N - 1] = mpow(fac[N - 1], mod - 2);
	for (int i = N - 2; i; --i) finv[i] = 1LL * finv[i + 1] * (i + 1) % mod;
}
int nCr(int n, int m) {
	if (m < 0 || n < m) return 0;
	return 1LL * (1LL * fac[n] * finv[m] % mod) * finv[n - m] % mod;
}


int main() {
	int n, m, k; cin >> n >> m >> k;
	factor(200010);
	int ans = 0;
	rep(i, 1, 2 * n) ans = (ans + (1LL *m*m)%mod* min(i, 2 * n - i) * abs(n - i)) % mod;
	rep(i, 1, 2 * m) ans = (ans + (1LL *n*n)%mod* min(i, 2 * m - i) * abs(m - i)) % mod;
	ans = (1LL * ans * mpow(2, mod - 2))%mod;
	ans = (1LL*ans*nCr(n * m-2, k - 2))%mod;
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
    int A[5] = {0};
    int i = 0;

    scanf("%d %d %d %d %d",
          &A[0], &A[1], &A[2], &A[3], &A[4]);
    for (i = 0; i < 5; i++)
    {
        if (A[i] == 0)
        {
            printf("%d", i + 1);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1676
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
typedef pair<ll, ll> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, long long K, vector<long long> X, vector<long long> Y) {
  std::vector<ll> x, y;
  REP(i, N) { x.push_back(X[i]), y.push_back(Y[i]); }

  ll ans = LLONG_MAX;
  REP(x_min, N) REP(x_max, N) REP(y_min, N) REP(y_max, N) {
    if (x[x_min] > x[x_max] || y[y_min] > y[y_max])
      continue;

    int c = 0;
    REP(i, N) {
      if (x[i] >= x[x_min] && x[i] <= x[x_max] && y[y_min] <= y[i] &&
          y[y_max] >= y[i])
        c++;
    }

    if (c < K)
      continue;

    ll buf = (x[x_max] - x[x_min]) * (y[y_max] - y[y_min]);
    // dump(ans, buf);
    ans = min(ans, buf);
  }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  long long K;
  cin >> N;
  vector<long long> x(N - 1 + 1);
  vector<long long> y(N - 1 + 1);
  cin >> K;
  for (int i = 0; i <= N - 1; i++) {
    cin >> x[i];
    cin >> y[i];
  }
  solve(N, K, x, y);
  return 0;
}


Measured memory_bytes: 256
N = int(raw_input())
CSF = []
ans = []
for i in range(0,N-1):
  CSF.append(list(map(int,raw_input().split())))


for i in range(0,N):
  time = 0
  for j in range(i,N-1):
    if time < CSF[j][1]:
      time = CSF[j][1]
    elif time % CSF[j][2] == 0:
      time = time
    else:
      time = time + CSF[j][2] - (time % CSF[j][2])
    time = time + CSF[j][0]
  ans.append(time)

for i in ans:
  print i

Measured memory_bytes: 2692
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main(int argc, char *argv[]) {
  string s;
  int cnt=0,i,del_num,b=0,r=0;
  cin>>s;
  for(i=0;i<s.size();i++){
    if(s[i]=='0')
      b++;
    else
      r++;
  }
  cout<<2*min(b,r)<<endl;
}


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

double x[100], y[100], z[100], r[100], d[100][100];
bool used[100];
double distance(double x1, double y1, double z1, double r1, double x2, double y2, double z2, double r2) {
	return max(0., sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2) + pow(z1 - z2, 2)) - r1 - r2);
}
int main() {
	int n;
	while (scanf("%d", &n), n) {
		rep(i, n)scanf("%lf%lf%lf%lf", &x[i], &y[i], &z[i], &r[i]);
		rep(i, n)for (int j = i + 1; j < n; j++)d[i][j] = d[j][i] = distance(x[i], y[i], z[i], r[i], x[j], y[j], z[j], r[j]);
		double sum = 0;
		memset(used, 0, sizeof(used));
		priority_queue<P, vector<P>, greater<P>>que; que.push(P(0, 0));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			if (used[p.second])continue;
			used[p.second] = true;
			sum += p.first;
			rep(i, n)que.push(P(d[p.second][i], i));
		}
		printf("%.3lf\n", sum);
	}
}

Measured memory_bytes: 3400
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;


int main()
{
	int A, B;
	cin >> A >> B;
	if (A < 10 && B < 10) cout << A * B << endl;
	else cout << -1 << endl;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> vec){ return (ll)vec.size(); }
ll sz(string s){ return (ll)s.size(); }

ll gcd(ll a,ll b){
    if(!b) return a;
    return gcd(b,a%b);
}



int main(){

    ll n;
    cin >> n;
    ll a[n] = {};
    ll memo;
    ll amax = 0;
    map<ll,ll> m;
    rep(i,0,n){
        cin >> a[i];
        if(i == 0) memo = a[i];
        else memo = gcd(memo,a[i]);
        
        if(m.count(a[i]) == 0) m[a[i]] = 1;
        else m[a[i]]++;
    }

    if(memo != 1){
        cout << "not coprime" << endl;
        return 0;
    }

    bool is_not_prime[1000001] = {};
    for(ll i = 2; i <= 1000000; i++){
        ll cnt = 0;
        if(is_not_prime[i]) continue;
        for(ll j = 1; i*j <= 1000000; j++){
            is_not_prime[i*j] = true;
            if(m.count(i*j) != 0) cnt += m[i*j];
        }
        if(cnt > 1){
            cout << "setwise coprime" << endl;
            return 0;
        }
    }

    rep(i,0,n){
        if(m[a[i]] > 1 && a[i] != 1){
            cout << "setwise coprime" << endl;
            return 0;
        }
    }
    cout << "pairwise coprime" << endl;
    
    return 0;
}




Measured memory_bytes: 74664
S = input()
S = S[:-1]
if len(S)%2==1:
  S = S[:-1]
l = len(S)
while(True):
  if S[:l//2] == S[l//2:]:
    break
  S = S[:-1]
  S = S[:-1]
  l -= 2
print(l)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String s1 = s.next();
        String s2= s.next();
        String s3= s2.substring(0,s1.length());
        if(s1.length()+1==s2.length() && s3.equals(s1))
            System.out.println("Yes");
        else
            System.out.println("No");

    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 26984