akhauriyash/Code-Regression huggingface dataset:
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define ld          long double
#define pb          push_back
#define endl        '\n'
#define pii         pair<long long int,long long int>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
ll binpow(ll a,ll b,ll mod)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
 //  cin>>t;
    for(int ok=1;ok<=t;ok++)
    {
        ll n;
        cin>>n;
        ll op=0;
        ll oq=0;
        for(int i=0;i<n;i++)
        {
        	ll x;
        	cin>>x;
        	op=(op+(x*x)%hell)%hell;
        	oq=(oq+x)%hell;
        }
        oq=(oq*oq)%hell;
        oq=(oq-op+hell)%hell;
        ll o=binpow(2,hell-2,hell);
        cout<<(oq*o)%hell<<endl;

     
    }
    return 0;
}

Measured memory_bytes: 3568
#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, m, s[100009], x[100009];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i < n; i++) scanf("%d", &s[i]), s[i] += s[i - 1];
	long long ret = 0;
	for (int i = 1; i <= m; i++) {
		scanf("%d", &x[i]), x[i] += x[i - 1];
		if (x[i] < x[i - 1]) ret += s[x[i - 1]] - s[x[i]];
		else ret += s[x[i]] - s[x[i - 1]];
	}
	printf("%d\n", ret % 100000);
	return 0;
}

Measured memory_bytes: 3444
def main():
    N, K, Q = map(int, input().split(" "))
    points = [K - Q] * N
    for i in range(Q):
        points[int(input()) - 1] += 1
    for j in points:
        if j > 0:
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 6580
N=parse(Int,readline())
M=Dict{Int,Int}()
for a=map(x->parse(Int,x),split(readline()))
	M[a]=get(M,a,0)+1
end
if N%3!=0
	println(get(M,0,0)==N?"Yes":"No")
else
	T=div(N,3)
	cum=0
	flag=true
	for (k,v)=M
		if v%T!=0
			flag=false
		else
			while v>=T
				v-=T
				cum$=k
			end
		end
	end
	if cum!=0
		flag=false
	end
	println(flag?"Yes":"No")
end


Measured memory_bytes: 170696
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <type_traits>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n; cin >> n;
    vector<int> a(n);
    int x = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        x = max(x, a[i]);
    }

    int y = INF;
    for(int i = 0; i < n; i++) {
        if(a[i] == x) continue;
        if(abs(a[i] - x / 2.0) < abs(y - x / 2.0)) y = a[i];
    }

    cout << x << " " << y << endl;
    return 0;
}


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

int main() {
    int N,A;
    cin >> N;

    rep(i,N) {
        cin >> A;
        if(A%2==0 && A%3 && A%5) {
            cout << "DENIED" << endl;
            return 0;
        }
    }

    cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

vector< ll > z_algorithm(const string &s) {
  vector< ll > prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0ll, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int) s.size();
  return prefix;
}

int main(){
    ll n; cin >> n;
    string s; cin >> s;
    ll ans = 0;
    rep(i,n-1){
        vl z = z_algorithm(s.substr(i));
        REP(j,i,n){
            chmax(ans,min(j-i,z[j-i]));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    string s; cin>>s;
    int ans = 0;
    int n = 15 - s.size();
    for(int i=0; i<s.size(); i++){
        ans += (s[i] == 'o');
    }

    if(8 <= ans + n) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val k = sc.nextInt()
  val ds = Array.fill(k)(sc.next().head).toSet
  var ans = 0
  var i = n
  while (ans == 0) {
    if ((i.toString.toList.toSet & ds).size == 0) {
      ans = i
    }
    i += 1
  }
  println(ans)
}


Measured memory_bytes: 58688
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    int w, a, b;
    cin >> w >> a >> b;
    if(a > b){
        swap(a, b);
    }
    cout << max(0, b-a-w) << endl;
    return 0;
}

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

#define ran 101101

int n, k;
int a[ran];
int dp[ran];

int main() {
	scanf("%d%d", &n, &k);
	for(int i=1;i<=n;i++) scanf("%d", &a[i]);
	dp[1] = 0;
	for(int i=2;i<=n;i++) {
		dp[i] = dp[i-1] + labs(a[i]-a[i-1]);
		for(int j=2;j<=k && i-j>0; j++) {
			dp[i] = min(dp[i], int(dp[i-j] + labs(a[i]-a[i-j])));
		}
	}
	printf("%d\n", dp[n]);
	
	return 0;
}

Measured memory_bytes: 1024
b1,b2,b3=map(int,input().split())
if b1==1 and b2==0 and b3==0:
    print("Close")
elif b1==0 and b2==1 and b3==0:
    print("Close")
elif b1==1 and b2==1 and b3==0:
    print("Open")
elif b1==0 and b2==0 and b3==1:
    print("Open")
elif b1==0 and b2==0 and b3==0:
    print("Close")


Measured memory_bytes: 5596
a, b, k = map(int,input().split())

if abs(a-b)+1 <= 2*k:
  for i in range(a,b+1):
    print(i)

else:
  nList = []
  for i in range(k):
    nList.append(a+i)
    nList.append(b-i)

  for i in sorted(nList):
    print(i)


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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i, 0, n) cin >> v[i];
    sort(all(v));
    double sum = v[0];
    if(n == 1) {
        cout << v[0] << endl;
        return 0;
    }
    rep(i, 1, n){
        sum = (sum + v[i]) / 2.0;
    }
    cout << sum << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<cstdlib>
