akhauriyash/Code-Regression huggingface dataset:
N = int(input())
ha = [[0]*3 for _ in range(N+1)]
for i in range(N):
  a = list(map(int, input().split()))
  for k in range(3):
    ha[i+1][k] = a[k]

dp = [[0]*3 for _ in range(N+1)]
for i in range(1,N+1):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i][j] = max(dp[i][j], dp[i-1][k] + ha[i][j])
ans = 0
for i in range(3):
  ans = max(ans,dp[N][i])
print(ans)

Measured memory_bytes: 42500
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int main(){
    ll n,m;
    cin>>n>>m;
    if(n%3==0||m%3==0){
        cout<<0<<endl;
        return 0;
    }
    ll ans=999999999999999;
    ll s=m*n;
    ll s1,s2,s3;
    for(int i=1;i<n;i++){
        s1=i*m;
        s2=((n-i)/2)*m;
        s3=s-s1-s2;
        if(s2>0&&s3>0) ans=min(ans,max(s1,max(s2,s3))-min(s1,min(s2,s3)));
    }
    for(int i=1;i<n;i++){
        s1=i*m;
        s2=(m/2)*(n-i);
        s3=s-s1-s2;
        if(s2>0&&s3>0) ans=min(ans,max(s1,max(s2,s3))-min(s1,min(s2,s3)));
    }
    swap(n,m);
    for(int i=1;i<n;i++){
        s1=i*m;
        s2=((n-i)/2)*m;
        s3=s-s1-s2;
        if(s2>0&&s3>0) ans=min(ans,max(s1,max(s2,s3))-min(s1,min(s2,s3)));
    }
    for(int i=1;i<n;i++){
        s1=i*m;
        s2=(m/2)*(n-i);
        s3=s-s1-s2;
        if(s2>0&&s3>0) ans=min(ans,max(s1,max(s2,s3))-min(s1,min(s2,s3)));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
var lines = []; var result = 0;
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
})

rl.on('close', function () {
    var A = Number(lines[0].split(" ")[0]);
    var B = Number(lines[0].split(" ")[1]);

    console.log(0 + Math.max(A + B, A - B, A * B));
});

Measured memory_bytes: 7500
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 1000000007;
const int N = 100000 + 7;

int main()
{
    int k,n;
    scanf("%d%d",&k,&n);
    vector<int>arr(n);
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
    }
    vector<int>dist;
    for(int i=1;i<n;i++){
        dist.push_back(abs(arr[i]-arr[i-1]));
    }
    dist.push_back(k-arr[n-1]+arr[0]);
    sort(dist.begin(),dist.end());
    cout<<k-dist[dist.size()-1];
    return 0;
}



Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define int long long 
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

