akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
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 << "Right" << endl;
  else
  	cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main() {
	scanf("%d %d %d",&a,&b,&c);
	if ((a==5&&b==5&&c==7)
		||(a==5&&b==7&&c==5)
		||(a==7&&b==5&&c==5))
		printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod2 = 1000000007;
constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// --------------------------------------------------------------------------


int main(){
  string S;
  cin >> S;
  if(S.back() == 's'){
    cout << S + "es\n";
  }else{
    cout << S + "s\n";
  }
}

Measured memory_bytes: 3604
#include<iostream>
using namespace std;
int main(){
  int n,m,a;
  int t[1001],u[1001];
  for(int i=0;i<1001;i++)u[i]=t[i]=0;
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>t[i];
  }
  for(int i=0;i<m;i++){
    cin>>a;
    for(int j=0;j<n;j++){
      if(t[j]<=a){
	u[j]++;
      break;
      }

    }
  }
  int mx,mxno;
  mx=0;
  for(int i=0;i<n;i++){
    if(mx<u[i]){
      mx=u[i];
      mxno=i+1;
    }
  }
  cout<<mxno<<endl;
  return 0;
}

Measured memory_bytes: 1168
#include<stdio.h>

int digitSum(int a)
{
	int sum = 0;
	while (a > 0) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}

int main(void)
{
	int X=0, f(X);
	scanf("%d", &X);
	if (X % digitSum(X) == 0)
		printf("Yes");
	else
		printf("No");
	return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  string S;
  cin >> S;
  int sum = 0;
  int n = S.size();
  for(int i = 0;i < n;i++){
    sum += stoi(S.substr(i,1));
  }
  int N = stoi(S);
  if(N%sum == 0)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



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

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

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll 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;
    }
}

