akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int h, w;
vstr s;
vint dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};

int bfs(int sx, int sy) {
    queue<P> que;
    que.push(P(sx, sy));
    vvint d(h, vint(w, INF));
    d[sx][sy] = 0;

    while (que.size()) {
        P p = que.front();
        que.pop();
        rep(i, 4) {
            int nx = p.fi + dx[i], ny = p.se + dy[i];

            if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != '#' && d[nx][ny] == INF) {
                que.push(P(nx, ny));
                d[nx][ny] = d[p.fi][p.se] + 1;
            }
        }
    }
    int mx = 0;
    rep(i, h) rep(j, w) {
        if (d[i][j] != INF && d[i][j] > mx) mx = d[i][j];
    }
    return mx;
}

int main() {
    cin >> h >> w;
    s.resize(h);

    rep(i, h) cin >> s[i];

    int ans = 0;
    rep(i, h) rep(j, w) {
        if (s[i][j] != '#') {
            ans = max(ans, bfs(i, j));
        }
    }

    cout << ans << endl;
    return 0;
}

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

fun solve(N: Long, A: LongArray){
    if (N == 2L){
        println(A.max())
        return
    }
    var ans = 0L
    val dp = Array<LongArray>(2){ LongArray(N.toInt()) }
    dp[0][0] = A[0]
    dp[1][N.toInt() - 1] = A[N.toInt() - 1]
    for (i in 1 until N.toInt()){
        dp[0][i] = gcd(dp[0][i-1], A[i])
    }
    for ( i in (N-2L).toInt() downTo 0 ){
        dp[1][i] = gcd(dp[1][i+1], A[i])
    }
    var s = 0L
    for ( i in 0 until N.toInt()){
        if (i == 0){ s = dp[1][1] }
        else if (i == N.toInt() - 1){ s = dp[0][N.toInt() - 2] }
        else{
            s = gcd(dp[0][i - 1], dp[1][i + 1])
        }
        ans = Math.max(s, ans)
    }
    println(ans)
    return
}

fun gcd(x: Long, y: Long): Long = if (y == 0L) x else gcd(y, x % y)

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val A = LongArray(N.toInt())
    for (i in 0 until N.toInt()) {
        A[i] = sc.next().toLong()
    }
    solve(N, A)
}


