akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  ll N,x;
  ll a[110000];
  ll res=0;
  cin >> N >> x;
  rep(i,N) cin >> a[i];

  rep(i,N-1){
    //printf("%d + %d -> ", a[i], a[i+1]);                                      
    ll b = a[i]+a[i+1];
    if(b>x){
      ll n = min(a[i+1],b-x);
      res += n;
      a[i+1] -= n;
      b = a[i] + a[i+1];
      if(b>x){
        ll m = min(a[i], b-x);
        res += m;
        a[i] -= m;
      }
    }
    //printf("%d + %d\n", a[i], a[i+1]);                                        
  }

  cout << res << endl;
}


Measured memory_bytes: 1024
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// chrono::steady_clock sc;
 //  	auto start = sc.now();
 //  	ifstream cin;
 //  	cin.open("INPUT.txt");

	string S;
	cin>>S;
	int x=0;
	int ans=0;
	for (int i = 0; i < S.length(); ++i)
	{
		if(S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T')
		{
			x++;
		}
		else
		{
			if(ans<x)
			{
				ans=x;
			}
			x=0;
		}
	}
	if(ans<x)
			{
				ans=x;
			}

	cout<<ans<<endl;
	
	// cin.close();
	// auto end = sc.now();
 //   	auto time_span = static_cast<chrono::duration<double>>(end - start);
 //   	cout<<"Operation took: "<<time_span.count()<<" seconds";

	return 0;
}

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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define fastio    ios::sync_with_stdio(0); cin.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  fastio;
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) {
    int x;
    cin >> x;
    a[max(0, i - x)]++;
    if (i + x + 1 < n) a[i + x + 1]--;
  }

  vi p(n);
  partial_sum(all(a), p.begin());

  rep(i, k - 1) {
    vi b(n);
    rep(i, n) {
      b[max(0, i - p[i])]++;
      if (i + p[i] + 1 < n) b[i + p[i] + 1]--;
    }
    
    partial_sum(all(b), p.begin());
    bool ok = true;
    rep(j, n) if (p[j] != n) {
      ok = false;
      break;
    }
    if (ok) break;
  }
  rep(j, n) cout << p[j] << ' ';

  return 0;
}