signed main(void){
    int n, L; cin >> n >> L;
    vi a(n); for(auto & e : a) cin >> e;

    int res = 0;
    int cur = 1;

    int pos = -1;
    rep(i, n - 1){
        if(a[i] + a[i + 1] >= L){
            pos = i;
            break;
        }
    }

    if(pos == -1){
        cout << "Impossible" << endl;
        return 0;
    }

    cout << "Possible" << endl;
    rep(i, pos){
        cout << i + 1 << endl;
    }
    rrep(i, n - 1, pos + 1){
        cout << i + 1 << endl;
    }
    cout << pos + 1 << endl;

    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<string>

int diffA(char a){
  return int('{' - a);
}

int main(){
  std::string str;
  int n;
  std::cin >> str;
  std::cin >> n;
  int size = str.size();
  for(int i=0;i<size;i++){
    if(str[i] == 'a'){
      continue;
    }
    int d = diffA(str[i]);
    if(d<=n){
      str[i] = 'a';
      n = n - d;
    }
  }
  if(n!=0){
    str[size-1] = 'a' + (n%26 + str[size-1] - 'a') % 26;
  }
  std::cout << str << std::endl;
}


Measured memory_bytes: 576
#include<stdio.h>
int main(void){
  int n,i;
  scanf("%d",&n);
  for(i=1;i<=9;i++){
  	if(n/i>=1&&n/i<=9&&n%i==0){
    	printf("Yes\n");
	return 0;
	}
  }
	printf("No\n");
  return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int left, right;
  left = A + B;
  right = C + D;
  
  if (left > right) {
    cout << "Left" << endl;
  }
  else if (left == right) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

using namespace std;

int main()
{
    int n, result, a[101];
    double average = 0, tmp = 100000;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        average += a[i];
    }
    average /= n;
    for(int i = 0; i < n; ++i) {
        if(tmp > abs((double)average - a[i])) {
            tmp = abs((double)average - a[i]);
            result = i; 
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

long long modpow(long long x,long long n,long long mod)
{
  if(n==0)return 1;
  long long res=modpow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll mod= 998244353;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  int sa=0;
  rep(i,n)sa+=a[i];
  int l=sa/2;
  vector<ll>dp(l+1,0LL);
  dp[0]=1;
  rep(i,n)
  {
    for(int j=l-a[i];j>=0;j--)
    {
      if(dp[j]==0)continue;
      dp[j+a[i]]+=dp[j]*2;
    }
    if(((-i&i)&8)||i==n-1)rep(j,l+1)dp[j]%=mod;
  }
  rep(i,l+1)if(dp[i]<0)dp[i]+=mod;
  ll res=modpow(3,n,mod);
  rep(i,l+1)dp[i]=dp[i]*3;
  for(auto i:dp)res+=3*mod-i;
  res%=mod;
  if(!(sa&1))
  {
    fill(all(dp),0LL);
    dp[0]=1;
    rep(i,n)
    {
      for(int j=l-a[i];j>=0;j--)
      {
        if(dp[j]==0)continue;
        dp[j+a[i]]+=dp[j];
      }
      if(((-i&i)&16)||i==n-1)rep(j,l+1)dp[j]%=mod;
    }
    res+=dp.back()*3;
  }
  cout<<res%mod<<endl;


  return 0;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   vector<int> h(n);
   f(i,0,n){
      cin >> h[i];
   }
   int cur = 0, ans = 0;
   for(int i=n-2;i>=0;i--){
      if(h[i+1] <= h[i]){
         cur++;
      }else{
         cur = 0;
      }
      ans = max(ans,cur);
   }
   cout << ans << '\n';
   return 0;
}

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

int main(){
  string r, a;
  while(1){
    cin >> r >> a;
    if(r[0] - '0' == 0 && a[0] - '0' == 0) break;
    int hit = 0, blow = 0;
    for(int i = 0; i < 4; i++){
      for(int j = 0; j < 4; j++){
	if(r[i] == a[j]){
	  if(i == j) hit++;
	  else blow++;
	}
      }
    }
    cout << hit << " " << blow << endl;
  }
}

Measured memory_bytes: 1180
L, R = map(int,input().split())
ans = 2019
if R-L >= 2019:
    ans = 0
else:
    ans = 2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            mod_ij = (i*j)%2019
            #print(mod_ij)
            if mod_ij < ans:
                ans = mod_ij

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(),(x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

signed main(){
    int n;
    scanf("%d",&n);
    int a[214];
    REP(i,n*2) scanf("%d",&a[i]);
    sort(a,a+2*n);
    int ans = 0;
    REP(i,n) ans += a[i*2];
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

enum Type{
	not_visited,
	visited,
};

struct Info{
	Info(int arg_node_id,ll arg_sum_dist,ll arg_v,Type arg_type){
		node_id = arg_node_id;
		sum_dist = arg_sum_dist;
		v = arg_v;
		type = arg_type;
	}
	bool operator<(const struct Info &arg) const{
		return sum_dist > arg.sum_dist;
	};
	int node_id;
	ll sum_dist,v;
	Type type;
};

struct Data{
	Data(int arg_to,ll arg_time){
		to = arg_to;
		time = arg_time;
	}
	int to;
	ll time;
};

int N,M;
ll A,B,C;
ll min_dist[2][500][50];

ll calc_V(ll pre_v){
	return (A*pre_v+B)%C;
}

int main(){

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

	vector<Data> V[N];

	int from,to;
	ll time;

	for(int loop = 0; loop < M; loop++){
		scanf("%d %d %lld",&from,&to,&time);
		from--;
		to--;
		V[from].push_back(Data(to,time));
		V[to].push_back(Data(from,time));
	}

	ll first_v;
	scanf("%lld",&first_v);
	scanf("%lld %lld %lld",&A,&B,&C);

	for(int a = 0; a < 2; a++){
		for(int b = 0; b < N; b++){
			for(int c = 0; c < 50; c++)min_dist[a][b][c] = 999999999999999;
		}
	}

	priority_queue<Info> Q;
	min_dist[not_visited][0][first_v] = 0;
	Q.push(Info(0,0,first_v,not_visited));

	ll ans = 999999999999999;
	int next_node;
	ll next_v;

	while(!Q.empty()){

		if(Q.top().node_id == 0 && Q.top().type == visited){
			ans = min(ans,Q.top().sum_dist);
			Q.pop();
		}else if(Q.top().sum_dist > min_dist[Q.top().type][Q.top().node_id][Q.top().v] || Q.top().sum_dist >= ans){
			Q.pop();
		}else{
			next_v = calc_V(Q.top().v);

			for(int i = 0; i < V[Q.top().node_id].size(); i++){
				next_node = V[Q.top().node_id][i].to;

				if(next_node != N-1){
					if(min_dist[Q.top().type][next_node][next_v] > Q.top().sum_dist+Q.top().v*V[Q.top().node_id][i].time){
						min_dist[Q.top().type][next_node][next_v] = Q.top().sum_dist+Q.top().v*V[Q.top().node_id][i].time;
						Q.push(Info(next_node,min_dist[Q.top().type][next_node][next_v],next_v,Q.top().type));
					}
				}else{ //next_node == N-1
					if(min_dist[visited][next_node][next_v] > Q.top().sum_dist+Q.top().v*V[Q.top().node_id][i].time){
						min_dist[visited][next_node][next_v] = Q.top().sum_dist+Q.top().v*V[Q.top().node_id][i].time;
						Q.push(Info(next_node,min_dist[visited][next_node][next_v],next_v,visited));
					}
				}
			}
			Q.pop();
		}
	}

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

	return 0;
}

Measured memory_bytes: 11576
n = int(input())

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

dat_map = []
for i in range(n):
    dat_map.append([0] * 100)

for i in range(n):
    for j in range(dat_h[i]):
        dat_map[i][j] = 1

res = 0
for i in range(100):
    cur = 0
    for j in range(n):
        if cur == 0:
            if dat_map[j][i] == 1:
                res += 1
        cur = dat_map[j][i]

print(res)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
   
	 private static boolean isPrint = false;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] inStr = br.readLine().split(" ");
        int candleCount = Integer.parseInt(inStr[0]);
        int burning = Integer.parseInt(inStr[1]);
        showMessage("蜡烛总数:"+candleCount+",点燃总数:"+burning);
        int[] arr = new int[candleCount];
        inStr = br.readLine().split(" ");
        for (int i = 0; i < candleCount; i++) {
            arr[i] = Integer.parseInt(inStr[i]);
        }

        int min = Integer.MAX_VALUE;
        int left, right, temp=0;
        for (int i = 0; i < candleCount - burning + 1; i++) {
            left = arr[i];
            right = arr[i + burning - 1];
            //右边在负轴
            if(right<0) {
            	temp = Math.abs(left);
            	min = Math.min(min, temp);
            	continue;
            }
            //左边在正轴
            if(left >= 0) {
            	temp = Math.abs(right);
            	min = Math.min(min, temp);
            	continue;
            }
            if(right>=0&&left<0) {
            	temp = Math.min(Math.abs(left) * 2 + right, Math.abs(left) + right * 2); 
            	min = Math.min(min, temp);
            }
        }
        System.out.println(min);
    }
    public static void showMessage(Object message) {
		if(isPrint) {
			System.out.println(message);
		}
	}
}

Measured memory_bytes: 38420
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// constexpr inline ll mod = 1'000'000'007;
// constexpr int max_n = 200'000 + 5;

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    char a,b,c;
    cin >> a >> b >> c;
    if (a == '7' || b == '7' || c == '7') {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll mod_pow(ll a,ll b){
    a%=mod;
    if(b==0)return 1;
    if(b==1)return a;
    ll res=mod_pow(a,b/2)%mod;
    res*=res; res%=mod;
    if(b%2)res*=a;
    return res%mod;
}

struct perm{
private:
    int sz;
    vector<ll> p,invp;
public:
    perm(int n){
        sz=n+1;
        p.resize(sz),invp.resize(sz);
        p[0]=1;
        for(int i=1;i<=sz-1;i++){
            p[i]=p[i-1]*i%mod;
        }
        invp[sz-1]=mod_pow(p[sz-1],mod-2);
        for(int i=sz-2;i>=0;i--){
            invp[i]=invp[i+1]*(i+1)%mod;
        }
    }
    ll comb(ll x,ll y){
        if(x<y||y<0)return 0;
        return (p[x]*invp[x-y]%mod)*invp[y]%mod;
    }
};
perm p(1<<20);

ll dp[200200];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    dp[0]=1;
    for(int i=1;i<n;i++){
        dp[i]=p.comb(n,i)*p.comb(n-i-1+i,i)%mod;
    }
    ll ans=0;
    for(int i=0;i<=min(n-1,k);i++){
        (ans+=dp[i])%=mod;
    }
    cout << ans << endl;
}

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

#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

bool check(vector<ll> ghosts, ll i, ll a, ll b) {
    ll minus = b * i;
    ll diff = a - b;

    for (int j = 0; j < ghosts.size(); j++) {
        ghosts[j] -= minus;
    }

    ll count = 0;

    for (ll k : ghosts) {
        if (k <= 0) continue;
        count += ((k + diff - 1) / diff);
    }
    return count <= i;

}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    vector<ll> originals(n);


    rep(i, n) {
        cin >> originals[i];
    }

    if(check(originals, 1 , a, b)) {
        cout << 1 << endl;
        return 0;
    }

    ll floor = [&] {
        ll sum = accumulate(originals.begin(), originals.end(), 0ll);

        ll zako = b * (n - 1);
        ll tsuyo = a;
        ll ikkai = zako + tsuyo;

        return max(sum / ikkai - 1, 1ll);
    }();
    ll ceil = [&] {
        ll sum = accumulate(originals.begin(), originals.end(), 0ll);
        return sum / b + 1;
    }();

    while (floor + 1 < ceil) {
        ll mid = (floor + ceil) / 2;
        if (check(originals, mid, a, b)) {
            ceil = mid;
        } else {
            floor = mid;
        }
    }

    cout << ceil << endl;

}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stack>
#include<queue>
#include<string.h>
#include<algorithm>
#include<math.h>
#define MOD 1000000007
#include<stdlib.h>
using namespace std;
int main()
{
	char a[100005];
	scanf("%s",a);
	int len;
	len=strlen(a);
	char k;
	k=a[0];
	int sum=0;
	for(int i=1;i<len;i++)
	{
		if(k==a[i])
		continue;
		else
		{
			sum++;
			k=a[i];
		}
	}
	printf("%d\n",sum);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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 <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int main(){
    int N, M=INF;
    cin>>N;
    vector<int> X(N);
    rep(i,N)cin>>X[i];
    rep(i,101){
        int sum=0;
        rep(j,N){
            sum+=(X[j]-i)*(X[j]-i);
        }
        M=min(M,sum);
    }

    cout<<M<<endl;

    return 0;
}

//a=97,z=122

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

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

ll N,M,K;
ll ans = -1;

cin >> N >> M >> K;

vector<ll> A(N);
vector<ll> B(M);

for(ll i = 0;i < N;++i) cin >> A[i];
for(ll j = 0;j < M;++j) cin >> B[j];

vector<ll> sumA(N+1,0);
vector<ll> sumB(M+1,0);

for(ll i = 0;i < N;++i) sumA[i+1] = sumA[i] + A[i];
for(ll i = 0;i < M;++i) sumB[i+1] = sumB[i] + B[i];

for(ll i = 0;i <= N;++i){

  ll t = K - sumA[i];

  if(t < 0) break;

    ll left = 0;
    ll right = M+1;
    ll mid = 0;

    while(right - left > 1){

      mid = (left + right)/2;

      if(sumB[mid] <= t) left = mid;
      else right = mid;

    }

    ll res = i + left;

    ans = max(ans,res);

  }


cout << ans << endl;

return 0;

}   


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

void solve1()
{
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;
    S[K - 1] = tolower(S[K - 1]);
    cout << S << endl;
}

void solve2()
{
    string S;
    cin >> S;

    bool YYMM, MMYY;
    if ((S[0] == '1' && S[1] == '0' || S[1] == '1' || S[1] == '2') || (S[0] == '0' && S[1]  != '0') )
    {
        MMYY = true;
    }
    else
    {
        MMYY = false;
    }
    if ((S[2] == '1' && S[3] == '0' || S[3] == '3' || S[3] == '2') || (S[2] == '0' && S[3]  != '0'))
    {
        YYMM = true;
    }
    else
    {
        YYMM = false;
    }

    string ans;
    if (YYMM && MMYY)
    {
        ans = "AMBIGUOUS";
    }
    else if (!YYMM && !MMYY)
    {
        ans = "NA";
    }
    else if (YYMM)
    {
        ans = "YYMM";
    }
    else
    {
        ans = "MMYY";
    }
    cout << ans << endl;
}

int main()
{
    //   solve1();
    solve2();
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            ReadLine();
#endif
        }

        void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int a = cin.ReadInt;
            int b = cin.ReadInt;

            var ans = Min(a * n, b);

            Console.WriteLine(ans);
        }
    }

    class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;

        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 10000;
  for (int i = 0; i < s.size() - 2; i++) {
    string tmp = s.substr(i, 3);
    int x = abs(753 - stoi(tmp));
    ans = min(ans, x);
  }
  cout << ans << endl;
}

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

