akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <string>
#include <cstring>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <memory>

//#pragma comment(linker, "/STACK:16777216")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt,tune=native")

using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define ull unsigned long long
//#define double long double
//#define int ll
//#define int ull
//#define int short
//#define int unsigned short
//#define int unsigned int
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define pdd pair<double, double>
#define pid pair<int, double>
#define pdi pair<double, int>
#define hash hash228
const int SZ = 5e5 + 4;
const double EPS = 1e-7;
const int mod = 998244353;
const int hashpow = 2;
const int inf = 2e9;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int h1, m1, h2, m2, k;

inline void read() {
    cin >> h1 >> m1 >> h2 >> m2 >> k;
}

inline void solve() {
    int x = (h2 * 60 + m2 - h1 * 60 - m1 + 2 * 24 * 60) % (24 * 60);
    cout << max(x - k, 0) << "\n";
}

signed main() {

#ifdef __LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

//    int t;
//    cin >> t;
//    for (int i = 0; i < t; ++i) {
    read();
    solve();
//    }

    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N=20202;
int x[N]={};

int main()
{
    int n,m,t;
    cin >>n >>m >>t;

    rep(i,n)
    {
        int a;
        cin >>a;
        ++x[a-m];
        --x[a+m];
    }

    rep(i,N-1) x[i+1]+=x[i];

    int ans = 0;
    rep(i,t) ans+=(x[i]==0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3164
#include<iostream>
using namespace std;
#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

void preParse(int u) {
	if (u == NIL) return;
	cout << " " << u;
	preParse(T[u].l);
	preParse(T[u].r);
}

void inParse(int u) {
	if (u == NIL) return;
	inParse(T[u].l);
	cout << " " << u;
	inParse(T[u].r);
}

void postParse(int u) {
	if (u == NIL) return;
	postParse(T[u].l);
	postParse(T[u].r);
	cout << " " << u;
}


int main()
{
	int i, v, l, r, root;
	cin >> n;
	for (i = 0; i < n; i++) T[i].p = NIL;
	
	for (i = 0; i < n; i++) {
		cin >> v >> l >> r;
		T[v].l = l;
		T[v].r = r;
		if (l != NIL)T[l].p = v;
		if (r != NIL)T[r].p = v;
	}

	for (i = 0; i < n; i++) if (T[i].p == NIL) root = i;

	cout << "Preorder" << endl;
	preParse(root);
	cout << endl;
	cout << "Inorder" << endl;
	inParse(root);
	cout << endl;
	cout << "Postorder" << endl;
	postParse(root);
	cout << endl;

    return 0;
}

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

int main()
{
  int N;scanf("%d",&N);
  vector<int> alphabets(26,0);
  int maxal=0;
  map<string,int> m;
  for(int i=0;i<N;i++)
  {
    string S;cin>>S;
    m[S]++;
    maxal=max(maxal,m[S]);
  }
  for(auto p : m)
  {
    if(p.second==maxal)cout<<p.first<<endl;
  }
}

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

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define MOD 1000000007

bool isvowel(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        return true;
        return false;
}
ll isprime(ll n)
{
    ll ans=1;
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            ans = i;
    }
    return ans;
}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    if(b==1)
        return a%m;
    ll temp=power(a,b/2,m);
    if(b%2==0)
        return ((temp%m)*(temp%m))%m;
    else
        return ((((temp%m)*(temp%m))%m)*a%m)%m;
}

/*-----------------------------------------------------------------------------*/

ll c(ll n, ll k)
{
    ll C[n + 1][k + 1];
    ll i, j;

    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= min(i, k); j++)
        {

            if (j == 0 || j == i)
                C[i][j] = 1;

            else
                C[i][j] = (C[i - 1][j - 1]%MOD +
                          C[i - 1][j])%MOD;
        }
    }
    return C[n][k]%MOD;
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {

        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;


        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;

    return x;
}
ll func(ll n)
{
    ll ans=0;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            if(i/10==0)
                ans+=1+func(i)*func(n/i);
            else
                ans+=func(i)*func(n/i);
        }
    }
    return ans;
}
ll dp[205][205][205];
ll check(ll red[],ll gre[],ll blu[],ll r,ll g,ll b,ll i,ll j,ll k)
{
   if(dp[i][j][k]!=-1)
    return dp[i][j][k]; 
   if(i<r&&j<g&&k<b)
   {
       return dp[i][j][k]=max(red[i]*gre[j]+check(red,gre,blu,r,g,b,i+1,j+1,k),max(gre[j]*blu[k]+check(red,gre,blu,r,g,b,i,j+1,k+1),blu[k]*red[i]+check(red,gre,blu,r,g,b,i+1,j,k+1)));
   }
   else if(i<r&&j<g) 
   {
       return dp[i][j][k]=red[i]*gre[j]+check(red,gre,blu,r,g,b,i+1,j+1,k);
   }
   else if(j<g&&k<b)
   {
       return dp[i][j][k]=gre[j]*blu[k]+check(red,gre,blu,r,g,b,i,j+1,k+1);
   }
   else if(i<r&&k<b)
   {
       return dp[i][j][k]=red[i]*blu[k]+check(red,gre,blu,r,g,b,i+1,j,k+1);
   }
   else
   {
       return 0;
   }
}
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    //freopen("1.txt","rt",stdin);
    //freopen("output.txt","wwt",stdout);

    ll t;
    t=1;
    //cin>>t;
    //ll t1=0;
    while(t--)
    {
        ll x,k,d,ans;
        cin>>x>>k>>d;
        if(x<0)
         x=-1*x;

        if(x/k >= d )
        {
            ans=abs(x-k*d);
        } 
        else
        {
            ll p=x/d;
            x=x-p*d;
            k-=p;
            if(k%2==0)
             ans=x;
            else
            {
                ans=abs(x-d);
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3692
from collections import Counter
N = int(input())
A = sorted(list(map(int, input().split())))
div = 10 ** 9 + 7
if N % 2 == 0:
    B = [i for i in range(1, N, 2)]
    B.extend(B)
    B.sort()
    if A == B:
        print(2**(int(N/2)) % div)
    else:
        print(0)

else:
    B = [i for i in range(2, N, 2)]
    B.extend(B)
    B.append(0)
    B.sort()
    if A == B:
        print(2**(int(N/2)) % div)
    else:
        print(0)


Measured memory_bytes: 14196
from heapq import heapify, heappush, heappop

def solve():
    N = int(input())
    Ss = list(map(int, input().split()))

    Ss.sort(reverse=True)
    pow2s = [2**i for i in range(N)]

    PQs = [[-Ss[0]] for _ in range(N)]
    nums = [0] * N
    tm0 = 0
    for S in Ss[1:]:
        for tm in range(tm0, N):
            if nums[tm] >= pow2s[tm]:
                tm0 = tm
            else:
                if -PQs[tm][0] > S:
                    heappop(PQs[tm])
                    nums[tm] += 1
                    for i in range(tm+1, N):
                        heappush(PQs[i], -S)
                    break
        else:
            return False

    return True

if solve():
    print('Yes')
else:
    print('No')


Measured memory_bytes: 34376
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;
int n;
string s;

int main(){
	IOS
	ll ans=0;
	cin >> n >> s;
	for(int i=0;i+2<n;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
			ans++;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
#define FAST std::ios::sync_with_stdio(false);
#define endl '\n'
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAX_N 4010
#define Mem(a,b) memset(a,b,sizeof(a))
#define FREI freopen("in.txt","r",stdin)
#define FREO freopen("out.txt","w",stdout)
using namespace std;
const ll mod=1e9+7;
 
char str[100];
int main() {
#ifdef ONLINE_JUDGE
#else
    //FREI;
    // FREO;
#endif
    //FAST;
    char s[5]="YAKI";
    scanf("%s",str);
    int len=strlen(str);
    bool flag=1;
    for(int i=0;i<min(len,4);i++){
        if(str[i]!=s[i])
            flag=0;
    }
    if(len<4)
        flag=0;
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

int main(){
    char c;
    cin >> c;

    if ( c == 'a'){
        cout << "vowel" << endl;
    }
    else if (c == 'i'){
        cout << "vowel" << endl;
    }
    else if (c == 'u'){
        cout << "vowel" << endl;
    }
    else if (c == 'e'){
        cout << "vowel" << endl;
    }
    else if (c == 'o'){
        cout << "vowel" << endl;
    }
    else {
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
S = input()
flag =False
S_set = set(list(S))

if len(S_set) == 2:
  count_1 = S.count(list(S_set)[0])
  count_2 = S.count(list(S_set)[1])
  if count_1 == 2 and count_2 == 2:
  	flag = True

if flag:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
from itertools import accumulate
def inpl(): return tuple(map(int, input().split()))
N = int(input())
A = inpl()
B = inpl()
res = 0
for i in range(N):
    res = max(res, sum(A[:i+1]) + sum(B[i:]))

print(res)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
#define S stack<int>
#define Q queue<int>
#define V vector<int>
using namespace std;
signed main(){
	int a,b,ans=0;
	cin>>a>>b;
	for(int i=1;i*i<=b;i++){
		if(b%i==0){
			if(i<=b/a) ans=max(ans,i);
			if(b/i<=b/a) ans=max(ans,b/i);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;

const int NMAX = 2* 1e5+3;
using namespace std;

long pow(long a, long b) {
  if (b == 0) {
    return 1;
  } else if (b % 2 == 0) {
    long d = pow(a, b / 2);
    return (d * d) % MOD;
  } else {
    long d = pow(a, b - 1);
    return (a * d) % MOD;
  }
}

int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    ll fact[NMAX+1], invfact[NMAX+1];
    
    fact[0] = 1;
    invfact[0] = 1;
    for(ll i = 0; i < NMAX; i++){
        fact[i+1] = fact[i]*(i+1)%MOD;
    }
    invfact[NMAX] = pow(fact[NMAX], MOD-2);
    for(ll i = NMAX-1; i > 0; i--){
        if(i ==0) exit(1);
        invfact[i] = invfact[i+1]*(i+1)%MOD;
    }

    ll top = 0;
    ll btm = 0;
    for(ll i = 0; i <= n; i++){
        top += n-i;
        btm += i;
        if(i >= k-1){
            ll tmp = (top-btm+1)%MOD;
            ans += tmp%MOD;
        }
    }

    cout << ans%MOD << endl;
}

Measured memory_bytes: 5212
from collections import deque
def main():
    S=input()
    S=deque(S)
    Q=int(input())
    flag=1
    for _ in range(Q):
        q=input()
        if q=="1":
            flag*=-1
            continue
        q=list(q.split(" "))
        q[1]=int(q[1])
        if q[1]==2:
            q[1]=-1
        if q[1]*flag <=0:
            S.append(q[2])
        else:
            S.appendleft(q[2])
    if flag==1:
        print("".join(list(S)))
    else:
        print("".join(list(S)[::-1]))
            

main()

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

typedef long long ll;

const int mod = 1000000007;
const int Maxn = 2005;

int n, k;
int a[Maxn];
int res;

int main()
{
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) if (a[i] > a[j])
            if (i < j) res = (res + ll(k) * (k + 1) / 2) % mod;
            else res = (res + ll(k - 1) * k / 2) % mod;
    printf("%d\n", res);
    return 0;
}


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

int main() {
  string w;
  cin >> w;
  vector<int> a(26, 0);
  rep(i, w.size()) ++a[w[i] - 'a'];
  bool b = true;
  rep(i, 26) if (a[i] % 2 == 1) b = false;
  if (b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int k;
    cin >> k;
    string s;
    cin >> s;

    if (s.size() <= k) cout << s << endl;
    else cout << s.substr(0, k) + "..." << endl;


    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
int main() {
	int x, a;
	cin >> x >> a;
	if (x < a) cout << 0 << endl;
	else cout << 10 << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
H=[int(i) for i in input().split()]
#print(H)
flag=True
H.reverse()
temp = H[0]+1
for i in H:
    if(i>temp+1):
        flag=False
        break
    elif(i==temp+1):
        temp=i-1
    elif(i<=temp):
        temp=i;

if(flag):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S,T;
    cin>>S>>T;
    int cnt=0;
    if(S[0]==T[0])cnt++;
    if(S[1]==T[1])cnt++;
    if(S[2]==T[2])cnt++;
    cout<<cnt;
    
    
return 0;
}


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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		int rnum = 0;
		for(char x : s.toCharArray()) {
			if(x == 'R')
				rnum += 1;
		}
		if(rnum > N - rnum)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b;
    cin>>a>>b;
    cout<<(a*b)/__gcd(a,b)<<endl;
}


Measured memory_bytes: 3596
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>


#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr,__VA_ARGS__)

using namespace std;

inline char nc(){ static char buf[100000] , *p1,*p2; return p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,100000,stdin),p1 == p2) ? EOF: *p1++;}
template<class T>inline void rd(T & x){ x = 0;char ch = nc();for(;!isdigit(ch);ch = nc()); for(;isdigit(ch);ch = nc()) x = x * 10 - 48 + ch;}

typedef long long ll;

const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;

int a[maxn],  inv[maxn];
void getinv(){
	inv[0] = inv[1] = 1;
	for(int i = 2;i < maxn;i++){
		inv[i] = mod - (ll)inv[mod % i] * (mod / i) % mod;
	}
}
int main(){
	int n;
	rd(n);
	for(int i = 1;i <= n;i++){ rd(a[i]); }
	getinv();
	int sum = 0,ans = 0;
	for(int i = 1;i <= n;i++) sum = (sum + inv[i]) % mod;
	for(int i = 1;i <= n;i++){
		ans = (ans + (ll)a[i] * sum % mod) % mod;
		sum = ((ll)sum - inv[n - i + 1] + mod) % mod;
		sum = (sum + inv[i + 1]) % mod;
	}
	for(int i = 2;i <= n;i++){
		ans = 1ll * ans * i % mod;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstdint>
using namespace std;
typedef int64_t i64;
vector<i64> L(87);

i64 lucas(int n){
    if(n == 0) return 2;
    if(n == 1) return 1;
    if(L[n] == 0) L[n] = lucas(n-1) + lucas(n-2);
    return L[n];
}

int main(void){
    int n;
    cin >> n;
    cout << lucas(n) << '\n';
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    double g[n][n];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) g[i][j] = 100000000;
    int b[n], x[n], y[n];
    for (int i = 0; i < n; i++) {
      int b, _x, _y;
      cin >> b >> _x >> _y;
      x[b - 1] = _x;
      y[b - 1] = _y;
      // cin >> b[i] >> x[i] >> y[i];
    }
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++) {
        int xx = x[i] - x[j], yy = y[i] - y[j];
        if (pow(xx, 2) + pow(yy, 2) <= 2500 && i != j) g[i][j] = g[j][i] = sqrt(pow(xx, 2) + pow(yy, 2));
      }
    int m;
    cin >> m;
    int s, go;
    for (int i = 0; i < m; i++) {
      cin >> s >> go;
      s--;
      go--;
      vector<int> used(n, false);
      vector<int> gone(n, false);
      vector<double> dist(n, 100000000);
      dist[s] = 0;
      gone[s] = 0;
      while (1) {
        int va = -1;
        for (int j = 0; j < n; j++)
          if (used[j] == false && (va == -1 || dist[va] > dist[j])) va = j;
        if (va == -1) break;
        used[va] = true;
        for (int j = 0; j < n; j++) {
          if (dist[j] >= dist[va] + g[va][j]) gone[j] = va;
          dist[j] = min(dist[j], dist[va] + g[va][j]);
        }
      }
      if (s == go)
        cout << s + 1 << " " << go + 1 << endl;
      else if (dist[go] == 100000000)
        cout << "NA" << endl;
      else {
        int kari = go;
        stack<int> out;
        while (1) {
          out.push(gone[kari] + 1);
          kari = gone[kari];
          if (kari == s) break;
        }
        while (!out.empty()) {
          cout << out.top() << " ";
          out.pop();
        }
        cout << go + 1 << endl;
      }
    }
  }
}

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

long solve(long n)
{
	if(n==1) return 1;
	else return 2*solve(n/2)+1;
}


int main()
{
		
	long n; cin>>n;
	long ans = solve(n);
	cout<<ans;


	return 0;
}

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

using namespace std;

using int64 = long long;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}
template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

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

  int h, w;
  cin >> h >> w;
  vector<string> board(h);
  for (int r = 0; r < h; r++) {
    cin >> board[r];
  }

  auto d_table = Make2DVector<int>(h, w, INT32_MAX);
  deque<tuple<int, int>> q;
  for (int r = 0; r < h; r++) {
    for (int c = 0; c < w; c++) {
      if (board[r][c] == '#') {
        d_table[r][c] = 0;
        q.push_back(make_tuple(r, c));
      }
    }
  }

  int ans = 0;
  vector<int> dxs({1, 0, -1, 0});
  vector<int> dys({0, 1, 0, -1});
  while (!q.empty()) {
    auto p = q.front();
    q.pop_front();
    int r, c;
    tie(r, c) = p;
    // cout << "r: " << r << " c: " << c << endl;
    for (int d = 0; d < 4; d++) {
      int nr = r + dys[d];
      int nc = c + dxs[d];
      // cout << "nr: " << nr << " nc: " << nc << endl;
      if (nr < 0 || nr >= h) continue;
      if (nc < 0 || nc >= w) continue;
      // cout << "DEBUG 1" << endl;
      if (d_table[nr][nc] < INT32_MAX) continue;
      // cout << "DEBUG 2" << endl;
      d_table[nr][nc] = d_table[r][c] + 1;
      UpdateMax(ans, d_table[nr][nc]);
      q.push_back(make_tuple(nr, nc));
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 13456
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <climits>

#define REP(i,N) for(auto i = 0; i <N; i++)


typedef long long ll;
//const int MOD = pow(10,9)+7;
//const int MAX = 100001;

using namespace std;
int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}


int main() {

    ll N = lin();
    
    vector<ll> cards;

    ll sum = 0;
    REP(i,N){
        cards.push_back(lin());
        sum+=cards.back();
    }
    
    ll ansS = 0;
    ll ansA = sum;
    
    ll diff = LONG_MAX;
    
    for(auto i = 0; i < N-1; i++){
        
        ansS+=cards[i];
        ansA-=cards[i];
        
        if (diff > abs(ansA-ansS)) diff = abs(ansA-ansS);
    }
    
    cout << diff << endl;
    
    
    return 0;
    
    
}








Measured memory_bytes: 2420
n,m = map(int,input().split())
s = input()[::-1]


# If at i can go to j,k and from j can go to l then can also go to l from k since (j-l) < m => (k-l) < m
# so it is always best to take the highest move possible from i
# Reversing to get max moves

def getFarthest(start):
    for i in range(min(n,start+m),start-1,-1):
        if s[i] == '0':
            return i

ans = []
start = 0
found = True
while True:
    nxt = getFarthest(start)
    if nxt == start:
        found = False
        break
    ans.append(nxt - start)
    start = nxt
    if start == n:
        break
ans = ans[::-1]
if found:
    for i in ans:
        print(i,end=" ")
    print()
else:
    print(-1)


Measured memory_bytes: 4888
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

int grid[2010][2010] = {0};
int sum[2010][2010] = {0};

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

    rep(i, n){ 
        int x, y; char c; bool z; 
        cin >> x >> y >> c;
        if (c=='W') z = false;
        else z = true;
        int dx = x%(2*k);
        int dy = y%(2*k);
        if (!z) dx = (dx+k)%(2*k);
        grid[dx][dy]++;
    }

    rep(i, 2*k){
        rep(j, 2*k){
            sum[i+1][j+1]=sum[i+1][j]+sum[i][j+1]-sum[i][j]+grid[i][j];
        }
    }

    // rep(i, 2*k){
    //     rep(j, 2*k){
    //         cout << grid[i][j] << ":";
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    // rep(i, 2*k){
    //     rep(j, 2*k){
    //         cout << sum[i+1][j+1] << ":";
    //     }
    //     cout << endl;
    // }
    int ans_max = 0;
    //[hansei] 探索範囲の誤り
    rep(i, k+1){
        rep(j, k+1){
            // ans += sum[2*k][2*k] - sum[2*k][j+k] - sum[i+k][2*k];
            // ans += sum[2*k][j] + sum[i][2*k];
            // ans += (sum[i+k][j+k] - sum[i][j+k] - sum[i+k][j] + sum[i][j])*2;
            //cout << i << j << ":" << ans << endl;
            int tmp1=sum[i][j]+sum[0][0]-sum[i][0]-sum[0][j];
            int tmp2=sum[i+k][j+k]+sum[i][j]-sum[i+k][j]-sum[i][j+k];
            int tmp3=sum[2*k][2*k]+sum[i+k][j+k]-sum[2*k][j+k]-sum[i+k][2*k];
            int tmp4=sum[i][2*k]+sum[0][j+k]-sum[i][j+k]-sum[0][2*k];
            int tmp5=sum[2*k][j]+sum[i+k][0]-sum[2*k][0]-sum[i+k][j];
            int ans=tmp1+tmp2+tmp3+tmp4+tmp5;
            ans_max = max(ans_max, ans);
            ans_max = max(ans_max, n-ans);
        }
    }
    cout << ans_max << endl;
}



Measured memory_bytes: 31744
#include<bits/stdc++.h>
#define llu unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define to_lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define to_upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define Mod 1000000007
using namespace std;

// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// print vector
template <typename T> 
inline ostream &operator<<(ostream &out, vector<T> &a) {
    for(auto &x : a) out << x <<" ";
    // return in;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}
vector<ll> value, weight;
vector<vector<ll> > dp;
ll n,w, ans;
ll solve(int index, ll c)
{
	if(index<0)
		return 0;
	if(dp[index][c]!=-1)
		return dp[index][c];
	if(weight[index]>c)
		dp[index][c]=solve(index-1,c);
	else
		dp[index][c]=max(solve(index-1,c),value[index]+solve(index-1,c-weight[index]));
	return dp[index][c];
}

int main()	
{
	#ifdef SANS
		freopen("ongoingin.txt","r",stdin);
		freopen("ongoingout.txt","w",stdout);
	#endif
	fast
	int t=1;
	// cin>>t;
	while(t--)
	{
		cin>>n>>w;
		dp.resize(n);
		weight.resize(n);
		value.resize(n);
		for(int i=0; i<n; i++)
		{
			dp[i].resize(w+1,-1);
			cin>>weight[i]>>value[i];
		}
		cout<<solve(n-1,w)<<endl;
	}
	#ifdef SANS
		cout<<"\nTime Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC <<"sec\n";
	#endif
}

Measured memory_bytes: 81432
#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 RFOR(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)

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; }

#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; cin>>N;
    vll a(N);
    rep(i,N) cin>>a[i];
    ll goal=0;
    FOR(i,2,N-1) goal^=a[i];
    ll sum = a[0]+a[1];
    ll diff = sum-goal;
    if (diff<0 || diff%2==1){
        cout<<"-1\n";
        return 0;
    }
    diff/=2;
    if (diff>a[0] || (diff&goal)!=0){
        cout<<"-1\n";
        return 0;
    }
    ll ans = diff;
    RFOR(i,60,0){
        if (goal>>i&1 && ans+(1LL<<i)<=a[0]) ans += 1LL<<i;
    }
    if (ans==0){
        cout<<"-1\n";
    }else{
        cout<<a[0]-ans<<endl;
    }
    return 0;
}


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

using namespace std;

int main() {
	char A[4];
	char B[4];
	scanf("%s%s", A, B);
	if (A[0] == B[2] && A[1] == B[1] && A[2] == B[0]) printf("YES\n");
	else printf("NO\n");
	return 0;
}


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

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int,int> Paint;

#define anyfill(n,s) setw(n) << setfill(s)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define pb push_back
#define MAX 1000000000
#define MOD 1000000007

int main(){
  long long n;cin>>n;
  long long ans = 0;
  for(int i = 1; (n-i)/i > i; i++){
    if((n-i)%i == 0 && (n-i)/i > i){
      ans += (n-i)/i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
a=[int(input()) for i in range(N)]
sw=True
b=sorted(a,reverse=True)

if b[0]>b[1]:
    max2=b[1]
    max1=b[0]
    sw=False

if sw==True:
    max1=b[0]
    for k in range(N):
        print(max1)
else:
    for k in range(N):
        if a[k]==max1:
            print(max2)
        else:
            print(max1)


Measured memory_bytes: 18972
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    constexpr int MAX = 1e6;
    int N; cin >> N;
    map<int,int> mp;
    REP(i,N) {
        int a; cin >> a;
        mp[a]++;
    };
    vector<int> a;
    vector<int> erato(MAX+5);
    for(auto p:mp) {
        if (p.second == 1) a.push_back(p.first);
        else {
            for(int j = 1; p.first * j <= MAX; j++) erato[p.first*j] = p.first;
        }
    }
    int ans = 0;
    REP(i,a.size()) {
        if (erato[a[i]]) continue;
        // cerr << a[i] << endl;
        ans++;
        for(int j = 1; a[i] * j <= MAX; j++) erato[a[i]*j] = a[i];
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 17332
function main()
  
  A, B = split(chomp(readline()), " ")
  
  B = replace(B, "." => "")
  
  A = parse(BigInt, A)
  B = parse(Int, B)
  
  ans::BigInt = div(A * B, 100)
  
  println(ans)
  
end

main()

Measured memory_bytes: 165204
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;

const int N = 1e3 + 5;
char s[N][N];
vector<int> g[N * N];
bool vis[N * N];
int h, w, d[N * N];
int color[N][N], cp;
int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
void dfs(int x, int y)
{
    color[x][y] = cp;
    for (int i = 0; i < 4; ++i){
        int nx = x + dx[i], ny = y + dy[i];
        if (nx < 1 || nx > h || ny < 1 || ny > w) continue;
        if (!color[nx][ny] && s[nx][ny] != '#') dfs(nx, ny);
    }
}
queue<int> qi;
int main()
{
    int ch, cw, dh, dw;
    scanf("%d %d %d %d %d %d", &h, &w, &ch, &cw, &dh, &dw);
    for (int i = 1; i <= h; ++i) scanf("%s", s[i] + 1);
    for (int i = 1; i <= h; ++i){
        for (int j = 1; j <= w; ++j){
            if (s[i][j] == '.' && !color[i][j]){
                ++cp;
                dfs(i, j);
            }
        }
    }
    for (int tx = 1; tx <= h; ++tx){
        for (int ty = 1; ty <= w; ++ty){
            if (s[tx][ty] == '#') continue;
            for (int j = -2; j < 3; ++j){
                for (int k = -2; k < 3; ++k){
                    int nx = tx + j, ny = ty + k;
                    if (nx < 1 || nx > h || ny < 1 || ny > w || s[nx][ny] == '#' || (nx == tx && ny == ty)) continue;
                    if (color[tx][ty] != color[nx][ny]){
                        g[color[tx][ty]].push_back(color[nx][ny]);
                        g[color[nx][ny]].push_back(color[tx][ty]);
                    }
                }
            }
        }
    }
    memset(d, 0x3f, sizeof(d));
    d[color[ch][cw]] = 0;
    vis[color[ch][cw]] = true;
    qi.push(color[ch][cw]);
    while(!qi.empty()){
        int u = qi.front(); qi.pop();
        for (int v : g[u]){
            if (d[v] > d[u] + 1){
                d[v] = d[u] + 1;
                if (!vis[v]){
                    vis[v] = true;
                    qi.push(v);
                }
            }
        }
    }
    if (d[color[dh][dw]] < 0x3f3f3f3f) printf("%d\n", d[color[dh][dw]]);
    else puts("-1");
    return 0;
}


Measured memory_bytes: 58336
n=gets.chomp.to_i
h=gets.chomp.split(" ").map{|s| s.to_i}
ans=[]
m=0
for i in 1..n-1
  if h[i-1]>=h[i]
    m+=1
  else
    ans.push(m)
    m=0
  end
end
ans.push(m)
p ans.max

Measured memory_bytes: 9988
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

D = defaultdict(int)
for a in A:
    for i in range(61):
        D[1 << i] += bool(a & (1 << i))

ans = 0
for key, value in D.items():
    ans += ((key * value) % MOD) * (N - value) % MOD
    ans %= MOD

print(ans % MOD)


Measured memory_bytes: 122936
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let mut t = (0,0);
    for _ in 0..n {
        let v: Vec<String> = read_vec();
        match (&v[0], &v[1]) {
            (l,r) if l > r => t.0 += 3,
            (l,r) if l < r => t.1 += 3,
            _ => {
                t.0 += 1;
                t.1 += 1;
            }
        };
    }
    println!("{} {}", t.0, t.1);
}



Measured memory_bytes: 5048
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] data1 = br.readLine().split(" ");
    int n = Integer.parseInt(data1[0]);
    int m = Integer.parseInt(data1[1]);
    
    String[] data2 = br.readLine().split(" ");
    int[] as = new int[n];
    int sum = 0;
    
    for (int i=0; i<n; i++){
      as[i] = Integer.parseInt(data2[i]);
      sum += as[i];
    }
    int o = 0;
    for (int i : as){
      if (i >= (double)sum/(4*m)){
        o++;
      }
    }
    if (o >= m){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
	int N;
	cin >> N;
	if(N % 2 == 1) cout << 2 * N << endl;
	else cout << N << endl;
	return 0;
}


Measured memory_bytes: 256
function Main(input) {
    var X = BigInt(input[0]);
    var y = 0;
    var money = 100n;

    while(X > money) {
        money = money + money / 100n;
        y = y + 1;
    }
    console.log(y);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 29832
def solve_c(n, b_list):
    
    a_list = [0] * n
    
    a_list[0] = b_list[0]
    a_list[-1] = b_list[-1]
    for i in range(1, n - 1):
        a_list[i] = min(b_list[i - 1], b_list[i])
        
    return sum(a_list)


def main():
    
    n = int(input())
    b_list = list(map(int, input().split()))
    
    print(solve_c(n, b_list))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#line 1 "/workspaces/compro/lib/template.hpp"


#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "main.cpp"

const std::string YES = "Yes";
const std::string NO = "No";
bool solve(string N) {
  ll c = 0;
  REP(i, N.length()) { c += N[i] - '0'; }
  return c % 9 == 0;
}

// generated by online-judge-template-generator v4.4.0 (https://github.com/kmyk/online-judge-template-generator)
int main() {
  string N;
  std::cin >> N;
  auto ans = solve(N);
  std::cout << (ans ? YES : NO) << std::endl;
  return 0;
}


Measured memory_bytes: 3860
//高速化なしver
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquestring;
typedef priority_queue<int> priqueint;
typedef priority_queue<ll> priquell;
typedef priority_queue<char> priquechar;
typedef priority_queue<string,vector<string>,greater<string>> rpriquestring;
typedef priority_queue<int,vector<int>,greater<int>> rpriqueint;
typedef priority_queue<ll,vector<ll>,greater<ll>> rpriquell;
typedef priority_queue<char,vector<char>,greater<char>> rpriquechar;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

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


int main(){
    int h,w;cin >> h >> w;
    vector<vector<char>> a(h,vector<char>(w));
    queue<pair<int,int>> q;
    rep(i,h)rep(j,w){
        cin >> a[i][j];
        if(a[i][j]=='#')q.push(pair<int,int>(i,j));
    }
    
    int cnt=-1;
    while(!q.empty()){
        int n=q.size();
        rep(i,n){
            pair<int,int> now=q.front();q.pop();
            rep(j,4){
                int nx=now.first+dx[j];int ny=now.second+dy[j];
                if(nx<0||ny<0||nx>=h||ny>=w)continue;
                if(a[nx][ny]=='#')continue;
                q.push(pair<int,int>(nx,ny));a[nx][ny]='#';
            }
        }
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 9488
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
VPII e[SIZE];
int an[SIZE];
void dfs(int x,int lt,int v){
    an[x]=v&1;
    for(auto y:e[x]){
        if(y.F==lt)continue;
        dfs(y.F,x,v^y.S);
    }
}
int main(){
    int N; R(N);
    REPP(i,1,N){
        int u,v,w;
        R(u,v,w);
        e[u].PB({v,w});
        e[v].PB({u,w});
    }
    dfs(1,1,0);
    FOR(i,1,N)W(an[i]);
    return 0;
}


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

using namespace std;

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

#define N 100010
#define M 200010
#define endl "\n"
#define mod 1000000007 

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	string str;
	
	cin >> str;
	
	if(str == "ABC") str = "ARC";
	else str = "ABC";
	
	cout << str << endl;
	
	return 0;
}

Measured memory_bytes: 3604
#include<iostream> 
#include<cstring>
#include<cmath>
using namespace std;

const int MAX = 100;
int N, M;
char garden[MAX][MAX+1];
int num;

void dfs(int x, int y, char ch){
	garden[x][y] = '.';
	for(int dx = -1; dx <= 1; dx++){
		for(int dy = -1; dy <= 1; dy++){
			if(abs(dx) + abs(dy) > 1) continue;
			int nx = x + dx, ny = y + dy;
			if(nx >= 0 && nx < N && ny >= 0 && ny < M && garden[nx][ny] == ch) dfs(nx, ny, ch);
		}
	}
	return;
}

int main(){
	for(;;){
		cin >> N >> M;
		if(N == 0) break;
		memset(garden,'\0',sizeof(garden));
		for(int i = 0; i < N; i++)
			cin >> garden[i];
		num = 0;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < M; j++){
				if(garden[i][j] != '.') {
					dfs(i,j,garden[i][j]);
					num++;
				}
			}
		}
		cout << num << endl;
	}
	return 0;
}



Measured memory_bytes: 4344
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		while(sc.hasNext()){
			String str = sc.next();
			Separate(str);
		}
		sc.close();
	}
	public static void Separate(String str){
		String str2 = "";
		for(int j = 0; j < 9 ; j++){
			int num[] = new int[str.length()];
			String num2[] = new String [str.length()];
			//System.out.println(str);
			for(int i = 0 ; i < str.length();i++){
				num[i]=str.charAt(i)-48;
			}
			for(int i = 0 ; i < str.length()-1;i++){
				int p = 0;;
				p = (num[i]+num[i+1]) % 10;
				num2[i]=String.valueOf(p);	
				//System.out.println(p);
			}
			//System.out.println(" ");
			for(int i = 0 ; i < str.length()-1;i++){
				str2 = str2+num2[i];
			}	
			if(j == 8 )System.out.println(num2[0]);
			str = str2;
			str2 = "";
			
		}
	}
}
	

Measured memory_bytes: 25688
n = int(input())
A = list(map(int, input().split()))

SWAP = 0

def conquer(A, left, mid, right):
  L, R = A[left:mid], A[mid:right]
  # L, Rの末尾にINFTYを入れないと、L[-1] or R[-1]が評価されない
  INFTY = 2 ** 30
  L.append(INFTY)
  R.append(INFTY)
  # i : position in L, j : position in R
  i, j = 0, 0

  swap_times =  0

  # 元のArrayを変えたいため、kを生成
  for k in range(left, right):
    # print(i, j, L, R, A)
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1
      swap_times += (mid-left) - i

  return swap_times

def divide(A, left, right):
  # print(left, right)

  # A[right-left]が2つ以上の場合に
  if left+1 < right:
    mid = (left+right)//2

    countL = divide(A, left, mid)
    countR = divide(A, mid, right)

    return conquer(A, left, mid, right) + countL + countR

  return 0

def mergeSort(A):
  return divide(A, 0, len(A))

swap = mergeSort(A)
print(swap)


Measured memory_bytes: 27496
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main(void){
  int a, b;
  scanf("%d", &a);
  scanf("%d", &b);
  if(a<b){
    int tmp = a;
    a = b;
    b = tmp;
  }

  long int i=1;
  long int mul;
  while(1){
    mul = (long int)a*i;
    if(mul%b == 0)
      break;
    i++;
  }

  printf("%ld\n", mul);
  
  return 0;
}


Measured memory_bytes: 128