// 二項係数計算
ll 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;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;
    cin>>n>>m;
    map<ll,ll,greater<ll>> mp;
    rep(i,n){
        ll a;
        cin>>a;
        mp[a]++;
    }
    rep(i,m){
        ll b,c;
        cin>>b>>c;
        mp[c]+=b;
    }
    ll cou=0,sum=0;
    while(cou<n){
        for(auto p:mp){
            if(cou==n) break;
            rep(i,p.second){
                sum+=p.first;
                cou++;
                if(cou==n) break;
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 12800
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
	int i;
	for(i=0;i<s.length();i+=2)
            System.out.print(s.charAt(i));

	System.out.println("");
    }
}




Measured memory_bytes: 28108
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
	int N,M;
	int num = 0;
	int des[200001];
	bool canN[200001];

	for(int i=0;i<200001;i++){
		des[i] = 0;
		canN[i] = false;
	}

	scanf("%d %d",&N,&M);

	for(int i=0;i<M;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		if(a==1){
			des[num++] = b;
		}
		if(b==N){
			canN[a] = true;
		}
	}

	for(int i=0;i<=num;i++){
		if(des[i]==0) break;
		if(canN[des[i]]){
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");
	return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int i;
  long k,n,ans=1000;
  scanf("%ld",&n);
  while(n>=100){
    k=abs(n%1000-753);
    if(ans>k){
      ans=k;
    }
    n=n/10;
  }
  printf("%ld",ans);
  return 0;
}
   	

Measured memory_bytes: 128
from itertools import permutations
n, m = map(int, input().split())
edges = [tuple(map(int, input().split())) for _ in range(m)]

ans = 0
for i in permutations(range(2, n+1), n-1):
    load = [1]+list(i)
    ans += sum(1 for edge in zip(load, load[1:])
               if tuple(sorted(edge)) in edges) == n-1
print(ans)


Measured memory_bytes: 3316
#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 DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	double ans = -1, res = 0, sugar = 0;
	REP(i, f / (100 * a) + 1) {
		REP(j, (f - a*i*100) / (100 * b) + 1) {
			int w = i*a * 100 + j*b * 100;
			assert(w <= f);
			int m = f - w;
			REP(k, m / c + 1) {
				REP(l, (m - k*c) / d + 1) {

					int s = k*c + l*d;
					assert(s <= m);
					double tmp = double(100 * s) / (w + s);
					if ((i*a+j*b)*e>=s&&tmp > ans + EPS) {
						
						ans = tmp;
						res = w + s;
						sugar = s;
					}
				}
			}
		}


	}
	cout << res << " " << sugar << endl;

}


Measured memory_bytes: 256
from collections import Counter
n,k =list(map(int,input().split()))

a = list(map(int,input().split()))

c = Counter(a).most_common()
ans = 0
tmp = 0
for i,cnt in c:
    tmp += cnt
    k-=1
    if k == 0:
        ans = n-tmp
        break
print(ans)

Measured memory_bytes: 39352
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &e : a)
    cin >> e;
  int ans = 2000000;
  for (int i = -100; i <= 100; ++i)
  {
    int sum = 0;
    for (int j = 0; j < n; ++j)
    {
      sum += (i - a[j]) * (i - a[j]);
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
#-*- coding: utf-8 -*-

if __name__ == '__main__':
    raw_input()
    l = map(int, raw_input().split())
    for i in range(1, len(l)):
        print ' '.join(map(str, l))
        v = l[i]
        j = i - 1
        while j >= 0 and l[j] > v:
            l[j + 1] = l[j]
            j -= 1
        l[j + 1] = v
    print ' '.join(map(str, l))


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

using namespace std;
typedef long long ll;
int main() {

    ll k, n = 0;  cin >> k;
    ll ans = -1;
    for (ll i = 1; i < 1000007; i++) {
        n = (n * 10 + 7) % k;
        if(n == 0) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
object Main {
  def main(args: Array[String]): Unit = {
    for (ss <- io.Source.stdin.getLines()) {
      var s = ss
      (0 to 25).foreach { _ =>
        if (check(s)) {
          println(s)
          s = next(s)
        } else {
          s = next(s)
        }
      }
    }
  }

  def next(s: String): String = {
    val sss = s.map(c => {
      c match {
        case ' ' => ' '
        case '.' => '.'
        case cc: Char => (((cc - 'a' + 1) % 26) + 'a').toChar
      }
    })
    return sss.toString()
  }

  def check(s: String): Boolean = {
    val list = List("the", "this", "that")
    list.foreach { ss =>
      s.contains(ss) match {
        case true => return true
        case _ =>
      }
    }
    return false
  }
}

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

#define ff first
#define ss second
#define ll long long
#define W(x) cerr << "\033[31m"<< #x << " = " << x << "\033[0m" << endl;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef set<int> si;
typedef vector<vi> vii;
typedef vector<ii> vpi;
typedef vector<ll> vll;
int oo = (1e9) + 7;
ll oo2 = 1ll*oo*oo; 


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

    double ans = 0;
    double x1;
    string s;
    while(n--) {
        cin >> x1 >> s;
        ans += s == "BTC" ? 380000*x1 : x1;
    }
    printf("%.5lf\n", ans);

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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

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

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

using namespace std;

typedef long long ll;
 
const int MOD = 1e9 + 7;

ll n,k,p[110],dp[100100],pref[100100],c;

int main() {
	
	scanf("%d %d", &n, &k);
	
	for(int i = 0; i < n; i++) {
		
		scanf("%lld", &p[i]);
	}
	for(int i = 0; i < n; i++) {
		if(!i) {
			for(int j = k - p[i]; j <= k; j++) {
				dp[j] = 1;
				if(j == 0) pref[i] = dp[j];
				else pref[j] = pref[j - 1] + dp[j];
			}
			
		}
		else 
		for(int j = 0; j <= k; j++) {
			c = j + p[i];
			if(j + p[i] > k) c = k;
			dp[j] += pref[c] - pref[j] % MOD;
			dp[j] %= MOD;
			//printf("%d %d %lld %lld\n",i,j,c,pref[j]);
			if(j == 0) pref[j] = dp[j];
			else pref[j] = (dp[j] + pref[j - 1]) % MOD;
			
			pref[j] += MOD; pref[j] %= MOD;
			
		}
		
		/*for(int j = 0; j <= k; j++) printf("%lld ",dp[j]);
		printf("\n");
		for(int j = 0; j <= k; j++) printf("%lld ",pref[j]);
		printf("\n");*/
	}
	
	printf("%lld", dp[0]);
	
	return 0;
}

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

int main()
{
	int ans=0;
	string s;
	cin>>s;
	
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='o')
			ans+=100;
	}
	cout<<700+ans;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){

    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

bool IsPrime(ll num){
    if(num < 2) return false;
    else if(num == 2) return true;
    else if(num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for(ll i = 3; i <= sqrtNum; i += 2){
        if(num%i==0){
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}

signed main(){
  int x; cin>>x;
  while(1){
    if(IsPrime(x)) return cout << x << endl,0;
    else x++;
  }

  return 0;
}


Measured memory_bytes: 256
$cnt = 0

def calc arr
  operators = %w(+ - *)
  stack = []
  arr.each { |item|
    # ??????????????£????????????????????????2???????????????????¨????????????????????????????????????\????????????
    if operators.include? item
      first = stack.pop
      second = stack.pop
      stack.push eval "#{second} #{item} #{first}"
    elsif
      # ??°????????£???????????????????????°???
      stack.push item
    end
  }

  stack
end

inputs = STDIN.gets.chomp.split(' ')

p calc(inputs).first

Measured memory_bytes: 8720
/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define ld long double
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define el '\n'
#define N 1000000007
#define re return
#define F first
#define S second
#define L length
#define deb(x) cout<<#x<<" "<<x<<el;
#define mp make_pair
#define PI 3.14159265
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int i=0;i<n;i++)
#define forf(i,x,n) for(int i=x;i<n;i++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
#define take(a,n) forup(i,n) cin>>a[i];
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

ll poww(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n==1) return x;
    else if(n%2 == 0)        //n is even
        return poww(x*x,n/2);
    else                              //n is odd
        return x*poww(x*x,(n-1)/2);
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

template<typename T>
T maxx(T a,T b)
{
  if(a<b) re b;
  re b;
}
template<typename T, typename... Args>
T maxx(T a,T b, Args... args)
{
    re(maxx(maxx(a,b),args...));
}

template<typename T>
T minn(T a,T b)
{
  if(a<b) re a;
  re b;
}
template<typename T, typename... Args>
T minn(T a,T b, Args... args)
{
    re(minn(minn(a,b),args...));
}

template<typename T>
void read(T& a)
{
  cin>>a;
}
template<typename T, typename... Args>
void read(T& a,Args&... args)
{
  cin>>a; read(args...);
}

template<typename T>
void write(T a)
{
  cout<<a<<' ';
}
template<typename T, typename... Args>
void write(T a,Args... args)
{
  cout<<a<<' '; write(args...);
}

inline ll min(ll a,ll b)
{
  if(a<b) re a;
  else re b;
}
inline ll max(ll a,ll b)
{
  if(a<b) re b;
  else re a;
}

ll gcd(ll a, ll b)
{
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    else return gcd(a, b-a);
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=((ans*((n-i)%N))%N*modInverse(i+1,N))%N;
  }
  re ans;
}

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

  int t=1;
  //cin>>t;
  while(t--)
  {
    ll n,m,k;
    cin>>n;
    set<string> s;
    forup(i,n)
    {
      string t;
      cin>>t;
      s.insert(t);
    }
    cout<<s.size()<<el;

  }


  return 0;
}


Measured memory_bytes: 19288
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
 
using lint=long long;
using pint=pair<int,int>;
template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

int main()
{
   int N; cin>>N;
   map<int,int> cnt;
   for(int i=0;i<N;i++){
      int a; cin>>a;
      cnt[a]++;
   }

   bool ok=true;
   for(auto I:cnt) if(I.second>=2) ok=false;
   cout<<(ok? "YES":"NO")<<endl;
   return 0;
}


Measured memory_bytes: 9600
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int sum = 0;
		for(int i = 0; i < n; i++)
			sum += (i < k) ? x : y;
		System.out.println(sum);
	}
}

Measured memory_bytes: 23636
N = int(input())
B = list(map(int, input().split()))

max_sum = 0
for i in range(N):
	if i == 0:
		max_sum += B[0]
	elif i == N - 1:
		max_sum += B[N-2]
	else:
		max_sum += min(B[i-1], B[i])
print(max_sum)

Measured memory_bytes: 3060
n , k = map(int , input().split())
if n < k:
	if abs(n-k) < n:
		exit(print(abs(n-k)))
	else:
		exit(print(n))
ans  = max(n,k) - (max(n,k)//min(n,k))*min(n,k)
if abs(ans - k) < ans:
	ans = abs(ans-k)
print(ans)


Measured memory_bytes: 38256
#include<bits/stdc++.h> 
#include<stdio.h>
using namespace std; 
int main(){
	string s;
	cin >>s;
	if(s.compare(2,1,s,3,1)==0&& s.compare(4,1,s,5,1)==0) cout << "Yes";
		else cout << "No";
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;

int main() {
  int n,a,b,min,max;
  cin >> n >> a >> b;
  if(a >= b) max = b;
  else max = a;
  if(a + b <= n) min = 0;
  else min = a + b - n;
  cout << max << " " << min;
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		
		Scanner in=new Scanner(System.in);
		
		int sumNeeded = in.nextInt();
		int coins=in.nextInt();
		
		ArrayList<Integer> values=new ArrayList<Integer>(coins);
		
		
		for(int i=0;i<coins;i++){
			values.add(in.nextInt());
		}
		
		Collections.sort(values);		
		
		int[] matrix=new int[sumNeeded+1];
		
		for(int i=1;i<matrix.length;i++)
			matrix[i]=Integer.MAX_VALUE;
		
		
		for(int sum=1; sum<matrix.length;sum++){			
			for(int j=0; j<values.size(); j++){				
				int coinValue=values.get(j);				
				if(sum>=coinValue) {
					matrix[sum] =Math.min(matrix[sum],matrix[sum-coinValue] + 1);
					//System.out.println("Updated matrix[" + sum + "] = " + matrix[sum] );
				}					
			}		
		}
		
		System.out.println(matrix[sumNeeded]);
	}

}

Measured memory_bytes: 27248
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
using ll = long long;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    ll n;
    cin >> n;
    ll a[n];
    ll gcdofl[n + 1];
    ll gcdofr[n + 1];
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
}
gcdofl[0] = 0;
gcdofr[n] = 0;
for (ll i = 0; i < n; i++) {
    gcdofl[i + 1] = __gcd(gcdofl[i], a[i]);
}
for (ll i = n-1; i >=0 ;i--){
    gcdofr[i] = __gcd(gcdofr[i+1], a[i]);
}
ll ans = 0;
for (ll i = 0; i < n; i++) {
    chmax(ans, __gcd(gcdofl[i], gcdofr[i+1]));
}
cout << ans << endl;
}