int main()
{
	int n,a[3][110],dp[3][110]={0};
	cin >> n;
	for (int i=1;i<=2;++i) {
		for (int j=1;j<=n;++j) {
			cin >> a[i][j];
		}
	}
	dp[1][1] = a[1][1];
	dp[2][1] = a[1][1] + a[2][1];
	for (int i=1;i<=2;++i) {
		for (int j=2;j<=n;++j) {
			dp[i][j] = max(dp[i-1][j],dp[i][j-1]) + a[i][j];
		}
	}
	cout << dp[2][n] << endl;
	return 0;
}

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

typedef unsigned long long uLL;
typedef long long int LL;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;
typedef pair <long long,long long> pll;
typedef pair <long long,pll> plll;
const int N = 1e5 + 5;
const int inf = 1e9;
const long long INF = 1e18;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int MOD = 1000000007;

int r , c;
LL dp[ 1001 ][ 1001 ];
string s[ 1005 ];

LL solve( int x , int y ) {
        if( x == r - 1 && y == c - 1 ) return 1;
        if( x >= r || y >= c ) return 0;
        if( s[x][y] == '#' ) return 0;
        if( dp[x][y] != -1 ) return dp[x][y];
        LL ret = 0;
        ret += solve( x + 1 , y );
        ret %= MOD;
        ret += solve( x , y + 1 );
        ret %= MOD;
        return dp[x][y] = ret;
}
int main( int argc , char const *argv[] ) {
        ios_base::sync_with_stdio( false ); cin.tie( NULL );
        cin >> r >> c;
        for( int i = 0; i < r; i++ ) cin >> s[i];
        memset( dp , -1 , sizeof( dp ) );
        cout << solve( 0 , 0 ) << endl;
        return 0;
}













