akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
    int k;
    cin >> k;
    int a,b;
    if(k%2==1){
        a=k/2+1;
        b=k/2;
    }
    else{
        a=k/2;
        b=k/2;
    }
    cout << a*b << endl;
}

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


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

std::vector<int> CutByDigit8(int num)
{
	int exp10 = 1;

	std::vector<int> CuttedNumbers;

	for(int i=0; i<8; ++i)
	{
		CuttedNumbers.push_back((num%(exp10*10))/exp10);

		exp10 *= 10;
	}

	return CuttedNumbers;
}

int ComposeByDigit8(std::vector<int> v)
{
	int ComposedNum = 0;

	int exp10 = 1;

	for(size_t i=0; i<v.size(); ++i)
	{
		ComposedNum += v[i]*exp10;

		exp10 *= 10;
	}

	return ComposedNum;
}

void PrintVector(std::vector<int> v)
{
	std::for_each(v.begin(),v.end(),[](int n){std::cout << n << ' ';});

	std::cout << '\n';
}


int main()
{
	int n;

	std::cin >> n;

	int num;

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

		std::vector<int> max,min;

		max = CutByDigit8(num);

		std::sort(max.begin(),max.end());

		min = max;

		std::reverse(min.begin(),min.end());

		int resultMax = ComposeByDigit8(max); 
			
		int	resultMin = ComposeByDigit8(min);

		std::cout  << resultMax-resultMin << '\n';
	}

}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <string>

typedef long long ll;
using namespace std;

int n;

