akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

int n;
int count[100];
int max_number=0;

int main(){
	memset(count,0,sizeof(count));
	while(cin >> n){
		count[n - 1] += 1;
	}

	//?????§?????°????????????
	for(int i=0;i<100;i++){
		if(count[i] > max_number){
			max_number = count[i];
		}
	}

	//????????????
	for(int i=0;i<100;i++){
		if(count[i] == max_number){
			cout << i+1 << endl;
		}
	}
}

Measured memory_bytes: 3076
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

bool seen[300000];
Graph G(300000);
bool f;
int g;
void dfs(int v, int cnt){
    seen[v] = true;
    if(v == g){
        f = true;
        return;
    }
    if(cnt == 2)return;
    for(int nv : G[v]){
        if(seen[nv])continue;
        dfs(nv, cnt+1);
    }

}

int main(){
    int d[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout <<  d[k - 1] << endl;
}



Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';
int mod = 1e9 + 7;
ll inf = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int res = 0;
    if(s[0]==t[0])
        res++;
    if(s[1]==t[1])
        res++;
    if(s[2]==t[2])
        res++;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int i, j, k;
	int a[3];
	k = 0;
	for (i = 0;i < 3;i++) {
		scanf("%d", &a[i]);
	}
	for (i = 0;i < 2;i++) {
		if (a[i] == a[i + 1]) {
			k = k + 1;
		}
	}
	if (a[0] == a[2]) {
		k = k + 1;
	}
	if (k == 1) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    int n;
    cin>>n;
    ll a[n],b[n],cnt=0;
    for (int i = 1; i <=n; ++i) cin>>a[i]>>b[i];  
    for (int i = n; i>=1; i--)if((a[i]+cnt)%b[i])cnt+=b[i]-(a[i]+cnt)%b[i];
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    int n; cin >> n;
    map<P,int> mp;
    for (int i = 1; i <= n; i++) {
        string tmp = to_string(i);
        if (tmp.size() == 1) mp[P(i,i)]++;
        else mp[P(tmp.front()-'0',tmp.back()-'0')]++;
    }
    int ans = 0;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            int x = mp[P(i,j)];
            int y = mp[P(j,i)];
            ans += x*y;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

vector<int> a;


int main() {
int n, k;
scanf("%d %d", &n, &k);
int  b;
while (scanf("%d", &b) != EOF) {
a.push_back(b);
}
int len = n - k;
int j = 0;
while (len--) {
if (a[k] > a[j])
printf("Yes\n");
else
printf("No\n");
k++;
j++;
}
return 0;
}

Measured memory_bytes: 3808
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int r = sc.nextInt();

        System.out.println(n >= 10 ? r :  r + 100 * (10 - n));
    }

}


