akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdlib>
#include <bits/stdc++.h>
#include <algorithm>
#include <cctype>
using namespace std ;
bool ch(long long int a[] , int b , int ex){
    for (int j = 0; b > 0 ; j++)
    {
        for(int i = 0 ; i < ex ; i++ ){
        if(a[i] == b%10 ) return true ;
        }
        b = b/10 ;
    }
    return false ;
    
}

int main(){
    long long int n , count , temp ;
    cin >> n >> count ;
    long long int *a = (long long int *)malloc(count * sizeof(long long int)) ;
    for (int i = 0; i < count; i++)
    {
        cin >> a[i] ;
    }
    temp = n ;
    while (ch(a , temp , count))
    {
        temp++ ;
    }
    cout << temp ;
    return  0 ;
    }

    


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int N, ans;
  cin >> N;
  ans = 0;
  for (int i = 1; i < N; ++i) {
    int tmp = N - i;
    double sq = sqrt(tmp);
    for (int j = 1; j < N; ++j) {
      if (j * j > tmp) {
        break;
      }
      if (j * j == tmp) {
        ++ans;
      }
      else if (tmp % j == 0) {
        ans += 2;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

#define reint register int
#define coint const int

using namespace std;

typedef long long ll;

coint SIZE = 200000 + 5;

struct Node {
    int tim, dead;

    bool operator < (const Node &nd) const {
        return dead < nd.dead;
    }
};

Node li[SIZE];

inline int getint(void) {
    reint x = 0, ch = getchar();
    for (; ch < '0' || ch > '9'; ch = getchar());
    for (; ch >= '0' && ch <= '9';
            x = (x << 1) + (x << 3) + ch - '0', ch = getchar());
    return x;
}

int main(void) {
    int n = getint();
    for (reint i = 1; i <= n; ++i) li[i].tim = getint(), li[i].dead = getint();
    ll tick = 0;
    sort(li + 1, li + n + 1);
    for (reint i = 1; i <= n; ++i) {
        tick += li[i].tim;
        if (tick > li[i].dead) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}



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

int main(){
    string s;
    cin >> s;
    string ans = "Yes";

    rep(i,s.size()){

    if(s.size() %2 == 1) {
        ans = "No";
        break;
        }
    if((i%2 == 0) && (s[i]!='h')){
        ans = "No";
        break;
    }   
    else if(i%2 == 1 && s[i] != 'i'){
        ans = "No";
        break;
    }
    
    }
   
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int a, b;
	char op;
	while(true)
	{
		cin >> a >> op >> b;
		if(op == '?')
			break;
		else if(op == '+')
			cout << a + b << endl;
		else if(op == '-')
			cout << a - b << endl;
		else if(op == '/')
			cout << a / b << endl;
		else if(op == '*')
			cout << a * b << endl;
	}
}


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

int main()
{
	int n, m;
	cin >> n >> m;
	char c;
	vector<vector<int>> d(m, vector<int>(n + 2));
	for (int i = 0; i < m; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> c;
			if (c == 'E') {
				d[i][j] = 1;
			}
		}
		d[i][n + 1] = 1;
	}
	for (int i = 0; i < m; i++) {
		for (int j = 1; j <= n + 1; j++) {
			d[i][j] += d[i][j - 1];
		}
	}
	int res, merr = n * m;
	for (int i = 1; i <= n + 1; i++) {
		int err = 0;
		for (int j = 0; j < m; j++) {
			err += d[j][i - 1] + (n + 2 - i - (d[j][n + 1] - d[j][i - 1]));
		}
		if (err < merr) {
			merr = err;
			res = i - 1;
		}
	}
	cout << res << ' ' << res + 1 << endl;
	return 0;
}

Measured memory_bytes: 6836
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b;
    cin >> a >> b;
    cout << ((a * 3 + b) / 2);
    return 0;
}

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

int main(){
    double w,h,x,y ;
    cin >>w >>h>>x>>y ;
    if(x == w/2 && y == h/2){
        cout << fixed << setprecision(6) << w*h/2 << " "<< 1 <<'\n';
    }else{
        cout << fixed << setprecision(6) << w*h/2 << " "<< 0 <<'\n';
    }
    return 0 ;
}


Measured memory_bytes: 256
import math

H,W=(int(i) for i in input().split())
li=[]
for i in range(0,H):
    li2=[]
    S1=input()
    for j in range(0,W):
        li2.append(S1[j])
        #print(li2)

    li.append(li2)
    
#print(li)
Flag=False
#横探索
for i in range(0,H):
    
    for j in range(0,W):
        if (li[i][j]=="." or li[i][j]=="Remove"):
            Flag=True
        else:
            Flag=False
            break

    if Flag==True:
         for j in range(0,W):
            li[i][j]="Remove"
          


    
#横探索
for i in range(0,W):
    
    for j in range(0,H):
         if (li[j][i]=="." or li[j][i]=="Remove"):
            Flag=True
         else:
            Flag=False
            break

    if Flag==True:
         for j in range(0,H):
            li[j][i]="Remove"
       
for i in range(0,H):
    for j in range(0,W):
        if (li[i][j]=="Remove"):
            li[i][j]=""

#print("ans")
for i in range(0,H):
    count=0
    for j in range(0,W):
        
        if (li[i][j]==""):
            Flag=True
            count+=1
        else:
            Flag=False
        
        print(str(li[i][j]),end="")

    if count!=W:
        print("")   


    
    


Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main() {
  Real a, b;
  cin >> a >> b;
  Bint t = static_cast<Bint>(a * b);
  cout << t << endl;
}


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

const int mod = 1000000007;

int main () {
  int n, m;
  while ( cin >> n >> m ) {
    vector<vector<char>> grid(n, vector<char>(m));
    vector<vector<int>> dp(n, vector<int>(m));
    for ( auto& i : grid ) for ( auto& j : i ) cin >> j;

    dp[0][0] = (grid[0][0] == '.');
    for ( int i = 1; i < m; ++i )
      dp[0][i] = ((grid[0][i] == '.') ? dp[0][i - 1] : 0);
    for ( int i = 1; i < n; ++i ) 
      dp[i][0] = ((grid[i][0] == '.') ? dp[i - 1][0] : 0);
    
    for ( int i = 1; i < n; ++i ) {
      for ( int j = 1; j < m; ++j ) {
        if ( grid[i - 1][j] == '.' ) {
          dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod; 
        }
        if ( grid[i][j - 1] == '.' ) {
          dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
        }
      }
    }

    cout << dp[n - 1][m - 1] << endl;
  }
  return 0;
}

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

#define Fast           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO             freopen("in.txt", "r", stdin)
#define FC             freopen("out.txt", "w", stdout)
#define aise           cout<<"aise"<<endl
#define pb             push_back
#define pf             push_front
#define ppb            pop_back
#define ppf            pop_front
#define mp             make_pair
#define ll             long long
#define all(x)         x.begin(), x.end()
#define mset(v, a)     memset(v, a, sizeof(v))
#define pll            pair< ll, ll >
#define pd             pair< double, double >
#define ff             first
#define ss             second
#define pi             acos(-1.0)
#define mxN            2010
#define inf            1e14
#define mod            1000000007

//NCR iterative
/*voidcomb_table(intN)
{
    for(inti=0; i<=N; ++i)
    {
        for(intj=0; j<=i; ++j)
        {
            if(j==0or j==i)
            {
                C[i][j]=1LL;
            }
            else
            {
                C[i][j]=(C[i-1][j-1]+C[i-1][j]);
            }
        }
    }
}*/


//NCR recursive
/*ll dp[55][55];

ll NCR(ll n,ll r)
{

    if(n==r)
        return dp[n][r]=1;
    if(r==0)
        return dp[n][r]= 1;
    if(r==1)
        return dp[n][r]=n ;
    if(dp[n][r] != -1)
        return dp[n][r];
    return dp[n][r] = NCR(n-1,r)+NCR(n-1,r-1);
}*/

//Sieve:
/*bool Flag[1000010];
vector<ll> Prime;

void sieve()
{

    ll val=sqrt(1000010);
    for(ll i=4;i<=1000005; i+=2) Flag[i]=1;
    for(ll i=3;i <= val;i+=2)
    {

        if(Flag[i]==0)
        {

            for(ll j=i*i;j<=1000005;j+=i) Flag[j]=1;
        }
    }
    Flag[1]=1;
    for(ll i=1;i<=1000000;i++)
        if(Flag[i]==0) Prime.pb(i);
}*/


//Conversion
/*string bin(ll x)
{

    string ret;
    while(x)
    {

        ll t=x%2;
        char c;
        if(t==1)
            c='1';
        else
            c='0';
        ret.pb(c);
        x/=2;
    }
    reverse(all(ret));
    return ret;
}*/

/*ll lcm(ll x, ll y)
{

    ll ret=__gcd(x,y);
    return (x*y)/ret;
}*/

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

ll powr(ll x, ll y)
{

    ll ret=1;
    for(ll i=0;i<y;i++) ret*=x;
    return ret;
}

int main()
{

   ll n;
   cin >> n;
   vector<ll> v;
   ll sm=0;
   map<ll,ll> mp;
   for(ll i=0;i <n ;i++)
   {

       ll x;
       cin >> x;
       v.pb(x);
       sm+=x;
       mp[i]=x;
   }
   ll m;
   cin >> m;
   while(m--)
   {

       ll i, x;
       cin >> i >> x;
       i--;
       sm-=mp[i];
       sm+=x;
       cout << sm << endl;
       sm-=x;
       sm+=mp[i];
   }
}


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

int main() {
	long long int N, a=1, b;
	cin >> N;
	for (int i = 1; i<=sqrt(N); i++) {
		if (N % i == 0) {
			a = i;
		}

	}
	b = N / a;
	

	cout << a - 1 + b - 1;
}

Measured memory_bytes: 256
using System;
class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] n = new int[3];
        for (int i = 0; i < 3; i++)
            n[i] = int.Parse(str[i]);
        Array.Sort(n);
        Console.WriteLine((n[0] == 5 && n[1] == 5 && n[2] == 7) ? "YES" : "NO");
    }
}

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