Measured memory_bytes: 5692
#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
int main()
{
    string s,r;
    cin>>s;
    int n;
    cin>>n;


    for(int i=0;i<s.size();i+=n)
        cout<<s[i];


return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<cstdio>
long long pow10[25];
long long keep[25];
long long way[25][2];
//way[i]: number of pair (a,b) that a-b+offset = i
//0: a[0,9] 1: a[1,9]

void preWork(){
	int offset = 10;
	for(int i = -9; i <= 9; i++) way[i+offset][0] = way[i+offset][1] = 0;
	for(int a = 0; a <= 9; a++){
		for(int b = 0; b <= 9; b++){
			int u = a-b;
			way[u+offset][0]++;
			if(b!=0) way[u+offset][1]++;
		}
	}
	pow10[0] = 1;
	for(int i = 1; i <= 20; i++) pow10[i] = pow10[i-1]*10ll;
}

long long getWay(int n){
	int offset = 10;
	long long res = 1;
	for(int i = n; i >= 1; i--){
		int j = n-i+1;
		if(i<j) break;
		if(i==n) res *= way[keep[i]+offset][1];
		else res *= way[keep[i]+offset][0];
	}
	return res;
}
//reduce the constant
int main(){
	preWork();
	long long d;
	scanf("%lld",&d);
	long long ans = 0;
	for(int bit = 0; bit <= 19; bit++){
		//0 for positive, 1 for neg
		for(int mask = 0; mask < (1<<bit); mask++){
			int u = mask; long long sum = 0;
			//printf("mask = %d\n",mask);
			long long add = 1ll;
			for(int i = 1; i <= bit; i++){
				long long mod = pow10[i], need = d%pow10[i];
				int s = 0, t = 9;
				if(u%2) s = -9, t = -1;
				u /= 2;
				long long find = -111;
				for(long long j = s; j <= t; j++){
					long long left = (j*pow10[i-1]%mod+sum%mod)%mod; if(left<0) left += mod;
					if(left==need){
						find = j;
						break;
					}
				}
				if(find==-111){
					 add = 0;
					 break;
				 }
				else{
					keep[i] = find;
					sum += find*pow10[i-1];
					int j = bit-i+1;
					if(i>=j){
						if(keep[i]+keep[j]!=0){
							add = 0;
							break;
						} 
						else{
							int offset = 10;
							if(i==bit) add *= way[keep[i]+offset][1];
							else add *= way[keep[i]+offset][0];
						}
					}
				}
			}
			if(sum!=d) add = 0;
			ans += add;
		}
		//printf("ans = %lld\n",ans);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1740
#include <stdio.h>
#include <stdlib.h>

#define N 100000
#define DIGIT 1000000000

typedef struct wide_int{
	int x1;
	int x2;
}wint;

wint add_wint(wint a, wint b){
	int carry=0, bias=0;
	wint r;

	if(a.x2 + b.x2 >= DIGIT){
		carry += 1;
		bias = DIGIT;
	}
	r.x1 = a.x1 + b.x1 + carry;
	r.x2 = a.x2 + b.x2 - bias;

	return r;
}

wint to_wint(int a){
	wint r;
	
	r.x1 = a/DIGIT;
	r.x2 = a%DIGIT;

	return r;
}

print_wint(wint a){
	if(a.x1 == 0) printf("%d\n", a.x2);
	else printf("%d%09d\n", a.x1, a.x2);
}

int main(void){
	int n, x;
	int a[N], b[N];
	int i;
	wint r;

	r.x1=0;
	r.x2=0;
	scanf("%d %d", &n, &x);
	for(i=0; i<n; i++){
		scanf("%d", &(a[i]));
		b[i] = a[i];
	}
	if(b[0] > x) b[0] = x;
	for(i=1; i<n; i++){
		if(b[i-1]+b[i] > x) b[i] = x-b[i-1];
	}
	for(i=0; i<n; i++){
		r = add_wint(r, to_wint(a[i]-b[i]));
	}

	/*for(i=0; i<n; i++){
		printf("%d ", b[i]);
		} */
	printf("\n");
	print_wint(r);
	


	return 0;
}

Measured memory_bytes: 896
package main

import(
	"fmt"
)

func main(){
	var a,b,c int
	fmt.Scan(&a, &b, &c)
	var ans int = 0
	var ab int 
	if a < b{
		ans += a
		ab = b
	} else{
		ans += b
		ab = a
	}
	if ab>c{
		ans += c
	}else{
		ans += ab
	}
	fmt.Println(ans)

}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <functional>
#include <time.h>

using namespace std;


int main() {
	
	int n = 0, k = 0;

	cin >> n >> k;
	vector<int> h(n);

	int count = 0;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if (h[i] < k){}
		else { count += 1; }
	}

	cout << count << endl;



}



Measured memory_bytes: 640
S = list(input())
f1 = 1
f2 = 1
A = int(''.join(S[:2]))
B = int(''.join(S[2:]))
if A >= 13 or A == 0:
    f1 = 0
if B >= 13 or B == 0:
    f2 = 0
if f1 == 1 and f2 == 1:
    print('AMBIGUOUS')
elif f1 == 1 and f2 == 0:
    print('MMYY')
elif f1 == 0 and f2 == 1:
    print('YYMM')
else:
    print('NA')

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


int main(){
    string S;
    cin>>S;
    if(S.at(S.size()-1)=='s'){
        S+="es";
    }else{
        S+='s';
    }
    cout<<S;
    return 0;
}


Measured memory_bytes: 3632
K = gets.chop.to_i

$hash = {}

def gcb(a, b)
  return a if b == 0
  gcb(b, a % b)
end

# def hoge(a, b, c)
#   arr = [a, b, c].sort!.map(&:to_s).join('-')
#   if $hash[arr]
#     return $hash[arr]
#   else
#     x = gcb(a, b)
#     y = gcb(x, c)
#     $hash[arr] = y
#     return y
#   end
# end

def hoge(a, b, c)
  x = gcb(a, b)
  y = gcb(x, c)

  return y
end

ans = []

(1..K).each do |i|
  (i..K).each do |j|
    (j..K).each do |k|
      if i == j && j == k && i == k
        ans.push(hoge(i, j, k))
      elsif i == j || j == k || i == k
        ans.push(hoge(i, j, k) * 3)
      else
        ans.push(hoge(i, j, k) * 6)
      end
    end
  end
end

puts ans.inject(:+)


Measured memory_bytes: 24968
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
#define dbg(vec) for (size_t _ = 0; _ < vec.size(); ++_){std::cerr << #vec << "[" << _ << "] : " << vec[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

const double pi = 3.141592653589793;
vector<double> x(101), y(101);
int n; 

inline double naiseki(const double& x1, const double& y1, const double& x2, const double& y2) {
  return x1 * x2 + y1 * y2;
}

// 角度 theta の方向を最終的に向くとして計算
// theta は radian
double calc(const double& theta) {
  double res = 0.0;
  double dx = cos(theta), dy = sin(theta);
  for (int i = 0; i < n; ++i) {
    res += max(0.0, naiseki(dx, dy, x[i], y[i]));
  }
  return res;
}

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

  auto start = chrono::system_clock::now();

  cin >> n;
  rep(i, n) cin >> x[i] >> y[i];

  int step = 7777777;

  double ans = 0.0;
  /*
  for (int i = 0; i < step; ++i) {
    double theta = 2.0 * pi * i / step;
    chmax(ans, calc(theta));
  }
  */
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> r(0, step);

  auto msec = 0.0;

  do {
    double theta = 2.0 * pi * r(mt) / step;
    chmax(ans, calc(theta));
    auto end = chrono::system_clock::now();
    auto dur = end - start;
    msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
  } while (msec <= 1950);

  cout << setprecision(15) << ans << '\n';

  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define prime 1000000007
#define INF 4000000000000000000
int dx8[8]={-1,0,1,1,1,0,-1,-1};
int dy8[8]={1,1,1,0,-1,-1,-1,0};
int dx4[4]={-1,0,1,0};
int dy4[4]={0,-1,0,1};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int uni[100010];
int root(int a){
    if(uni[a]<0)return a;
    return uni[a]=root(uni[a]); 
}
bool connect(int a,int b){
    a=root(a);
    b=root(b);
    if(a==b)return false;
    if(uni[a]>uni[b]){
        swap(a,b);
    }
    uni[a]=uni[a]+uni[b];
    uni[b]=a;
    return true;
}
int mod_pow(int x,int n,int mod){
    int res=1;
    while(n>0){
        if(n&1)res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}
signed main(void){
    int n;cin>>n;
    int V[n],V0[n];
    rep(i,n){
        cin>>V[i];
        V0[i]=V[i];
    }
    map<int,int>Lcm;
    rep(i,n){
        //素因数分解
        map<int,int>M;
        for(int j=2;j<=sqrt(V[i]);j++){
            if(V[i]%j==0){
                int count=0;
                while(V[i]%j==0){
                    count++;
                    V[i]/=j;
                }
                M[j]=count;
            }
        }
        if(V[i]>1)M[V[i]]++;
        map<int,int>::iterator ite;;
        for(ite=M.begin();ite!=M.end();ite++){
            P p=*ite;
            Lcm[p.F]=max(Lcm[p.F],p.S);
        }
    }
    int lcm=1;
    map<int,int>::iterator ite;;
    for(ite=Lcm.begin();ite!=Lcm.end();ite++){
        P p=*ite;
        lcm=(lcm*mod_pow(p.F,p.S,prime))%prime;
    }
    //cout<<lcm<<endl;
    int ans=0;
    rep(i,n){
        ans=(ans+lcm*mod_pow(V0[i],prime-2,prime)%prime)%prime;
    }
    cout<<ans<<endl;
    
    
}
        


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()

	N := readInt()
	K := readInt()
	L := readInt()

	p := make([]int, K)
	q := make([]int, K)
	xu := NewUnionFind(N)
	for i := range p {
		p[i] = readInt() - 1
		q[i] = readInt() - 1
		xu.Union(p[i], q[i])
	}

	r := make([]int, L)
	s := make([]int, L)
	yu := NewUnionFind(N)
	for i := range r {
		r[i] = readInt() - 1
		s[i] = readInt() - 1
		yu.Union(r[i], s[i])
	}

	m := make(map[int]map[int]int)
	for i := 0; i < N; i++ {
		x := xu.Find(i)
		y := yu.Find(i)
		if m[x] == nil {
			m[x] = make(map[int]int)
		}
		m[x][y]++
	}
	sp := ""
	for i := 0; i < N; i++ {
		x := xu.Find(i)
		y := yu.Find(i)
		printf("%s%d", sp, m[x][y])
		sp = " "
	}
	println()

}

// -----------------------------------------------------------------------------

type UnionFind struct {
	parent []int
	rank   []int
	size   []int
}

// Initialize UnionFind for [0 - n) elements.
// Use n+1 if you need [1 - n] elements
func NewUnionFind(n int) *UnionFind {
	u := &UnionFind{
		parent: make([]int, n),
		rank:   make([]int, n),
		size:   make([]int, n),
	}

	for i := range u.parent {
		u.parent[i] = i
		u.rank[i] = 0
		u.size[i] = 1
	}

	return u
}

func (u *UnionFind) Find(i int) int {
	if u.parent[i] == i {
		return i
	}
	p := u.Find(u.parent[i])
	u.parent[i] = p
	return p
}

func (u *UnionFind) Union(i, j int) {
	p := u.Find(i)
	q := u.Find(j)

	if p == q {
		return
	}

	if u.rank[p] < u.rank[q] {
		p, q = q, p
	}
	u.parent[p] = q
	if u.rank[p] == u.rank[q] {
		u.rank[q]++
	}
	u.size[q] += u.size[p]
}

func (u *UnionFind) Size(i int) int {
	p := u.Find(i)
	return u.size[p]
}


Measured memory_bytes: 60288
let scan_words () = Scanf.scanf "%d %d\n" (fun x y -> (x, y))

let n, k = scan_words ()

let ar = Array.make 100001 0

let () =
  for i = 1 to n do 
    let a, b = scan_words () in 
    ar.(a) <- (ar.(a) + b) ;
  done ;
  let rec f i tmp =
    let new_tmp = tmp - ar.(i) in 
    if new_tmp <= 0 then i else f (i + 1) new_tmp
  in f 0 k |> Printf.printf "%d\n"

Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e6 + 3;
const double EPS = 1e-10;

ll fac[MOD],finv[MOD],inv[MOD];

void init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MOD; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

int pow(ll x,ll k){
    int res = 1;
    ll y = x;
    while(k){
        if(k & 1) res = (res * y) % MOD;
        y = (y * y) % MOD;
        k >>= 1;
    }
    return res;
}


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int q,x,d,n;
    init();
    cin >> q;
    REP(i,q){
        cin >> x >> d >> n;
        ll ans;
        if(d==0){
            cout << pow(x,n) % MOD << '\n'; continue;
        }

        ll y = x * inv[d] % MOD;
        if(y == 0 || y + n - 1 >= MOD){ // product % MOD == 0
            cout << 0 << '\n'; continue;
        }

        ans = fac[y+n-1] * finv[y-1] % MOD * pow(d,n) % MOD;
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 24320
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
#include <stack>
//#include <atcoder/scc>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
//using namespace atcoder;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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;
    }
}

lli gcd2(lli x, lli y)
{
    lli t;
    while (y != 0)
        t = x % y, x = y, y = t;
    return (x);
}

lli lcm2(lli x, lli y)
{
    lli xy = x * y;
    if (xy < 0)
        xy = -xy;
    return (xy / gcd2(x, y));
}
lli m = 1e9 + 7;
int main(void)
{
    int N;
    cin >> N;
    vector<int> a;
    int tmp;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int A = 0;
    int B = 0;
    for (int i = 0; i < N; i++)
    {
        if (i % 2 == 0)
        {
            A += a[i];
        }
        else
        {
            B += a[i];
        }
    }
    cout << A - B << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<assert.h>

#define max(a,b) ((a)>(b))?(a):(b)
#define min(a,b) ((a)>(b))?(b):(a)

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b)
{
	if (a % b) { return gcd(b, a % b); }
	return b;
}

int main(void)
{
	ll a, b;
	scanf("%lld%lld", &a, &b);
	a = gcd(a, b);

	ll n = 3;
	int pre = 0, cnt = 0;
	ll sqrt_a = sqrt(a);

	while (!(a % 2))
	{
		a /= 2;
		pre = 2;
	}
	while (a != 1)
	{
		if (!(a % n))
		{
			a /= n;
			if (pre && pre != n)
			{
				cnt++;
			}
			pre = n;
		}
		else
		{
			n += 2;
			if (n > sqrt_a)
			{
				n = a;
			}
		}
	}
	if (pre)cnt++;

	printf("%d", cnt + 1);
}

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

vector<vector<int>> R(100000);
vector<bool> Gr(100000, false);

bool dfs(int x) {
	if (Gr[x])
		return false;
	Gr[x] = true;
	for (int j = 0;j < R[x].size();j++)
		dfs(R[x][j]);
	return true;
}

int main() {
	int N, M;
	cin >> N >> M;
	int x, y, z;
	for (int i = 0;i < M;i++) {
		cin >> x >> y >> z;
		x--; y--;
		R[x].push_back(y);
		R[y].push_back(x);
	}
	int cnt = 0;
	for (int i = 0;i < N;i++) {
		if (dfs(i))
			cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 8832
def main():
    n, *abc = map(int, open(0).read().split())
    x, y, z = 0, 0, 0
    for (a, b, c) in zip(*[iter(abc)] * 3):
        x, y, z = a + max(y, z), b + max(z, x), c + max(x, y)

    ans = max([x, y, z])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 35636
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n,k,q;cin>>n>>k>>q;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> que;
    rep(i,n) que.push(make_pair(a[i],i));


    ll ans=LINF;
    vector<bool> check(n,true);
    bool f=false;
    while(!que.empty()){
        if(f){
            auto P=que.top();que.pop();
            ll num=P.first;
            while(!que.empty() and que.top().first==num) que.pop();
            rep(i,n)if(a[i]==num)check[i]=false;
        }
        else{
            f=true;
        }
        vector<ll> v;
        int idx=0;
        while(idx<n){
            while(idx<n and !check[idx]){
                idx++;
            }
            priority_queue<ll,vector<ll>,greater<ll>> minq;
            while(idx<n and check[idx]){
                minq.push(a[idx]);
                idx++;
            }
            while(minq.size()>=k){
                v.push_back(minq.top());minq.pop();
            }
        }
        if(v.size()<q) break;
        sort(ALL(v));
        chmin(ans,v[q-1]-v[0]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int main()
{
  int n;
  cin >> n;
  int 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};
  cout << a[n  - 1]<< endl;
}


Measured memory_bytes: 256
while True:
    data=[]
    n=int(input())
    if n==0:break
    for i in range(n):
        a=list(map(int,input().split(' ')))
        a.append(sum(a))
        data.append(a)
    a=[]
    for i in range(n+1):
        a.append(sum(x[i] for x in data))
    data.append(a)
    for i in range(n+1):
        for j in range(n+1):
            print('{:5}'.format(data[i][j]),end='')
        print('')
                  

Measured memory_bytes: 6720
#include <complex>
#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;
typedef complex<double> xy_t;
double dot_product(xy_t a, xy_t b);
double cross_product(xy_t a, xy_t b);
xy_t P[110];

int main(){
  int N = 0;
  double x,y;
  while(~scanf("%lf,%lf", &x, &y)){
    P[N++] = xy_t(x,y);
  }
  double sum = 0;
  for (int i=0; i+2<N; ++i){
    xy_t a=P[0], b=P[i+1], c=P[i+2];
    sum += cross_product(b-a, c-a)/2;
  }
  printf("%.6f\n", abs(sum));
}



double dot_product(xy_t a, xy_t b){
  return (conj(a)*b).real();
}
double cross_product(xy_t a, xy_t b){
  return (conj(a)*b).imag();
}

Measured memory_bytes: 1244
using System;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            if (a < b)
                Console.WriteLine("a < b");
            else if(a > b)
                Console.WriteLine("a > b");
            else
                Console.WriteLine("a == b");

        }
    }
}

Measured memory_bytes: 8932
#include <iostream>
using namespace std;
int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A*B > C*D)
		cout << A*B << endl;
	else if (A*B < C*D)
		cout << C*D << endl;
	else if (A*B == C*D)
		cout << A*B << endl;
	return 0;
}