Measured memory_bytes: 9216
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,a,p=1;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		if(a==p)
		{
			p++;
		}
	}
	if(p==1)
	{
		cout<<-1<<endl;
	}
	else
	{
		cout<<n-p+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]

def dfs(s):
    stack = [s]
    visited = [False]*N
    while stack:
        v = stack.pop()
        if visited[v]:
            continue
        visited[v] = True
        for u in graph[v]:
            if not visited[u]:
                point[u] += point[v]
                stack.append(u)

N, Q = list(map(int,input().split()))
graph = [deque([]) for _ in range(N)]
point = [0]*N

for i in range(N-1):
    a,b = list(map(int,input().split()))
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

for i in range(Q):
    p,x = list(map(int,input().split()))
    p -= 1
    point[p] += x

dfs(0)
print(*point)


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

#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int, int> P;
typedef vector<int> vi;

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

int N;
vi a;

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

  cin>>N;
  a.pb(0);
  rep(i,0,N) {
    int A; cin>>A;
    a.pb(A);
  }

  vi ans(N+1,0);
  for(int i=N;2*i>N;i--) {
    ans[i]=a[i];
  }
  for(int i=N/2;i>0;i--) {
    ans[i]=a[i];
    for(int j=2;j*i<=N;j++) {
      ans[i]^=ans[j*i];
    }
  }
  int ctn=0;
  vi ans1;
  rep(i,1,N+1) {
    if(ans[i]==1){
      ctn++;
      ans1.pb(i);
    }
  }
  cout<<ctn<<endl;
  rep(i,0,ans1.size()) {
    cout<<ans1[i]<<' ';
  }
  return 0;
}




