akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 aa, bb, xx, ans;
	cin >> aa >> bb >> xx;
	ans = bb / xx + 1;
	ans -= (aa == 0 ? 0 : (aa - 1) / xx + 1);
	cout << ans << endl;
	return 0;
}

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

int main(){
  int r;
  cin >> r;
  cout << r * r << endl;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

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


Measured memory_bytes: 13312
def main():
    n = int(input())
    seq = tuple(map(lambda x: int(x), input().split()))

    points = []
    for i in range(n - 1):
        points.append([0] * n)

    if n == 1:
        print(seq[0])
        return

    for i in range(n - 1):
        points[i][i + 1] = (
            max(seq[i], seq[i + 1]),
            min(seq[i], seq[i + 1])
        )

    for k in range(2, n):
        for i in range(n - k):
            currLeft = seq[i] + points[i + 1][i + k][1]
            currRight = seq[i + k] + points[i][i + k - 1][1]
            nextLeft = points[i + 1][i + k][0]
            nextRight = points[i][i + k - 1][0]

            if currLeft > currRight:
                points[i][i + k] = (currLeft, nextLeft)
            else:
                points[i][i + k] = (currRight, nextRight)

        points.pop()

    print(points[0][n - 1][0] - points[0][n - 1][1])

main()


Measured memory_bytes: 386472
#include <stdio.h>

int isPrime(int);

int main(){
  int N,i,x,res = 0;
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d",&x);
    if(isPrime(x)){
      ++res;
    }
  }
  printf("%d\n",res);
  return 0;
}

int isPrime(int x){
  int i;
  if(x < 2){ return 0; }
  for(i = 2 ; i*i <= x ; i++){
    if(x % i == 0){ return 0; }
  }
  return 1;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int y = sc.nextInt();
        int x = sc.nextInt();
        char[][] array = new char[y][x];
        int[] dy = {-1,0,0,1};
        int[] dx = {0,-1,1,0};
        for(int i = 0; i<y; i++) {
            String s = sc.next();
            for(int j=0; j<x; j++) {
                array[i][j] = s.charAt(j);
            }
        }
        for(int i = 0; i<y; i++) {
            for(int j=0; j<x; j++) {
                if(array[i][j] == '#'){
                    int count = 0;
                    for(int k=0; k<4; k++) {
                        int ni = i + dy[k];
                        int nj = j + dx[k];
                        if(ni <0 || y<=ni) continue;
                        if(nj <0 || x<=nj) continue;
                        if(array[ni][nj]=='#') count++;
                    }
                    if(count == 0) {
                        System.out.println("No");
                        return;
                    }
                }
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 23764
#include <stdio.h>

int main()
{
    char a, b, ans;
    scanf("%c %c", &a, &b);
    if (a == 'H') {
        if (b == 'H') {
            ans = 'H';
        } else {
            ans = 'D';
        }
    } else {
        if (b == 'H') {
            ans = 'D';
        } else {
            ans = 'H';
        }
    }
    printf("%c\n", ans);
}


Measured memory_bytes: 128
a, b, c, d = list(input())
op = '+-'
for op1 in op:
    for op2 in op:
        for op3 in op:
            ans = a + op1 + b + op2 + c + op3 + d
            if eval(ans) == 7:
                print('{}=7'.format(ans))
                break
        else:
            continue
        break
    else:
        continue
    break


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,N;
  cin >> N >> A >> B;

  int i = 1, i_tmp;
  // 求める総和
  int total = 0;
  // 各桁の和
  int X;
  // 格桁の数
  int x[5];

  while (i<=N){
    i_tmp = i;
    X = 0;

    for(int j=0;j<5;j++){
      x[j] = i_tmp/pow(10,4-j);
      i_tmp -= x[j]*pow(10,4-j);
      X += x[j];
    }

    if(A<=X&&X<=B)total += i;

    i += 1;
  }

  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args)throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //PrintWriter out = new PrintWriter(System.out);
        int[] a = new int[5];
        int ans = 1000000000;
        for(int i=0;i<5;i++) a[i]= sc.nextInt();
        for(int s=12345;s<=54321;s++){
            char[] cur = Integer.toString(s).toCharArray();
            if(!legal(cur)) continue;
            int time = 0;
            for(int i=0;i<5;i++){
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            }
            ans = Math.min(ans,time);
        }
        System.out.println(ans);
    }
    static boolean legal(char[] s){
        int[] rec = new int[10];
        for(char w:s) rec[w-'0']++;
        boolean ans = true;
        for(int i=1;i<=5;i++) ans &= rec[i]==1;
        return ans;
    }
}

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

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

