akhauriyash/Code-Regression huggingface dataset:
import math
# import numpy as np
import itertools
N = int(input())
x = []
y = []
for i in range(N):
    s1,s2 = map(int,input().split())
    x.append(s1)
    y.append(s2)
    
def length(i,j):
    return math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)

LI = [i for i in range(N)]
A = list(itertools.permutations(LI))
ans = 0
for item in A:
#     print(item)
    count = 0
    for i in range(len(item)):
        if i == len(item)-1:
            break
#         print(length(item[count],item[count+1]))
        ans = ans+length(item[count],item[count+1])
        count +=1
print(ans/math.factorial(N))

Measured memory_bytes: 47724
a,b,c=map(int,input().split())
na=0
nb=0
s=input()
for i in range(a):
  if s[i]=='a':
    if na+nb<b+c:
      print('Yes')
      na+=1
    else:
      print('No')
  elif s[i]=='b':
    if na+nb<b+c and nb<c:
      print('Yes')
      nb+=1
    else:
      print('No')
  else:
    print('No')

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

int main(){
    char S[19];
    cin >> S;
    for(int i=0;i<5;i++){
        cout << S[i];
    }
    cout << " ";
    for(int i=6;i<13;i++){
        cout << S[i];
    }
    cout << " ";
    for(int i=14;i<19;i++){
        cout << S[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
const int mod = 1000000007;
int main(void) {
    int n, m; cin >> n >> m;
    int sw[10][10]={0};
    rep(i, m) {
        int k; cin >> k;
        rep(j, k) {
            int c;
            cin >> c;
            sw[i][c-1] = 1;
        }
    }
    vector<int> p(m);
    rep(i, m) {
        cin >> p[i];
    }
    int ans = 0;
    rep(i,(1<<n)) {
        vector<int> judge(n);
        for(int j=0;j<n;j++){//要素取り出す
            if((i>>j)&1){
                judge.push_back(j);
            }
        }
        bool flag = true;
        rep(j, m) {
            int cnt = 0;
            for(int on : judge) {
                if(sw[j][on]) cnt++;
            }
            if(cnt%2!=p[j]) flag = false;
            if(!flag) break;
        }
        if(flag) ans++;
    }
    cout << ans;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var n = Input();
            var v = Input3();
            Array.Sort(v);
            double mix =(double)(v[0]+v[1])/2 ;
            double ans = mix;
           
            
            for(long i = 2; i <= n-1; i++)
            {
                ans =(mix+v[i])/2;
                mix = ans;
              
            }

            ;

            Console.WriteLine(ans);
                
                





        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }

        
       
    }
}


Measured memory_bytes: 11348
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     setbits(x)  __builtin_popcountll(x)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    string s;
    cin>>s;
    int q;
    cin>>q;
    deque<char>d;
    for(char c:s) d.pb(c);
    bool beg=1;
    while(q--){
        int t;
        cin>>t;
        if(t==1){
            beg=!beg;
        }
        else{
            char c;
            cin>>t>>c;
            if(t==1){
                if(beg) d.push_front(c);
                else d.pb(c);
            }
            else{
                if(!beg) d.push_front(c);
                else d.pb(c);
            }
        }
    }
    if(!beg) reverse(all(d));
    for(char c:d) cout<<c;
    return 0;
}


Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
string c;
signed main() {
	cin >> n;
	set <string> s;
	for(int i = 0;i<n;i++){
		cin >> c;
		s.insert(c);
	}cout << s.size() << endl;
	return 0;
}

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

int N;
const int MAX_N = 2.0e5 + 100;
int A[MAX_N];
 
int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];

    int N1 = 0;
    int N2 = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] >= N1) {
            N2 = N1;
            N1 = A[i];
        }
        else if (A[i] >= N2) {
            N2 = A[i];
        }
    }

    if (N1 == N2) {
        for (int i = 0; i < N; i++) {
            cout << N1 << endl;
        }
    }
    else {
        for (int i = 0; i < N; i++) {
            if (A[i] == N1) {
                cout << N2 << endl;
            }
            else {
                cout << N1 << endl;
            }
        }
    } 

    return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string s, t; cin >> s >> t;
	int ans = 0;
	rep(i, 0, s.size()) {
		if (s[i] != t[i])++ans;
	}
	cout << ans << "\n";
	
	return 0;
}

Measured memory_bytes: 3780
//header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) begin(x),end(x)
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;
 
