akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set> 
#include <iterator>
#include <bitset> 
#include <bits/stdc++.h> 
using namespace std;
typedef  long long int ll;
ll mod=1000000007;

    

int main() {
       int n,k;
        cin>>n>>k;
        int a[n];
        for(int i=0;i<n;i++ )
            cin>>a[i];
        //cout<<binarys(0,n-1,x,a)<<endl;
         ll dp[n];
         for(int i=0;i<n;i++)
            dp[i]=INT_MAX;
         dp[0]=0;
         dp[1]=abs(a[1]-a[0]);
         for(int i=2;i<n;i++)
         {  for(int j=1;i-j>=0 && j<=k;j++ )
                dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
            
         }
         cout<<dp[n-1];
            
    
	return 0;
}


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


string s, t;

void read() {
    int dummy;
    cin >> dummy >> s >> t;
}


void work() {
    for (int i = 0; i < s.size(); ++i) {
        cout << s[i] << t[i];
    }
    cout << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
const int INF = 1e9;
const int MOD = 1e9+7;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, K; cin >> N >> K;
    string S; cin >> S;
    int ans = 0;
    int l = 0, r = 0;
    while(r < N)
    {
        while(S[r] == '1' && r < N) r++;
        ans = max(ans, r-l);
        while(S[r] == '0' && r < N) r++;
        K--;
        if(K < 0)
        {
            while(S[l] == '1' && l < N) l++;
            while(S[l] == '0' && l < N) l++;
        }
        ans = max(ans, r-l);
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

ll pow_kai(ll a, ll n) {
    ll x = 1;
    while(n > 0) {
        if(n&1) {
            x = x*a;
        }
        a = a*a;
        n >>= 1;
    }
    return x;
}

int main() {
    string sa,sb,sc;
    cin >> sa >> sb >> sc;
    queue<char> SA;
    queue<char> SB;
    queue<char> SC;
    rep(i,sa.size()) {
        SA.push(sa[i]);
    }
    rep(i,sb.size()) {
        SB.push(sb[i]);
    }
    rep(i,sc.size()) {
        SC.push(sc[i]);
    }
    bool win = false;
    char winner;
    char turn = SA.front();
    SA.pop();
    if (SA.size() == 0) {
        cout << 'A' << "\n";
        return 0;
    }
    while(win==false) {
        if (turn == 'a') {
            if (SA.size()==0){
                winner = 'A';
                win = true;
            }
            turn = SA.front();
            SA.pop();
        }
        if (turn == 'b') {
            if (SB.size()==0) {
                winner = 'B';
                win = true;
            }
            turn = SB.front();
            SB.pop();
        }
        if (turn == 'c') {
            if (SC.size()==0) {
                winner = 'C';
                win = true;
            }
            turn = SC.front();
            SC.pop();
        }
    }
    cout << winner << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

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

int64_t solve(int64_t n, std::vector<int64_t> as) {
  int64_t ret = as.front();
  for (int i = 1; i < n; ++i) {
    ret = gcd(as[i], ret);
    if (ret == 1) {
      return 1;
    }
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> as(n);
  for (int i = 0; i < n; i++) {
    std::cin >> as[i];
  }
  auto const res = solve(n, std::move(as));
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 1024
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
    ($line:expr,$name:ident,$t:tt) => {
        let $name=value!($line,$t);
    };
    }

    macro_rules! values_def {
    ($lines:expr,$n:expr,$name:ident,$t:tt) => {
        let $name={
        let mut vec=Vec::new();
        for i in 0..$n{
            let mut next=$lines.next().unwrap().split_whitespace();
            vec.push(value!(next,$t));
        }
        vec
        };
    };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:i64));
    let mut hashmap = HashMap::new();
    for i in 2..(n + 1) {
        prime_factor(i, &mut hashmap);
    }
    let mut res = 1;
    for i in hashmap.into_iter().map(|(_, x)| x + 1) {
        res = mul(res, i);
    }
    res.to_string()
}

use std::collections::HashMap;
//素因数分解
pub fn prime_factor(mut n: i64, res: &mut HashMap<i64, i64>) {
    let mut i = 2;
    while i * i <= n {
        while n % i == 0 {
            let v = match res.get(&i) {
                Some(v) => *v + 1,
                None => 1,
            };
            res.insert(i, v);
            n /= i;
        }
        i += 1;
    }
    if n != 1 {
        {
            let i = n;
            let v = match res.get(&i) {
                Some(v) => *v + 1,
                None => 1,
            };
            res.insert(i, v);
            n /= i;
        }
    }
}

fn mul(a: i64, b: i64) -> i64 {
    ((a % 1000000007) * (b % 1000000007)) % 1000000007
}

fn ncr(n: i64, r: i64) -> i64 {
    if r == 0 {
        1
    } else {
        mul((n - r + 1), ncr(n, r - 1)) / r
    }
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "3" => "4",
    test2: "6" => "30",
    test3: "1000" => "972926972",
}


Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

#ifdef __DEBUG__

template<typename T, typename U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &pair)
{
  os << pair.first << ": " << pair.second;
  return os;
}

template<class ForwardIterator>
std::ostream& _iterator_to_display(
  std::ostream &os, 
  ForwardIterator begin, ForwardIterator end, 
  const std::string &delim = ", "
)
{
  auto itr = begin;
  while (itr != end) {
    os << *itr;
    ++itr;
    if (itr != end) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  os << '[';
  _iterator_to_display(os, list.begin(), list.end());
  os << ']';
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &vector)
{
  os << '[';
  _iterator_to_display(os, vector.begin(), vector.end());
  os << ']';
  return os;
}

template<typename T, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::set<T> &set)
{
  os << '{';
  _iterator_to_display(os, set.begin(), set.end());
  os << '}';
  return os;
}

template<typename T, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::multiset<T> &set)
{
  os << '{';
  _iterator_to_display(os, set.begin(), set.end());
  os << '}';
  return os;
}