Measured memory_bytes: 6000
#include <iostream>
#include <algorithm>
 
#define MAX 500
 
using namespace std;

int main(void){
    while(1){
        int kami[MAX][MAX]={0};
		int w, h, t, p;
		cin >> w >> h >> t >> p;
        if(!w && !h && !t && !p) break;
        for(int i=0; i<h; i++){
			fill(kami[i], kami[i]+w, 1);
        }
 
        int origin_x = 0, origin_y =0;
        for(int k=0; k<t; k++){
			int d, c;
			cin >> d >> c;
			
			int dist = 1;
            if(d == 1){
				for(int j=origin_x+c; j<origin_x+(2*c); j++){
                     for(int i=origin_y; i<MAX; i++){
                        kami[i][j] += kami[i][j-dist];
	                }
		            dist += 2;
			    }
                origin_x += c;
            } else{
                for(int i=origin_y+c; i<origin_y+(2*c); i++){
                    for(int j=origin_x; j<MAX; j++){
                        if(i-dist >= 0)kami[i][j] += kami[i-dist][j];
                    }
                    dist += 2;
                }
                origin_y += c;
            }
        }
         
        for(int k=0; k<p; k++){
			int x, y;
			cin >> x >> y;
			cout << kami[origin_y+y][origin_x+x] << endl;
        }
    }
 
    return 0;
}


