akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define VI(v,n) vector<int> v(n)



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

	if (a > 0) {
		cout << "Positive" << endl;;
	}
	else if (a == 0) {
		cout << "Zero" << endl;
	}
	else if (b >= 0) {
		cout << "Zero" << endl;
	}
	else {
		if ((b - a) % 2 == 0) {
			cout << "Negative" << endl;
		}
		else {
			cout << "Positive" << endl;
		}
	}
	

	
	return 0;
}



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

using namespace std;

#define int long long

int INF = 1e9 + 7;

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

//n^(INF-2)
int invMod(int n)
{
    return myPow(n, INF - 2);
}

vector<int> frac((int)1e6);

void set_frac()
{
    frac[0] = 1;
    for (int i = 1; i < frac.size(); i++)
    {
        frac[i] = frac[i - 1] * i % INF;
    }
}

// nCm = n!/m!/(n-m)!
int comb(int n, int m)
{
    int res = frac[n];
    res = res * invMod(frac[m]) % INF;
    res = res * invMod(frac[n - m]) % INF;
    return res;
}

signed main()
{
    int N, M, K;
    cin >> N >> M >> K;

    int sum_cost = 0;

    for (int i = 1; i < M; i++)
    {
        for (int j = 1; j < N; j++)
        {
            //diag
            sum_cost += (i + j) * (M - i) * (N - j) * 2;
            sum_cost %= INF;
        }
    }

    for (int i = 1; i < N; i++)
    {
        sum_cost += i * M * (N - i);
        sum_cost %= INF;
    }

    for (int i = 1; i < M; i++)
    {
        sum_cost += i * N * (M - i);
        sum_cost %= INF;
    }

    set_frac();
    cout << sum_cost * comb(N * M - 2, K - 2) % INF << endl;
}

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

/*
首先,箱子里没球的不可能存在 
其次红球具有传递性,当且经当当前箱子里没有求,才不算红球 
*/

int n,m,num[100005],x,y,sum=0;
bool red[100005];
int main(){
	
	cin>>n>>m;
	for(int i=1;i<=n;i++)num[i]=1,red[i]=false;
	red[1]=true;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		num[x]--;
		num[y]++;
		if(red[x]==true){//可能存在红球 
		if(num[x]==0)red[x]=false;
		red[y]=true;//y可能会有 
		}
	}
	for(int i=1;i<=n;i++)if(red[i]==true)sum++;
	cout<<sum<<endl;
}

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

using namespace std;
typedef long long ll;

vector<int> g[200005];
ll val[2000005];

void dfs(int p,int c,ll sum){
    val[c] += sum;
    for (auto i:g[c]){
        if(i!=p){
            dfs(c,i,val[c]);
        }
    }
}