#define vint vector<int>
#define vvint vector<vint>
#define sint stack<int>
#define qint queue<int>
#define rep(i, n) for(int i=0;i<(int)(n);i++) // 繰り返し処理
#define all(x) (x).begin(),(x).end() // 全体 こんな感じで使う→sort(all(a));
#define ct(a) cout << a << endl
#define iceil(a,b) (a+(b-1))/b //int ceil : 繰り上げの割り算 通常のceilではceil((7.0/2.0))のようにしなければならなかった。
#define ld long double
#define ll long long
vint CinLine(int N){vint v(N);for(int i=0;i<N;i++){cin >> v.at(i);}return v;}//cin line 連続でvectorに格納
void CoutLine(vint v){for(int i=0;i<v.size()-1;i++){cout<<v.at(i)<<" ";}cout << v.at(v.size()-1)<<endl;}

bool IsOver2(ll a, ll b, ll lim){
    if(b > lim/a){
        return true;
    }else{
        return false;
    }
}

bool IsOver(ll a, ll b){
    ll x = b * a;
    return (x/a != b);
}

bool IsOver_ng(ll a, ll b){
    ll x = b * a;
    if(x/a != b){
        return true;
    }else{
        return false;
    }
}


void Main(){
    ll limit = pow(10,18);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0; i<n;i++){
        cin >> a[i];
        if(a[i] == 0){
            ct(0);
            return;
        }
    }
    ll ans = 1;
    for(ll i = 0; i < n; i++){
        if(IsOver2(ans,a[i], limit)){
        //if(IsOver(ans,a[i])){
            ct(-1);
            return;
        }else {
            ans *= a[i];
            if ( ans > limit ){
                ct(-1);
                return;
            }
        }
    }
    ct(ans);
    return;
}

