akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;

#define ll long long int

int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin >> n;
    if(n%1000 == 0)
      cout<<n%1000;
    else
      cout<<1000-(n%1000);
}


Measured memory_bytes: 3636
#!/usr/bin/env python3
n = int(input())
s = input()
ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n):
    for j in range(i + 1, n):
        k = j * 2 - i
        if k >= n:
            continue
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            ans -= 1
print(ans)


Measured memory_bytes: 9152
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
void solve(){
    int n;
    cin >> n;
    unordered_map<int, int> m;
    vi a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        m[a[i]]++;
        m[a[i]+1]++;
        m[a[i]-1]++;
    }
    int mx = 0;
    for (auto p : m) {
        mx = max(mx, p.se);
    }
    cout << mx;
    
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

Measured memory_bytes: 4644
#include<bits/stdc++.h>
#define ll long long
#define oo 1000000010
using namespace std;

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

	ll n, ans = 0;
	cin >> n;
	string s;
	cin >> s;
	for(int i=0; i<n-2; i++){
		int l = i + 1, r = i + 2, cntR = 0, cntG = 0, cntB = 0;
		for(int j=i+1; j<n; j++){
			if(s[j] == 'R') cntR++;
			if(s[j] == 'G') cntG++;
			if(s[j] == 'B') cntB++;
		}
		if(s[i] == 'R'){
			ans += cntG*cntB;
			while(r < n){
				if(s[i] != s[r] && s[i] != s[l] && s[r] != s[l]) ans--;
				l++, r+=2;
			}
		}
		else if(s[i] == 'G'){
			ans += cntR*cntB;
			while(r < n){
				if(s[i] != s[r] && s[i] != s[l] && s[r] != s[l]) ans--;
				l++, r+=2;
			}
		}
		else if(s[i] == 'B'){
			ans += cntG*cntR;
			while(r < n){
				if(s[i] != s[r] && s[i] != s[l] && s[r] != s[l]) ans--;
				l++, r+=2;
			}
		}
	}
	cout << ans;

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[n - 1] - a[0] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main { //クラス名はMain
    public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String n = scan.next();
    String d = scan.next();
    int N = Integer.parseInt(n);
    int D = Integer.parseInt(d);
    
    int ans = (N + 2*D) / (2*D +1);
    
    System.out.println(ans);
 
 
    }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> ab;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    ab.emplace_back(a, b);
  }
  auto calc = [&](int s) -> i64 {
    i64 sum = 0;
    rep(i, n) {
      int a, b;
      tie(a, b) = ab[i];
      if ((a & s) == a) {
        sum += b;
      }
    }
    return sum;
  };
  i64 ans = calc(k);
  rep(i, 30) {
    if (!(k & bit32(i))) {
      continue;
    }
    amax(ans, calc((k & ~bit32(i)) | (bit32(i) - 1)));
  }
  cout << ans << endl;
}


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

// セグメント木
// ref:https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html
template <typename Mnd>
struct segment_tree {
    int sz;
    vector<Mnd> data;
    function<Mnd(Mnd, Mnd)> f;
    Mnd e;
    //サイズだけ指定して初期化
    segment_tree(int _sz, function<Mnd(Mnd, Mnd)> _f, Mnd _e) : f(_f), e(_e) {
        sz = 1;
        while (sz < _sz) sz <<= 1;
        data.assign(sz * 2, e);
    }
    //参照渡しなので代入とかもできる
    Mnd& operator[](const int& k) {
        return data[k + sz];
    }
    //木を構築 O(n)
    void build() {
        for (int i = sz - 1; i > 0; i--) data[i] = f(data[2 * i], data[2 * i + 1]);
    }
    //更新しつつ木を再構築 O(log n)
    void update(int k, Mnd x) {
        data[k += sz] = x;
        while (k >>= 1) data[k] = f(data[2 * k], data[2 * k + 1]);
    }
    //[a,b)でのクエリに答える　O(log n)
    Mnd query(int a, int b) const {
        Mnd l = e, r = e;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) l = f(l, data[a++]);
            if (b & 1) r = f(r, data[--b]);
        }
        return f(l, r);
    }
};

int n, q;
string s;