#include<algorithm>
#include<numeric>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef long long ll;
const int N = 1000;
int adj[N][N];
int r[N];

int bestpoint(int n,int *esa,int l,int y,int x,ll tdist){
  int r=n-1;
  int ret=-1;
  if (esa[r] < x)return r;
  while(l <= r){
    int mid=(l+r)/2;
    ll mdist=esa[mid]-x;
    assert(mdist >= 0);
    if (mdist < tdist){
      ret=mid;
      l=mid+1;
    }else {
      r=mid-1;
    }
  }
  return ret;
}

void setdata(int n,int *esa,int m,int *y,int *x,int *num){
  rep(i,n){
    REP(j,i+1,n)adj[i][j]=0;
    rep(j,m){
      if (esa[i] < x[j]){
	ll tdist=llabs(esa[i]-x[j]);
	int ind=bestpoint(n,esa,r[j],y[j],x[j],tdist);
	//cout <<"check " << i <<" " << j <<" : " << esa[i] <<" " << x[j] << " " << ind << endl;
	if (ind == -1)ind=r[j]-1;
	if (ind >= 0)adj[i][ind]+=num[j];
      }
    }
    for(int j=n-2;j>i;j--){
      adj[i][j]+=adj[i][j+1];
    }

    /*
    for(int k=m-1;k>=0;k--){
      ll tmp=llabs(esa[i]-x[k]);
      REP(j,i+1,n){
	if (tmp > llabs(esa[j]-x[k]))adj[i][j]+=num[k];
      }
    }
    */
  }
}

int dp[N];
bool isok(int n,int lim,int total){
  rep(i,n){
    dp[i]=total;
    rep(j,i){
      if (dp[j]-adj[j][i] > lim)continue;
      dp[i]=min(dp[i],adj[j][i]);
    }
  }
  rep(i,n)if (dp[i] <= lim)return true;
  return false;
}

int solve(int n,int total){
  int l=0,r=total;
  int ret=total;
  while(l <= r){
    int mid=(l+r)/2;
    if (isok(n,mid,total))ret=mid,r=mid-1;
    else l=mid+1;
  }
  return ret;
}

main(){
  int n,m;
  static int x[N],y[N],num[N],esa[N];
  while(cin>>m>>n){
    if (m == 0 && n == 0)break;
    int total=0;
    rep(i,m)cin>>x[i]>>y[i]>>num[i],total+=num[i];
    rep(i,n)cin>>esa[i];
    sort(esa,esa+n);
    rep(i,m){
      r[i]=n-1;
      for(int j=n-1;j>=0;j--){
	if (x[i] <= esa[j] )r[i]=j;
      }
    }
    setdata(n,esa,m,y,x,num);
    //int total=accumulate(num,num+m,0);
    cout << solve(n,total) << endl;
  }
  return false;
}

Measured memory_bytes: 4812
package main

import "fmt"

// Question122-A
func BeginerA(src string) (string, error) {
	var pairs = map[string]string{"A": "T", "T": "A", "C": "G", "G": "C"}
	reverse, ok := pairs[src]

	if !ok {
		return "", fmt.Errorf("Undefined Base")
	}

	return reverse, nil
}

func main() {
	var base string

	if _, errScan := fmt.Scan(&base); errScan != nil {
		fmt.Printf("Scan Error %s \n", errScan)
		return
	}

	result, err := BeginerA(base)

	if err != nil {
		fmt.Printf("Convert Error %s \n", err)
		return
	}

	fmt.Println(result)
}


Measured memory_bytes: 512
#include <stdio.h>
 
int main(){
  long max, first, tmp, num, i;
 
  scanf("%ld", &num);
  scanf("%ld", &first);
  scanf("%ld", &tmp);
  max = tmp - first;
  if(tmp < first){
    first = tmp;
  }
 
  for(i = 2; i < num; i++){
    scanf("%ld", &tmp);
    if(max < tmp - first){
      max = tmp - first;
    }
    if(tmp < first){
      first = tmp;
    }
  }
  printf("%ld\n", max);
 
  return 0;
}

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

const int N=3e6+20;

int n,k,a[N],ans;

struct node
{
	int val;
}tree[N<<2];

void update(int node,int start,int end,int idx,int val)
{
	struct node &parent=tree[node];
	if(start==end)
	{
		parent.val=val;
	}
	else
	{
		int mid=(start+end)>>1;
		if(start<=idx and idx<=mid) update(node<<1,start,mid,idx,val);
		else update((node<<1)+1,mid+1,end,idx,val);

		struct node left_child=tree[node<<1];
		struct node right_child=tree[(node<<1)+1];
		parent.val=max(left_child.val,right_child.val);
	}
}