int main() {
    Main();
}


Measured memory_bytes: 4048
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int T, N, K, cnt;
string S;
int main(){
    cnt = 0;
    cin >> S;
    int ans[26] = {0};
    REP(i, S.size()){
        REP(j, S.size()){
            if(S[i] == S[j] && i != j){
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;
    return 0;
}

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

int main() {
    long n, m;
    cin >> n >> m;
    long res;
    if (n == 2 || m == 2) {
        res = 0L;
    } else if (n == 1 && m == 1) {
        res = 1L;
    } else if (n == 1) {
        res = m - 2;
    } else if (m == 1) {
        res = n - 2;
    } else {
        res = (m-2) * (n-2);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: usize,
        a: [usize;n]
    }
    let mut v = vec![0;n+1];
    for i in &a {
        v[i-1] += 1;
    }
    let vc = v.iter().map(|a| {
        if *a < 2 { 0 } else { a * (a-1usize) / 2 }
    }).collect::<Vec<usize>>();
    // println!("{:?}", vc);
    let sm = vc.iter().sum::<usize>();
    for i in &a {
        let i = i-1;
        let a = (v[i] as i64) - 1;
        let c = if a < 2 { 0 } else { a * (a-1) / 2 } as usize;
        println!("{}", sm - (vc[i] - c));
    }
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 14844
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll a;
  string S;
  cin >> a >> S;
  string ans = a >= 3200 ? S : "red";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>

using namespace std;

typedef long long ll;

int n,m;
ll a[200005],s[200005],b[200005];

int main(){
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		s[i]=s[i-1]+a[i];	
	}
	ll k=1,r=0;
	ll ans=1e18,cnt=0;
	for(int i=1;i<=n;i++){
		int res=s[i]+r;
		if(k>0){
			
			if(res<=0){
				r+=-res+1;
				cnt+=-res+1;
			}
		}else{
			if(res>=0){
				r-=(res+1);
				cnt+=(res+1);
			}
		}
		k=-k;
	}
	ans=min(ans,cnt);
	k=-1,r=0,cnt=0;
	for(int i=1;i<=n;i++){
		int res=s[i]+r;
		if(k>0){
			
			if(res<=0){
				r+=-res+1;
				cnt+=-res+1;
			}
		}else{
			if(res>=0){
				r-=(res+1);
				cnt+=(res+1);
			}
		}
		k=-k;
	}
	ans=min(ans,cnt);
	printf("%lld\n",ans);
	
	return 0;
	
} 

Measured memory_bytes: 2816
#include <stdio.h>

int selectionSort(int A[], int n){
    int i, j, t, sw=0, min_i;
    for(i=0;i<n-1;i++){
        min_i=i;
        for(j=i;j<n;j++){
            if(A[j]<A[min_i]) min_i=j;
        }
        t=A[i];A[i]=A[min_i];A[min_i]=t;
        if(i!=min_i) sw++;
    }
    return sw;
}

int main(){
    int A[100], n, i, sw;
    scanf("%d", &n);
    for(i=0;i<n;i++)scanf("%d", &A[i]);
    sw=selectionSort(A,n);
    for(i=0;i<n;i++){
        if(i>0)printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", sw);
    return 0;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const int N = 55;
string s,t="Yes";
int n, d[N];
vector<P> p;
int a[N], b[N], c[N];

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  rep(i,n) {cin >> a[i]; a[i]--;}
  rep(i,n) cin >> b[i];
  rep(i,n-1) cin >> c[i];
  ll result=0;
  rep(i,n) {
    result += b[a[i]];
    if(i==0) continue;
    if(a[i] - a[i-1] == 1) {
      result += c[a[i-1]];
    }
  }
  pl(result);
  br();
}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t,u;
  cin >>s>>t>>a>>b>>u;
  if(s==u){
    a--;
  }else{
    b--;
  }
  cout <<a<<' '<<b;
}

Measured memory_bytes: 3664
#include <stdio.h>          // printf(), scanf()

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

	return gcd(b, a % b);
}

int
lcm(int a, int b)
{
	if (a < b)
		return a * b / gcd(b, a);

	return a * b / gcd(a, b);
}

int
main(int argc, char** argv)
{
	int a;
	int n;
	int i;

	scanf("%d", &n);
	scanf("%d", &a);

	int l = a;
	for (i = 1; i < n; ++i)
	{
		scanf("%d", &a);
		l = lcm(a, l);
	}

	printf("%d\n", l);
	return 0;
}

Measured memory_bytes: 596
use proconio::{input, marker::Bytes};


fn main() {
    input!{
        s: Bytes,
        t: Bytes,
    };
    let mut ans = 0;
    for (s, t) in s.into_iter().zip(t.into_iter()) {
        if s != t {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2832
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

/*
区間1の長方形は1回ずつ
区間2の長方形は端除いて2回ずつ
区間3の長方形は1, 2, 3...

1 1 1 ... 1 1 1
1 2 2 ... 2 2 1
1 2 3 ... 3 2 1

1 2 3 ... n/2 n/2 ... 3 2 1

2 * ( n 2n-1 3n-3 4n-6 5n-10 )

1 1 1 1 1 1 1 1 1
1 2 2 2 2 2 2 2 1
1 2 3 3 3 3 3 2 1
1 2 3 4 4 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 4 4 3 2 1

*/

int main() {
    ll n, m; cin >> n >> m;
    ll D = 1e9+7;
    vector<ll> x(n), y(m);
    for (ll i = 0; i < n; i++) cin >> x[i];
    for (ll i = 0; i < m; i++) cin >> y[i];

    for (ll i = 0; i < n-1; i++) x[i] = x[i+1]-x[i];
    for (ll i = 0; i < m-1; i++) y[i] = y[i+1]-y[i];

    ll sx = 0, sy = 0; n--; m--;
    for (ll j = 0; j < n; j++) {
        ll i = min(j,n-1-j);
        sx = (sx+((i+1)*n-i*(i+1))*x[j]) % D;
    }
    for (ll j = 0; j < m; j++) {
        ll i = min(j,m-1-j);
        sy = (sy+((i+1)*m-i*(i+1))*y[j]) % D;
    }

    cout << sx * sy % D << endl;









}


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

int main()
{
	ll n,K;
	cin>>n>>K;
	ll ans[n];
	ll h[n];
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
	}
	ans[0] = 0;
	ans[1] = abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
	{
		ll min_ = 1e9;
		for(int j = max(i-K,ll(0));j<=i-1;j++)
		{
			if(min_> ans[j]+abs(h[i]-h[j]))
				min_ = ans[j]+abs(h[i]-h[j]);
		}
		ans[i] = min_;
	}
	cout<<ans[n-1]<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main(){
	ll h,w,mod=pow(10,9)+7,n;
	cin>>n;
	vector<long double> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	vector<vector<long double>> p(n+1,vector<long double>(n+1,(long double)0));
	p[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(!j)
			p[i][j]=p[i-1][j]*(1-a[i-1]);
			else {
				p[i][j]=p[i-1][j-1]*a[i-1]+p[i-1][j]*(1-a[i-1]);
			}
//			cout<<p[i][j]<<" ";
		}
//		cout<<endl;
	}
	if(n%2)
	cout<<setprecision(20)<<accumulate(p[n].begin()+ceil(n/2.0),p[n].end(),(long double)0)<<endl;
	else 
	cout<<setprecision(20)<<accumulate(p[n].begin()+n/2+1,p[n].end(),(long double)0)<<endl;
}


Measured memory_bytes: 144356
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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

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

	if (S[0] != 'A'){
		cout << "WA" << endl;
		return 0;
	}
	ll Ccnt = 0;
	rep(i, 1, S.size()){
		if ((2 <= i) && (i <= (S.size() - 2))){
			if (S[i] == 'C') Ccnt++;
		}
		if (('a' <= S[i]) && (S[i] <= 'z')){
		}else{
			if (S[i] != 'C'){
				cout << "WA" << endl;
				return 0;
			}
		}
	}
	if (1 != Ccnt){
		cout << "WA" << endl;
		return 0;
	}
	cout << "AC" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

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

    for(int cx = 0; cx <= 100; ++cx){
        for(int cy = 0; cy <= 100; ++cy){
            int H;
            for(int i = 0; i < n; ++i){
                if(h[i] == 0)   continue;
                int height = h[i] + abs(cx - x[i]) + abs(cy - y[i]);
                H = height;
                break;
            }
            bool ok = true;
            for(int i = 0; i < n; ++i){
                int height = max(H - abs(cx - x[i]) - abs(cy - y[i]), 0);
                if(h[i] != height){
                    ok = false;
                    break;
                }
            }
            if(ok){
                cout << cx << " " << cy << " " << H << endl;
                return 0;
            }
        }
    }
}

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

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

int N;
vector<ll> A;
vector<pi> P;
vector<vi> C;

void input_init(void) {
	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; ++i) {
		string s;
		cin >> s;
		int pos = s.find('.', 0);
		if (pos != string::npos) {
			int l_cnt = s.length() - 1 - pos;
			int z_cnt = 9 - l_cnt;
			string s2 = s.substr(0, pos) + s.substr(pos + 1) + string(z_cnt, '0');
			A[i] = stoll(s2);
		}
		else {
			s = s + string(9, '0');
			A[i] = stoll(s);
		}
	}
}

void make_data(void) {
	P.resize(N);
	C.resize(19, vi(19, 0));
	for (int i = 0; i < N; ++i) {
		int x = 0;
		int y = 0;
		ll z = A[i];
		while (true) {
			if (z % 2 != 0)
				break;
			z /= 2;
			++x;
		}
		while (true) {
			if (z % 5 != 0)
				break;
			z /= 5;
			++y;
		}
		P[i] = make_pair(x, y);
		if (x > 18)
			x = 18;
		if (y > 18)
			y = 18;
		++(C[x][y]);
	}
}

ll solve(void) {
	ll all_cnt = (ll)0;
	for (int i = 0; i <= 18; ++i) {
		for (int j = 0; j <= 18; ++j) {
			int x = 18 - i;
			int y = 18 - j;
			for (int k = x; k <= 18; ++k) {
				for (int l = y; l <= 18; ++l)
					all_cnt += (ll)C[i][j] * C[k][l];
			}
		}
	}
	ll same_cnt = (ll)0;
	for (int i = 0; i < N; ++i) {
		int x = 2 * P[i].first;
		int y = 2 * P[i].second;
		if (x >= 18 && y >= 18)
			++same_cnt;
	}
	ll cnt = (all_cnt - same_cnt) / 2;
	return cnt;
}

int main(void) {
	input_init();
	make_data();
	ll ans = solve();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 6332
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
typedef long long int ll;
ll dfs(int day,int r1,int r2);
ll dp[101][4][4];
int n,k;
map<int,int> plan;
int main(){
	cin >> n >> k;
	for(int i=0;i<k;i++){
		int a,b; cin >> a >> b;
		a--; plan[a] = b;
	}
	memset(dp,-1,sizeof(dp));
	cout << dfs(0,0,0) << endl;
}

ll dfs(int day,int r1,int r2){
	if(day==n) return 1;
	if(dp[day][r1][r2] != -1) return dp[day][r1][r2];
	if(plan[day] != 0){
		if(r1 == r2 && r1 == plan[day]) return 0;
		else return dfs(day+1,plan[day],r1)%10000;
	}
	ll ret = 0;
	for(int i=1;i<=3;i++){
		if(r1 == r2 && r1 == i) continue;
		ret += dfs(day+1,i,r1)%10000;
	}
	return dp[day][r1][r2] = ret%10000;
}

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

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

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 1111, inf = 1000111222;

int m[max_n];
int n;


int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> m[i];
    }
    int ans = inf;
    for (int T = 0; T + 1 < n; ++T) {
        int s1 = 0;
        int s2 = 0;
        for (int i = 0; i <= T; ++i) {
            s1 += m[i];
        }
        for (int i = T + 1; i < n; ++i) {
            s2 += m[i];
        }
        ans = min(ans, abs(s2 - s1));
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}
int in[10][10];

int a[3][5][5] = {
    /*Small*/
  {{ 0, 0, 1, 0, 0},
   { 0, 1, 1, 1, 0},
   { 0, 0, 1, 0, 0}},
  //*midium*/
  {{ 0, 0, 1, 1, 1},
   { 0, 0, 1, 1, 1},
   { 0, 0, 1, 1, 1}},
  /*large*/
  {{ 0, 0, 1, 0, 0},
   { 0, 1, 1, 1, 0},
   { 1, 1, 1, 1, 1},
   { 0, 1, 1, 1, 0},
   { 0, 0, 1, 0, 0}},
};
bool check(int x, int y, int t){
    rep(i,5)rep(j,5){
        int p = x+i, q = y+j-2;
        if(p < 0 || p > 9 || q < 0 || q > 9){
            if(a[t][i][j])return false;
        }else if(in[p][q] - a[t][i][j] < 0)return false;
    }
    return true;
}

void paint(int x, int y, int t){
    rep(i,5)rep(j,5)in[x+i][y+j-2] -= a[t][i][j];
}
void repaint(int x, int y, int t){
    rep(i,5)rep(j,5)in[x+i][y+j-2] += a[t][i][j];
}

bool f(int x, int y, int n){
    if(n < 0)return false;
    if(x == 10)return n == 0;
    if(in[x][y] == 0)return f(x+(y == 9), (y+1)%10, n);
    rep(i,3){
        if(check(x,y,i) == false)continue;
        paint(x,y,i);
        if(f(x,y,n-1)){
            if(i == 0)cout << y << " " << x+1;
            if(i == 1)cout << y+1 << " " << x+1;
            if(i == 2)cout << y << " " << x+2;
            cout << " " << i+1 << endl;
            return true;
        }
        repaint(x,y,i);
    }
    return false;
}

signed main(void) {
    int n;
    cin >> n;
    rep(i,10)rep(j,10)cin >> in[i][j];
    f(0,0,n);
}



Measured memory_bytes: 3120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class CPoll
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var sDic = new Dictionary<string, int>();
            for (int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                if (sDic.ContainsKey(s))
                {
                    sDic[s]++;
                }
                else
                {
                    sDic.Add(s, 1);
                }
            }

            int maxCount = sDic.Values.Max();
            var answers = new List<string>();
            foreach (var kv in sDic)
            {
                if (kv.Value == maxCount)
                {
                    answers.Add(kv.Key);
                }
            }

            answers.Sort(StringComparer.Ordinal);
            Console.WriteLine(string.Join("\n", answers));
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 49016
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <unordered_map>
#include <utility>
#include <queue>

int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int32_t N, K;
  std::cin >> N >> K;
  using elem_cnt_map_type = std::unordered_map<int32_t, int32_t>; 
  elem_cnt_map_type elem_cnt_map;
  for (int32_t i = 0; i < N; i++) {
    int32_t a_tmp = 0;
    std::cin >> a_tmp;
    elem_cnt_map[a_tmp]++;
  }

  std::priority_queue<int32_t> pqueue; 
  std::for_each (elem_cnt_map.begin(), elem_cnt_map.end(), [&pqueue](elem_cnt_map_type::value_type p) {
    pqueue.push(p.second);
  });

  int32_t sum_topk = 0;
  for (int32_t i = 0; i < K; i++){
    if (pqueue.empty()) break;
    sum_topk += pqueue.top();
    pqueue.pop();
  }

  int32_t res = N - sum_topk;
  std::cout << res << std::endl;

  return 0;
}


Measured memory_bytes: 10312
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b)