int main() {
    cin >> n >> s >> q;
    segment_tree<bitset<26>> seg(
        n, [](const bitset<26> a, const bitset<26> b) { return a | b; }, 0);
    for (int i = 0; i < n; i++) {
        int c = s[i] - 'a';
        seg[i] = (1 << c);
    }
    seg.build();
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            int x;
            char c;
            cin >> x >> c;
            x--;
            int keta = c - 'a';
            seg.update(x, 1 << keta);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            cout << seg.query(l, r).count() << endl;
        }
    }
}

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


int main(){
	bool ok = false;		
	vector<LL>A(3);
	rep(i,3) {
		cin >> A[i];
		if(A[i]%2==0) ok = true;
	}
	sort(A.begin(),A.end());
	if(ok) cout << 0 << endl;
	else cout << A[0]*A[1] << endl;

}














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

int main(){
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2>> m2 >> k;
  cout << (h2-h1)*60 + m2 - m1 -k <<endl;
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

ll x,y;

int main() {
//	file_put(); 
	
	scanf("%lld%lld",&x,&y);
	if (x*y<=0) return 0*printf("%lld\n",abs(abs(x)-abs(y))+!(x<y && (!x || !y)));
	printf("%lld\n",abs(x-y)+(x>y)*2);
	
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;
char s[100005];
int main(int argc, char** argv) 
{
	scanf("%s",s);
	int len = strlen(s);
	for(int i=0; i<len; ++i)
		if(i%2==0)
			printf("%c",s[i]);
	printf("\n");
	return 0;
}






















Measured memory_bytes: 256
// Problem : B - Strings with the Same Length
// Contest : AtCoder Beginner Contest 148
// URL : https://atcoder.jp/contests/abc148/tasks/abc148_b
// Memory Limit : 1024.000000MB 
// Time Limit : 2000.000000milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define all(a) a.begin(),a.end()
#define vl vector<ll>


/*#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}*/


//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

using namespace __gnu_pbds;
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update> order_set;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w;
string s,s1,s2;
//vvl v;
//vl vis,d;

int main() {
    IOS;
	cin>>n;
	cin>>s1>>s2;
	fo(i,n){
		s=s+s1[i]+s2[i];
	}    
	cout<<s;
    return 0;
}


Measured memory_bytes: 256
class DP2D(object):

    def __init__(self, item_n: int, border: int, initializer: int = 0):
        self.item_n = item_n
        self.border = border
        self.table = [[initializer for _ in range(self.item_n + 1)] for _ in range(self.border + 1)]

    def __str__(self):
        return "\n".join(list(map(lambda l:
                                  " ".join(list(map(str, l)))
                                  , self.table)))

    def __repr__(self):
        return "DynamicProgramming object:\n" + \
               "item_n: " + str(self.item_n) + ", border: " + str(self.border) + "\n" + \
               "table:\n" + self.__str__()

    def solve(self, expr: callable) -> list:
        raise NotImplementedError

    def fill_0_idx_with(self, value: int) -> "DP2D":
        self.table[0] = [value for _ in range(self.item_n + 1)]
        for i in range(1, self.border + 1):
            self.table[i][0] = value
        return self


class DP2DOptimizer(DP2D):

    def __init__(self, item_n: int, border: int, obj_coef: list, sbj_coef: list, initializer: int = 0):
        super(DP2DOptimizer, self).__init__(item_n, border, initializer=initializer)

        if len(obj_coef) == self.item_n:  # to 1-base
            obj_coef = [0] + obj_coef
        self.obj_coef = obj_coef

        if len(sbj_coef) == self.item_n:
            sbj_coef = [0] + sbj_coef
        self.sbj_coef = sbj_coef

    def solve(self, expr: callable) -> list:
        for weight_lim in range(1, self.border + 1):
            for item_idx in range(1, self.item_n + 1):
                self.table[weight_lim][item_idx] = expr(weight_lim, item_idx)

        return self.table

    def knapsack_expr(self, weight_lim: int, item_idx: int) -> int:
        res = self.table[weight_lim][item_idx - 1]
        if weight_lim - self.sbj_coef[item_idx] >= 0:
            res = max(res, self.table[weight_lim - self.sbj_coef[item_idx]][item_idx] + self.obj_coef[item_idx])
        return res


if __name__ == '__main__':
    N, W = map(int, input().split())
    v, w = [], []
    for _ in range(N):
        buff = [int(i) for i in input().split()]
        v.append(buff[0])
        w.append(buff[1])
    dp = DP2DOptimizer(N, W, v, w)
    print(dp.solve(dp.knapsack_expr)[W][N])



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

#define get_variable_name(x) #x
#define debug(x) cout << #x << " = " << x << endl
#define rep(i, begin, end) for(int (i) = (begin); (i) < (end); (i)++)

#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())
#define REVERSE(x) reverse( (x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define PW(x) (1LL<<(x))

using namespace std;
using ll = int64_t;
using P = pair<int, int>;

template<class T,class U>
ostream& operator<<(ostream &os, const pair<T, U> &p) {
    os << get_variable_name(p) << " = (" << p.first <<", " << p.second << ")";
    return os;
}

template<class T>
ostream& operator <<(ostream& os, const vector<T> &v){
    cout << get_variable_name(v) << " = [";
    for(auto i : v) 
        os << " " << i;
    os << " ]";
    return os;
}


const int INF = 1e8;

int main() {
    ios::sync_with_stdio(false);
    int N, L;
    string s;
    vector<string> v;
    cin >> N >> L;
    rep(i,0,N) {
        cin >> s;
        v.emplace_back(s);
    }
    sort(v.begin(), v.end());
    s = "";
    rep(i,0,N) s += v[i];
    cout << s << endl;
}


Measured memory_bytes: 256
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    cnt_A = 0
    cnt_B = 0
    for i in range(N):
        if A[i] > B[i]:
            cnt_A += A[i] - B[i]
        if B[i] > A[i]:
            cnt_B += (B[i] - A[i]) // 2

    if cnt_B >= cnt_A:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 10516
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ll long long
#define int long long
#define mod 1000000007
#define DEBUG cout<<"Hello1\n";
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))
#define deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int N = 1e7 + 5;
const double pi =  acosl(-1);
const ll inf = 1e18 + 5;
using namespace std;
template<typename T> void debug(string s, T x) {cout << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cout << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}
template<class T> void print_container(T &container) { for (auto &t : container) { cout << t << " ";} cout << endl;}
template<class T> void printArr(T &a , int n) { for (int i = 0; i < n; i++) {cout << a[i] << " ";} cout << endl;}