Measured memory_bytes: 2560
#include <stdio.h>
int main(void)
{
	char str[20];
	int a;
	int b;
	int c;
	int d;
	int x;
	int y;
	int z;
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d %d %d",&a, &b, &c);
	if(a < b){
	} else if(a > b){
		x = a;
		a = b;
		b = x;
	}
	if(b < c){
	}else if(b > c){
		y = b;
		b = c;
		c = y;
	}
	if(a < b){
	}else if(a > b){
		z = a;
		a = b;
		b = z;
	}
	
	printf("%d %d %d\n", a, b, c);

	return 0;
	

}

Measured memory_bytes: 604
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    string S;
    int N;
    cin >> N >> S;

    int count = 0;
    size_t pos = 0;
    while (pos < N && (pos = S.find("ABC", pos)) != string::npos) {
        ++count; 
        pos += 3;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    char x,y;
    cin >> x >> y;
    if(x>y){
        cout << ">" << endl;
    }else if(x==y){
        cout << "=" << endl;
    }else{
        cout << "<" << endl;
    }
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            long X = in.nextInt();
            long a = X / 500;
            long b = (X % 500) / 5;
            out.println(a * 1000 + b * 5);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

using ll=long long;
#define int ll
#define upto(a,b,i) for(int i=(a),b_=(b);i<=b_;++i)
#define uptil(a,b,i) for(int i=(a),b_=(b);i<b_;++i)
#define downto(a,b,i) for(int i=(a),b_=(b);i>=b_;--i)
#define downtil(a,b,i) for(int i=(a),b_=(b);i>b_;--i)
#define times(n,i) uptil(0,n,i)
#define rtimes(n,i) downto((n)-1,0,i)
#define sp << " "
#define ln << endl
template<class T> using vec = vector<T>;

void solve() {
  int N; cin >> N;
  vec<pair<int,int>> zp(N);
  times(N, i) {int A, B;cin >> A >> B; zp[i] = {B,A};}
  sort(begin(zp), end(zp));
  int k = 0;
  times(N, i) {
    k += zp[i].second; // A
    if(k > zp[i].first) {// B
      cout << "No" ln;
      goto next_case;
    }
  }
  cout << "Yes" ln;
  next_case:;
}

signed main() {
  cout << fixed << setprecision(20);
  cerr << fixed << setprecision(10);
  solve();
return 0;
}


Measured memory_bytes: 3328
#!python3

LI = lambda: list(map(int, input().split()))

# input
N = int(input())
H = LI()

INF = 10 ** 10


def main():
    dp = [INF] * N
    dp[0] = 0
    dp[1] = abs(H[0] - H[1])
    for i in range(2, N):
        a = dp[i - 2] + abs(H[i] - H[i - 2])
        b = dp[i - 1] + abs(H[i] - H[i - 1])
        dp[i] = min(a, b)
    ans = dp[-1]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 20544
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    string a;
    string z,x;
    cin>>a;
    z=a[0];
    x=a[1];

    if(z=="9"&&x=="9")
    {
        cout<<"Yes";
    }else if(z=="9")
    cout<<"Yes";
    else if(x=="9")
        cout<<"Yes";
    else
        cout<<"No";








    return 0;
}