Measured memory_bytes: 43688
#include<iostream>
using namespace std;
int w,h,xs,ys,xg,yg,n;
int map[101][101];
string ans;
char start;
void fun(int y,int x){
    if(map[y][x]==start){
        map[y][x]=7;
    }
    else
        return;
    if(x<1||w<x||y<1||h<y)
        return;
    if(map[y][x]==map[yg][xg]){
        ans="OK";
        return;
    }
    fun(y,x+1);
    fun(y,x-1);
    fun(y+1,x);
    fun(y-1,x);
}
void mc(){
    int c,d,x,y;
    for(int i=0;i<n;i++){
        cin >> c >> d >> x >> y;
        if(d==0){
            for(int j=0;j<2;j++){
                for(int k=0;k<4;k++){
                    map[y+j][x+k]=c;
                }
            }
        }
        else{
            for(int j=0;j<4;j++){
                for(int k=0;k<2;k++){
                    map[y+j][x+k]=c;
                }
            }
        }
    }
}
int main(){
    while(cin >> w >> h,w){
    	ans="NG";
        cin >> xs >> ys >> xg >> yg >> n;
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                map[i][j]=0;
            }
        }
        mc();
        start=map[ys][xs];
        if(map[ys][xs]==0||map[yg][xg]==0);
        else
        	fun(ys,xs);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3192
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main()
{
	string a;
	bool flag=false;
	int n;
	cin>>a;
	for(int i=0;i<a.size()-1;i++)
		if(a[i]=='C') 
		{
			flag=true;
			n=i;
			break;
		}
	if(flag) 
	{
		for(int i=n+1;i<a.size();i++)
		if(a[i]=='F')
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

int main(){
  int N;
  string c;
  cin >> N >> c;
  int wn = 0;
  int rr = 0;
  int ans = 0;
  REP(i,N) if ( c[i] == 'W' ) wn++;
  if ( wn != 0 && wn != N ){
    REP(i,wn) if ( c[N-wn+i] == 'R' ) rr++;
    ans = rr;
  }
  cout << ans << endl;

}


Measured memory_bytes: 3760
#include <vector>
#include <iostream>
#include <algorithm>

struct City {
	int P, Y, num;
};

bool cmp(City *a, City *b) {
	if (a->P == b->P) {
		return (a->Y < b->Y);
	}
	return (a->P < b->P);
}

bool cmp1(City *a, City *b) {
	return (a->num < b->num);
}

int main(void) {
	int N, M;
	std::cin >> N >> M;
	std::vector<City*> cities;

	for (int i = 0; i < M; i++) {
		City *c = new City();
		c->num = i;
		std::cin >> c->P >> c->Y;
		cities.push_back(c);
	}
	std::sort(cities.begin(), cities.end(), cmp);
	int num = 1;
	for (int i = 0; i < M - 1; i++) {
		if (cities[i]->P == cities[i + 1]->P) {
			cities[i]->Y = num++;
		} else {
			cities[i]->Y = num;
			num = 1;
		}
	}
	if (cities[M - 1]->P == cities[M - 1]->P)
		cities[M - 1]->Y = num;
	else
		cities[M - 1]->Y = ++num;
	std::sort(cities.begin(), cities.end(), cmp1);
	for (int i = 0; i < M; i++) {
		printf("%06d%06d\n", cities[i]->P, cities[i]->Y);
	}
	return 0;
}

Measured memory_bytes: 5364
//#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
//#include <iomanip>
#include <vector>
#include <string>
//#include <algorithm>
//#include <functional>
//#include <cmath>
//#include <time.h>

using namespace std;


int main(){

	int n, k1, k2, left, right, buf, flag;
	string s1, s2 , out;
	int aa1[10], aa2[10], ans[11];

	cin >> n;

	for (int nn = 0; nn < n; nn++){
		for (int i = 0; i < 10; i++){
			aa1[i] = 0;
			aa2[i] = 0;
			ans[i] = 0;
		}
		ans[10] = 0;
		flag = 0;

		cin >> s1 >> s2;
		k1 = s1.size();
		k2 = s2.size();

		if (k1 > 80 || k2 > 80){
			cout << "overflow" << endl;
		}
		else{
			buf = 8 - k1 % 8;
			for(int i = 0; i < buf; i++){
				s1.insert(0,"0");
			}
			buf = 8 - k2 % 8;
			for (int i = 0; i < buf; i++){
				s2.insert(0, "0");
			}
			left = s1.size()-8;
			for (int i = 0; i < 10; i++){
				aa1[i] = atoi(s1.substr(left, 8).c_str());
				left -= 8;
				if (left < 0)break;
			}
			left = s2.size() - 8;
			for (int i = 0; i < 10; i++){
				aa2[i] = atoi(s2.substr(left, 8).c_str());
				left -= 8;
				if (left < 0)break;
			}

			for (int i = 0; i < 10; i++){
				ans[i] += aa1[i] + aa2[i];
				if (ans[i] >= 100000000){
					ans[i + 1] += 1;
					ans[i] -= 100000000;
				}
			}
			if (ans[10] >= 1){
				cout << "overflow" << endl;
			}
			else{
				for (int i = 9; i >= 0; i--){
					if (flag == 0){
						if (ans[i] != 0){
							printf("%d",ans[i]);
							flag = 1;
						}
					}
					else{
						printf("%08d", ans[i]);
					}
				}
				if (flag == 0)cout << 0;
				cout << endl;
			}
		}

	}
	
	return 0;
}

Measured memory_bytes: 1276
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int A, B;
	long result;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		A = Integer.parseInt(tokens[0]);
		B = Integer.parseInt(tokens[1]);
	}

	int gcd(int large, int small) {
		if (large < small) {
			return gcd(small, large);
		}
		if (large % small == 0) {
			return small;
		}
		return gcd(small, large % small);
	}

	void calc() {
		int gcd = gcd(A, B);
		result = (long) A * (long) B / (long) gcd;
	}

	void showResult() {
		System.out.println(result);
	}
}


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

int N, M;
vector<int> G[8];

int dfs(int s, bool visited[8]) {
    visited[s] = true;
    bool done = true;
    for(int i=0; i<N; i++) {
        if(!visited[i]) {
            done = false;
            break;
        }
    }
    if(done){
        visited[s] = false;
        return 1;
    }
    int sum = 0;
    for(int i=0; i<G[s].size(); i++) {
        if(!visited[G[s][i]]){
            sum += dfs(G[s][i], visited);
        }
    }
    visited[s] = false;
    return sum;
}

int main() {
    cin >> N >> M;
    for(int i=0; i<M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    bool visited[8];
    for(int i=0; i<N; i++) visited[i] = false;
    cout << dfs(0, visited) << endl;
    return 0;
}


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

using namespace std;

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

    vector<int> v(N);
    for(int i=0;i<N;i++){
        cin>>v[i];
    }
    sort(v.begin(),v.end());

    cout<<v[N-1]- v[0];
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e5 + 10, S2 = 1e7 * 2;

ll cnt[52][27];



int main() {
    fastInp;

    ll n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        string t;
        cin >> t;
        for (auto a : t) {
            cnt[i][a - 'a']++;
        }
    }

    ll ans = 0;
    string k;
    for (int i = 0; i < 26; i++) {
        ll cur = INT64_MAX;
        for (int j = 0; j < n; j++) {
            cur = min(cur, cnt[j][i]);
        }
        for (int j = 0; j < cur; j++) k.push_back(i + 'a');
    }

    cout << k;
    return 0;
}



