akhauriyash/Code-Regression huggingface dataset:
import math

def my_round(x,d=0):
    p = 10 ** d
    return float(math.floor((x * p) + math.copysign(0.5, x))) / p

class Equation():
    def __init__(self, a, b, c, d, e, f):
        self.a = a
        self.b = b
        self.c = c
        self.d = d
        self.e = e
        self.f = f

    def calc(self):
        temp = (self.a * self.e - self.b * self.d)
        temp_a = (self.c * self.e - self.b * self.f)
        temp_b = (self.a * self.f - self.c * self.d)
        try:
            x = round(temp_a / temp+0., 3)
        except ZeroDivisionError:
            x = round(temp_a / 1.0, 4)

        try:
            y = round(temp_b / temp+0., 3)
        except:
            y = round(temp_b / 1.0, 4)


        return x, y


    def print(self):
        ans = self.calc()
        print("{0:.3f} {1:.3f}".format(ans[0], ans[1]))


def main():
    data = []

    while 1:
        try:
            n = input().split()

            a = float(n[0])
            b = float(n[1])
            c = float(n[2])
            d = float(n[3])
            e = float(n[4])
            f = float(n[5])

            data.append(Equation(a, b, c, d, e, f))

        except EOFError:
            break

    for num in data:
        num.print()

if __name__ == "__main__":
    main()

Measured memory_bytes: 5660
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <stack>
#include <set>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
    return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
    os<<'[';
    rep(i,a.size()) os<<(i?" ":"")<<a[i];
    return os<<']';
}

int bits_of(int dat, int msb, int lsb) {
	int x = dat >> lsb;
	int m = 1 << msb - lsb + 1;
	return x & m - 1;
}

int swap(int n, int a, int b) {
	int x = bits_of(n, 2 + a * 3, a * 3);
	int y = bits_of(n, 2 + b * 3, b * 3);
	int _z = ~(n ^ (x << a * 3));
	int z = ~(_z ^ (y << b * 3));
	return z | x << b * 3 | y << a * 3;
}


int main() {
		queue<pii> q;
		q.push(mp(0, 01234567));
		map<int, int> visited;
		
		while(!q.empty()) {
			pii st = q.front();
			int b = st.snd;
			q.pop();
			
			if (visited[b] != 0) continue;
			visited[b] = st.fst + 1;
			
			int p = 0;
			int t = b;
			while(t != 0) {
				if (t == (t >> 3) << 3) break;
				t >>= 3;
				p++;
			}
			int d[] = {-1, 1, -4, 4};
			rep(i, 4) {
				if (p == 3 && i == 1) continue;
				if (p == 4 && i == 0) continue;
				int tp = p + d[i];
				if (tp < 0 || tp >= 8) continue;
				b = swap(b, p, tp);
				q.push(mp(st.fst + 1, b));
				b = swap(b, p, tp);
			}
		}
	
		for(string s; getline(cin, s); ) {
			int board = 0;
			rep(i, 8) {
				board = board << 3 | s[i * 2] - '0';
			}
			cout << visited[board] - 1 << endl;
		}
    
    return 0;
}

Measured memory_bytes: 2156
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define MAX_N 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1