Measured memory_bytes: 256
//21171_somesh || asomesh999

#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define io ios::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
long int mod=1000000007;

int main()
{
	io
	#ifdef CODE
		clock_t startTime = clock();
		freopen("input.txt","r",stdin);
	#endif

	char ch;
	cin >> ch;
	cout << char(ch + 1);

	#ifdef CODE
		cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;
	#endif
	return 0;
}

Measured memory_bytes: 256
n, k, c = [0] * 3
s = ""

def format_input(filename = None):
	global n, k, c
	global s
	if filename == None:
		n, k, c = list(map(int, input().split()))
		s = str(input())

	elif filename == '__random__':
		from random import randint as rng
		from random import choices
		n = rng(1, 2 * 10**5)
		k = rng(1, n)
		c = rng(0, n)
		s = ''.join(choices('ox', k = n))
		print(n, k, c)
		print(s)

def get_answer():
	left = []
	pointer = 0
	while pointer < n and len(left) < k:
		if s[pointer] == 'o':
			left.append(pointer + 1)
			pointer += c + 1
		else:
			pointer += 1

	right = []
	pointer = n - 1
	while pointer >= 0 and len(right) < k:
		if s[pointer] == 'o':
			right.append(pointer + 1)
			pointer -= c + 1
		else:
			pointer -= 1

	fixed = []
	if len(left) == k and len(right) == k:
		for i in range(k):
			if left[i] == right[-(i+1)]:
				fixed.append(left[i])

	for i in range(len(fixed)):
		print(fixed[i])