Measured memory_bytes: 4064
import itertools

n, d = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]

cnt = 0
for v in itertools.combinations(X, 2):
    y = 0
    for i in range(d):
        y += (v[0][i] - v[1][i]) ** 2
    if(y ** 0.5).is_integer():
        cnt += 1

print(cnt)

Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 110
using namespace std;
int n, m, m1, sum, s, a[N], b[N];
int main(){
	scanf("%d%d", &n, &m);
	for(int i=1; i<=m; i++)scanf("%d", &a[i]);
	sum=0; for(int i=1; i<=m; i++)if(a[i]&1)sum++;
	if(sum>=3){printf("Impossible"); return 0;}
	for(int i=2; i<=m; i++)if(a[i]&1){
		if(a[1]&1)swap(a[i], a[m]); else swap(a[i], a[1]);
	}
	for(int i=1; i<=m; i++)b[i]=a[i];
	if(m==1){m1=2; b[1]--; b[2]=1;}
	else{m1=m; b[1]--; b[m1]++;}
	s=0; for(int i=1; i<=m1; i++)if(b[i])b[++s]=b[i];
	for(int i=1; i<=m-1; i++)printf("%d ", a[i]); printf("%d\n", a[m]);
	printf("%d\n", s);
	for(int i=1; i<=s-1; i++)printf("%d ", b[i]); printf("%d\n", b[s]);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    cin >>N;
    vector<int> a(N,0);

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

    sort(a.begin(),a.end());

    cout<<a[N-1]-a[0]<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}


