akhauriyash/Code-Regression huggingface dataset:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
S = [LS2() for _ in range(N)]

# Aj-Ai == Bj-Bi のとき、
# (Ai,Bi) を選んだときの盤面が'よい' ⇔ (Aj,Bj) を選んだときの盤面が'よい'

ans = 0
for a in range(N):
    X = [S[i] for i in range(a,N)] + [S[i] for i in range(a)]
    for i in range(N-1):
        for j in range(i+1,N):
            if X[i][j] != X[j][i]:
                break
        else:
            continue
        break
    else:
        ans += 1

print(ans*N)


Measured memory_bytes: 72060
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int a;
   cin >> a;
   cout << a + a*a + a*a*a << endl;
}

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

int main(void)
{
  long long int a,b,c,k,ans;
  scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
  if(k % 2 == 1)
    {
      ans = b - a;
    }
  else
    {
      ans = a - b;
    }
  if(abs(ans) > 1000000000000000000 )
    {
      printf("Unfair\n");
    }
  else
    {
      printf("%lld\n",ans);
    }
  return 0;
}
  


Measured memory_bytes: 128
//_nebula_
#include<bits/stdc++.h>
using namespace std;
#define int long  long
#define double long double
int t;
const int M=1e9+7;
int factt(int n)
{
    int ans=1;
    for(int i=1;i<=n;i++)
    {
        ans*=i;
        ans=ans%M;
    }
    return ans;
}
int max(int a,int b,int c)
{
    return max(a,max(b,c));
}
int min(int a,int b,int c)
{
    return min(a,min(b,c));
}
int fspow(int x,int y)
{
    int ans;
    if(y==0) return 1;
    ans=fspow(x, y/2);
    if(y%2==0) return (ans*ans);
    return x*ans*ans;
}
int gcd(int x,int y)
{
    if(x<y) swap(x,y);
    if(y==0) return x;
    return gcd(x%y,y);
}
int p2(int x)
{
    int ans=0;
    while(x>=1)
    {
        ans++;
        x/=2;
    }
    return ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    t=1;
    // freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //cin>>t;
    // int tmp=t;
    while(t--)
    {
      int n;
      cin>>n;
      int a[n];
      for(int i=0;i<n;i++) cin>>a[i];
      int ans=0;
      for(int i=1;i<n;i++)
      {
        if(a[i]<a[i-1])
        {
            ans+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
      }
      cout<<ans<<"\n";
    }
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    double r; cin >> r;
    cout << (r*3.14159265358979*2) << endl;
    return 0;
}


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

const ll mod = 1000000007;

// mod. m での a の逆元 a^{-1} を計算する
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll pow_kai(ll a, ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a;
      x %= mod;
    }
    a = a*a;
    a %= mod;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

ll choose(ll n, ll r) {
    ll ret = 1;
    for (ll i = n; i > n-r;--i){
        ret *= i;
        ret %= mod;
    }
    for (ll i = 1; i < r+1; ++i) {
        // ret /= i;
        ret %= mod;
        ret = ret * modinv(i,mod) % mod;
    }
    return ret;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = pow_kai(2, n) - 1;
    ans -= choose(n, a);
    ans -= choose(n, b);
    while (ans < 0) ans += mod;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     int N = sc.nextInt();
     int K = sc.nextInt();
     int[] p= new int[N];
     int i,ans=0,pans=0;
     double answer;
     for(i=0;i<N;i++){
       p[i] = sc.nextInt();
     }
     for(i=0;i<K;i++){
         ans+=p[i];
     }
     pans = ans;
     for(i=K;i<N;i++){
       pans = pans-p[i-K]+p[i];
       if(pans>ans){
         ans = pans;
       }
     }
     answer = (ans+K)/2.0;
     System.out.print(answer);
   }
}


Measured memory_bytes: 72208
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int mod = 10000*100000+7;
#define ll long long 
#define outarr(arr) for(int i=0;i<arr.size();i++)cout<<arr[i]<<" ";
void pairsort(int a[], int b[], int n) 
{ 
    pair<int, char> pairt[n];
    for (int i = 0; i < n; i++)  
    { 
        pairt[i].first = a[i]; 
        pairt[i].second = b[i]; 
    }
    sort(pairt, pairt + n); 
    for (int i = 0; i < n; i++)  
    { 
        a[i] = pairt[i].first; 
        b[i] = pairt[i].second; 
    } 
} 
std::vector<int> decToBinary(int n) 
{  
    int binaryNum[1000]; 
    std::vector<int> res;
    int i = 0; 
    while (n > 0) {
        binaryNum[i] = n % 2; 
        n = n / 2; 
        i++; 
    }
    for (int j = i - 1; j >= 0; j--){
    	res.push_back(binaryNum[j]);
        //cout << binaryNum[j]; 
    }
    return res;
} 
long long Pow(long long x,long long p)
{
    long long res = 1;
    x = x%mod;
    while(p)
    {
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

bool isPrime(long long int n){
	if(n==1 || n==2)return true;
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0)return false;
	}
	return true;
}