if __name__ == '__main__':
	format_input()

	get_answer()


Measured memory_bytes: 22168
# include <cstdio>
# include <iostream>
# include <set>
# include <string>
# include <cstring>

using namespace std;

string a;
char c;
bool f=true;
int l,n;
set <string> s;

int main()
{
	scanf("%d",&n);
	cin>>a;
	l=a.length();
	c=a[l-1];
	s.insert(a);
	for (int i=2;i<=n;++i)
	{
		cin>>a;	
		if(a[0]!=c) f=false;
		l=a.length();
		c=a[l-1];
		if(s.find(a)!=s.end()) f=false;
		s.insert(a);
	}
	if(f) printf("Yes");
	else  printf("No");
	return 0;	
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    s = input()
    K = int(input())

    a = set()

    for i in range(len(s)):
        for j in range(K):
            a.add(s[i:i+j+1])
            if i + j > len(s):
                break
    a_list = list(a)
    a_list.sort()
    print(a_list[K-1])
            

if __name__ == '__main__':
    main()

Measured memory_bytes: 4464
///////////////////////////////////////////
// twentyto.cpp created 2018-12-22
// Kamil Tokarski

/*       biblioteczka       */
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;

// types
typedef long long ll;
typedef long double ld;

#define PR  pair
#define PII pair<int, int>
#define PLL pair<ll, ll>

#define VEC vector
#define VL VEC<ll>
#define VI VEC<int>
#define VPI VEC<PII>
#define VPL VEC<PLL>

// IO
#define fastio ios_base::sync_with_stdio(NULL);cout.tie(NULL);cin.tie(NULL)
#define precise(x) cout << fixed << setprecision(x)

#define read_file(var, file) ifstream var(file)
#define write_file(var, file) ofstream var(file)
#define close_file(var) var.close()

// containers
#define sz(x) (int)(x.size())
#define all(x) x.begin(), x.end()
/*          koniec          */


int a;
int N;


int main(int argc, char **argv) {
  fastio;

  cin >> N; 
  while(N) {
    if(N % 10 == 2)
      ++a;
    N /= 10;
  }

  cout << a << endl;
  return 0;
}



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

int main(){
  
  int t[20000];
  int n,m;

  while(1){
    for(int i=0;i<2000;i++)t[i]=0;

    cin >> n>>m;
    if(n==0&&m==0)break;

    for(int i=0;i<n+m;i++)cin>>t[i];

    sort(t,t+(n+m));

    int max=0;
    for(int i=1;i<n+m;i++){
      if((t[i]-t[i-1])>max&&(t[i]-t[i-1])!=0)max=t[i]-t[i-1];
    }
    if(t[0]>max)cout<<t[0]<<endl;
    else cout << max<<endl;
  }
  
    return 0;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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 int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, C, K;
    cin >> N >> C >> K;
    vector<ll> T(N);
    rep(i,N)cin >> T[i];
    sort(all(T));
    int r = 0;
    int ans = 0;
    for(int l = 0; l < N;){
        while(r+1 < N && r+1 - l + 1 <= C && T[r+1] <= T[l] + K){
            r++;
        }
        l = r+1;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,count=0;
    bool flag,flag2,flag3;
    string s,h1,h2,h3;
    cin>>n>>s;
    rep(i,10){
        rep(j,10){
            rep(k,10){
                flag=false;
                flag2=false;
                flag3=false;
                h1=to_string(i);
                h2=to_string(j);
                h3=to_string(k);
                rep(l,n){
                    if(!flag && s[l]==h1[0]){
                        flag=true;
                    }
					else if(flag && !flag2 && s[l]==h2[0]){
                        flag2=true;
                    }
                    else if(flag && flag2 && !flag3 && s[l]==h3[0]){
                        flag3=true;
                    }
                }
                if(flag && flag2 && flag3){
                    count++;
                }
            }
        }
    }
    cout<<count<<'\n';
    return(0);
}

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

#define Mset(s, n)      memset(s, n, sizeof(s))
#define All(a)          (a).begin(), (a).end()
#define Lwb             lower_bound
#define Upb             upper_bound
#define Sz(a)           int((a).size())
#define Exist(a, b)     (find(All(a), (b)) != (a).end())
#define Sort(x)         sort(All(x))
#define Gsort(x)        sort(All(x), greater<typeof(*((x).begin()))>())
#define Unique(v)       Sort(v); (v).resize(unique(ALL(v)) - (v).begin())

#define fi              first
#define se              second
#define pb              push_back
#define pf              push_front
#define is              insert
#define ooi             INT_MAX
#define ool             LLONG_MAX
#define ll              long long
#define ull             unsigned ll
#define ld              long double
#define pii             pair<int, int>
#define vi              vector<int>
#define vpii            vector<pii>

const ll MOD = (ll) 1e9 + 7;
const ld PI = acos((ld) -1);
inline int Get_bit(int x, int k){return (x >> (k - 1)) & 1;}
inline ll Gcd(ll a, ll b) {ll r; while(b){ r = a % b; a = b; b = r;} return a;}
inline ll Lcm(ll a, ll b) {return a / Gcd(a, b) * b;}
inline ll Pow(ll n, ll k) {ll r = 1; for(; k; k >>= 1, n = n * n % MOD){if(k & 1) r = r * n % MOD;} return r;}
const int base = 311;


const int N = 1e5 + 5;


ll n, m, k, q;


void Solve(){
	string s;
	cin >> s;
	int n = Sz(s);
	int res = 0;
	for(int i = 0; i < n / 2; i++){
        if(s[i] != s[n - i - 1]) res++;
	}
	cout << res;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    Solve();
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect

class Monster:
    def __init__(self, hp, atk):
        self.hp = hp
        self.atk = atk

    def __repr__(self):
        return "hp {} atk {}".format(self.hp, self.atk)

    def atack(self, opponent):
        opponent.hp -= self.atk
        if opponent.hp <= 0:
            return True
        else:
            return False

def battle(x, y):
    while True:
        #print('x') # debug
        #print(x) # debug
        #print('y') # debug
        #print(y) # debug
        if x.atack(y):
            return True
        #print('x') # debug
        #print(x) # debug
        #print('y') # debug
        #print(y) # debug
        if y.atack(x):
            return False

if __name__ == '__main__':
    a, b, c, d = list(map(int, input().split()))
    takahashi = Monster(a, b)
    aoki = Monster(c, d)
    if battle(takahashi, aoki):
        print("Yes")
    else:
        print("No")


    #print('\33[32m' + 'end' + '\033[0m') # debug


Measured memory_bytes: 68396
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<utility>
#define mod 998244853 
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, nb=0;
    string s;
    cin >> n;cin.ignore();
    cin >> s;
    for(int i = 0; i < n; i++)
    {
        nb++;
        int j = i+1;
        while(s[j]==s[i] && j < n)
            j++;
        i=j-1;
    }
    cout << nb << '\n';
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define maxn 200005
#define ll long long
using namespace std;
int arr[maxn],cnt[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		cin >> arr[i] , cnt[arr[i]]++;
	ll ans = 0;
	for(int i=1;i<=n;i++)
		ans += (ll)cnt[i] * (cnt[i]-1) / 2;
	for(int i=1;i<=n;i++)
		cout << ans - max(0,cnt[arr[i]]-1) << endl;
	return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;

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

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))

const int N_MAX = 1000*100;

int count32bit(unsigned int v) {
	unsigned int count = (v & 0x55555555) + ((v >> 1) & 0x55555555);
	count = (count & 0x33333333) + ((count >> 2) & 0x33333333);
	count = (count & 0x0f0f0f0f) + ((count >> 4) & 0x0f0f0f0f);
	count = (count & 0x00ff00ff) + ((count >> 8) & 0x00ff00ff);
	return (count & 0x0000ffff) + ((count >> 16) & 0x0000ffff);
}

int main() {
	int N, C;
	scanf("%d %d", &N, &C);
	unsigned int time[(N_MAX+1)*2];
	SET_ZERO(time);
	for (int i = 0; i < N; i++) {
		int s, t, c;
		scanf("%d %d %d", &s, &t, &c);
		time[s*2-1] |= 1 << (c-1);
		time[t*2] |= 1 << (c-1);
	}

	int max = 0;
	unsigned int state = 0;
	for (int i = 0; i < (N_MAX+1)*2; i++) {
		state = state ^ time[i];
		chmax(max, count32bit(state));
	}
	printf("%d\n", max);
	return 0;
}


Measured memory_bytes: 1024
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <cstring>
#include <fstream>

using namespace std;

int dist[1001][1001];
char board[1001][1001];
int n, m;
const int INF = 1e9;
int dy[4] = { -1,0,1,0 };
int dx[4] = { 0,1,0,-1 };

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> n >> m;

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

	priority_queue <pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pque;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (board[i][j] == '#')
			{
				dist[i][j] = 0;
				pque.push(make_pair(dist[i][j], make_pair(i, j)));
			}
			else
			{
				dist[i][j] = INF;
			}
		}
	}

	while (!pque.empty())
	{
		int y = pque.top().second.first;
		int x = pque.top().second.second;
		pque.pop();

		for (int k = 0; k < 4; k++)
		{
			int ny = y + dy[k];
			int nx = x + dx[k];
			if (ny < 0 || ny >= n || nx < 0 || nx >= m)
			{
				continue;
			}
			if (dist[ny][nx] > dist[y][x] + 1)
			{
				dist[ny][nx] = dist[y][x] + 1;
				pque.push(make_pair(dist[ny][nx], make_pair(ny, nx)));
			}
		}
	}

	int res = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			res = max(res, dist[i][j]);
		}
	}

	cout << res << '\n';

	return 0;
}

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