Measured memory_bytes: 21588
package main
import(
  "fmt"
  "sort"
)
func main(){
  var n, m, i int
  temp:=0
  fmt.Scan(&n, &m)
  x:=make([]int, m)
  l:=make([]int, m-1)
  for i=0;i<m;i++{
    fmt.Scan(&x[i])
  }
  if n>=m{
    fmt.Println(0)
    return
  }
  sort.Sort(sort.IntSlice(x))
  for i=1;i<m;i++{
    l[i-1]=x[i]-x[i-1]
  }
  sort.Sort(sort.IntSlice(l))
  for i=m-n;i<m-1;i++{
    temp+=l[i]
  }
  fmt.Println(x[m-1]-x[0]-temp)
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,nw;
int main()
{
	cin>>a>>b>>c>>d;
	while(a>0 && c>0)
	{
		if(nw==0)
		{
			c-=b;
		}
		else
		{
			a-=d;
		}
		nw=1-nw;
	}
	if(a<=0)
	{
		cout<<"No"<<endl;
	}
	else
	{
		cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
char a1[105],b1[105],c1[105];
int main()
{
    queue<char> a;
    queue<char> b;
    queue<char> c;
    char t,p;
    cin>>a1>>b1>>c1;
    for(int i=0;i<strlen(a1);i++)
        a.push(a1[i]);
    for(int i=0;i<strlen(b1);i++)
        b.push(b1[i]);
    for(int i=0;i<strlen(c1);i++)
        c.push(c1[i]);
        t=a.front();
        a.pop();
        while(1)
        {
            if(t=='a')
            {
                if(a.empty())
                {
                    cout<<"A";
                    break;
                }
                t=a.front();
                a.pop();
            }
            else if(t=='b')
            {
                if(b.empty())
                {
                    cout<<"B";
                    break;
                }
                t=b.front();
                b.pop();
            }
            else if(t=='c')
            {
                if(c.empty())
                {
                    cout<<"C";
                    break;
                }
                t=c.front();
                c.pop();
            }
        }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    //テストケース の個数
    int n = sc.nextInt();
    //ac
    int c0 = 0;
    //wa
    int c1 = 0;
    //tle
    int c2 = 0;
    //re
    int c3 = 0;
    for(int i = 0;i <= n;i++){
      String s = sc.nextLine();
      if(s.equals("AC")){
        c0++;
      }else if(s.equals("WA")){
        c1++;
      }else if(s.equals("TLE")){
        c2++;
      }else if(s.equals("RE")){
        c3++;
      }
    }
    System.out.println("AC x " + c0);
    System.out.println("WA x " + c1);
    System.out.println("TLE x " + c2);
    System.out.println("RE x " + c3);
    
  }
}

Measured memory_bytes: 59408
#pragma GCC optimize ("O3")
// #pragma GCC target ("avx")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
LL A[100011];

void MAIN() {
    scanf("%d", &N);
    REP (i, N+1) scanf("%lld", A+i);

    LL ans = 0;
    if (N == 0) {
	if (A[0] == 1) {
	    ans = 1;
	} else {
	    ans = -1;
	}
    } else if (A[0]) {
	ans = -1;
    } else {
	LL sum = 0;
	REP (i, N+1) sum += A[i];
	ans = 1;
	LL X = 2;
	for (int i=1; i<=N; i++) {
	    if (X < A[i]) {
		ans = -1;
		break;
	    }

	    ans += A[i];
	    X -= A[i];
	    sum -= A[i];
	    amin(X, sum);
	    ans += X;
	    X *= 2;
	}
    }

    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

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

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


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll n, k, ans = 0LL;
    cin >> n >> k;
    for(ll i=k;i<=n+1;++i) {
        ll min_sum = (i-1) * i / 2;
        ll max_sum = n * (n+1) / 2 - (n-i) * (n-i+1) / 2;
        ans += (max_sum - min_sum + 1);
        ans %= MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

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

void solve(){
  int n;cin>>n;
  ll ans = 0;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      for(int k=1;k<=n;k++)
        ans += gcd(gcd(i,j),k);
  cout<<ans<<endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  solve();
  return 0;
}


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

using namespace std;

const int vy[] = {-1, 1, 0, 0}, vx[] = {0, 0, -1, 1};

int H, W;
string S[20];
int dp[20][20][21][21];

int rec(int sx, int sy, int gx, int gy)
{
  if(sx >= gx || sy >= gy) return (0);
  if(~dp[sx][sy][gx][gy]) return (dp[sx][sy][gx][gy]);
  set< int > grundy;
  for(int mx = sx; mx < gx; mx++) {
    for(int my = sy; my < gy; my++) {
      if(S[my][mx] == 'X') continue;
      grundy.insert(rec(sx, sy, mx, my) ^
                    rec(mx + 1, sy, gx, my) ^
                    rec(sx, my + 1, mx, gy) ^
                    rec(mx + 1, my + 1, gx, gy));
    }
  }
  int ret = 0;
  while(grundy.count(ret)) ++ret;
  return (dp[sx][sy][gx][gy] = ret);
}

int main()
{
  cin >> H >> W;
  for(int i = 0; i < H; i++) {
    cin >> S[i];
  }
  memset(dp, -1, sizeof(dp));
  if(rec(0, 0, W, H)) cout << "First" << endl;
  else cout << "Second" << endl;
}

Measured memory_bytes: 3864
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
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;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int h,w,k;
    int ans=4000;
    cin >>h>>w>>k;
    int len=0;
    vector<string>s(h,"");
    vector<vector<int>> sum(h+1,vector<int>(w+1,0));
    vector<int> total(h+2, 0);
    rep(i,h){
        cin>>s[i];
        rep(j,w){
            if(s[i][j]=='1'){
                sum[i][j]++;
              
            }
            sum[i + 1][j] = sum[i][j];
        }
    }

   // rep(i,h){
   //     rep(j,w){
   //         clog<<sum[i][j]<<" ";
    //    }
    //    clog<<endl;
   // }

    int W=0;
    //int b;
    int a;
    bool over=false;
  
    int cut=0;
    for(int bit=0;bit<(1<<(h-1));bit++){
      //  clog << (bit)<<endl;
         a = 0;
        cut=__builtin_popcount(bit);
        //for(int a=0;a<w;a++)
        while(a<w){
            W=0;
            total[0]-=0;
          //  clog << endl;
            for(int b=0;b<h;b++){
                
                if((bit&(1<<b))or b==h-1){
                    total[W]+=sum[b][a];
                    if(total[W]>k){
                        over=true;
                    }
               //     clog<<total[W]<<" ";
                    total[W+1]-=sum[b][a];
                    W++;
                }
               /*
                if(s[b][a]=='1'){
                    total[W]++;
                    if(total[W] >k){
                        over=true;
                        clog<<a<<" ";
                    }
                }
                if(bit&(1<<b)){
                    W++;
                }
                b++;
                */
            }
            if (over == true){
             //   cout<<" roll ";
                rep(AT, h+1){
                    total[AT] = 0;
                }
                over = false;
                if(len==1){
                    goto F;
                }
                len=1;
                cut++;
            }else{
                a++;
                W=0;
                len=0;
            }
        }

        clog<<" -->  "<<cut<<endl;
        ans=min(ans,cut);
       // clog<<endl<<endl;
        rep(AT, h + 1){
            total[AT] = 0;
        }
        F:
        len=0;
    }
    //cout<<ans<<endl;
    printf("%d\n",ans);
}
// bitDP or bit serch

/*
 5
 5
 5
 6  = 21
   3 2 2 2 2  - 1  2   2  3 2
   3 5 7 9 11   12 14 16 19 21 
*/


Measured memory_bytes: 256
#include<iostream>
#include<utility>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef pair<int,int> p;

bool prime[10000000];

int main(){
	rep(i,10000000)prime[i]=true;
	prime[0]=prime[1]=false;
	loop(i,2,1000){
		for(int j=i*2;j<10000000;j+=i)prime[j]=false;
	}
	int n;
	while(cin>>n,n){
		int cnt=0;
		bool used[n];
		rep(i,n)used[i]=true;
		loop(i,2,n-1){
			if(prime[i] && prime[n-i] && used[i] && used[n-i]){
				used[i]=used[n-i]=false;
				cnt++;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 11896
#include<iostream>
using namespace std;
int main(){
	int x[300],y[300],minx,n,miny,maxy,maxx;
	int dx[]={-1,0,1,0},dy[]={0,-1,0,1},s,w;
	x[0]=0,y[0]=0;
	while(cin>>n,n){
		miny=0;
		minx=0;
		maxx=0;
		maxy=0;
		for(int i=1;i<=n-1;i++){
			cin>>s>>w;
			x[i]=x[s]+dx[w];
			y[i]=y[s]+dy[w];
			if(x[i]>maxx)
			maxx=x[i];
			else	if(x[i]<minx)
			minx=x[i];
			else if(y[i]>maxy)
			maxy=y[i];
			else if(y[i]<miny)
			miny=y[i];
		}
		cout<<maxx-minx+1<<' '<<maxy-miny+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a


a,b,c,d = map(int,input().split())

tot = b - a + 1
e = c*d//gcd(c,d)
ans = tot - (b//c-(a-1)//c) - (b//d-(a-1)//d) + (b//e-(a-1)//e)
print(int(ans))

Measured memory_bytes: 3060
#define max(a,b)(a>b?a:b)
a[5][5];main(n,i,j,k,l,m,M){
for(scanf("%d",&n);n--;printf("%d\n",M)){
for(i=0;i<5;i++)for(j=0;j<5;j++)scanf("%d",a[i]+j);
for(M=i=0;i<5;i++)for(j=0;j<5;j++){
	for(k=i;k<5;k++){
		if(!a[k][j])break;
		for(l=j;l<5;l++){
			for(m=i;m<=k;m++){
				if(!a[m][l])goto end;
			}
		}
		end:
		l-=1;
		M=max(M,(k-i+1)*(l-j+1));
	}
}
}exit(0);}

Measured memory_bytes: 600
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
//void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }


signed main()
{
	string s;
	cin >> s;
	int ans = 0;
	REP(i, 3)
	{
		if (s[i] == '1') ans++;
	}
	cout << ans << endl;
}




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

typedef long long ll;
const int INF = 1e+9;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b) << endl;
	return 0;
}

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

int tt, nT = 1;

template<typename T>
void Read(T &x)
{
    bool neg = false;
    char c;
    for (c = getchar(); !isdigit(c); c = getchar())
        if (c == '-') neg = true;
    x = c - '0';
    for (c = getchar(); isdigit(c); c = getchar())
        x = x * 10 + c - '0';
    if (neg) x = -x;
}

template<typename T>
void Write(T x)
{
    if (x < 0)
    {
        putchar('-');
        Write(-x);
        return;
    }
    if (x > 9) Write(x / 10);
    putchar(x % 10 + '0');
}

void Enter()
{
    string s;
    for (int i = 1; i <= 3; ++i)
    {
        cin >> s;
        cout << char(s[0] - 'a' + 'A');
    }
}

void Init()
{

}

void Solve()
{

}

void PrintRes()
{

}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);   cout.tie(nullptr);
    if (ifstream("test.inp"))
    {
        freopen("test.inp", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            freopen("test.out", "w", stdout);
        #endif //CHECKING
    }
    else if (ifstream(taskname".inp"))
    {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    //Read(nT);
    for (tt = 1; tt <= nT; ++tt)
    {
        Enter();
        Init();
        Solve();
        PrintRes();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int d, t, s;
    cin >> d >> t >> s;
    int ans;
    ans = t*s;
    if (ans >= d){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define clr(v, d) memset(v, d, sizeof(v))
#define fi first
#define se second
#define pp push_back
#define pb pop_back
#define pi 3.141592654
#define MOD 1000000007 
#define cons1 1e12
#define cons2 1e6
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, ll> pa;
typedef unsigned long long int ull;
typedef double long dl;
const int N = 1e5+9,oo=-1e9;
ll dp[109][N], n, v[109][109];
ll sol(int i, int k){
	if (i == n)  return 0;
	if (!dp[i][k]) {
		if (k >= v[i][0])   
			dp[i][k] = v[i][1] + sol(i + 1, k - v[i][0]);
		dp[i][k] = max(dp[i][k], sol(i + 1, k));
	}

	return dp[i][k];
}
void solve() {
	int w;
	cin >> n >> w;
	rep(i, 0, n)
		cin >> v[i][0] >> v[i][1];
	cout << sol(0, w) << endl;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	//cin >> t;
	while (t--)
		solve();

#ifndef ONLINE_JUDGE
	- system("pause");
#endif

}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

const int INF = 1999999999;

int main(){
    int N,K;
    cin>>N>>K;
    Vi x(N);
    REP(i,N){
        cin>>x[i];
    }

    int ans = INF;
    REP(i,N-K+1){
        ans = min(ans,abs(x[i])+abs(x[i]-x[i+K-1]));
        ans = min(ans,abs(x[i+K-1])+abs(x[i]-x[i+K-1]));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define N 1005
#define LL long long
#define PAIR pair<LL,int>
using namespace std;
const int mo=1e6+7;
vector<PAIR> G[mo];
int n,c[N][4],f[4];
PAIR z[4]; LL now,ans;
LL H(int g[4],int x)
{
	int i; LL S=0;
	for(i=0;i<4;i++)
		S=S*1000+g[(i+x)&3];
	return S;
}
LL Z(int g[4])
{
	int i,j,h[4]; LL S=0;
	for(i=0;i<4;i++) h[i]=g[i];
	for(i=1;i<4;i++){
		for(j=0;j<4;j++)
			if(g[(j+i)&3]!=h[j]) break;
		if(j<4&&g[(j+i)&3]<h[j])
			for(j=0;j<4;j++) h[j]=g[(j+i)&3];
	  }
	for(i=0;i<4;i++)
		S=S*1000+h[i];
	return S;
}
void ins(LL S,int d)
{
	int i,u=S%mo;
	for(i=0;i<G[u].size();i++)
		if(G[u][i].first==S){ G[u][i].second+=d; return ;}
	G[u].push_back(PAIR(S,d));
}
int cnt(LL S)
{
	int i,u=S%mo;
	for(i=0;i<G[u].size();i++)
		if(G[u][i].first==S) return G[u][i].second;
	return 0;
}
int cir(LL S)
{
	int i,j,g[4],cnt=0;
	g[0]=S/1000000000;
	g[1]=(S/1000000)%1000;
	g[2]=(S/1000)%1000;
	g[3]=S%1000;
	for(i=0;i<4;i++){
		for(j=0;j<4;j++)
			if(g[j]!=g[(j+i)&3]) break;
		if(j>=4) cnt++;
	  }
	return cnt;
}
int main()
{
	int i,j,k,l,p,q; LL v;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		for(j=0;j<4;j++)
			scanf("%d ",&c[i][j]);
		for(j=0;j<4;j++)
			ins(H(c[i],j),1);
	  }
	for(i=1;i<=n;i++){
		for(j=0;j<4;j++) ins(H(c[i],j),-1);
		for(j=0;j<=0;j++)
			for(k=i+1;k<=n;k++){
				for(l=0;l<4;l++) ins(H(c[k],l),-1);
				for(l=0;l<4;l++){
					f[0]=c[k][(l+1)&3],f[1]=c[k][l],f[2]=c[i][(j+1)&3],f[3]=c[i][j],v=Z(f),z[0]=PAIR(v,cnt(v));
					f[0]=c[i][(j+3)&3],f[1]=c[i][(j+2)&3],f[2]=c[k][(l+3)&3],f[3]=c[k][(l+2)&3],v=Z(f),z[1]=PAIR(v,cnt(v));
					f[0]=c[k][(l+1)&3],f[1]=c[i][j],f[2]=c[i][(j+3)&3],f[3]=c[k][(l+2)&3],v=Z(f),z[2]=PAIR(v,cnt(v));
					f[0]=c[i][(j+1)&3],f[1]=c[k][l],f[2]=c[k][(l+3)&3],f[3]=c[i][(j+2)&3],v=Z(f),z[3]=PAIR(v,cnt(v));
					sort(z,z+4),q=0,now=1;
					for(p=0;p<4;p++){
						if(p&&z[p].first==z[p-1].first) q+=cir(z[p].first); else q=0;
						now*=(z[p].second-q);
					  }
					ans+=now;
				  }
				for(l=0;l<4;l++) ins(H(c[k],l),1);
			  }
		for(j=0;j<4;j++) ins(H(c[i],j),1);
	  }
	cout<<ans/3;
	return 0;
}


Measured memory_bytes: 23808
#include <iostream>
#include <numeric>
#include <vector>
#include <string>

std::string normalize(std::string str)
{
  std::vector<int> ch(26,0);
  std::string res;
  int n = 0;
  for (int i=0; i<str.size(); ++i) {
    int c = str[i] - 'a';
    if (ch[c] == 0) {
      ch[c] = ++n;
    }
    res.push_back((char)('a'+ch[c]-1));
  }
  return res;
}

int main()
{
  std::string s,t;

  std::cin >> s >> t;
  s = normalize(s);
  t = normalize(t);
//  std::cout << "s:" << s << std::endl;
//  std::cout << "t:" << t << std::endl;
  
  if (s == t) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}


Measured memory_bytes: 1464
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

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

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

mint factorial(ll n) {
  mint answer = 1;
  while (n > 1) {
    answer *= n;
    n--;
  }
  return answer;
}

mint combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

mint permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

// setprecision(8) 桁数指定
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

vector<ll> Eratosthenes(const ll N) {
  bool is_prime[1000000 + 1];
  vector<ll> P;
  for (ll i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (ll i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  FOR(i, 1, w + 1) {
    if (max(h, w) * i >= n) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  const items = input.map(v => v.split(" "))
  const n = parseInt(items[0][0], 10)
  const m = parseInt(items[0][1])

  const judge = (num) => {
    if (num < 2) {
      return 0
    } else if (num === 2) {
      return 1
    } else {
      return num * (num - 1) / 2
    }
  }

  //文字列から10進数に変換するときはparseIntを使います
  // const a = parseInt(input[0], 10);
  //出力
  console.log(judge(n) + judge(m));
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main()
{

	int a, b, c, d;

	cin >> a >> b >> c >> d; 
	if (  b <= c || a >= d ){
		cout << "0" << endl;
	}
	else {
		if ( b <= d && a <= c ) {
			cout << b-c << endl;
		}
		else {
			if ( c <= b && b <= d ) {
				cout << b-a << endl;
			}
			else {
				if (c >= a && b >= d ) {
					cout << d-c << endl;
				}
				else {
					cout << d-a << endl;
				}
			}
		}
	}	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	string s;
	cin >> s;
	if (s[0] == s[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    ans = float("inf")
    for i in range(n+1):
        m = 0
        k = i
        while k > 0:
            m += k%6
            k //= 6
        k = n-i
        while k > 0:
            m += k%9
            k //= 9
        ans = min(ans,m)
    print(ans)
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 41200
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

queue<int> A[1001];

int main()
{
	int N, Ain, total, cnt = 0;
	int peer, ans = 0;
	queue<pair<int, int> > game;

	cin >> N;
	repc(i, 1, N) {
		rep(j, N - 1) {
			cin >> Ain;
			A[i].push(Ain);
		}
	}

	repc(i, 1, N) {
		map<int, bool> skip;

		peer = A[i].front();
		if (skip.count(i) > 0) continue;
		if (skip.count(peer) > 0) continue;

		if (peer > i&& A[peer].front() == i) {
			game.push(make_pair(i, peer));
			skip[peer] = true;
		}
	}

	total = N * (N - 1) / 2;
	while (cnt < total) {
		map<int, bool> skip;
		int num = game.size();

		ans++;
		cnt += num;

		if (num == 0) {
			ans = -1;
			break;
		}

		rep(i, num) {
			pair<int, int> com = game.front(); game.pop();
			int first = com.first;
			int second = com.second;
			int p1, p2;

			A[first].pop();
			A[second].pop();

			if (!A[first].empty()) {
				p1 = A[first].front();

				if (skip.count(first) == 0 || skip.count(p1) == 0) {
					if (A[p1].front() == first) {
						game.push(make_pair(first, p1));
						skip[first] = true;
						skip[p1] = true;
					}
				}
			}

			if (!A[second].empty()) {
				p2 = A[second].front();

				if (skip.count(second) == 0 || skip.count(p2) == 0) {
					if (A[p2].front() == second) {
						game.push(make_pair(second, p2));
						skip[second] = true;
						skip[p2] = true;
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
map<pair<int,int>,bool>ex;
const int N = 2e5+10;
vector<int>G[N];
int vis[N];
int ctr;
void dfs(int u){
	ctr++;
	vis[u] = 1;
	int sz = G[u].size();
	int v;
	for (int i = 0; i < sz; i++){	
		v = G[u][i];
		if (!vis[v])
			dfs(v);
	}
}
int main(){
	int n,m,a,b;
	cin >> n >> m;

	while (m--){
		cin >> a >> b;
		if (a > b)
			swap(a,b);
		if (ex.count(make_pair(a,b)))
			continue;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int>v;
	for (int i = 1; i <= n; i++){
		if (!vis[i]){
			ctr = 0;
			dfs(i);
			v.push_back(ctr);
		}
	}
	int ans = 0;
	sort(v.begin(), v.end());
	int sub = 0;
	for (int i = 0; i < v.size(); i++){
		v[i] -= sub;
		v[i] = max(v[i],0);
		ans += v[i];
		sub += v[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 24688
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
s = readline().rstrip()
q = int(readline())
queries = [[i for i in readline().split()] for _ in range(q)]

t = ''

for query in queries:
    if query[0] == '1':
        s,t = t,s
    else:
        if query[1] == '1':
            t += query[2]
        else:
            s += query[2]
            
print(t[::-1]+s)

Measured memory_bytes: 27892
import collections

N = int(input())

words = [input() for i in range(N)]

C = collections.Counter(words)
if C.most_common()[0][1] > 1:
    print('No')
    exit()

for i in range(N-1):
    if words[i][-1] != words[i+1][0]:
        print('No')
        exit()

print('Yes')


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

int main () {
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < (s.size()/2); i++) {
        if (s.at(i) != s.at(s.size() -1 -i)) {
            ans ++;
        }
    }
    printf("%d",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second

main(){
    int n;
    cin>>n;
    r(i,100){
        int x=i+1;
        int y=i+i*10+i*100;
        if(n<=y){
            cout<<y<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
/*

  "With age, comes wisdom. With travel, comes understanding.
   Remember that happiness is a way of travel – not a destination"

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define ld             long double
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

int const N = 25;
int vis[N][N], n, m, mx;
int dx[4] = { -1, +1, 0, 0};
int dy[4] = {0, 0, +1, -1};

char c[N][N];

void bfs(int x, int y)
{
	priority_queue<pii, vector<pii>, greater<pii> > q;
	q.push({x, y});
	vis[x][y] = 1;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			vis[i][j] = 1e9;

	// bug(x, y);

	vis[x][y] = 0;

	while (!q.empty())
	{
		int x = q.top().first;
		int y = q.top().second;
		q.pop();
		for (int dir = 0; dir < 4; dir++)
		{
			int x1 = x + dx[dir];
			int y1 = y + dy[dir];
			if (x1 < 1 || y1 < 1 || x1 > n || y1 > m) continue;

			if ((vis[x1][y1] > vis[x][y] + 1) && c[x1][y1] == '.')
			{
				vis[x1][y1] = vis[x][y] + 1;
				q.push({x1, y1});
			}
		}
	}

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			// cout << vis[i][j] << " ";
			if (vis[i][j] != 1e9)
				mx = max(mx, vis[i][j]);
		}
		// cout << endl;
	}

}

void solve()
{
	int i, j;
	cin >> n >> m;
	for (i = 1; i <= n; i++)
		for (j = 1; j <= m; j++)
			cin >> c[i][j];

	for (i = 1; i <= n; i++)
		for (j = 1; j <= m; j++)
			if (c[i][j] == '.')
				bfs(i, j);

	cout << mx;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


	cout << setprecision(9) << fixed;
	clock_t z = clock();
	solve();
	cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

	return 0;
}

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

def io_generator():
	return input()

#+++++++++++++++++++

def t_search(a_list, pos):
	oo=10**20
	if pos< a_list[0]:
		pm=oo
		pp=a_list[0]-pos
		return pm,pp
	elif pos>a_list[-1]:
		pm=pos-a_list[-1]
		pp=oo
		return pm,pp
	ok=0
	ng=len(a_list)-1
	while abs(ok-ng)>1:
		mid=(ok+ng)//2
		if a_list[mid]<=pos:
			ok=mid
		else:
			ng=mid
	
	if a_list[ok]==pos:
		return 0,0
	pm=a_list[ok]
	pp=a_list[ok+1]
	return pos-pm, pp-pos

def main(io):
	a,b,q= map(int, io().split())
	syu=list(range(a))
	ten=list(range(b))
	for i in range(a):
		syu[i]=int(io())
	for i in range(b):
		ten[i]=int(io())
		
	ret=list(range(q))
	for i in range(q):
		init_pos=int(io())
		md_syu,pd_syu = t_search(syu,init_pos)
		md_ten,pd_ten= t_search(ten,init_pos)
		r=min(
			max(md_syu,md_ten),
			md_syu*2+pd_ten,
			pd_syu*2+md_ten,
			md_ten*2+pd_syu,
			pd_ten*2+md_syu,
			max(pd_syu,pd_ten)
			)
		ret[i]=str(r)
		
	for r in ret:
		print(r)

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	main(io)

Measured memory_bytes: 19312
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n, p, m = 0, ans = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> p;
        ans += p;
        m = max(m, p);
    }
    cout << ans - m / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a,b;
int sum1;
int ans;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>a>>b;
	sum1=n*a;
	ans=min(sum1,b);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
/******************************\
*  Everyone has a different way of thinking, so God Created us
   Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Mo_Murad   *
\******************************/
#include<bits/stdc++.h>
using namespace std;
#include<unordered_map>
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define SZ(c) int(c.size())
#define ff first
#define ss second
#define INF INT32_MAX
#define _INF INT32_MIN
#define PQ priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	LL c;
	while (a != 0) {
		c = a;
		a = b % a;
		b = c;
	}
	return b;
}
int LCM(int a, int b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		printf("%d ", 2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			printf("%d ", i);
			n /= i;
		}
	}
	if (n > 2)printf("%d ", n);
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
void dijjkstra(int src, int n) {
	list<ipair>adj[1000005];
	vector<bool>visited(1000005, false);
	vector<int>dis(1000005, 1e9);
	PQ<ipair, vector<ipair>, greater<ipair>>pq;
	pq.push(MP(0, 1));
	dis[src] = 0;
	while (!pq.empty())
	{
		int u = pq.top().ss;
		visited[u] = true;
		pq.pop();
		list<ipair>::iterator i;
		for (i = adj[u].begin(); i != adj[u].end(); i++)
		{
			int v = i->ff;
			int we = i->ss;
			if (!visited[v] && dis[v] > dis[u] + we)
			{
				dis[v] = dis[u] + we;
				pq.push(MP(dis[v], v));
			}
		}
	}
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n, k, q;
	cin >> n >> k >> q;
	vector<int>a(n, k);
	for (int i = 0; i <q; i++)
	{
		int x;
		cin >> x;
		x--;
		a[x]++;
	}
	for (int i = 0; i < n; i++)
	{
		if (a[i] <= q)
			cout << "No\n";
		else cout << "Yes\n";
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
using Graph = vector<vector<ll>>;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);


int main(){
    ll a, b, k;
    cin >> a >> b >> k;
    if((b - a + 1) >= 2*k){
        Rep(i, a, a+k){
            cout << i << endl;
        }
        Rep(i, b-k+1, b+1){
            cout << i << endl;
        }
    }
    else{
        Rep(i, a, b+1){
            cout << i << endl;
        }
    }
}


Measured memory_bytes: 3644
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> l(N);
  for (int i = 0; i < N; i++) {
    cin >> l[i];
  }
  sort(l.rbegin(), l.rend());
  ll ans = 0;
  for (int i = 0; i < K; i++) {
    ans += l[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256