template<typename T, typename U, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::map<T, U> &map)
{
  os << '{';
  _iterator_to_display(os, map.begin(), map.end());
  os << '}';
  return os;
}

template<typename T, typename U, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::multimap<T, U> &map)
{
  os << '{';
  _iterator_to_display(os, map.begin(), map.end());
  os << '}';
  return os;
}

#define debug(var) std::cerr << #var" = " << var << std::endl

#endif /* __DEBUG__ */

int main(int argc, char **argv)
{
  uint64_t N;
  std::cin >> N;
  
  uint64_t M = ((N / 111) + (N % 111 == 0 ? 0 : 1)) * 111;
  std::cout << M << std::endl;
  
  return 0;
}

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

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

	for (int a = 1; a <= 9; a++) {
		for (int b = 1; b <= 9; b++) {
			if ((a * b) == N){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    
    int n, i, j, temp;
    int A[100];
    int flag = 1;
    int count = 0;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++)
        scanf("%d", &A[i]);

    while(flag){
        flag = 0;
        for(j = n - 1; j > 0; --j){
            if(A[j] < A[j - 1]){
                temp = A[j];
                A[j] = A[j - 1];
                A[j - 1] = temp;
                count++;
                flag = 1;
            }
        }
    }
    
    for(i = 0; i < n; i++){
        printf("%d", A[i]);
        if(i != n - 1)
            printf(" ");
    }
    printf("\n%d\n", count);
}

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

using namespace std;

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> homeworks;
  for(int i=0;i<M;i++) {
    int a;
    cin >> a;
    homeworks.emplace_back(a);
  }
  long long int total = reduce(homeworks.begin(), homeworks.end(), 0L);
  int rest = N - total;
  cout << (rest>=0 ? rest : -1) << endl;
}



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

typedef long long ll;

using namespace std;