vector<long long int> findFactors (long long int n){
	vector<long long int> ans;
	for(int i=1;i<=sqrt(n);i++){
		if(n%i==0){
			ans.push_back(i);
			if(i*i!=n){
				ans.push_back(n/i);
			}
		}
	}
	return ans;
}
bool isPerfectSquare(long long int x) 
{   
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0); 
} 
vector<long long int> findPrimeFactors (long long int n, bool sq){
	vector<long long int> ans;
	int root = sqrt(n);
	for(int i=1;i<=sqrt(n);i++){
		if(n%i==0){
			if(isPrime(i) && i!=1)
			ans.push_back(i);
			if(!sq||(sq && i!=root)){
				if(isPrime(n/i) && (n/i)!=1)
				ans.push_back(n/i);
			}
		}
	}
	return ans;
}

int main(){
	IOS
	int a,b;
	cin>>a>>b;
	if(b%a==0)cout<<(a+b)<<endl;
	else cout<<(b-a)<<endl;
  	return 0;
}

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

namespace ABC112B
{
    static class MainClass
    {
        public static void Main(string[] args)
        {

            string[] input1 = Console.ReadLine().Split(' ');
            int N = int.Parse(input1[0]);
            int T = int.Parse(input1[1]);


            var c = new List<int>();
            var t = new List<int>();
            for (int i = 0; i < N; i++)
            {
                string[] input2 = Console.ReadLine().Split(' ');
                var ttmp = int.Parse(input2[1]);
                if (ttmp <= T)
                {
                    c.Add(int.Parse(input2[0]));
                    t.Add(int.Parse(input2[1]));
                }
            }

            if (t.Count() == 0)
            {
                Console.WriteLine("TLE");

            }
            else
            {
                c.Sort();
                Console.WriteLine(c[0]);
            }


        }


    }
}






Measured memory_bytes: 11220
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int x = tx - sx;
	int y = ty - sy;
	string i1 = "";
	string i2 = "";
	string i3 = "";
	string i4 = "";
	for (int i = 0; i < x; i++) {
		i2 += "R";
		i4 += "L";
	}
	for (int i = 0; i < y; i++) {
		i1 += "U";
		i3 += "D";
	}
	cout << i1 << i2 << i3 << i4;
	cout << "D" << i2 << "R" << i1 << "U" << "L";
	cout << "U" << i4 << "L" << i3 << "D" << "R" << endl;
}

Measured memory_bytes: 256
/*

*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define cou(x) cout << x
#define cous(x) cout << x << " "
#define coul(x) cout << x << "\n"
#define ret(x) return x
#define MAX 5000001
#define start int main() {   fastio
#define finish ret(0); }
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cntv(v,a) count(v.begin(),v.end(),a)
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=1000000007;
//ll rnd(ll x) { return mrand() % x;}
const ll X[]= {+0,+0,+1,-1,-1,+1,-1,+1};
const ll Y[]= {-1,+1,+0,+0,+1,+1,-1,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}ret(res);}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[13];
void factorial() {   fact[0]=1;  rep(i, 1, 12) fact[i]=(fact[i-1]*i);  }
vector <ll> sie; //for sieve function
ll spf[MAX+7];  //for sieve function
void sieve() {    rep(i, 2, MAX)  {  if (spf[i] == 0) {  spf[i] = i;   sie.pb(i);  }    for (ll j=0; j<SZ(sie) && i*sie[j] <= MAX && sie[j] <= spf[i]; j++)   spf[i * sie[j]] = sie[j]; }   }
// head collected

ll t, n, k, _, __,ans, r, g, b;
string str;
ll R[4007], G[4007], B[4007];

start;

    cin2(t, str);

    rep(i, 0, t){
        if ( str[i] == 'R' )
            r++;
        if ( str[i] == 'B' )
            b++;
        if ( str[i] == 'G' )
            g++;

        R[ i ] = r;
        B[ i ] = b;
        G[ i ] = g;
    }

    ll sum = 0;
    rep(i, 0, t-2){
        rep(j, i+1, t-1){
            if( str[i] == str[j] )
                continue;
            else if( str[i] != 'R' && str[j] != 'R' ){
                sum += (  R[t-1] - R[j] );
                if( str[j + (j - i)] == 'R')
                    sum--;
            }
            else if( str[i] != 'B' && str[j] != 'B' ){
                sum += (  B[t-1] - B[j] );
                if( str[j + (j - i)] == 'B')
                    sum--;
            }
            else if( str[i] != 'G' && str[j] != 'G' ){
                sum += (  G[t-1] - G[j] );
                if( str[j + (j - i)] == 'G')
                    sum--;
            }


           // if(str[i] == str[j] )
                //continue;
            /*rep(k, j+1, t){
                //cout << "j";
                if( str[i] != str[j] && str[i] != str[k ]  && str[k] != str[j] && j-i != k -j)
                    sum ++;
            }*/
        }
    }

    coul(sum);
     /*if( a == 7 || b == 7 || c ==  7 )
        coul("Yes");
     else
        coul( "No");*/



finish