Measured memory_bytes: 256
//Never stop chasing!-MdSourav.
#include <bits/stdc++.h>
#define ll long long int
#define l long int
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;

int main()
{
        int ara[200000]={0},sh[200000];
        int i,j=1,k,a,b,s=0;
        cin>>a;
        for(i=0;i<a-1;i++)
        {
            cin>>sh[i];
            ara[sh[i]]++;
            if(sh[i]>s)
                s=sh[i];
        }
        for(i=1;i<=s;i++)
        {
           cout<<ara[i]<<endl;
        }
        b=a-s;
        for(i=0;i<b;i++)
        {
            cout<<"0"<<endl;
        }
        return 0;
}

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

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REP1(i, n) for(ll i = 1;i < n;i++)
#define ll long long
#define MOD 1000000007

int a,b,c;

int main(){
  int ans=0;
  vector<int> ar(3);
  cin >> ar[0] >> ar[1]>>ar[2];
  sort(ar.begin(), ar.end());
  
  cout<<(ar[0]+ar[1])<<endl;
  return 0;
}

Measured memory_bytes: 380
#include <stdio.h>
int main(void){
    // Your code here!
    char x[128];
    int s=0,i=0;
    scanf("%s",x);
    
    while(x[i]){
        if(x[i]=='+'){
            s++;
        }
        else{
            s--;
        }
        i++;
    }
    printf("%d",s);
    return 0;
}