template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}
 
    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};
 
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
template <class T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class K, class V> using Umap = gp_hash_table<K, V>;
using Trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;
 
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};
//}}}

//}}}
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    int k;
    cin >> k;

    rep(i,k){
        cout << "ACL";
    }
    cout << '\n';

    return 0;
}

Measured memory_bytes: 3532
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int k;
  cin>>k;
  queue<string> q;
  for(int i=1;i<=9;i++){
    char pushed='0'+i;
    q.push(string{pushed});
  }
  int count=1;
  while(true){
    string curr=q.front();
    q.pop();
    if(count==k){
      cout<<curr<<endl;
      return 0;
    }
    for(int d=-1;d<=1;d++){
      char added=curr.back()+d;
      if(added<'0'||'9'<added) continue;
      string next=curr+added;
      q.push(next);
    }
    count++;
  }


  return 0;
}




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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define in2(x, y) int x,y;cin>>x>>y
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)

#define lim5 100002
#define lim9 1000000002

#define deg(rad) (((rad)/2/M_PI)*360)

int main() {
	in(n);
	string s, t = "";
	cin >> s;

	if (n % 2) {
		out("No");
		return 0;
	}

	rep (i, n / 2) {
		if (s[i] != s[i + n / 2]) {
			out("No");
			return 0;
		}
	}
	out("Yes");

	return 0;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    pos = (0, 0)
    time_before = 0
    can = True

    for i in range(n):
        t, x, y = map(int, input().split())
        dist = abs(pos[0] - x) + abs(pos[1] - y)
        time = t - time_before
        # 時間内に到達不可
        if dist > time:
            can = False
            break
        if (dist % 2 == 0 and time % 2 != 0) or (dist % 2 != 0 and time % 2 == 0):
            can = False
            break
        time_before = t
        pos = (x, y)
    print('Yes' if can else 'No')

if __name__ == '__main__':
    main()


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

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    map<ll, ll> mmi;
    map<ll, ll> mpl;
    rep(i, N){
        cin >> A[i];
        int num = i+1;
        mmi[A[i] - num]++;
        mpl[A[i] + num]++; 
    }

    ll ans = 0;
    for(auto p : mmi){
        auto key = p.first;
        auto value = p.second;
        int pl = mpl[-key];
        ans += value * pl;
    }

    cout << ans << endl;


    return 0;
}

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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	int ans = 0,cur = 0;
	deque<int> st;
	int lst = a[0];
	for(int i=1;i<n;i++){
		if(a[i] <= lst)cur++;
		else cur = 0;
		ans = max(ans , cur);
		lst = a[i];
	}
	cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int h, w, n;
int sr, sc;
string s, t;

bool die(int x, int m, char u, char d) {
    int y = x;
    FOR(i,0,n-1){
        if (s[i] == u) --y;
        if (y < 1) return 1;
        if (t[i] == d) y = min(y+1, m);
    }

    y = x;
    FOR(i,0,n-1){
        if (s[i] == d) ++y;
        if (y > m) return 1;
        if (t[i] == u) y = max(y-1, 1);
    }

    return 0;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> h >> w >> n;
    cin >> sr >> sc;
    cin >> s >> t;
    if (die(sr, h, 'U', 'D') or die(sc, w, 'L', 'R')) {
        cout << "NO" << '\n';
    } else {
        cout << "YES" << '\n';
    }
}


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

long long R, W, H, X, Y, i, j, L[510][510], O, T, a, b;
long long m[5] = {1, 0, -1, 0, 1};
bool u[510][510], v[510][510];
vector<long long> d1, d2;
tuple<long long, long long, long long> t;
priority_queue<tuple<long long, long long, long long>, vector<tuple<long long, long long, long long> >, greater<tuple<long long, long long, long long> > > q;

