akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//2000*2000で全探索か
int main(){
  ll H,W; cin>>H>>W;
  vector<vector<char>> G(H+2,vector<char>(W+2,'x'));
  vector<vector<ll>> C(H+2,vector<ll>(W+2,0)),L(H+2,vector<ll>(W+2,0));
  for(int j=1; j<=H; j++){
    for(int i=1; i<=W; i++){
      char S; cin>>S; G[j][i]=S;
    }
  }
  //Lのカウント
  for(int j=1; j<=H; j++){
    ll tmp=0;
    for(int i=1; i<=W+1; i++){
      if(G[j][i]=='.') tmp++;
      else{
        for(int k=0; k<tmp; k++)
          L[j][i-1-k]=tmp;
        tmp=0;
      }
    }
  }
  //Cのカウント
  for(int i=1; i<=W; i++){
    ll tmp=0;
    for(int j=1; j<=H+1; j++){
      if(G[j][i]=='.') tmp++;
      else{
        for(int k=0; k<tmp; k++)
          C[j-1-k][i]=tmp;
        tmp=0;
      }
    }
  }
  ll ans=0;
  for(int j=1; j<=H; j++){
    for(int i=1; i<=W; i++)
      ans=max(ans, L[j][i]+C[j][i]);
  }
  cout<<ans-1<<endl;
}


Measured memory_bytes: 67072
s = input()

l = int(s[:2])
r = int(s[2:])

if 0 < l and l <= 12:
    if 0 < r and r <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 0 < r and r <= 12:
        print('YYMM')
    else:
        print('NA')



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

#define int long long

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int d[]={1,-1,7,-7};

int N,M,Q;
bool f[700000*2];

int a[111111];

int calc(int m){
    memset(f,0,sizeof(f));
    for(int i=0;i<Q;i++){
        for(int j=a[i];j<m;j+=M)f[j]=true;
    }

    UnionFindTree uf(m);

    rep(i,m){
        rep(j,4){
            if(i%7==0&&d[j]==-1)continue;
            if(i%7==6&&d[j]==1)continue;
            int nx=i+d[j];
            if(nx<0||nx>=m)continue;
            if(f[i]||f[nx])continue;
            uf.unite(i,nx);
        }
    }
    int res=0;
    rep(i,m)if(!f[i]&&uf.find(i)==i)res++;
    return res;
}

signed main(){
    cin>>N>>M>>Q;
    int MM=M;
    if(M%7)MM*=7;
    rep(i,Q){
        cin>>a[i];
    }

    int x=calc(MM);
    int y=calc(2*MM);
    cout<<x+(y-x)*(N*7/MM-1)<<endl;
    return 0;
}


Measured memory_bytes: 23616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
struct edge{ll to,cost;};
const int inf = 1<<28;
const ll INF = 1LL<<53;
const int COMBMAX = 500005;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(v, e) for(const auto& e : v)
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance(v.begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance(v.begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n,ll mod=MOD){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v,a)-lower_index(v,a);} 
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
template<class T> void debug2(T v){rep(i,v.size()){rep(j,v[i].size())cout<<v[i][j]<<" ";cout<<endl;}}
template<class T> void rdv(T &v){rep(i,v.size())cin>>v[i];}
template<class T> void rdvv(T &v){rep(i,v.size()){rep(j,v[i].size())cin>>v[i][j];}}



int main(){
    ll MAX_V = 100005;
    ll N,W; cin >> N >> W;
    vl w(N),v(N);
    rep(i,N) cin >> w[i] >> v[i];
    vvl dp(N+1,vl(MAX_V+1,INF));
    dp[0][0] = 0;
    rep(i,N)rep(j,MAX_V){
        chmin(dp[i+1][j],dp[i][j]);
        if(0<=j-v[i]) chmin(dp[i+1][j],dp[i][j-v[i]] + w[i]);
    }
    ll ans = 0;
    rep(i,MAX_V)if(dp[N][i]<=W)chmax(ans,(ll)i);
    cout << ans << endl;
}

Measured memory_bytes: 80256
#include<iostream>
#define F 7500000
using namespace std;
int n,m,i;
int main(){
	while(cin>>m>>n&&m){
		bool t[F]={};
		while(1){
			if(!t[m]){
				if(!n)break;
				for(i=m*2;i<F;i+=m)t[i]=1;
				n--;
			}
			m++;
		}
		cout<<m<<endl;
	}
	return 0;
}

Measured memory_bytes: 10364
#include <stdio.h>
#include <math.h>

int main()
{
	double X,deposit = 100;
	int year = 0;

	scanf("%lf",&X);

	while(deposit < X){
		deposit = floor(deposit * 1.01);
		year++;
	}

	printf("%d\n",year);

	return 0;
}


