akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

//--> definitions
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=b-1;i>=a;i--)

//--> typedef
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<pii,int> piii;
typedef tuple<int,int,int> tiii;

#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define INF 1e9

const int maxN = 1e4+11;

int occs[26],occt[26];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
    
    string s,t;
    cin>>s>>t;
    
    int n=s.length();
    int m=t.length();
    int sol=m;
    FOR(i,0,n-m+1){
        int cnt=m;
        FOR(j,0,m){
            if(s[i+j] == t[j]){
                --cnt;
            }
        }
        sol=min(sol,cnt);
    }
    
    cout<<sol<<"\n";

	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s;
    ll k,cnt=0;
    cin >> s >> k;
    vector<ll> a;
    for(ll i=0;i<s.size();){
        ll j=i;
        while(j<s.size()&&s[i]==s[j]) j++;
        a.push_back(j-i);
        i=j;
    }
    for(ll i=1;i<a.size()-1;i++) cnt += a[i]/2;
    if(s[0]!=s[s.size()-1]) cout << (cnt+a[0]/2+a[a.size()-1]/2)*k << endl;
    else{
        if(a.size()==1) cout << (a[0]*k)/2 << endl;
        else cout << cnt*k+a[0]/2+a[a.size()-1]/2+((a[0]+a[a.size()-1])/2)*(k-1) << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
int main(){
  string s,key;
  cin>>s;
  key="keyence";
  for(int i=0;i<7;i++){
    bool f=true;
    for(int j=0;j<=i;j++){
      if(s[j]!=key[j]){
        f=false;
        break;
      }
      //cout<<s[j]<<"/"<<j<<" //";
    }
    int k=i+1;
    for(int j=s.size()-(7-i)+1;j<s.size();j++){
      //cout<<"::"<<s[j]<<" ";
      if(s[j]!=key[k]){
        f=false;
        break;
      }
      k++;
    }
    //cout<<endl;
    if(f){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
	int x,y;
	cin>>x>>y;
	char grid[50][50];
	int j;
	for(int i=0;i<x;i++)
	{
		for(j=0;j<y;j++)
		{	
			cin>>grid[i][j];
		}
	}
	for(int i=0;i<x;i++)
	{
		for(int j=0;j<y;j++)
		{
			if(grid[i][j]=='#')
			{
				if(grid[i-1][j]=='.'&&grid[i+1][j]=='.'&&grid[i][j-1]=='.'&&grid[i][j+1]=='.')
				{
					cout<<"No";return 0;
				}
			}
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int l=m;
	int r=n+m-1;
	int num=(n+2*m-1)*n/2;
	if(l>0) num-=l;
	else if(r<0) num-=r;
	cout<<num;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    // if ((x -= a.x) < 0) x += mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint nb_vec[100005];

int main() {
    cout << fixed << setprecision(10);
    
    int N, K; cin >> N >> K;

    mint ans = 0;
    // vector<ll> ans_vec(K+1);
    reprrev(i, 1, K+1) {
        mint t = K/i;
        nb_vec[i] = t.pow(ll(N));
        // cout << "i " << i << " " << nb_vec[i].x << endl;
        // int ti = t.x;
        for (int j=i*2; j<(K+1); j+=i) {
            // cout << "-j " << j << " " << nb_vec[j].x << endl;
            nb_vec[i] -= nb_vec[j];
        }
        // cout << "i " << i << " " << nb_vec[i].x << endl;
        ans += nb_vec[i] * i;
        // cout << ans.x << endl;
    }
    cout << ans.x << endl;
    
    return 0;
}

Measured memory_bytes: 4420
A = list(map(int, input().split()))
res = 0
if A[0] == 0:
    print(1)
if A[1] == 0:
    print(2)
if A[2] == 0:
    print(3)
if A[3] == 0:
    print(4)
if A[4] == 0:
    print(5)

Measured memory_bytes: 9120
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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

	int A[200100];
	for (int i=1; i<=N; i++) {
		A[i] = 0;
	}
	for (int i=2; i<=N; i++) {
		int a;
		cin >> a;
		A[a] += 1;
	}
	for (int i=1; i<=N; i++) {
		cout << A[i] << endl;
	}
}

Measured memory_bytes: 4416
H = int(input())

keys = input().split()

for i, x in enumerate(keys):
    h_i = i + 1
    print('node {0}: '.format(h_i), end = '')
    print('key = {0}, '.format(keys[i]), end = '')
    if h_i != 1:
        print('parent key = {0}, '.format(keys[h_i // 2 - 1]), end = '')
    left_index = h_i * 2
    if left_index <= H:
        print('left key = {0}, '.format(keys[left_index - 1]), end = '')
    right_index = left_index + 1
    if right_index <= H:
        print('right key = {0}, '.format(keys[right_index - 1]), end = '')
    print('')

Measured memory_bytes: 7724
#include <iostream>
#include <math.h>
#include <regex>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    string s; cin >> s;
    ll n = s.size();
    ll cnt = 0;
    rep(i,n){
        if(s[i] == 'g'){
            cnt++;
        }else{
            cnt--;
        }
    }
    cout << cnt/2 << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<math.h>
#define L(_i,_N) for(int _i=0;_i<_N;_i++)
#define C(_Dis) cout<<_Dis<<endl

using namespace std;

typedef long long int lli;

int main() {
	int A, B;
	cin >> A >> B;
	cout << (A + B) % 24 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long sum;
long long cnt;
int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i ++){
		int x;
		long long y;
		cin >> x >> y;
		sum += x * y;
		cnt += y;
	}
	if(sum >= 10){
		sum -= 1;
		sum /= 9;
		sum += (cnt - 1); 
	}
	else{
		sum = cnt - 1;
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <sstream>
using namespace std;
int main(){
	string n,s;
	cin>> n;
	int q=0;
	while (cin>> s){
		for (int i=0;i<s.size();i++){
			if (s[i]<97){
				s[i]=s[i]+32;
			}
		}
		if (s==n){
			q++;
		}
	}
	cout<< q<< endl;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    for(int i = 0; i < a + 1; i++){
        for(int j = 0; j < a + 1 - i; j++){
            for(int k = 0; k < a + 1 - i - j; k++){
                if(10000 * k + 5000 * j + 1000 * i == b && i + j + k == a){
                cout << k << " " << j << " " << i << endl; 
                return 0;
                }
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N),B(N),C(N);
  for(int i = 0;i < N;i++){
    cin >> A[i];
  }
  for(int i = 0;i < N;i++){
    cin >> B[i];
  }
  for(int i = 0;i < N - 1;i++){
    cin >> C[i];
  }

  int total = 0;
  for(int i = 0;i < N;i++){
    total += B[i];
    if(A[i + 1] - 1 == A[i] && i < N-1){
      total += C[A[i] - 1];
    }
  }
  cout << total;
}

Measured memory_bytes: 256
#include <stdio.h>

int p, q, a, n;

int search(int p, int q, int a, int n, int x) {
	int count = 0, i;

	if (p == 0) {
		return 1;
	}
	if (n <= 0) {
		return 0;
	}

	for (i = x; i <= a; i++) {
		if (q <= i * p) {
			count += search(p * i - q, q * i, a / i, n - 1, i);
		}
	}
	return count;
}


int main(void) {
	while (1) {
		int count = 0;
		scanf("%d %d %d %d", &p, &q, &a, &n);

		if (p == 0 && q == 0 && a == 0 && n == 0) {
			break;
		}

		count = search(p, q, a, n, 1);
		printf("%d\n", count);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    string S;
    cin >> S;
    int length = 0;
    int A_length = 0;
    if(S.size() > 9){
        cout << "NO" << endl;
        return 0;
    }
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'K' && length == 0){
            length++;
            A_length = 0;
        }else if(S[i] == 'I' && length == 1){
            length++;
            A_length = 0;
        }else if(S[i] == 'H' && length == 2){
            length++;
            A_length = 0;
        }else if(S[i] == 'B' && length == 3){
            length++;
            A_length = 0;
        }else if(S[i] == 'R' && length == 4){
            cout << "YES" << endl;
            return 0;
        }else if(S[i] != 'A' || (S[i] == 'A' && (length == 1 || length == 2 || A_length == 1))){
            cout << "NO" << endl;
            return 0;
        }else{
            A_length++;
        }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	char str[100];
	int year, month, day;
	int omomi = 1000;
	int i, j, k;

	year = month = day = 0;
	scanf("%s", str);
	for (i = 0; str[i] != '/'; i++) {
		
		year += (str[i] - 0x30) * omomi;
		omomi /= 10;
	}
	omomi = 10;
	for (j = i + 1; str[j] != '/'; j++) {
		
		month += (str[j] - 0x30)*omomi;
		omomi /= 10;
	}
	omomi = 10;
	for (k = j + 1; str[k] != '\0'; k++) {
		
		day += (str[k] - 0x30)*omomi;
		omomi /= 10;
	}
	//printf("%d %d %d\n", year, month, day);
	if (year <= 2019 && month <= 4 && day <= 30) {
		printf("Heisei\n");
	}
	else {
		printf("TBD\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int f[10010];
int main(){
    int n,i,j,M=10000,x;
    scanf("%d",&n);f[0]=1;
    for(i=1;i<=n;i++){
        scanf("%d",&x);
        for(j=M;j>=x;j--) f[j]|=f[j-x];
    }
    for(j=M;j>=1;j--) if(f[j]&&j%10) break;
    printf("%d",j);
    return 0;
}


Measured memory_bytes: 256
/* I have already deleted My old account because somebody stole my code
and i have no idea how. If you are copying this code atleast make it look different 
Yours Faithfully
Shobhit Yadav */

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

int N;
/*ll freq[200005];*/
void solve(){
	 /*memset(freq,0,sizeof(freq));*/
	cin>>N;
	bool flag = false;
	ll val;
    
if(N<10)
	cout<<"Yes"<<'\n';

 else{
  	for(ll i = 9 ; i>=2 ; i--){
  		if(N%i == 0){
         val = N/i;
         if(val<=9){
         	flag = true;
         	break;
         }
  		}
  	}


  	if(flag)
  		cout<<"Yes"<<'\n';

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


	
}



int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
   solve();

	return 0;
}

Measured memory_bytes: 3644
n = int(input())
p_list = list(map(int,input().split()))
count = 0

for i in range(1,n-1):
    if p_list[i-1] == p_list[i] < p_list[i+1] or p_list[i] == p_list[i+1] < p_list[i-1]:
        cout += 1
    if p_list[i-1] < p_list[i] < p_list[i+1] or p_list[i+1] < p_list[i] < p_list[i-1]:
        count += 1

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
pair<int, int> robots[101010];
int dp[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) {
		int x, l;
		cin >> x >> l;
		robots[i] = { x + l, l };
	}
	sort(robots, robots + N);

	rep(i, 0, N) {
		chmax(dp[i + 1], dp[i]);
		
		int x = robots[i].first - robots[i].second;
		int l = robots[i].second;

		auto ite = lower_bound(robots, robots + N, make_pair(x - l, inf));
		int pre = ite - robots;
		chmax(dp[i + 1], dp[pre] + 1);
	}

	cout << dp[N] << endl;
}







Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>


using namespace std;

int a[100005] = {}, b[100005] = {};
int g[100005] = {}, h[100005] = {};;
int main() {

	int n;
	
	cin >> n;
	int w = 0, v = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i]; w = max(w, a[i]);
	}
	for (int j = 0; j < n; j++) {
		cin >> b[j]; v = max(v, b[j]);
	}
	
	g[0] = 1;
	for (int i = 1; i < n; i++) {
		if (a[i - 1] != a[i])g[i] = 1;
		else g[i] = a[i];
		//cout << g[i] << endl;
	}
	//cout << endl;
	h[n - 1] = 1;
	for (int i = n - 2; i >= 0; i--) {
		if (b[i + 1] != b[i])h[i] = 1;
		else h[i] = b[i];
		//cout << h[i] << endl;
	}
	//cout << endl;
	long long int ans = 1;
	if (w != v)ans = 0;
	if (b[0] != a[n - 1])ans = 0;
	for (int i = 0; i < n; i++) {
		if (g[i] == 1 && a[i] > b[i])ans = 0;

		int p = min(h[i], g[i]);
		//cout << p << endl;
		ans *= p;
		ans %= 1000000007;

	}
	cout << ans << endl;

	return 0;

}




Measured memory_bytes: 1792
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
S = list(input())
a, b = 0, 0
for s in S:
    if s=='c':
        print('No')
        continue
    if s=='a':
        if a+b<A+B:
            print('Yes')
            a += 1
        else:
            print('No')
    else:
        if a+b<A+B and b<B:
            print('Yes')
            b += 1
        else:
            print('No')

Measured memory_bytes: 79688
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n, a[100000];
vector<pair<int, int>> ans;

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	sort(a, a + n);
	
	
	incID(i, 1, n - 1) {
		if(a[i] < 0) {
			ans.EB(a[n - 1], a[i]);
			a[n - 1] -= a[i];
		} else {
			ans.EB(a[0], a[i]);
			a[0] -= a[i];
		}
	}
	ans.EB(a[n - 1], a[0]);
	a[n - 1] -= a[0];
	
	cout << a[n - 1] << endl;
	RF(e, ans) { cout << e.FI << " " << e.SE << "\n"; }
	
	return 0;
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;

#define MAX_N 1002020

typedef long long int64;

const int64 mod = 1e9 + 7;

inline int64 extgcd(int64 a, int64 b, int64 &x, int64 &y)
{
  int64 d = a;
  if(b != 0) d = extgcd(b, a % b, y, x), y -= (a / b) * x;
  else x = 1, y = 0;
  return d;
}

inline int64 modPow(int64 x, int64 n)
{
  if(n == 0) return 1;
  int64 ret = modPow(x, n/2);
  (ret *= ret) %= mod;
  if(n & 1) (ret *= x) %= mod;
  return ret;
}

inline int64 modInv(int64 a)
{
  return modPow(a, mod - 2);
}

inline int64 modFact(int n)
{
  int64 ret = 1;
  while(n > 1) (ret *= n--) %= mod;
  return ret;
}

inline int64 modComb(int64 n, int64 r)
{
  static int64 fact[MAX_N], invfact[MAX_N];
  if(fact[0] == 0) {
    fact[0] = invfact[0] = 1;
    for(int i = 1; i < MAX_N; i++) {
      fact[i] = fact[i-1] * i % mod;
      invfact[i] = modInv(fact[i]);
    }
  }
  if(r < 0 || n < r) return 0;
  return fact[n] * invfact[r] % mod * invfact[n-r] % mod;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int h, w, a, b;
  cin >> h >> w >> a >> b;
  int ans = 0;
  reps(i, b, w) {
    int x = modComb(i+h-a-1, i) % mod;
    int y = modComb(w-i-1+a-1, a-1) % mod;
    (ans += (x*y)%mod) %= mod;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 15872
N = int(input())
for n in range(1, 3501):
    for w in range(n, 3501):

        try:
            t = (N*n*w) % (4*n*w - N*w - N*n)
        except:
            continue

        if t == 0 and 4*n*w - N*w - N*n>=0:
            print((N*n*w) // (4*n*w - N*w - N*n), n, w)
            exit()


Measured memory_bytes: 40556
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
/////////////////////////////////
int main(){
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n-1);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n-1) cin >> c[i];
    int ans = 0;
    rep(i,n){
        ans += b[a[i]-1];
        if(i!=0){
            if(a[i]-1==a[i-1]){
                ans += c[a[i-1]-1];
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3604
Module AtCoder166
  
    Sub Main(args As String())

        Dim arr As String() = Split(Console.ReadLine())
        Dim tenboidai_Count As Integer = CInt(arr(0))
        Dim way_Count As Integer = CInt(arr(1))

        '展望台の高さリスト
        Dim tenboidai_height_List As List(Of Integer) = New List(Of Integer)()
        '展望台別の繋がっている展望台リストのディクショナリ
        Dim tenboidai_way_Dic As Dictionary(Of Integer, List(Of Integer)) = New Dictionary(Of Integer, List(Of Integer))()
        Dim arr_height As String() = Split(Console.ReadLine())
        For i As Integer = 1 To tenboidai_Count
            '標高代入
            tenboidai_height_List.Add(CInt(arr_height(i - 1)))
            '道ディクショナリ初期化
            tenboidai_way_Dic.Add(i, New List(Of Integer)())
        Next

        '繋がっている展望台の組合せ
        For j As Integer = 1 To way_Count
            Dim arr_way As String() = Split(Console.ReadLine())
            Dim pointA As Integer = CInt(arr_way(0))
            Dim pointB As Integer = CInt(arr_way(1))
            '道ディクショナリ代入
            Dim listA As List(Of Integer) = tenboidai_way_Dic(pointA)
            listA.Add(pointB)
            tenboidai_way_Dic(pointA) = listA
            Dim listB As List(Of Integer) = tenboidai_way_Dic(pointB)
            listB.Add(pointA)
            tenboidai_way_Dic(pointB) = listB
        Next

        'よい展望台判定
        Dim ret As Integer = 0
        For k As Integer = 1 To tenboidai_Count
            Dim way_list As List(Of Integer) = tenboidai_way_Dic(k)
            '道なし
            If way_list.Count = 0 Then
                ret = ret + 1
                Continue For
            End If
            '道あり
            Dim height_side As List(Of Integer) = New List(Of Integer)()
            For m As Integer = 1 To way_list.Count
                height_side.Add(tenboidai_height_List(way_list.Item(m - 1) - 1))
            Next
            Dim higtest As Integer = height_side.Max()
            If tenboidai_height_List.Item(k - 1) > higtest Then ret = ret + 1
        Next

        Console.WriteLine(ret.ToString())

    End Sub

End Module

Measured memory_bytes: 160908
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<unsigned char, unsigned char> pcc;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> matrix;

int loc[501];
int ret[501*501];

void die() {
  cout << "No\n";
  exit(0);
}

void solve() {
  int n;
  cin >> n;
  for(int i = 0; i < n*n; i++) ret[i] = -1;
  vector<pii> v;
  for(int i = 0; i < n; i++) {
    cin >> loc[i];
    loc[i]--;
    ret[loc[i]] = i;
    v.push_back({loc[i], i});
  }
  sort(v.begin(), v.end());
  map<int, int> left;
  for(int i = 1; i < n; i++) left[i] = i;
  for(int i = 0; i < n*n; i++) {
    if(ret[i] >= 0) {
      if(left.count(ret[i])) {
        die();
      }
      if(ret[i] != n-1) left[ret[i]] = n-1-ret[i];
      v.push_back(v[0]);
      v.erase(v.begin());
      continue;
    }
    int use = -1;
    for(pii out: v) {
      if(left.count(out.second)) {
        use = out.second;
        break;
      }
    }
    if(use < 0) die();
    if(--left[use] == 0) left.erase(use);
    ret[i] = use;
  }
  cout << "Yes\n";
  for(int i = 0; i < n*n; i++) {
    cout << ++ret[i];
    if(i == n*n-1) cout << "\n";
    else cout << " ";
  }
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ":" << "\n";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


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

int main() {
  int n;
  cin >> n;
  std::vector<int> vec(n);
  rep(i,n) cin >> vec.at(i);
  int ans = 0, cnt = 0;
  rep(i,n-1) {
    if (vec.at(i) >= vec.at(i+1)) {
      cnt++;
      ans = max(ans,cnt);
      continue;
    }
    cnt = 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3784
#include <iostream>
int main()
{
    unsigned long long n = 0;
    unsigned long long h = 0;
    unsigned long long m = 1;
    scanf("%llu", &h);
    while (true) {
        if (h == 0)
            break;
        n += m;
        m = m * 2;
        h = h / 2;
    }
    printf("%llu", n);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
int main() {
    
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    vector<int> ans;
    ll sum = 0;
    ans.resize(n);
    for(int i = 0 ; i < n ; i++)
    {
        cin >> ans[i];
    }
    sort(ans.rbegin(),ans.rend());
    
    for(int i = k ; i < n ; i++)
    {
        sum+=ans[i];
    }
    cout << sum ;
}   


Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
    if a not in d:
        d[a] = 0
    d[a] += 1
total = 0
for k, v in d.items():
    if v >= 2:
        total += int(v * (v-1) / 2)

for a in A:
    v = d[a]
    ans = total - int(v * (v-1) / 2)
    v -= 1
    if v >= 2:
        ans += int(v * (v-1) / 2)
    print(ans)

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll m;
  cin >> m;
  vl A(n);
  vl HA(n);
  rep(i, 0, n) {
    cin >> A[i];
    HA[i] = A[i] / 2ll;
  }

  ll lcm = 1ll;
  rep(i, 0, n) {
    ll g = __gcd(lcm , HA[i]);
    lcm = (HA[i] * lcm / g);
  }

  if (lcm > m) {
    cout << 0 << endl;
    return 0;
  }

  bool flag = true;
  rep(i, 0, n) {
    if ((lcm / HA[i]) % 2ll == 0ll) {
      flag = false;
      break;
    }
  }

  if (flag) {
    ll ans = m / lcm;
    cout << (ans+1ll)/2ll << endl;
  } else {
    cout << 0 << endl;
  }


  return 0;
};


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
bool aaa[11111111];
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}


int main() {
  int a;
  ll k,x,y,m,memo=1,sx=1,sy=1,gx,gy;
  string ka,ss;
  ll n,ans=0;
  cin>>n;
  ans+=(n%500)-(n%5);
  ans+=(n-(n%500))*2;
  cout<<ans<<endl;
  
  
  
  //cout<<dp[x-1][y-1]<<endl;

  //vector<vector<bool>> sinsetsu(15,vector<bool>(14)),usotsuki(15,vector<bool>(14));
  //vector<vector<int>> sss(15,vector<int>(14))
  //vector<vector<int>> sss(h,vector<int>(w));
  //vector<int> a(k),b(k);
  //char x;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<cassert>
#define fr first
#define sc second
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 998244353;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P> PP;

vector<int>G[1005];
int a[2006], b[2006];
int g[1005][1005];

bool vst[1006],fin[1006];
stack<int>st;
int pos2 = -1;

void dfs(int now) {
	vst[now]= true;
	st.push(now);
	for(int i:G[now]){
		if (fin[i])continue;
		if (vst[i]) {
			pos2 = i; return;
		}
		dfs(i);
		if (pos2 != -1)return;
	}
	st.pop();
	fin[now] = true;
}
vector<int>cycle(int start) {
	dfs(start);
	vector<int>cycle;
	while (st.size()) {
		int t = st.top(); st.pop();
		cycle.push_back(t);
		if (t == pos2)break;
	}
	return cycle;
}


signed main() {
	int n, m; cin >> n >> m;
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		G[a[i]].push_back(b[i]);
		g[a[i]][b[i]]++;
	}

	fill(vst, vst + n, false);
	fill(fin, fin + n, false);
	vector<int>v;
	rep(i, n) {
		if (!vst[i]&&!v.size()) {
			v = cycle(i);
		}
	}
	int s = v.size();
	if (s == 0) {
		cout << -1 << endl; return 0;
	}

	reverse(v.begin(), v.end());
	int l, r; int dis = inf;
	rep(i, s) {
		rep(j, s) {
			if (g[v[j]][v[i]] && dis > (j - i + s) % s) {
				l = i; r = j;
				dis = (j - i + s) % s;
			}
		}
	}
	cout << dis + 1 << endl;
	if (l < r) {
		for (int i = l; i <= r; i++)cout << v[i] + 1 << endl;
	}
	else {
		for (int i = l; i <= r + s; i++)cout << v[i%s]+1 << endl;
	
	}
}

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

int main(void) {
	long long X; cin >> X;

	long long money = 100;
	long long ans = 0;
	while (money < X) {
		money += (money / 100);
		ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3544
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using Graph = vector<vector<int>>;

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pi = pair<int, int>;

//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(), (a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF (int)1e9
#define INFL (long long)1e18
#define MOD (int)(1e9+7) 

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//template 
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}
template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}
template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}
template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
template<typename T>
string join(vector<T>& vec, string sep = " "){
  stringstream ss;
  for(int i=0; i<vec.size(); i++){
    ss << vec[i] << ( i+1 == vec.size() ? "" : sep );
  }
  return ss.str();
}

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 (a > b) { a = b; return 1; }
	return 0;
}

template< typename T = ll >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}
template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

int main()
{
  	int k, n;
  	cin >> k >> n;
  	auto v = make_v<int>(n);
  	cin >> v;
    vi dis;
    REPS(i, n-1){
        dis.push_back(v[i]-v[i-1]);
    }
    dis.push_back(k-v[n-1]+v[0]);
  	sort(RAll(dis));
  	cout << k-dis[0] << endl;
    return 0;
}


Measured memory_bytes: 2168
import java.util.Scanner;

class Main
{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		
		int d;
		int r;
		double f;
		
		d = a / b;
		r = a % b;
		f = (double)a / (double)b;
		
		System.out.println(d+" "+r+" "+String.format("%.5f", f));
	}
}


Measured memory_bytes: 26464
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    string s;
    map<string, int> mp;
    rep(i,n){
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    ll ans = 0;
    for (auto &u : mp){
        int cnt = u.second;
        ans += (ll)cnt*(cnt-1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

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

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

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

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

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

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

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

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

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

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

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

void debug_out() { cerr << endl; }

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

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
    char a; cin >> a;
  	if(a >='A' && a <= 'Z') cout << "A" << endl;
  	else cout << "a" << endl;
}


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

typedef long long ll;

int phi(int n) {
	int result=n;
	for (int i=2; i*i<=n; i++) {
		if(n%i==0) result-=result/i;
		while(n%i==0) n/=i;
	}
	if(n>1) result-=result/n;
	return result;
}

// (a^b)%m
ll exp(ll a, ll b, ll m) {
	ll r=1;
	while(b) {
		if(b%2) r=(r*a)%m;
		a=(a*a)%m;
		b/=2;
	}
	return r;
}

// a^-1 %m, any m
ll inv(ll a, ll m) {
	return exp(a, phi(m)-1, m);
}

// a^-1 %m, prime m
ll invp(ll a, ll m) {
	return exp(a, m-2, m);
}

// (a*b)%m
ll mul(ll a, ll b, ll m) {
	ll x=0, y=a%m;
	while(b>0) {
		if(b%2) x=(x+y)%m;
		y=(y*2)%m;
		b/=2;
	}
  return x%m;
}

// (a+b)%m
ll add(ll a, ll b, ll m) {
	return (a+b)%m;
}

const int mx=1e6+5;
const int mod=998244353;

ll fact[mx];

ll combi(int n, int x, ll m) {
	ll p=fact[n], q=fact[x], r=fact[n-x];
	ll ret=p;
	ret=(ret*invp(q,m))%m;
	ret=(ret*invp(r,m))%m;
	return ret;
}

bool isprime(int n) {
	if(n==1) return false;
	for (int i=2; i*i<=n; i++)
		if(n%i==0) return false;
	return true;
}

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

int main() {
	fact[0]=1;
	for (int i=1; i<mx; i++)
		fact[i]=(fact[i-1]*i)%mod;
	ll N,M,K; cin>>N>>M>>K;
	ll ret=0;
	for (ll x=0; x<=K; x++) {
		ll cur=combi(N-1,x,mod);
		cur=(cur*M)%mod;
		cur=(cur*exp(M-1,N-1-x,mod))%mod;
		ret=(ret+cur)%mod;
	}
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 11452
import java.util.*;

public class Main {
	static class Position {
		int y,x;
		int dis;
		public Position(int y, int x, int dis) {
			this.y = y;
			this.x = x;
			this.dis = dis;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] A = new char[H][];
		for(int i=0; i<H; i++)
			A[i] = sc.next().toCharArray();
		
		boolean[][] queued = new boolean[H][W];
		boolean[][] visited = new boolean[H][W];
		ArrayList<Position> que = new ArrayList<>();
		int cur = 0;
		for(int i=0; i<H; i++) {
			for(int j=0; j<W; j++) {
				if(A[i][j] == '#') {
					que.add(new Position(i, j, 0));
					queued[i][j] = true;
				}
			}
		}
		
		int cnt = 0;
		
		final int[] dx = {1, 0, -1, 0};
		final int[] dy = {0, 1, 0, -1};
		
		int max = 0;
		while(cnt < H*W) {
			Position p = que.get(cur);
			if(!visited[p.y][p.x]) {
				for(int d=0; d<4; d++) {
					int ny = p.y + dy[d];
					int nx = p.x + dx[d];
					if(0<=ny && ny<H && 0<=nx && nx<W && !queued[ny][nx]) {
						que.add(new Position(ny, nx, p.dis+1));
						queued[ny][nx] = true;
					}
				}
				visited[p.y][p.x] = true;
				cnt++;
				max = p.dis;
			}
			cur++;
		}
		
		System.out.println(max);
		sc.close();
	}
}



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

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

signed main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>> a(h, vector<char>(w));
	int cnt = 0;
	queue<pair<int, int>> que, next_que;
	int sharp = 0, rest = h * w;

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			cin >> a[i][j];
			if (a[i][j] == '#') {
				next_que.push(make_pair(i, j));
				sharp++;
			}
		}
	}

	rest -= sharp;
	
	while (rest) {
		que = next_que;
		while (!next_que.empty()) next_que.pop();
		while (!que.empty()) {
			pair<int, int> u;
			u = que.front();
			que.pop();
			int i = u.first, j = u.second;
			for (int k = 0; k < 4; ++k) {
				if (i + dx[k] >= 0 and i + dx[k] < h and j + dy[k] >= 0 and j + dy[k] < w) {
					if (a[i + dx[k]][j + dy[k]] == '.') {
						a[i + dx[k]][j + dy[k]] = '#';
						rest--;
						next_que.push(make_pair(i + dx[k], j + dy[k]));
					}
				}
			}
		}
		cnt++;
	}

	cout << cnt << endl;
}


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

using namespace std;

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args)
	{
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
		__f(comma+1, args...);
	}
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"
#define PI acos(-1)

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

int main()
{
	FAST_IO;

 	ld a, b, h, m;
 	cin >> a >> b >> h >> m;
 	ld ang1 = 30.000 * h + m / 2.0000;
 	ld ang2 = 6.000 * m;
 	ld ang = abs(ang1 - ang2);
 	ang = (ang * PI) / 180.000;
 	ld res = a * a + b * b;
 	res -= 2 * a * b * cos(ang);
 	cout << fixed << setprecision(15) << sqrt(res) << endl;
    return 0;
}

Measured memory_bytes: 4184
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
    int l[10],v1,v2;
    while(scanf("%d",&l[0])!=EOF){
        for(int i=1;i<10;i++)scanf(",%d",&l[i]);
        scanf(",%d,%d",&v1,&v2);
        int sum=0;
        for(int i=0;i<10;i++)sum+=l[i];
        double x=(double)sum/(v1+v2);
        x*=v1;
        int ite=0;
        while(true){
            x-=l[ite];
            if(x<=0){
                cout<<ite+1<<endl;
                break;
            }
            ite++;
        }
    }
    return 0;
}

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

int main(){
  	int n,count = 0;
  	char c;
  	string s;
	cin >> n;
  	cin >> s;
  	if(n % 2 != 0)
    {
    	cout << "No" << endl;
        return 0;
    }
  	for(int i = 0; i < n/2; i++){
    	if(s.substr(i,1) == s.substr(n/2 + i,1)){
          	++count;
        	if((n/2) - 1 == count){
            	break;
            }
        }
      	else{
          	cout << "No" << endl;
        	return 0;
        }
    }
  	cout << "Yes" << endl;
	return 0;
}

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

int main() {
    int n, x, y;
    cin >> n >> x >> y;

    vector<vector<int>> tree(n);
    for (int i=1; i<n-1; i++) {
        tree.at(i).push_back(i+1);
        tree.at(i).push_back(i-1);
    }
    tree.at(0).push_back(1);
    tree.at(n-1).push_back(n-2);
    tree.at(x-1).push_back(y-1);
    tree.at(y-1).push_back(x-1);

    vector<int> ans(n-1, 0);

    for (int i=0; i<n; i++) {
        vector<int> c(n, -1);
        c.at(i) = 0;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            int now = q.front();
            q.pop();
            for (int h=0; h<tree.at(now).size(); h++) {
                if (c.at(tree.at(now).at(h)) == -1) {
                    c.at(tree.at(now).at(h)) = c.at(now) + 1;
                    q.push(tree.at(now).at(h));
                    ans.at(c.at(now))++;
                }
            }
        }
    }

    for (int i=0; i<n-1; i++) {
        cout << ans.at(i) / 2 << endl;
    }
}

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

using namespace std;
int main(){
    int n;
    cin >>n;
    string s;
    cin >> s;
    bool flag = false;
    int cnt = 0;
    rep(i,n){

        if(s[i]=='x'){
            if(flag) break;
            else flag = true;
        }else{
            flag = false;
        }
        cnt += 1;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3308
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[100010];
    rep(i, N) cin >> a[i + 1];
    int cnt = 0;
    int on = 1;
    while(cnt <= N) {
        on = a[on];
        cnt++;
        if (on == 2) {
            cout << cnt << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header
int main() {
	int n, k, sum=0;
	cin >> n >> k;
	vector<int> p(n);
	rep(i,n) cin >> p[i];
	sort(all(p));
	rep(i,k){
		sum+=p[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3624
import math
X = int(input())
a1 = math.ceil(X**(1/5))
N = int(1e10)
c = 0
b = 0
while c <= N:
    if b**5 < -X:
        b2 = b + 1
        break
    b -= 1
c = 0
while c <= N:
    c += 1
    b1 = math.floor((a1**5-X)**(1/5))
    a2 = math.floor((X+b2**5)**(1/5))
    if a1**5 - b1**5 == X:
        print(a1, b1)
        break
    elif a2**5 - b2**5 == X:
        print(a2, b2)
        break
    a1 += 1
    b2 += 1

Measured memory_bytes: 9472
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
 
int main(){
    int n;
    cin>>n;
    vector<long> a(n),b(n),c(n);
    for (int i=0; i<n; i++){
        cin>>a[i];
    }
    for (int i=0; i<n; i++){
        cin>>b[i];
    }
    for (int i=0; i<n; i++){
        cin>>c[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    long long ans=0;
    for (int i=0; i<n; i++){
        long x=lower_bound(a.begin(),a.end(),b[i])-a.begin();
        long y=c.end()-upper_bound(c.begin(),c.end(),b[i]);
        //y=c.size()-y;
        ans+=x*y;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2560
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


const int INF = 1e9 + 7;
int _;

int main() {
	INIT
	int n, m;
	cin >> n >> m;
	VI A(n + 1);
	ll sum = 0;
	rep (i, 1, n + 1) {
		cin >> A[i];
		sum += 1ll * A[i];
	}
	sort(A.begin() + 1, A.end(), greater<int>());
	//cout << 4 * m * A[m] << ' ' << sum << endl;
	if (4 * m * A[m] >= sum) {
		cout << "Yes";
	}   else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256