template<class C> using iodef_rng_t = typename enable_if<decltype(declval<C>().begin(), true_type{})::value && !is_same<C, string>::value>::type;
template<class C, class = iodef_rng_t<C>> istream& operator>>(istream& in, C& c) { for (auto& v : c) { in >> v; } return in; }
template<class C, class = iodef_rng_t<C>> ostream& operator<<(ostream& out, const C& c) { int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    string s, t;
    cin >> s >> t;
    if (s.size() + 1 == t.size() && t.substr(0, s.size()) == s) {
        puts("Yes");
    } else {
        puts("No");
    }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, a, b;
    cin >> x >> a >> b;
    cout << (x - a) % b << endl;
}

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

using namespace std;

int main(){
    int A[4];
    while(cin >> A[0] >> A[1] >> A[2] >> A[3]){
        vector<int> c(10, 0);
        for(auto& t : A) c[t] = 1;
        cout << (c[1] && c[4] && c[7] && c[9] ? "YES" : "NO") << endl;
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map> 
#include<vector>
#include<queue>
#include<set>
#include<deque> 
#include<bitset>
#include<string>
#define N 40
#define K 300005
#define MOD 1e9+7
#define int long long 
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int mod = 1e9 + 7;
int lim = 1e4 +1;

//denotes the number of numbers for pos i...end with rem of digit sum = j
//3rd index is for 0 if on border and 1 if not on border
int dp[10005][105][2];

string no;
int d;

int max(int a, int b){
	if(a > b)
		return a;
	return b;
}



int32_t main(){
	cin>>no;
	cin>>d;
	
	int pad = lim - no.length();
	for(int i=0;i<pad;i++)
		no = '0' + no;
	//it will be on the border as the first digit is always one
	dp[0][0][1] = 1;
	for(int pos = 1; pos <lim; pos++){
		for(int sum = 0; sum < d; sum ++){
			for(int bor = 0; bor<2; bor++){
				if(bor == 0){
					for(int dig = 0; dig <10; dig++){
						int v = dig %d;
						int req = (sum + d - v)%d;
						dp[pos][sum][bor] += dp[pos - 1][req][0];
						if(dp[pos][sum][bor] >= mod)
							dp[pos][sum][bor] %= mod;
					}
					int last_poss = no[pos] - '0';
					for(int i=0;i<last_poss;i++){
						int v = i%d;
						int req = (sum + d - v)%d;
						dp[pos][sum][bor] += dp[pos - 1][req][1];
						if(dp[pos][sum][bor] >= mod)
							dp[pos][sum][bor] %= mod;
					}	
				}
				else{
					int last_poss = (no[pos] - '0')%d;
					int req = (sum + d - last_poss)%d;
					dp[pos][sum][bor] += dp[pos-1][req][1];
					if(dp[pos][sum][bor] >= mod)
						dp[pos][sum][bor] %= mod;
				}
			}
		}
	}
    
	cout<<(dp[lim-1][0][0] + dp[lim-1][0][1] + mod - 1)%mod<<endl;
    
    

	
	
	
}




Measured memory_bytes: 17276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    vector<int> b(n);
    vector<int> c(n);
    int memo1 = a.at(n - 1);
    for (int i = n - 1; i >= 0; i--)
    {
        memo1 = gcd(memo1, a.at(i));
        b.at(i) = memo1;
    }
    int memo2 = a.at(0);
    for (int i = 0; i < n; i++)
    {
        memo2 = gcd(memo2, a.at(i));
        c.at(i) = memo2;
    }
    int ansmax = 0;
    for (int i = 0; i < n - 2; i++)
    {
        ansmax = max(ansmax, gcd(c.at(i), b.at(i + 2)));
    }
    ansmax=max({ansmax,b.at(1),c.at(n-2)});
    cout << ansmax << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}
const int INF = 1001001001;
int n, A, B, C;
vi l(8);

int dfs (int cur, int a, int b, int c) {
    if (cur == n) {
        if (a != 0 && b != 0 && c != 0) return abs(A-a) + abs(B-b) + abs(C-c);
        else return INF;
    }
    int res1 = dfs(cur+1, a, b, c);
    int res2 = dfs(cur+1, a + l[cur], b, c) + 10 * (a != 0);
    int res3 = dfs(cur+1, a, b + l[cur], c) + 10 * (b != 0);
    int res4 = dfs(cur+1, a, b, c + l[cur]) + 10 * (c != 0);
    return min({res1, res2, res3, res4});
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> A >> B >> C;
    rep(i, n) cin >> l[i];
    cout << dfs(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())

if n % a == 0:
    x = n // a
else:
    x = n // a + 1

if n % c == 0:
    y = n // c
else:
    y = n // c + 1

ans = min(x * b, y * d)
print(ans)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  cout << A * B << endl;
  
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
bool has3(int i){
	while(i){
		if(i%10==3)return true;
		i/=10;
	}
	return false;
}
int main(){

	int n ,i;
	cin>>n;
	for(i=1;i<=n;i++){
		if(i%3==0||has3(i)){
			cout<<" "<<i;
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3084
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n, a;
	cin >> n >> a;
	
	if(n % 500 == 0){
		cout << "Yes" << endl;
	}else if(n % 500 <= a){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int N=3005;
int a[N][N];
    int dp[N][N][4];
    
int32_t main(){ios_base::sync_with_stdio(false);
         cin.tie(NULL);
         cout.tie(NULL);
    int n,m,k,i,j,x,y,v;
    cin>>n>>m>>k;
    
    for(i=0;i<k;i++){
        cin>>x>>y>>v;
    a[x][y]=v;
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            dp[i][j][0]=max(dp[i][j][0],max(dp[i-1][j][3],dp[i][j-1][0]));
            dp[i][j][1]=max(dp[i-1][j][3]+a[i][j],dp[i][j-1][1]);
            dp[i][j][1]=max(dp[i][j][1],dp[i][j-1][0]+a[i][j]);
            dp[i][j][2]=max(dp[i-1][j][3]+a[i][j],dp[i][j-1][2]);
            dp[i][j][2]=max(dp[i][j][2],dp[i][j-1][1]+a[i][j]);
            dp[i][j][3]=max(dp[i-1][j][3]+a[i][j],dp[i][j-1][3]);
            dp[i][j][3]=max(dp[i][j][3],dp[i][j-1][2]+a[i][j]);
        }
    }
    cout<<dp[n][m][3];
    return 0;
}

Measured memory_bytes: 355592
#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5+10;
const double inf=1e9;
typedef long long ll;
typedef pair<int,int>pr;
const ll mod=1e9+7;
ll _pow(ll  a,ll b) {
    ll ans=1;
    while(b) {
        if(b&1)
            ans=ans*a;
        a=a*a;
        b>>=1;
    }
    return ans;
}
double a[maxn];
int main(){
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin>>n;
  double sum=1.0,num=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    sum*=a[i];
  }
  for(int i=1;i<=n;i++){
     num+=sum/a[i];
  }
  printf("%.5lf\n",sum/num);
  return 0;
}
/*
9 111 92
150 254 268 417 798 704 701 927 128
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;
    string ans = "";
    rep(i, 0, dx) ans += 'R';
    rep(i, 0, dy) ans += 'U';
    rep(i, 0, dx) ans += 'L';
    rep(i, 0, dy) ans += 'D';
    ans += 'L';
    rep(i, 0, dy + 1) ans += 'U';
    rep(i, 0, dx + 1) ans += 'R';
    ans += 'D';
    ans += 'R';
    rep(i, 0, dy + 1) ans += 'D';
    rep(i, 0, dx + 1) ans += 'L';
    ans += 'U';
    o(ans);
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
    int W, H, x, y, r;
    int circle_left, circle_right, circle_bottom, circle_top;
    scanf("%d %d %d %d %d", &W,&H,&x,&y,&r);
    circle_left = x - r;
    circle_right = x + r;
    circle_bottom = y - r;
    circle_top = y + r;

    if (0 <= circle_left && circle_right <= W && 0 <= circle_bottom && circle_top <= H) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 2148
#include<iostream>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;
string s;
int k;
int main(){
  scan(s);scan(k);
  vector<string> sub;
  rep(i,s.size()){
    rep1(j,k){
      if(i+j<=s.size()){
	sub.push_back(s.substr(i,j));
      }
    }
  }

  sort(sub.begin(),sub.end());
  vector<string> uni;
  rep(i,sub.size()-1){
    if(sub[i]!=sub[i+1]){
      uni.push_back(sub[i]);
    }
  }
  uni.push_back(sub[sub.size()-1]);
  prin(uni[k-1]);
 
  return 0;
}


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

typedef long long ll;
const int N = 132000;

int n, v[N]; ll l, r, mid, ans;
vector<int> G[N];

struct node {
	ll x, y;
	node(ll a = 0, ll b = 0)
		:x(a), y(b) {}
	bool operator < (const node &p)
	const {return x != p.x ? x < p.x : y < p.y;}
}; vector<node> st[N];

void dfs(int u)
{
	if(G[u].empty())
	{
		st[u].emplace_back(0, 0);
		return;
	}
	int p = G[u][0], q = G[u][1];
	dfs(p);
	dfs(q);
	vector<node> a, b;
	// st[p].y + v[p] + v[q] + st[q].x <= mid
	int lp = st[p].size(), lq = st[q].size();
	for(int i = 0, j = -1; i < lp; ++i)
	{
		for(; j + 1 < lq && st[p][i].y + v[p] + v[q] + st[q][j + 1].x <= mid; ++j);
		if(~j && (a.empty() || a.back().y > st[q][j].y + v[q]))
			a.emplace_back(v[p] + st[p][i].x, st[q][j].y + v[q]);
	}
	swap(p, q);
	swap(lp, lq);
	for(int i = 0, j = -1; i < lp; ++i)
	{
		for(; j + 1 < lq && st[p][i].y + v[p] + v[q] + st[q][j + 1].x <= mid; ++j);
		if(~j && (b.empty() || b.back().y > st[q][j].y + v[q]))
			b.emplace_back(v[p] + st[p][i].x, st[q][j].y + v[q]);
	}
	vector<node> c(a.size() + b.size());
	merge(a.begin(), a.end(), b.begin(), b.end(), c.begin());
	for(const auto&p : c)
		if(st[u].empty() || (st[u].back().x < p.x && st[u].back().y > p.y))
			st[u].emplace_back(p);
}

bool check()
{
	for(int i = 1; i <= n; ++i)
		vector<node>().swap(st[i]);
	dfs(1);
	return !st[1].empty();
}

int main()
{
	scanf("%d", &n);
	for(int i = 2, x; i <= n; ++i)
	{
		scanf("%d %d", &x, v + i);
		G[x].push_back(i);
		r += v[i];
	}
	while(l <= r)
	{
		mid = (l + r) / 2;
		if(check())
			ans = mid, r = mid - 1;
		else
			l = mid + 1;
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 32540
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n = sc.nextInt();
    long a = 0;
    for(int i=0;i<n;i++){
      a+=i;
    }
    System.out.println(a);
  }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
double PI = acos(-1);

const int MAX_N = 2e5+10;
int n, a[MAX_N];
int dp[MAX_N];
 
 
int LIS() {
    fill(dp, dp + n, INF);
    for(int i = 0; i < n; i++){
        *lower_bound(dp, dp + n, a[i]) = a[i];
    }
    return lower_bound(dp, dp + n, INF) - dp;
}

int main(){
#ifdef LOCAL_TEST
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif
	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	int N;
	cin >> N;
	vector<pii> v(N);
	rep(i, N) cin >> v[i].fi >> v[i].se;
	if(sx > gx) {
		sx = -sx;
		gx = -gx;
		rep(i, N) v[i].fi = -v[i].fi;
	}
	if(sy > gy) {
		sy = -sy;
		gy = -gy;
		rep(i, N) v[i].se = -v[i].se;
	}
	sort(all(v));
	n = 0;
	rep(i, N) {
		if(sx <= v[i].fi && v[i].fi <= gx &&
			sy <= v[i].se && v[i].se <= gy) {
			a[n++] = v[i].se;
		}
	}
	int k = LIS();
	int p, q, s = gx - sx + gy - sy;
	if(k == min(gx - sx, gy - sy) + 1) {
		p = k -1;
		q = 1;
	}
	else {
		p = k;
		q = 0;
	}
	double ans = 100.0 * s - (20 - 5*PI)*p + (10*PI - 20) * q;
	printf("%.15lf\n", ans);
	// cerr << s << " " << p << " " << q << " " << k << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits//stdc++.h>
using namespace std;
int main(void){
    
    while(1){
        long long i,j,a,b,c,k,l;
        cin>>a>>b;
        if(a==0&&b==0)
        break;
        long long island[a][a];
        for(i=0;i<a;i++){
            for(j=0;j<a;j++){
                if(i==j)
                    island[i][j]=0;
                    
                else
                    island[i][j]=LLONG_MAX/2;
                    
            }
        }
        int frag=0;
        for(l=0;l<b;l++){
            cin>>c;
            if(c){
                long long d,e,f;
                cin>>d>>e>>f;
                if(island[d-1][e-1]>f){
                    island[d-1][e-1]=f;
                    island[e-1][d-1]=f;
                    frag=1;
                }
            }
            else{
                
                if(frag){
                    frag=0;
                    for(k=0;k<a;k++){
                        for(j=0;j<a;j++){
                            for(i=0;i<a;i++)
                            island[i][j]=min(island[i][j],island[i][k]+island[k][j]);
                        }
                    }
                }
                long long d,e;
                cin>>d>>e;
                long long ans=island[d-1][e-1];
                if(ans<LLONG_MAX/2)
                cout<<ans<<endl;
                else
                cout<<"-1"<<endl;
            }
        }
    }
    return 0;
    
}



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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	vvi pos(26);
	vi cntt(26);
	REP(i, s.size()) {
		pos[s[i] - 'a'].push_back(i);
	}
	REP(i, t.size()) {
		cntt[t[i] - 'a']++;
	}
	REP(i, 26) {
		if (cntt[i] > 0 && pos[i].empty()) {
			cout << -1 << endl;
			return 0;
		}
	}
	ll ans = 0, spos = -1,  cnt = 0;
	REP(i, t.size()) {
		int c = upper_bound(ALL(pos[t[i] - 'a']), spos) - pos[t[i] - 'a'].begin();
		if (c == pos[t[i] - 'a'].size()) {
			cnt++;
			spos = pos[t[i] - 'a'][0];
		}
		else {
			spos = pos[t[i] - 'a'][c];
		}
	}
	cout << cnt * s.size() + spos + 1 << endl;
}

Measured memory_bytes: 1228
<?php

$n = trim(fgets(STDIN));

for($i=0; $i<$n; $i++){
  $a[$i] = trim(fgets(STDIN));
}
$at = $a;
rsort($at);
$m = $at[0];
$sm = $at[1];

for($i=0; $i<$n; $i++){
  if ($i !== 0) echo "\n";
  if ($a[$i] == $m){
	echo $sm;
  } else {
    echo $m;
  }
}

?>

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

int main() {
  string N;
  cin >> N;
  int sum = 0;
  if (N[0] == '9') { ++sum; }
  if (N[1] == '9') { ++sum; }
  if (sum == 0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10000005];
ll dp[10005][10005];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
string s[200005];
int main() {
	int n;
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	sort(s, s + n);
	int count = 1;
	int ans = 0;
	for(int i = 0; i < n-1; i++) {
		if (s[i] == s[i + 1]) {
			count++;
		}
		else {
			ans = max(ans, count);
			count = 1;
		}
	}
	ans = max(ans, count);
	
	int kai = 1;
	for (int i = 0; i < n-1; i++) {
		if (s[i] == s[i + 1]) {
			kai++;
		}
		else {
			if (ans == kai) {
				cout << s[i] << endl;
				
			}
			kai = 1;
		}
	}
	
	if (ans == kai) {
		cout << s[n - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 14208
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc073/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int N;
    cin >> N;
    set<int> A;
    rep(i, N){
        int a; 
        cin >> a;
        if(A.count(a) == 1){
            A.erase(a);
        }else{
            A.insert(a);
        }
    }
    cout << A.size() << "\n";
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,vl>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;



int main(){
    ll H;
    cin >> H;
    ll W;
    cin >> W;
    ll K;
    cin >> K;
    vector<vector<char>> S(H, vector<char>(W));
    for(ll i=0;i<H;i++){
     for(ll j=0;j<W;j++){
         cin>>S[i][j]
     ;}
    ;}
    ll ans=INF;
    for(ll bit=0;bit<(1<<(H-1));bit++){
        vector<ll> kireme(0);
        ll count=0;
        for(ll i=0;i<H-1;i++){
            if(bit&(1<<i)){
                kireme.emplace_back(i);
                count++;
            }
        ;}
        ll num=kireme.size();
        vector<vector<ll>> choco(num+1, vector<ll>(W, 0));
        for(ll i=0;i<W;i++){
            ll t=0;
         for(ll j=0;j<H;j++){
             if(S[j][i]=='1')choco[t][i]++;
             if(t<num&&j==kireme[t]){t++;}
         ;}
        ;}
        vector<ll> stock(num+1,0);
        ll round=1;
        for(ll i=0;i<W;i++){
            for(ll j=0;j<num+1;j++){
                stock[j]+=choco[j][i]
            ;}
            bool check=0;
            for(ll i=0;i<num+1;i++){
                if(stock[i]>K){
                    check=1;break;
                }
            ;}
            if(check){
                if(round==1)goto SKIP;
                for(ll j=0;j<num+1;j++){
                stock[j]=0
                ;}
                count++;
                round=1;
                i--;
            }
            else round++;

        ;}
        ans=min(ans,count);
        SKIP:
    ;}
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
//#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}



int main(void) {
    FAST_IO;
    
    ll n, k;
    cin >> n >> k;
    ll x = n % k;
    cout << max(0LL, min(abs(x - k), x)) << endl;
    
    return 0;
}

Measured memory_bytes: 384
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long[] h = new long[n];
		long max = 0;
		for(int i = 0; i < n; i++){
		    h[i] = sc.nextLong();
		    max = max(max, h[i]);
		}
		
		// 計算
		long result = 0;
		long l = -1;
		long r = max/b+1;
		while(r-l > 1){
			long c = (r + l)/2;
			
			if(func(c, a, b, h)){
				r = c;
			}else{
				l = c;
			}
		}
		result = r;
		
		// 出力
		System.out.println(result);
	}
	
	static boolean func(long cnt, long a, long b, long[] h){
	    long tmp = 0;
	    for(long i : h){
	        tmp += (max(i - b*cnt, 0) + (a-b-1))/(a-b);
	    }
	    if(cnt < tmp) return false;
	    return true;
	}
}


Measured memory_bytes: 50236
n = int(input())
x_list = []
l_list = []
for i in range(n):
    x, l = map(int, input().split())
    x_list.append(x)
    l_list.append((x - l, x + l))

l_list = sorted(l_list, key=lambda a:a[1])
# print(l_list)
t = l_list[0][1]
ans = 1
for i in range(1, n):
    s = l_list[i][0]
    if s < t:
        continue
    t = l_list[i][1]
    ans += 1

print(ans)

Measured memory_bytes: 28660
#ABC174 B
import math
n, d = map(int, input().split())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
count = 0
for i in range(n):
  length = math.sqrt(x[i]**2 + y[i]**2)
  if length <= d:
    count += 1
print(count)

Measured memory_bytes: 116740
N, K = map(int, input().split())
x = list(map(int, input().split()))

if x[0] > 0:
    x.insert(0, 0)
    K+=1
    N+=1
elif x[-1] < 0:
    x.append(0)
    K+=1
    N+=1
else:
    for i in range(N-1):
        if x[i] < 0 and x[i+1]> 0:
            x.insert(i+1, 0)
            K += 1
            N+=1
            break

ans = float("inf")
for i in range(N):
    j = i + K-1
    if j >= N:
        break
    if x[i]*x[j] > 0:
        continue
    ans = min(ans, -2*x[i]+x[j], -x[i]+2*x[j])
    
print(ans)

Measured memory_bytes: 14564
def main():
    n,k = map(int,input().split())
    D = set(map(int,input().split()))

    while True:
        flg = 0
        for i in str(n):
            i = int(i)
            if i in D:
                flg = 1
                break
        if flg == 0:
            break
        n+=1

    print(n)

main()

Measured memory_bytes: 9124
#include<stdio.h>

int main(void){
    int h,x,i,j;
    
    while(1){
        scanf("%d" "%d",&h,&x);
        if(h==0&&x==0){
            break;
        }else{
            for(i=0;i<h;i++){
                for(j=0;j<x;j++){
                    if((i==0||j==0)||(i==(h-1)||j==(x-1))){
                        putchar('#');
                    }else{
                        putchar('.');
                    }
                }
                putchar('\n');
            }
        }
        putchar('\n');
    }
}


Measured memory_bytes: 2036
L,R = map(int,input().split())

ans = 2019 ** 2

if R - L >= 2018:
  ans = 0
  print(ans)
else: 
  for i in range(L,R):
    for j in range(L + 1,R + 1):
      mod = (i * j) % 2019 
      if mod < ans:
        ans = mod
      elif mod == 0:
        ans = 0
        break
  print(ans)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k,asc[56];
	char s[56];
	cin>>n>>k;
	k-=1;
	for(int i=0;i<n;i++){
		cin>>s[i];
		asc[i]=s[i];
	}
	asc[k]+=32;
	s[k]=asc[k];
	for(int i=0;i<n;i++)cout<<s[i];
	cout<<endl;
}


Measured memory_bytes: 256
package main

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

func nextInt(sc *bufio.Scanner) (n int, err error) {
	sc.Scan()
	s := sc.Text()
	n, err = strconv.Atoi(s)
	return
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for {
		var a, b, c int
		var err error
		if a, err = nextInt(sc); err == nil {
			if b, err = nextInt(sc); err == nil {
				c, _ = nextInt(sc)
				switch {
				case a < b && b < c:
					fmt.Println("Yes")
				default:
					fmt.Println("No")
				}
			} else {
				break
			}
		} else {
			break
		}
	}
}



Measured memory_bytes: 1056
h, w, k = map(int, input().split())
s = [input() for _ in range(h)]
ans = []
vacant = 0
cnt = 0
for x in range(h):
    if s[x] == '.' * w:
        vacant += 1
        continue
    else:
        cnt += 1
        tmp = []
        yet = False
        for y in range(w):
            if s[x][y] == '#':
                if not yet:
                    yet = True
                else:
                    cnt += 1
            tmp.append(cnt)
        for _ in range(vacant + 1):
            ans.append(tmp)
        vacant = 0
for _ in range(vacant):
    ans.append(ans[-1])
for a in ans:
    print(*a, sep=" ")

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

using namespace std;

int main() {
  int N, M;
  unordered_set<string> words;
  unordered_map<string, int> S, T;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string word;
    cin >> word;
    S[word]++;
    words.insert(word);
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    string word;
    cin >> word;
    T[word]++;
    words.insert(word);
  }

  int answer = 0;
  for (const string& word : words) {
    int gain = S[word] - T[word];
    answer = max(answer, gain);
  }
  cout << answer;

  return 0;
}


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

int main(){
int n;
  cin>>n;
  int sum=0;
  int i=0;
  do{
    sum+=i;
    i++;
  }while(sum<=n);
  int div = sum - n;
  for(int k=1;k<i;++k){
    if(k==div) continue;
    cout << k<<endl;
  }
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
using namespace std;
typedef long long int ll;
const int k_mod = 1e9 + 7;
void chmin( int &a, int b ){
	if (a > b)
		a = b;
	return;
}

int main( void ){
	int n, k;
	cin >> n >> k;
	int* array = new int[ n ];
	rep( i, 0, n ){
		cin >> array[ i ];
	}
	int* dp = new int[ n ]();
	rep(i,1,n){
		dp[i] = k_mod;
	}
	rep( i, 1, n ){
		for(int j = 1; j <= k && i - j > -1; j++){
			chmin( dp[ i ], dp[ i - j ] + abs( array[ i ] - array[ i - j ] ));
		}
		// rep(i,0,n){
		// 	cout << dp[i]<<", ";
		// }
		// printf("\n");
	}
	printf( "%d\n", dp[ n - 1 ] );
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int pre = a[0], ff = 1;
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    if (a[i] == pre) {
      ff++;
    } else {
      pre = a[i];
      ans += ff / 2;
      ff = 1;
    }
  }
  ans += ff / 2;
  cout << ans << endl;
}

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

int main() {
    int N; cin >> N;
    int sum = 0;
    vector<int> X(N); for(int i = 0; i < N; i++) {cin >> X[i]; sum += X[i];}
    sum /= N;
    int a = 0;
    int b = 0;
    int c = 0;
    for (int i = 0; i < N; i++) {
        a += (X[i] - sum) * (X[i] - sum);
        b += (X[i] - sum + 1) * (X[i] - sum + 1);
        c += (X[i] - sum - 1) * (X[i] - sum - 1);
    }
    cout << min(a, min(b, c)) << endl;
}


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

int main() {
  int N, K; cin >> N >> K;
  string S; cin >> S ;
  if (S.at(K-1)=='A') S.at(K-1)='a';
  if (S.at(K-1)=='B') S.at(K-1)='b';
  if (S.at(K-1)=='C') S.at(K-1)='c';
  cout << S << endl;
}
  


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

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int64_t> B(N-1);
  int64_t ans=0;
  for(int i=0;i<N-1;i++){
    cin >> B.at(i);
  }
  for(int i=0;i<N-2;i++){
    int k=0;
    k=min(B.at(i),B.at(i+1));
    ans=ans+k;
  }
  ans=ans+B.at(0)+B.at(N-2);
  cout << ans << endl;
  return 0;
}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 H,W;
    cin >> H >> W;

    vector<string> A(H);
    rep(i,0,H) cin >> A[i];

    i64 ans=0;
    queue<pair<i64,i64>> que;
    vector<vector<i64>> dist(H,vector<i64>(W,inf64));
    rep(i,0,H){
        rep(j,0,W){
            if(A[i][j]=='.') continue;
            que.push(make_pair(i,j));
            dist[i][j]=0;
        }
    }

    vector<i64> dx={1,0,-1,0},dy={0,-1,0,1};
    while(!que.empty()){
        auto p=que.front();
        que.pop();

        i64 i=p.first,j=p.second;
        chmax(ans,dist[i][j]);
        rep(k,0,4){
            i64 ni=i+dx[k],nj=j+dy[k];
            if(ni<0 or H<=ni or nj<0 or W<=nj) continue;
            if(dist[i][j]+1>=dist[ni][nj]) continue;
            dist[ni][nj]=dist[i][j]+1;
            chmax(ans,dist[ni][nj]);
            que.push(make_pair(ni,nj));
        }
    }

    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

using namespace std;

const int N = 100010;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    s[k - 1] += 'a' - 'A';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d) {
		cout << "Left" << endl;
	}
	else if (a + b == c + d) {
		cout << "Balanced" << endl;
	}
	else {
		cout << "Right" << endl;
	}
	int y;
	cin >> y;
}

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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

int main() {
  cout << setprecision(18);
  u32 N;
  cin >> N;
  u64 res = 0;
  for (u32 i = 1; i <= N; ++i) {
    if (i % 3 != 0 && i % 5 != 0) res += i;
  }
  cout << res << endl;
}


Measured memory_bytes: 3644
import numpy as np
N, M = map(int, input().split())
cities = {}
P = {}
Y = {}
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = p
    Y[i] = y

ans = {}
sorted_Y = sorted(Y.items(), key=lambda x:x[1])
P_i = np.zeros(N)
for i,y in sorted_Y:
    p = cities[i]
    P_i[p-1] += 1
    ans[i] = (p, int(P_i[p-1]))

for i in range(M):
    print('{0:06}{1:06}'.format(ans[i][0], ans[i][1]))


Measured memory_bytes: 62228
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < n; i++) ans += sc.nextInt() - 1;
        System.out.println(ans);
    }    
}


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

const int INF = 1000000007;

int G[15][15];
int dp[1 << 15][15][15];

int main(){
    int V, E;
    scanf("%d%d", &V, &E);
    for(int i = 0; i < V; i++){
        fill(G[i], G[i] + V, INF);
        G[i][i] = 0;
    }
    for(int i = 0; i < E; i++){
        int s, t, d;
        scanf("%d%d%d", &s, &t, &d);
        G[s][t] = d;
    }
    for(int i = 0; i < (1 << 15); i++){
        for(int j = 0; j < 15; j++){
            for(int k = 0; k < 15; k++){
                dp[i][j][k] = INF;
            }
        }
    }
    for(int i = 0; i < 15; i++){
        dp[0][i][i] = 0;
    }
    for(int b = 0; b < (1 << V); b++){
        for(int i = 0; i < 15; i++){
            for(int j = 0; j < 15; j++){
                for(int k = 0; k < 15; k++){
                    if(((b >> k) & 1) == 0 && G[j][k] < INF){
                        int next_b = b | (1 << k);
                        dp[next_b][i][k] = min(dp[next_b][i][k],
                                               dp[b][i][j] + G[j][k]);
                    }
                }
            }
        }
    }
    int ans = INF;
    for(int i = 0; i < V; i++){
        ans = min(ans, dp[(1 << V) - 1][i][i]);
    }
    if(ans < INF){
        printf("%d\n", ans);
    }else{
        puts("-1");
    }
    return 0;
}

Measured memory_bytes: 29992
import sys
n,m,x=map(int,input().split())
A=[]
for i in range(n):
    ca=list(map(int,input().split()))
    A.append(ca)
ans=10**7

for i in range(2**n):#n冊をそれぞれ選ぶか選ばないか
    tmp=[0]*m
    cost=0
    for j in range(n):#ある選び方
        if (1<<j)&i:
            cost+=A[j][0]
            for k in range(m):
                tmp[k]+=A[j][k+1]
    for l in range(m):#理解度がx以上か判定
        if tmp[l]<x:
            break
    else:
        ans=min(ans,cost)#すべてのアルゴリズムの目標理解度を満たすとき
if ans==10**7:#ansが更新されない場合(for文が最後まで実行されるとelseが実行)
    ans=-1
print(ans)




Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    if (n % 1000 > 0){
        cout << 1000 - (n % 1000) << endl;
    }
    else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    char a[100],b[100];
	cin >> a;
	b[2]=a[0];
	b[1]=a[1];
	b[0]=a[2];
	if(strcmp(a,b)==0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
ans = 0
while(True) :
    if N <= 9 :
        ans += N
        break
    else :
        ans += 9
    if N >= 100 :
        if N < 1000 :
            ans += N - 100 + 1
            break
        else :
            ans += 900
    else :
        break
    if N >= 10000 :
        if N < 100000 :
            ans += N - 10000 + 1
            break
        else :
            ans += 90000
            break
    else :
        break
print(ans)

Measured memory_bytes: 3060
import java.util.*;
 
public class Main {
    public static void main(String args[]){
         Scanner sc = new Scanner(System.in);          
         int a = sc.nextInt();
         int b = sc.nextInt();
         
         System.out.printf("%d %d %.8f", a / b, a % b, (double)a / (double)b);
}
}


Measured memory_bytes: 26452
def enq(a,x)
  b = a[i=-1]
  until b.frozen?
    return a << x  if x >= (a=b)[-1]
    return a.unshift x  if x <= a[0]
    b = a[i = a.bsearch_index{|y| x < (y.frozen? ? y: y[0])}-1]
  end  if b && b=a
  a[i+9] or return a.insert i+1, x
  i>0 ? a[i]=[b,x] : enq(a[i+=1].to_a,x)  rescue a[i]=[x,a[i]]
end
def deq(a) r=a.shift; a[0].frozen? or a.unshift *a.shift; r end
def poq(a) r=a.pop; a[-1].frozen? or a.push *a.pop; r end
N,M,*A = $<.read.split.map{|x| -x.to_i}
A.sort!
(-M).times { break if A[0]==0; enq A, -(-(deq A)/2)}
p A.flatten.inject(0,:-)

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

int main(){
  int a, b;
  cin >> a >> b;
  if(a < b) cout << "a < b" << endl;
  else if(a > b) cout << "a > b" << endl;
  else if(a == b) cout << "a == b" << endl;
}


Measured memory_bytes: 3092
import java.util.Scanner;

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

        int N = sc.nextInt();

        System.out.println(solve(N));

        sc.close();
    }

    static int solve(int N) {
        return N * 800 - N / 15 * 200;
    }
}

Measured memory_bytes: 23764