Measured memory_bytes: 3724
#include<stdio.h>
int main(void){
    int a,b,c,temp;
    scanf("%d %d %d",&a,&b,&c);
    
    if(a>b){
        temp=a;
        a=b;
        b=temp;
    }
    if(a>c){
        temp=a;
        a=c;
        c=temp;
    }
    if(b>c){
        temp=b;
        b=c;
        c=temp;
    }
    
    printf("%d %d %d\n",a,b,c);
    return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=n-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    int n,k;
  	string s;
    cin>>n>>k>>s;
    if(s[k-1]=='A')s[k-1]='a';
  	else if(s[k-1]=='B')s[k-1]='b';
  	else s[k-1]='c';
  
    cout<<s<<"\n";

    return 0;

}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    
    int n;
    int a[100];
    
    int i;
    int max = 0, cur = 0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    
    for(i=0;i<n;i++){
        if(a[i] == 1) cur++;
        else{
            if (cur > max) max = cur;
            cur = 0;
        }
    }
    if (cur > max) max = cur;
    printf("%d\n", max+1);
    return 0;
    
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var (N, K) = ReadLineInt2();

            var data = new List<int>();
            foreach(var p in ReadLineStr().Split(' '))
            {
                data.Add(Convert.ToInt32(p));
            }


            data = data.OrderBy(p => p).ToList();

            var sum = 0;
            for(var i = 0; i < K; i++)
            {
                sum += Convert.ToInt32(data[i]);
            }

            Console.WriteLine(sum);
        }


        #region 使いまわし
        static string ReadLineStr() { return Console.ReadLine(); }
        static int ReadLineInt() { return Convert.ToInt32(Console.ReadLine()); }
        static (int, int) ReadLineInt2()
        {
            var temp = Console.ReadLine().Split(' ');
            return (Convert.ToInt32(temp[0]), Convert.ToInt32(temp[1]));
        }
        #endregion
    }
}