//Template Ends
int n;
ll ans = 0;
int dp[N];

void solve() {

	cin >> n;

	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j += i) {
			dp[j]++;
		}
	}

	for (int i = 1; i <= n; i++) {
		ans += i * dp[i];
	}

	cout << ans << endl;
}

int32_t main() {
	IOS;
	solve();


	return 0;
}




Measured memory_bytes: 81728
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <deque>
#include <queue>
#include <stack>
 
using namespace std;	
 
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define rev reverse
#define mp make_pair
#define all(x) x.begin(), x.end()
#define ll long long
#define sz(x) (int)x.size()
/*
string lower(string a)
{
	for(int i=0;i<a.size();i++)
	{
		a[i]=tolower(a[i]);
	}
	return a;
}
ll nod(ll a,ll b)
{
    if(a==0)
        return b;
    else if(b==0)
        return a;
    if(a>=b)
        return nod(a%b,b);
    else if(a<=b)
        return nod(a,b%a);
}
ll nok(ll x, ll y)
{
	return x/nod(x,y)*y;
}
*/
const ll INF = 1e9+7;
int main()
{
//	freopen("D.in", "r", stdin);
//	freopen("D.out", "w", stdout);	
	IOS;\
	ll h, w, n;
	cin >> h >> w >> n;
	ll mx = max(h, w);
	if(mx == w)
	{
		ll cnt = 0, ans = 0;
		while(cnt < n)
		{
			cnt += w;
			ans++;
		}
		cout << ans << endl;
	}
	else
	{
		ll cnt = 0, ans = 0;
		while(cnt < n)
		{
			cnt += h;
			ans++;
		}
		cout << ans << 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;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
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; }

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    ll xorsum = a[0];
    for (int i = 1; i < n; ++i) {
        xorsum = xorsum ^ a[i];
    }

    vector<ll> ans(n);
    rep(i, n) {
        ans[i] = xorsum ^ a[i];
        cout << ans[i] << " ";
    }
}


Measured memory_bytes: 6428
#include <stdio.h>

int main()
{
	int a, b, c, d, e;
	scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
	if (a == 0) printf("1\n");
	else if (b == 0) printf("2\n");
	else if (c == 0) printf("3\n");
	else if (d == 0) printf("4\n");
	else printf("5\n");
	fflush(stdout);
	return 0;
}

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