#define         ull             unsigned long long
#define         ll              long long
#define         inf             INT_MAX
#define         pi              acos(-1.0)
#define         vi              vector<int>
#define         vl              vector<long long>
#define         pii             pair<int,int>
#define         pll             pair<long long,long long>
#define         mp              make_pair
#define         mii             map<int,int>
#define         mll             map<int,int>
#define         mli             multimap<int,int>
#define         mlll            multimap<long long,long long>
#define         msi             multiset<int>
#define         msl             multiset<long long>
#define         si              set<int>
#define         sl              set<long long>
#define         FOR(I,A,B)      for(int I = (A); I < (B); I++)
#define         rev(I,A,B)      for(int I = A ; I >= B ; I--)
#define         mem(a, v)       memset(a, v, sizeof (a))
#define         mod             1000000007
#define         all(a)          a.begin(),a.end()
#define         rall(a)         a.rbegin(),a.rend()
#define         ff              first
#define         ss              second
#define         arsort(ar,n)    sort(ar,ar+n);
#define         vsort(v)        sort(v.begin(),v.end())
#define         vrev(v)         reverse(v.begin(),v.end())
#define         arrev(ar,n)     reverse(ar,ar+n)
#define         pb              push_back
#define         popb            pop_back
#define         booster()       ios_base::sync_with_stdio(0); cin.tie(0);
#define         read(f)         freopen(f, "r", stdin)


