akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

#define PI 3.1415926535897932384626433832795028841

int isreach(int x,int y,int wangle,int wpower,int fangle) {
	double angle1,angle2,angle3,angle4;
	if(x*x+y*y>wpower*wpower)return 0;
	angle1=atan2(y,x);
	angle2=wangle*PI/180.0;
	angle3=fangle*PI/180.0;
	angle4=fabs(angle1-angle2);
	while(angle4>=PI*2)angle4-=PI*2;
	if(angle4>PI)angle4=PI*2-angle4;
	return angle4<=angle3/2;
}

int main(void) {
	int H,R;
	int housex[100],housey[100],houseok[100];
	int U,M,S,du,dm,ds;
	int ux[10],uy[10],mx[10],my[10],sx[10],sy[10];
	int w,a;
	int i,j,k;
	int ok,max;
	while(scanf("%d%d",&H,&R)==2 && (H|R)!=0) {
		for(i=0;i<H;i++) {
			scanf("%d%d",&housex[i],&housey[i]);
			houseok[i]=0;
		}
		scanf("%d%d%d%d%d%d",&U,&M,&S,&du,&dm,&ds);
		for(i=0;i<U;i++)scanf("%d%d",&ux[i],&uy[i]);
		for(i=0;i<M;i++)scanf("%d%d",&mx[i],&my[i]);
		for(i=0;i<S;i++)scanf("%d%d",&sx[i],&sy[i]);
		for(i=0;i<R;i++) {
			scanf("%d%d",&w,&a);
			for(j=0;j<H;j++) {
				if(isreach(housex[j],housey[j],w,a,du)) {
					ok=1;
					for(k=0;k<U;k++) {
						if(isreach(housex[j]-ux[k],housey[j]-uy[k],w,a,du)) {
							ok=0;
							break;
						}
					}
					if(ok) {
						for(k=0;k<M;k++) {
							if(isreach(housex[j]-mx[k],housey[j]-my[k],w,a,dm)) {
								ok=0;
								break;
							}
						}
					}
					if(ok) {
						for(k=0;k<S;k++) {
							if(isreach(housex[j]-sx[k],housey[j]-sy[k],w,a,ds)) {
								ok=0;
								break;
							}
						}
					}
					if(ok)houseok[j]++;
				}
			}
		}
		max=0;
		for(i=0;i<H;i++) {
			if(houseok[i]>max)max=houseok[i];
		}
		if(max==0)puts("NA");
		else {
			ok=0;
			for(i=0;i<H;i++) {
				if(houseok[i]==max) {
					if(ok)putchar(' ');
					printf("%d",i+1);
					ok=1;
				}
			}
			putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 676
#include <stdio.h>

int main(void)
{
	int p;
	char mass[8][8];
	int i, j;
	
	for(i = 0; i < 8; i++){
		scanf("%s", mass[i]);
	}
	
	printf("90\n");
	for (i = 0; i < 8; i++){
		for (j = 7; 0 <= j; j--){
			printf("%c", mass[j][i]);
		}
		printf("\n");
	}
	
	printf("180\n");
	for (i = 7; 0 <= i; i--){
		for (j = 7; 0 <= j; j--){
			printf("%c", mass[i][j]);
		}
		printf("\n");
	}
	
	printf("270\n");
	for (i = 7; 0 <= i; i--){
		for (j = 0; j < 8; j++){
			printf("%c", mass[j][i]);
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  int N,M,X;cin>>N>>M>>X;
  vi A(M);rep(i,M)cin>>A[i];
  int left=0,right=0;
  f(i,1,X){
    f(j,0,M){
      if(A[j]==i)left++;
    }
  }
  f(i,X+1,N){
    f(j,0,M){
      if(A[j]==i)right++;
    }
  }
  cout<<min(left,right)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,C;
  cin>>n>>C;
  bool m[C][200001];
  memset(m,false,sizeof(m));
  int s,t,c;
  for(int i=0;i<n;i++){
    cin>>s>>t>>c;
    c--;
    for(int j=s*2-1;j<=t*2;j++) m[c][j]=true;
  }
  vector<int> a(200001,0);
  for(int i=0;i<C;i++){
    for(int j=0;j<200001;j++){
      if(m[i][j]) a[j]++;
    }
  }
  int cnt=0;
  for(int i=0;i<200001;i++)
    cnt=max(cnt,a[i]);
  cout<<cnt;
}

Measured memory_bytes: 6912
#include<iostream>
using namespace std;
int b,r,g,c,s,t,ans;
int main(){
  while(1){
    cin>>b>>r>>g>>c>>s>>t;
    if(b==0&&r==0&&g==0&&c==0&&s==0&&t==0)break;
    ans=100;
    ans-=t*3;
    ans+=(b*(15*6+5)+r*(15*4+3)+g*7+c*2+3*s);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstring>
using namespace std;
long long n;
string s= "";
int main()
{
    cin>> n;
    while(n){
        if(n%26== 0){
            s= 'z'+ s;
            n-- ;
        }
        else
        {
            char c= (n%26- 1)+ 'a';
            s= c+ s;
        }
        n/= 26;
    }
    cout<< s;
    return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String a, b;
		
		a = sc.next();
		b = sc.next();
		
		if(a.equals("H"))
			System.out.println(b);
		else {
			if(b.equals("H"))
			System.out.println(a);
			else
				System.out.println("H");
		}	
		sc.close();
	}

}


Measured memory_bytes: 20820
#include <assert.h>
#include <cstdint>
#include <iostream>

using namespace std;

#define MAX_ANIMALS 100000
char animals[MAX_ANIMALS];
char answers[MAX_ANIMALS];

void decide_animals(uint64_t N)
{
  for (uint64_t i = 1; i < N - 1; i++) {
    switch (animals[i]) {
    case 'S':
      if (answers[i] == 'o') {
        animals[i + 1] = animals[i - 1];
      } else {
        animals[i + 1] = animals[i - 1] == 'S' ? 'W' : 'S';
      }
      break;
    case 'W':
      if (answers[i] == 'x') {
        animals[i + 1] = animals[i - 1];
      } else {
        animals[i + 1] = animals[i - 1] == 'S' ? 'W' : 'S';
      }
      break;
    default:
      assert(0);
      break;
    }
  }
}

bool is_valid_at(uint64_t N, uint64_t at)
{
  uint64_t pre = at - 1;
  if (at == 0) {
    pre = N - 1;
  }

  switch (animals[at]) {
  case 'S':
    if (answers[at] == 'o') {
      return animals[pre] == animals[(at + 1) % N];
    } else {
      return animals[pre] != animals[(at + 1) % N];
    }
    break;
  case 'W':
    if (answers[at] == 'x') {
      return animals[pre] == animals[(at + 1) % N];
    } else {
      return animals[pre] != animals[(at + 1) % N];
    }
    break;
  default:
    assert(0);
    break;
  }
  assert(0);
  return false;
}

bool check_validity(uint64_t N)
{
  if (is_valid_at(N, 0) && is_valid_at(N, N - 1)) {
    return true;
  }

  return false;
}

void valid(uint64_t N)
{
  for (uint64_t i = 0; i < N; i++) {
    cout << animals[i];
  }
  cout << endl;
}

void invalid()
{
  cout << -1 << endl;
}

int32_t main()
{
  uint64_t N;
  cin >> N;

  for (uint64_t i = 0; i < N; i++) {
    char answer;
    cin >> answer;
    answers[i] = answer;
  }

  animals[0] = 'S';
  animals[1] = 'S';
  decide_animals(N);
  if (check_validity(N)) {
    valid(N);
    return 0;
  }

  animals[0] = 'S';
  animals[1] = 'W';
  decide_animals(N);
  if (check_validity(N)) {
    valid(N);
    return 0;
  }

  animals[0] = 'W';
  animals[1] = 'S';
  decide_animals(N);
  if (check_validity(N)) {
    valid(N);
    return 0;
  }

  animals[0] = 'W';
  animals[1] = 'W';
  decide_animals(N);
  if (check_validity(N)) {
    valid(N);
    return 0;
  }

  invalid();

  return 0;
}


Measured memory_bytes: 512
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        k: usize,
        s: String,
    }

    if s.len() <= k {
        println!("{}", s);
    } else {
        println!("{}...", &s[0..k]);
    }
}


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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s,t;
    cin>>s>>t; 
    
    ll ans=LLONG_MAX;
    
    for(int i=0;i<=s.size()-t.size();i++)
    {
        int j=0;
        ll tmp=0;
        while(j!=t.size())
        {
            if(t[j]!=s[j+i])tmp++;
            j++;
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
	return 0;
}


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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define MIN(c) (*min_element(ALL(c))) 
#define MAX(c) (*max_element(ALL(c)))
#define ACC(c) (accumulate(ALL(c), 0))
#define SLL(x, n) ((x) << (n))
#define SRL(x, n) ((x) >> (n))
#define MIN2(a, b) ((a) < (b)) ? (a) : (b)
#define MAX2(a, b) ((a) > (b)) ? (a) : (b)
#define MP(a, b) (make_pair((a), (b)))
#define ENDL "\n"
#define PRINT(x) cout << (x) << ENDL

template<typename T> inline void fill(T array[], T value) {for(T t: array) t = value;}
inline int in(int& a) {return scanf("%d", &a);}
inline void out(int n) {printf("%d\n", n);}

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

int N, M;
int L[100000], R[100000];

signed main(){
    in(N); in(M);
    REP(i, M){
        in(L[i]); in(R[i]);
    }
    sort(L, L + M);
    sort(R, R + M);
    PRINT(MAX2(0, R[0] - L[M - 1] + 1));
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	int A[N]{};
	for (int i = 1; i < N; i++) {
		cin >> A[i];
	}
	int b[N]{};
	for (int i = 1; i < N; i++) {
		b[A[i] - 1]++;
	}
	for (int i : b) {
		cout << i << "\n";
	}
	return 0;
}

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

int main() {
    int n;
    string T, H;
    int tPoint = 0, hPoint = 0;
    cin >> n;

    for(int i = 0; i < n; i++) {
        cin >> T >> H;
        if (T == H) {
            tPoint++;
            hPoint++;
            continue;
        }

        int tSize = T.size();
        int hSize = H.size();
        int sSize;
        if (tSize > hSize) {
            sSize = hSize;
        } else {
            sSize = tSize;
        }

        for(int i = 0; i < sSize; i++) {
            if (T[i] == H[i]) {
                if (i == sSize -1) {
                    if (tSize > hSize) {
                        tPoint += 3;
                    } else {
                        hPoint += 3;
                    }
                    break;
                }
                continue;
            }
            
            if (T[i] > H[i]) {
                tPoint += 3;
            } else {
                hPoint += 3;
            }
            break;
        }
    }

    cout << tPoint << " " << hPoint << endl;
}


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

using namespace std;

struct point {
	double x,y;
};

struct circle {
	point p;
	double r;
};

double dist[1002][1002];

double f(point &a, point &b) {
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

double g(circle &a, circle &b) {
	return max(0.0,f(a.p,b.p)-a.r-b.r);
}

int main() {
	point s,t; cin >> s.x >> s.y >> t.x >> t.y;
	int n; cin >> n;
	vector<circle> cs(n);
	for(int i=0;i<n;++i) cin >> cs[i].p.x >> cs[i].p.y >> cs[i].r;
	for(int i=0;i<n;++i) {
		for(int j=i+1;j<n;++j) {
			dist[i][j]=dist[j][i]=g(cs[i],cs[j]);
		}
		dist[i][n]=dist[n][i]=max(0.0,f(s,cs[i].p)-cs[i].r);
		dist[i][n+1]=dist[n+1][i]=max(0.0,f(t,cs[i].p)-cs[i].r);
	}
	dist[n][n+1]=dist[n+1][n]=f(s,t);
	for(int k=0;k<n+2;++k)
		for(int i=0;i<n+2;++i)
			for(int j=0;j<n+2;++j)
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
    printf("%.10f\n",dist[n][n+1]);
	
	return 0;
}


Measured memory_bytes: 8064
#include <stdio.h>

int main()
{
  int count, price, min, profit;
  scanf("%d", &count);

  int prices[count - 1];

  for (int n = 0; n < count; ++n)
  {
    scanf("%d", &prices[n]);
  }

  min = prices[0];
  profit = prices[1] - prices[0];

  for (int j = 1; j < count; ++j)
  {
    if (prices[j] < min)
      min = prices[j];
    else if (prices[j] - min > profit)
      profit = prices[j] - min;
  }

  printf("%d\n", profit);

  return 0;
}


Measured memory_bytes: 2640
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  string s;
  cin>>s;
  int n=s.size();
  int64_t ans=0;
  for(int p=0;p<(1<<n-1);p++){
    int64_t r=0,sum=0;
    for(int i=0;i<n-1;i++){
      string t=s.substr(r,i-r+1);
      if((p>>i)&1){sum+=stoll(t);r=i+1;}
     // cout<<t<<endl;
    }
    sum+=stoll(s.substr(r));
    ans+=sum;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
	 public static void main(String[] args){
		 int a,b,c;
         Scanner sc = new Scanner(System.in);
    
        
         a = sc.nextInt();
         b = sc.nextInt();
         c = sc.nextInt();
         if(a<b&&b<c){
        	 System.out.println("Yes");
         }else{
        	 System.out.println("No");
        
         sc.close();
	 }
	 }
	 }




Measured memory_bytes: 26392
#include<bits/stdc++.h>
using namespace std;
static const int N = 1000;
int n;
struct info{
 	char c; 
 	int v;
};
void BubbleSort(info *c){
	 for(int i=0;i<n;i++){
       for(int j=n-1;j>i;j--){
        	if(c[j].v<c[j-1].v){
           	 	swap(c[j],c[j-1]);
       		}    
 		}
  	}
}
void SelectSort(info *c){
    int mini; 
 	for(int i=0;i<n;i++){	 
   	 	mini=i;     
  		for(int j=i+1;j<n;j++){    
     		if(c[j].v<c[mini].v)
      			mini=j;
  	  	}
  		if(mini!=i)
			swap(c[mini],c[i]);
   }
}
int main(){
   cin>>n;
  	info a[n],b[n]; 
    bool select=false;
    for(int i=0;i<n;i++){
        cin>>a[i].c>>a[i].v;
        b[i].c=a[i].c;
        b[i].v=a[i].v;
    }
    BubbleSort(a);
    SelectSort(b);
    for(int i=0;i<n;i++){
        if(i<n-1)
            cout<<a[i].c<<a[i].v<<" ";
        else
            cout<<a[i].c<<a[i].v<<endl;
    }
    cout<<"Stable"<<endl;
    for(int i=0;i<n;i++){
        if(!select&&a[i].c!=b[i].c){
            select = true;
        }
        if(i<n-1)
            cout<<b[i].c<<b[i].v<<" ";
        else
            cout<<b[i].c<<b[i].v<<endl;
    }
    if(select){
        cout<<"Not stable"<<endl;
    }
    else
        cout<<"Stable"<<endl;
    return 0;
}


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

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

int main()
{
    string S, T;
    cin >> S >> T;
    if(S.length() == T.length() - 1){
        if(S == T.substr(0, T.length() - 1)){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}



Measured memory_bytes: 3628
/*
For Bantako San
By shyyhs.

Using hash to insert and search for a perticular number.
Every insert and search is O(1) ideally.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
#define ll long long
//#define Hsize 100009
#define Hsize (1<<16)
#define MAXN 201001 
ll sumZ=0; //sum from the beginning
int Ai; //This is Ai in the problem, we use it only once so array is not necessary.
int N; //N in the problem

struct T
{
    ll number,times;
    T* next;
}hashBucket[MAXN];
int top=0;
int hashIndex[Hsize];


//x->hash(x)
inline int hashFunc(ll x)
{
    return (x&(0x0000FFFF));
}

//add the current sumZ to the hash table
inline void addToHash(ll sumZ)
{
    int HsumZ;
    T *index, *beginP;
    HsumZ = hashFunc(sumZ);
    for (beginP=index=&hashBucket[hashIndex[HsumZ]]; (index->times>0); index=index->next)
        if (index->number==sumZ)
        {
            index->times++;
            return;
        }
    hashIndex[HsumZ]=(++top);
    index=&hashBucket[top];
    index->number = sumZ;
    index->times = 1;
    index->next = beginP;
}

void init()
{
    scanf("%d",&N);
    addToHash(0);
    for (int i=0; i<N; ++i)
    {
        scanf("%d",&Ai);
        sumZ=sumZ+Ai;
        addToHash(sumZ);
    }
}

void work()
{
    ll answer=0;
    for (int i=1; i<=top; ++i)
    if (hashBucket[i].times>1)
        answer=answer+(((hashBucket[i].times)*(hashBucket[i].times-1))>>1) ;
    cout<<answer<<endl;
}
    
int main()
{
    init();
    work();
    return 0;
}


Measured memory_bytes: 5248
#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,s,n) for(int i = (s); i < (n); ++i)

typedef long long ll;

ll gcd(ll a, ll b) {
	ll c;
	while (true) {
		c = a % b;
		if (c == 0) {
			return b;
		}
		a = b;
		b = c;
	}
}

int H, W;



int main() {
#ifdef CIN_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif

	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {
		cin >> H >> W;
		if (H == W) {
			cout << "1 0" << endl;
			continue;
		}

		ll C = gcd(H, W);
		ll h = H / C, w = W / C;

		ll siro = (h * w) / 2;
		ll kuro = (h * w + 1) / 2;

		if (!(h & 1) || !(w & 1)){
			// gusu
			cout << "1 1" << endl;
		}
		else{
			cout << kuro << " " << siro << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <vector>

struct Combination {
  std::vector<long long> fac, finv, inv;
  int mod;
  Combination(int max_n, int _mod) {
    fac = finv = inv = std::vector<long long>(max_n + 10, 0);
    mod = _mod;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < max_n + 10; i++) {
      fac[i] = fac[i - 1] * i % mod;
      inv[i] = mod - inv[mod % i] * (mod / i) % mod;
      finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }
  long long mod_comb(int n, int k) {
    if (n < k || n < 0 || k < 0) {
      return 0;
    }
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
  }
};

int main() {
  int max_n = 2000;
  int mod = 1000000007;

  Combination comb(max_n, mod);

  int n, k;
  std::cin >> n >> k;

  for (int i = 1; i <= k; i++) {
    long long a = comb.mod_comb(n - k + 1, i);
    long long b = comb.mod_comb(k - 1, i - 1);
    std::cout << a * b % mod << "\n";
  }

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>

using namespace std;

const int N=3010;

int n, a[N];
bool flag[N];
int head[N], cnt;

struct EDGE {
	int y, nex;
}edge[N<<1];

void add(int x, int y) {
	edge[++cnt].y=y;
	edge[cnt].nex=head[x];
	head[x]=cnt;
}

void dfs(int x, int fa) {
	flag[x]=0;
	for(int i=head[x]; i; i=edge[i].nex) {
		int y=edge[i].y;
			if(y!=fa&&a[x]>a[y]) {
				dfs(y, x);
				if(!flag[y]) {
					flag[x]=1;
					return;
				}
			}
	}
}

int main() {
	scanf("%d", &n);
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	for(int i=1; i<n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		add(x, y), add(y, x);
	}
	for(int i=1; i<=n; i++) {
		dfs(i, 0);
		if(flag[i]) printf("%d ", i);
	}
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define UNIQUE(v) do{ (v).erase( unique(begin(v), end(v)), end(v) ); } while(0)

namespace std {
	template<class S, class T> pair<S, T> operator + (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first + b.first, a.second + b.second);}
	template<class S, class T> pair<S, T> operator - (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first - b.first, a.second - b.second);}
	template<class S, class T> pair<S, T>& operator += (pair<S, T> &a, const pair<S, T> &other) {return a = a + other;}
	template<class S, class T> pair<S, T>& operator -= (pair<S, T> &a, const pair<S, T> &other) {return a = a - other;}
	template<class S, class T> ostream& operator << (ostream& ost, pair<S, T> p) {ost << "(" << p.first << ", " << p.second << ")";return ost;}
	template<class T> ostream& print_iterable_container(ostream& ost, T& container) {
		for (auto&& iter = begin(container); iter != end(container); ++iter) ost << (iter == begin(container) ? " [ " : ", ") << (*iter);
		return ost << " ]";
	}
#	define APPLY_PRINT_ITERABLE_CONTAINER(container_type)\
	template<class T> ostream& operator << (ostream& ost, container_type<T>& container) {\
		return print_iterable_container(ost, container);\
	}
	APPLY_PRINT_ITERABLE_CONTAINER(vector);
	APPLY_PRINT_ITERABLE_CONTAINER(list);
	APPLY_PRINT_ITERABLE_CONTAINER(deque);
}

template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

using ld = long double;

template<class T> using VV = vector<vector<T> >;
template<class T> using maxPQ = priority_queue<T>;
template<class T> using minPQ = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> using uomap = unordered_map<T, U>;
template<class T> using uoset = unordered_set<T>;

const ll INF = 1001001001;
const ll INFll = (ll)INF * INF;
const ll MOD = 1000000007;
const ll MOD_FFT = 998244353;
const ld EPS = 1e-15;

//function<void(int,int)> tensi_no_3p=[&](int v,int d){
//};

int main() {
	ios_base::sync_with_stdio(false);
	int ans = 0;
	ll X, Y; cin >> X >> Y;
	while (X <= Y) {
		X *= 2;
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#
# 4c
#


def main():
    while True:
        a, op, b = input().split()
        a = int(a)
        b = int(b)
        if op == "?":
            break
        elif op == "+":
            print(a+b)
        elif op == "-":
            print(a-b)
        elif op == "*":
            print(a*b)
        elif op == "/":
            print(a//b)
        else:
            pass


if __name__ == '__main__':
    main()


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

const int INF = 1e9;

int main() {
  int n, t;
  cin>>n>>t;
  int prev_ti;
  cin>>prev_ti;
  long long ans = 0;
  for (int i=0; i<n-1; i++) {
    int ti;
    cin>>ti;
    if (prev_ti + t <= ti) {
      ans += t;
    } else {
      ans += ti - prev_ti;
    }
    prev_ti = ti;
  }
  cout<<ans+t<<endl;
}

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

int main() {
    int n; cin >> n;
    int M = -1, m = 1e9 + 10;
    for (int i=0; i<n; ++i) {
        int num; cin >> num;
        if (num > M) M = num;
        if (num < m) m = num;
    }
    cout << M - m << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>
#include <iomanip>

using namespace std;

int main()
{
	int n;
	
	cin >> n;
	vector <int > v(n);
	
	for (int i=0; i<n; i++) cin >> v[i];
	
	sort(v.begin(), v.end());
	
	cout << v[v.size()/2] - v[v.size()/2 - 1] <<endl;	
	
	
	
	
	
	return 0;
}



Measured memory_bytes: 640
#abc096b

a,b,c=map(int,raw_input().split())
k=int(raw_input())
mx=max(a,b,c)
if mx==a:
 print a*2**k+b+c
elif mx==b:
 print b*2**k+a+c
else:
 print c*2**k+a+b


Measured memory_bytes: 2568
#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>
 
using namespace std;
 
 
int main(int argc, const char * argv[]) {
 
    double r;
    
    cin >> r;
    
    printf("%.10f\n", 2*M_PI*r);
    
    return 0;
    
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n, m;
  cin >> n >> m;
  ll ans = min(n, m/2);
  n -= ans;
  m -= 2*ans;
  ans += m/4;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// ABC075A - 

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	int A, B, C;
	cin >> A >> B >> C;

	if (A == B) {
		cout << C << endl;
	} else if (B == C) {
		cout << A << endl;
	} else {
		cout << B << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    long n; cin >> n;
    long p[n];
    for(int i =0;i<n;i++){
        cin >> p[i];
    }
    long a[n];
    long b[n];
    long sum[n];
    for(int i=0;i<n;i++){
        a[i] = b[i] = sum[i] = 0;
    }
    for(int i = 0; i<n;i++){
        a[i] = 2 + 40000*i;
    }
    for(int i= 0; i<n;i++){
        int x = p[i]-1;
        sum[x] = 2 + a[n-1] + i;
    }
    for(int i = 0; i< n;i++ ){
        b[i] = sum[i] - a[i];
    }



    cout << a[0];
    for(int i = 1; i< n;i++){
        cout << " " << a[i];
    }
    cout << endl;
    cout << b[0];
    for(int i = 1; i< n;i++){
        cout << " " << b[i];
    }
    cout << endl;
}

Measured memory_bytes: 1280
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int n;
int a[N];
set < int > s;

int main(){
  cin >> n;
  for(int i = 1; i <= n; ++i){
    cin >> a[i];
    s.insert(a[i]);
  }
  if(sz(s) == 1){
    if(*s.begin() == n - 1 || *s.begin() * 2 <= n){
      cout << "Yes\n";
    } else{
      cout << "No\n";
    }
  } else if(sz(s) == 2){
    int c1 = count_if(a + 1, a + 1 + n, [&](int x){
      return x == *s.begin();
    });
    int c2 = count_if(a + 1, a + 1 + n, [&](int x){
      return x == *s.rbegin();
    });
    if(*s.begin() + 1 != *s.rbegin()){
      cout << "No\n";
      return 0;
    }
    if(!(c1 <= *s.begin() && c1 + c2 / 2 >= *s.rbegin())){
      cout << "No\n";
      return 0;
    }
    cout << "Yes\n";

  } else{
    cout << "No\n";
  }

  return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,n) for(ll i=0;i<n;i++)
#define fa(i,a,b) for(ll i=a;i<=b;i++)
#define fr(i,n) for(ll i=n-1;i>=0;i--)
#define endl "\n"
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ms(array,value) memset(array,value,sizeof(array))
#define test(t) ll t;cin>>t;while(t--)
#define en cout<<endl;
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define pb push_back
#define all(a) a.begin(),a.end()
#define pi pair<int,int>
#define mod2  998,244,353

int main()
{
    int k; cin>>k;
    ll sum=0;
    fa(i,1,k)
    {
        fa(j,1,k)
        {
            int x=__gcd(i,j);
            fa(l,1,k)
            {
                int y=__gcd(j,l);
                sum+=__gcd(x,y);
            }
        }
    }
    cout<<sum<<endl;

}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <set>
using namespace std;

int main(){

    string S;
    cin >> S;

    string t = S.substr(0,2);
    string u = S.substr(2,2);
    int n1 = stoi(t);
    int n2 = stoi(u);

    if(n1>=1 && n1<=12 && n2>=1 && n2 <=12) cout << "AMBIGUOUS" << endl;
    else if(n1>=1 && n1 <= 12) cout << "MMYY" << endl;
    else if(n2>=1 && n2 <=12) cout << "YYMM" << endl;
    else cout << "NA" << endl;
}

Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    return (a.second<b.second);
}

int main()
{
    ios;
    ll n,k;
    cin>>n>>k;
    int a[n];
    int c=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>=k)
            c++;
    }
    cout<<c<<endl;



}





Measured memory_bytes: 3944
'''
l = input().split()

l = list(map(int, l))
a,b,c = l[0],l[1],l[2]
'''
a,b,c = map(int, input().split())
if a > b:
	a,b = b,a

if b > c:
	b,c = c,b
	
if a > b:
	a,b = b,a
	
print(a,b,c)


Measured memory_bytes: 5612
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
inline int read()
{
	int f=0,x=1;char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')x=-1;ch=getchar();
	}
	while(ch>='0'&&ch<='9')f=(f<<1)+(f<<3)+ch-'0',ch=getchar();
	return f*x;
} 
int ans=0,b,k,f=0,zz=1;
char s[100009],ss[100009];
int main()
{
	scanf("%s",s+1);
	int l=strlen(s+1);
	//printf("%d\n",l);
	ss[zz]=s[1];
	for(int i=2;i<=l;i++)
	{
		if(s[i]!=ss[zz]&&zz!=0)zz--,ans+=2;
		else zz++,ss[zz]=s[i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
	int N =	sc.nextInt();
	int M =	sc.nextInt();
	int X =	sc.nextInt();
	int[] a	= new int[M];
	int pre	= 0;
	int fol	= 0;
        for(int i = 0; i<M; i++) {
            int	place =	sc.nextInt();
            if(place<X) pre++;
            else fol++;
        }
        System.out.println(Math.min(pre,fol));
    }
}

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

// Author: Ashish

int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin>>n>>m;
  vector<int> input(n);
  for(auto&itr:input) cin>>itr;
  int total=0;
	for(auto&itr:input) total+=itr;
	int required=total/(4*m)+(total%(4*m)!=0);
	int taken=0;
	for(auto&itr:input) taken+=itr>=required;
	if(taken>=m) cout<<"Yes";
	else cout<<"No";


 	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a;
    long long arr[200005];
    cin>>n>>a;
    long long x=n,max=0,y=0,i;
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
        y+=arr[i];
    }
    sort(arr,arr+n);
    if(a==0&&x-a==x)
      cout<<y<<endl;
    else if(a!=0&&x-a<=0)
      cout<<"0"<<endl;
    else
    {
          long p=x-a;
            for(int i=0;i<p;i++)
                  max+=arr[i];
          cout<<max<<endl;
    }



}


Measured memory_bytes: 1792
#include<queue>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof a)
#define  For(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define rFor(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
using namespace std;
typedef long long LL;
const int N=300010;
template<typename T>inline T chkmax(T _A,T _B){return _A>_B?_A:_B;}
template<typename T>inline T chkmin(T _A,T _B){return _A<_B?_A:_B;}
template<typename T>void read(T&x)
{
    x=0;int _f(0);char ch=getchar();
    while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
    while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x=_f?-x:x;
}
inline void file()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}
int n;
LL L[N],R[N],SumL[N],SumR[N],a[N],ans;
priority_queue<LL>Maxq;
priority_queue<LL,vector<LL>,greater<LL> >Minq;
int main()
{
	ans=-1e15;
	scanf("%d",&n);
	For(i,1,n*3)scanf("%lld",&a[i]);
	For(i,1,3*n)SumL[i]=SumL[i-1]+a[i];
	rFor(i,3*n,1)SumR[i]=SumR[i+1]+a[i];
	For(i,1,n)Minq.push(a[i]);
	For(i,n+1,2*n)
	{
		Minq.push(a[i]);
		L[i]=L[i-1]+Minq.top();
		Minq.pop();
	}
	rFor(i,3*n,2*n+1)Maxq.push(a[i]);
	rFor(i,2*n,n+1)
	{
		Maxq.push(a[i]);
		R[i]=R[i+1]+Maxq.top();
		Maxq.pop();
	}
	For(i,n,2*n)ans=chkmax(ans,(SumL[i]-L[i])-(SumR[i+1]-R[i+1]));
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 13556
#include <stdio.h>
#include <complex>
#include <iostream>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
typedef complex<double> P;
#define INF (1e100)
#define EPS (1e-12)

inline double cross(const P& a, const P& b) { return imag(conj(a)*b); }
inline double dot(const P& a, const P& b) { return real(conj(a)*b); }
inline P projection(const P& l0, const P& l1, const P& p) {
    const double t = dot(p-l0, l1-l0) / norm(l1-l0);
    return l0 + t*(l1-l0);
}
inline P reflection(const P& l0, const P& l1, const P& p) {
    return 2.0*projection(l0, l1, p) - p;
}
int ccw(const P& a, P b, P c) {
    b -= a; c -= a;
    if(cross(b, c)>0) return 1;
    if(cross(b, c)<0) return -1;
    if(dot(b, c)<0) return 2;
    if(norm(b)<norm(c)) return -2;
    return 0;
}
inline bool intersectSP(const P& s0, const P& s1, const P& p) {
    return abs(s0-p)+abs(s1-p)-abs(s1-s0)<EPS;
}
inline bool intersectSS(const P& s0, const P& s1, const P& t0, const P& t1) {
    return ccw(s0, s1, t0)*ccw(s0, s1, t1) <= 0
        && ccw(t0, t1, s0)*ccw(t0, t1, s1) <= 0;
}
inline P crosspoint(const P& l0, const P& l1, const P& m0, const P& m1) {
    const double A = cross(l1-l0, m1-m0);
    const double B = cross(l1-l0, l1-m0);
    if(abs(A)<EPS && abs(B)<EPS) return m0;
//    if(abs(A)<EPS) throw 0;
    return m0 + B/A * (m1-m0);
}

int n, ord[8];
P ps[8][8], qs[8][8], gl[8], st;

bool crossing_any(int d, P s, P t) {
    rep(i, n) {
        if(intersectSP(ps[d][i], qs[d][i], s)) continue;
        if(intersectSP(ps[d][i], qs[d][i], t)) continue;
        if(intersectSS(ps[d][i], qs[d][i], s, t)) return true;
    }
    return false;
}

double calc(int d) {
    P p = st;
    rep(i, d) {
        const int k = ord[i];
        if(!intersectSS(ps[i][k], qs[i][k], p, gl[d])) return INF;
        const P np = crosspoint(ps[i][k], qs[i][k], p, gl[d]);
        if(crossing_any(i, p, np)) return INF;
        p = np;
    }
    if(crossing_any(d, p, gl[d])) return INF;
    return abs(gl[d]-st);
}

double rec(int d, int pre) {
    double ans = calc(d);
    if(d<5) {
        rep(i, n) if(i!=pre) {
            ps[d+1][i] = ps[d][i];
            qs[d+1][i] = qs[d][i];
            rep(j, n) if(j!=i) {
                ps[d+1][j] = reflection(ps[d][i], qs[d][i], ps[d][j]);
                qs[d+1][j] = reflection(ps[d][i], qs[d][i], qs[d][j]);
            }
            gl[d+1] = reflection(ps[d][i], qs[d][i], gl[d]);
            ord[d] = i;
            ans = min(ans, rec(d+1, i));
        }
    }
    return ans;
}

int main() {
    for(;;) {
        scanf("%d", &n);
        if(n==0) return 0;
        int x, y;
        rep(i, n) {
            scanf("%d%d", &x, &y);
            ps[0][i] = P(x, y);
            scanf("%d%d", &x, &y);
            qs[0][i] = P(x, y);
        }
        scanf("%d%d", &x, &y);
        gl[0] = P(x, y);
        scanf("%d%d", &x, &y);
        st = P(x, y);
        const double ans = rec(0, -1);
        printf("%.9f\n", ans);
    }
}

Measured memory_bytes: 0
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,p] <- getIntList
    print . product . map (\(q,m) -> q ^ (m `div` n)) $ factorize p

f n k
  | n < k = n
  | n `mod` k == 0 = f (n `div` k) k
  | otherwise = f (n `mod` k) k

primes = map fromIntegral primes'
  where
    primes' = [2, 3, 5] ++ f 5 7 (drop 2 primes')
    f m s (p:ps) = [n | n <- ns, gcd m n == 1] ++ f (m * p) (p * p) ps
      where
        ns = [x + y | x <- [s,s + 6 .. p * p - 2], y <- [0, 4]]

factorize 1 = [(1, 0)]
factorize n = format $ factorize' n primes
  where
    format ps = [(x, length xs) | xs@(x:_) <- group ps]
    factorize' n ps@(p:ps')
      | p * p > n = [n]
      | rem n p == 0 = p : factorize' (div n p) ps
      | otherwise = factorize' n ps'

Measured memory_bytes: 3196
use std::collections::BinaryHeap;
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut heap = BinaryHeap::<i64>::new();
    for _i in 0..n {
        let v = read::<i64>();
        heap.push(v);
    }
    for _i in 0..m {
        let v = heap.pop().unwrap();
        heap.push(v / 2);
    }
    let mut ans = 0;
    for _i in 0..n {
        let v = heap.pop().unwrap();
        ans += v;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main(){
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double pi=3.141592653589793238462643383279;
  double time=60*h+m;
  double x1=2*pi*time/720;
  double x2=2*pi*m/60;
  double X=x1-x2;
  double l;
  
  l=sqrt(a*a+b*b-2*a*b*cos(X));
  cout << fixed << setprecision(20);
  cout << l << endl;
}

Measured memory_bytes: 4228
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long int
const int INF=0x3f3f3f3f;
int main()
{
	int	a,b;
	scanf("%d %d",&a,&b);
	double i=1;
	for(;i<=1500;i+=1.0){
		if((int)(i*0.08)==a&&(int)(i*0.1)==b){
			printf("%d\n",(int)i);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 128
from collections import deque
h,w = map(int,input().split())
grid = []
white = 0
grid.append(["#"]*(w+2))
for i in range(h):
    a = list(input())
    white += a.count(".")
    a.insert(0,"#")
    a.append("#")
    grid.append(a)
grid.append(["#"]*(w+2))

grid[1][1] = "1"

def bfs():
    q = deque([(1,1)])
    used = set()
    while q:
        here = q.popleft()
        num = int(grid[here[0]][here[1]])
        x = here[0]
        y = here[1]
        if grid[x-1][y] == "." and (x-1,y) not in used:
            grid[x-1][y] = str(num + 1)
            used.add((x-1,y))
            q.append((x-1,y))
        if grid[x+1][y] == "." and (x+1,y) not in used:
            grid[x+1][y] = str(num + 1)
            used.add((x+1,y))
            q.append((x+1,y))
        if grid[x][y-1] == "." and (x,y-1) not in used:
            grid[x][y-1] = str(num + 1)
            used.add((x,y-1))
            q.append((x,y-1))
        if grid[x][y+1] == "." and (x,y+1) not in used:
            grid[x][y+1] = str(num + 1)
            used.add((x,y+1))
            q.append((x,y+1))

bfs()
if grid[h][w] == ".":
    print(-1)
else:
    print(white-int(grid[h][w]))

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9 + 7;

int main(){
	int N; cin >> N;
	int a[N];
	for(int i=0; i<N; i++) cin >> a[i];
	int now = 0, ans = 1e9;
	for(int i=1; i<=N; i++){
		while(now < N && a[now] != i) now++;
		if(now >= N) break;
		if(ans > N - i) ans = N - i;
	}
	if(ans == 1e9) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin>>n>>k;
    ll s; cin>>s;
    ll ume;
    if (s==1e9) ume = 1e9-1;
    else ume = 1e9;
    rep(i,k) cout<<s<<" ";
    rep(i,n-k){
        if (i!=0) cout<<" ";
        cout<<ume;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
	
		cin>>a[i];
	}

	int s=1000000000;
	for(int i=0;i<100;i++){
	
		int temp=0;

		for(int j=0;j<n;j++){

			temp+=pow(a[j]-i,2);
		}
		if(temp<s){
		
			s=temp;
		}
	}
	cout<<s<<"\n";
	return 0;
}


Measured memory_bytes: 3588
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        if(n.charAt(0) == n.charAt(2)){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#define MAXN 210
#define INF 0x3f3f3f3f
using namespace std;

int R,C;
char a[MAXN][MAXN];

struct Cell {
  int r, c;
  Cell(int r, int c):r(r),c(c) {}
};

const int dr[] = {-1,1,0,0};
const int dc[] = {0,0,-1,1};
int d[MAXN][MAXN][2], vis[MAXN][MAXN][2];

queue<Cell> Q;
void bfs(int kind) {
  while(!Q.empty()) {
    Cell cell = Q.front(); Q.pop();
    int r = cell.r, c = cell.c;
    for(int dir = 0; dir < 4; dir++) {
      int nr = r + dr[dir], nc = c + dc[dir];
      if(nr >= 0 && nr < R && nc >= 0 && nc < C && a[nr][nc] == '.' && !vis[nr][nc][kind]) {
        Q.push(Cell(nr, nc));
        vis[nr][nc][kind] = 1;
        d[nr][nc][kind] = d[r][c][kind] + 1;
      }
    }
  }
}

int ans;
void check(int r, int c) {
  if(a[r][c] != '.' || !vis[r][c][0]) return;
  if(!vis[r][c][1] || d[r][c][0] < d[r][c][1]) ans = min(ans, d[r][c][0] + 1);
}

int main() {

    scanf("%d%d", &R, &C);
    int jr, jc;
    int tr,tc;
    vector<Cell> fires;
    for(int i = 0; i < R; i++) {
      scanf("%s", a[i]);
      for(int j = 0; j < C; j++)

      if(a[i][j]=='%')
      {
      	tr=i; tc=j; a[i][j]='.';
	  }
        else if(a[i][j] == '@') { jr = i; jc = j; a[i][j] = '.'; }
        else if(a[i][j] == '$') { fires.push_back(Cell(i,j)); a[i][j] = '.'; }
    }
    memset(vis, 0, sizeof(vis));
    vis[jr][jc][0] = 1; d[jr][jc][0] = 0;
    Q.push(Cell(jr, jc));
    bfs(0);
    for(int i = 0; i < fires.size(); i++) {
      vis[fires[i].r][fires[i].c][1] = 1;
      d[fires[i].r][fires[i].c][1] = 0;
      Q.push(fires[i]);
    }
    bfs(1);
    ans = INF;
    check(tr,tc);
    if(ans == INF) printf("No\n"); else printf("Yes\n");
  
  return 0;
}

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

int main() {
  int N;
  string S, T;
  cin >> N >> S >> T;

  rep(i, N) {
    cout << S[i] << T[i];
  }
  cout << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
 
#define INF (1e9)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int gcd(int a,int b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

int N;


int main()
{
	cin >> N;
	int X[N];
	vector<pair<int, int> > v;
	REP(i, N)
	{
		cin >> X[i];
		v.push_back(make_pair(X[i], i));
	}

	int B[N];

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

	REP(i,N){
		if(i<N/2){
			B[v[i].second] = v[N / 2].first;
		}else{
			B[v[i].second] = v[N / 2-1].first;
		}
	}

	REP(i,N){
		cout << B[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 5488
#include <iostream>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
using namespace std;

typedef complex<double> P;

const double EPS = 1e-8;

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

double dot(P a, P b) {
  return a.real()*b.real() + a.imag()*b.imag();
}

double norm(P a) {
  return dot(a, a);
}

double cross(P a, P b) {
  return a.real()*b.imag() - a.imag()*b.real();
}
int ccw(P p0, P a, P b) {
  a -= p0;
  b -= p0;
  if(cross(a, b) > EPS) return 1;
  if(cross(a, b) < -EPS) return -1;
  if(dot(a, b) < -EPS) return 2;
  if(norm(a) < norm(b)) return -2;
  return 0;
}

vector<P> convex_hull(vector<P> ps) {
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  vector<P> ch(2*n);
  for(int i = 0; i < n; ch[k++] = ps[i++])
    while(k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  for(int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--])
    while(k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  ch.resize(k-1);
  return ch;
}

bool isIntersect(P a1, P a2, P b1, P b2) {
  return ( ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0 &&
	   ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0);
}

bool isIn(vector<P> &g, P p) {
  int n = g.size();
  for(int i = 0; i < g.size(); ++i) {
    if(ccw(g[i], g[(i+1)%n], p) != 1) return false;
  }
  return true;
}

bool isIntersect(vector<P> &u, vector<P> &v) {
  int n = u.size();
  int m = v.size();
  for(int i = 0; i < u.size(); ++i) {
    for(int j = 0; j < v.size(); ++j) {
      if(isIntersect(u[i], u[(i+1)%n], v[j], v[(j+1)%m])) return true;
    }
  }
  for(int i = 0; i < u.size(); ++i) {
    if(isIn(v, u[i])) return true;
  }
  for(int j = 0; j < v.size(); ++j) {
    if(isIn(u, v[j])) return true;
  }
  return false;
}

bool solve(vector<P> &u, vector<P> &v) {
  u = convex_hull(u);
  v = convex_hull(v);
  return !isIntersect(u, v);
}

int main() {
  int n, m;
  while(cin >> n >> m && (n || m)) {
    vector<P> u, v;
    P p;
    for(int i = 0; i < n; ++i) {
      cin >> p.real() >> p.imag();
      u.push_back(p);
    }
    for(int i = 0; i < m; ++i) {
      cin >> p.real() >> p.imag();
      v.push_back(p);
    }
    if(solve(u, v)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int check(int a)
{
    int cnt = 0;
    while (a > 0)
    {
        a /= 10;
        cnt++;
    }
    if (cnt % 2 == 1)
        return 1;
    else
        return 0;
}

int N, ans;

int main()
{
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        ans += check(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int x = scan.nextInt();
		int[] m = new int[n];
		for (int i = 0; i < n; i++) {
			m[i] = scan.nextInt();
		}
		int min = 2000;
		for (int i = 0; i < n; i++) {
			if (m[i] < min) {
				min = m[i];
			}
		}
		int num = 0;
		for (int i = 0; i < n; i++) {
			x -= m[i];
		}
		num += n;
		x = x / min;
		num += x;
		System.out.println(num);
	}
}


Measured memory_bytes: 22612
<?php
$input = trim(fgets(STDIN));
$array = explode(" ", $input);
$W = $array[0];
$H = $array[1];
$x = $array[2];
$y = $array[3];
$r = $array[4];
if($r <= $x && $x <= ($W - $r) &&  $y <= ($H -$r) && $r <= $y){
    echo "Yes";
}else{
    echo "No";
}
?>

Measured memory_bytes: 15124