Measured memory_bytes: 256
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      998244353
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    pll                      pair <long long int , long long int>
#define    ppl                      pair <long long int , pll>              //pair of ll and pair ll 
#define    sp(x)                    setprecision(x)


int32_t main()
{
    speed upp
   int n,k;
   cin>>n>>k;
   if(n*500>=k)
    cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 256
h,w=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(2*h)]
board=[[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    board[i][j]+=arr[i][j]
for i in range(h):
  for j in range(w):
    board[i][j]=abs(board[i][j]-arr[h+i][j])
dp=[[set() for _ in range(w)] for _ in range(h)]
dp[0][0].add(board[0][0])
for i in range(h):
  for j in range(w):
    if i!=0:
      for k in dp[i-1][j]:
        dp[i][j].add((k+board[i][j])%640)
        dp[i][j].add(abs(k-board[i][j])%640)
    if j!=0:
      for k in dp[i][j-1]:
        dp[i][j].add((k+board[i][j])%640)
        dp[i][j].add(abs(k-board[i][j])%640)
print(min(dp[h-1][w-1]))

Measured memory_bytes: 229768
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    
    std::cout << std::fixed;
    std::cout << a/b << " ";
    std::cout << a%b << " ";
    std::cout << std::setprecision(8) << (double)a/b << "\n"; // "3.14"
}



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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

ll MOD = 1000000007;

ll modPow(ll a, int p) {
	if (p == 0) {
		return 1;
	}

	
	if (p % 2 == 0) {
		int halfP = p / 2;
		ll half = modPow(a, halfP);
		return half * half % MOD;
	} else {
		return a * modPow(a, p - 1) % MOD;
	}
}

ll calcComb(int a, int b) {
	if (b > a - b) {
		return calcComb(a, a - b);
	}

	ll ansMul = 1, ansDiv = 1;
	for (int i = 0; i < b; i++) {
		ansMul *= (a - i) ;
		ansMul %= MOD;

		ansDiv *= (i + 1);
		ansDiv %= MOD;
	}

	ll ans = ansMul * modPow(ansDiv, MOD - 2) % MOD;

	return ans;
}

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

	int n, m;
	cin >> n >> m;

	int mNokori = m;
	ll ans = 1;

	for (int i = 2; i * i <= mNokori; i++) {
		if (mNokori % i == 0) {
			int cnt = 0;
			while (mNokori % i == 0) {
				cnt++;
				mNokori /= i;
			}
			ans *= calcComb(n + cnt - 1, cnt);
			ans %= MOD;
		}
	}

	if (mNokori != 1) {
		ans *= calcComb(n + 1 - 1, n - 1);
		ans %= MOD;
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int x,y,p=0,q=0,i,a[7]={1,3,5,7,8,10,12},b[4]={4,6,9,11};
	scanf("%d %d", &x, &y);
	for(i=0; i<7; i++)
	{
		if(a[i]==x||a[i]==y)
		p++;
	}
	for(i=0; i<4; i++)
	{
		if(b[i]==x||b[i]==y)
		q++;
	}
	if(p>1||q>1)
	printf("Yes\n");
	else
	printf("No\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    int count=0;
    while(true){
        bool a=false;
        for(int i=1;i<=N;i++){
            if(i%2==0) a=true;
        }
        if(a){
            N/=2;
            count++;
        }
        else break;
    }
    int b=1;
    for(int i=0;i<count;i++){
        b*=2;    
    }
    cout << b << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0; i<N; i++) cin >> L[i];

  bool ans = true;
  for(int i=0; i<N; i++){
    int sum = 0;
    for(int j=0; j<N; j++){
      if(i==j) continue;
      sum += L[j];
    }
    if(L[i] >= sum) ans = false;
  }
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
  // cout << fixed;//小数点を確実に10桁で表示するためのもの
  // cout << setprecision(10); 
}


Measured memory_bytes: 3612
while
  l = gets.to_i
  exit if l == 0
  s = 0
  ans = 0
  12.times do |i|
    m, n = gets.split.map(&:to_i)
    if l > 0
      l -= m - n
      ans = i + 1 if l <= 0
    end
  end
  puts ((ans > 0) ? ans : 'NA')
end

Measured memory_bytes: 6104
#include <iostream>
#include <math.h>
int l[1001];
int r[1001];
int main(){

    int N;
    std::cin >> N;
    int num = 0;
    for(int i=0;i < N;++i){
        std::cin >> l[i] >> r[i];
    }
    for(int i=0;i < N; ++i){
        num += (r[i] - l[i])+1;
    }
    std::cout << num << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  map<ll, ll> b, c;
  for (int i = 0; i < n; i++){
    if (i % 2){
      c[a[i]]++;
    }
    else 
      b[a[i]]++;
  }

  vector<P> bs(0), cs(0);
  for (auto p : b){
    bs.emplace_back(P(p.second, p.first));
  }
  for (auto p : c){
    cs.emplace_back(P(p.second, p.first));
  }
  sort(bs.begin(), bs.end());
  sort(cs.begin(), cs.end());
  
  if (bs[bs.size()-1].second == cs[cs.size()-1].second){
    if (bs.size() == 1){
      if (cs.size() == 1){
        cout << n/2 << endl;
      }
      else {
        cout << n/2 - cs[cs.size()-2].first << endl;
      }
    }
    else {
      if (cs.size() == 1)
        cout << n/2 - bs[bs.size()-2].first << endl;
      else {
        ll s = bs[bs.size()-1].first + cs[cs.size()-2].first;
        ll t = bs[bs.size()-2].first + cs[cs.size()-1].first;
        cout << n - max(s, t) << endl;
      }
    }
  }
  else
    cout << n - bs[bs.size()-1].first - cs[cs.size()-1].first << endl;

  return 0;
}


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

int main() {
	long n,i,cur;
	string s;
	cin >> s;
	n=s.size();
	vector<long> ans(n+1,0);
	for(i=0; i<n; i++){
		if(s[i]=='<'){
			ans[i+1]=ans[i]+1;
		}
	}
	
	for(i=0; i<n; i++){
		if(s[n-1-i]=='>'){
			ans[n-1-i]=max(ans[n-i]+1,ans[n-1-i]);
		}
	}
	
	cur=0;
	for(i=0; i<n+1; i++){
		cur+=ans[i];
	}
	cout << cur << endl;
	return 0;
}

Measured memory_bytes: 4740
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		System.out.println(solve());
	}

	public static int solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] t = new int[N];

		for (int i = 0; i < N; i++) {
			t[i] = sc.nextInt();
		}

		int k = 1;
		int sum = 0;
		for (int j = 0; j < N; j++) {
			if (t[j] == k) {
				sum++;
				k++;
			}
		}

		int res = N - sum;
		if (sum == 0) {
			res = -1;
		}

		return res;
	}
}