int main() {
    ll N;
    cin >> N;
    vector<pair<ll, ll>> P;
    ll n = N;
    ll total_e = 0;
    // 試し割り
    for (ll p = 2; p * p <= N; p++) {
        ll e = 0;
        while (n % p == 0) {
            total_e++;
            e++;
            n /= p;
        }
        if (e > 0) {
            P.push_back(make_pair(p, e));
        }
    }
    if (n > 1) {
        P.push_back(make_pair(n, 1));
    }

    ll total_count = 0;
    vector<ll> dec(P.size(), 1);
    vector<bool> finish(P.size(), false);
    // 指数部の合計値が0になるか全ての素数で操作できなくなるまで
    while (total_e >= 0) {
        for (ll i = 0; i < P.size(); i++) {
            ll p = P[i].first; ll e = P[i].second;
            if (finish[i]) continue;
            ll d = dec[i];
            if (e - d >= 0) {
                e -= d;
                P[i] = make_pair(p, e);
                dec[i]++;
                total_e -= d;
                total_count++;
            }
            if (e == 0 || e - dec[i] < 0) {
                finish[i] = true;
            }
        }
        bool all_finished = true;
        for (bool f : finish) {
            if (!f) {
                all_finished = false;
            }
        }
        if (all_finished) {
            break;
        }
    }
    cout << total_count << endl;
    return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
// const ll mod= 1000000007;

signed main() {
    int n;
    int a[200010], b[200010];
    vector<pair<int, int>> schedule;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        schedule.emplace_back(make_pair(b[i], a[i]));
    }

    sort(schedule.begin(), schedule.end());

    int sa = 0, sb = 0;
    bool can = true;
    for (int i = 0; i < n; i++) {
        sa += schedule[i].second;
        if (schedule[i].first < sa) can = false;
    }

    cout << (can ? "Yes" : "No") << endl;
}

// sort

Measured memory_bytes: 8688
#include <iostream>

using namespace std;

int main(void){
  int A, B, T;
  cin >> A >> B >> T;

  int counter = 0;

  for (int i = 1; i < T + 0.5; i++) {
    if (i % A == 0) {
      counter += B;
    }
  }

  cout << counter << '\n';

 return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0, d = 0, e = 0, ans = 0, x = 0, y = 0, z = 0, N = 0, m = 0, maxy = 0, mini = 9999, counter = 0, endp = 0, checker = 0;

std::vector <char> vec{}, vecsec{}, vecth{};
long long int iremono[100010], koware[100001];
long long  int iremono2[100001], check[100001], xpo[10000001], ypo[10000001], hei[1000001];
std::vector<std::string>kinds{}, kaku{};
char maze[1000];
int sx, sy;
int gx, gy;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
long long int dp[4][100003] ,ire[4][100003];
std::string input[103],one,two,three;
char re;

int H, W;//はんい
bool qw = false, er = false, ty = false, ui = false;
std::string code;
long long int gcd(long long int a, long long int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}

	return b ? gcd(b, a % b) : a;
}

long long int lcm(long long int a,long long int b)
{
	return a * b / gcd(a, b);
}

int main() {
	
	cin >> a >> b >> c >> d;
	x = (b / c - (a - 1) / c);
	y = (b / d - (a - 1) / d);
	e = lcm(c,d);
	z = (b / e - (a - 1 )/ e);
	cout << b - a + 1 - x - y + z << endl;
}




Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <cstring>
#include <fstream>

using namespace std;
using ll = long long;

int dp[100005][3]; // dp[i][j] = max score if 
array<int, 3> a[100005];

int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	for(int i = 0; i < 3; i++)
		dp[0][i] = a[0][i];
	for(int i = 1; i < n; i++)
	{
		dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = a[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = a[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
	}
	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl;
	return 0;
}



Measured memory_bytes: 5908
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
// 多くてもN回
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int a[N+1]; FOR(i,1,N+1) cin >> a[i];
  int now = 1;
  FOR(i,0,N+1) {
    if(now == 2) {
      cout << i << '\n';
      return 0;
    }
    now = a[now];
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 640
N = int(input())
#print(N)

S = input()

count = 0
for i in range(N):
    #print(S[i] , i)
    if i == N-1:
        break
    else:
        if S[i+1] != S[i]:
            count += 1

if count == 0:
    print(1)
else:
    print(count+1)

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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)


#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;


    char c;

    cin >> c;

    int a = (int)(c);


    cout << (char)(a+1) << endl;




    return 0;
}



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

int max(int x, int y) {
	if (x > y) return x;
	return y;
}

int min(int x, int y) {
	if (x < y) return x;
	return y;
}