#define         min3(a,b,c)     min(a,min(b,c))
#define         max3(a,b,c)     max(a,max(b,c))
#define         min4(a,b,c,d)   min(min(a,b),min(c,d))
#define         max4(a,b,c,d)   max(max(a,b),max(c,d))
#define         max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define         min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))


#define         bitCheck(a,k)     ((bool)(a&(1<<(k))))
#define         bitOff(a,k)       (a&(~(1<<(k))))
#define         bitOn(a,k)        (a|(1<<(k)))
#define         bitFlip(a,k)      (a^(1<<(k)))


int fx[] = {-1,+0,+1,+0,+1,+1,-1,-1,+0};
int fy[] = {+0,-1,+0,+1,+1,-1,+1,-1,+0};
int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

using namespace std;

bool comp(int x, int y) { return x > y; }

/*********************** let the play begin() ***********************************/

int main()
{
    booster()
    string s;
    cin>>s;
    string s1=s;
    reverse(all(s1));
    if(s==s1)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

typedef long long ll;
const ll mod=1e9+7;
const int N=200000;

void Run()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
ll a[N];
int main()
{
    Run();
    int n,k,res=0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<k;i++)
        res+=a[i];
    cout<<res;
}


Measured memory_bytes: 3680
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_C() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    string S; cin >> S;
    S = "B" + S;

    vi w(N+1, 0);
    FOR(i,1, N+1) {
        if (S[i]=='W') w[i] = w[i - 1] + 1;
        else w[i] = w[i - 1];        
    }

    int ans = INF;
    FOR(i,1,N+1) {
        // cost = w[i-1] + e[i+1]
        int cost = w[i - 1] + (N - w[N]) - (i - w[i]);
        ans = min(ans, cost);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1904
n, d = map(int, input().split())
count = 0
X = [list(map(int, input().split())) for i in range(n)]
for x in range(n - 1):
	for y in range(x + 1, n):
		d = sum([(a - b)**2 for a, b in zip(X[x], X[y])])**0.5
		if d == d // 1:
			count += 1
print(count)

Measured memory_bytes: 38384
//競技プログラミング　テンプレ
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cstdlib> //abs() これは整数のみ

using namespace std;

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

const int max_v = 300;
const int INF = 1000000;



int main() {
	int n, ans=0 ,hp;
	cin >> n >> hp;
	vector <int> A(n);
	vector <int> B(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i] >> B[i];
	}

	int max = *max_element(A.begin(),A.end());
	sort(B.begin(), B.end());
	REP(i,n){
		if(max <= B[n-i-1]) {hp -= B[n-i-1]; ans++;}
		if(hp <=0) {cout << ans ; return 0;}
	}

	while(hp >0){
		hp -= max;
		ans ++;
	}

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


Measured memory_bytes: 1024