Measured memory_bytes: 128
import numpy as np

n=int(input())
a=list(int(x) for x in input().split())
bou_length=0
l=[]
for i in range(len(a)):
  bou_length += a[i]
  l.append(bou_length)
#print(bou_length)
#print(l)

def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    list: データ配列
    num: 対象値
    return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

diff=getNearestValue(l, (bou_length/2))
#print(diff)
print(abs(l[-1]-2*diff))

Measured memory_bytes: 34208
#include<bits/stdc++.h>
using namespace std;
long long ans = INT64_MAX;
long long dif(long long a, long long b, long long c) {
    return max(a, max(b, c))-min(a, min(b, c));
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long H, W;
    cin >> H >> W;
    long long A, B, C;
    for (int i = 0; i < 2; i++, swap(H, W)) {
        if (H%3 == 0) ans = 0;
        else {
            ans = min(ans, W);
            if (H%3 == 1) {
                A = (H/3)*W;
                B = (H/3*2+1)*(W/2+W%2);
                C = (H/3*2+1)*(W/2);
                ans = min(ans, dif(A, B, C));
                A = (H/3+1)*W;
                B = (H/3*2)*(W/2+W%2);
                C = (H/3*2)*(W/2);
                ans = min(ans, dif(A, B, C));
            } else {
                A = (H/3+1)*W;
                B = (H/3*2+1)*(W/2+W%2);
                C = (H/3*2+1)*(W/2);
                ans = min(ans, dif(A, B, C));
                A = (H/3)*W;
                B = (H/3*2+2)*(W/2+W%2);
                C = (H/3*2+2)*(W/2);
                ans = min(ans, dif(A, B, C));
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val line = readLine()!!.trim()
    val (n, k) = line.split(" ").map { it.toInt() }
    val line2 = readLine()!!.trim()
    val prices = line2.split(" ").map { it.toInt() }.take(n)

    val sortedPrices = prices.sortedBy {it}

    val price: Int = sortedPrices.take(k).sum()

    println("${price}")
}


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


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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        String s = scanner.next();
        StringBuilder sb = new StringBuilder();
        for (int i=1;i<=s.length();i++) {

        	if(i%2==1) {
        		sb.append(s.substring(i-1, i));
        	}
        }
        System.out.println(sb.toString());

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 28244
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    stack<int> S1;
    stack<pair<int, int>> S2;
    char ch;
    int sum=0;
    for(int i =0; cin>>ch; i++){
        if(ch=='\\') S1.push(i);
        else if(ch =='/' && S1.size()>0){
            int j = S1.top(); S1.pop();
            sum += i - j;
            int a = i - j;
            while(S2.size() >0 && S2.top().first >j ){
                a+= S2.top().second; S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }

    vector<int> ans;
    while(S2.size()>0){ans.push_back(S2.top().second); S2.pop();}
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for(int i =0; i < (int)ans.size(); i++){
        cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 3224
#coding:utf-8
from __future__ import division,print_function
try:
    input = raw_input
except NameError:
    pass
# 上記のコードはPython2とPython3の違いを一部吸収するためのもの
memo=[0]*31
def solve(x):
    if memo[x]==0:
        if x>0:
            memo[x]=solve(x-1)+solve(x-2)+solve(x-3)
            return memo[x]
        elif x==0:
            memo[x]=1
            return 1
        else:
            return 0
    else:
        return memo[x]

def main():
    while True:
        inp=int(input())
        if inp==0:
            break
        print((solve(inp)-1)//3650+1)

main()

Measured memory_bytes: 4228
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
//~ #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")
#include<bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(0)cout
#endif

const int maxn = (1e6)+7;
const int maxk = 20;
const int inf = (1e9)+7;
const LL LLinf = (1e18)+7;
const LD eps = 1e-9;
const LL mod = 1e9+7;

// ***************************** CODE ***************************** //

LL res = 0LL;
map<pair<string, int> , LL > mapa;

int main()
{
      _upgrade
      int n;
      cin>>n;
      string s;
      cin>>s;
      for(int i = 0 ;i < (1<<n);i++)
      {
      	string a, b;
      	for(int j = 0;j < n;j++)
      		if((1<<j) & i)
      			a.pb(s[j]);
      		else
      			b.pb(s[j]);
      	reverse(all(b));
      	a += b;
     	 	mapa[{a, SZ(b)}]++;
      }
      for(int i = 0 ;i < (1<<n);i++)
      {
      	string a, b;
      	for(int j = 0;j < n;j++)
      		if((1<<j) & i)
      			a.pb(s[j + n]);
      		else
      			b.pb(s[j + n]);
      	reverse(all(b));
      	a = b + a;
 		res += mapa[{a, n - SZ(b)}];
      }
      cout<<res;

      return 0;
}

Measured memory_bytes: 68224
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef long double ld;
const ld pi = 4*atan((ld)1);
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll nax = 0;

ll n;

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



Measured memory_bytes: 3652
M, K = gets.split.map(&:to_i)
if K >= 2**M
  puts -1
  exit
end
if M == 1
  if K == 0
    puts "0 0 1 1"
  else
    puts -1
  end
  exit
end
ans = []
for i in 0..2**M-1
  if i != K
    ans << i
  end
end
ans << K
for j in 1..2**M
  i = 2**M - j
  if i != K
    ans << i
  end
end
ans << K
puts ans

Measured memory_bytes: 16644
// Last Change:       11/29/2018 23:05:33.
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <list>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N, K, x[100005];
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }

  int ans = 1000000000, left, right;

  for (int i = 0; i <= N - K; i++) {
    right = x[i + K - 1];
    left = x[i];
    ans = min(ans, abs(left) + abs(right - left));
    ans = min(ans, abs(right) + abs(right - left));
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;

//0からpまでのxorsum
ll xs(ll p){
	ll ans=0;
	if(p%4==1||p%4==2)ans+=1;
	rep1(i,40){
		ll c=exp2(i);
		ll rm=p%(c*2);
		if(rm>=c&& rm%2==0 )ans+=c;
	}
	return ans;
}

int main(){
	ll a,b;
	cin>>a>>b;
	if(a==0)cout<<xs(b);
	else{
		ll g=xs(a-1);
		ll h=xs(b);
		ll f= g ^ h;
		cout<<f;
	}
}

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

int main(){
  int h, w;
  cin >> h >> w;
  
  vector<char> a(h*w,0), b((h+2) * (w+2),'#');
  for(int i = 0; i < h*w; i++)
    cin >> a.at(i);
  for(int i = 0;i<h;i++){
    for(int j = 0; j < w; j++)
      b.at((i+1)*(w+2)+j+1) = a.at(i*w+j);
  }
  
  for(int i = 0; i < h+2; i++){
    for(int j = 0; j < w+2; j++)
      cout << b.at(j + i*(w+2));
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
	llong N;
	cin >> N;
	llong M = N;
	llong S = 0;
	while(true){
		if(N>9){
			S += N%10;
			N /= 10;
		}else{
			S += N;
			break;
		}
	}
	if(M%S==0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

const int M = 8000000;

int main() {
    int n, m;
    bitset<M> ok;
    while(cin >> m >> n, n){
        ok.reset();
        for (int i = m, cnt = 0; cnt < n; ++i) {
            if(ok[i]) continue;
            cnt++;
            for (int j = i; j < M; j += i) {
                ok.set(j);
            }
        }
        for (int i = m; i < M; ++i) {
            if(!ok[i]) {
                cout << i << "\n";
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4044
T = input()
N = len(T)
hatena = T.count("?")
t = list(T)
for i in range(0,N) :
    if t[i] == "?" :
        t[i] = "D"
        hatena = hatena - 1
        if hatena == 0 :
            break


print(''.join(t))


    

Measured memory_bytes: 10844
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys


A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for a in range(51):
  for b in range(51):
    if (X - a*500 - b*100) % 50 > 0 or a > A or b > B:
      continue
    else:
      c = (X - a*500 - b*100) // 50
      if c >= 0 and c <= C:
        ans += 1

print(ans)

Measured memory_bytes: 39024
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        int[] ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        Console.WriteLine(Math.Max(ab[0] + ab[1], Math.Max(ab[0] - ab[1], ab[0] * ab[1])));
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

ll get(ll n, ll dig, bool mn){
	string s = to_string(n);
	ll t = dig - s.size();
	rep(i,t) s.push_back('0');
	if(mn) sort(all(s));
	else sort(rall(s));
	return stoi(s);
}

int main(){
	while(1){
		ll n,m; cin >> n >> m;
		if(!n && !m) break;
		ll sum = 0;
		vpl v(n);
		rep(i,n) cin >> v[i].second >> v[i].first, sum += v[i].second * v[i].first;
		sort(rall(v));
		rep(i,n){
			sum -= v[i].first * min(v[i].second,m);
			m -= min(v[i].second,m);
		}
		cout << sum << endl;
	}
}


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

/*
xとyは対称なので、xを動かしてからyを動かして検証していけばよい？
ナイーブにやると、(1, 1), (2, 1) ... (N, 1)を検証していく。
しかしNが大きい可能性があるので間に合わない。

xとyの対称性に注目すると、
xはsqrt(N)までを調べればよいこれなら十分まにあう
*/


int main() {
    long N;
    cin >> N;

    long minv = 1e12;
    for (long x = 1; x <= ceil(sqrt(N)+0.5); x++)
    {
        if (N % x == 0)
        {
            long y = N / x;
            minv = min(minv, (x - 1) + (y - 1));
        }

        
    }

    cout << minv << endl;
}

Measured memory_bytes: 3660
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;
int s[100005];
int main()
{
	int a,b,c,i,j,k,n;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&s[i]);
	}
	k=0;
	if(n==1)
		printf("Yes\n");
	else
	{
		for(i=1;i<=n;i++)
		{
			if(s[i]<k)
				{printf("No\n");break;}
			if(i!=n&&s[i]>s[i+1]+1)
				{printf("No\n");break;}
			else
					s[i]=s[i]-1;
			k=max(k,s[i]);

		}
		if(i==n+1)
            printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
 
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();
 
    long lcm = (C * D) / gcd(D, C);
    
    System.out.println(count(B, C, D, lcm) - count(A-1, C, D, lcm));
  }
  
  private static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a%b);
  }
  
  private static long count(long n, long C, long D, long lcm) {
    return n - n/C - n/D + n/lcm;
  }
}

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

const int mod = 1e9+7;


int a,b,c;
signed main(){
  cin>>a>>b>>c;
  int ans=abs(b-c)-a;
  if(ans<0)ans=0;
  cout<<ans<<endl;

  return 0;
}


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

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

	int n;

	cin >> n;

	if(n%2==0)
	{
		cout << n << '\n';
	}
	else
	{
		cout << 2*n << '\n';
	}
	
	return 0;	
}

Measured memory_bytes: 256
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}

int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("in.txt",  "r",  stdin);
        freopen("out.txt", "w", stdout);
    #endif
//*/

        

        
    int n;
    cin>>n;

    int i = 1;

    for(; i*i < n; i++)
    {
        if(n%i == 0 && i >= 1 && i <= 9 && n/i >= 1 && n/i <= 9)
        {
            cout<<"Yes";
            return 0;
        }
    }

    if(i >= 1 && n/i <= 9 && i*i == n) cout<<"Yes";
    else cout<<"No";









    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	long long s, c; cin >> s >> c;
	if (s * 2 >= c)cout << (c - c % 2) / 2 << endl;
	else cout << s + ((c - s * 2) - (c - s * 2) % 4) / 4 << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    stack = []
    for i in range(N):
        if not stack:
            stack.append(S[i])
            continue

        if S[i] == "(":
            stack.append(S[i])
        else: ## )
            if stack[-1] == "(":
                stack.pop()
            else:
                stack.append(S[i])
    right_count = stack.count('(')
    left_count = stack.count(')')

    answer = '('*left_count+S+')'*right_count
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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;}

const ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  int K, X; cin >> K >> X;
  if (500 * K >= X) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int H,W;
	int x,y;
	while(1){
		scanf("%d%d",&H,&W);
		if(H==0 || W==0){break;}
		for(x=0;x<H;x++){
			for(y=0;y<W;y++){
				if((x+y)%2==0){
					printf("#");
				}
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringJoiner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            String[] arr = br.readLine().split(" ");
            int r = Integer.parseInt(arr[0]), c = Integer.parseInt(arr[1]);
            int[][] table = new int[r+1][c+1];
            int[] lastRow = new int[c+1];
            int total = 0;
            
            for(int i=0; i<r; i++){
                String[] a = br.readLine().split(" ");
                for(int j=0; j<a.length; j++){
                    table[i][j] = Integer.parseInt(a[j]);
                }
            }
            
            for(int row=0; row<r; row++){
                int tmp = 0;
                for(int col=0; col<c; col++){
                    tmp += table[row][col];
                    lastRow[col] += table[row][col];
                }
                table[row][c] = tmp;
                total += tmp;
            }
            lastRow[c] = total;
            table[r] = lastRow;
            
            for(int i=0; i<=r; i++){
                StringJoiner sj = new StringJoiner(" ");
                Arrays.stream(table[i]).forEach(d -> sj.add(String.valueOf(d)));
                System.out.println(sj.toString());
            }
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 32168