int main(void){
    int n,q;
    cin >> n>>q;
    for (int i=0;i<n-1;i++){
        int a,b;
        cin >> a>>b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for(int i=0;i<q;i++){
        int p,x;
        cin>>p>>x;
        p--;
        val[p]+=x;
    }
    dfs(-1,0,0);

    for(int i=0;i<n;i++){
        cout<<val[i]<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 25600
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include <fstream>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 200005;
ll T,n,m;
int main() {
	cin>>n>>m;
	ll sum = 0;
	if(n==1) sum+=300000;
	else if(n==2) sum+=200000;
	else if(n==3) sum+=100000; 
	if(m==1) sum+=300000;
	else if(m==2) sum+=200000;
	else if(m==3) sum+=100000;
	if(n==1&&m==1)
		sum+=400000;
	cout<<sum<<endl;
    return 0;
}



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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

vector<int> work;
int N, M, Q;
int A[50],B[50],C[50],D[50];

int ans = 0;
void solve(int depth){
    if(depth == N){
        int res = 0;
        rep(i, Q){
            int a = A[i]-1, b = B[i]-1;
            if(work[b]-work[a] == C[i]) res += D[i];
        }
        ans = max(ans, res);
    }
    else if(depth == 0){
        for(int i = 1; i <= M; i++){
            work.push_back(i);
            solve(depth+1);
            work.pop_back();
        }
    }
    else{
        for(int i = work.back(); i <= M; i++){
            work.push_back(i);
            solve(depth+1);
            work.pop_back();
        }
    }
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> M >> Q;
    rep(i, Q) cin >> A[i] >> B[i] >> C[i] >> D[i];
    solve(0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
import java.util.*;
public class Main {
    public static void main(String args []) {
        Scanner sc = new Scanner(System.in);
        int x= sc.nextInt();
        int y = sc.nextInt();
        List<Integer> a = Arrays.asList(1,3,5,7,8,10,12);
        List<Integer> b = Arrays.asList(4,6,9,11);
        if(a.contains(x)&&a.contains(y)) System.out.println("Yes");
        else if(b.contains(x)&&b.contains((y))) System.out.println("Yes");
        else if(x==2&&y==2) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  string s;
  while(cin>>s){
    vector<int> t;
    REP(i,9){
      char a=s[i]-'0';
      char b=s[i+1]-'0';
      int tmp=(a+b)%10;
      t.PB(tmp);
    }
    REP(j,9){
      vector<int> u;
      REP(i,t.size()-1){
        u.PB((t[i]+t[i+1])%10);
      }
      t=u;
    }
    cout<<t[0]<<endl;
  }
  return 0;
}




Measured memory_bytes: 3108
n = int(input())
cnt = [[0]*9 for _ in range(9)]
for i in range(1,n+1):
    s = str(i)
    if s[-1]!="0":
        cnt[int(s[0])-1][int(s[-1])-1] += 1
ans = 0
for i in range(9):
    for j in range(9):
        ans += cnt[i][j]*cnt[j][i]
print(ans)

Measured memory_bytes: 9200
n=int(input())
s=[]
for _ in range(n):
  s0=list(input())
  s0.sort()
  s.append(''.join(s0))
s.sort()
ans=0
p=s[0]
pc=1
for i in range(1,n):
  if p==s[i]:
    pc+=1
  else:
    ans+=pc*(pc-1)//2
    pc=1
    p=s[i]
ans+=pc*(pc-1)//2
print(ans)


Measured memory_bytes: 10612
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    String op = sc.next();
    int b = sc.nextInt();
    String plus = "+";
    String minus = "-";
    if(op.equals(plus)){
      System.out.println(a+b);
    }
    else if(op.equals(minus)){
      System.out.println(a-b);
    }
  }
}


Measured memory_bytes: 22868
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll n=in();
    cout<<(n+999)/1000*1000-n<<endl;
}


Measured memory_bytes: 3628
code_a = Hash[
*%w(
'   000000
,   000011
-   10010001
.   010001
?   000001
A   100101
B   10011010
C   0101
D   0001
E   110
F   01001
G   10011011
H   010000
I   0111
J   10011000
K   0110
L   00100
M   10011001
N   10011110
O   00101
P   111
Q   10011111
R   1000
S   00110
T   00111
U   10011100
V   10011101
W   000010
X   10010010
Y   10010011
Z   10010000
) +
[' ', '101']
]

code_a = code_a.invert
 
code_b = Hash[*%w(
11011   .
11100   ,
11101   -
11110   '
11111   ?
)] 
(?A..?Z).each{|c|
	code_b["%05b" % (c.ord - ?A.ord)] = c
}
code_b['11010'] = " "

code_b = code_b.invert

while gets
	ans = []
	s = $_
		.chomp
		.each_char
		.map{|c| code_b[c]}
		.join
	loop do
		i = 0
		i += 1 until i >= s.size || x = code_a[s[0..i]]
		break if i >= s.size
		ans << x
		s = s[i+1..-1]
	end
	puts ans.join
end

Measured memory_bytes: 8716
#include<iostream>
using namespace std;
int main(){
  const int MAX = 1e5;
  for(int n,m;cin>>n>>m,n;){
    int cost[m][m];
    int time[m][m];
    for(int i=0;i<m;i++){
      for(int j=0;j<m;j++){
	cost[i][j] = MAX;
	time[i][j] = MAX;
      }
    }
    int a,b,c,t;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c>>t;
      cost[a-1][b-1] = c;
      cost[b-1][a-1] = c;
      time[a-1][b-1] = t;
      time[b-1][a-1] = t;
    }
    for(int k=0;k<m;k++){
      for(int i=0;i<m;i++){
	for(int j=0;j<m;j++){
	  if(cost[i][j]>cost[i][k]+cost[k][j])
	    cost[i][j] = cost[i][k]+cost[k][j];
	  if(time[i][j]>time[i][k]+time[k][j])
	    time[i][j] = time[i][k]+time[k][j];
	}
      }
    }
    int l,r;
    cin>>l;
    for(int i=0;i<l;i++){
      cin>>a>>b>>r;
      if(r)
	cout<<time[a-1][b-1]<<endl;
      else
	cout<<cost[a-1][b-1]<<endl;      
    }
  }
  return 0;
}

Measured memory_bytes: 944
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cstring>

using namespace std;
int n,m;
long long int a[101];


int main(){
  cin >> n >> m;
  if(n+m==15)cout << "+" << endl;
  else if(n*m==15) cout << "*" << endl;
  else cout << "x" << endl;
 
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  int num = pow(2,N);
  map<int,int,greater<int>> slime; 
  rep(i,num) { int tmp; cin >> tmp; slime[tmp]++; }

  int now[num]; now[0] = (*slime.begin()).first;
  if (slime[now[0]]==1) slime.erase(now[0]);
  else slime[now[0]]--;
  int p = 1;
  rep(i,N) {
    rep(j,pow(2,i)) {
      auto pos = slime.upper_bound(now[j]);
      if (pos==slime.end()) { 
        cout <<  "No" << endl;
        return 0;
      }
      now[p+j] = (*pos).first;
      if ((*pos).second==1) slime.erase((*pos).first);
      else (*pos).second--;
    }
    p += pow(2,i);
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 13568
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<queue>
#include<functional>
#include<numeric>

using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k, x, y;
	cin >> n >> k;
	vector<pair<long long, long long>> xy(n);
	for (auto& e : xy) {
		cin >> x >> y;
		e=make_pair(x, y);
	}
	sort(xy.begin(), xy.end());
	long long ans = LLONG_MAX;

	for (int i = 0; i < n - k + 1; i++) {
		for (int j = i + k - 1; j < n; j++) {
			vector<long long> vec;
			for (int ii = i; ii <= j; ii++) {
				vec.push_back(xy[ii].second);
			}
			sort(vec.begin(), vec.end());
			for (int ii = 0; ii <= j - i - k + 1; ii++) {
				ans = min(ans, (vec[ii + k-1] - vec[ii])*(xy[j].first-xy[i].first));
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = sorted((int(x) for x in input().split()))
 
parent = [A[-1]]
rest = A[:-1]
bl = True
for _ in range(N):
    next_parent = []
    next_rest = []
    for p in parent[::-1]:
        while rest:
            x = rest.pop()
            if x < p:
                next_parent.append(x)
                break
            else:
                next_rest.append(x)
                continue
    parent += next_parent
    parent.sort()
    rest = rest + next_rest[::-1]
 
bl = len(parent) == (2**N)
answer = 'Yes' if bl else 'No'
print(answer)
 

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    string s,t;cin >>s>>t;
    s+=s;
    ll n=s.size();
    vector<vector<ll>>list(28,vector<ll>());
    for (int i = 0; i < n; ++i) {
        list[s[i]-'a'].push_back(i);
    }
    ll m=t.size();
    ll key=-1;
    ll ans=1;
//    for (int i = 0; i < 26; ++i) {
//        cout <<(char)('a'+i)<<" ";
//        for(auto u:list[i]){
//            cout <<u<<" ";
//        }
//        cout <<endl;
//    }
    for (int j = 0; j < m; ++j) {
        if(list[t[j]-'a'].empty()){
            cout <<-1<<endl;
            return 0;
        }
        ll k=upper_bound(all(list[t[j]-'a']),key)-list[t[j]-'a'].begin();
        k=list[t[j]-'a'][k];
//        cout <<k<<" "<<key <<endl;
        if(key<0)key=0;
        ans+=k-key;
        key=k;
        if(key>=n/2)key-=n/2;
    }
    cout <<ans <<endl;
    return 0;
}



Measured memory_bytes: 2804
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#define M_PI 3.14159265358979323846
using namespace std;
int main() {
  long double a, b, h, m;
  cin >> a >> b >> h >> m;
  //Each clock number is 30 degrees
  long double min = 60*h + m;
  long double hour = m/60+h;
  long double angleH = (90-hour*30) * M_PI/180;
  long double angleM = (90-6*min) * M_PI/180;
  long double distance = sqrt(pow(a*sin(angleH)-b*sin(angleM),2) + pow(a*cos(angleH)-b*cos(angleM),2));
  cout << fixed << setprecision(20) << distance;
}

Measured memory_bytes: 3536
n, k = map(int, input().split())
total = n * (n - 1) // 2
ans = total - k
if ans < n - 1: print(-1)
else:
    print(ans)
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if ans == 0: exit()
            ans += -1
            print(i, j)

Measured memory_bytes: 42736
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define mk make_pair
#define endl '\n'

int main()
{
    IOS;
        int n;
        cin>>n;
        int temp=n%10;
        if(temp==2 || temp==4|| temp==5 || temp==7 || temp==9)
        {
            cout<<"hon";
        }
        else if(temp==3)
        {
            cout<<"bon";
        }
        else
        {
            cout<<"pon";
        }
        

}

Measured memory_bytes: 3640
#include <stdio.h>
#include <math.h>
int main()
{
	int n;
	double x;
	scanf("%i",&n);
	x=n/1.08;
	int z=ceil(x);
	double n1=z*1.08;
	int y=floor(n1);
	if(y==n)
	{
		printf("%i",z);
	}
	else printf(":(");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int x; cin >> x;
    string ans = "NO";
    if (x == 7 || x == 5 || x == 3) ans = "YES";
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 7;
typedef long long ll;
int n, num[maxn];
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j += i) {
            num[j]++;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = ans + (ll)i * num[i];
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 42852
#include <bitset>
#include <cstdio>
#include <utility>
#include <vector>

const int N = 100000;

int n, count[16], sum[1 << 16], dp[1 << 16];
std::vector<std::pair<int, int>> tree[N];

int dfs(int p, int u)
{
    int result = 0;
    for (auto it : tree[u]) {
        if (it.first == p) {
            continue;
        }
        result ^= it.second;
        count[it.second ^ dfs(u, it.first)] ++;
    }
    return result;
}

int main()
{
    for (int msk = 1, i = 0; msk < 1 << 16; ++ msk) {
        if (~msk >> i & 1) {
            i ++;
        }
        sum[msk] = sum[msk ^ (1 << i)] ^ i;
    }
    for (int msk = 1; msk < 1 << 16; ++ msk) {
        dp[msk] = 16;
        for (int sub = msk; sub > 0; sub = sub - 1 & msk) {
            dp[msk] = std::min(dp[msk], dp[msk ^ sub] + __builtin_popcount(sub) - !sum[sub]);
        }
    }
    scanf("%d", &n);
    for (int i = 0, x, y, z; i < n - 1; ++ i) {
        scanf("%d%d%d", &x, &y, &z);
        tree[x].emplace_back(y, z);
        tree[y].emplace_back(x, z);
    }
    dfs(-1, 0);
    int result = 0;
    int msk = 0;
    for (int i = 1; i < 16; ++ i) {
        result += count[i] >> 1;
        msk |= (count[i] & 1) << i;
    }
    printf("%d\n", result + dp[msk]);
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define inf 1e18
#define inp(arr,n) for(int i=0;i<n;i++) cin>>arr[i]
#define fr(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int T=1;
    while (T--) {
        int n;
        cin>>n;
        int arr[n];
        inp(arr,n);
        int left[n],right[n];
        left[0]=0;
        fr(i,1,n-1)  left[i]=left[i-1]^arr[i-1];
        right[n-1]=0;
        for(int i=n-2;i>=0;i--) right[i]=right[i+1]^arr[i+1];
        fr(i,0,n-1) cout<<(left[i]^right[i])<<" ";
        cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 5852
s = str(input())
if s[0]==s[1] and s[2]==s[3] and s[0]!=s[2]:
    print("Yes")
elif s[0]==s[2] and s[1]==s[3] and s[0]!=s[1]:
    print("Yes")
elif s[0]==s[3] and s[1]==s[2] and s[0]!=s[1]:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 38384
#include <iostream>

 

using namespace std;

 

int main()
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if(x-r>=0 && y-r>= 0 && x+r<=w && y+r<=h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
        
}


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

template <typename T, T (*op)(T, T), T id>
struct SegmentTree {
    int size;
    vector<T> node;

    SegmentTree(int n) {
        size = 1;
        while (size < n) size <<= 1;
        node.resize(2 * size, id);
    }

    T operator[](int k) {
        return node[k + size];
    }

    void build(const vector<T>& v) {
        for (int k = 0; k < v.size(); k++) node[k + size] = v[k];
        for (int k = size - 1; k > 0; k--) node[k] = op(node[2 * k], node[2 * k + 1]);
    }

    void update(int k, T x) {
        k += size;
        node[k] = x;
        while (k >>= 1) {
            node[k] = op(node[2 * k], node[2 * k + 1]);
        }
    }

    T query(int l, int r) {
        T L = id, R = id;
        for (l += size, r += size; l < r; l >>= 1, r >>= 1) {
            if (l & 1) L = op(L, node[l++]);
            if (r & 1) R = op(node[--r], R);
        }
        return op(L, R);
    }
};

int op(int a, int b) {
    return max(a, b);
}

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

    int N, Q;
    cin >> N >> Q;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    SegmentTree<int, op, 0> st(N);
    st.build(A);
    for (int i = 0; i < Q; i++) {
        int T;
        cin >> T;
        if (T == 1) {
            int X, V;
            cin >> X >> V;
            st.update(X - 1, V);
        } else if (T == 2) {
            int L, R;
            cin >> L >> R;
            cout << st.query(L - 1, R) << "\n";
        } else {
            int X, V;
            cin >> X >> V;
            int lb = X - 1, ub = N + 1;
            while (ub - lb > 1) {
                int m = (lb + ub) / 2;
                if (st.query(X - 1, m) >= V) ub = m;
                else lb = m;
            }
            cout << ub << "\n";
        }
    }
}

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

const ll INF = 1LL * 1e18;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(begin(a), end(a));
    ll ok = -INF;
    ll ng = INF + 1;
    auto f = [&a, &n, &k](ll x) {
        ll count = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] < 0) {
                ll ok = n;
                ll ng = -1;
                while (abs(ok - ng) > 1) {
                    ll m = (ok + ng) / 2;
                    (a[m] * a[i] < x ? ok : ng) = m;
                }
                count += n - ok;
            } else {
                ll ok = -1;
                ll ng = n;
                while (abs(ok - ng) > 1) {
                    ll m = (ok + ng) / 2;
                    (a[m] * a[i] < x ? ok : ng) = m;
                }
                count += ok + 1;
            }
            if (a[i] * a[i] < x) count--;
        }
        count /= 2;
        return count < k;
    };
    while (abs(ok - ng) > 1) {
        ll m = (ok + ng) / 2;
        (f(m) ? ok : ng) = m;
    }
    cout << ok << endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;

namespace contest_Csharp
{
    class Program
    {
        static long power(long a, long b, long modulo)
        {
            long result = 1;
            long buff = a;
            for (long i = 1; i <= b; i *= 2)
            {
                result = result * ((b / i % (2) == 1) ? buff : 1) % modulo;
                buff = (buff * buff) % modulo;
            }
            return result % modulo;
        }
        static void Main(string[] args)
        {
            var vals = Console.ReadLine().Split(' ');
               // .Select(x => int.Parse(x)).ToList();
            var ans = (vals[0] == "ABC") ? "ARC" : "ABC";
            Console.WriteLine(ans);
        }



    }


}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;
int n, d;

int main() {
  cin >> n >> d;
  int x[n + 1][d + 1];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < d; ++j) cin >> x[i][j];

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int subtot = 0;
      for (int k = 0; k < d; ++k) {
        subtot += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      double subtotsq = sqrt(subtot);
      
      if (floor(subtotsq) == subtotsq) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
class SegmentTree:
    """Segment Tree (Point Update & Range Query)

    Query
        1. update(i, val): update i-th value to val
        2. query(low, high): find f(value) in [low, high)

    Complexity
        time complexity: O(log n)
        space complexity: O(n)
    """

    def __init__(self, N, f, default):
        self.N = 1 << (N-1).bit_length()
        self.default = default
        self.f = f
        self.segtree = [self.default] * ((self.N << 1) - 1)

    @classmethod
    def create_from_array(cls, arr, f, default):
        N = len(arr)
        self = cls(N, f, default)
        for i in range(N):
            self.segtree[self.N - 1 + i] = arr[i]

        for i in reversed(range(self.N - 1)):
            self.segtree[i] = self.f(
                self.segtree[(i << 1) + 1], self.segtree[(i << 1) + 2])
        return self

    def update(self, i, val):
        i += self.N - 1
        self.segtree[i] = val
        while i > 0:
            i = (i - 1) >> 1
            self.segtree[i] = self.f(
                self.segtree[(i << 1)+1], self.segtree[(i << 1)+2])

    def query(self, low, high):
        # query [l, r)
        low, high = low + self.N, high + self.N
        ret = self.default
        while low < high:
            if low & 1:
                ret = self.f(ret, self.segtree[low-1])
                low += 1
            if high & 1:
                high -= 1
                ret = self.f(ret, self.segtree[high-1])
            low, high = low >> 1, high >> 1
        return ret


def yosupo():
    # https://judge.yosupo.jp/problem/staticrmq
    _, Q = map(int, input().split())
    A = [int(x) for x in input().split()]
    rmq = SegmentTree.create_from_array(A, min, 10**9)
    for _ in range(Q):
        l, r = map(int, input().split())
        print(rmq.query(l, r))


def aoj():
    # https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_A
    N, Q = map(int, input().split())
    default = (1 << 31) - 1
    rmq = SegmentTree(N, min, default)
    for _ in range(Q):
        com, x, y = map(int, input().split())
        if com == 0:
            rmq.update(x, y)
        else:
            print(rmq.query(x, y+1))


if __name__ == '__main__':
    # yosupo()
    aoj()



Measured memory_bytes: 8708
n = int(input())
A = list(map(int, input().split()))

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

ans = 0
L = [0]*(n)
R = [0]*(n+1)
for i in range(n-1):
    L[i+1] = gcd(L[i], A[i])
    R[i+1] = gcd(R[i], A[-i-1])
for l, r in zip(L[::-1],R):
    ans = max(ans, gcd(l, r))
print(ans)

Measured memory_bytes: 14584
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int A;
  int B;
  cin >> A >> B;
  int a[3];
  a[0]=A+B;
  a[1]=A-B;
  a[2]=A*B;
  sort(a,a+3);
  cout << a[2] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c;
    cin >> a >> b >> c;
    if(a + b + 1 < c) cout << a + b * 2 + 1 << endl;
    else cout << b + c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e5 + 5, M = 1e9 + 5;
ll h[N], dp[N];
int main()
{
	ll n, k;
	cin >> n >> k;
	for(ll i = 1; i <= n; i++)
	{
		cin >> h[i];
		dp[i] = M;
	}

	dp[n] = 0;

	for(ll i = n - 1; i; i--)
		for(ll j = 1; j <= min(k, n - i); j++)
			dp[i] = min(dp[i], dp[i + j] + abs(h[i] - h[i + j]));
	
	cout << dp[1];
}

Measured memory_bytes: 1792
import sys
from collections import deque
from functools import lru_cache
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    if N == 1:
        print(0)
        return

    res = pow(10, N, mod)
    res -= 2 * pow(9, N, mod)
    res %= mod
    res += pow(8, N, mod)
    res %= mod
    print(res)


if __name__ == "__main__":
    main()



Measured memory_bytes: 68036
n = int(input())
w = list(map(int,input().split()))
min_n = 1000 
for m in range(n):
    sum_min = 0
    sum_max = 0
    sum_n = 0
    for i in range(m):
        sum_min += w[i]
    for j in range(m,n):
        sum_max += w[j]
    sum_n = abs(sum_max - sum_min)
    if min_n > sum_n:
        min_n = sum_n
print(min_n)

Measured memory_bytes: 9172
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;

  if (n == k) {
    cout << 0 << endl;
    return 0;
  }

  long long current = n;

  if (n > k) {
    current = n % k;
  } else {
    current = n;
  }


  int counter = 0;
  while (counter < 2) {
    long long tmp = abs(current - k);
    if (tmp <= current) {
      counter++;
    }
    current = tmp;
  }

  cout << current << endl;
}

Measured memory_bytes: 3168
#include<stdio.h>

int main(){
  char str[5];
  char ans[4][16]={"AMBIGUOUS\n","YYMM\n","MMYY\n","NA\n"};
  int i = 0;
  scanf("%s",str);
  if(str[0] > '1'||(str[0]=='1'&&str[1]>'2')||(str[0] == '0'&&str[1]=='0')){i++;}
  if(str[2] > '1'||(str[2]=='1'&&str[3]>'2')||(str[2] == '0'&&str[3]=='0')){i+=2;}
  printf(ans[i]);
  return 0;
}

Measured memory_bytes: 128
import math

a, b, x = list(map(int, input().split()))
if a**2*b == x:
    theta = 90
elif a**2*b/2 > x:
    h = 2*x/a/b
    theta = math.degrees(math.atan(h/b))
else:
    h = 2*x/(a**2)-b
    theta = math.degrees(math.atan(a/(b-h)))

print(90 - theta)


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

PII max_sports(vector<vector<int>> &A, vector<int> &ptr)
{
    map<int, int> cnt;
    int mx = 0, mx_idx = -1;

    rep(i, A.size()) {
        int sp = A[i][ptr[i]];
        cnt[sp]++;
        if (cnt[sp] >= mx) {
            mx = cnt[sp];
            mx_idx = sp;
        }
    }

    return PII(mx, mx_idx);
}

int main()
{
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;

    vector<vector<int>> A(N, vector<int>(M));
    rep(n, N) rep(m, M) cin >> A[n][m];

    vector<int> ptr(N, 0);
    int ans = INF;
    set<int> erased;

    while (true) {
        PII t = max_sports(A, ptr);
        ans = min(ans, t.first);
        erased.insert(t.second);
        if (erased.size() == M) break;

        rep(i, N) {
            while (erased.count(A[i][ptr[i]])) {
                ptr[i]++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b; cin >> a >> b;
    if ((a + b) % 2 == 1) cout << "IMPOSSIBLE\n";
    else cout << (a+b)/2 << '\n';
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<int,int>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int INF=1000000007;
using ll=long long;

int n,p[110][11]={};
bool f[110][10]={};

int calc(int select,vector<int> cnt){
	if(!select)return -INF;
	ll ans=0;
	rep(i,0,n)ans+=p[i][cnt[i]];
	return ans;
}
int dfs(int time,int select,vector<int> cnt){
	if(time==10)return calc(select,cnt);
	vector<int> tmp=cnt;
	rep(i,0,n)if(f[i][time])tmp[i]++;
	return max(dfs(time+1,select+1,tmp),dfs(time+1,select,cnt));
}

int main(){
	cin>>n;
	rep(i,0,n)rep(j,0,10)cin>>f[i][j];
	rep(i,0,n)rep(j,0,11)cin>>p[i][j];
	vector<int> cnt(n,0);
	print(dfs(0,0,cnt));
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int 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 vvi 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 MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    int dp[n+1][4][4][4]={};
    dp[0][3][3][3]=1;
    rep(i,n){
        rep(j,4){
            rep(k,4){
                rep(l,4){
                    rep(a,4){
                        if(k==0&&l==2&&a==1)continue;
                        if(k==0&&l==1&&a==2)continue;
                        if(k==2&&l==0&&a==1)continue;
                        if(j==0&&l==2&&a==1)continue;
                        if(j==0&&k==2&&a==1)continue;
                        dp[i+1][k][l][a]=(dp[i+1][k][l][a]+dp[i][j][k][l])%mod;
                    }
                }
            }
        }
    }
    int ans=0;
    rep(i,4){
        rep(j,4){
            rep(k,4){
                ans=(ans+dp[n][i][j][k])%mod;
            }
        }
    }
    cout<<ans<<endl;
}
    

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int const N = 1e6 + 7;
int sieve[N];
int main()
{
	fastio;

	for (ll i = 0; i < N; ++i)
		sieve[i] = i;
	for (ll i = 2; i < N; i += 2)
		sieve[i] = 2;
	for (ll i = 3; i < N; i += 2)
	{
		if (i == sieve[i])
		{
			for (ll j = i*i; j < N; j += i)
				sieve[j] = i;
		}
	}

	int n;
	int gcd;

	bool pairwise = true;
	set<int> used;
	cin >> n;

	int num;
	for (int i = 0; i < n; ++i)
	{
		cin >> num;

		i ? gcd = __gcd(gcd, num) : gcd = num;

		if (pairwise)
		{
			while (num > 1)
			{
				int prime = sieve[num];
				if (used.count(prime))
				{
					pairwise = false;
					break;
				}
				used.insert(prime);
				while (num % prime == 0)
					num /= prime;
			}
		}
	}

	if (pairwise) cout << "pairwise coprime\n";
	else if (gcd == 1) cout << "setwise coprime\n";
	else cout << "not coprime\n";

	return 0;
}


Measured memory_bytes: 11216
import sys
input = sys.stdin.readline
def search(L,e):
    def bsearch(L,e,l,h):
        if h==l:
            return L[l]==e
        m=(h+l)//2
        if L[m]==e:
            return True
        elif L[m]>e:
            if l==m:
                return False
            else:
                return bsearch(L,e,l,m-1)
        else:
            return bsearch(L,e,m+1,h)
    if len(L)==0:
        return False
    else:
        return bsearch(L,e,0,len(L)-1)
n,m=map(int,input().split())
a=[tuple(map(int,input().split())) for i in range(m)]
a.sort(key=lambda x:x[1])
b=[]
for i in range(m):
    if a[i][0]==1:
        b.append(a[i][1])
#print(a)
for i in range(m):
    if a[i][1]==n and search(b,a[i][0]):
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


Measured memory_bytes: 33180
#include <stdio.h>

int main() {
    int i, n = 0;
    int a[100], b[100];
    char op[100];
    int x, y;
    char c;
    while(1) {
        scanf("%d %c %d", &x, &c, &y);
        if(c == '?') break;
        a[n] = x;
        op[n] = c;
        b[n] = y;
        n++;
    }
    for(i = 0; i < n; i++) {
        if(op[i] == '+') printf("%d\n", a[i] + b[i]);
        else if(op[i] == '-') printf("%d\n", a[i] - b[i]);
        else if(op[i] == '*') printf("%d\n", a[i] * b[i]);
        else if(op[i] == '/') printf("%d\n", a[i] / b[i]);
    }
    return 0;
}

Measured memory_bytes: 1796
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
void solve(){
	int w, h;
	cin >> w >> h;
	vector<string> inputs;
	REP(i, h) {
		string s;
		cin >> s;
		inputs.push_back(s);
	}
	int ans = 0;
	REP(i, h) {
		REP(q, w) {
			if (inputs[i][q] == 'W')ans++;
		}
	}
	int now = ans;
	int itr = 0;
	REP(q, w) {
		REP(i, h) {
			if (inputs[i][q] == 'W') ans--;
			if (inputs[i][q] == 'E') ans++;
		}
		if (ans < now) {
			now = ans;
			itr = q + 1;
		}
	}
	cout << itr << " " << itr + 1 << endl;
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 4168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


int main(void){
    string s;
    cin >> s;
    int n = s.size();
    int cnt1 = 0, cnt2 = 0;
    rep(i,n) {
        if ('0'+(i%2) == s[i]) cnt1++;
        if ('0'+(i%2) != s[i]) cnt2++;
    }
    cout << min(cnt1,cnt2) << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		int k = sc.nextInt();
		String s = sc.next();

		if (k >= s.length()) {
			System.out.println(s);
		} else {
			s = s.substring(0,k);
			System.out.print(s);
			System.out.println("...");
		}

        sc.close();
	}
}

Measured memory_bytes: 35748
#include<bits/stdc++.h>
using namespace std;
typedef long long int i64;
i64  mod= 1000000007;
void inline solve(int tt){

    i64 n;
    cin>>n;
    i64 mini=1e13;
    for(int i=1;i<=sqrt(n);i++)
    {
        if((n%i) == 0)
        {
            i64 t=n/i;
            i64 p=i;
            mini=min(mini,(p+t-2));
        }
    }
    cout<<mini<<endl;

}
int main()
{
    int tt=0,t=1;
    //cin>>t;

    while(t--){solve(++tt);}
}



Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MAXN = (int)2e5;
int N;
P arr[MAXN];

bool comp(P a, P b) {
    return a.second < b.second;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) 
        cin >> arr[i].first >> arr[i].second;
    

    if (N % 2 == 1) {
        sort(arr, arr + N);
        int minl = arr[N / 2].first;

        sort(arr, arr + N, comp);
        int maxr = arr[N / 2].second;
        cout << maxr - minl + 1 << endl;
    } else {
        sort(arr, arr + N);
        int l1 = arr[N / 2 - 1].first, l2 = arr[N / 2].first;
        sort(arr, arr + N, comp);
        int r1 = arr[N / 2 - 1].second, r2 = arr[N / 2].second;
        cout << r1 + r2 - l1 - l2 + 1 << endl;
    }
}


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

int main() {
	string S;
	cin >> S;

	string weathers[] = { "Sunny", "Cloudy", "Rainy" };

	int nTommorow;
	for (int i = 0; i < 3; i++) {
		if (weathers[i] == S) {
			nTommorow = i + 1;
			break;
		}
	}

	if (nTommorow == 3) {
		nTommorow = 0;
	}

	cout << weathers[nTommorow];

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int V[N],C[N];
  for(int i=0;i<N;i++) {
    cin>>V[i];
  }
  for(int i=0;i<N;i++) {
    cin>>C[i];
  }
  int ma=0;
  
  for(int tmp=0;tmp<(1<<20);tmp++) {
    bitset<20> s(tmp);
    
    int X=0,Y=0;
    for(int i=0;i<N;i++) {
      if(s.test(i)){
        X+=V[i];
        Y+=C[i];
      }
    }
    ma=max(ma,X-Y);
  }
  cout<<ma<<endl;
  return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
AClst = [0]
c = 0

for i in range(N-1):
  if S[i:i+2]=="AC":
    c += 1
  AClst.append(c)

for q in range(Q):
  l, r = map(int, input().split())
  print(AClst[r-1]-AClst[l-1])

Measured memory_bytes: 6100
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define all(c) (c).begin(),(c).end()

using namespace std;
int in(){int x;cin>>x;return x;}

main(){
    const ll N=1LL<<53;
    while(1){
        ll n;cin>>n;
        if(!n)return 0;
        string s;cin>>s;
        ll k=1;
        for(auto e:s)k=k*2+(e-'0');
        ll st = k;
        ll sisuu = 0;
        while(1){
            ll m = (N-st+k-1)/k;
            if(m>n){
                st+=n*k;break;
            }
            n-=m;
            st = (st+k*m);
            st>>=1;
            k>>=1;
            sisuu++;
            if(!k)break;
        }
        rep(i,12){
            if((1<<(11-i))&sisuu){
                cout<<'1';
            }
            else cout<<'0';
        }
        rep(i,52){
            if(st&(1LL<<(51-i)))cout<<'1';
            else cout<<'0';
        }
        cout<<endl;
    }
}




Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int h, w, K; cin >> h >> w >> K;
  vector<string> s(h);
  for(int i = 0; i < h; i++){
    cin >> s[i];
  }  

  int ans = 0;
  for(int i = 0; i < 1 << h; i++){
    for(int j = 0; j < 1 << w; j++){
      auto t = s;
      for(int k = 0; k < h; k++){
        if(i >> k & 1){
          for(int l = 0; l < w; l++){
            t[k][l] = '.';
          }
        }
      }
      for(int k = 0; k < w; k++){
        if(j >> k & 1){
          for(int l = 0; l < h; l++){
            t[l][k] = '.';
          }
        }
      }

      int cnt = 0;
      for(int k = 0; k < h; k++){
        for(int l = 0; l < w; l++){
          cnt += (t[k][l] == '#');
        }
      }
      if(cnt == K) ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3616
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
ll in(){ ll x; cin >> x; return x; }
vector<ll> in(size_t n){ vector<ll> v(n); each(x, v) cin >> x; return v; }
/* ]]] */

string s;
ll t = 0;

void dfs(int i, vector<ll> v){
  if (i == s.size()) t += accumulate(all(v), 0ll);
  rep(j, i + 1, s.size() + 1){
    auto u = v;
    u.push_back(stol(s.substr(i, j - i)));
    dfs(j, u);
  }
}

int main(){
  cin >> s;
  dfs(0, {});
  cout << t << endl;
}



Measured memory_bytes: 256