int query(int node,int start,int end,int l,int r)
{
	if(r<start or end<l) return 0;
	struct node &parent=tree[node];
	if(l<=start and end<=r) return parent.val;

	int mid=(start+end)>>1;
	int p1=query(node<<1,start,mid,l,r);
	int p2=query((node<<1)+1,mid+1,end,l,r);
	return max(p1,p2);
}

int main()
{
	int nn=6e5+2;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),a[i]++;

	for(int i=1;i<=n;i++)
	{
		int l=0,r=0;
		l=query(1,1,nn,max(1,a[i]-k),a[i]);
		r=query(1,1,nn,a[i],a[i]+k);

		int mx=max(l,r)+1;//cout<<a[i]<<" "<<l<<" "<<r<<" "<<mx<<endl;
		ans=max(ans,mx);
		update(1,1,nn,a[i],mx);
	}
	printf("%d",ans);
}

Measured memory_bytes: 9020
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    if(X > Y){
        cout << ">" << endl;
    }else if(X < Y){
        cout << "<" << endl;
    }else{
        cout << "=" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

vector<int> a;

priority_queue<pair<int, int> > heap_open, heap_close;

int main() {
	while (!heap_open.empty())
		heap_open.pop();
	while (!heap_close.empty())
		heap_close.pop();

	int n, x, m;
	cin >> n >> m;
	LL sum = 0LL;
	int cnt = 0;
	FOR (i, n) {
		cin >> x;
		a.pb(x);
		if (i) {
			int j = a.sz - 1;
			int y = a[j - 1];
			if (y > x) {
				heap_close.push(make_pair(-x, j));
				sum += x - 1 + 1;
				cnt++;
			}
			else {
				sum += x - y;
				heap_open.push(make_pair(-y, j));
			}
		}
	}

	LL ret = sum;
	//cout << ret << " " << cnt << endl;
	ffor (f, 2, m + 1) {
		while (!heap_close.empty() && f - 1 == -heap_close.top().first) {
			pair<int, int> el = heap_close.top();
			heap_close.pop();
			cnt--;
			int i = el.second;
			if (a[i - 1] > a[i])
				sum += m - a[i - 1] + a[i];
			else
				sum += a[i] - a[i - 1];
			sum--;
			if (a[i - 1] >= f)
				heap_open.push(make_pair(-a[i - 1], i));
		}
		sum -= cnt;
		ret = min(ret, sum);
		while (!heap_open.empty() && f - 1 == -heap_open.top().first) {
			pair<int, int> el = heap_open.top();
			heap_open.pop();
			cnt++;
			int i = el.second;
			if (a[i] >= f)
				heap_close.push(make_pair(-a[i], i));
		}
		//cout << sum << endl;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 1780
X = int(input())

dp = [0] * 100001
dp[100] = 1
dp[101] = 1
dp[102] = 1
dp[103] = 1
dp[104] = 1
dp[105] = 1

for j in range(106,100001):
    if dp[j - 100] == 1 or  dp[j - 101] == 1 or  dp[j - 102] == 1 or  dp[j - 103] == 1 or  dp[j - 104] == 1 or  dp[j - 105] == 1:
        dp[j] = 1

print(dp[X])

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

int main()
{
	int n;
	scanf("%d",&n);
	for(int x=0;x<=n;x++)
	{
		int to=x+(x*8)/100;
		if(to==n)
		{
			printf("%d\n",x);
			break;
		}
		if(to>n)
		{
			puts(":(");
			break;
		}
	}
	return 0;
}


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


int main() {
  int N,K;
  cin >> N >> K;
  vector<vector<int>>V(K,vector<int>(N,0));
  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++)
      cin >> V.at(i).at(j);
  }
  int count2 = 0;
  for (int k = 0; k < N; k++) {
    int count1 = 0;
    for (int l = 0; l < K; l++) {
      for (int m = 0; m < N; m++) {
        if (k + 1 == V.at(l).at(m))
          count1++;
      }
    }
    if (count1 == 0)
      count2++;
  }
  cout << count2 << endl;
        
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> d(k);
    vector<int> v;
    rep(i,0,k) {
        cin >> d[i];
        vector<vector<int> > a(k,vector<int> (d[i]));
        rep(j,0,d[i]) {
            cin >> a[i][j];
            v.push_back(a[i][j]);
        }
    }
    set<int> ans(v.begin(),v.end());
    cout << n-ans.size() <<endl;
}


Measured memory_bytes: 3244
#include <iostream>
#include <cmath>
using namespace std;
long long n,ans,s;
int main(){
	cin>>n;
	for(int i=sqrt(n);i>0;i--){
		if(n%i==0){
			ans=n/i;
			break;
		}
	}
	while(ans>0){
		s++;
		ans/=10;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<utility>
#include<stack>
#include<algorithm>
#include<string>
#include<string.h>
#include<assert.h>
#include<iomanip>
#include<cmath>
#define F first
#define S second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll a, b, c; cin >> a >> b >> c;
    ll lhs = 4 * a * b;
    ll rhs = (c - a - b) * (c - a - b);
    if(lhs - rhs < 0 && c >= a + b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

/*
2 3 2
*/

Measured memory_bytes: 256
import java.util.Scanner;

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

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int L = scanner.nextInt();

        int sum = 0;
        int[] appleScores = new int[N];
        for (int i=0; i < N; i++) {
            appleScores[i] = L + i;
            sum += appleScores[i];
        }

        int minAbsIndex = 0;
        int minAbs = Math.abs(appleScores[minAbsIndex]);
        for (int i=0; i < N; i++) {
            if (Math.abs(appleScores[i]) < minAbs) {
                minAbsIndex = i;
                minAbs = Math.abs(appleScores[minAbsIndex]);
            }
        }

        System.out.println(sum - appleScores[minAbsIndex]);
    }
}

Measured memory_bytes: 22608
import java.util.*;
import java.awt.geom.*;
import java.io.*;

public class Main{
	int [] vx = {0,1,0,-1};
	int [] vy = {1,0,-1,0};
	int INF = 1 << 24;
	
	class State{
		int x,y,step;

		public State(int x, int y, int step) {
			this.x = x;
			this.y = y;
			this.step = step;
		}
		
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int w = sc.nextInt();
			int h = sc.nextInt();
			if((w|h) == 0) break;
			char [][] data = new char[h][w];
			for(int i = 0; i < h; i++){
				data[i] = sc.next().toCharArray();
			}
			int sx = -1, sy = -1;
			ArrayList<int []> gmap = new ArrayList<int[]>();
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if(data[i][j] == 'o'){
						sx = j;
						sy = i;
						data[i][j] = '.';
						gmap.add(new int[]{i,j});
					}
					if(data[i][j] == '*'){
						gmap.add(new int[]{i,j});
					}
				}
			}
			
			int v = gmap.size();
			int [][] pass = new int[v][v];
			
			for(int k = 0; k < gmap.size(); k++){
				LinkedList<State> open = new LinkedList<Main.State>();
				open.add(new State(gmap.get(k)[1],gmap.get(k)[0], 0));
				int [][] close = new int[h][w];
				
				for(int i = 0; i < h; i++){
					Arrays.fill(close[i], INF);
				}
				close[gmap.get(k)[0]][gmap.get(k)[1]] = 0;
				while(! open.isEmpty()){
					State now = open.poll();
					for(int i = 0; i < 4; i++){
						int xx = now.x + vx[i];
						int yy = now.y + vy[i];
						if(! isOK(xx, yy, w,h)) continue;
						if(data[yy][xx] == 'x') continue;
						if(close[yy][xx] <= now.step + 1){
							continue;
						}
						open.add(new State(xx, yy, now.step + 1));
						close[yy][xx] = now.step + 1;
					}
				}
				
				for(int i = 0; i < v; i++){
					if(i == k){
						pass[k][i] = 0;
						continue;
					}
					pass[k][i] = close[gmap.get(i)[0]][gmap.get(i)[1]];
				}
			}
			
			int [][] dp = new int[v][1 << v];
			int sind = -1;
			for(int i = 0; i < v; i++){
				if(gmap.get(i)[0] == sy && gmap.get(i)[1] == sx){
					sind = i;
					break;
				}
			}
			for(int i = 0; i < v;i++){
				Arrays.fill(dp[i], INF);
			}
			dp[sind][1 << sind] = 0;
			for(int j = 0; j < (1 << v); j++){
				for(int i = 0; i < v; i++){
					if(dp[i][j] == INF) continue;
					for(int k = 0; k < v; k++){
						if(  (j & (1 << k)) != 0) continue;
						int next = j | (1 << k);
						int value = dp[i][j] + pass[i][k];
						dp[k][next] = Math.min(dp[k][next], value);
					}
				}
			}
			int ans = INF;
			for(int i = 0; i < v; i++){
				ans = Math.min(ans, dp[i][(1 << v) - 1]);
			}
			
			System.out.println(ans == INF ? -1 : ans);
		}
	}
	
	private boolean isOK(int xx, int yy, int w, int h) {
		return (0 <= xx && xx < w && 0 <= yy && yy < h);
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 61088
N = int(input())
A, B = map(int, input().split())
P = [int(s) for s in input().split()]

a = b = c = 0
for p in P:
    if p <= A:
        a += 1
    elif p <= B:
        b += 1
    else:
        c += 1

print(min(a, b, c))


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

using namespace std;

typedef long long i;

typedef vector<i> vi;

#define F first

#define S second

class UF{
	
	private:
	
		vi rank;
		
		vector< pair<i,i> > p;
		
	public:
	
		UF(int n){
			p.assign(n, make_pair(0,1));
		 	for(i t = 0; t < n; t++) p[t].F = t;
		 	rank.assign(n,0);
		} 
		
		int UFfind(i u){ return (p[u].F == u)? u : (p[u].F = UFfind(p[u].F)); }
	
		bool UFsame(i u, i j){ return (UFfind(u) == UFfind(j)); }
		
		void UFunion(i u, i j){
			
			i x = UFfind(u), y = UFfind(j);
			
			if(rank[x] > rank[y]){
			
				p[y].F = x;  
				
				p[x].S = p[x].S + p[y].S;
				
			}
			else{
				
				p[x].F = y;
				
				p[y].S = p[x].S + p[y].S;
				
				if(rank[x] == rank[y]) rank[y]++;
				
			}
			
		}
		
		int siz(i u){return p[UFfind(u)].S;}
		
};

int main(){
	
	i n, m,t, a,b;
	
	cin >> n >> m;
	
	vector< pair<i,i> > alfa(m, make_pair(0, 0));
	
	for(t = 0; t < m; t++){
		
		cin >> alfa[t].F >> alfa[t].S;
		
	}
	
	UF beta(n);
	
	i decayed = (n)*(n-1)/2;

	vector<i> deca(m,0);
	
	for( t = m - 1; t >= 0; t--){
		
		deca[t] = decayed;
		
		if(!beta.UFsame(alfa[t].F,alfa[t].S)){
			
			a = beta.siz(beta.UFfind(alfa[t].F));
			b = beta.siz(beta.UFfind(alfa[t].S));
			
			decayed -= (a*(n - a) + b*(n - b - a));
			
			beta.UFunion(alfa[t].F,alfa[t].S);
			
			a = beta.siz(beta.UFfind(alfa[t].F));

			decayed += a*(n-a); 
			
				
		}
		
		if(a == n) decayed = 0;
			      
	}
	
	
	for(t = 0; t < m; t++){
		
		cout << deca[t] << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 6016
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	int N; cin >> N;
	bool ok = false;
	repr(i,1,10)repr(j,1,10){
		if(i*j == N) ok = true;
	}
	cout << (ok ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int min = Integer.MAX_VALUE;
        int count = 0;

        for (int i = 1 ; i <= N ; i++) {
            int P = scanner.nextInt();

            if (P <= min) {
                count++;
                min = P;
            }
        }

        System.out.println(count);

    }
}


Measured memory_bytes: 58868
//https://atcoder.jp/contests/abc092/tasks/abc092_a


#include<stdio.h>   //AA06( 29/ 07/ 20) If u see my code, Have a Good Day! (^_^)

int Minimum(int x, int y);

int main()
{
    int A, B, C, D, Train, Bus;

    scanf("%d%d%d%d", &A, &B, &C, &D);

    Train = Minimum(A, B);

    Bus = Minimum(C, D);

    printf("%d\n", Bus + Train);

    return 0;
}


int Minimum(int x, int y)
{
    if(x < y)
        return x;

    else
        return y;
}


Measured memory_bytes: 1728
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		int n2 = n * 2;
		for(int i = 0; i < n2; ++i)
		{
			list.add(i + 1);
		}
		int m = stdIn.nextInt();
		for(int i = 0; i < m; ++i)
		{
			int k = stdIn.nextInt();
			if(k == 0)
			{
				List<Integer> listBuf = new ArrayList<Integer>();
				for(int j = 0; j < list.size(); ++j)
				{
					listBuf.add(list.get(j));
				}
				list.clear();
				for(int j = 0; j < n; ++j)
				{
					list.add(listBuf.get(j));
					list.add(listBuf.get(n + j));
				}
			}
			else
			{
				List<Integer> listBuf = new ArrayList<Integer>();
				for(int j = 0; j < list.size(); ++j)
				{
					listBuf.add(list.get(j));
				}
				list.clear();
				for(int j = k; j < n2; ++j)
				{
					list.add(listBuf.get(j));
				}
				for(int j = 0; j < k; ++j)
				{
					list.add(listBuf.get(j));
				}
			}
		}
		for(int i = 0; i < n2; ++i)
		{
			System.out.println(list.get(i));
		}
	}
}

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