int main() {
  int N, X, a;
  cin >> N;
  int n = N;

  for (int i=0; i<8; i++) {
    a = n % 10;
    X += a;
    n = (n-a) /10;
  }
  
  if (N % X == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    static double dp[21][250011];
    rep(i,21)rep(j,250011)dp[i][j] = INF;
    dp[0][1] = 0;
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=250010;j++){
            double diff = (double)abs(v[i-1]-j)/v[i-1];
            int sq = sqrt(j);
            for(int k=1;k<=sq;k++){
                if(j%k==0){
                    dp[i][j] = min( dp[i][j], max( dp[i-1][k],   diff ) );
                    dp[i][j] = min( dp[i][j], max( dp[i-1][j/k], diff ) );
                }
            }
        }
    }
    double ans = INF;
    rep(i,250011)ans = min(ans,dp[n][i]);
    printf("%.20lf\n",ans);
}

Measured memory_bytes: 44244
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define x first
#define y second
#define pb push_back
#define ll long long
#define int ll
#define ld long double
#define ii pair<int, int>
#define iii pair<int, ii>
#define vi vector<int>
#define vii vector<ii>
#define pq priority_queue
using namespace std;
const int ms = 3100;
const int mod = 1e9+7;
const int inf = 1e9 + 100;
const int sigma = 30;
int n, m, k, t = 1;
string a, b;
int lim;
double ele[ms];

double dp[ms][ms];
int seen[ms][ms];

double sol(int qt, int i){
  if(i==n) return 1.0;

  if(seen[qt][i]) return dp[qt][i];
  seen[qt][i] = 1;

  if(qt==lim){
    return dp[qt][i] = sol(qt, i+1)*ele[i];
  }
  return dp[qt][i] = sol(qt+1, i+1)*(1.0 - ele[i]) + sol(qt, i+1)*(ele[i]);
}

void solve(){
  cin>>n;
  lim = (n/2);
  for(int i=0; i<n; i++){
    cin>>ele[i];
  }
  cout<<fixed<<setprecision(10);
  cout<<sol(0, 0)<<endl;
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  while(t--){
    solve();
  }
}

Measured memory_bytes: 76288
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;


int main(){
int N;
cin >> N;
string S;
for(int i = 0; i < N; i++){
cin >> S[i] ;
}
int counter = 0;

for(int i = 0; i < N; i++){
    if(S[i] == 'Y')counter++;
   
}

if(counter != 0)cout << "Four" << endl;
else cout << "Three" << endl;

}


Measured memory_bytes: 256
#include <iostream>
using ll = long long;
using namespace std;
constexpr ll M = 1e9+7;