int main(){
  for(;scanf("%lld", &R), R != 0;){
  d1.clear();
  d2.clear();
  scanf("%lld%lld%lld%lld", &W, &H, &X, &Y);
  for(i = 0; i < H; ++i){
    for(j = 0; j < W; ++j){
      scanf("%lld", L[j] + i);
    }
  }
  for(i = 0; i < 510; ++i){
    for(j = 0; j < 510; ++j){
      u[j][i] = false;
      v[j][i] = false;
    }
  }
  d1.push_back(0);
  d2.push_back(0);
  q.push(make_tuple(1, X - 1, Y - 1));
  u[X - 1][Y - 1] = true;
  while(!q.empty()){
    t = q.top();
    q.pop();
    tie(O, a, b) = t;
    d1.push_back(O);
    //cout << O << endl;
    for(i = 0; i < 4; ++i){
      if(0 <= a + m[i] && a + m[i] < W && 0 <= b + m[i + 1] && b + m[i + 1] < H && !u[a + m[i]][b + m[i + 1]]){
        //cout << L[a + m[i]][b + m[i + 1]] << " " << a + m[i] << " " << b + m[i + 1] << endl;
	u[a + m[i]][b + m[i + 1]] = true;
	q.push(make_tuple(max(O, L[a + m[i]][b + m[i + 1]]), a + m[i], b + m[i + 1]));
      }
    }
  }
  O = W * H + 1;
  scanf("%lld%lld%lld%lld", &W, &H, &X, &Y);
  for(i = 0; i < H; ++i){
    for(j = 0; j < W; ++j){
      scanf("%lld", L[j] + i);
    }
  }
  q.push(make_tuple(1, X - 1, Y - 1));
  v[X - 1][Y - 1] = true;
  while(!q.empty()){
    t = q.top();
    q.pop();
    tie(T, a, b) = t;
    d2.push_back(T);
    for(i = 0; i < 4; ++i){
      if(0 <= a + m[i] && a + m[i] < W && 0 <= b + m[i + 1] && b + m[i + 1] < H && !v[a + m[i]][b + m[i + 1]]){
	//cout << a + m[i] << " " << b + m[i + 1] << endl;
	v[a + m[i]][b + m[i + 1]] = true;
	q.push(make_tuple(max(T, L[a + m[i]][b + m[i + 1]]), a + m[i], b + m[i + 1]));
      }
    }
  }
  T = W * H + 1;
  a = 1099511627775LL;
  /*for(i = 0, j = O; i < j; ++i){
    cout << d1[i] << " ";
  }
  cout << endl;
  for(i = 0, j = T; i < j; ++i){
    cout << d2[i] << " ";
  }
  cout << endl;// */
  for(i = 0LL, j = R + 1; i < j; ++i){
    //cout << i << " " << R - i << endl;
    if(R - i <= T && i <= O)a = min(a, d1[i] + d2[R - i]);
  }
  cout << a << endl;
  }
  return 0;
}

Measured memory_bytes: 11812
#include<stdio.h>

main(void){
	int a[3],x;
		scanf("%d %d %d\n",&a[0],&a[1],&a[2]);
	
	if(a[0]>a[1]){
	x=a[0];
		a[0] = a[1];
	a[1]=x;}
	
	if(a[1]>a[2]){
	x=a[1];
		a[1] = a[2];
	a[2]=x;}
	
	if(a[0]>a[1]){
	x=a[0];
		a[0] = a[1];
	a[1]=x;}
	
	printf("%d %d %d\n",a[0],a[1],a[2]);
return 0;
}


Measured memory_bytes: 2088
#include"bits/stdc++.h"
using namespace std;
int f[100001],a[101];
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(a[j]<=i&&!f[i-a[j]])
			{
				f[i]=1;
				break;
			}
			else if(a[j]<=i&&f[i-a[j]])
				f[i]=0;
		}
		//printf("**%d %d\n",i,f[i]);
	}
	if(f[m]==1)
		printf("First");
	else
		printf("Second");
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define F first
#define S second
#define SHN 1e9
#define lSHN 1e18
using namespace std;
int n,m;
ll a[1010][3];
ll res=-lSHN;
vector<ll> v; 
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++)
	    cin >>a[i][0]>>a[i][1]>>a[i][2];
	for (int tr=0;tr<8;tr++)
	{
		v.clear();
		for (int i=0;i<n;i++)
		{
			int t=tr;
			ll r=0;
			for (int j=0;j<3;j++)
			{
				if (t & 1) r+=a[i][j];
				else r-=a[i][j];
				t/=2;
			}
			v.push_back(r);
		} 
		sort(v.begin(),v.end());
		ll r=0;
		for (int i=0;i<m;i++) r+=v[n-1-i];
		res=max(res,r);
	}
	cout <<res;
	return 0;
}

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

int N, C;
int D[31][31];
int c[501][501];