int main() {
	std::string nstr;
	std::cin >> nstr;
	int n = std::stoi(nstr);

	std::vector<int> v(n, 0);

	int max_num = 0;
	int min_num = 1000000001;
	for (int i = 0; i < n; i++) {
		std::string xstr;
		std::cin >> xstr;

		int x = std::stoi(xstr);

		max_num = max(max_num, x);
		min_num = min(min_num, x);
	}

	std::cout << max_num - min_num << std::endl;
}

Measured memory_bytes: 256
from collections import Counter
h,w=map(int,input().split())
cnt=Counter()
for i in range(h):
  c=Counter(input())
  cnt+=c
sum1=0
sum2=0
sum4=0
for i in cnt.values():
  sum1+=i%2
  sum4+=i//4
  sum2+=(i-(i//4)*4)//2
if h%2==0 and w%2==0:
  print('Yes' if sum1==0 and sum2==0 else 'No')
elif h%2==1 and w%2==1:
  print('Yes' if sum1==1 and sum4>=((w-1)*(h-1))/4 else 'No')
elif h%2==1 and w%2==0:
  print('Yes' if sum1==0 and sum2<=w/2 else 'No')
else:
  print('Yes' if sum1==0 and sum2<=h/2 else 'No')

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


int main(){
    int ans=1;
    int N,X;
    cin >> N >> X;
    int D=0;
    for(int i=0; i<N; i++){
        int L;
        cin >> L;
        D+=L;
        if(D<=X){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,c,ans,na
    integer(int32), allocatable:: a(:)
    read*, n
    allocate(a(n))
    do i=1,n
        read*, a(i)
    end do

    call merge_sort(a,1,n)
    na=0
    c=0
    ans=0
    do i=1,n
        if (na /= a(i)) then
            ans=ans+mod(c,2)
            c=0
            na=a(i)
        end if
        c=c+1
    end do

    if (c>=1) ans=ans+mod(c,2)
    print*, ans

    
contains
    recursive subroutine merge_sort(ar, fst, lst)
        integer(4),intent(inout):: ar(:)
        integer(4),intent(in):: fst,lst
        integer(4):: mdl

        if (lst-fst < 2) then
            if (ar(fst) > ar(lst)) call swap(ar(fst),ar(lst))
            return
        end if

        mdl = (fst+lst)/2
        call merge_sort(ar, fst, mdl)
        call merge_sort(ar, mdl+1, lst)
        call merge_(ar, fst, mdl, lst)
    end subroutine

    subroutine merge_(ar, fst, mdl, lst)
        integer(4),intent(inout):: ar(:)
        integer(4),intent(in):: fst, mdl, lst
        integer(4),allocatable:: tmp(:)
        integer(4):: li, ri, ti

        allocate(tmp(lst-fst+1))

        li=fst
        ri=mdl+1   
        ti=1

        do while (li <= mdl .and. ri <= lst)
            if (ar(li) <= ar(ri)) then
                tmp(ti) = ar(li)
                li=li+1
            else
                tmp(ti) = ar(ri)
                ri=ri+1
            end if
            ti=ti+1
        end do

        if (li <= mdl) then
            tmp(ti:) = ar(li:mdl)
        else
            tmp(ti:) = ar(ri:lst)
        end if

        ar(fst:lst) = tmp(:)
        deallocate(tmp)
    end subroutine

    subroutine swap(x,y)
        integer(4),intent(inout):: x,y
        integer(4):: tmp
        tmp = x
        x = y
        y = tmp
    end subroutine
end program name

Measured memory_bytes: 1468
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <iostream>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

const int MAXN = 100005;

int n, u, v, w, C[MAXN];
vector<vector<pii>> G;

void dfs_color(int v, int p, int col) {
    C[v] = col;

    for (pii edge : G[v]) {
        int child = edge.X;
        int weight = edge.Y;

        if (child != p) {
            dfs_color(child, v, weight % 2 == 0 ? col : 1 - col);
        }
    }
}

int main() {
    scanf("%d", &n);

    G.resize(n);

    for (int i = 0; i < n - 1; i++) {
        scanf("%d%d%d", &u, &v, &w);
        G[u - 1].push_back({v - 1, w});
        G[v - 1].push_back({u - 1, w});
    }

    dfs_color(0, -1, 0);

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

    return 0;
}

Measured memory_bytes: 8960
n = int(input())
A_list = list(map(int, input().split()))
count_node = 0
count_pre_node = 0
sum_node = 0
Tree_list = []

for  i in range(len(A_list)):
    if i == 0:
        Tree_list.append(1)
        continue
    Tree_list.append(2*(Tree_list[i-1]) - A_list[i])
Tree_list.reverse()

A_list.reverse()
for i in range(len(A_list)):
    if n == 0 and A_list[0] == 1:
        sum_node = 1
        break

    count_node = A_list[i] + count_pre_node
    sum_node += count_node
    
    #一番上がエラーの時
    if i == 0 and A_list[-1] != 0:
        sum_node = -1
        break
    
    #ラストなら終わり
    if i == len(A_list)-1:
        break

    if count_node > 2*Tree_list[i+1]:
        sum_node = -1
        break
    
    if count_node >= Tree_list[i+1]:
        count_pre_node = Tree_list[i+1]
    else:
        count_pre_node = count_node

print(sum_node)



Measured memory_bytes: 668612
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using i64 = long long;



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

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

  s+=s;

  if (s.find(t) != string::npos) {
    cout<<"Yes\n";
  } else {
    cout<<"No\n";
  }
}


Measured memory_bytes: 256
def main():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    ans = 0
    for a in range(A+1):
        for b in range(B+1):
            for c in range(C+1):
                if 500*a + 100*b + 50*c == X:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38896
from collections import deque
from sys import setrecursionlimit
setrecursionlimit(10**6)

def dfs1(now,visited,ans):
    visited[now]=True
    for nx in g[now]:
        if not visited[nx]:
            ans.appendleft(nx)
            dfs1(nx,visited,ans)
            break

def dfs2(now,visited,ans):
    visited[now]=True
    for nx in g[now]:
        if not visited[nx]:
            ans.append(nx)
            dfs2(nx,visited,ans)
            break

n,m=map(int,raw_input().split())
g=[[] for _ in xrange(n)]
for i in xrange(m):
    a,b=map(int,raw_input().split())
    a-=1;b-=1
    g[a].append(b)
    g[b].append(a)
ans=deque([a,b])
visited=[False]*n
visited[a]=True
visited[b]=True
dfs1(a,visited,ans)
dfs2(b,visited,ans)
print len(ans)
for i in xrange(len(ans)):
    print ans[i]+1,
print


Measured memory_bytes: 91700
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N;
  cin >> N;
  vector<vector<int>> ans;
  ans.push_back({});
  ans.push_back({});
  int j = 0;
  for(int i=1; i<N+1; i++){
    int n = ans.size();
    if(j==n-1){
      j = 0;
      ans.push_back({});
      n++;
    }
    ans[j].push_back(i);
    ans[n-1].push_back(i);
    j++;
  }

  // for(int i=0; i<ans.size(); i++){
  //   for(int j=0; j<ans[i].size(); j++){
  //     cout << ans[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  if(ans[0].size() != ans[ans.size()-1].size()){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    cout << ans.size() << endl;
    for(int i=0; i<ans.size(); i++){
      cout << ans[i].size();
      for(int j=0; j<ans[i].size(); j++){
        cout << " " << ans[i][j];
      }
      cout << endl;
    }
  }

}

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

int main()
{
    string s;
    int q;
    cin >> s >> q;

    int n = s.size();
    bool rev = false;
    deque<string> t;
    rep(i,n) t.push_back(s.substr(i,1));

    rep(i,q) {
        int a, b;
        string si;
        cin >> a;
        if(a == 1) {
            rev = !rev;
            continue;
        }
        cin >> b >> si;
        if((b == 1 && rev) || (b == 2 && !rev))
            t.push_back(si);
        else
            t.push_front(si);
    }

    if(rev) reverse(t.begin(),t.end());

    for(auto& ti:t) cout << ti;
    cout << endl;
    return 0;
}

Measured memory_bytes: 17152
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    r,g = IR(2)
    print(2*g-r)

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 39152
def fib(n):
    a, b = 0, 1
    for i in range(n):
        a, b = b, a + b
    return b


n, m = map(int, input().split())
if m == 0:
    print(fib(n) % 1000000007)
    exit()
a = [int(input()) for _ in range(m)]

total = 1
i = 0
for x in a:
    if x == i:
        print(0)
        exit()
    total *= fib(x - i - 1)
    i = x + 1
if a[-1] != n:
    total *= fib(n - (a[-1] + 1))

print(total % 1000000007)


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

int main() {
  int a,b,k;
  cin>>a>>b>>k;
  
  rep(i,k) if(a<=b) cout<<a++<<endl;
  a--;
  for(int i=k-1;i>=0;--i){
    if(b-i>a)
      cout<<b-i<<endl;
  }
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e+15;
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n, f[101][11], p[101][12];
long long int sum, ans;

int main(){
	cin >> n;
	ans-=INF; 
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin >> f[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<11;j++){
			cin >> p[i][j];
		}
	}
	for(int S=1;S < 1<<10;S++){
		sum=0;
		for(int j=0;j<n;j++){
			int s=0;
			for(int i=0;i<10;i++){
				if((S>>i & 1)&&(f[j][i]==1))s++;
			}
			sum += p[j][s];
		}
		ans = max(sum, ans); 
	}

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

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<usize>();
    let b = read::<usize>();
    let c = read::<usize>();
    let ans = [a + b + 10 * c, a + 10 * b + c, 10 * a + b + c]
        .iter()
        .cloned()
        .max()
        .unwrap();
    println!("{}", ans);
}


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

#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int h,r;
    cin>>h>>r;

    if(h+r>0){
        cout<<1<<endl;
    }
    else if(h+r==0){
        cout<<0<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {
	string S;
	cin >> S;

	bool isR = true;
	ll pos = 0;
	ll cntR = 0;
	ll cntL = 0;

	vector<ll> ans(S.size(),0);

	rep(i, S.size()) {
		
		if (S[i] == 'R') {
			if (isR == false) {

				ans[pos - 1] += (cntR - cntR / 2) + cntL / 2;
				ans[pos] += cntR / 2 + (cntL - cntL / 2);

				cntR = 0;
				cntL = 0;
			}
			cntR++;
			isR = true;
		}
		else {
			cntL++;
			if (isR == true) {
				isR = false;
				pos = i;
			}
		}

	}

	ans[pos - 1] += (cntR - cntR / 2) + cntL / 2;
	ans[pos] += cntR / 2 + (cntL - cntL / 2);

	rep(i, S.size()) {
		cout << ans[i] << " ";
	}

}

int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 1472
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;


public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int d = in.nextInt();
            if(Math.abs(a-c) <=d)out.println("Yes");
            else if (Math.abs(a-b) <=d && Math.abs(b-c)<=d)out.println("Yes");
            else out.println("No");

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}


Measured memory_bytes: 23380
from collections import defaultdict
from collections import deque

N,M=map(int,input().split())

Graph=defaultdict(list)

for _ in range(M):
  A,B=map(int,input().split())
  Graph[A].append(B)
  Graph[B].append(A)

ans=[0]*(N+1)
q=deque()
q.append(1)

while(q):
  start=q.popleft()
  startans=ans[start]
  for a in Graph[start]:
    if ans[a]>0 or a==1:
      continue
    else:
      ans[a]=start
      q.append(a)
  #print(ans,q)
#print(Graph)
print('Yes')
for i in range(2,N+1):
  print(ans[i])

Measured memory_bytes: 38444
function Main(input) {
  input = input.trim()
  input = input.split("");
  var sum = input.length;
  for(var i=0;true;i++){
    if(input[i]=="A"){
      break;
    }else{
      sum--;
    }
  }
  for(i=1;true;i++){
  if(input[input.length-i]=="Z"){
    break;
  }else{
    sum--;
  }
  }
  console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9548
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int a[200000];
int b[200000];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i];
	for (int i = 0; i < N; i++) cin >> b[i];
	int ans = 0;
	for (int k = 0; k < 30; k++) {
		vector<int> odd, even;
		for (int i = 0; i < N; i++) {
			if (a[i] & (1 << k)) odd.push_back(a[i] % (1 << k));
			else even.push_back(a[i] % (1 << k));
		}
		sort(odd.begin(), odd.end());
		sort(even.begin(), even.end());
		LL cnt = 0;
		for (int i = 0; i < N; i++) {
			int c = b[i] % (1 << k);
			if (b[i] & (1 << k)) {
				cnt += lower_bound(even.begin(), even.end(), (1 << k) - c) - even.begin();
				cnt += odd.end() - lower_bound(odd.begin(), odd.end(), (1 << k) - c);
			}
			else {
				cnt += lower_bound(odd.begin(), odd.end(), (1 << k) - c) - odd.begin();
				cnt += even.end() - lower_bound(even.begin(), even.end(), (1 << k) - c);
			}
		}
		if (cnt % 2) ans |= (1 << k);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
n,m = map(int,input().split())
x = list(map(int,input().split()))
if m<=n :
    print(0)
else:
    x_delta=[]
    x.sort()
    for i in range(len(x)-1):
        delta = x[i+1] - x[i]
        x_delta.append(delta)
    print(sum(sorted(x_delta)[:m-n]))

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

namespace testing
{
    class Program
    {

        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(b);
            bool c = true;
            for (int i = 0; i < a - 1; i++)
            {
                if (b[i] == b[i+1]) { c = false; break; }
            }
            if (c == false) { Console.WriteLine("NO"); }
            if (c == true) { Console.WriteLine("YES"); }
        }
    }
}


Measured memory_bytes: 44308
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, 0, n){
        cin >> p[i];
        p[i]--;
    }
    int ans = 0;
    rep(i, 0, n - 1){
        if(p[i] == i){
            swap(p[i], p[i + 1]);
            ans++;
        }
    }
    if(p[n - 1] == n - 1) ans++;
    cout << ans << endl;
}

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