void solve()
{
    int n;
    cin>>n;
    int ans=0;
    int m = 1e9;
    for(int i=0;i<n;i++) {
        int a;
        cin>>a;
        if(a<=m) {
            m=a;
            ans++;
        }
    }
    cout<<ans;
}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    long long N,M;
    cin>>N>>M;
    long long ans;
    if(N>=M/2){
        //Sが余るか丁度
        ans=M/2;
    }else{
        //cが余る
        ans=N;
        //まずSの分全部処理
        M=M-2*N;
        //残ったMが4個あるごとに1個増やせる
        ans=ans+M/4;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf("%.12lf\n",mid);
// __builtin_popcount(int) count 1's in binary
// get decimal pert of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = "And I feel fine...";
    istringstream iss(sentence);
*/  

double eps = .000000001;

int main ()
{
  prep();
  int n;
  cin >> n;
  vector<string> v;
  map<string, int> mp;
  long long pairs = 0;
  for (int i=0; i<n; i++){
      string s;
      cin >> s;
      sort(s.begin(), s.end());
      auto thing = mp.find(s);
      if (thing == mp.end()){
          mp[s] = 1;
      }else{
          pairs += thing->second;
          mp[s] = thing->second+1;
      }
  }
  cout << pairs;
  return 0; 
}

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

using namespace std;
const int mod = 1e9 + 7;
const long long INF = 1e18;
#define PI 3.141592653589793
#define REP(i, n) for(long long i = 0;i < n;i++)
int main()
{
  long long N;
  int A,B;
  long long  sum=0;
  long long  ans=0;
  string S;
  bool flag=false;
  cin>>N;
  int count=0;
  for(int i=0;i<N;i++){
    cin>>A;
    cin>>B;
    if(A==B){
      count++;
    }else{
      count=0;
    }
    if(count==3)flag=true;
  }
  if(flag)cout<<"Yes";
  else cout<<"No";
  return 0;
}




Measured memory_bytes: 3620
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, vector<vector<T>> &v)
{
	for (vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, vector<T> &v)
{
	for (T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

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

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

long long p (long long x, long long y)
{
	static const int mod = 1000000007;
	if (y == 0) return 1;
	long long z = p (x, y / 2);
	z *= z;
	z %= mod;
	return (y & 1 ? (z * x) % mod : z);
}

long long inv (long long x)
{
	static const int mod = 1000000007;
	return p (x, mod - 2);
}

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	ll n, k;
	cin >> n >> k;
	vl ans(k+1);
	rep(i,1,k+1)
		ans[i] = p(k / i, n);
	per(i,k,0)
	{
		for(int j = 2 * i; j < k + 1; j += i)
			ans[i] = (ans[i] - ans[j] + h) % h;
	}
	// cerr << ans;
	ll f_ans = 0;
	rep(i,1,k+1)
		f_ans += ans[i] * i, f_ans %= h;
	cout << f_ans;
}


Measured memory_bytes: 3988
import itertools
N,Q = [int(i) for i in input().split()]
S = list(input())

li = [0]*N
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        li[i+1] = 1
ans = list(itertools.accumulate(li))
k = []
for j in range(Q):
    a,b = [int(i) for i in input().split()]
    k.append(ans[b-1]-ans[a-1])

[print(i) for i in k]


Measured memory_bytes: 70136
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    ll N;
    cin >> N;
    ll n = sqrt(N);

    ll ans = N-1;
    for (int i = 1; i <= n; ++i) {
        ll r = N % i;
        if (r != 0) continue;
        else {
            ll q = N / i;
            ans = min(ans, (i-1)+(q-1));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
s_readline = sys.stdin.readline


def solve():

    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))

    #N, K = 2 * (10**5), 10000000
    #A = [0] * N

    for k in range(K):

        B = [0] * N
        for i in range(N):
            l = max(0, i - A[i])
            B[l] += 1
            r = i + A[i] + 1
            if r <= N - 1:
                B[r] += -1

        s = B[0]
        for i in range(N - 1):
            B[i + 1] += B[i]
            s += B[i + 1]

        A = B

        if s == N * N:
            print(' '.join(map(str, A)))
            exit()

    print(' '.join(map(str, A)))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 139056
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1e18;

signed main(){
    int n;
    cin>>n;
    V<string> s(n);
    cinf(n,s);
    map<string,int> mp;
    set<string> st;
    rep(i,n) mp[s[i]]++;
    int cnt=0;
    rep(i,n) chmax(cnt,mp[s[i]]);
    rep(i,n){
        if(mp[s[i]]==cnt) st.insert(s[i]);
    }
    while(!st.empty()){
        string t=*begin(st);
        st.erase(t);
        cout<<t<<endl;
    }
}

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

typedef long long ll;
ll N, K;
vector<int> A;
vector<bool> Ab;


int main(){
    cin >> N >> K;
    A = vector<int>(N);
    Ab = vector<bool>(N, false);
    for(int i = 0; i < N; i++){
        cin >> A[i];
        A[i]--;
    }
    vector<int> firstloop;
    for(int i = 0;;){
        if(Ab[i]) {
            firstloop.push_back(i);
            break;
        }
        firstloop.push_back(i);
        Ab[i] = true;
        i = A[i];
    }

   auto firsta =  find(firstloop.begin(), firstloop.end(), firstloop[firstloop.size()-1]);
   int first = distance(firstloop.begin(), firsta);
   vector<ll> loop(firstloop.size() - (first + 1));
   copy(firstloop.begin() + (first + 1), firstloop.end(), loop.begin());
   vector<ll> beforeloop(first + 1);
   copy(firstloop.begin(), firstloop.begin() + (first + 1), beforeloop.begin());

   if((ll)beforeloop.size() - 1 >= K){
       cout << beforeloop[K] + 1 << endl;
   }
   else{
       K -= (ll)beforeloop.size();
       K %= (ll)loop.size();
       cout << loop[K] + 1 << endl;
   }

}

Measured memory_bytes: 6312
n = int(input())
a = [int(input()) for _ in range(n)]
m1 = 0
m2 = 0
mp = 0
for i in range(n):
    if (m1 < a[i]):
        m2 = m1
        m1 = a[i]
        mp = i
    elif (m2 < a[i]):
        m2 = a[i]
#print(m1,m2,mp)
for i in range(n):
    if (mp == i):
        print(m2)
    else:
        print(m1)

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N - 1);
	rep(i, N - 1) cin >> A.at(i);
	vector<int> ans(N, 0);

	sort(A.begin(), A.end());
	rep(i, N - 1) ans.at(A.at(i) - 1)++;

	rep(i, N) cout << ans.at(i) << endl;

	return 0;
}

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