int main() {
    ll N;
    cin >> N;
    ll res = 1;
    for(ll i=1; i<=N; ++i) {
        res *= i;
        res %= M;
    }
    cout << res << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; ++i) {
    cin >> d.at(i);
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      ans += d.at(i) * d.at(j);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def line_to_int(): return int(sys.stdin.readline())
def line_to_each_int(): return map(int, sys.stdin.readline().split())
def line_to_list(): return list(map(int, sys.stdin.readline().split()))
def line_to_list_in_iteration(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
# def dp(init, i, j): return [[init]*i for i2 in range(j)]
import sys
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #A = [0]+list(accumulate(A))
import bisect #bisect.bisect_left(B, a), bisect.bisect_right(B,a)

n = line_to_int()
if n % 1000 == 0:
    print(0)
else:
    print((n // 1000 + 1)*1000 - n)

Measured memory_bytes: 9200
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <map>

const int mod = 1000000007;
//const int mod = 998244353;
int maximum(int a, int b) { return a < b ? b : a; }
bool same(char*s, char*t) {
	for (int i = 0;; i++) {
		if (s[i] != t[i])return false;
		if (s[i] == 0) {
			return true;
		}
	}
}

int main() {
	int N;
	scanf("%d", &N);
	auto A = new int[N];
	for (int i = 0; i < N; i++) {
		scanf("%d", A + i);
	}
	std::sort(A, A + N);
	for (int i = 1; i < N; i++) {
		if (A[i - 1] == A[i]) {
			printf("NO");
			return 0;
		}
	}
	printf("YES");
	return 0;
}

Measured memory_bytes: 1024
import bisect
import itertools
def find_ge(a, x):
    i = bisect.bisect_right(a,x)
    return i

def solve(n, a, b, c):

    tmp = len(c)
    b_count =list(itertools.accumulate([tmp - find_ge(c, x) for x in b]))
    ans = 0
    for i in a:
        min_index = find_ge(b, i)
        
        ans += b_count[-1] -(0 if min_index == 0 else b_count[min_index-1])
    
    return ans

if __name__ == "__main__":
    n = int(input())
    a = sorted([int(i) for i in input().split()])
    b = sorted([int(i) for i in input().split()])
    c = sorted([int(i) for i in input().split()])
    print(solve(n, a, b, c))

Measured memory_bytes: 25588
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

const int LIM=10000010;

bool sosu[LIM];
int quad[LIM];

int main() {
	int i,j;
	for(i=0;i<LIM;i++)sosu[i]=true;
	sosu[0]=sosu[1]=false;
	for(i=0;i<LIM;i++){
		if(sosu[i]){
			for(j=i*2;j<LIM;j+=i){
				sosu[j]=false;
			}
		}
	}
	int q;
	for(i=13;i<LIM;i++){
		if(sosu[i-8]&&sosu[i-6]&&sosu[i-2]&&sosu[i])q=i;
		quad[i]=q;
	}
	int n;
	while(n=in()){
		cout<<quad[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}
		
		// 計算
		int result = -1;
		int cnt = 0;
		boolean ok = false;
		for(int i = 0; i < n; i++){
		    int sa = a[i] - (i+1) + cnt;
		    if(sa != 0){
		        cnt++;
		    }else{
		        ok = true;
		    }
		}
		if(ok) result = cnt;
		//System.out.println(list.toString());
		
		// 出力
		System.out.println(result);
	}
}




Measured memory_bytes: 78268
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <math.h>
#include <typeinfo>
#include <numeric>
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <queue>

using namespace std;


int main()
{
	long long N, M;

	cin >> N >> M;

	long long ans = 0;
	if (N == 1 && M == 1)
	{
		ans = 1;
	}
	else if (N == 1 || M == 1)
	{
		ans = max(N, M) - 2;
	}
	else
	{
		ans = (N - 2) * (M - 2);
	}

	cout << ans << endl;

	return 0;
 
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

struct restaurant
{
    int num;
    char s[11];
    int p;
};


int main()
{
    int n;
    cin >> n;
    restaurant city[n], tmp;
    for (int i = 0; i < n; i++)
    {
        city[i].num = i;
        scanf("%s%d", city[i].s, &city[i].p);
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = i+1; j < n; j++)
        {
            if (city[i].p < city[j].p)
            {
                tmp = city[i];
                city[i] = city[j];
                city[j] = tmp;
            }
        }
    }
    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j < n; j++)
        {
            if (strcmp(city[j-1].s, city[j].s)>0)
            {
                tmp = city[j-1];
                city[j-1] = city[j];
                city[j] = tmp;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << city[i].num + 1 << endl;
    }

    return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	string s;
	cin >> s;

	rep(i, s.size()){
		if(i % 2 == 0){
			cout << s[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 592
EPS = 0.0001
while True:
	try:
		a = list(map(float, input().split()))
		dd = a[0]*a[4]-a[3]*a[1]
		d1 = a[2]*a[4]-a[5]*a[1]
		d2 = a[0]*a[5]-a[3]*a[2]
		print("{0:.3f} {1:.3f}".format(d1/dd+EPS, d2/dd+EPS))
	except EOFError:
		break



Measured memory_bytes: 5580
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[1000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
    int n;
    int a,b,c;
    while(cin>>n,n){
        double ave;
        double mave;
        for(int i=0;i<n;i++){
            cin>>a>>b>>c;    
            ave=(a+b+c)/3;
            mave=(a+b)/2;
            if(a==100||b==100||c==100) cout<<"A"<<endl;
            else if(mave>=90) cout<<"A"<<endl;
            else if(ave>=80) cout<<"A"<<endl;
            else if(ave>=70) cout<<"B"<<endl;
            else if(ave>=50&&(b>=80||a>=80)) cout<<"B"<<endl;
            else cout<<"C"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5344
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using static Scanner;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Solve();
        Console.Out.Flush();
    }
    static void Solve() {
        var N = ScanInt();
        var set = new HashSet<int>();
        for (int i = 0; i < N; i++) {
            var num = ScanInt();
            if (set.Contains(num)) set.Remove(num);
            else set.Add(num);
        }
        Console.WriteLine(set.Count);
    }
}

public static class Scanner
{
    static readonly Stream stream = Console.OpenStandardInput();
    static readonly byte[] buffer = new byte[1024];
    static int length, p;
    static bool isEof;
    private static byte ConsoleIn() {
        if (isEof) return 0;
        if (p < length) return buffer[p++];
        p = 0;
        if ((length = stream.Read(buffer, 0, 1024)) > 0) return buffer[p++];
        isEof = true;
        return 0;
    }
    public static char GetChar() {
        var by = ConsoleIn();
        while ((by < '!' || '~' < by) && !isEof) by = ConsoleIn();
        return (char) by;
    }
    public static int ScanInt() {
        var temp = 0;
        for (var ch = GetChar(); '0' <= ch && ch <= '9'; ch = (char) ConsoleIn()) {
            temp = temp * 10 + ch - '0';
        }
        return temp;
    }
}

Measured memory_bytes: 22432
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll m; cin >> m;
    vector <ll> hs;
    REP(i, n){
        ll h; cin >> h;
        hs.push_back(h);
    }
    vector <ll> notgood(n, 0);
    REP(i, m){
        ll a; cin >> a; a--;
        ll b; cin >> b; b--;
        if (hs[a] >= hs[b]){
            notgood[b]++;
        }
        if (hs[a] <= hs[b]){
            notgood[a]++;
        }
    }
    ll ans = 0;
    REP(i, n){
        ans += notgood[i] == 0;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int N; std::cin >> N;

  int AC = 0, WA = 0, TLE = 0, RE = 0;

  for(int i = 0; i < N; ++i){
    std::string s; std::cin >> s;

    if(s == "AC") ++AC;
    if(s == "WA") ++WA;
    if(s == "TLE") ++TLE;
    if(s == "RE") ++RE;
  }

  std::cout << "AC x " << AC << "\n"
            << "WA x " << WA << "\n"
            << "TLE x " << TLE << "\n"
            << "RE x " << RE << "\n";
  
  

  return 0;
}


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

using namespace std;
using ll = long long;

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

  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  vector<vector<int>> ans(h, vector<int>(w));

  int y = 0;
  int x = 0;
  auto coloring = [&](int color) {
    ans[y][x] = color;
    if (y == 0) {
      if (x % 2 == 0 && h != 1) {
        y++;
      } else {
        x++;
      }
    } else if (y == h - 1) {
      if (x % 2 == 0) {
        x++;
      } else {
        y--;
      }
    } else {
      if (x % 2 == 0) {
        y++;
      } else {
        y--;
      }
    }
  };

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < a[i]; j++) {
      coloring(i + 1);
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3676
N=int(input())
A=list(map(int,input().split()))
L=[0 for i in range(200010)]
R=[0 for i in range(200010)]
for i in range(N):
    if A[i]+i<200010:
        L[A[i]+i]+=1
    if -A[i]+i>0:
        R[-A[i]+i]+=1
ans=0
for i in range(200010):
    ans+=L[i]*R[i]
print(ans)

Measured memory_bytes: 32160
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let s = get_line();
    let checker = "AGCT".to_string();
    let mut result = 0;
    for i in 0..s.len() {
        for j in i + 1..s.len() + 1 {
            if s[i..j].chars().all(|c| checker.contains(c)) {
                if result < s[i..j].len() {
                    result = s[i..j].len();
                }
            }
        }
    }
    println!("{}", result);
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

int n;
vec<int> v;

bool bin(int key) {
   int left = 0, right = n - 1;
   while (left <= right) {
      int mid = (left+right)/2;
      if (key > v[mid]) {
         left = mid + 1;
      } else if (key < v[mid]) {
         right = mid - 1;
      } else {
         return true;
      }
   }
   return false;
}

int main() {
   cin >> n;
   rep (i, 0, n) {
      int x;
      cin >> x;
      v.push_back(x);
   }
   sort(all(v));

   int q;
   cin >> q;
   int cnt = 0;
   rep (i, 0, q) {
      int x;
      cin >> x;
      if (bin(x)) cnt++;
   }
   cout << cnt << endl;

   return 0;
}


Measured memory_bytes: 3436
#include <stdio.h>

int main(void){
	int i , l[10] , v1 , v2 , d , l2[10];
	double pos;
	while(scanf("%d" , l)!=EOF){
		for(i=1;i<10;i++){
			scanf(",%d" , &l[i]);
		}
		scanf(",%d,%d" , &v1 , &v2);
		d = 0;
		for(i=0;i<10;i++){
			d += l[i];
		}
		pos = ((double)v1 / (v1 + v2)) * d;
		l2[0] = l[0];
		for(i=1;i<10;i++){
			l2[i] = l2[i-1] + l[i];
		}
		for(i=1;i<=10;i++){
			if(pos <= l2[i-1]){
				printf("%d\n" , i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>
//#include<vector>
#include<algorithm>


#ifdef L_JUDGE
#pragma warning(disable:4996)
#endif

using namespace std;
typedef long long int LL;
const int MAXN=1005;
const LL MODU=1e9+7;

LL n,a,b,c,d;
LL dp[2][MAXN];
LL C[MAXN][MAXN];
LL fac[MAXN];
LL prod[MAXN];

LL ModExp(LL a,LL b,LL p){
    LL ret=1;
    while(b){
        if(1&b)ret=ret*a%p;
        a=a*a%p;
        b>>=1;
    }
    return ret;
}

LL Call(LL k,LL left){
    memset(prod,0,sizeof(prod));
    prod[0]=1;
    LL tmpn=left;
    LL pp=1;
    if(left<k*c)return 0;

    int ci=0;
    while(tmpn>=k){
        pp=pp*C[tmpn][k]%MODU;
        tmpn-=k;
        ci++;
        if(ci<c)continue;
        prod[ci]=pp*ModExp(fac[ci],MODU-2,MODU)%MODU;
        if(ci>d)break;
    }

    return 0;

}

int main(){
	#ifdef L_JUDGE
		freopen("in.txt","r",stdin);
//		freopen("out.txt","w",stdout);
	#endif
    memset(C,0,sizeof(C));
    C[0][0]=1;
    fac[0]=fac[1]=1;
    for(int i=1;i<MAXN;i++){
        fac[i]=fac[i-1]*i%MODU;
        C[i][0]=1;
        for(int j=1;j<=i;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%MODU;
        }
    }
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    if(a*c>n)return 0*printf("0\n");

    memset(dp,0,sizeof(dp));
    int now=0,la=1;

    Call(a,n);
    dp[now][0]=1;
    for(int i=c,v=c*a;i<=d&&v<=n;i++,v+=a){
        dp[now][v]=prod[i];
    }
    int jmax=min(n,a*d);
    for(int ni=a+1;ni<=b;ni++){
        swap(now,la);
        memset(dp[now],0,sizeof(dp[now]));
        for(int j=0;j<=jmax;j++){
            LL tmpn=n-j;
            Call(ni,tmpn);
            dp[now][j]=(dp[la][j]+dp[now][j])%MODU;
            for(int k=c,v=ni*c;k<=d&&v<=tmpn;k++,v+=ni){
                dp[now][j+v]=(dp[now][j+v]+dp[la][j]*prod[k])%MODU;
            }
        }
        jmax=min(n,jmax+ni*d);
    }
    printf("%lld\n",dp[now][n]);

	#ifdef L_JUDGE
		fclose(stdin);
		fclose(stdout);
//		system("out.txt");
	#endif

	return 0;
}


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

using namespace std;

vector<int> a;

int main() {
  int n;
  scanf("%d", &n);
  a.resize(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int mini = 1000000;
  int maxi = 0;
  for (int c : a) {
    mini = min(mini, c);
    maxi = max(maxi, c);
  }
  if (maxi - mini > 1) {
    printf("No\n");
    return 0;
  }

  if (mini == maxi) {
    if (mini * 2 <= n) {
      printf("Yes\n");
    } else if (n == mini + 1) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  } else {
    int lower = 0;
    int upper = 0;
    for (int c : a) {
      if (c == mini) lower++;
      if (c == maxi) upper++;
    }
    if (lower >= maxi) {
      printf("No\n");
    /*} else if (lower == maxi) {
      if (upper == 1) {
        printf("No\n");
      } else {
        printf("Yes\n");
      }*/
    } else {
      // lower < maxi.
      int colorsLeft = maxi - lower;
      if (colorsLeft == 0) {
        printf("No\n");
        return 0;
      }
      if (2 * colorsLeft <= upper) {
        printf("Yes\n");
      } else {
        printf("No\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 768
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    long long n,tot=1,ans=0;scanf("%lld",&n);
    while(n){
        ans+=tot;
        tot*=2;
        n/=2;
    }
    printf("%lld\n",ans);
    return 0;
}


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

int getDigits(int n){
    int digits = 0;
    while(n > 0){
        n /= 10; 
        digits++;
    }
    return digits;
}

int main() {
    
    int N;
    cin >> N; 
    int ans = 0;
    for(int i = 1; i <= N; i++){
        if(getDigits(i) % 2 == 1){
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <cassert>
#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 <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#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 <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	bool hantei = true;
	int aa, bb;
	string a;
	cin >> aa >> bb >> a;
	for (int i = 0; i < a.size(); i++)
	{
		if (i != aa)
		{
			if ('0' <= a[i] && a[i] <= '9')
			{

			}
			else 
			{
				hantei = false;
			}
		}
		else 
		{
			if (a[i] != '-')
			{
				hantei = false;
			}
		}
	}
	if (hantei == true)
	{
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}
}

/*
	1011
	0101

*/

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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;


void solve() {
	int n;
	cin >> n;
	int ans = INF;
	for (int d = 1; d * d <= n; d++) {
		if (n % d == 0) {
			ans = min(ans, d + n / d - 2);
		}
	}
	cout << ans;
}
	

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
   public static void main(String Args[]){
      Scanner sc = new Scanner(System.in);
      int  W = sc.nextInt();
      int  H = sc.nextInt();
      int  x = sc.nextInt();
      int  y = sc.nextInt();
      int  r = sc.nextInt();
      
     
      if(x<=W && y<=H && x>=0 && y>=0 && r+x<=W && r+y<=H)
        System.out.println("Yes");
      else
        System.out.println("No");
   }
}


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

using namespace std;
const int N = 1e6+100;
long long a[N];
int main(){
	int n;
	cin>>n;
	int num=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]<0) num++;
	}
	long long ans=0;
	for(int i=1;i<=n;i++){
		a[i]=abs(a[i]);
		ans+=a[i];
	}
	sort(a+1,a+n+1);
	if(num&1){
		cout<<ans-2*a[1]<<endl;
	}
	else{
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>


using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 K = 0;
	SINT32 ans = 0;

	cin >> N;
	cin >> K;

	vector<SINT32> DATA(N);
	
	rep(i,0,N) {
		cin >> DATA[i];
		ans += MIN(DATA[i],ABS(K - DATA[i]))*2;
	}

	cout << ans << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));	//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/
/* 文字列合成
	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;
	ans = stoi(N+M);
*/



/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

// Binary Indexed Tree
template <class T> struct BIT {
    vector<T> d;

    BIT(int n) { init(n); }
    void init(int n) { d.assign(n + 1, 0); }

    // a: 1-indexed
    inline void add(int a, T x) {
        for (int i = a; i < (int)d.size(); i += i & -i) {
            d[i] = d[i] + x;
        }
    }

    // [1, a]
    // a: 1-indexed
    inline T sum(int a) {
        T res = 0;
        for (int i = a; i > 0; i -= i & -i) {
            res = res + d[i];
        }
        return res;
    }

    // [a, b)
    // a, b: 1-indexed
    inline T sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
};

int N, Q;
string S;

void _main() {
    cin >> N >> S >> Q;
    vector<BIT<int>> bit(26, BIT<int>(N));
    REP (i, N) bit[S[i] - 'a'].add(i + 1, 1);
    REP (t, Q) {
        int c;
        cin >> c;
        if (c == 1) {
            int i;
            char x;
            cin >> i >> x;
            i--;
            bit[S[i] - 'a'].add(i + 1, -1);
            bit[x - 'a'].add(i + 1, 1);
            S[i] = x;
        } else {
            int l, r;
            cin >> l >> r;
            int ans = 0;
            REP (i, 26) ans += (bit[i].sum(l, r + 1) > 0);
            cout << ans << endl;
        }
    }
}

signed main(signed argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 106396