Measured memory_bytes: 28664
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
const double pi = 3.141592653589793;
int main(){
    string s;
    cin>>s;
    int n=s.length();
    if(n==2){
        if(s[0]==s[1])cout<<"1 2"<<endl;
        else cout<<"-1 -1"<<endl;
        return 0;
    }
    rep(i,n-1){
        string t = s.substr(i,3);
        if(t[0]==t[1]||t[1]==t[2]||t[0]==t[2]){
            cout<<i+1<<" "<<i+3<<endl;
            return 0;
        }
    }
    cout<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 3720
#include <stdio.h>
int main(){int n,c[510],s[510],f[510];scanf("%d",&n);for(int*d=c,*t=s,*g=f;d<c+n-1;++d,++t,++g)scanf("%d%d%d",d,t,g);++(f[n-1]=s[n-1]=c[n-1]=0);for(int i=0;i<n;i++)for(int a=0,j=i;j<n||!printf("%d\n",a);j++)a=c[j]+(a<s[j]?s[j]:(a/f[j]+(a%f[j]!=0))*f[j]);}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ll x;

    cin >> x;

    for (ll i = 0; i <= 2000; i++)
    {
        for (ll j = 0; j <= 2000; j++)
        {
            ll a = i - 1000;
            ll b = j - 1000;
            ll t = a * a * a * a * a;
            ll s = b * b * b * b * b;

            if (t - s == x)
            {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int a,b,c,d,len;
int main(){
    cin>>a>>b;c=b;
    while(c>0) c/=10,len++;
    a=a*pow(10,len)+b;
    d=sqrt(a);
    if(d*d==a) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 384
from collections import deque

N = int(input())
es = [[] for _ in range(N)]

for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    es[u].append((v, w))
    es[v].append((u, w))

clr = [None] * N
clr[0] = 0

dq = deque()
dq.append(0)

while dq:
    v = dq.popleft()
    for nv, w in es[v]:
        if clr[nv] is not None:
            continue
        clr[nv] = (clr[v] + w) % 2
        dq.append(nv)
print(*clr, sep='\n')


Measured memory_bytes: 70048
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete

f xs = [cond x 0 $ arr!x == 1 | x <- xs]
  where
    arr = array (1,100) . map (fnTuple (head, length)) . group . sort $ xs

main = do
    n <- getInt
    replicateM n getInts >>= mapM_ print . foldl1 (zipWith (+)) . map f . transpose
    

Measured memory_bytes: 4204
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,t,m=0; cin>>n;
  int a[100100]={0}; for(int i=0;i<n;i++) cin>>t,a[t]++;
  for(int i=1;i<100001;i++) m=max(m,a[i-1]+a[i]+a[i+1]);
  cout<<m<<endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll n;
	cin >> n;

	ll a[n];
	ll sum =  0;
	rep(i,n){
		cin >> a[i];
		sum += a[i];
	}

	ll s[n];
	s[0] = a[0];
	rep(i,n-1){
		s[i+1] = s[i] + a[i+1];
	}

	ll mn = 1e16;
	rep(i,n-1){
		ll c = abs(s[i] - (sum-s[i]));
		mn = min(mn,c);
	}

	cout << mn << endl;	
}

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

using ll = long long;
const ll inf = 1e15;
const int MAXN = 200*1000+5;
int a[MAXN];

map<pair<int, int>, ll> memo;

ll dp(int idx, int need) {
    if(idx < 0) {
        return need == 0 ? 0 : -inf;
    }
    if(need == 0) return 0;
    if(need > (idx+1)/2+1) return -inf;
    pair<int, int> state{idx, need};
    
    if(memo.count(state)) return memo[state];
    return memo[state] = max(dp(idx-1, need), dp(idx-2, need-1) + a[idx]);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cout << dp(n-1, n/2) << endl;
}


Measured memory_bytes: 37236
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<math.h>
#include <iomanip>

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

using namespace std;

const int INF = 1 << 21;

int main()
{
	/*
		一回の移動回数で、i&jは1しか移動できない
		i * j 最初(1, 1)にいるから、(i - 1) + (j - 1)これが最小になるものがマスの答え
		i * j = N    i + j - 2       (√Nの計算量以下)
	*/ 

	ll N;
	cin >> N;

	int loop = sqrt(N);

	ll ans;
	for (int i = 1; i <= loop; i++) {
		if (N % i == 0) {
			ans = i + (N / i) - 2;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int sentinel=2000000000;
int L[250002],R[250002];
int cnt;

void merge(int A[],int left,int mid,int right)
{
	int n1=mid-left;
	int n2=right-mid;
	int i,j,k;
	
	for(i=0;i<n1;i++)
	{
		L[i]=A[left+i];
	}
	for(i=0;i<n2;i++)
	{
		R[i]=A[mid+i];
	}
	L[n1]=sentinel;
	R[n2]=sentinel;
	i=0;
	j=0;
	
	for(k=left;k<right;k++)
	{
		cnt++;
		if(L[i]<=R[j])
		{
			A[k]=L[i];
			i++;
		}
		else
		{
			A[k]=R[j];
			j++;
		}
	}
}

void mergeSort(int A[],int left,int rigft)
{
	if(left+1<rigft)
	{
		int mid=(left+rigft)/2;
		mergeSort(A,left,mid);
		mergeSort(A,mid,rigft);
		merge(A,left,mid,rigft);
	}
}

int main(void)
{
	int n,i;
	int A[500000];
	cnt=0;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
	}
	
	mergeSort(A,0,n);
	
	for(i=0;i<n-1;i++)
	{
		printf("%d ",A[i]);
	}
	printf("%d\n%d\n",A[i],cnt);
	
	return 0;
}


Measured memory_bytes: 5652
//@sakshjha
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pi 3.14159265358979
const ll MOD = 1000000000;
const ll N=100005;
int main()
{
    IOS
    ll n;
    cin>>n;
    ll a[n],i,b[n+5]={0};
    for(i=0; i<n-1; i++)
    {
        ll u;
        cin>>u;
        b[u]++;
    }
    for(i=1; i<=n; i++)
        cout<<b[i]<<"\n";
    return 0;
}


Measured memory_bytes: 5224
#include<bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int N = (int)S.size();
  vector<int>A(N);
  for (int i = 0; i < N; i ++) {
    A[i] = (int)S[i] - (int)'0';
  }
  int ans = 10000;
  for (int i = 0; i < N - 2; i ++) {
    int kj = A[i] * 100 + A[i + 1] * 10 + A[i + 2];
    if (ans > max(753 - kj, kj - 753)) {
      ans = max(753 - kj, kj - 753);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3568
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
  int A,B,C,D,P,money_x,money_y;
  scanf("%d%d%d%d%d",&A,&B,&C,&D,&P);
  money_x=A*P;
  if(P<C) money_y=B;
  if(P>C) money_y=B+(P-C)*D;
  if(money_x<money_y) printf("%d\n",money_x);
  else printf("%d\n",money_y);
  return 0;
}



Measured memory_bytes: 2100
package main

import (
	"fmt"
	"math"
)

func pow(a int, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func main() {
	var a int
	fmt.Scan(&a)
	fmt.Println(a + pow(a, 2) + pow(a, 3))
}


Measured memory_bytes: 1836
fun main(args: Array<String>) {
    var (N, K) = listOfLong()
    val MAX = 100005
    val C = LongArray(MAX + 1)
    for (n in 0 until N) {
        val (a, b) = pairIntLong()
        C[a] += b
    }
    for (a in C.indices) {
        if (K <= C[a]) return println(a)
        K -= C[a]
    }
}

fun pairIntLong() = listOfLong().let { Pair(it[0].toInt(), it[1]) }
fun tripleIntIntLong() = listOfLong().let { Triple(it[0].toInt(), it[1].toInt(), it[2]) }
fun tripleIntLongLong() = listOfLong().let { Triple(it[0].toInt(), it[1], it[2]) }
fun pairIntLong(offset: Pair<Int, Long> = Pair(0, 0L)) = listOfLong().let { Pair(it[0].toInt() + offset.first, it[1] + offset.second) }
fun tripleIntIntLong(offset: Triple<Int, Int, Long> = Triple(0, 0, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1].toInt() + offset.second, it[2] + offset.third) }
fun tripleIntLongLong(offset: Triple<Int, Long, Long> = Triple(0, 0L, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1] + offset.second, it[2] + offset.third) }

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }
fun listOfLong() = listOfString().map(String::toLong)
fun listOfLong(offset: Long = 0L) = listOfString().map { it.toLong() + offset}


Measured memory_bytes: 53672
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
# define pb push_back
typedef long long ll;

int main(){
    int n,k;
    cin >> n >> k;
    int count = 0;
    rep(i,n){
        int h;
        cin >> h;
        if(h>=k){
            count ++;
        }
    }
    cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  string s;
  cin>>s;
  if(s=="SUN"){
    cout<<7<<endl;
  }
  if(s=="MON"){
    cout<<6<<endl;
  }
  if(s=="TUE"){
    cout<<5<<endl;
  }
  if(s=="WED"){
    cout<<4<<endl;
  }
  if(s=="THU"){
    cout<<3<<endl;
  }
  if(s=="FRI"){
    cout<<2<<endl;
  }
  if(s=="SAT"){
    cout<<1<<endl;
  }
}

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

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

    ll n;
    cin >> n;
    vector<ll> a(n), b(n);

    ll a_sum = 0;
    ll b_sum = 0;
    rep(i, n){
        ll tmp;
        cin >> tmp;
        a[i] = tmp;
        a_sum += tmp;
    }
    
    rep(i, n){
        ll tmp;
        cin >> tmp;
        b[i] = tmp;
        b_sum += tmp;
    }

    if(a_sum < b_sum){
        cout << -1 << endl;
        return 0;
    }

    ll same_cnt = 0;
    ll greater_cnt = 0;
    vector<ll> resource(n, -1);
    vector<ll> lack(n, -1);
    rep(i, n){
        if(a[i] >= b[i]){
            if(a[i] == b[i]) {
                ++same_cnt;
                resource[i] = 0;
            }
            else{
                resource[i] = a[i] - b[i];
                ++greater_cnt;
            }
        }
        else{
            lack[i] = b[i] - a[i];
        }
    }

    sort(resource.begin(), resource.end(), greater<ll>());
    sort(lack.begin(), lack.end(), greater<ll>());

    ll res = n - same_cnt - greater_cnt + 1;
    ll ptr = 0;
    rep(i, resource.size()){
        ll current = resource[i];
        while(ptr != lack.size()){
            if(current >= lack[ptr]){
                current -= lack[ptr];
                ++ptr;
            }
            else{
                lack[ptr] -= current;
                break;
            }
        }

        if(ptr == lack.size()) break;
        else ++res;
    }
    if(n == same_cnt+greater_cnt) cout << 0 << endl;
    else cout << res << endl;
    
    return 0;
}

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

int main(int argc,char *argv[]){
	if(argc>=2){freopen(argv[1],"r",stdin);}
	if(argc>=3){freopen(argv[2],"w",stdout);}
	int a,b,c,d,e,f;
	scanf("%d%d%d",&d,&e,&f);
	a=min(d,min(e,f));
	c=max(d,max(e,f));
	b=d+e+f-a-c;
	int ans=0;
	if((a+b)%2==1){
		++ans;
		++c;++a;
	}
	while(a<b){
		++ans;
		a+=2;
	}
	while(a<c){
		++ans;
		++a;++b;
	}
	printf("%d",ans);
	
	fclose(stdin);fclose(stdout);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,i;

  scanf("%d",&n);

  int a[1000];

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  i--;
  do{
    
    printf("%d",a[i]);
    if(i!=0){
      printf(" ");
    }
    i--;
  }while(i!=-1);
  printf("\n");
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+9;
typedef long long ll;
int main() {

	int a, b;
	cin >> a >> b;
	if(a > b) {
		for(int i = 0; i < a; ++i) {
			cout << b;
		}
	} else {
		for(int i = 0; i < b; ++i) {
			cout << a;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
void init(long long int *arr, long long int len)
{
	long long int index =0;
	while (index <len)
	{
		arr[index] =0;
		index++;
	}
}

long long int conv_2(long long int x)
{
	if (x <=0 )
		return (0);
	if (x < 2)
		return (0);
	if (x == 2)
		return (1);
	return(x*(x-1)/2);
}
int main(void)
{
	long long int N;
	scanf("%lld", &N);
	long long int index =0;
	long long int arr_A[N];
	while (index <N)
	{
		scanf("%lld", &arr_A[index]);
		index++;
	}
	long long int arr_count[N+1];
	init(arr_count, N+1);
	index =0;
	while (index < N)
	{
		arr_count[arr_A[index]]++;
		index++;
	}
	index=1;
	long long int sum =0;
	while (index <=N)
	{
		sum = sum + conv_2(arr_count[index]);
		if (arr_count[index] ==1)
			arr_count[index] =0;
		if (arr_count[index] >1)
			arr_count[index] = conv_2(arr_count[index])-conv_2(arr_count[index]-1);
		index++;
	}
	index =0;
	while (index < N)
	{
		printf("%lld\n",sum - arr_count[arr_A[index]]);
		index++;
	}
	return (0);
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 100 + 5;
const int MAX_N = 1e5 + 5;

#define MAX_N 200000 //10^5
int ans[MAX_N];

int main() {
    int n, q;
    cin >> n >> q;
    vector<P> v;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        v.push_back(P(a, b));
    }
    auto comp = [](const P &a, const P &b) {
        return a.first < b.first;
    };
    sort(v.begin(), v.end(), comp);
    rep(i, q) {
        int a, b;
        cin >> a >> b;
        a--;
        ans[a] += b;
    }
    rep(i, n - 1) {
        auto p = v[i];
        ans[p.second] += ans[p.first];
    }
    rep(i, n) {
        cout << ans[i] << " ";
    }
    cout << endl;
}


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

using namespace std;
#define ll long long
#define inf 998244353

int main()
{
    int n;
    scanf("%d",&n);
    int z=(n/500)*1000;
    n=n%500;
    printf("%d\n",z+(n/5)*5);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using Point = pair<int, int>;
const int INF = (int)1e9;

int D, G;
int p[10], c[10];

int main(void){
    cin >> D >> G;
    for(int i = 0; i < D; i++) cin >> p[i] >> c[i];

    int min = INF;

    for(int i = 0; i < (1<<D); i++){
        int num = 0, score = 0;
    
        for(int j = 0; j < D; j++){
            if(i & (1<<j)){
                num += p[j];
                score += 100 * (j + 1) * p[j];
                score += c[j];
            }
        }

        while(score < G){
            for(int j = D - 1; j >= 0; j--){
                if(i & (1<<j)) continue;

                for(int k = 0; k < p[j] && score < G; k++){
                    num += 1;
                    score += 100 * (j + 1);
                }
            }
        }

        if(num < min) min = num;
    }

    cout << min << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define VEC(n)  int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}

int main()
{
    FAST();
    ll int n,m,res=0;


cin>>n>>m;
VEC(n);
sort(v.begin(),v.end());
for(int i=0;i<m;i++)res+=v[i];
cout<<res<<endl;


}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;

int main() {
	// your code goes here
	int k,x,i;
	cin >> k >> x;
	for(i=x-k+1;i<=k+x-1;i++){
		cout << i;
		if(i!=k+x-1) cout << " ";
		else cout << endl;
	}
	return 0;
}

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

int main(){
    ll n ;
    cin>>n;
    ll arr[n+1];
    for(ll i=1;i<=n;i++)cin>>arr[i];
    
    ll dp[n+1];
    for(ll i=0;i<=n;i++)dp[i]=10000000000;
    dp[0]=0;dp[1]=0;
    for(ll i=1;i<=n ;i++){
        if(i+1<=n){
            dp[i+1]=min(dp[i+1],dp[i]+abs(arr[i]-arr[i+1]));
        }
        if(i+2<=n){
            dp[i+2]=min(dp[i+2],dp[i]+abs(arr[i]-arr[i+2]));
        }
    }
    // for(ll i=0;i<=n;i++)cerr<<dp[i]<<" ";
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 1792
n = list(map(int, input().split()))
N = n[0]
M = n[1]
X = []
Y = []
for i in range(M):
    a = list(map(int, input().split()))
    X.append(a[0])
    Y.append(a[1])
v=0
w=0
x=max(X)
y=min(Y)
if y>=x:
    print(y-x+1)
else:
    print(0)






Measured memory_bytes: 56536
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n)cin >> a[i];
	sort(ALL(a), greater<ll>());
	ll x = a[0];
	ll y = 0;
	rep(i, n)
	{
		ll d =abs((x+1)/ 2 - y);
		if (abs(x / 2 - a[i]) < d)
		{
			y = a[i];
		}
	}
	co(x << " " << y);
	return 0;
}


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

#define N 100010
#define pii pair <int, int>
#define fi first
#define se second
int n, a[N];
map <int, int> mp;

int main() {
	while (scanf("%d", &n) != EOF) {
		mp.clear();
		for (int i = 1; i <= n; ++i) {
			scanf("%d", a + i);
			++mp[a[i]];
		}
		vector <pii> vec;
		for (auto it : mp) vec.push_back(it);
		int sze = mp.size();
		if (sze == 1) {
			if (vec[0].fi == 0) {
				puts("Yes");
			} else {
				puts("No");
			}
		} else {
			if (n % 3) {
				puts("No");
			} else {
				if (sze == 2) {
					if ((vec[0].se == vec[1].se * 2 && vec[1].fi == 0) || (vec[0].se * 2 == vec[1].se && vec[0].fi == 0)) {
						puts("Yes");
					} else {
						puts("No");
					}
				} else if (sze == 3) {
					if (vec[0].se == vec[1].se && vec[0].se == vec[2].se && ((vec[0].fi ^ vec[1].fi) == vec[2].fi)) {
						puts("Yes");
					} else {
						puts("No");
					}
				} else {
					puts("No");
				}	
			}
		}
	}
	return 0;
}


Measured memory_bytes: 5372
require 'bigdecimal'

def para?(x1,y1,x2,y2,x3,y3,x4,y4)
  if x1==x2 and x3==x4 then
    return true
  elsif x1==x2 or x3==x4 then
    return false
  else
    return (y2-y1)/(x2-x1) == (y4-y3)/(x4-x3)
  end
end

n=STDIN.gets.to_i
0.upto(n-1){|i|
  x1,y1,x2,y2,x3,y3,x4,y4 = STDIN.gets.chomp.split.map{|x| BigDecimal.new(x)}
  puts para?(x1,y1,x2,y2,x3,y3,x4,y4) ? "YES" : "NO"
}


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

int main(void)
{
    string s;
    cin >> s;
    int n = s.size();
    int edgeCnt = 0;
    for (int i = 1; i < n; i++)
    {
        if(s[i] != s[i-1]){
            edgeCnt++;
        }
    }
    
    cout << edgeCnt << endl;

    return 0;
}


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

int main(){
    using namespace std;
    int N, K; cin >> N >> K;
    vector<double> p;
    for (int i = 0; i < N; i++)
    {
        double v; cin >> v;
        p.push_back(v*(v+1.)/2./v);
    }

    //for(double i : p )cout << i << ' ';
    //cout << endl;

    double sum = 0;
    vector<double> E;
    for (int i = 0; i < K; i++)
    {
        sum += p[i];
    }

    double ans = sum;
    //cout << sum << endl;
    for (int i = 0; i < N-K; i++)
    {
        //cout << p[i+K] << endl;
        sum = sum - p[i] + p[i+K];
        ans = max(ans, sum);
    }
    cout << setprecision(10) << ans << endl;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<chrono>
#include<typeinfo>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds; 
#define lli long long int
#define fr(i,a,b) for(lli i=a;i<b;i++)
#define bfr(i,a,b) for(lli i=a;i>=b;i--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
#define tc int t;cin>>t;while(t--)
#define mod 1000000007LL
#define mod2 998244353LL
#define all(vec) vec.begin(),vec.end()  
#define ld long double
#define pb push_back
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 
lli pmod(lli x,lli y){lli res=1;while(y>0){if(y&1)res = ((res%mod)*(x%mod))%mod;y>>=1;x= ((x%mod)*(x%mod))%mod;}return res;} 
lli power(lli x,lli y){lli res=1;while(y>0){if(y&1)res=res*x;y>>=1;x=x*x;}return res;}



void dfs(vector<lli> adj[],bool vis[],lli u)
{
    if(vis[u])return;
    vis[u]=true;
    fr(v,0,adj[u].size())dfs(adj,vis,adj[u][v]);
}
int main()
{
   
         

    fio
    
    lli n,m;
    cin>>n>>m;
    vector<lli> adj[n];
    fr(i,0,m)
    {
        lli x,y;
        cin>>x>>y;
        x--,y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    bool vis[n];
    memset(vis,false,n);
    lli cnt=0;

    fr(i,0,n)
    if(!vis[i]){dfs(adj,vis,i);cnt++;}


    cout<<cnt-1;

   






  
     

    


     

     


    
      




 

return 0;}

Measured memory_bytes: 10836
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {   if (y & 1)
        res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main()
{
	IOS;
	int n;
	cin>>n;
	ll mi=INT_MAX;
	vector<int>v;
	ll s=0;
	rep(i,0,n-1)
	{
		int x;cin>>x;
		v.pb(x);
		
	}
	int x=v[0],y=v[n-2];
	v.insert(v.begin(),x);
	v.pb(y);
	for(int i=1;i<v.size();i++)
	{
		s+=min(v[i],v[i-1]);
	}
	cout<<s;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
ll n;
  cin>>n;
  vll a(n);
  map<ll,ll> cnt;
  ll M=0;
  ll ans=inf;
  rep(i,0,n){
    cin>>a[i];
    a[i]-=i+1;
    cnt[a[i]]++;
  }
  sort(all(a));
  int l=0;///a[i]以下の数
  l++;
  rep(i,0,n){
   
    M+=abs(a[i]-a[0]);
  }
  ans=M;
  rep(i,1,n){
    ll sa=a[i]-a[i-1];
    M=M+sa*(l);
    M=M-sa*(n-l);   
      
      
      
      l++;
    chmin(ans,M);
    //cout<<M<<sa<<l<<endl;
  }
  
  
   cout<<ans<<endl;
}

Measured memory_bytes: 17240
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int sy[4] = { 0,1,0,-1 };
const ll atcoder = 1e9 + 7;

#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int main(){

	string s, t;
	cin >> s >> t;

	if(s.length() > t.length())pr("GREATER");
	else if (s.length() < t.length())pr("LESS"); 
	else {
		if (s > t)pr("GREATER");
		else if (s < t)pr("LESS");
		else pr("EQUAL");
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long X)
{
    bool dp[101000] = {false};

    dp[0] = true;

    for (int i = 0; i < 100010; i++)
    {
        if (dp[i])
        {
            dp[i + 100] = true;
            dp[i + 101] = true;
            dp[i + 102] = true;
            dp[i + 103] = true;
            dp[i + 104] = true;
            dp[i + 105] = true;
        }
    }

    if(dp[X]){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}

int main()
{
    long long X;
    scanf("%lld", &X);
    solve(X);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
pair<int,int> x[100010];
priority_queue<int> pq;
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>x[i].first>>x[i].second;
        x[i].first=m-x[i].first+1;
    }
    sort(x,x+n);
    long long ans=0;
    for(int i=m,j=n-1;i;i--){
        while(j>=0){
            if(x[j].first<i)break;
            pq.push(x[j].second);
            j--;
        }
        if(pq.size())ans+=pq.top(),pq.pop();
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1660
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){

	int H,W;

	for(;;){
		cin >> H >> W;
		if(H == 0 && W == 0) break;

		for(int i=0;i<H;i++){
			if(i == 0 || i == H-1){
				for(int j=0;j<W;j++){
					cout << "#";
				}
			}
			else{
				for(int j=0;j<W;j++){
					if(j == 0 || j == W-1){
						cout << "#";
					}
					else{
						cout << ".";
					}
				}
			}
			cout << endl;
		}

		cout << endl;

	}

	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
ll dp[1010][1010];
bool st[1010][1010];
int h,w;
int main() {
    cin >> h >> w;
    string temp;
    for(int i = 1; i <= h; i ++) {
        cin >> temp;
        for(int j = 1; j <= w; j ++) {
            if(temp[j-1] == '#') {
                st[i][j] = true;
            }
        }
    }
    dp[0][1] = 1;
    for(int i = 1; i <= h; i ++) {
        for(int j = 1; j <= w; j ++) {
            if(st[i][j]) continue;
            if(!st[i-1][j]) {
                dp[i][j] += dp[i-1][j];
                dp[i][j] %= mod;
            } 
            if(!st[i][j-1]) {
                dp[i][j] += dp[i][j-1];
                dp[i][j] %= mod;
            }
        }
    }
    cout << dp[h][w] % mod<< endl;
    return 0;
}

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

#define int long long

struct UnionFind {
  vector<int> p, ranks;

  UnionFind(int n) : p(n), ranks(n, 0) {
    for(int i = 0; i < n; ++i)
      p[i] = i;
  }

  int find_set(int x) {
    return p[x] == x ? x : p[x] = find_set(p[x]);
  }

  bool is_same_set(int a, int b) {
    return find_set(a) == find_set(b);
  }

  void unite(int a, int b) {
    int x = find_set(a), y = find_set(b);
    if(x == y)
      return;
    if(ranks[x] > ranks[y])
      p[y] = x;
    else {
      p[x] = y;
      if(ranks[x] == ranks[y])
	++ranks[y];
    }
  }
};

signed main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  vector<int> v(n);
  for(int i = 0; i < n; ++i)
    cin >> v[i];
  for(int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    uf.unite(a-1, b-1);
  }

  int ans = 0;
  for(int i = 0; i < n; ++i) {
    ans += uf.is_same_set(v[i]-1, i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main() {
  int n, i, cnt;
  int a[10004];
  double ave_num;

  while (1) {
    scanf("%d", &n);
    if (n == 0) { break; }

    // 最初は 0 を入れる
    ave_num = 0;

    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      ave_num += a[i];
    }

    ave_num /= n;
    cnt = 0;
    for (i = 0; i < n; i++) {
      if (a[i] <= ave_num) {
        cnt++;
      }
    }
    printf("%d\n", cnt);
  }

  return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define N 100005
#define ll long long
using namespace std;
ll a[N],ans[N],mx;
int n,m,jdb[N];
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for (int i=2;i<=n;i++){
		jdb[i]=jdb[i-1];
		for (;a[i]+1ll*jdb[i]*m<a[i-1];jdb[i]++);
		a[i]+=1ll*jdb[i]*m;
	}
	for (int i=2;i<=n;i++){
		int l=a[i-1]%m+1,r=a[i]%m;
		if (l!=m) ans[l+1]++;
		if (r!=m){
			ans[r+1]-=(m+r-l)%m+1;
			ans[r+2]+=(m+r-l)%m;
		}
		if (l>r){
			ans[1]+=m-l+1;
			ans[2]-=m-l;
		}
	}
	for (int i=1;i<=m;i++) ans[i]+=ans[i-1];
	for (int i=1;i<=m;i++) ans[i]+=ans[i-1];
	for (int i=1;i<=m;i++)
		mx=max(mx,ans[i]);
	printf("%lld\n",a[n]-a[1]-mx);
}

Measured memory_bytes: 2176
/*
Look at the star
Look at the shine for U
*/
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define sl(x) scanf("%I64d",&x)
using namespace std;
const int N = 2e6+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}

int main()
{
	int n,t,i,j,k,l;
	cin >> n >> l;
	int minn = INF;
	for(i = 0;i < n;i++)
	{
		cin >> j >> k;
		if(k <= l)
			minn = min(minn,j);
	}
	if(minn == INF) puts("TLE");
	else
	cout << minn << endl;
}

Measured memory_bytes: 256
//IN THE NAME OF GOD;
//Test By Dev-C++5.11
#include<bits/stdc++.h>
#define ll  long long
#define isc ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ld long double
#define ss string
#define ww while
#define vl vector<ll>
#define pb push_back
#define in insert
#define itr iterator
#define gt goto
#define rep(i,n,j) for(ll i=n;i<j;i++)
#define tep(i,n,j) for(ll i=n;i>=j;i--)
#define co(n) cout << n ;
#define pll pair<ll,ll>
#define bft bool f=true
#define bff bool f=false
using namespace std;

ll bmm(ll a, ll b) {
	if (b == 0) return a;
	else return bmm(b, a%b);
}
ll kmm(ll a, ll b) {
	return(a*b) / bmm(a, b);
}

const ll mod = 1e9 + 7;
const ll MAXN = 2e5+5;

ll n,ans=9e6,x,y,z;

int main() {
	isc;
	cin >> n;
	x=n;y=1;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			x=n/i;
			y=i;
		}
	}
	cout << y+x-2;
	return 0;
}


Measured memory_bytes: 256