typedef long long LL;

int n;
LL ans, a[100050], x;

int work() {
    scanf("%d%lld", &n, &x);
    for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
    ans = max(a[0]-x, 0LL);
    a[0] -= ans;
    for (int i = 1; i < n; ++i) ans += max(a[i]+a[i-1]-x, 0LL), a[i] = min(x-a[i-1], a[i]);
    printf("%lld\n", ans);
    return 0;
}

int main() {
    work();
    //while (~scanf("%d", &n)) work();
    //scanf("%d", &T); while (T--) work();

    return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    int a, b;
    int r[N + 1] = {0};
    rep(i, M) {
        cin >> a >> b;
        r[a]++;
        r[b]++;
    }
    for (int i = 1; i < N + 1; i++) {
        cout << r[i] << endl;
    }
    
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

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

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

    ll a;
    cin >> a;

    cout << a+a*a+a*a*a<<endl; 



    return 0;

}



Measured memory_bytes: 3608
#include<stdio.h>
int main(void)
{
    int j,N,len[3],a[3],b[3],i;
    scanf("%d",&N);
    for(j=0;j<N;j++){
    scanf("%d%d%d",&len[0],&len[1],&len[2]);

        for(i=0;i<3;i++){
            a[i]=len[i]*len[i];
        }
    b[0]=a[0]+a[1];
    b[1]=a[0]+a[2];
    b[2]=a[1]+a[2];

        if(b[0]==a[2]||b[1]==a[1]||b[2]==a[0]){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    return 0;

}

Measured memory_bytes: 580
#include<stdio.h>
int main()
{
int a,b,m,i,minf,minr,ans;
  minf=10*10*10*10*10;
  minr=10*10*10*10*10;
  scanf("%d %d %d",&a,&b,&m);
  
int frz[a],range[b],x[m],y[m],c[m];
  
  for(i=0;i<a;++i)
  {
   scanf("%d",&frz[i]);
   if(minf>frz[i])  minf=frz[i];
  }
  
  for(i=0;i<b;++i)
  {
   scanf("%d",&range[i]);
   if(minr>range[i])  minr=range[i];
  }
  
ans=minf+minr;
  
  for(i=0;i<m;++i)
  {
  scanf("%d %d %d",&x[i],&y[i],&c[i]);
  if(frz[x[i]-1] + range[y[i]-1] -c[i] < ans) ans=frz[x[i]-1] + range[y[i]-1] -c[i];
  }

printf("%d",ans);
return 0;
}


Measured memory_bytes: 2176