int main(){
    cin >> N >> C;
    for(int i = 1; i <= C; i++){
        for(int j = 1; j <= C; j++){
            scanf("%d", &D[i][j]);
        }
    }
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            scanf("%d", &c[i][j]);
        }
    }

    long long ans = 1e15;
    long long cost[3][31] = {};

    for(int i = 1; i <= C; i++){
        for(int x = 1; x <= N; x++){
            for(int y = 1; y <= N; y++){
                cost[(x+y)%3][i] += D[c[x][y]][i];
            }
        }
    }
                
    
    for(int p = 1; p <= C; p++){
        for(int q = 1; q <= C; q++){
            for(int r = 1; r <= C; r++){
                if(p == q || q == r || r == p){
                    continue;
                }
                long long tmp = 0;
                tmp = cost[0][p] + cost[1][q] + cost[2][r];
                ans = min(ans, tmp);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<int> B(N-1);
  for(int &i:B)
    cin>>i;
  int ans=B[0]+B[N-2];
  for(int i=1;i<N-1;i++)
    ans+=min(B[i],B[i-1]);
  cout<<ans<<endl;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  string n;
  cin >> n;
  i32 ans = 0;
  rep(i, n.size()) ans += n[i] - '0';
  {
    i32 cnt = n[0] - '1';
    cnt += (n.size() - 1) * 9;
    amax(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
g = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    g[a].append((b,c))
    g[b].append((a,c))
q,k = map(int,input().split())
k -= 1
c = [-1]*n
c[k] = 0
stack = [k]
while stack:
    cur = stack.pop()
    for next_,cost in g[cur]:
        if c[next_]<0:
            c[next_] = c[cur]+cost
            stack.append(next_)

for i in range(q):
    x,y = map(lambda x: int(x)-1,input().split())
    print(c[x]+c[y])

Measured memory_bytes: 103452
N = int(input())
args = [int(p) for p in input().split()]
sort_list = args[:]
sort_list.sort()

cnt = 0
for i in range(N):
	if args[i] != sort_list[i]:
		cnt += 1
	
if cnt == 0 or cnt == 2:
	print("YES")
else:
	print("NO")


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef pair<int, int> pii;
typedef pair<string, int> P;
typedef long long ll;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[ry]>rank[rx]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};
vector<ll> fac(1e6),inv(1e6),finv(1e6);
void initcom(){
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(int i=2;i<1e6;++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(int n,int k){
    if(n<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
int compress(vector<int> &x,int w){
    vector<int> sx;
    for(int i=0;i<(int)x.size();++i){
        for(int d=-2;d<=2;++d){
            int t=x[i]+d;
            if(t>=0&&t<w) sx.push_back(t);
        }
    }
    sort(sx.begin(),sx.end());
    sx.erase(unique(sx.begin(),sx.end()),sx.end());
    for(int i=0;i<(int)x.size();++i){
        x[i]=lower_bound(x.begin(),x.end(),x[i])-x.begin();
    }
    return (int)sx.size();
}
int main(){
    int n,k;cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;++i) cin>>a[i];
    for(int i=k;i<n;++i){
        if(a[i-k]<a[i]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 27556
def main():
    A = [list(map(int,input().split(" "))) for i in range(3)]
    N = int(input())
    b_list = [int(input()) for _ in range(N)]

    for i in range(3):
        for j in range(3):
            for b in b_list:
                if(A[i][j] == b):
                    A[i][j] = 0

    flag = False
    for i in range(3):
        for j in range(3):
                if(j+2 < 3 and A[i][j] == 0 and A[i][j+1] == 0 and A[i][j+2] == 0):
                    flag = True
                    break
                if(i+2 < 3 and A[i][j] == 0 and A[i+1][j] == 0 and A[i+2][j] == 0):
                    flag = True
                    break
                if(i+2 < 3 and j+2 < 3 and A[i][j] == 0 and A[i+1][j+1] == 0 and A[i+2][j+2] == 0):
                    flag = True
                    break
                if(i-2 >= 0 and j-2 >= 0 and A[i][j] == 0 and A[i-1][j-1] == 0 and A[i-2][j-2] == 0):
                    flag = True
                    break
                if(i-2 >= 0 and j+2 < 3 and A[i][j] == 0 and A[i-1][j+1] == 0 and A[i-2][j+2] == 0):
                    flag = True
                    break
                if(i+2 < 3 and j-2 >= 0 and A[i][j] == 0 and A[i+1][j-1] == 0 and A[i+2][j-2] == 0):
                    flag = True
                    break
        if(flag):
            break

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

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
BIG = (10 ** 9) + 7

f_list = [1] * 200000
f_r_list = [1] * 200000

for i in range(199999):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % BIG)

def power(n, x):
	if x == 1:
		return n
	elif x % 2 == 0:
		return power(int((n * n) % BIG), int(x / 2))
	else:
		return int((n * power(n, x - 1)) % BIG)

f_r_list[-1] = power(f_list[-1], BIG - 2)

for i in range(2, 200001):
	f_r_list[-i] = int((f_r_list[-i + 1] * (200002 - i)) % BIG)

def comb(n, r):
	if n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % BIG) * f_r_list[r - 1]) % BIG 

h, w, a, b = map(int, input().split())

ans = 0

for i in range(h - a):
	ans = int((ans + int((comb(b + i - 1, b - 1) * comb(h + w - b - i - 2, w - b - 1)) % BIG)) % BIG)

print(int(ans))

Measured memory_bytes: 18804
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


n,m = map(int,input().split())
X = [list(map(int,input().split())) for i in range(n)]
res = 0
for (a,b,c) in product([-1,1],[-1,1],[-1,1]):
    tmp=[]
    for x,y,z in X:
        tmp.append(a*x+b*y+c*z)
    tmp.sort(reverse=True)
    res = max(res,sum(tmp[:m]))

print(res)

Measured memory_bytes: 40688
import java.util.*;

public class Main{
    
    public static final int MOD = (int)1e9+7;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        
        Combination comb = new Combination((int)1e5*5, MOD);
        
        long ans = 0;
        for(int i=0; i<Math.min(k, n-1)+1; i++){
            long room = comb.c(n, i);
            long c = comb.h(n-i, i);
            long tmp = room*c%MOD;
            ans = (ans+tmp)%MOD;
        }
        
        System.out.println(ans);
    }
}

class Combination{
    int mod;
    long[] fact;
    long[] rfact;
    
    public Combination(int max, int mod){
        this.mod = mod;
        fact = new long[max];
        rfact = new long[max];
        fact[0] = 1;
        rfact[0] = 1;
        for(int i=1; i<max; i++){
            fact[i] = (fact[i-1]*i)%mod;
            rfact[i] = mod_inverse(fact[i], mod);
        }
    }
    
    public static long mod_pow(long x, long p, long m){
        long a = 1;
        while(p>0){
            if(p%2==1){
                a = a*x%m;
            }
            x = x*x%m;
            p /= 2;
        }
        return a;
    }
    
    public static long mod_inverse(long a, long m){
        return mod_pow(a, m-2, m);
    }
    
    public long p(int n, int r){
        if(r < 0 || n < r) return 0;
        return fact[n] * rfact[r]%mod;
    }
    
    public long c(int n, int r){
        if(r < 0 || n < r) return 0;
        return fact[n] * rfact[r]%mod * rfact[n-r]%mod;
    }
    
    public long h(int n, int r){
        if(n < 0 || r < 0) return 0;
        return r==0||n==0 ? 1 : c(n+r-1, r);
    }
}


Measured memory_bytes: 30420
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

int main(){
	int r;
	cin >> r;
	double ans = 2 * M_PI * r;
	printf("%lf", ans);
} 

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int a = in(), b = in(), c = in();
  int x = in();

  int ans = 0;
  for (int i = 0; i <= a; ++i) {
    for (int j = 0; j <= b; ++j) {
      for (int k = 0; k <= c; ++k) {
        if (500 * i + 100 * j + 50 * k == x) ans++;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define N 300001
#define E 6000001
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;void re(int& x)
{
	while(ch=getchar(),ch<33);x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
}
using namespace std;
int n,m,last[N];
int siz,root[N],ls[E],rs[E],sum[E];
struct node
{
	int a,b;
	bool operator < (const node& i)const{return a<i.a;}
}w[N];
void build(int &x,int y,int l,int r,int a)
{
	x=++siz;
	ls[x]=ls[y];
	rs[x]=rs[y];
	sum[x]=sum[y]+1;
	if(l==r)return;
	int mid=l+r>>1;
	if(a<=mid)build(ls[x],ls[y],l,mid,a);
	else build(rs[x],rs[y],mid+1,r,a);
}
int query(int x,int l,int r,int a)
{
	if(!x)return 0;
	if(a<=l)return sum[x];
	int mid=l+r>>1;
	if(a>mid)return query(rs[x],mid+1,r,a);
	else return query(ls[x],l,mid,a)+query(rs[x],mid+1,r,a);
}
int main()
{
	re(n),re(m);
	for(int i=1;i<=n;++i)
		re(w[i].a),re(w[i].b);
	sort(w+1,w+n+1);
	for(int i=1;i<=n;++i)
	{
		build(root[i],root[i-1],1,m,w[i].b);
		last[w[i].a]=root[i];
	}
	for(int i=1;i<=m;++i)
		if(!last[i])
			last[i]=last[i-1];
	for(int i=1;i<=m;++i)
	{
		int ans=0;
		for(int j=i;j<=m;j+=i)
			ans+=query(last[j],1,m,j)-query(last[j-i],1,m,j);
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 73088
# coding: utf-8
# Your code here!
#n = int(input())
#x,y = map(int,input().split())	
#list=[int(input()) for i in range(n)]


def digitsum(x):
    s=0
    while(x > 0):
        a = x%10
        x = x//10
        s+= a
    return(s)

n = int(input())

ans = 1<<20
for i in range(1,n):
    ans = min(ans,digitsum(i)+digitsum(n-i))

print(ans)
    


Measured memory_bytes: 40812
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0;
    rep(i, n) if (s[i] == 'R') r++;
    if (r > n - r) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import math
x =  [int(s) for s in input().split()]
numList = [[int(s) for s in input().split()] for i in range(x[0])]
sum = 0
for i in range(len(numList)):
    for j in range(i+1,len(numList)):
        d = 0
        for k in range(x[1]):
            d += (numList[i][k] - numList[j][k]) ** 2
        num = d ** 0.5
        numStr = str(num).split('.')
        if(numStr[len(numStr)-1] == '0'):
            sum += 1
            
print(sum)
        
            
            
            

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


int main() {
    int N,K; cin >> N >> K;
    int h[N];
    for (int i=0; i<N; i++) cin >> h[i];
    sort(h,h+N);
    int min;
    min = h[K-1]-h[0];
    for (int i=1; i<=N-1-K+1;i++){
        if (min >= h[i+K-1]-h[i]){
            min = h[i+K-1]-h[i];
        }
    }
    cout << min << endl;
    
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9+7

using namespace std;
typedef long double ld;

ld calc(int s, int a, int c, const vector<int> &in){
  int r[260];
  r[0] = s;
  for(int i=1; i<260; i++){
    r[i] = (a * r[i-1] + c) % 256;
  }
  map<int, int> count;
  REP(i, in.size()){
    int target = (in[i] + r[i+1]) % 256;
    if(count.find(target)!=count.end()) count[target]++;
    else count[target] = 1;
  }
  ld res = 0;
  for(auto itr = count.begin(); itr != count.end(); itr++){
    res -= itr->second  * (log(itr->second) - log(in.size()));
  }
  return res;
}

int main(){
  int n;
  while(cin >> n and n){
    vector<int> nums(n);
    REP(i, n) cin >> nums[i];
    ld tmp = INF;
    int rs, ra, rc;
    REP(i, 16) REP(j, 16) REP(k, 16){
      ld tres = calc(i, j, k, nums);
      if(tmp > tres){ rs = i; ra = j; rc = k; tmp = tres; }
    }
    cout << rs << " " << ra << " " << rc << endl;
  }
  return 0;
}

Measured memory_bytes: 3260
//
// Created by jazcarreta on 14.12.18.
//

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

long long LL;

int main()
{
    int n;
    cin >> n;
    if (n == 25) cout << "Christmas";
    else if (n == 24) cout << "Christmas Eve";
    else if (n == 23) cout << "Christmas Eve Eve";
    else if (n == 22) cout << "Christmas Eve Eve Eve";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int> >;

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

vector<int>A(N);
rep(i,N)cin>>A[i];
auto _A=A;
sort(_A.begin(),_A.end(),greater<int>());

rep(i,N){
    if(A[i]==_A[0]){
        cout<<_A[+1]<<endl;
    }
    else{
        cout<<_A[0]<<endl;
    }
}
//system("pause");
return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <ctime>
#include <climits>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <cstdlib>

using namespace std;
long int pow107 = (int)pow(10, 9) + 7;
int ilimit = INT_MAX;
long int llimit = LONG_MAX;

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

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//コンビネーションfactorial
//

int main(){
    int n ;
     cin >> n;
    int c = 0,j = 1;
    vector<int> v;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        v.push_back(a);
    }
    while(j != 2){
        
        if(c >= n){
            c = -1;
            break;
        }
        j = v[j-1];
        c++;
    }

    cout << c << endl;

}

Measured memory_bytes: 892
// #include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
 
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())
 
#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int check[35];

int solve(int c, int d, int limit, int weight) {
  int m = min(limit ,weight);
  int ans = 0;
  for(int i = 0; i <= 3000; ++i) {
    for(int j = 0; j <= 3000; ++j) {
      if(i*c + j*d <= m) {
        ans = max(ans, i*c + j*d);
      }
    }
  }
  // cout << "a" << ans << endl;
  return ans;
}

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

  int a, b, c, d, e, f;

  cin >> a >> b >> c >> d >> e >> f;

  for(int i = 0; i < 35; ++i) {
    check[i] = 0;
  }

  int temp;
  for(int i = 0; i <= 30; ++i) {
    for(int j = 0; j <= 30; ++j) {
      temp = i*a + j*b;
      if(temp <= 30) {
        check[temp] = 1;
      }
    }
  }

  int ans = 0;

  int limit;
  int weight;
  int water = 0;
  int sugar;
  int total;
  int cs = -1;
  int ct = -1;
  for(int i = 0; i <= 30; ++i) {
    if(check[i] == 1) {
      limit = e*i;
      weight = f - 100*i;
      // cout << "I" << i << endl;
      // cout << "L" << limit << endl;
      // cout << "W" << weight << endl;
      if(weight >= 0) {
        sugar = solve(c, d, limit, weight);
        total = sugar + 100*i;
        if(cs == -1 && ct == -1) {
          cs = sugar;
          ct = total;
          weight = i;
        } else
        if(cs == 0 && ct == 0) {
          cs = sugar;
          ct = total;
          weight = i;
        } else {
          if(sugar*ct > total*cs) {
            cs = sugar;
            ct = total;
            weight = i;
          }
        }
        // cout << sugar << " " << total << endl;
        // cout << cs << " " << ct << endl;
      }
    }
  }

  cout << ct << " " << cs << endl;

  return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
L=list(map(int,input().split()))
    
import math
MAX=10**9
MIN=0
for i in range(100):
    Mid=(MAX+MIN)/2
    cnt=0
    for j in range(N):
        cnt+=L[j]//Mid
    if cnt<=K:
        MAX=Mid
    else:
        MIN=Mid
    #print(cnt)
print(math.ceil(Mid))


Measured memory_bytes: 93780
def build_cost_table(n):
    ret = [-1] * (n ** 2)
    for r in range(n):
        dr = min(r, n - 1 - r)
        for c in range(n):
            dc = min(c, n - 1 - c)
            ret[r * n + c] = min(dr, dc)
    return ret


def main():
    from collections import deque

    N = int(input())
    *p, = (int(x) - 1 for x in input().split())

    H = build_cost_table(N)  # 離席コスト
    S = [1] * (N ** 2)  # 着席

    ans = 0
    for pi in p:
        hpi = H[pi]  # piの離席コスト
        ans += hpi  # piの離席コストを加算
        S[pi] = 0  # piを空席にする

        # BFSで離席コストを更新
        dq = deque()
        dq.append((pi, hpi))
        while dq:
            x, h = dq.popleft()
            r, c = divmod(x, N)

            nx = x - N
            if r != 0 and H[nx] > h:
                H[nx] = h
                dq.append((nx, h + S[nx]))

            nx = x + N
            if r != N - 1 and H[nx] > h:
                H[nx] = h
                dq.append((nx, h + S[nx]))

            nx = x - 1
            if c != 0 and H[nx] > h:
                H[nx] = h
                dq.append((nx, h + S[nx]))

            nx = x + 1
            if c != N - 1 and H[nx] > h:
                H[nx] = h
                dq.append((nx, h + S[nx]))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 135408
from heapq import heappush,heappop
from collections import deque
h,w=map(int,input().split())
sx,sy=map(int,input().split())
sx-=1
sy-=1
gx,gy=map(int,input().split())
gx-=1
gy-=1
g=[list(input()) for _ in range(h)]
v=[[0 for j in range(w)] for i in range(h)]
v2=[[0 for j in range(w)] for i in range(h)]
q=deque([])
q.append([0,sx,sy])
while q:
    c,x,y=q.popleft()
    if x==gx and y==gy:
        print(c)
        exit()
    if v[x][y]==1:
        continue
    v[x][y]=1
    for a in range(-2,3):
        for b in range(-2,3):
            if a==b==0:
                continue
            if a*b==0 and abs(a+b)==1:
                nx=x+a
                ny=y+b
                if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and v[nx][ny]==0:
                    q.appendleft([c,nx,ny])
                continue
            nx=x+a
            ny=y+b
            if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and v[nx][ny]==0 and v2[nx][ny]==0:
                q.append([c+1,nx,ny])
                v2[nx][ny]=1
print(-1)


Measured memory_bytes: 147132
n = int(input())
w = [input() for i in range(n)]
flag = 1
for i in range(n):
  for j in range(n):
    if i == j:
      continue
    if w[i] == w[j]:
      flag = flag *0
      break
for i in range(n):
  if i == 0:
    continue
  if w[i-1][-1] == w[i][0]:
    flag = flag * 1
  else:
    flag = flag * 0
    
if flag == 1:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3060
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    return gcd(b, a % b)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    tmp = A[0]
    gcdA = [0] * N
    gcdB = [0] * N
    gcdA[0] = A[0]
    gcdB[N-1] = A[N-1]
    for i in range(1, N):
        gcdA[i] = gcd(A[i], gcdA[i-1])
        gcdB[N-i-1] = gcd(A[N-i-1], gcdB[N-i])
    ans = max(gcdA[N-2], gcdB[1])
    for i in range(1, N-1):
        ans = max(ans, gcd(gcdA[i-1], gcdB[i+1]))
    print(ans)


if __name__ == "__main__":
    main()


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

int main()
{
  int K, T;

  cin >> K;
  cin >> T;
  vector<int> A(T);
  int temp;
  int temp_Index;
  for(int i=0; i < T; i++)
    cin >> A[i];
   
  int cont = 0;
  vector<int>::iterator maxIt;
  size_t max_Index;
  for(int t=K; t > 0; t--){
    maxIt = max_element(A.begin(), A.end());
    max_Index = distance(A.begin(), maxIt);
    if(A[max_Index] == 0){
      cont = temp;
      break;
    }
    A[max_Index]--;
    if(t != K ) A[temp_Index] = temp;
    temp = A[max_Index];
    temp_Index = max_Index;
    A[max_Index] = 0;
  }

  cout << temp << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  unordered_map<int, int> up;
  int num = 0;
  up[0]++;
  int x = 0, tot = 1;
  int mod = 2019;
  REP(i, S.size()) {
    x += (S[i] - '0') * tot;
    x %= mod;
    tot *= 10;
    tot %= mod;
    up[x]++;
  }
  int ans = 0;
  for (auto s : up) {
    ans += (s.second * (s.second - 1)) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define JOINT(A,B) int A##B
vector<int>dp(51,0LL),dp2(51,0LL);
signed main(){
    int n,x; cin >> n >> x;
    rep(i,51){
        if(i == 0){
            dp[0] = dp2[0] = 1LL;
        } else {
            dp[i] = dp[i-1] + dp[i-1] + 3;
            dp2[i] = dp2[i-1] + dp2[i-1] + 1;
        }
    }
    function<int(int,int)>cal = [&](int i,int x) -> int{
        if(x == 0)return 0LL;
        if(i == 0)return 1LL;
        if(dp[i-1] + 2 >= x){
            return cal(i-1,x-1) + (dp[i-1] + 2 == x);
        } else {
            return cal(i-1,x - dp[i-1] - 2) + dp2[i-1] + 1;
        }
    };
    cout << cal(n,x) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int m,f,r;
    while(1){
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1){break;}
        if(m==-1 || f==-1 || m+f<30){cout << "F" << endl;}
        else if(m+f>=80){cout << "A" << endl;}
        else if(m+f>=65){cout << "B" << endl;}
        else if(m+f>=50){cout << "C" << endl;}
        else if(m+f>=30 && r>=50){cout << "C" << endl;}
        else{cout << "D" << endl;}
    }
}


Measured memory_bytes: 3040
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int a =sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();
        if(s.equals(u)){
            System.out.println(a-1);
            System.out.println(b);
        }else {
            System.out.println(a);
            System.out.println(b-1);
        }
    }
}

Measured memory_bytes: 23764