int main() {
	string s;
	cin >> s;
	
	vector <int> v(4);
	for (int i = 0; i < s.length(); i++) {
		v[i] = s[i];
	}

	sort(v.begin(), v.end());

	string ret;
	if (v[0] == v[1] && v[1] != v[2] && v[2] == v[3]) ret = "Yes";
	else ret = "No";
	
	cout << ret << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
int toInt(const string &s){
    if(s[0] == '-')
        return -(s[1] - '0');
    return (s[0] - '0');
}
int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    int n;
    cin >> n;
    int aux = n / 15;
    aux *= 200;
    cout << abs(n * 800 -aux) << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/



signed main() {
	int n, ans = inf; cin >> n;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			int j = n / i;
			chmin(ans, i + j - 2);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import heapq
def dijkstra_heap(s):
    d = [float("inf")] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d


n,m = map(int,input().split())

edge = [[] for i in range(n)]
for i in range(m):
    x,y,z = map(int,input().split())
    edge[x-1].append([z,y-1])
    edge[y-1].append([z,x-1]) 
for i in range(1,n):
  edge[i].append([0,i-1])
x=dijkstra_heap(0)[n-1]
if x==float("inf"):
  print(-1)
else:
  print(x)

Measured memory_bytes: 105120
#include <iostream>
using namespace std;
int main(){
    int n,k,ans=0;
    int h[100000];
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>h[i];
        if(h[i]>=k) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main{
   public static void main(String[] args) {
	  Scanner sc =new Scanner(System.in);
 for(;;){
	 int n =sc.nextInt();
   if(n==0)break;
 int []num =new int[n];
 int []kyori =new int[n];
   for(int i=0; i<n; i++){
	 num[i]=sc.nextInt();
	 kyori[i]+=sc.nextInt();
	 kyori[i]+=sc.nextInt();
 }
   int most=0; int mostn=0;
   for(int i=0; i<n; i++){
    if(most<=kyori[i]){
    	most = kyori[i];
    	mostn = num[i];
    }
   }
   System.out.println(mostn+" "+most);
 }
 }
 }

Measured memory_bytes: 158424
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
const double PI=acos(-1.0);
struct node
{
	node *next[26];
};
node *root;
int k;
string dfs(node *p)
{
	if( k==0 )	return "";
	for(int i=0;i<26;i++)
	{
		if( p->next[i]!=NULL )
		{
			k--;
			string s=dfs(p->next[i]);
			if( k==0 )
				return char(i+'a')+s;
		}
	}return "";
}
void buildtree(string s)
{
	int len=s.length();
	node *p=root,*newnode;
	for(int i=0;i<len;i++)
	{
		int x=s[i]-'a';
		if( p->next[x]==NULL )
		{
			newnode=(node*)malloc(sizeof(node));
			for(int j=0;j<26;j++)	newnode->next[j]=NULL;
			p->next[x]=newnode;
		}
		p=p->next[x];
	}
}
int main()
{
	string s;
	while( cin>>s>>k )
	{
		root=(node*)malloc(sizeof(node));
		for(int i=0;i<26;i++)	root->next[i]=NULL;
		int len=s.length();
		buildtree(s);
		for(int i=1;i<len;i++)
			if( len<1000 || ( len>=1000 && s[i]<'f' ) )
			buildtree(s.substr(i,len-i));
		cout<<dfs(root)<<endl;
	}
}


Measured memory_bytes: 542336
use proconio::{input, fastout};
use std::collections::HashMap;
use std::collections::HashSet;
use num::Integer;

fn modpow(x: i64, y: i64, m: i64) -> i64 {
  if y == 0 { return 1; }
  if y == 1 { return x; }
  let mut ans = modpow(x, y>>1, m);
  ans = ans * ans % m;
  if y & 1 == 1 {
    ans = ans * x % m;
  }
  ans
}

fn gcd<T: Integer+Copy>(x: &T, y: &T) -> T {
  if y == &T::zero() {
    *x
  } else {
    let t = *x % *y;
    gcd(y, &t)
  }
}

fn norm(x: i64, y: i64) -> (i64, i64) {
  let (ax, ay) = (x.abs(), y.abs());
  let g = gcd(&ax, &ay);
  (x / g, y / g)
}

#[fastout]
fn main() {
  let mmm = 1000000007;
  input!{
    n: usize,
    ab: [(i64, i64); n]
  };
  let mut h : HashMap<(i64, i64), i64> = HashMap::new();
  let mut zerozero = 0;
  for (a, b) in &ab {
    let (a, b) = if *b < 0 {
      (*a * -1, *b * -1)
    } else {
      (*a, *b)
    };
    if a == 0 && b == 0 {
      zerozero += 1;
    } else if a == 0 {
      *h.entry((0, 1)).or_insert(0) += 1;
    } else if b == 0 {
      *h.entry((1, 0)).or_insert(0) += 1;
    } else {
      *h.entry(norm(a, b)).or_insert(0) += 1;
    }
  }
  // dbg!(&h, -1 % mmm);

  let mut ans : i64 = 1;
  let mut s : HashSet<(i64, i64)> = HashSet::new();
  for (r, v) in &h {
    let r = *r;
    let v = *v;
    if !s.contains(&r) {
      let r2 = if r.0 <= 0 {
        (r.1, r.0 * -1)
      } else {
        (r.1 * -1, r.0)
      };
      let v2  = match h.get(&r2) {
        Some(vv2) => *vv2,
        None => 0
      };
      let mut pow = (modpow(2, v, mmm) + modpow(2, v2, mmm) - 1) % mmm;
      while pow < 0 {
        pow += mmm;
      }
      // dbg!(&r, &s, &pow, v, v2);
      s.insert(r);
      s.insert(r2);
      ans = ans * pow % mmm;
    }
  }
  ans -= 1;
  ans += zerozero;
  while ans < 0 {
    ans += mmm;
  }
  println!("{}", ans % mmm);
}


Measured memory_bytes: 36460
def resolve():
    n = int(input())
    x = 0
    c = 0
    a = list(map(int, input().split()))
    for i in range(n):
        if a[i] == x+1:
            x += 1
            continue
        else:
            c += 1
    if c == n:
        print(-1)
    else:
        print(c)
resolve()

Measured memory_bytes: 32320