for i in range(n-1):
  if a[i+1] == a[i] + 1:
    ans += c[a[i]-1]

print(ans)

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

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

    ll ans=0;
    rep(i, N+1){
        if(i!=0) if(!(i%3==0 || i%5==0)) ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

bool check(long long a,long long b,vector<long long>& h,long long k)
{
    long long sum = 0;

    for(long long i = 0;i < h.size() && h[i] - b*k > 0;i++)
    {
	sum += (long long)ceil((1.0*h[i]-b*k)/(a-b));
    }

    if(sum > k)
	return false;

    return true;
}

int main(void)
{
    long long n,a,b;
    vector<long long> h;
    cin>>n>>a>>b;

    for(long long i = 0;i < n;i++)
    {
	long long temp;
	cin>>temp;

	h.push_back(temp);
    }

    sort(h.begin(),h.end(),greater<long long>());

    long long max = h[0]/b+1;
    long long min = 1;
    long long mid;
    while(min < max) {
	mid = (max+min) / 2;
	if(check(a,b,h,mid))
	    max = mid;
	else
	    min = mid+1;
    };

    cout<<min<<endl;

    return 0;
}



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

int main(){
  int N,Y;
  cin >> N >> Y;
  rep(i,Y/10000+1) rep(j,(Y-10000*i)/5000+1){
    if(10000*i+5000*j+1000*(N-i-j)==Y) {
      cout << i << " " << j << " " << N-i-j << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;  
  return 0;
}


Measured memory_bytes: 256
//BISMILLAHIR RAHMANIR RAHIM
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <list>
#define cos(a) cos(a*pi/180)
#define sin(a) sin(a*pi/180)
#define tan(a) tan(a*pi/180)
#define cosi(a) acos(a)/(pi/180)
#define sini(a) asin(a)/(pi/180)
#define tani(a) atan(a)/(pi/180)
#define mem(a, b) (memset(a, b, sizeof(a)))
#define read (freopen("input.txt", "r", stdin))
#define write (freopen("output.txt", "w", stdout))
#define fastIO (ios::sync_with_stdio(0), cin.tie(0), cout.tie(0));
#define dis(x1, y1, x2, y2) ((x1-x2) * (x1-x2)) + ((y1-y2) * (y1-y2))
#define debug (printf("PINK FLOYD:)\n"))
#define iosflags (cout<<setiosflags(ios::fixed)<<setprecision(8))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define pi 3.1415926535897932384
#define INF 2147483647
#define EPS 1e-8
#define MOD 1000000007
#define MAX 100005
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

const int inf = 1<<28;
int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
int dx[] = { -1, 1, 0, 0 };
int dy[] = { 0, 0, -1, 1 };
int fx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
int fy[] = { -1,  1, -2,  2, -2,  2, -1,  1 };

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int main()
{
	fastIO;
	int n, a, idx = 1;

    cin>>n;

    multiset<int> ms;

    for(int i = 0; i < n; i++){
        cin>>a;
        multiset<int> :: iterator it = ms.lower_bound(a);
        if(it == ms.begin())
            ms.insert(a);
        else{
            it--;
            //cout<<*it<<endl;
            ms.erase(it);
            ms.insert(a);
        }
    }

    cout<<ms.size()<<endl;

    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000


int main(){

	string s;
	cin>>s;
	
	for(int i=0;i<s.size();i+=2){
		cout<<s[i];
	}
	cout<<endl;
		
	
    return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>

#define REP(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main() {
	int N; cin >> N;
	map<int, int>mp;//keyが直径でvalueが出現回数
	REP(i, N) {
		int d; cin >> d;
		mp[d]++;
	}
	int ans = mp.size();
	cout << ans << endl;


	/*for (auto x : mp) {
		cout << x.first << " " << x.second << endl;
	}*/
}


Measured memory_bytes: 384
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, a) for (ll i = a; i >= 0; --i)
#define all(obj) begin(obj), end(obj)
#define rall(obj) rbegin(obj), rend(obj)
#define pb push_back
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    //
    //
    ll N;
    cin >> N;
    vector<ll> X[3];
    rep (i, 3) {
        rep (j, N) {
            ll x;
            cin >> x;
            X[i].pb(x);
        }
        sort(all(X[i]));
    }
    ll ans = 0;
    rep (i, N) {
        ll b = X[1][i];
        auto it_a = lower_bound(all(X[0]), b);
        auto it_a_begin = X[0].begin();
        if (it_a == it_a_begin) {
            continue;
        }
        --it_a;
        ll cnt_a = distance(it_a_begin, it_a) + 1;
        auto it_c = upper_bound(all(X[2]), b);
        auto it_c_end = X[2].end();
        if (it_c == it_c_end) {
            continue;
        }
        ll cnt_c = distance(it_c, it_c_end);
        ans += cnt_a * cnt_c;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3572
import random as ra
import copy
import time

start_time = time.time()

D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]

### 得点計算用
#t = [int(input()) for i in range(D)]
def cal_point(t):
    score = 0
    last = [0]*26
    for d in range(D):
        score += s[d][t[d]-1]
        last[t[d]-1] = d+1
        for i in range(26):
            score -= c[i]*(d+1-last[i])
    #print(score)
    return score


t = []
last = [0]*26
for i in range(D):
    opt1 = s[i].index(max(s[i]))
    opt2 = last.index(min(last))
    if ra.random()<0.5:
        t.append(opt1+1)
        last[opt1] = i+1
    else:
        t.append(opt2+1)
        last[opt2] = i+1


#t = [ra.randint(1,26) for i in range(D)]
max_score = 0
optimal_t = copy.deepcopy(t)
#M = 10**5
while (time.time()-start_time)<1.95:
#for i in range(M):
    d = ra.randint(1,D)
    q = ra.randint(1,26)
    td = t[d-1]
    t[d-1] = q
    now = cal_point(t)
    if now > max_score:
        optimal_t = copy.deepcopy(t)
        max_score = now
    else:
        t[d-1] = td

print(*optimal_t,sep='\n')


Measured memory_bytes: 10024
def is_prime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    x = 3
    while x * x <= n:
        if n % x == 0:
            return False
        x += 2
    return True


def get_n(N):
    import math

    n = 0
    for i in range(2, 1 + math.ceil(math.sqrt(N))):
        if N % i == 0:
            n = i
    return n


N = int(input())
if is_prime(N):
    print(N - 1)
else:
    n = get_n(N)
    print(n + N // n - 2)


Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {
	int N;
	cin >> N;
	double X = 0;

	vector<double>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		X += 1 / A.at(i);
	}
	cout << fixed << setprecision(20) << 1/X << endl;
}


Measured memory_bytes: 3780
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int H,W,K,ans=0,count,maxC=0;
	int row[6]={0},col[6]={0};
	char C;
	bool c[6][6];
	cin>>H>>W>>K;
	for(int i=0;i<H;i++)for(int j=0;j<W;j++){
		cin>>C;
		c[i][j]=C=='#';
		maxC+=c[i][j];
	}
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)row[i]+=c[i][j];
	for(int i=0;i<W;i++)for(int j=0;j<H;j++)col[i]+=c[j][i];
	
	for(int h=0;h<(1<<H);h++)for(int w=0;w<(1<<W);w++){
		count=0;
		for(int i=0;i<H;i++){
			if((1<<i)&h)count+=row[i];
		}
		for(int i=0;i<W;i++){
			if((1<<i)&w)count+=col[i];
		}
		for(int i=0;i<H;i++)for(int j=0;j<W;j++){
			if(((1<<i)&h) && ((1<<j)&w))count-=c[i][j];
		}
		if(maxC-count==K)ans++;
	}
	cout<<ans;
	return 0;
}

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


int main() {
    long long int X, K, D;
    std::cin >> X >> K >> D;

    if (std::abs(X) / D >= K) {
        std::cout << std::abs(X) - D * K << std::endl;
        return 0;
    }

    long long int count = std::abs(X) / D;
    long long int res = K - count;
    if (res % 2 == 0) {
        std::cout << std::abs(X) - D * count << std::endl;
    } else {
        std::cout << -std::abs(X) + D * (count + 1) << std::endl;
    }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ull unsigned long long

using namespace std;

const int INF = 1e9+7;

vector<vector<int>> books(100005);
vector<int> cost(100005);
int n, m, x;

int mn = INF;

void buyBooks(int pos, int sum, vector<int> sums)
{
	if(pos == n)
	{
		bool ok = true;
		for(int i = 0; i < m; i++)
		{
			if(sums[i] < x) ok = false;
		}
		if(ok)
		{
			mn = min(sum, mn);
		}
		return;
		
	}else
	{
		buyBooks(pos+1, sum, sums);
		
		for(int i =0; i< m; i++)
		{
			sums[i] += books[pos][i];
		}
		
		buyBooks(pos+1, sum + cost[pos], sums);
	}
	return;
}

int main()
{
    ios_base::sync_with_stdio(false);	
    cin.tie(NULL); cout.tie(NULL);
    
	cin >> n >> m >> x;

	for(int i = 0; i < n; i++)
	{
		int x; cin >> x;
		cost[i] = x;
		
		for(int j = 0; j < m; j++)
		{
			int y; cin >> y;
			books[i].pb(y);
		}
	}
	
	vector<int> sums(m, 0);
	
	buyBooks(0, 0, sums);
	
	cout << (mn==INF?-1:mn) << '\n';
    
    return 0;
}


Measured memory_bytes: 6100
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Convert;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }


        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadLong;
            var a = 0L;
            var b = 0L;
            var start = (int)Ceiling(Sqrt(N));
            for(int i = (int)Ceiling(Sqrt(N)); i >= 1; i--)
            {
                if(N % i == 0)
                {
                    a = i;
                    b = N / i;
                    break;
                }
            }
            WriteLine(a + b - 2);

        }


        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"a < b"<<endl;
	}else if(a>b){
		cout<<"a > b"<<endl;
	}else{
		cout<<"a == b"<<endl;
	}
	
	return 0;

}

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


int main() {
  string s,t;
  cin>>s>>t;
  int ans=0;
  rep(i,s.size()){
    if(s.at(i)!=t.at(i)){
      ans++;
    }
  }
  
  
  cout<<ans<<endl;
}




Measured memory_bytes: 3916