void print(vector<int> v) {
    rep(i, v.size()) {
        if(i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}

int main() {
    int A, B, K;
    vector<int> v;
    vector<int> v2;
    cin >> A >> B >> K;

    repp(i, 1, A + 1) {
        if(A % i == 0) {
            v.push_back(i);
        }
    }
    // print(v);

    rep(i, v.size()) {
        if(B % v[i] == 0) {
            v2.push_back(v[i]);
        }
    }
    // print(v2);

    cout << v2[v2.size() - K] << endl;
}


Measured memory_bytes: 256
import math
import copy

a,b,c = map(int,input().split())
if (a > b)and(a > c):
    mx = a
    if b > c:
        md = b
        mn = c
    else:
        md = c
        mn = b
elif (a > b)or(a > c):
    md = a
    if b > c:
        mx = b
        mn = c
    else:
        mx = c
        mn = b
else:
    mn = a
    if b > c:
        mx = b
        md = c
    else:
        mx = c
        md = b
neko = mx-md
if mx != mn+neko:
    nya = mx - (mn+neko)
    neko += math.ceil(nya/2) + nya%2
print(neko)

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

vector<pair<ll,ll> > abc[100001];
vector<ll> cost(100001,0);
vector<bool> visit(100001,true);

void dfs(ll n,ll c){
    if(abc[n].size()==0) ;
    else{
        for(int i=0;i<abc[n].size();i++){
            if(visit[abc[n][i].first]){
                visit[abc[n][i].first]=false;
                cost[abc[n][i].first]=c+abc[n][i].second;
                dfs(abc[n][i].first,cost[abc[n][i].first]);
            }
        }
    }
}

int main(){

    ll n;
    cin >> n;

    for(int i=0;i<n-1;i++){
        ll a,b,c;
        cin >> a >> b >> c;
        abc[a].push_back({b,c});
        abc[b].push_back({a,c});
    }

    ll q,k;

    cin >> q >> k;

    visit[k]=false;
    dfs(k,0);

    for(ll i=0;i<q;i++){
        ll x,y;
        cin >> x >> y;
        cout << cost[x]+cost[y] << endl;
    }

    return 0;
}

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

class UnionFind {
private:
    vector<int> par;
    vector<int> rank;
    vector<int> size;
public:
    UnionFind(int n) {
        for (int i = 0; i < n; i++) {
            par.push_back(i);
            rank.push_back(0);
            size.push_back(1);
        }
    }

    int find(int x) {
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        int px = find(x);
        int py = find(y);
        if (px == py) return;
        if (rank[px] < rank[py]) {
            par[px] = py;
            size[py] += size[px];
        } else {
            par[py] = px;
            size[px] += size[py];
            if (rank[px] == rank[py]) rank[px]++;
        }
    }

    int get_size(int x) {
        return size[find(x)];
    }
};

int main(int argc, char const *argv[]) {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
    }

    int ans = 1;
    for (size_t i = 0; i < n; i++) ans = max(ans, uf.get_size(i));

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


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    int k,a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin>>k;

    //cout <<fixed<<setprecision(16)<< << endl;
    
    cout<<a[k-1]<<endl;
    
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=1e15;
const ll MOD=1000000007;

int main(){
    int X;cin>>X;
    for(int i=1;i<=X/100;i++){
        int N=X-i*100;
        if(0<=N and N<=5*i){
            cout<<1<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int H, W;
  char a[110][110] = {};
  char b[110][110] = {};

  scanf("%d%d", &H, &W);
  for(int i = 0; i < H; i++){
    scanf("%s", a[i]);
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      b[i+1][j+1] = a[i][j];
    }
  }

  for(int i = 0; i < H + 2; i++){
    b[i][0]   = '#';
    b[i][W+1] = '#';
  }

  for(int j = 0; j < W + 2; j++){
    b[0][j]   = '#';
    b[H+1][j] = '#';
  }

  for(int i = 0; i < H + 2; i++){
    printf("%s\n", b[i]);
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
 
int main() {
	string str;
	cin >> str;
	for(int i=0; i<str.size(); i++){
		if(i==5 || i==13){
			cout << " ";
		}else{
			cout << str.at(i);
		}
	}
	cout << endl;
}

Measured memory_bytes: 384
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	string s;
	cin >> s;
	int month = stoi(s.substr(5, 2));
	int date = stoi(s.substr(8, 2));
	if (month < 4) {
		cout << "Heisei\n";
	} else if (month == 4 && date <= 30) {
		cout << "Heisei\n";
	} else {
		cout << "TBD\n";
	}
}

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

int main() {
	int a, b; cin >> a >> b;
	if (a <= 0 && b >= 0) { cout << "Zero" << endl; return 0; }
	if (a > 0 && b > 0) { cout << "Positive" << endl; return 0; }

	int multiple = abs(b - a);
	if (multiple % 2 != 0)cout << "Positive" << endl;
	else cout << "Negative" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
  int ans; int h,w;
int grid[21][21];
const int dx[] = {-1, 0, 1, 0, -1,-1, 1, 1};
const int dy[] = { 0, 1, 0,-1, -1, 1,-1, 1};
bool isallowed(int x,int y)
{
  if(x>=0 and x<h and y>=0 and y<w and grid[x][y])
    return true;
  return false;
}
void bfs(int r,int c)
{
  int vis[h][w];
  memset(vis,0,sizeof(vis));
  queue<pair<int,pair<int,int>>>q;
  q.push({r,{c,0}});
  while(!q.empty())
  {
    r=q.front().first;
    c=q.front().second.first;
    int d=q.front().second.second;
    q.pop();
    vis[r][c]=1;
    ans=max(ans,d);
    for(int i=0;i<4;i++)
    {
      if(isallowed(r+dx[i],c+dy[i]) and !vis[r+dx[i]][c+dy[i]])
      {
        vis[r+dx[i]][c+dy[i]]=1;
        q.push({r+dx[i],{c+dy[i],d+1}});
      }
    }
  }
}
  int main()
{
 
  cin>>h>>w;
  string s;
  
  for(int i=0;i<h;i++)
  {
    cin>>s;
    for(int j=0;j<w;j++)
    {
      if(s[j]=='.')
        grid[i][j]=1;
      else
        grid[i][j]=0;
    }
  }
  for(int i=0;i<h;i++)
  {
    for(int j=0;j<w;j++)
    {
      if(grid[i][j])
        bfs(i,j);
    }
  }
    cout<<ans<<"\n";
    return 0;
  }


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

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


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


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

std::vector<int64_t> convert_base_to(int64_t val, int64_t base){
  if(val == 0) return {0};

  std::vector<int64_t> ret;
  while(val){
    if(val < base){
      ret.push_back(val);
      break;
    }
    ret.push_back(val % base);
    val /= base;
  }
 
  return ret;
}

int64_t convert_base_from(const std::vector<int64_t> &val, int64_t base){
  int64_t ret = 0;
  for(auto it = val.rbegin(); it != val.rend(); ++it){
    (ret *= base) += *it;
  }

  return ret;
}




int main(){
  int N, K;
  while(cin >> N >> K){
    auto res = convert_base_to(N, K);

    puts_all(res.size());
    
  }

  return 0;
}


Measured memory_bytes: 256
// Aizu Vol0 0029: English Sentence
// 2017.7.31

#include <stdio.h>
#include <ctype.h>
#include <string.h>

char *gets(char *);

#define MAX 1000
char *w[MAX + 5];
int len[MAX + 5];
int cnt[MAX + 5];
char buf[MAX + 10], *p;

void PutW(char *w, int n)
{
	while (n--) putchar(*w++);
}

int main()
{
	int i, j, n;
	int max1, max2, ans1, ans2;
	char *p;

	n = 0;
	gets(p = buf);
	while (*p) {
		while (isspace(*p)) p++;
		if (!*p) break;
		w[n] = p;
		while (isalnum(*p)) p++;
		len[n] = p - w[n];
		n++;
	}

	for (i = 0; i < n; i++) {
		if (cnt[i] < 0) continue;
		for (j = i + 1; j < n; j++) {
			if (len[j] == len[i] && !memcmp(w[i], w[j], len[j])) {
				cnt[i]++, cnt[j] = -1;
			}
		}
	}
	for (i = 0, max1 = max2 = 0; i < n; i++) {
		if (cnt[i] > max1) ans1 = i, max1 = cnt[i];
		if (len[i] > max2) ans2 = i, max2 = len[i];
	}
	PutW(w[ans1], len[ans1]);
	putchar(' ');
	PutW(w[ans2], len[ans2]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 524
object Main extends App {
 
  def safeDivide(l: Double, r: Double) = if (l == 0.0) 0.0 else l / r
  def format(x: Double) = {
    val s = (x * 1000).round formatted "%04d"
    s.dropRight(3) + "." + s.takeRight(3)
  }
 
  val sc = new java.util.Scanner(Console.in)
 
  while (sc.hasNextLine()) {
    val line = sc.nextLine()
    val Array(a, b, c, d, e, f) = line.split(' ').map(_.toDouble)
    val x = safeDivide(c*e - b*f, a*e - b*d)
    val y = safeDivide(c - a*x, b)
 
    println(format(x) + " " + format(y))
  }
}


Measured memory_bytes: 45384
use proconio::{input, fastout};

macro_rules! echo {
  ($val:expr) => {
    println!("{}", $val);
  }
}


#[fastout]
fn main() {
  input! {
    n: u64
  };

  let mut ans : u64 = 0;
  for i in 1..=n {
    let mut _ans = 1;
    let k = n / i;
    ans += (1+k) * k / 2 * i;
  }
  echo!(ans);
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
#include <boost/foreach.hpp>
using namespace std;
#define pi 2*asin(1.0)
#define MAX 10000000
#define MOD 1000000007
#define _GLIBCXX_DEBUG
 
vector<long> fac(MAX);
vector<long> finv(MAX);
vector<long> inv(MAX);
vector<long> Primelist;
//template functions
/////////////////////////
void Prinit(){
long PR=10000001;
vector<long> P(PR,0);
for(long i=2;i*i<PR;i++){
    if(P.at(i)==0){
        long j=i;
      j+=i;
        while(j<PR){
            P.at(j)=1;
             j+=i;         
        }
    }
}

for(long i=2;i*i<PR;i++){//Primelist.size()=446
    if(P.at(i)==0){
        Primelist.push_back(i);
    }
}
}

void Cominit(){
  fac.at(0)=fac.at(1)=1;
  finv.at(0)=finv.at(1)=1;
  inv.at(1)=1;
  for(long i=2;i<MAX;i++){
      fac.at(i)=(fac.at(i-1)*i)%MOD;
      inv.at(i)=MOD-inv.at(MOD%i)*(MOD/i)%MOD;
      finv.at(i)=finv.at(i-1)*inv.at(i)%MOD;
  }
}

long facComb(long N,long M){// nCm%
if(N<M) return 0;
if(N<0||M<0) return 0;
return fac.at(N)*(finv.at(M)*finv.at(N-M)%MOD)%MOD;
}

long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}

long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}

long GCM(long A,long B){
            long W,r;
    if(A<B){

        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}

long upDiv(long a,long b){
  return (a+b-1)/b;
}

long strtolong(string str){
istringstream ss;
ss=istringstream(str);
long num;
ss>>num;
return num;
}

long chartolong(char ch){
long num;
num=ch-'0';
return num;
}

string longtostr(long N){
    string str;
    str=to_string(N);
    return str;
}









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


//Answer


int main() {

long N,r,s;
cin>>N;
r=sqrt(N);
for(int i=r;i>0;i--){
    if(N%i==0){
        s=i;
        break;
    }
}
cout<<s+(N/s)-2<<endl;



}


Measured memory_bytes: 237532
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  vll ts(n + 1), vs(n + 1);
  rep(i, n) cin >> ts[i];
  rep(i, n) cin >> vs[i];
  ts[n] = 0;
  vs[n] = 0;

  vll minv(2*20005, 400);
  ll sumt = 0;
  rep(i, n + 1) {
    ll stminv = 2*vs[i] + sumt;
    rep(j, sumt) { chmin(minv[j], stminv - j); }
    rep(j, 2*ts[i] + 1) { chmin(minv[j + sumt], 2*vs[i]); }
    sumt += 2*ts[i];
  }
  ll curv = 0;
  double ans = 0.0;
  repLRE(i, 1, sumt) {
    ll prev = curv;
    if (curv < minv[i])
      curv++;
    else if (curv > minv[i])
      curv--;
    ans += (curv + prev) / 2.0;
  }

  cout << ans/4.0 << endl;

  return 0;
}


Measured memory_bytes: 512
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(string S, ll K) {
  bool allOne = true;
  char c;
  rep(i, K) {
    if (S.at(i) != '1') {
      allOne = false;
      c = S.at(i);
      break;
    }
  }

  if (allOne)
    cout << 1 << endl;
  else
    cout << c << endl;
}

int main() {
  string S;
  cin >> S;
  ll K;
  cin >> K;
  solve(S, K);
  return 0;
}


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

int gcd(int x, int y)
{
  if (x % y) gcd(y % x, x);
  else return y;
}

int main()
{
  ll A, B;
  cin >> A >> B;
  cout << A * B / gcd(A, B) << endl;
  return 0;
}

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

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int C[5];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) {
    string s;
    cin >> s;
    if (s[0] == 'M') C[0]++;
    if (s[0] == 'A') C[1]++;
    if (s[0] == 'R') C[2]++;
    if (s[0] == 'C') C[3]++;
    if (s[0] == 'H') C[4]++;
  }
  long long s = 0;
  rep(a, 5) rep(b, a) rep(c, b) s += 1LL*C[a]*C[b]*C[c];
  cout << s << "\n";
  return 0;
}


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

using namespace std;
const int N = 100;
int a[N],b[N];
int main(){
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	for(int i=1;i<=n;i++){
		if(a[i]-b[i]>0) ans+=(a[i]-b[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
	ll n, t;
	cin >> n >> t;
	vector<ll> x(n);
	rep(i, 0, n)cin >> x[i];
	int ans = 0;
	rep(i, 1, n) {
		ans += min(t, x[i] - x[i - 1]);
	}
	ans += t;
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <unordered_map>
using namespace std;

int main()
{
	int n;
	
	string str;
	//vector<string> str_vec;
	int count=0;

	unordered_map<char, int> my_map;
	unordered_map<char, int> global_map;
	string res;
	for (char c = 'a'; c <= 'z'; c++)
	{
		global_map[c] = 99;
		my_map[c] = 0;
	}

	cin >> n;
	while (cin >> str)
	{
		for (auto& chr : str)
		{
			my_map[chr]++;
		}
		for (auto& entry : my_map)
		{
			if (entry.second < global_map[entry.first])
			{
				global_map[entry.first] = entry.second;
			}
		}
		//str_vec.push_back(str);

		for (char c = 'a'; c <= 'z'; c++)
		{
			my_map[c] = 0;
		}

		count++;
		if (count == n)
			break;
	}
	
	
	for (char c='a';c<='z';++c)
	{
		//cerr << c << " " << global_map[c] << endl;
		res.append(global_map[c], c);
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int T = sc.nextInt();
		int S = sc.nextInt();
		int E = sc.nextInt();
		int W = sc.nextInt();
		int N = sc.nextInt();
		int B = sc.nextInt();
		String[] ss = sc.next().split("");
		for (int i=0; i<ss.length; i++) {
			if (ss[i].equals("N")) {
				int[] temp = {T,S,E,W,N,B};
				T = temp[1];
				N = temp[0];
				B = temp[4];
				S = temp[5];
			}
			else if (ss[i].equals("E")) {
				int[] temp = {T,S,E,W,N,B};
				T = temp[3];
				E = temp[0];
				B = temp[2];
				W = temp[5];
			}
			else if (ss[i].equals("S")) {
				int[] temp = {T,S,E,W,N,B};
				T = temp[4];
				N = temp[5];
				B = temp[1];
				S = temp[0];
			}
			else if (ss[i].equals("W")) {
				int[] temp = {T,S,E,W,N,B};
				T = temp[2];
				E = temp[5];
				B = temp[3];
				W = temp[0];
			}
		}
		System.out.println(T);
	}
}			


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

using namespace std;

int main()
{

    int n;
    cin>>n;
    int arr[n+3];
    long long int x;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        if(i!=0)
        {
            x=x^arr[i];
        }
        else
            x=arr[i];
    }
    for(int i=0;i<n;i++)
    {
        cout<< (x^arr[i]) <<" ";
    }
    cout<<endl;
    return 0;
}


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

int main(void)
{
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> a(101, 0);

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

    int ans1 = 0,ans2 = 0;

    int posi = x;
    while(1)
    {
        if (posi == 0) break;
        posi--;
        ans1 += a[posi];
    }

    posi = x;
    while(1)
    {
        if (posi == n) break;
        posi++;
        ans2 += a[posi];
    }
    cout << min(ans1, ans2) << endl;
    
    return 0;
}


Measured memory_bytes: 3596
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int f(int x) {
		int result = 0;
		for (int i = 1; i <= x; i++) {
			if (x % i == 0) {
				result++;
			}
		}
		return result;
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();

		int ans = 0;
		for (int i = 1; i <= N; i += 2) {
			if (f(i) == 8) {
				ans++;
			}
		}
		out.println(ans);

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            List<int> lstCand = new List<int>();
            for (int i = 0; i < 3; i++) { lstCand.Add(int.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            lstCand.Sort();
            string sOut = "No";
            if (lstCand[0] + lstCand[1] == lstCand[2]) { sOut = "Yes"; }

            // 出力
            Console.WriteLine("{0}", sOut.ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


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

using namespace std;

int main() {
  int n, a[100], tmp;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = i; j > 0; j--) {
      if (a[j] >= a[j - 1]) {
        break;
      } else {
        tmp = a[j];
        a[j] = a[j - 1];
        a[j - 1] = tmp;
      }
    }
    for (int j = 0; j < n; j++) {
      j == n - 1 ? printf("%d\n", a[j]) : printf("%d ", a[j]);
    }
  }
  return 0;
}



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

int main() {
  int N;
  cin >> N;
  
  vector<char> S(N);
  for (int i=0; i<N; i++) {
    cin >> S[i];
  }
  
  int K;
  cin >> K;
  
  char fix = S[K-1];
  
  for (int i=0; i<N; i++) {
    if (S[i] != fix) S[i] = '*';
  }
  
  for (int i=0; i<N; i++) {
    cout << S[i];
    if (i == N-1) cout << endl;
  }
  
}

Measured memory_bytes: 256
<?php
$line = trim(fgets(STDIN));
$arr = explode(" ", $line);

if ($arr[0] == $arr[1]) {
    echo "Draw";
} elseif (($arr[0] == 1) || ($arr[0] > $arr[1] && $arr[1] != 1) ) {
    echo "Alice";
} else {
    echo "Bob";
}

Measured memory_bytes: 3828
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class UnionFindTree
{
    int n;
    vector<int> parent; // 親ノード
    vector<int> rank;   // 木の高さの上限
    vector<int> num;    // グループの要素数
    int find(int x){
        if(parent[x] == x)
            return x;
        return parent[x] = find(parent[x]);
    }
public:
    UnionFindTree(int n0){ // コンストラクタ
        n = n0;
        parent.resize(n);
        for(int i=0; i<n; ++i)
            parent[i] = i;
        rank.assign(n, 0);
        num.assign(n, 1);
    }
    void unite(int x, int y){ // xとyのグループを併合
        if((x = find(x)) != (y = find(y))){
            if(rank[x] < rank[y]){
                parent[x] = y;
                num[y] += num[x];
            }else{
                parent[y] = x;
                if(rank[x] == rank[y])
                    ++ rank[x];
                num[x] += num[y];
            }
            -- n;
        }
    }
    bool same(int x, int y){ // xとyのグループが同じかを調べる
        return find(x) == find(y);
    }
    int getNum(){ // グループの数を返す
        return n;
    }
    int getNum(int x){ // xのグループの要素数を返す
        return num[find(x)];
    }
};

template <size_t T>
bool nextBitset(bitset<T> &bs, int digit)
{
    if(bs.none())
        return false;
    bitset<T> x, y, z;
    x = bs.to_ulong() & (~(bs.to_ulong()) + 1ULL);
    y = bs.to_ulong() + x.to_ulong() + 0ULL;
    z = bs & ~y;
    if(bs[digit-1] && bs == z)
        return false;
    bs = ((z.to_ulong() / x.to_ulong()) >> 1) + 0ULL;
    bs |= y;
    return true;
}

int n, m;
vector<string> name;
vector<bitset<30> > use;

void solve()
{
    for(int i=1; i<=min(5, n); ++i){
        bitset<30> bs((1<<i)-1);
        do{
            UnionFindTree uft(m);
            for(int j=0; j<m; ++j){
                for(int k=0; k<j; ++k){
                    if((use[j] & use[k] & bs).any())
                        uft.unite(j, k);
                }
            }

            if(uft.getNum() == 1){
                cout << i << endl;
                for(int j=0; j<n; ++j){
                    if(bs[j])
                        cout << name[j] << endl;
                }
                return;
            }
        }while(nextBitset(bs, n));
    }

    cout << "Impossible" << endl;
}

int main()
{
    bool isFirst = true;

    for(;;){
        cin >> n >> m;
        if(n == 0)
            return 0;

        name.resize(n);
        map<string, int> index;
        for(int i=0; i<n; ++i){
            cin >> name[i];
            index[name[i]] = i;
        }

        use.assign(m, 0);
        for(int i=0; i<m; ++i){
            int a;
            cin >> a;
            for(int j=0; j<a; ++j){
                string s;
                cin >> s;
                use[i][index[s]] = true;
            }
        }

        if(isFirst)
            isFirst = false;
        else
            cout << endl;

        solve();
    }
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

int main() {
	string s;

	cin >> s;
	string ans;
	for(int i = 0; i < s.size(); i++) {
		ans = ans + "x";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int d,n;
  cin>>d>>n;
  if(d==0){
   cout<<(n+n/100)<<endl;
  }
  else if(d==1){
    cout<<n*100+n/100*100<<endl;
  }
  else{
    cout<<n*10000+n/100*10000<<endl;
  }
}


Measured memory_bytes: 256
import sys
from itertools import combinations, permutations, product, combinations_with_replacement, accumulate
from heapq import heapify, heappop, heappush, heappushpop
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from math import sqrt, log, floor, ceil, factorial, cos, sin, pi#, gcd
from fractions import gcd
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
LINF = 2**63-1
NIL = -LINF
MOD = 10**9+7
MGN = 4
def AST(exp: bool, msg: str = ""): assert exp, msg
def TAST(exp: bool, msg = ""):
    if exp is False: print("TAssertionError:", msg)
    while exp is False:
        pass
def II(): return int(input())
def IF(): return float(input())
def IS(): return input().replace('\n', '')
def ILCI(n: int): return [II() for _ in range(n)]
def ILCF(n: int): return [IF() for _ in range(n)]
def ILI(): return list(map(int, input().split()))
def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)]
def ILF(): return list(map(float, input().split()))
def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)]
def LTOS(lst: list, sep: str = ' '): return sep.join(map(str, lst))
def DEC(lst: list): return list(map(lambda x: x-1, lst))
def INC(lst: list): return list(map(lambda x: x+1, lst))

def z_algo(S: str) -> list:
    N = len(S)
    if N == 0:
        return []
    ln = [0] * N
    ln[0] = N  
    i = 1
    w = 0
    while i < N:
        while i + w < N and S[w] == S[i + w]:
            w += 1
        ln[i] = w  
        if w == 0:
            i += 1
        else:
            j = 1
            while i + j < N and j + ln[j] < w:
                ln[i+j] = ln[j]
                j += 1
            i += j
            w -= j
    return ln

def z_algo_search(S: str, W: str) -> list:
    lens = z_algo(W+S)
    if len(lens) == 0:
        return []
    SL = len(S)
    WL = len(W)
    slens = lens[WL:]
    res = []
    for i in range(SL):
        if slens[i] >= WL:
            res.append(i)
    return res

def xor_next(A: list) -> list:    
    N = len(A)
    res = []
    for i in range(N-1):
        res.append(A[i]^A[i+1])
    
    res.append(A[-1]^A[0])
    return res

def main():
    N = II()
    A = ILI()
    B = ILI()

    C = xor_next(A)
    D = xor_next(B)

    # C の中から D を周期的にを探す
    pos = z_algo_search(C*2, D)
    pos = list(filter(lambda x: x < N, pos))
    
    ans = []
    for i in pos:
        ans.append((i, A[i] ^ B[0]))

    for e in ans:
        print(e[0], e[1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 62552
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <random>
#include <map>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)
#define YN(f) f?cout<<"YES"<<endl:cout<<"NO"<<endl;
#define yn(f) f?cout<<"Yes"<<endl:cout<<"No"<<endl;

int n;
int h[200];
int ans;

signed main(){
	cin>>n;
	rep(i,n)cin>>h[i];
	rep(i,n){
		while(h[i]>0){
			ans++;
			h[i]--;
			for(int j=i+1;j<n;j++){
				if(h[j]>0){
					h[j]--;
				}
				else break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <bitset>
#include <cstring>
#include <vector>
using namespace std;

typedef long long ll;

ll n, m, q, l, a, b, c, d[305][305], g[305][305];

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

    cin >> n >> m >> l;

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
        {
            d[i][j] = 1e15;
            g[i][j] = 1e15;
        }

    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b >> c;
        d[a - 1][b - 1] = c;
        d[b - 1][a - 1] = c;
    }

    for (int i = 0; i < n; ++i)
    {
        d[i][i] = 0;
        g[i][i] = 0;
    }

    for (int k = 0; k < n; ++k)
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                if (d[i][j] > d[i][k] + d[k][j])
                    d[i][j] = d[i][k] + d[k][j];

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            if (d[i][j] <= l)
                g[i][j] = 1;

    for (int k = 0; k < n; ++k)
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                if (g[i][j] > g[i][k] + g[k][j])
                    g[i][j] = g[i][k] + g[k][j];

    cin >> q;
    while (q--)
    {
        cin >> a >> b;
        if (a == b)
            cout << 0 << endl;
        else if (g[a - 1][b - 1] == 1e15)
            cout << -1 << endl;
        else
            cout << g[a - 1][b - 1] - 1 << endl;
    }
    return 0;
}

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

int main() {  
  int64_t H, W;
  
  cin >> H >> W;
  
  int64_t total;
  
  if (W == 1 || H == 1) {
    total = 1;
  }

  else if (W % 2 == 0) {
    total = H * W / 2;
  }
  
  else if (W % 2 != 0 && H % 2 == 0) {
    total = H * W / 2;
  }
  else {
    total = (H * W + 1) / 2;
  } 
  cout << total << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,X; cin>>N>>X;
    vint a(N);
    REP(i,N) cin>>a[i];

    int ans=0;
    if(a[0]>X) ans+=a[0]-X,a[0]=X;
    for(int i=1;i<N;i++){
        if(a[i-1]+a[i]>X){
            ans+=(a[i-1]+a[i])-X;
            a[i]=X-a[i-1];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
/**
 *    author:  math2do
 *    created: 21.04.2020 09:55:21 IST
**/

#include <bits/stdc++.h>

using namespace std;

class Graph {
private:
  int L;
  int R;
  vector <vector <int>> adj;
  vector <int> level;
  vector <int> mate;
  bool levelize();
  bool dfs(int u);

public:
  Graph(int L, int R);    
  void addEdge(int u, int v);
  int matching(); 
};

Graph::Graph(int L, int R) {
  this->L = L;
  this->R = R;
  adj.resize(L + R);
  level.resize(L);
  mate.resize(L + R);
}


void Graph::addEdge(int u, int v) {
  adj[u].push_back(v + L);
  adj[v + L].push_back(u);
}

bool Graph::levelize() {
  queue <int> q;
  for (int u = 0; u < L; u++) {
    level[u] = -1;
    if (mate[u] == -1) {
      level[u] = 0;
      q.push(u);
    }
  }
         
  while (!q.empty()) {
    int u = q.front();
    q.pop();

    for (int w : adj[u]) {
      int v = mate[w];
      if (v == -1) {
        return true;
      }

      if (level[v] == -1) {
        level[v] = level[u] + 1;
        q.push(v);
      } 
    }
  }
  return false;
}

bool Graph::dfs(int u) {
  for (int w : adj[u]) {
    int v = mate[w];
    if (v == -1 || (level[v] == level[u] + 1 && dfs(v))) {
      mate[u] = w;
      mate[w] = u;
      return true;
    }
  }

  return false;
}

int Graph::matching() {
  int match = 0;
  fill(mate.begin(), mate.end(), -1);

  while (levelize()) {
    for (int u = 0; u < L; u++) {
      if (mate[u] == -1 && dfs(u)) {
        match++;
      }
    }
  }
  return match; 
} 

int main() {
  int L, R, E;
  cin >> L >> R >> E;
  int u, v; 
  Graph g(L, R);
  for (int i = 0; i < E; i++) {
    cin >> u >> v;
    g.addEdge(u, v);
  }
  cout << g.matching() << '\n';
  return 0;
} 


Measured memory_bytes: 3240
//#include "pch.h"
#include <iostream>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <string>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;

#define FOR(i, s, e) for(int i=s; i<e; i++)
#define REF(i, s, e) for(int i=s; i>e; i--)
typedef long long ll;

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

	int n;
	double k;
	cin >> n >> k;

	double sum = 0.0;
	FOR(i, 1, n+1) {

		//2^digit>k/iとなるdigit求める
		double tmp = k / i;
		int digit = 0;
		while (tmp > 1) {
			tmp /= 2;
			digit++;
		}
		//cout << digit << endl;

		//出目がiの時の確率計算
		double ans = pow(0.5, digit) / n;
		//cout << "ans: " << ans << endl;
		sum += ans;

	}
	cout << setprecision(15) << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#define REP(i,N) for(int i=0;i<N;++i)
using namespace std;

int main(){
  int N;
  cin>>N;
  vector<int> line(N);
  REP(i, N){
    cin >> line[i];
  }
  vector<int> ans;
  while(!line.empty()){
    int pl = -1;
    for(int i=0;i<line.size();++i){
      if(line[i] == i + 1){
        pl = i;
      }
    }
    if(pl==-1){
      cout << -1 << endl;
      return 0;
    }
    ans.push_back(pl+1);
    line.erase(line.begin() + pl);
  }
  reverse(ans.begin(),ans.end());
  for(int i=0;i<N;++i){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n, k = map(int,input().split())
mod = int(1e9)+7
# print(type(mod))
ans=0
for i in range(k,n+2):
	ans+=((n*i)-(i*(i-1))/2) - (i*(i-1))/2 + 1
	ans=ans%(mod)
print(int(ans))

Measured memory_bytes: 67492
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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


int main(){
    unsigned x; cin >> x;
    cout << bitset<32>(x) << "\n";
    cout << bitset<32>(~x) << "\n";
    cout << bitset<32>(x<<1) << "\n";
    cout << bitset<32>(x>>1) << endl;
    return 0;
}



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

const int M = 100010;

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

    int n, m;
    cin >> n >> m;

    vector<int> G[M];
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        if(a > m) continue;
        G[a].push_back(b);
    }
    
    int ans = 0;
    priority_queue<int> q;
    for(int i = 1; i <= m; i++){
        for(int j = 0; j < G[i].size(); j++){
            q.push(G[i][j]);
        }

        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> city(N, 0);
  
  for (int i = 0; i < M; i++) {
    int in, out;
    cin >> in >> out;
    city.at(in - 1) += 1;
    city.at(out - 1) += 1;
  }
  
  for (int i = 0; i < N; i++) {
    cout << city.at(i) << endl;
  }
}

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

int main() {

    int N,K;
    cin >> N >> K;

    string s[N];
    map<char,int> x;
    for(int i=0; i<N; i++) {
	string s; cin >> s;
	if( x.find(s[0]) == x.end() )
	    x[s[0]] = 1;
	else
	    x[s[0]] ++;
    }
    vector<int> num;
    for(auto e : x)  num.push_back(e.second);

    int ans = 0;
    while(1) {

	sort(num.begin(),num.end());
	reverse(num.begin(),num.end());

	if(num.size() < K or num[K-1] == 0) break;
	ans ++;
	for(int i=0; i<K; i++) num[i]--;
	for(int i=num.size()-1; i>=0; i--) {
	    if(num[i] == 0) num.pop_back();
	    else            break;
	}
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 384