int main()
{
    cin >> n;
    ll ans = 1;
    int a[1001] = {0};

    for(int i = 2; i <= n; i++){ //n!
        int s = i, t = 2;
        while(s != 1){ //素因数分解
            while(s % t == 0){
                a[t]++; //各数字の何乗かを格納
                s /= t;
            }
            t++;
        }
    }
    for (int i = 2; i <= 997; i++){
        ans = ans * (a[i] + 1) % (ll)(1e9 + 7); //(n+1)(m+1)...%(1e9+7)
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  int S = 0;
  int tmp = N;

  while(tmp!=0){
    S += tmp % 10;
    tmp /= 10;
  }

  if(N%S==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif
#define FILE_IO freopen("input.txt","r",stdin);
#define f first
#define int long long
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
vector<char> v={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
void solve(){
   set<char> a;
   string s;
   cin>>s;
   for(auto it:s)a.insert(it);
   if((int)a.size()==26){cout<<"None";return;}
   for(auto it:v){
    if(s.find(it)==string::npos){
        cout<<it;
        break;
    }
   }
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
    IOS;
    solve();
    #ifdef LOCAL_DEFINE
    cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
    #endif
}


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

int main(){
  int h,w;
  cin >> h >> w ;

  vector<vector<char>> s(h+2,vector<char> (w+2));

  for (int i = 0; i < h+2; i++)
  {
    for (int j = 0; j < w+2; j++)
    {
      if(i==0||i==h+1){
        s[i][j] = '.';
      }
      else{
        if(j==0||j==w+1){
          s[i][j] = '.';
        }
        else cin >> s[i][j];
      }
    }  
  }
  int flg=0;
  for (int i = 1; i <= h; i++)
  {
    for (int j = 1; j <= w; j++)
    {
      if(s[i][j]=='#' && s[i-1][j]=='.' && s[i][j+1]=='.' && s[i+1][j]=='.' && s[i][j-1]=='.') flg=1;
    }
  }

  if(flg) cout << "No" << endl;
  else cout << "Yes" << endl;  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int h, w; cin >> h >> w;
	vector<vector<int>> c(10, vector<int>(10));
	rep(i, 0, 9)rep(j, 0, 9)cin >> c[i][j];
	rep(k, 0, 9)rep(i, 0, 9)rep(j, 0, 9)
	{
		c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
	}
	int ans = 0;
	rep(i, 0, h - 1)rep(j, 0, w - 1)
	{
		int a; cin >> a;
		if (a == -1)continue;

		ans += c[a][1];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    *a, = map(int, input().split())

    mi = 200 ** 2 * 100
    for y in range(-100, 100 + 1):
        t = 0
        for x in a:
            t += (x - y) ** 2
        mi = min(mi, t)

    print(mi)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 2940
#!/usr/bin/env python3

from math import *
from itertools import *
from collections import *
from bisect import *


if __name__ == '__main__':
    input()
    lst = [int(x) for x in input().split()]
    lst.sort(reverse=True)
    n = sum(lst)
    na = sum(lst[::2])
    print(na-n+na)


Measured memory_bytes: 3316
package main

import (
	"fmt"
)

func main() {
	var a, b, x int
	fmt.Scan(&a, &b, &x)
  
	if a == 0 {
		fmt.Println(b/x + 1)
	} else {
		fmt.Println(b/x - (a-1)/x)
	}
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))

    count_4 = 0
    count_2 = 0
    for i in range(N):
        if a[i]%4 == 0:
            count_4 += 1
        elif a[i]%2 == 0:
            count_2 += 1
    odd = N - count_4 - count_2
    if count_2 == 0:
        if odd - 1 <= count_4:
            print("Yes")
        else:
            print("No")
    else:
        if odd <= count_4:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 14168
#pragma GCC optimize(2)
#include<iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <cstring>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <map>
#include <unordered_map>
#include <vector> 
#include <bitset>
#include <cctype>
#include <set>
#include <stack>
#include <queue>
#include <fstream>
#include <numeric>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAXN = 205;
const int MAXM = 50005;
const int MOD = 1e9+7;

#define MP make_pair
#define INF 0x3f3f3f3f
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mst(X,Y) memset(X,Y,sizeof(X)) 
#define rep(i, a, n) for (int i=(a); i<=(n); i++)
#define per(i, a, n) for (int i=(a); i>=(n); i--)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) { cerr << " " << to_string(H);    debug_out(T...);}
template <typename T> inline T max(T a, T b, T c) { return max(max(a, b),c); }



int main()
{closeSync;
#ifdef DEBUG
	// freopen("C:/Users/86159/Desktop/a2.in.txt", "r", stdin);
	// freopen("C:/Users/86159/Desktop/output.txt", "w", stdout);
#endif  
	ll x,k,d;
	cin>>x>>k>>d;
	x = abs(x);
	if (x==0)
	{
		if (k&1)
			cout<<d<<endl;
		else 
			cout<<"0\n";
	}
	else if (x>0)
	{
		ll t = x/d;
		ll z = x%d;
		if (k<=t)
			cout<<(x-k*d)<<endl;
		else 
		{
			ll y = k - t;
			if (y&1)
				cout<<(d-z)<<endl;
			else 
				cout<<z<<endl;
		}
	}
	return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    string s;
    cin >> s;
    int ans = size(s);
    REP(i, size(s)-1){
        if(s[i] != s[i+1]) chmin(ans, max(i + 1, size(s) - i - 1));
    }
    cout << ans << endl;
}

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

namespace abc164c
{
    class Program
    {
        static void Main(string[] args)
        {
            //==========================================================================================================================
            //1) input
            int n = int.Parse(Console.ReadLine());

            HashSet<string> hash = new HashSet<string>();

            for (int index = 0; index < n ;index++) {
                string input = Console.ReadLine();

                if (!hash.Contains(input))
                {
                    hash.Add(input);
                }

            }

            


            //==========================================================================================================================
            //2) output

            Console.WriteLine(hash.Count);

        }
    }
}


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

#define int long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const ld PI = acos(-1.0);

int32_t main(){
	fast;
	int n;
	cin >> n;
	
	int ans = 1;
	f(i,1,n+1)
		ans =(ans*i)%MOD;
	cout << ans;
}



Measured memory_bytes: 256
(defstruct p (i 0 :type integer) (city "" :type string) (point 0 :type integer))
(defun f (s)
  (let* ((n (read s))
         (arr (make-array `(,n) :element-type 'p :initial-element (make-p) :adjustable nil))
         (_ (loop #:for i #:from 1 to n
                   #:for city = (symbol-name (read s))
                   #:for point = (read s)
                   #:do (setf (elt arr (1- i)) (make-p :i i :city city :point point))))
         (sorted1 (sort arr #'> :key #'p-point))
         (sorted2 (stable-sort sorted1 #'string< :key #'p-city)))
    (loop #:for p #:across sorted2
          #:do (progn (princ (p-i p)) (terpri)))))
(f t)

Measured memory_bytes: 18784
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    int cnt = 0;
    rep(i,0,4){
        if(N % 10 == 2)cnt++;
        N /= 10;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main(void) {
	char ch;
	int counter[26] = {};
	
	while (scanf("%c", &ch) != EOF) {
		if (isupper(ch)) 
			counter[(int)ch - 'A']++;
		else if (islower(ch))
			counter[(int)ch - 'a']++;
	}
	
	for (ch = 0; ch < 26; ch++)
		printf("%c : %d\n", ch + 'a', counter[(int)ch]);
	
	return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tpl = tuple<int, int, int>;

int N, Q;
int S[200010];
int T[200010];
int X[200010];
int D[200010];
tpl ts[200010];
ll anss[200010];

map<int, int> m;

int main(){

    cin >> N >> Q;
    for(int i = 0; i < N; i++){
        cin >> S[i] >> T[i] >> X[i];
        ts[i] = tpl(X[i], S[i], T[i]);
    }
    sort(ts, ts + N);
    set<int> st;
    for(int i = 0; i < Q; i++){
        cin >> D[i];
        st.insert(D[i]);
        m[D[i]] = i;
    }
    const ll INF = (1LL<<60);
    for(int i = 0; i < 200010; i++) anss[i] = INF;

    for(int i = 0; i < N; i++){
        X[i] = get<0>(ts[i]);
        S[i] = get<1>(ts[i]);
        T[i] = get<2>(ts[i]);

        // [S[i], T[i])
        int bg, ed;
        bool ok = true;
        if(X[i] < S[i]){
            bg = S[i] - X[i];
            ed = bg + (T[i] - S[i]) - 1;
        }
        else if(X[i] >= S[i] && X[i] < T[i]){
            bg = 0;
            ed = T[i] - X[i] - 1;
        }
        else{
            ok = false;
        }
        if(ok){
            // [bg, ed] の範囲のD[j]はそこで止められる
            // X[i]を[bg, ed]の範囲に配置する
            while(st.size()){
                auto it = st.lower_bound(bg);
                int a = *it ;
                if(it == st.end()){
                    break;
                }
                if(bg <= a && a <= ed){
                    st.erase(it);
                    int idx = m[a];
                    anss[idx] = X[i];
                }
                else{
                    break;
                }
            }
        }
    }
    for(int i = 0; i < Q; i++){
        if(anss[i] == INF) cout << -1 << endl;
        else cout << anss[i] << endl;
    }


    return 0;
}


Measured memory_bytes: 27776
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1e9+1000;

typedef long long ll;

#define MAX_V 210005

struct edge {
    int to;
    int cost;
};


int V;
vector<edge> G[MAX_V];
int d[MAX_V];


void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}



int main(){
  int m;
  int p;
  cin >> V >> m;
  
  REP(i,V){
    int k;
    cin >> k;
    REP(j,k){
      int f,t,c;
      cin >> t;
      t--;
      t += V;
      f  = i;
      c = 1;
      edge e = {t,c};
      G[f].pb(e);
      e.to = f;
      G[t].pb(e);
    }
  }
  V += m;
  dijkstra(0);
  bool f = true;
  REP(i,V-m){
    if(d[i] == INF)
      f = false;
  }
  if(f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 11380
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll n;
	rl(n);
	// if(n<10)
	// ll x=10,ans=0;
	// while(x<=n)
	// {
	// 	ans+=(x-x/10);
	// 	x*=100;
	// }
	// x/=100;
	ll ans=0;
	if(n<10)
		ans=n;
	else if(n<100)
	{
		ans=9;
	}
	else if(n<1000)
	{
		ans=9+(n-99);
	}
	else if(n<10000)
	{
		ans=9+(999-99);
	}
	else if(n<100000)
	{
		ans=9+(999-99)+(n-9999);
	}
	else
	{
		ans=9+(999-99)+(99999-9999);
	}
	wl(ans);
	NL;


	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
ans = 'Yes'
for i in range(n-1,0,-1):
    if h[i-1]-h[i]>1:
        ans = 'No'
        break
    elif h[i-1]-h[i]==1:
        h[i-1]-=1
print(ans)

Measured memory_bytes: 14396
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

int main(){
    string s;
    cin >> s;
    int K;
    cin >> K;
    
    string s2 = s;
    sort(s2.begin(), s2.end());
    unique(s2.begin(), s2.end());
    //cout << s2 << endl;

    for(size_t i = 0; i < s2.size(); ++i){
        vector<string> vec;
        for(size_t j = 0; j < s.size(); ++j){
            if(s[j] == s2[i]){
                for(int k = 1; k <= 5 && j + k <= s.size(); ++k){
                    vec.push_back(s.substr(j, k));
                }
            }
        }
        sort(vec.begin(), vec.end());
        vec.erase(std::unique(vec.begin(), vec.end()), vec.end());/*
        for(size_t j = 0; j < vec.size(); ++j){
            cout << vec[j] << endl;
        }*/
        if(vec.size() < K){
            K -= vec.size();
        } else {
            cout << vec[K-1] << endl;
            break;
        }
    }
}

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

using namespace std;

int main() {
    // 考え方メモ

    int N;
    string S;
    cin >> N >> S;

    // 配列外にアクセスした場合にエラーが起こるためダミーの文字を追加する
    S += "ZZZ";

    int count = 0;
    for (int i = 0; i < N;) {
        if (S.substr(i, 3) == "ABC") {
            count++;
            i += 3;
        } else {
            i++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
_ = int(input())
A = list(map(int, input().split()))

def chk(a_list, sgn):
  
  cum_n = 0
  count = 0
  
  for a in a_list:
    cum_n += a
    
    if sgn>0 and cum_n<=0:
      count += abs(cum_n-1)
      cum_n = 1
    elif sgn<0 and cum_n>=0:
      count += abs(cum_n-(-1))
      cum_n = -1
      
    sgn = sgn*(-1)
  
  return(count)

print(min(chk(A, 1), chk(A, -1)))

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

const double PI = 3.14159265359;

int main() {
	double a, b, x;
	cin >> a >> b >> x;	
	x = x / a;
	if (x <= a * b / 2) {
		a = 2 * x / b;
	}
	else {
		x = a * b - x;
		b = 2 * x / a;
	}
	double rad = atan2(b, a);
	double angle = rad / PI * 180.0;
	printf("%.10f\n", angle);
	return 0;
}

Measured memory_bytes: 4172
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(data, 10, sizeof(int), compare_int)

int array[200100];
int buka[200100];

int main(){
	int n;
	scanf("%d", &n);
	for(int i=0; i<200010; i++){
		buka[i] = 0;
	}

	for(int i=2; i<=n; i++){
		scanf("%d", &array[i]);
	}

	for(int i=2; i<=n; i++){
		buka[array[i]]++;
	}

	for(int i=1; i<=n; i++){
		printf("%d\n", buka[i]);
	}
	
	return 0;
}

Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define yes "YES"
#define no "NO"
#define rsort(a) sort(a.rbegin(),a.rend())
const int mod=1000000007;
//void dfs(int i);
long long modular_expo(long long x,long long y);

bool cmp(pair<double,int>p1,pair<double,int>p2)
{
    if(p1.first>p2.first)
        return true;
    else
    {
        if(p1.first<p2.first)
            return false;
        else if(p1.first==p2.first)
        {
            if(p1.second<p2.second)
                return true;
            else
                return false;
        }
    }
}
/*bool cmp1(map<int,int>a,map<int,int>b)
{
    if(a.first<b.first)
        return true;
    else
        return false;
}*/
//ll m;


/*
void bsf(int t)
{
    queue<int>q;
    visited[t]=true;
    q.push(t);
    while(!q.empty())
    {
        int temp=q.front();
        //cout<<temp<<" ";
        if(temp==n)
            {
                vector<int>ans;
    ans.pb(n);
        int tttt=n;
    for(int i=0;i<tttt;i++)
    {
        ans.pb(parent[n]);
        n=parent[n];
        if(n==1)
            break;
    }
    if(n!=1)
    {
        break;
    }
    cout<<ans.size()<<endl;
    for(int i=ans.size()-1;i>=0;i--)
        cout<<ans[i]<<" ";
        f=1;

            }
        q.pop();
        //cout<<temp<<" ";
        for(auto i=l[temp].begin();i!=l[temp].end();i++)
        {
            if(!visited[*i])
            {
                q.push(*i);
                parent[*i]=temp;
                visited[*i]=true;
            }
        }
    }
}
*/
long long modular_expo(long long x,long long y)
{

    if(y==0)
        return 1;
    if(y%2==0)
        return (modular_expo((x*x),y/2));
    if(y%2==1)
        return ((x)*modular_expo((x*x),(y-1)/2));


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

    ll n,x,t;
    cin>>n>>x>>t;
    if(n<=x)
    {
        cout<<t;
        return 0;
    }
    cout<<(ll)ceil(((long double)(n))/x)*t;

}




Measured memory_bytes: 3692
#include <iostream>
#define INF 1000000005
using namespace std;

int n, k;
int tab[1000000];
int dp[1000000];
int main(){
    
    cin >> n >> k;
    
    for(int i = 1; i < n + 5; i++){
        dp[i] = INF;
    }
	for(int i = 0; i < n; i++){
		cin >> tab[i];
	}
    
    //cout<<dp[10];
	for(int i = 0; i < n; i++){
        for(int j = 1; j <= k; j++){
            dp[i + j] = min(dp[i + j], dp[i] + abs(tab[i] - tab[i + j]));
        }
        
    }
	cout << dp[n - 1];

}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
  vector<ll> P(A), Q(B), R(C);
  for (ll i = 0; i < A; i++) cin >> P.at(i);
  for (ll i = 0; i < B; i++) cin >> Q.at(i);
  for (ll i = 0; i < C; i++) cin >> R.at(i);
  sort(P.begin(), P.end(), greater<ll>());
  sort(Q.begin(), Q.end(), greater<ll>());
  sort(R.begin(), R.end(), greater<ll>());
  vector<ll> V;
  for (ll i = 0; i < X; i++) V.push_back(P.at(i));
  for (ll i = 0; i < Y; i++) V.push_back(Q.at(i));
  sort(V.begin(), V.end());
  ll lim = min(X+Y, C);
  for (ll i = 0; i < lim; i++) {
    if (V.at(i) < R.at(i)) V.at(i) = R.at(i);
    else break;
  }
  ll ans = 0;
  for (ll v : V) ans += v;
  cout << ans << endl;
  

  return 0;
}



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

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


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	int a, b;
	cin >> a >> b;
	if (a + b < 10)cout << a + b;
	else cout << "error" << endl;
	return 0;

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

class UnionFind{
public:
    vector<int> belong;
    vector<int> size;

    UnionFind(){

    }

    UnionFind(int n){
        rep(i, n + 1){
            belong.pback(i);
            size.pback(1);
        }
    }

    int find(int a){

        vector<int> fixv;
        while(belong[a] != a){
            fixv.pback(a);
            a = belong[a];
        }

        rep(i, fixv.size()){
            belong[fixv[i]] = a;
        }

        return a;
    }

    bool isSame(int a, int b){

        a = this->find(a);
        b = this->find(b);

        return a == b;
    }

    //sizeをかえす
    int merge(int a, int b){

        a = this->find(a);
        b = this->find(b);

        belong[b] = a;
        int tmp = size[a] + size[b];
        size[a] = tmp;

        return tmp;

    }

};

int main(){

    int n;
    cin >> n;

    map<ll,int> mx;
    map<ll,int> my;

    UnionFind uf(n);

    rep(i,n){
        ll a,b;
        cin >> a >> b;
        int idx = i + 1;

        if(mx.find(a) == mx.end()){
            mx[a] = idx;
        }else{
            uf.merge(mx[a], idx);
        }

        if(my.find(b) == my.end()){
            my[b] = idx;
        }else{
            uf.merge(my[b], idx);
        }

    }

    priority_queue<pair<ll, pair<int,int>>,
                   vector<pair<ll, pair<int,int>>>,
                   greater<pair<ll, pair<int,int>>>> pq;

    for(auto itr = mx.begin(); next(itr) != mx.end(); itr++){

        ll p = (*itr).first;
        ll q = (*(next(itr))).first;

        pq.push(mpair(q - p, mpair(mx[p], mx[q])));
    }

    for(auto itr = my.begin(); next(itr) != my.end(); itr++){

        ll p = (*itr).first;
        ll q = (*(next(itr))).first;

        pq.push(mpair(q - p, mpair(my[p], my[q])));
    }

    ll ans = 0;

    while(!pq.empty()){

        ll len = pq.top().first;
        int a = pq.top().second.first;
        int b = pq.top().second.second;

        if(!uf.isSame(a,b)){

            ans += len;
            int tmp = uf.merge(a,b);
            if(tmp == n) break;

        }

        pq.pop();
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 19564
import java.io.*;
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);
	static final int INF = (int) 1e9;
	static int n, m, k, dist[][];
	static char[][] adj;
	static int[] dx = {1,-1,0,0} , dy = {0,0,1,-1};
	
	static boolean valid(int r, int c) {
		return r >= 0 && r < n && c >= 0 && c < m && adj[r][c] != '@';
	}
	
	static void bfs(int x, int y, int x2, int y2) {
		dist[x][y] = 0;
		Queue<Pair> q = new LinkedList<>();
		q.add(new Pair(x, y, 0));
		
		while(!q.isEmpty()) {
			int r = q.peek().r, c = q.peek().c;
			if(q.poll().d > dist[r][c]) continue;
			
			for(int i = 0; i < 4; i++) {
				for(int j = 1; j <= k; j++) {
					int nr = dx[i] * j + r, nc = dy[i] * j + c;
					if(!valid(nr, nc) || dist[nr][nc] <= dist[r][c]) break;
					if(dist[nr][nc] > dist[r][c] + 1)
						q.add(new Pair(nr, nc, dist[nr][nc] = dist[r][c] + 1));
				}
			}
			
			if(r == x2 && c == y2) break;
		}
	}

	public static void main(String[] args) throws Exception {
		n = sc.nextInt();
		m = sc.nextInt();
		k = sc.nextInt();
		
		int x1 = sc.nextInt() - 1, y1 = sc.nextInt() - 1;
		int x2 = sc.nextInt() - 1, y2 = sc.nextInt() - 1;
		
		dist = new int[n][m];
		adj = new char[n][];
		for(int i = 0; i < n; i++) {
			adj[i] = sc.nextLine().toCharArray();
			Arrays.fill(dist[i], INF);
		}
		
		bfs(x1, y1, x2, y2);
		out.println(dist[x2][y2] == INF ? -1 : dist[x2][y2]);
		out.close();
	}

}

class Pair{
	int r, c, d;
	public Pair(int r, int c, int d) {
		this.r = r;
		this.c = c;
		this.d = d;
	}
}

class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream system) {
		br = new BufferedReader(new InputStreamReader(system));
	}

	public Scanner(String file) throws Exception {
		br = new BufferedReader(new FileReader(file));
	}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public Long nextLong() throws IOException {
		return Long.parseLong(next());
	}
}

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

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

  string prev = ""s;
  int prev_end = 0, next_pos = 0;
  int ans = 0;
  while(next_pos < S.length()){
    if(prev.length() == 1 && next_pos - prev_end < prev.length() && S[next_pos] == prev[next_pos - prev_end]){
      next_pos++;
    }else{
      prev = S.substr(prev_end, next_pos - prev_end + 1);
      //cout << next_pos << endl;
      next_pos++;
      prev_end = next_pos;
      ans++;
    }
  }
  cout << ans << endl;
}



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

int main() {
  int64_t N;
  cin >> N;
  
  int64_t Max;
  for (int64_t i=1; i*i<=N; i++){
    if (N%i!=0){
      continue;
    }
    Max = N/i;
  }
  int64_t A = floor(log(Max)/log(10))+1;
  cout << A << endl;
  return 0;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second
using ll = long long;
using P = pair<ll ,ll>;
using Tu = tuple<ll, ll, ll>;
const ll INFLL = 1LL<<60LL;
const ll INF = 1LL<<60LL;
const ll MOD = 1e9+7;



using ld = long double;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}


vector<vector<set<P> > > st(3, vector<set<P> >(3));
vector<set<ll>> ans(3);
vector<vector<ll> > v;
void erase_set(ll i, ll from){
  assert(ans[from].find(i) != ans[from].end());
  ans[from].erase(ans[from].find(i));
  for(int j=0;j<3;j++){
    if(j == from)
      continue;
    assert(st[from][j].find(P(v[i][j] - v[i][from], i)) != st[from][j].end());
    st[from][j].erase(st[from][j].find(P(v[i][j] - v[i][from], i)));
  }
}

void add_set(ll i, ll to){
  ans[to].insert(i);
  for(int j=0;j<3;j++){
    if(j == to)
      continue;
    st[to][j].insert(P(v[i][j] - v[i][to], i));
  } 
}

int main(){
  string s;
  cin >> s;
  vector<int> dim;
  ll N = s.size();
  for(int i=0;i<(int)s.size();i++)
    if(s[i] == '1')
      dim.push_back(i + 1);
  bool ok = true;
  ok &= s[N-1] == '0';
  ok &= s[0] == '1' && s[N-2] == '1';
  for(int i=0;i<(int)s.size()/2;i++)
    ok &= s[i] == s[N-1-i-1];
  if(!ok)
    cout << -1 << endl;
  else{
    int now = 0;
    for(int i=0;i<N;i++){
      if(now + 1 < dim.size() && i + 1 >= dim[now])
	now++;
      if(dim[now] == i + 1)
	continue;
      cout << i + 1 << " " << dim[now] << endl;
    }
  }
}

/*

10
o-o

110
o-o-o

1110
o-o-o-o
1010
o-o-o
  |
  o

11110
o-o-o-o-o
10010
  o
  |
o-o-o
  |
  o

1011010

o-o-o-o-o
  |   |
  o   o


1010100101010 13頂点1,3,5
        _
  5   3/ \1
o-o-o o-o o
  |   | 
  -----

  o o
  |/
o-o-o
  |
  o
|

1????10になる木だから それ以外作れそう？
 */


Measured memory_bytes: 2040
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect

r,c,k=map(int,input().split())
v=[[0]*c for _ in range(r)]
for i in range(k):
    ri,ci,val=map(int,input().split())
    v[ri-1][ci-1]=val
d=[[0]*(c*r) for _ in range(4)]
d[1][0]=v[0][0]
for i in range(1,c):
    d[1][i]=max(d[1][i-1],d[0][i-1]+v[0][i])
    d[2][i]=max(d[2][i-1],d[1][i-1]+v[0][i])
    d[3][i]=max(d[3][i-1],d[2][i-1]+v[0][i])
for i in range(c,r*c):
    m=0
    for j in range(4):
        m=max(m,d[j][i-c])
    cx=i%c
    rx=i//c
    d[0][i]=max(0,m)
    d[1][i]=max(d[1][i-1],m+v[rx][cx],v[rx][cx]+d[0][i-1]) if cx!=0 else max(0,v[rx][cx]+m)
    d[2][i]=max(d[2][i-1],v[rx][cx]+d[1][i-1]) if cx!=0 else 0
    d[3][i]=max(d[3][i-1],v[rx][cx]+d[2][i-1]) if cx!=0 else 0
ans=0
for j in range(4):
  ans=max(ans,d[j][r*c-1])
print(ans)

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

struct union_find{
    vector<int> par;
    vector<int> rank;
    vector<int> siz;
    
    union_find(int N) : par(N), rank(N), siz(N){
        rep(i,N){
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }
    
    int root(int x){
        if (par[x] == x){
            return x;
        }
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (rank[rx] < rank[ry]){
            par[rx] = ry;
            siz[ry] += siz[rx];
        }
        else{
            par[ry] = rx;
            siz[rx] += siz[ry];
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
    }
    
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int size(int x){
        return siz[root(x)];
    }
};

int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> X(M);
    vector<ll> Y(M);
    vector<ll> Z(M);
    rep(i,M){
        cin >> X[i] >> Y[i] >> Z[i];
        X[i]--;
        Y[i]--;
    }
    union_find tree(N);
    rep(i,M){
        tree.unite(X[i], Y[i]);
    }
    ll ans = 0;
    rep(i,N){
        if (tree.root(i) == i) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6668
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n)-1; i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define pb  push_back
#define eb  emplace_back

const int INF = 1<<28;
const int MOD = 1000000007;

int main(){
  int a, b; cin >> a >> b;
  if(a>=13) cout << b << endl;
  else if(a>=6) cout << b/2 << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int t[4];
	int n[4];
	int i;
	int money[4];
	
	for(i = 0;i < 4;i++){
		scanf("%d %d",&t[i],&n[i]);
	}
	
	for(i = 0;i < 4;i++){
		if(t[i] == 1){
			money[i] = n[i] * 6000;
		}
		else if(t[i] == 2){
			money[i] = n[i] * 4000;
		}
		else if(t[i] == 3){
			money[i] = n[i] * 3000;
		}
		else if(t[i] == 4){
			money[i] = n[i] * 2000;
		}
	}
	
	for(i = 0;i < 4;i++){
		printf("%d\n",money[i]);
	}
	
	return(0);
}

Measured memory_bytes: 600
#include <cstdio>

int d[200001];
int main(){
    int n, T;
    scanf("%d %d", &n, &T);
    for(int i=1; i<=n; i++)
		scanf("%d", &d[i]);
	int s=-1, e=-1;
	int sum=0;
	for(int i=1; i<=n; i++){
		if(e <= d[i]){
            sum += (e-s);
            s=d[i];
            e=d[i]+T;
		}
		else e=d[i]+T;
	}
	if(s!=e) sum+=(e-s);
	printf("%d", sum);
	return 0;
}


Measured memory_bytes: 896
N,K = map(int, input().strip().split(' '))
R,S,P = map(int, input().strip().split(' '))
score_dict = {'r': P, 's': R, 'p': S}
T = input().strip()

# 毎回勝つか勝たないかを選べる
# 勝つとK回後の手が制限される, 勝たないとK回後は好きな手が出せる(あいこ・負けはどちらでもよいので)
# 今勝ってもK回後勝っても勝利点は同じなので貪欲でよい

ans = 0
mem = ['x']*N  # 勝ったかどうかを覚えておく 'x'は勝ってない
for i,t in enumerate(T):
  if i < K:
    ans += score_dict[t]
    mem[i] = t
  elif t != mem[i-K]:
    ans += score_dict[t]
    mem[i] = t

print(ans)

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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+123;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define MP make_pair
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ll n,ans=9999999999999999,i,ok=0;
    cin>>n;
    ///cout<<ans el;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            ans=min(ans,i-1+n/i-1);
            ok++;
        }
    }
    if(!ok) ans=n-1;
    cout<<ans el;
}

main()
{
    fastio();
    _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <vector>
using namespace std;
map<int,int> m;
int n, a;
int main(){
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", &a);
		m[a]++;
		m[a - 1]++;
		m[a + 1]++;
	}
	int answer = 0;
	for (map<int,int>::iterator it = m.begin(); it != m.end(); it++){
		answer = max(answer, it -> second);
	}
	printf("%d\n", answer);
	
	
}

Measured memory_bytes: 4736
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=2e5;
char a[MAXN+5],tmp1[MAXN+5],tmp2[MAXN+5];
int n,ans;
int main()
{
	scanf("%s",a+1);
	n=strlen(a+1);
	int cnt1=0,cnt2=0;
	for(int i=1;i<=n;i++)
	{
		tmp2[++cnt2]=a[i];
		//printf("%s %s ans:%d\n--------\n",tmp1+1,tmp2+1,ans);
		if(strcmp(tmp1+1,tmp2+1)==0)//和前一个子串相同 
			continue;
		else
		{
			ans++;
			memcpy(tmp1+1,tmp2+1,cnt2+1);
			memset(tmp2,0,sizeof(tmp2));
			cnt2=0;
		}	
	}
	printf("%d",ans);
    return 0;
}


Measured memory_bytes: 640
a,b,c = map(int,input().split())
k = int(input())
count = 0
while a >= b:
  b *= 2
  count += 1
while b >= c:
  c *= 2
  count += 1
if a < b < c and k-count>= 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 8872
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

int main (int argc, char* argv[]) {
	int n;
	cin >> n;
	vector<int> nums(n);
	for (int i = 0; i < n; i++) {
		cin >> nums[i];
	}
	vector<int> left(n);
	left[0] = nums[0];
	for (int i = 1; i < n; i++) {
		left[i] = gcd(left[i - 1], nums[i]);
	}
	vector<int> right(n);
	right.back() = nums.back();
	for (int i = n - 2; i >= 0; i--) {
		right[i] = gcd(right[i + 1], nums[i]);
	}


	int max_gcd = 0;
	for (int i = 0; i < n; i++) {
		int l = (i - 1 >= 0) ? left[i - 1] : 0;
		int r = (i + 1 < n) ? right[i + 1] : 0;
		max_gcd = max(max_gcd, gcd(l, r));
	}
	cout << max_gcd << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    vector<int> order(n + 1, 0);
    for (int i = 0; i < n; i++) order[p[i]] = i;
    long long ans = 0;
    set<int> s;
    s.insert(-1);
    s.insert(-2);
    s.insert(1e6);
    s.insert(1e6 + 1);
    for (int i = n; i > 0; i--){
        int x = order[i];
        long long c = 0;
        vector<int> l(2);
        vector<int> r(2);
        s.insert(x);
        {
            auto itr = s.find(x);
            --itr; l[0] = *itr;
            --itr; l[1] = *itr;
        }
        {
            auto itr = s.find(x);
            ++itr; r[0] = *itr;
            ++itr; r[1] = *itr;
        }
        if (l[0] < 0 && r[0] >= 1e6) continue;
        if (l[0] < 0){
            if (r[1] >= 1e6) r[1] = n;
            c = (x + 1) * (r[1] - r[0]);
        }
        else if (r[0] >= 1e6){
            if (l[1] < 0) l[1] = - 1;
            c = (l[0] - l[1]) * (n - x);
        }
        else {
            if (l[1] < 0) l[1] = - 1;
            if (r[1] >= 1e6) r[1] = n;
            c += (x - l[0]) * (r[1] - r[0]);
            c += (l[0] - l[1]) * (r[0] - x);
        }
        ans += c * i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST         ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll           long long
#define ld           long double
#define pb           push_back
#define mp           make_pair
#define pii          pair<int,int>
#define mii          map<int,int>
#define vi           vector<int>
#define vll          vector<long long>
#define all(a)       (a).begin(),(a).end()
#define clz(a)       __builtin_clz(a) // count leading zeroes
#define ctz(a)       __builtin_ctz(a) // count trailing zeroes
#define popc(a)      __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul          1000000007
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define rfor(i,a,b)  for(int i=a; i>=b; i--)
#define SIZE         1000005
#define F            first
#define S            second
#define mod          998244353

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::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, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define endl         '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

void solve()
{
     int n; cin>>n;
     vi v(n);
     rep(i,0,n) cin>>v[i];
     sort(all(v));
     int ans = v[0];
     vi a(n);
     a = v;
     rep(i,0,n)
     {
        if(i&1)
        {
            a[i] = 24-v[i];
        }
        else{
            a[i] = v[i];
        }
     }
     sort(all(a));
     rep(i,1,n)
     {
        ans = min(ans,a[i]-a[i-1]);
     }
     cout<<ans;
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 256
t = input()
s = list(t)
a=0
if len(s)!=1:
    for i in range(len(s)-1):
        if s[i]==s[i+1] and s[i]=="1":
            s[i+1]="0"
            a=a+1
        elif s[i]==s[i+1] and s[i]=="0":
            s[i+1]="1"
            a=a+1
    print(a)
elif len(s)==1:
    print(0)

Measured memory_bytes: 3956
#include<cstdio>
char s[100][101];
int main() {
	int a, b, i, j;
	scanf("%d%d", &a, &b);
	for (i = 0; i < 50; i++) {
		for (j = 0; j < 100; j++)s[i][j] = '#';
		s[i][100] = '\0';
	}
	for (i = 50; i < 100; i++) {
		for (j = 0; j < 100; j++)s[i][j] = '.';
		s[i][100] = '\0';
	}
	a -= 1;
	b -= 1;
	for (i = 0; a > 0; i += 2) {
		if (a >= 50) for (j = 0; j < 100; j += 2) s[i][j] = '.';
		else for (j = 0; j < a; j++) s[i][2 * j] = '.';
		a -= 50;
	}
	for (i = 99; b > 0; i -= 2) {
		if (b >= 50) for (j = 0; j < 100; j += 2)s[i][j] = '#';
		else for (j = 0; j < b; j++)s[i][2 * j] = '#';
		b -= 50;
	}
	printf("100 100\n");
	for (i = 0; i < 100; i++)printf("%s\n", s[i]);
	return 0;
}

Measured memory_bytes: 128