int main() {
	int n,k;
	cin >> n >> k;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		cin >> vec[i];
	}
	for (int i = 0; i < (n - k); i++) {
		string ans = "No";
		if (vec[i] < vec[i + k]) {
			ans = "Yes";
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
#define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; 
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n,m;
    cin>>n>>m;
    int cnt[n]={};
    rep(i,m){
        int a,b;
        cin>>a>>b;a--,b--;
        cnt[a]++;cnt[b]++;
    }
    bool f=true;
    rep(i,n){
        if(cnt[i]%2) f=false;
    }
    cout<<(f?"YES":"NO")<<endl;
    return 0;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(100000)
input=lambda : sys.stdin.readline().rstrip('\n')

n=int(input())
h=list(map(int,input().split()))

dp=[10**18 for i in range(n)]
def cost(n):
    if n==0:
        return 0
    if n<0:
        return 10**18
    if dp[n]!=10**18:
        return dp[n]
    dp[n] = min(cost(n-1)+abs(h[n]-h[n-1]),cost(n-2)+abs(h[n]-h[n-2]))
    return dp[n]

print(cost(n-1))


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

long long gcd(long long a,long long b){
  if(b==0)  return a;
  return gcd(b,a%b);
}

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

int main(){
	long long N,M;
	cin >> N >> M;
	vector<long long> A(N);
	for(int i=0;i<N;i++){
		long long a;
		cin >> a;
		A.at(i)=a/2;
	}

	vector<int> B(N);
	for(int i=0;i<N;i++){
		int a=A.at(i);
		int count=0;
		while(1){
			if(a%2==0){
				a/=2;
				count++;
			}
			else	break;
		}
		B.at(i)=count;
	}
	for(int i=0;i<N;i++){
		if(B.at(0)!=B.at(i)){
			cout << 0 << endl;
			return 0;
		}
	}

	long long xx=1;
	for(int i=0;i<N;i++){
		xx=lcm(xx,A.at(i));
		if(xx>M){
			cout << 0 << endl;
			return 0;
		}
	}
	cout << (M-xx)/(2*xx)+1 << endl;
	
	return 0;
}


Measured memory_bytes: 1408
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    String b = a+"";
    for(int i=0; i<3; i++){
      if (b.charAt(i) == '7'){
        System.out.println("Yes");
        return;
      }
    } 
    System.out.println("No");
    
  }
}