Measured memory_bytes: 1748
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] bucket = new int[100];
    int max = 0;
    while (sc.hasNext()) {
      int num = sc.nextInt();
      bucket[num - 1]++;
      if (bucket[num - 1] > max) {
        max = bucket[num - 1];
      }
    }
    for (int i =0; i < 100; i++) {
      if (bucket[i] == max) {
        System.out.println(i + 1);
      }
    }
  }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
struct edge{
	int x,y;
	ll z;
} gs[400400];
int n,m;
ll ans;
ll best[200200];

int p[200200];
int par(int x){
	return (p[x]==x)?x:(p[x]=par(p[x]));
}

int main(){
	scanf("%d%d",&n,&m);
	memset(best,0x7f,sizeof best);
	for (int i=0;i<n;++i)
		p[i]=i;

	for (int i=0;i<m;++i){
		static int x,y;
		static ll z;
		scanf("%d%d%lld",&x,&y,&z);
		gs[i]=(edge){x,y,z};
		best[x]=min(best[x],z+1);
		best[y]=min(best[y],z+2);
	}

	for (int it=0;it<2;++it)
		for (int i=0;i<n;++i)
			best[(i+1)%n]=min(best[(i+1)%n],best[i]+2);

	for (int i=0;i<n;++i)
		gs[m+i]=(edge){i,(i+1)%n,best[i]};

	sort(gs,gs+m+n,[](const edge &a,const edge &b){return a.z<b.z;});
	for (int i=0;i<m+n;++i){
		int fa=par(gs[i].x);
		int fb=par(gs[i].y);
		if (fa!=fb){
			ans+=gs[i].z;
			p[fa]=fb;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 12032
# -*- coding: utf-8 -*-
# 整数の入力
A=input()
B=input()
ans=str()
if len(A)==len(B):
  for i in range (0,len(A)):
    ans+=A[i]+B[i]
else:
  for i in range (0,len(A)-1):
    ans+=A[i]+B[i]
  ans+=A[-1]
print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

int main() {
        int n; 
        cin >> n;
        vector<int> a(n);
        vector<int> b;
        for (int i = 0; i < n; i ++) {
                cin >> a[i];
                if (i % 2 == 0) b.push_back(a[i]);
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        long long ans = 0;
        for (int i = 0; i < b.size(); i ++) {
                int x = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
                if (x % 2 == 1) ans ++;
        } 
        cout << ans << endl;
        return 0;
}



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

string s;
int ans;

int main() {
  cin >> s;
  ans = 1000;
  if (s.size() <= 3) {
    ans = 753 - stoi(s);
  }else{
    rep (i, s.size() - 2) {
      ans = min(ans, abs(753 - stoi(s.substr(i, 3))));
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

double to_deg(double r){
  return 180.0 * r / (atan(1)*4.0);
}

int main(){
  double a,b,x;

  cin >> a >> b >> x;

  double ans;
  if(x <= a * a * b / 2.0){
    printf("%lf\n", 90 - to_deg(atan(2*x/(a*b*b))));
  }else{
    printf("%lf\n", to_deg(atan(2*(a*a*b-x)/(a*a*a))));;
  }

}



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

int main(){

  int a,b;
  cin>>a>>b;
  
  if ((a*b)%2==0){
    cout<<"No"<<endl;
  }
  
  else {
    cout<<"Yes"<<endl;
  }
  
  
  
  
  
  
}
  













Measured memory_bytes: 256
#l = list(map(int, input().split(' ')))

#num = int(input())
#S = str(input())
# k = (X - Ai - Bj) / C
# C = 0
#
A=int(input())
B=int(input())
C=int(input())
X=int(input())
sum = 0

for i in range(0,A+1):
    for j in range(0,B+1):
        for k in range(0,C+1):
            if(500*i+100*j+50*k==X):
                sum+=1

print(sum)

Measured memory_bytes: 3060
def check(x, y)
  2.times do |z|
    4.times do
      return true if x == y
      a, b, c, d, e, f  = x
      x = z.zero? ? [e, a, c, d, f, b] : [d, b, a, f, e, c]
      g = x
      4.times do
        i, j, k, l, m, n = g
        g = [i, k, m, j, l, n]
        return true if g == y
      end
    end
  end
  false
end
 
h = $<.map{|i| i.chomp.split}.drop(1)
h.size.times do |j|
  (j+1).upto(h.size - 1) do |k|
    (puts 'No')^exit if check(h[j], h[k])
  end
end
puts 'Yes'

Measured memory_bytes: 9980
use proconio::{input, marker::Usize1};

const M: u64 = 1000_000_007;

fn main() {
    input! {
        n: usize,
        xy: [(Usize1, Usize1); n - 1],
    }

    println!("{}", DP::new(n, &xy).calc(0, 0));
}

struct DP {
    dp: Vec<Option<(u64,u64)>>,
    t: Vec<Vec<usize>>,
}

impl DP {
    fn new(n: usize, xy: &Vec<(usize, usize)>) -> DP {
        let mut t = vec![vec![]; n];
        for &(x, y) in xy {
            t[x].push(y);
            t[y].push(x);
        }

        DP {
            dp: vec![None; n],
            t: t,
        }
    }

    fn calc(&mut self, i: usize, p: usize) -> u64 {
        let v = if let Some(v) = self.dp[i] {
            v
        } else {
            let mut v = (1, 1);
            for j in self.t[i].clone() {
                if j != p {
                    v.0 = v.0 * self.calc(j, i) % M;
                    v.1 = v.1 * self.dp[j].unwrap().0 % M;
                }
            }
            self.dp[i] = Some(v);
            v
        };
        (v.0 + v.1) % M
    }
}



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

int H,W;
ll d[MAX][MAX];
char p[MAX][MAX];

int dp(int h,int w){
    if(d[h][w]==-1){
        d[h][w]=(p[h+1][w]=='.')? dp(h+1,w):0;
        if(p[h][w+1]=='.')d[h][w]+=dp(h,w+1);
    }
    return d[h][w]%1000000007;
}
int main(){
    cin>>H>>W;
    
    rep(H)for(int j=0;j<W;j++)cin>>p[i][j];
    rep(H)p[i][W]='#';
    rep(W)p[H][i]='#';
    memset(d,-1,sizeof(d));
    d[H-1][W-1]=1;
    cout<<dp(0,0)<<endl;
    return 0;
}

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

using namespace std;

int main(){

    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(a>0 && b>0){
        c=c-b;
        if(c<=0)
            break;
        a=a-d;
        if(a<=0)
            break;
    }
    if(c<=0)
        cout<<"Yes\n";
    else
        cout<<"No\n";

    return 0;
}


Measured memory_bytes: 3640
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
 
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add_self(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int add(int a,int b){
	int c=a+b;
	if(c>=mod){
		c-=mod;
	}
	return c;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=2000005;
 
void solve(){
	int n;
	cin>>n;
	vi a(n);
	cin>>a;
	ll sum=accumulate(all(a),0ll);
	ll mdif=1e18,cur=0;
	for(int i=0;i<n;i++){
		cur+=a[i];
		mdif=min(mdif,abs(sum-2*cur));
	}
	cout<<mdif;
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 1024
// 無向グラフの作成

#include <iostream>
#include <algorithm>
using namespace std;
static const int N = 100; // 配列の最大次元

int main() {
	int M[N][N]; // 0オリジンの隣接配列
	int n, u, k, v;

	cin >> n;

	// 隣接配列を0で初期化
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) M[i][j] = 0;
	}


	// 無向グラフを作成する(u-v間に辺を張る、配列番号u-vに1を立てる)
	for (int i = 0; i < n; i++) {
		cin >> u >> k; // 頂点番号u, 出次数k
		u--;
		for (int j = 0; j < k; j++) {
			cin >> v; // 隣接ノード追加
			v--; // 0オリジンへ変換
			M[u][v] = 1; // uとvの間に辺を張る
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j) cout << " ";
			cout << M[i][j];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3104
#include<algorithm>
#include<iostream>
#include<cstdio>

using namespace std;
typedef pair<int,int> P;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
P position(char bet){
  if(bet == 'A')return P(0,0);
  else if(bet == 'B')return P(0,1);
  else if(bet == 'C')return P(0,2);
  else if(bet == 'D')return P(1,0);
  else if(bet == 'E')return P(1,1);
  else if(bet == 'F')return P(1,2);
  else if(bet == 'G')return P(2,0);
  else if(bet == 'H')return P(2,1);
  else if(bet == 'I')return P(2,2);
}

int main(){
  int n;
  char sc,tc,bc;
  P s,t,b;  

  while(cin >> n && n){
    double dp[3][3][n+1];
    for(int i=0;i<=n;i++){
      for(int j=0;j<3;j++){
	for(int k=0;k<3;k++){
	  dp[j][k][i] = 0;
	}
      }
    }
    cin >> sc >> tc >> bc;
    s = position(sc);
    t = position(tc);
    b = position(bc);
    dp[s.second][s.first][0] = 1;
    
    for(int k=0;k<n;k++){
      for(int i=0;i<3;i++){
	for(int j=0;j<3;j++){
	  if(dp[i][j][k] == 0 || (i == b.second && j == b.first))continue;
	  
	  for(int ii=0;ii<4;ii++){
	    int nx = j+dx[ii],ny = i+dy[ii];
	    if(0<=nx && nx <3  && 0<=ny && ny <3 && !(nx == b.first && ny == b.second)){
	      dp[ny][nx][k+1] += dp[i][j][k]*0.25;
	    }
	    else{
	      dp[i][j][k+1] += dp[i][j][k]*0.25;
	    }
	  }

	}
      }
    }

    printf("%.8f\n",dp[t.second][t.first][n]);

  }
  return 0;
}

Measured memory_bytes: 1188
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, maxi = -1, mini = 1000000000;
  cin >> n;
  REP(i,n) {
    int a;
    cin >> a;
    maxi = max(maxi,a);
    mini = min(mini,a);
  }
  cout << maxi - mini << endl;
  return 0;
}
//templete by private_yusuke

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

using namespace std;

#define PROBLEM "E"
#define TESTC ""

#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)
typedef pair<int, int> P;
#define F first
#define S second
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define LL long long

int main()
{
	#ifdef DBG
	freopen(PROBLEM TESTC ".in", "r", stdin);
	freopen(PROBLEM ".out", "w", stdout);
	#endif
	int n;
	int tmp;

	while(~scanf("%d",&n))
	{
		int arr[100005];
		int is_minus = 0;
		for (int i = 0; i < n; i++)
		{
			int tmp;
			scanf("%d",&tmp);
			if(tmp < 0)
				is_minus++;
			arr[i] = abs(tmp);
		}

		if(is_minus % 2 == 0)
		{
			LL ans = 0;
			for(int i = 0; i < n; i++)
				ans += abs(arr[i]);
			cout << ans << '\n';
		}
		else
		{
			LL ans2 = 0;
			int minn = INT_MAX;
			for(int i = 0; i < n; i++)
			{
				ans2 += arr[i];
				minn = min(minn, arr[i]);
			}
			ans2 -= minn * 2;
			cout << ans2 << '\n';
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static ArrayList<String> lisT = new ArrayList<String>();
	public static void main(String[] args) {

		String W = sc.nextLine();
		String[] T = inpStr();

		findingAword(W, T);
		sc.close();

	}

	private static void findingAword(String W, String[] T) {
		int wd = 0;

		for (int i = 0; i < T.length; i++) {
			if( T[i].equals(W) ) {
				wd++;
			}
		}

		System.out.println(wd);

	}



	private static String[] inpStr() {
		while (sc.hasNextLine()) {
			String t = " " + sc.nextLine() + " ";

			if (t.equals(" END_OF_TEXT ")) {
				break;
			} else {
				lisT.add(t);
			}

		}
		String str = lisT.toString();

		str = str.toLowerCase();


		String[] strs = str.split(" ");

		return strs;
	}

}


Measured memory_bytes: 26348
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h> 
#include <iostream>
#include <map>
#include <cmath>
#include<set>
#include <vector>
#include<bitset>
#include <string>
#include<queue>
#include <algorithm>
#include<set>
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define vl vector<long long >;
//#define rep(i,a,b) for(int i=a;i<b;++i)
//typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<int,int>ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef long long ll;
const int N=1e5+5;
int A[N];
ll dp[N]={0};
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

/*void show(vi v,int valeur){
    int count=0;
    
    rep(i,0,(int)v.size()){
        ++count;
        cout<<v[i]<<" " ;
        if(count==valeur){cout<<"\n";count=0;}
    }
}*/
 int main() {
        ios_base::sync_with_stdio(false); cin.tie(NULL);int n;
  //ll ans=0;
  cin>>n;
  rep(i,0,n){
      cin>>A[i];
  }
  dp[1]=abs(A[1]-A[0]);
  rep(i,2,n){
      dp[i]=min(abs(A[i]-A[i-2])+dp[i-2],abs(A[i]-A[i-1])+dp[i-1]);
  }
  cout<<dp[n-1];
   return 0;
 }



Measured memory_bytes: 4740
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

vector<vector<int> > mul(const vector<vector<int> > &a, const vector<vector<int> > &b){
  const int n = a.size();
  vector<vector<int> > ret(n, vector<int>(n, 0));

  REP(i,n) REP(j,n)
    if(a[i][j] == 1)
      REP(k,n)
	if(b[j][k])
	  ret[i][k] = 1;

  return ret;
}

vector<vector<int> > calc(const vector<vector<int> > &g, int z){
  if(z == 0){
    const int n = g.size();
    vector<vector<int> > ret(n, vector<int>(n, 0));
    REP(i,n) ret[i][i] = 1;
    return ret;
  }
  
  if(z % 2 == 1){
    return mul(g, calc(mul(g,g), z/2));
  }else{
    return calc(mul(g,g), z/2);
  }
}

int main(){
  while(true){
    int n = getInt();
    int m = getInt();
    int z = getInt();

    if(n + m + z == 0) break;

    vector<pair<int,int> > state(4*m);
    /* f => prevPos  s => nowPos */
    REP(i,m){
      state[4*i+1].s = state[4*i].f = getInt() - 1;
      state[4*i+1].f = state[4*i].s = getInt() - 1;

      state[4*i+2].s = state[4*i].f;
      state[4*i+2].f = n + state[4*i].s;

      state[4*i+3].s = state[4*i].s;
      state[4*i+3].f = n + state[4*i].f;
    }

    int mm = m + m + m + m;
    vector<vector<int> > g(mm, vector<int>(mm));

    REP(i,mm) REP(j,mm)
      if(state[j].f == state[i].s && state[j].s != state[i].f)
	g[i][j] = 1;

    //puts("g:");
    //REP(i,mm) { REP(j,mm) printf("%d ",g[i][j]); puts(""); }

    vector<vector<int> > ans = calc(g, z);

    //puts("ans:");
    //REP(i,mm) { REP(j,mm) printf("%d ",ans[i][j]); puts(""); }

    bool ok = false;
    REP(i,mm) REP(j,mm) if(ans[i][j] == 1){
      if(state[i].s == 0 && state[j].s == n - 1){
	ok = true;
	break;
      }
    }

    puts(ok ? "yes" : "no");
  }
  return 0;
}

Measured memory_bytes: 6296
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
//配列の添字ズレに注意
//=に注意
int main(){
  long n,d,x,y,ans=0; cin>>n>>d;
  d=d*d;
  
  rep(i,n){
    cin>>x>>y;
    if(d>=x*x+y*y)ans++;
  
  }
  
  //string s; cin>>s;
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;

const int MAX=1010;
char map[MAX][MAX];
int vis[MAX][MAX];
int  h,w,n;
int sx,sy;
int e[MAX][3];
int fx[]={1,-1,0,0};
int fy[]={0,0,1,-1};
struct node
{
    int x,y,step;
};
int bfs(int x,int y,int ex,int ey)
{
    memset(vis,0,sizeof(vis));
    vis[x][y]=1;
    node a;
    a.x=x,a.y=y,a.step=0;
    queue<node>Q;
    Q.push(a);
    while(!Q.empty())
    {
        node p=Q.front();
        Q.pop();
        if(p.x==ex&&p.y==ey)
        {
            sx=p.x,sy=p.y;
            return p.step;
        }
        for(int i=0;i<4;++i )
        {
            int tx=p.x+fx[i];
            int ty=p.y+fy[i];
            if(tx<1||tx>h||ty<1||ty>w||vis[tx][ty]||map[tx][ty]=='X')
                continue;
            vis[tx][ty]=1;
            node s;
            s.x=tx,s.y=ty,s.step=p.step+1;
            Q.push(s);
        }
    }

}
int main()
{
    while(scanf("%d%d%d",&h,&w,&n)!=EOF)
    {
        if(n==0&&w==0)
            break;
        for(int i=1;i<=h;++i)
        {
            scanf("%s",map[i]+1);
            for(int j=1;j<=w;++j)
            {
                if(map[i][j]=='S')
                {
                    sx=i,sy=j;
                }
                else if(map[i][j]!='X'&&map[i][j]!='.')
                {
                    e[map[i][j]-'0'][0]=i;
                    e[map[i][j]-'0'][1]=j;
                }
            }
        }
        int ans=0;
        for(int i=1;i<=n;++i)
        {
            ans+=bfs(sx,sy,e[i][0],e[i][1]);
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

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

  ll N; cin >> N;
  ll M; cin >> M;
  string S; cin >> S;

  vector<ll> ans;
  ll cnt = 0;
  ans.emplace_back(N);
  for (int i = 1; i <= N; i++) {
    for (int j = max(0ll, ans[i - 1] - M); j < ans[i - 1]; j++) {
      if (S[j] == '0') {
        ans.emplace_back(j);
        break;
      }
    }
    if (ans.size() == i) {
      cout << -1 << '\n';
      return 0;
    }
    if (ans[ans.size() - 1] == 0) {
      break;
    }
  }

  reverse(ans.begin(), ans.end());
  for (int i = 1; i < ans.size(); i++) {
    cout << (ans[i] - ans[i - 1]) << '\n';
  }
  return 0;
}

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

int main(){
    unordered_map<string, int> words;
    string ans;
    string s;

    cin >> ans;
    while(1){
        cin >> s;
        if(s=="END_OF_TEXT") break;
        transform(s.begin(), s.end(), s.begin(), ::tolower);
        if(words.count(s)==0){
            words[s] = 1;
        }else{
            words[s]++;
        }
    }

  	printf("%d\n", words[ans]);
    return 0;
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

pi AB[100000 + 10];

signed main(void) {
    int  N, M; cin >> N >> M;
    rep(i, N) {
        int A, B;
        cin >> A >> B;
        AB[i] = mp(A, B);
    }
    sort(AB, AB+N);
    int rest = M;
    int cost = 0;
    int i=0;
    while (1) {
        if (rest <= AB[i].se) { //この店で買い切れる
            cost += rest * AB[i].fi;
            break;
        } else {
            cost += AB[i].fi * AB[i].se;
            rest -= AB[i].se;
            i++;
        }
        // cout << "rest:" << rest << endl;
        // cout << "cost:" << cost << endl;
    }
    cout << cost << endl;
    
    return 0;
}

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

using namespace std;
#define pb push_back
#define mp make_pair
typedef long long int ll;


int main(){
    ios_base::sync_with_stdio(0);
    ll n,t;
    cin>>n>>t;
    ll res = 0;
    ll pre,cur;
    if(n==1){
        cout<<t;
        return 0;
    }
    cin>>pre;
    for(int i = 1;i<n;i++){
        cin>>cur;
        res+=min(cur-pre,t);
        pre = cur;
    }
    res+=t;
    cout<<res;
    
    return 0;
}


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

int main(){
   
   int k, S;
   cin >> k >> S;
   int cont = 0;
   
   //fijar valor de x
   for (int x = 0; x <= k; x++) {
   	
		//fijar valor de y
		for (int y = 0; y <= k; y++) {
			
			//ecuacion para obtener el valor de Z pada cada iteracion donde (x+y+z=S)
			int z = S - x - y;
			//validar que z este en el rango
			if (z >= 0 && z <= k) cont++;
		}
   	
   }
   cout << cont;
   
   return 0;
}


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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,a,b,c,dp[3][100001];

main() {
    cin >> n;
    rep1(i,n) {
        cin >> a >> b >> c;
        dp[0][i] = max(dp[1][i-1],dp[2][i-1])+a;
        dp[1][i] = max(dp[2][i-1],dp[0][i-1])+b;
        dp[2][i] = max(dp[0][i-1],dp[1][i-1])+c;
    }
    ct(max(max(dp[0][n],dp[1][n]),dp[2][n]))
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
			res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	#ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
	#endif

	int h, n;
	cin >> h >> n;
	int sum = 0;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		sum += x;
	}
	if(sum >= h) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>

#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)

using namespace std;

const ll sz=100005;
const ll szz=1000006;

int main()
{
    Ryuga;
    
   
    ll x;
    cin>>x;
    rep(i,-1000,1001)
    {
        rep(j,-1000,1001)
        {
            if((ll)pow(i,5)-pow(j,5)==x)
            {
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    
}//Goodbye...



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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0;i<N;i++){
        cin >> A[i];
    }
    vector<int> ans(N);
    for (int i=0;i<N;i++){
        ans[A[i]-1] = i+1;
    }
    for (int i=0;i<N;i++){
        if (i<N-1) cout << ans[i] << " ";
        else cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
using System;

class InsertionSort {
    static void PrintArr(int[] A, int N) {
        for (int i = 0; i < N; i++) {
            Console.Write(A[i]);
            if (i != N-1)
                Console.Write(" ");
            else
                Console.Write("\n");
        }
    }

    static void InSort(int[] A, int N) {
        for (int i = 1; i < N; i++) {
            PrintArr(A, N);

            int v = A[i];
            int j = i-1;

            while (j >= 0 && A[j] > v) {
                A[j+1] = A[j];
                j--;
            }
            A[j+1] = v;
        }
        PrintArr(A, N);
    }

    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        
        int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

        InSort(A, N);
    }
}

Measured memory_bytes: 9376
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        long ans = 0;
        for (int i = 1; i < n; i++) {
            if (a[i - 1] > a[i]) {
                ans += a[i - 1] - a[i];
                a[i] = a[i - 1];
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 60348
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int h,w,k;
    cin >> h >> w >> k;
    VS s(h);
    REP(i,0,h) cin >> s[i];
    int index = 0;
    VVI bo(h,VI(w));
    REP(i,0,h) {
        bool b = false;
        REP(j,0,w) if (s[i][j] == '#') {
            b = true;
            break;
        }
        if (b) {
            int j = 0;
            for (; j < w && s[i][j] != '#'; ++j) bo[i][j] = 0;
            for (; j < w; ++j) {
                if (s[i][j] == '#') ++index;
                bo[i][j] = index;
            }
            RREP(j,0,w-1) if (bo[i][j] == 0) bo[i][j] = bo[i][j+1];
        } else {
            if (i == 0) REP(j,0,w) bo[i][j] = 0;
            else REP(j,0,w) bo[i][j] = bo[i-1][j];
        }
    }
    REP(j,0,w) RREP(i,0,h-1) if (bo[i][j] == 0) bo[i][j] = bo[i+1][j];
    REP(i,0,h) {
        REP(j,0,w) {
            if (j) cout << " ";
            cout << bo[i][j];
        }
        cout << endl;
    }
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>
int cmp(const int *a,const int *b){
  return *b-*a;
}
int main(){
  int f=0,i,n,m,X,Y,x[100],y[100];
  scanf("%d%d%d%d",&n,&m,&X,&Y);
  for(i=0;i<n;i++)scanf("%d",&x[i]);
  for(i=0;i<m;i++)scanf("%d",&y[i]);
  qsort(x,n,sizeof(int),cmp);
  qsort(y,m,sizeof(int),cmp);
  for(i=Y;i>X;i--)if(x[0]<i&&i<=y[m-1])f=1;
  puts(f?"No War":"War");
  return 0;
}


Measured memory_bytes: 128
def main():
    n, a, b, c, d = map(int, input().split())
    s = input()

    if c < d:
        count = 0
        for i in range(a, d):
            if s[i] == '#':
                count += 1
                if count == 2:
                    print('No')
                    exit(0)
            else:
                count = 0
        print('Yes')
    else:
        count = 0
        for i in range(a, c):
            if s[i] == '#':
                count += 1
                if count == 2:
                    print('No')
                    exit(0)
            else:
                count = 0
        count = 0
        flag = 0
        for i in range(b - 2, d + 1):
            if s[i] == '.':
                count += 1
                if count == 3:
                    flag = 1
            else:
                count = 0
        print('Yes') if flag else print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout<<(x)<<endl
typedef long long ll;
template<class T> inline void chmax(T& a, T b) {
  if (a < b) a = b;
}

template<class T> inline void chmin(T& a, T b) {
  if (a > b) a = b;
}
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int X;
  cin >> X;
  if (X == 3 || X == 5 || X == 7) COUT("YES");
  else COUT("NO");
}

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

bool isAllEvil(vector<int> &A,int N){
    bool s=true;
    rep(i,N){
        if(A.at(i)%2==1){
            s=false;
            break;
        }
    }
    return s;
}

int main() {
    int N;
    cin >>N;
    vector<int> A(N);

    rep(i,N) cin >> A.at(i);
    //-----------------------------------
    int Ans=0;
    bool s=true;
    do{
        s=isAllEvil(A,N);
        if(s){
            rep(i,N) A.at(i)/=2;
            Ans++;
        }
    }while(s);

    cout << Ans <<endl;
}

Measured memory_bytes: 256
import heapq
import math


def main():
    N, M = list(map(int, input().split(' ')))
    neg_A = list(map(lambda x: - int(x), input().split(' ')))  # max to min
    heapq.heapify(neg_A)
    for _ in range(M):
        min_neg_a = heapq.heappop(neg_A)
        heapq.heappush(neg_A, min_neg_a / 2)
    answer = 0
    for _ in range(N):
        neg_a = heapq.heappop(neg_A)
        answer += math.floor(-neg_a)
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14536
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
int max(int cnt[],int k){
	int max = 0;
	for(int i=0;i <= k;i++)
      if(max < cnt[i]) max=cnt[i];
	return max;
}

int main() {
	ll N;
	cin >> N;
  	int cnt[200010]={0};
	ll P[200010],C[200010];
	for(int i=0;i < N;i++){
		cin >> P[i];
		C[P[i]-1]=i;
	}

  int k=0;
	for(int i=0;i < N-1;i++){
		if(C[i] < C[i+1]) cnt[k]++;
		else k++;
	}
	cout << N-max(cnt,k)-1 << endl;
	
	return 0;
}

Measured memory_bytes: 4096
N = int(input())

rN = int(N**(1/2))+1

ms = []
for m in range(1,rN+1):
	if N % m != 0:
		continue
	
	ms.append((m-1)+((N // m)-1))
	#print((m-1),((N // m)-1))
	
print(min(ms))

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

using namespace std;
using ll = long long;


int main()
{
    ll n, a[5];
    cin >> n;
    for(ll i = 0; i < 5; i++)cin >> a[i];
    ll nin = *min_element(a, a + 5);
    cout << ((n + nin - 1) / nin) + 4 << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    string s;
    cin >> s;
    int a=0,b=0;
    rep(i,s.size()){
        if(s[i]=='0') a++;
        else b++;
    }
    cout << min(a,b) * 2 << endl;
}

Measured memory_bytes: 512
#include <stdio.h> 
#include <algorithm> 
#include <iostream> 
#include <string.h> 
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;

stack<int> kuohao;

int main(){
    char a[55],b[55];
    int m ,n;
    scanf("%s\n%s",&a,&b);
    m = strlen(a);
    n = strlen(b);
    int flag1 = 0;
    //cout<<m<<n;
    for (int i = m - n;i>=0 ; i--){
        int flag = 0,flag2 = 0;
        for(int j = 0 ; j < n ; j++){
            //cout<<a[i+j]<<" "<<b[j];
            if (a[i+j] == b[j]||a[i+j] == '?') {continue;}
            flag = 1;
            break;
        }
        if (flag == 0)
            for(int j = 0 ; j < n ; j++){
                a[i+j] = b[j];flag2++;
            }
        if (flag2 != 0) {flag1 = 1 ;break;}
    }
    if (flag1 != 0){
    for(int i = 0 ; i < m ; i++){
        if (a[i] == '?') cout<<"a";
        else cout<<a[i];
    }cout<<endl;}
    else cout<<"UNRESTORABLE"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
#define int long long int
#define pb push_back
#define fi first
#define se second
#define deb cerr << "Line no." << __LINE__
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;
#ifndef LOCAL
#define endl '\n'
#endif

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
	uniform_int_distribution<int> uid(l, r);
	return uid(rng);
}
int pwr(int a,int b){
	int ans = 1;
	while(b){
		if(b & 1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ans;
}
const int N = 1e5 + 5;
const int NN = 1e7 + 5;
int a[N];
int fact[NN], ifact[NN];
int dp[105][N];
int ncr(int n,int k){
	if(n < k || k < 0) return 0;
	int ans = (fact[n] * ifact[k]) % mod;
	return (ans * ifact[n - k]) % mod;
}
void solve(){
	int n, k;
	cin >> n >> k;
	fr(i, 1, n){
		cin >> a[i];
	}
	fact[0] = 1;
	fr(i, 1, NN - 1){
		fact[i] = (fact[i - 1] * i) % mod;
	}
	ifact[NN - 1] = pwr(fact[NN - 1], mod - 2);
	for(int i = NN - 2; i >= 0; i--){
		ifact[i] = (ifact[i + 1] * (i + 1)) % mod;
	}
	dp[0][0] = 1;
	fr(i, 1, n){
		fr(j, 0, k){
			dp[i][j] += dp[i - 1][j];
			if(j >= a[i] + 1)
				dp[i][j]  -= dp[i - 1][j - a[i] - 1];
			dp[i][j] %= mod;
		}
	}
	int ans = 0;
	fr(i, 0, k){
		ans += (ncr(n + i - 1, n - 1) * dp[n][k - i]) % mod;
		ans %= mod;
	}
	ans = (ans + mod) % mod;
	cout << ans;
}
signed main(){
  	IO;
  	#ifdef LOCAL
		freopen("inp.txt","r", stdin);
		// freopen("out.txt", "w", stdout);
	#endif
 	clock_t clk = clock();
  	int t = 1;
  	// cin >> t;
  	fr(tt, 1, t){
    	solve();
  	}
  	cerr << endl << (double)(clock() - clk) / CLOCKS_PER_SEC;
  	return 0;
}

Measured memory_bytes: 235776
#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        cin>>b[i];
    }
    int x=0;
    bool bl=false;
    for(int i=0;i<n;i++){
        if(a[i]==b[i]){
            x++;
            if(x==3){
                bl=true;
                break;
            }
        }
        else{
            x=0;
        }
    }
    if(bl){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD (int64_t)1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector
#include <iomanip>



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

double N, K; cin >> N >> K;
vector<double> p(N); invec(p);

cout << fixed << setprecision(15);

double maxi = 0., sum = 0.;
vector<double> ex(N);
rep(i, 0, N){
    ex[i] = (p[i] + 1) / 2;
}
rep(i, 0, K) sum += ex[i];
rep(i, 0, N - K + 1){
    maxi = max(maxi, sum);
    sum += ex[i+K] - ex[i];
}

cout << maxi << "\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 3456
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int N, H, W;
	cin >> N >> H >> W;

	cout << (N - H + 1) * (N - W + 1) << endl;
}






Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main() {
    string s, t;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    string p;
    cin >> p;
    if (p == s)
        cout << a - 1 << " " << b << endl;
    else
        cout << a << " " << b - 1 << endl;
    return 0;
}

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

long long MOD = 1e9 + 7;

long long fast_pow(long long x, long long p){
    long long res = 1;
    while (p){
        if (p & 1){
            res *= x;
            res %= MOD;
        }

        p >>= 1;
        x *= x;
        x %= MOD;
    }

    return res;
}

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

    string s;
    cin >> s;
    
    long long ans = 0, len = s.length();
    vector<long long> fac(len + n + 1), inv(len + n + 1);
    fac[0] = fac[1] = 1;
    for (long long i = 2; i <= len + n; i++){
        fac[i] = (fac[i - 1] * i) % MOD;
    }

    inv[len + n] = fast_pow(fac[len + n], MOD - 2);
    for (long long i = len + n - 1; i >= 0; i--){
        inv[i] = (inv[i + 1] * (i + 1)) % MOD;
    }

    auto C = [&](long long a, long long b){
        long long res = 1;
        res = (((fac[a] * inv[b]) % MOD) * inv[a - b]) % MOD;
        return res;
    };

    for (long long i = 0; i <= n; i++){
        ans += (((fast_pow(25, n - i) * fast_pow(26, i)) % MOD) * C(len + n - i - 1, n - i)) % MOD;
        ans %= MOD;
    }

    cout << ans << '\n';

    return 0;
}


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

typedef long long int ll;

int main(){
	ll n, k;cin >> n >> k;
	ll m = k;
	int ans = 0;
	if(n < k)return cout << n, 0;
	while(k <= n){
		k *= m;
		ans++;
	}
	cout << ans + 1;
}


Measured memory_bytes: 256