Measured memory_bytes: 86360
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vaibhav ios_base::sync_with_stdio(false);cin.tie(NULL);
int n;
void dfs(vector<int>v[],ll ans[],int col[],int i, ll val)
{
   ans[i]=ans[i]+val;
   for(int j=0;j<v[i].size();j++)
   {
    int x=v[i][j];
    if(col[x]==0)
    {
      col[x]=1;
      dfs(v,ans,col,x,ans[i]);
    }
   }

}

int main()
{ vaibhav

  int q;
  cin>>n>>q;
  vector<int>v[n+1];
  int a,b;
  for(int i=0;i<n-1;i++)
  {
    cin>>a>>b;
    v[a].push_back(b);
    v[b].push_back(a);

  }
  ll ver,val;
  ll ans[n+1]={0};
  for(int i=0;i<q;i++)
  {
    cin>>ver>>val;
    ans[ver]=ans[ver]+val;

  }
  int col[n+1]={0};
  col[1]=1;
  dfs(v,ans,col,1,0);

  for(int i=1;i<=n;i++)
    cout<<ans[i]<<" ";
  return 0;
  
}

 

Measured memory_bytes: 28160
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

float mean(vector<float> v) {
    int size = v.size();
    float sum = 0;
    for (int i = 0; i < size; i++){
        sum += v[i];
    }
    return sum / size;
}

int main(){

	while(1){
		int N;
		cin >> N;
		if(N == 0){
			break;
		}

		vector<float> data(N);

		rep(i,data.size()){
			cin >> data[i];
		}

		sort(data.begin(),data.end());
		
		data.pop_back();
		data.erase(data.begin());

		cout << int(mean(data)) << endl;
	}

	return 0;
}

Measured memory_bytes: 1260
n = int(input())
a = list(map(int,input().split()))

li = {}
for i in range(n):
    if a[i] in li:
        li[a[i]] += 1
    else:
        li[a[i]] = 1

ans = 0
for i in li:
    if i==li[i]:
        continue
    elif i>li[i]:
        ans += li[i]
    elif i<li[i]:
        ans += li[i]-i
print(ans)