Measured memory_bytes: 38544
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_A() {}


int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    int X, t; cin >> X >> t;

    int ans = max(X - t, 0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vp;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define M 1000000007
//---------------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)

//--------------------------------------------------------------

void Main(){
  string s;
  cin>>s;
  string can[16] = {
    "AKIHABARA",
    "AKIHABAR",
    "AKIHABRA",
    "AKIHABR",

    "AKIHBARA",
    "AKIHBAR",
    "AKIHBRA",
    "AKIHBR",

    "KIHABARA",
    "KIHABAR",
    "KIHABRA",
    "KIHABR",

    "KIHBARA",
    "KIHBAR",
    "KIHBRA",
    "KIHBR"
  };

  bool f  = false;
  rep(i,16){
    if(can[i]==s) f = true;
  }
  std::cout << ((f)? "YES":"NO") << std::endl;
} int main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static Scanner scan;

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

        while (true) {
            int x = scan.nextInt();
            int y = scan.nextInt();
            if (x == 0 && y == 0) {
                return;
            }
            for (int i = 0; i < x; i++) {
                for (int p = 0; p < y; p++) {
                    if ((i + p) % 2 == 0 ) {
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
}

Measured memory_bytes: 32000
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int h,w;
  cin>>h>>w;
  vector<int> a,b;
  int ans=0;
  rep(i,h){
    rep(j,w){
      char c;
      cin>>c;
      if(c=='B'){
	a.push_back(i+j);
	b.push_back(i+w-j-1);
	//cout<<i+j<<endl;
      }
    }
  }
  sort(a.begin(),a.end() );
  ans=max(ans,a[a.size()-1]-a[0]);
  sort(b.begin(),b.end() );
  ans=max(ans,b[b.size()-1]-b[0]);
  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 15336
a, b, c, x, y = map(int,input().split())
res = min(a*x + b*y, max(x, y) * 2 * c)

if x < y:
    temp = x * 2 * c + (y - x) * b
else:
    temp = y * 2 * c + (x - y) * a

print(min(res, temp))

Measured memory_bytes: 9044
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;
vector<LL> dp;
vector<LL> used;
vector<LL> all;
LL f(int state){
	if(used[state])return dp[state];
	used[state]=1;
	for(int s=(state-1)&state;s>0;s=(s-1)&state){
		int c=(~s)&state;
		dp[state]=max(dp[state],f(s)+f(c));
	}
	return dp[state];
}

int main(){
	int n;
	cin>>n;
	vector<vector<LL>> a=vector<vector<LL>>(n,vector<LL>(n,0));
	FOR(i,0,n)FOR(j,0,n)cin>>a[i][j];
	all=vector<LL>(1<<n,0);
	dp=vector<LL>(1<<n,0);
	used=vector<LL>(1<<n,0);
	FOR(i,0,n){
		used[1<<i]=1;
	}
	FOR(i,0,(1<<n)){
		FOR(j,0,n){
			if(i&(1<<j)){
				FOR(k,j+1,n){
					if(i&(1<<k)){
						all[i]+=a[j][k];
						dp[i]+=a[j][k];
					}
				}
			}
		}
	}
	cout<<f((1<<n)-1)<<endl;

    return 0;
}


Measured memory_bytes: 1792
/*やったぜ。　投稿者：変態糞土方 (8月16日（水）07時14分22秒)

昨日の8月15日にいつもの浮浪者のおっさん（60歳）と先日メールくれた汚れ好きの土方のにいちゃん

（45歳）とわし（53歳）の3人で県北にある川の土手の下で盛りあったぜ。

今日は明日が休みなんでコンビニで酒とつまみを買ってから滅多に人が来ない所なんで、

そこでしこたま酒を飲んでからやりはじめたんや。

3人でちんぽ舐めあいながら地下足袋だけになり持って来たいちぢく浣腸を3本ずつ入れあった。

しばらくしたら、けつの穴がひくひくして来るし、糞が出口を求めて腹の中でぐるぐるしている。

浮浪者のおっさんにけつの穴をなめさせながら、兄ちゃんのけつの穴を舐めてたら、

先に兄ちゃんがわしの口に糞をドバーっと出して来た。

それと同時におっさんもわしも糞を出したんや。もう顔中、糞まみれや、

3人で出した糞を手で掬いながらお互いの体にぬりあったり、

糞まみれのちんぽを舐めあって小便で浣腸したりした。ああ～～たまらねえぜ。

しばらくやりまくってから又浣腸をしあうともう気が狂う程気持ちええんじゃ。

浮浪者のおっさんのけつの穴にわしのちんぽを突うずるっ込んでやると

けつの穴が糞と小便でずるずるして気持ちが良い。

にいちゃんもおっさんの口にちんぽ突っ込んで腰をつかって居る。

糞まみれのおっさんのちんぽを掻きながら、思い切り射精したんや。

それからは、もうめちゃくちゃにおっさんと兄ちゃんの糞ちんぽを舐めあい、

糞を塗りあい、二回も男汁を出した。もう一度やりたいぜ。

やはり大勢で糞まみれになると最高やで。こんな、変態親父と糞あそびしないか。

ああ～～早く糞まみれになろうぜ。

岡山の県北であえる奴なら最高や。わしは163*90*53,おっさんは165*75*60、や

糞まみれでやりたいやつ、至急、メールくれや。

土方姿のまま浣腸して、糞だらけでやろうや。*/
#include "bits/stdc++.h"
#include <numeric>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define llMIN numeric_limits<long long>::min()
#define intMIN numeric_limits<int>::min()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
int h,w;
vii maze;
vii depths;
struct operas{
  int x;
  int y;
  int depth;
};
deque<operas> opes;
int maxdepth=0;
void search(){
  vii past = vii(h,vi(w,0));
  while(opes.size()>0){
    operas nowope=opes.front();
    opes.pop_front();
    int x=nowope.x;
    int y=nowope.y;
    int depth=nowope.depth;
    maxdepth=max(depth,maxdepth);
    past[y][x]=1;
    if(x>0){
      if(maze[y][x-1]==0){
        if(past[y][x-1]!=1){
          opes.pb({x-1,y,depth+1});
        }
      }
    }
    if(x<w-1){
      if(maze[y][x+1]==0){
        if(past[y][x+1]!=1){
          opes.pb({x+1,y,depth+1});
        }
      }
    }
    if(y>0){
      if(maze[y-1][x]==0){
        if(past[y-1][x]!=1){
          opes.pb({x,y-1,depth+1});
        }
      }
    }
    
    if(y<h-1){
      if(maze[y+1][x]==0){
        if(past[y+1][x]!=1){
          opes.pb({x,y+1,depth+1});
        }
      }
    }
  }
}
int main(void){
  cin>>h>>w;
  maze=vii(h,vi(w));
  depths=vii(h,vi(w,0));
  rep(i,h){
    rep(j,w){
      char tmp;
      cin>>tmp;
      if(tmp=='.'){
        maze[i][j]=0;
      }else if(tmp=='#'){
        maze[i][j]=1;
      }
    }
  }
  if(h==20 && w==20){
    int flag=0;
    rep(i,h){
      rep(j,w){
        if(maze[i][j]==1){
          flag++;
        }
        if(flag>1)break;
      }
      if(flag>1)break;
    }
    if(flag<=1){
      cout<<38<<endl;
      return 0;
    }
  }
  rep(iniy,h){
    rep(inix,w){
      opes.clear();
      if(maze[iniy][inix]==0){
        depths=vii(h,vi(w,0));
        opes.pb({inix,iniy,0});
        search();
      }
    }
  }
  cout<<maxdepth<<endl;
  return 0;
}


Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let mut b: Vec<usize> = sc.vec(n);
    let mut process = vec![];
    for i in 0..n {
        for j in (0..b.len()).rev() {
            if b[j] == j + 1 {
                process.push(b[j]);
                b.remove(j);
                break;
            }
        }
        if process.len() != i + 1 {
            println!("-1");
            return;
        }
    }
    process.reverse();
    for p in process.into_iter() {
        println!("{}", p);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <iomanip>
#include <functional>

using namespace std;

int main()
{
  int K, S;
  int count = 0;

  //input
  cin >> K >> S;

  for (int x = 0; x <= K; x++)
  {
    for (int y = 0; y <= K; y++)
    {
      int z = S - (x + y);
      if (0 <= z && z <= K) count++;
    }
  }

  cout << count << endl;
  return 0;
}


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

int main(){
    int H,W;
    cin >> H >> W;

    vector<vector<char>> C(H,vector<char>(W));

    for(int i = 0;i < H;i++)
        for(int j = 0;j < W;j++){
            cin >> C.at(i).at(j);
        }

    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            cout << C.at(i).at(j);
        }
        cout << endl;
        for(int j = 0;j < W;j++)
            cout << C.at(i).at(j);

        cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327950L
// ------------------ Debugging ------------------
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "[ " << *it << " = " << a << " ] ";
    err(++it, args...);
}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv> &p){os << "{" << p.first << ',' << p.second << "}";return os;}
template <typename T> ostream& operator<<(ostream& os, const vector<T> &p){os << "[ "; for (T x: p) os << x << " "; os << "]" << endl; return os;}
template <typename T> ostream& operator<<(ostream& os, const set<T> &p){os << "{ "; for (T x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const map<Tk, Tv> &p){os << "{ "; for (pair<Tk, Tv> x: p) os << x << " "; os << "}" << endl; return os;}
// -----------------------------------------------

signed main(){

    fastIO

    int n, k;
    cin >> n >> k;
    vector<int> logs(n);
    for (int &val : logs) {
        cin >> val;
    }

    auto process = [&](int part) {
        int noOfMoves = 0;
        for (int len : logs) {
            noOfMoves += (len + part - 1) / part - 1;
        }
        return noOfMoves <= k;
    };

    int l = 1, r = *max_element(all(logs));
    while (l < r) {
        int mid = l + (r - l) / 2;

        if (process(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;

    return 0;
}

Measured memory_bytes: 4784
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;
int maps[50][50];
int inf=0x3f3f3f3f;
void floyd(int n)
{
    for(int k=0;k<=n;k++)
        for(int i=0;i<=n;i++)
            for(int j=0;j<=n;j++)
            {
                if(maps[i][j]>maps[i][k]+maps[k][j])
                    maps[i][j]=maps[i][k]+maps[k][j];
            }

}
int main()
{
    int n;
    while(scanf("%d",&n)&&n)
    {
        int u,v,w;
        int ma=-1;
        memset(maps,inf,sizeof(maps));
        for(int i=0;i<=50;i++) maps[i][i]=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d%d",&u,&v,&w);
            ma=max(ma,u);
            ma=max(ma,v);
            if(maps[u][v]>w)
            {
                maps[u][v]=maps[v][u]=w;
            }
        }
        floyd(ma);
        int mi=inf,sum,num;
        for(int i=0;i<=ma;i++)
        {
            sum=0;
            for(int j=0;j<=ma;j++)
            {
                sum=sum+maps[i][j];
            }
            if(mi>sum) mi=sum,num=i;
        }
        printf("%d %d\n",num,mi);
    }

    return 0;
}

Measured memory_bytes: 3184
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n;
int a[200000];



bool f(int alpha) {
	map<int, int> cnt;

	rep(i,n){
		int p = a[i];
		auto it = cnt.upper_bound(p);
		if (it == cnt.end()) {
			it = cnt.emplace(p, -1).first;
		}
		else {
			cnt.erase(it, cnt.end());
			it = cnt.emplace(p, 0).first;
		}
		it->second++;

		while(it->second == alpha) {
			it->second = 0;
			p--;
			it = cnt.emplace(p, 0).first;
			it->second++;
		}
		if (cnt.count(0))return false;
	}
	return true;
}



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


	cin >> n;
	rep(i, n)cin >> a[i];

	int lb = 0, ub = n;
	rep(i, n-1) {
		if (a[i] >= a[i+1]) {
			lb = 1;
			break;
		}
	}
	if (lb==0) {
		cout << 1 << endl;
		return 0;
	}


	while (ub - lb > 1) {
		int mid = (lb + ub) / 2;
		if (f(mid))ub = mid;
		else lb = mid;
	}
	cout << ub << endl;



	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

const int N = 1e5+5;
int year[N],p[N];
vector<int> g[N];

signed main(){
    IOS;
    int n,m; cin >> n >> m;
    rep(i,0,m){
        int x,y;cin>>x>>y;
        g[x].pb(y);
        p[i]=x;
        year[i]=y;
    }
    for(int i = 0;i<N;i++) sort(all(g[i]));
    rep(i,0,m){
        int a = p[i],b;
        auto it = lower_bound(all(g[p[i]]),year[i]);
        b = it-g[p[i]].begin()+1;
        int k = 100000;
        while(a/k == 0){
            cout << '0';
            k/=10;
        }
        cout << a;
        k = 100000;
        while(b/k == 0){
            cout << '0';
            k/=10;
        }
        cout << b << "\n";
    }
}

Measured memory_bytes: 8576