Measured memory_bytes: 17780
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
ll n,k,A[200001],B[200001],ans=0;
vector<ll> C;
int search(){
    ll b;
    for(int i=60;i>=0;i--){
        ll c=pow(2,i);
        ll a=0;
        rep(j,C.size()) if(C[j]>=c&&(c^C[j])==C[j]-c) a++;
        if(a>=k){ans+=pow(2,i);b=pow(2,i);break;}
        if(i==0) return 0;
    }
    vector<ll> D;
    rep(i,C.size()) if(C[i]>=b&&(b^C[i])==C[i]-b) D.push_back(C[i]-b);
    C=D;
    search();
}
int main(){
    cin>>n>>k;
    rep(i,n) cin>>A[i];
    B[0]=0;
    rep(i,n) B[i+1]=A[i]+B[i];
    rep(i,n+1)rep(j,n+1) if(i<j) C.push_back(B[j]-B[i]);
    sort(C.begin(),C.end());
    search();
    cout<<ans;
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

template <int MOD>
struct Fp
{
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD)
    {
        if (val < 0)
            val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator-() const noexcept
    {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp &operator+=(const Fp &r) noexcept
    {
        val += r.val;
        if (val >= MOD)
            val -= MOD;
        return *this;
    }
    constexpr Fp &operator-=(const Fp &r) noexcept
    {
        val -= r.val;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr Fp &operator*=(const Fp &r) noexcept
    {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp &operator/=(const Fp &r) noexcept
    {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b)
        {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr Fp &operator++() noexcept
    {
        val++;
        if (val >= MOD)
            val -= MOD;
        return *this;
    }
    constexpr Fp operator++(int) noexcept
    {
        Fp temp = *this;
        ++*this;
        return temp;
    }
    constexpr Fp &operator--() noexcept
    {
        val--;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr Fp operator--(int) noexcept
    {
        Fp temp = *this;
        --*this;
        return temp;
    }
    constexpr bool operator==(const Fp &r) const noexcept
    {
        return this->val == r.val;
    }
    constexpr bool operator!=(const Fp &r) const noexcept
    {
        return this->val != r.val;
    }
    friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept
    {
        return os << x.val;
    }
};

template <int MOD>
constexpr Fp<MOD> powmod(const Fp<MOD> &a, long long n) noexcept
{
    if (n == 0)
        return 1;
    if (n % 2 == 1)
        return a * powmod(a, n - 1);
    Fp<MOD> pwmd = powmod(a, n / 2);
    return pwmd * pwmd;
}

using mint = Fp<1000000007>;

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

    mint ans = 0;
    for (i64 m = k; m < n + 2; m++)
    {
        ans += m * n - m * (m - 1) + 1;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,k;
	cin >> n >> k;
	vector<long long> a(n);
	for(int i=0;i<n;i++) cin >> a[i];
	
	vector<long double> b(n+1);
	for(int i=0;i<n;i++){
		b[i+1]=b[i]+a[i]+1;
	}
	
	long long mx=0;
	for(int i=1;i<=n;i++){
		if((i-k)<0) continue;
		long long te=b[i]-b[i-k];
		mx=max(mx,te);
	}
	cout.precision(20);
	cout << (mx/2.0L) << "\n";
	return 0;
}

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

const ll MAX = 510000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    COMinit();

    // 求める
    for (ll i = 1; i <= k; ++i)
        cout << COM(k-1, i-1) * COM(n-k+1, i) % MOD << endl;
}


Measured memory_bytes: 12160
# coding: utf-8
# Your code here!

N,M = [int(i) for i in input().split()]


numbers = ['0'] * N
flags = [False] * N
result = True

for _ in range(M):
    s,c = input().split()
    s = int(s)
    if flags[s-1]:
        if numbers[s-1] != c:
            result = False
            break
    else:
        flags[s-1] = True
        numbers[s-1] = c

if not result or len(numbers) > 1 and numbers[0] == '0' and flags[0]:
    print(-1)
elif len(numbers) == 1:
    print(numbers[0])
else:
    if numbers[0] == '0':
        numbers[0] = '1'
    print(''.join(numbers))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
typedef long long ll;
using namespace std;
int v[10001], w[10001];
int cache[3001][3001];
pair<int, int> p[3001][3001];
int calc(string &s, int S, string &t, int T) {
	if(S==0 || T==0) {
		return 0;
	}
	
	if(cache[S][T]!=-1) {
		return cache[S][T];
	}
	
	int mx = 0;
	if(s[S-1]==t[T-1]) {
		mx = calc(s, S-1, t, T-1) + 1;
	}
	
	int one = calc(s, S-1, t, T);
	int two = calc(s, S, t, T-1);
	
	/*if(two >= mx && two>=one) {
		p[S][T] = make_pair(S, T-1);
	}
	if(one >= mx && one>=two) {
		p[S][T] = make_pair(S-1, T);
	}
	if(mx >= one && mx>=two) {
		p[S][T] = make_pair(S-1, T-1);
	}*/
	return cache[S][T] = max(mx, max(one,two));
}

string print(string s, string t, int l, int r) {
	if(l==0 || r==0) {
		return "";
	}
	
	if(s[l-1]==t[r-1]) {
		return print(s,t,l-1, r-1) + s[l-1];
	}
	
	if(cache[l-1][r] > cache[l][r-1]) {
		return print(s, t, l-1, r);
	}
	
	return print(s, t, l, r-1);
}
int main() {
	string s,t;
	cin>>s>>t;
	int dp[3001][3001];
	for (int i=0; i<=3000; i++) {
		for (int j=0; j<=3000; j++) {
			dp[i][j] = -1;
		}
	}
	for (int i=0; i<=s.size(); i++) {
		for (int j=0; j<=t.size(); j++) {
			if(i==0 || j==0) {
				dp[i][j] = 0;
			}else {
				if(s[i-1]==t[j-1]) {
					dp[i][j] = dp[i-1][j-1] + 1;
				} else {
					dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
				}
			}
		}
	}
	//cout << dp[s.size()][t.size()] << endl;
	int l = s.size();
	int	r = t.size();
	string w = "";
	while(l>0 && r>0) {
		if(s[l-1] == t[r-1]) {
			w = s[l-1] + w;
			l--;
			r--;
		} else if(dp[l-1][r] > dp[l][r-1]) {
			l--;
		} else {
			r--;
		}
	}
	cout << w;
	return 0;
}

Measured memory_bytes: 35584
#include "bits/stdc++.h"
#define pb push_back
#define mt make_tuple
#define all(a) (a).begin(),(a).end()
#define rep(i, n) for(int i=0;i<(n);++i)
#define rrep(i, n) for(int i=n-1;i>=0;--i)
#define debug(x) cout << #x << " : " << x << " ------------ " << endl;
using namespace std;
using TP = tuple<int, int>;
struct Record {
    int id, c, p;
    int wrong[11];
    bool operator<(const Record& rhs) const {
        if (c > rhs.c) return true;
        else if (c < rhs.c) return false;
        if (p < rhs.p) return true;
        else if (p > rhs.p) return false;
        if (id < rhs.id) return true;
        else return false;
    }
};
int main()
{
    int t, p, r;
    while (cin >> t >> p >> r, t | p | r) {
        map<TP, bool> solved;
        Record records[t + 1];
        rep (i, t + 1) {
            records[i] = {i, 0, 0};
        }
        rep (i, r) {
            int tid, pid, time;
            string msg;
            cin >> tid >> pid >> time >> msg;
            
            if (solved[tie(tid, pid)]) continue;
            
            if (msg == "CORRECT") {
                solved[tie(tid, pid)] = true;
                ++records[tid].c;
                records[tid].p += time + 1200 * records[tid].wrong[pid];
            } else {
                ++records[tid].wrong[pid];
            }
        }
        sort(records, records+t+1);
        for (auto rec : records) {
            if (rec.id != 0)
                cout << rec.id << " " << rec.c << " " << rec.p << endl;
        }
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3224
#Dギャンブル

n, k = map(int, input().split())
s=input()
kfk = []

for i in range(n):
    if s[i] == "L" and i == 0:
        kfk.append(0)
    elif s[i] == "L" and i != 0:
        if s[i-1] == "L":
            kfk.append(1)
        else:
            kfk.append(0)
    elif s[i] == "R" and i == (n-1):
        kfk.append(0)
    elif s[i] == "R" and i != (n-1):
        if s[i+1] == "R":
            kfk.append(1)
        else:
            kfk.append(0)

ans = sum(kfk) + (2 * k)
if ans < (n-1):
    print(ans)
else:
    print(n-1)

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

using namespace std;

int main()
{
  long long N, W; cin >> N >> W;
  long long dp[110][100100] = {0};

  for (long long  i = 0; i < N; i++) {
    long long w, v; cin >> w >> v;

    for (long long sum_w = 0; sum_w <= W; sum_w++) {
      if (sum_w - w >= 0) {
        dp[i + 1][sum_w] = dp[i][sum_w - w] + v;
      }
      dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w]);
    }
  }

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

  return 0;
}

Measured memory_bytes: 86272
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "next", long, "cost");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto a = new long[](n);
    n.iota.each!(x => a[x] = lread());
    auto dp = new long[][](n, 2);
    dp[0][0] = a[0] / 2;
    dp[0][1] = a[0] ? (a[0] - 1) / 2 : -INF;
    foreach (i; iota(n - 1))
    {
        dp[i + 1][0] = max(dp[i][0] + a[i + 1] / 2, dp[i][1] + (a[i + 1] + 1) / 2);
        dp[i + 1][1] = a[i + 1] ? max(dp[i][0] + (a[i + 1] - 1) / 2, dp[i][1] + a[i + 1] / 2) : -INF;
    }
    // dp.each!(x => x.writeln());
    max(dp[n - 1][0], dp[n - 1][1]).writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

class DisjointSet {
    public:
    vector<int> rank, p, s;

    DisjointSet(int size) {
        rank.resize(size);
        p.resize(size);
        s.resize(size);
        for(size_t i = 0; i < size; i++)
        {
            makeSet(i);
        }
    }
    void makeSet(int x) {
        p[x] = x;
        rank[x] = 0;
        s[x] = 1;
    }
    bool same(int x, int y) {
        return findSet(x) == findSet(y);
    }
    void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }
    void link(int x, int y) {
        if (x == y) return;
        if (rank[x] > rank[y]) {
            p[y] = x;
            s[x] += s[y];
        }
        else{
            p[x] = y;
            s[y] += s[x];
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }
    int size(int x){
        return s[findSet(x)];
    }
    int findSet(int x){
        if (x != p[x]){
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    for(size_t i = 0; i < M; i++)
    {
        cin >> A[i] >> B[i];
    }
    int ret = 0;
    for(size_t i = 0; i < M; i++)
    {
        DisjointSet set(N);
        for(size_t j = 0; j < M; j++)
        {
            if (j != i){
                set.unite(A[j]-1, B[j]-1);
            }
        }
        if (set.size(0) != N)
            ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll allsum = b - a +1;
	ll Ccount = b / c - a / c;
	if (a % c == 0) {
		Ccount++;
	}
	ll Dcount = b / d - a / d;
	if (a % d == 0) {
		Dcount++;
	}
	ll x = c*d/gcd(c, d);
	ll xcount = b / x - a / x;
	if (a % x == 0) {
		xcount++;
	}
	ll ans = Ccount + Dcount - xcount;
	cout << allsum - ans << endl;
	return 0;
}


Measured memory_bytes: 256
#
a,b,m=map(int, input().split())

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
#
m_l = []
for i in range(m):
    m_l.append(list(map(int, input().split())))
score = float('inf')
min_norm = min(a_l) + min(b_l)
sale_l = []
for m_ in m_l:
    sale_l.append(a_l[m_[0]-1]+b_l[m_[1]-1] - m_[-1])
print(min(min_norm,min(sale_l)))

Measured memory_bytes: 42412
package main

import (
	"fmt"
	"math"
	"os"
)

func main() {
	var A, B, K int
	var count int = 0
	fmt.Scan(&A, &B, &K)
	min := math.Min(float64(A), float64(B))
	for i := int(min); i > 0; i-- {
		if A%i == 0 && B%i == 0 {
			count++
		}
		if count == K {
			fmt.Println(i)
			os.Exit(0)
		}
	}
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


struct UF
{
    vector<long> par;
    vector<long> rank;

    UF(long n)
    {
        par.resize(n);
        rank.resize(n);
        long i;
        for(i=0; i<n; i++) {
            par[i]=i;  rank[i]=1;
        }
    }
	
    long find(long x)
    {
        if(x==par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(long x, long y)
    {
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]) {
            par[x]=y;
        }
        else {
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(long x, long y)
    {
        return find(x)==find(y);
    }
};


int main(int argc, char* argv[])
{
    long h, w;
    scanf("%ld%ld", &h, &w);

    char s[405][405]={0};

    long i, j;
    for(i=0; i<h; i++) {
        scanf("%s", s[i]);
    }

    UF  uf(h*w);
  
#define ID(i,j) ((i)*w+(j))
    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            if( j<w-1 && s[i][j] != s[i][j+1] ) {
                uf.unite( ID(i,j), ID(i,j+1) );
            }
            if( i<h-1 && s[i][j] != s[i+1][j] ) {
                uf.unite( ID(i,j), ID(i+1,j) );
            }
        }
    }

    map<long, pair<long,long> > mm;

    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            if(s[i][j]=='#') {
                mm[uf.find(ID(i,j))].first ++;
            }
            else {
                mm[uf.find(ID(i,j))].second ++;
            }            
        }
    }

    ll sum=0;
    auto it=mm.begin();
    for(; it!=mm.end(); ++it) {
        sum += (it->second.first) * (it->second.second);
    }
    printf("%lld\n", sum);

    return 0;
}


Measured memory_bytes: 11264
#include<iostream>
using namespace std;
#include<algorithm>
#include<cmath>
#include<iomanip>
#define int long long int
#define mod 1000000007
double function(double arr[],int initial,int final,double memo[3001][3001],int count)
{
	if(count==0)
	  return 1.000000000;
	if(initial>final)
	{
		if(count>0)
		  return 0.00000000000;
		else
		  return 1.00000000000;
	}
	if(memo[initial][count]!=-1)
	  return memo[initial][count];
	else
	{
		double val1=arr[initial]*function(arr,initial+1,final,memo,count-1);
		double val2=(1-arr[initial])*function(arr,initial+1,final,memo,count);
		memo[initial][count]=(val1+val2);
		return memo[initial][count];
	}
}
double memo[3001][3001];
int32_t main()
{
    int n;
    cin>>n;
    double arr[n];
    int j;
    for(j=0;j<n;j++)
      cin>>arr[j];
    int i;
    for(i=0;i<=n;i++)
    {
		for(j=0;j<=n;j++)
		{
			memo[i][j]=-1;
	    }
    }
    double answer=function(arr,0,n-1,memo,n/2+1);
    cout<<setprecision(12)<<answer<<endl;
}


Measured memory_bytes: 70784
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn=new Scanner(System.in);
	String c1 = stdIn.next();
	String c2 = stdIn.next();
	if(c1.charAt(1)==c2.charAt(1)&&c1.charAt(0)==c2.charAt(2)&&c1.charAt(2)==c2.charAt(0)){
	    System.out.println("YES");
	}else{
	    System.out.println("NO");
	}
    }
}



Measured memory_bytes: 21716
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>
 
#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>
 
#define cauto const auto&
#else
 
#endif
 
using namespace std;
 
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;
 
#define VV(T) vector<vector< T > >
 
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
 
template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}
 
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
 
#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
 
bool inside(int y, int x, int H, int W) {
    return 0<=y && y<H && 0<=x && x<W;
}

void main2(){
    int H, W;
    cin >> H >> W;
    vvint vis;
    initvv(vis, H, W, 0);
    queue<pii> q;
    rep(i, H) {
        rep(j, W) {
            char c;
            cin >> c;
            if(c == '#'){
                q.push(pii(i, j));
                vis[i][j] = 1;
            }
        }
    }
    int ans = 0;
    while(q.size()) {
        ans++;
        int qs  = q.size();
        rep(_, qs) {
            pii x = q.front();
            q.pop();
            vint dd = {1, 0, -1, 0, 1};
            // cout << "ans " << ans << " " << x.fi << " " << x.se << endl;
            rep(i, 4) {
                int ny = x.fi + dd[i];
                int nx = x.se + dd[i+1];
                if(!inside(ny, nx, H, W) || vis[ny][nx]) continue;
                vis[ny][nx] = 1;
                q.push(pii(ny, nx));
            }
        }
    }
    cout << ans - 1 << endl;
}
 
 
signed main() {
    main2();
}

Measured memory_bytes: 12432
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n;
    cin>>n;

    ll a[n],b[n],c[n];
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i]>>c[i];
    ll dp1[n],dp2[n],dp3[n];

    dp1[0] = a[0];
    dp2[0] = b[0];
    dp3[0] = c[0];

    for(int i=1;i<n;i++)
    {
        dp1[i] = max(dp2[i-1],dp3[i-1])+a[i];
        dp2[i] = max(dp1[i-1],dp3[i-1])+b[i];
        dp3[i] = max(dp2[i-1],dp1[i-1])+c[i];
    }

    cout<<max(dp1[n-1],max(dp2[n-1],dp3[n-1]));
    
    return 0;
}

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

int main(){
int N;
scanf("%d",&N);
vector<long long> A(5);
char c[5] = {'M','A','R','C','H'};
for(int i=0; i<N; i++){
	char name[100];
	scanf("%s",name);
	for(int j=0; j<5;j++){
		if(name[0]==c[j]){
			A[j]++;
			break;
		}
	}
}
long long  ans = A[0]*A[1]*(A[2]+A[3]+A[4])+(A[0]+A[1])*A[2]*(A[3]+A[4])+(A[0]+A[1]+A[2])*A[3]*A[4];
printf("%lld\n", ans);
return 0;
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main(){
	int mapp[101][101];
	int d[101],vis[101];
	int ans=0,n,u;
	cin>>n;
	for (int i=0; i<n; i++)
	    for (int j=0; j<n; j++)
	        cin>>mapp[i][j];
	memset(vis,0,sizeof(vis));
	memset(d,0x1f1f1f1f,sizeof(d));
	d[0]=0; 
	while (true){
		  int minn=0x1f1f1f1f;
		  for (int i=0; i<n; i++)
		  	  if (!vis[i] && d[i]<minn){
		  	  	 minn=d[i]; u=i;
			  }
		  vis[u]=1;
		  if (minn==0x1f1f1f1f)
		     break;
		  for (int i=0; i<n; i++)
		      if (!vis[i] && mapp[u][i]!=-1 && mapp[u][i]<d[i]){
		      	 d[i]=mapp[u][i];
			  }
	}
	for (int i=0; i<n; i++)
		ans+=d[i];
	cout<<ans<<endl;
	return 0;
}


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

int main(){
	bool b[31];
	for(int i=0; i <= 30; i++) b[i] = true;
	b[0] = false;
	for(int i=0; i < 28; i++){
		int in;
		cin>> in;
		b[in] = false;
	}
	for(int i=0; i <= 30; i++){
		if(b[i]) cout << i << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,tmp[133],rr[133]; string s[51];
int main()
{
	cin>>n;
	memset(tmp,127/3,sizeof(tmp));
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		memset(rr,0,sizeof(rr));
		for(int j=0;j<s[i].size();j++)
			++rr[s[i][j]];
		for(int j=0;j<128;j++)
			tmp[j]=min(tmp[j],rr[j]);
	}
	string rs;
	for(int j=0;j<128;j++)
	{
		if(tmp[j]==tmp[0]) continue;
		while(tmp[j]--) rs.pb(j);
	}
	cout<<rs<<"\n";
}


Measured memory_bytes: 256