akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();

        if(n*a < b) {
            System.out.println(a*n);
        }else {
            System.out.println(b);
        }
        
        
    }
}



Measured memory_bytes: 22612
#include<iostream>
using namespace std;
int main()
{
	int n,h1,h2;
	while(cin >> n && n>=100&&n<=999)
	{
		h1=n/100;
		h2=n%100%10;
		if(h1==h2)
			cout << "Yes" << endl;
		else
			cout << "No" <<endl;

	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Here your code !
    int i = 0;
    int a = 1;
    int temp = 0;
    for( i = 1; a == 1  ; ++i){
        scanf("%d", &temp);
        if( temp == 0 ){
            a = 0;
        }else{
            printf("Case %d: %d\n", i, temp);
        }
    }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstring>
#include <string>
#include <climits>

using namespace std;

int main(int argc, char *argv[]) {
  int h, w;
  cin >> h >> w;

  int *cicada = new int[h*w];
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      cicada[w*i+j] = s[j] - '0';
    }
  }

  int *hoge = new int[h*w];
  memset(hoge, 0, h*w);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int left, above;
      if (i == 0)
        above = INT_MAX;
      else
        above = hoge[w*(i-1)+j];
      if (j == 0 && i == 0)
        left = 0;
      else if (j == 0)
        left = INT_MAX;
      else
        left = hoge[w*i+j-1];
      /*                                                                                                                                                                  
      cout << left << ' ' << above << endl;                                                                                                                               
      */
      hoge[w*i+j] = cicada[w*i+j] + (above > left ? left : above);
    }
  }
  /*                                                                                                                                                                      
  for (int i = 0; i < h; i++)                                                                                                                                             
    for (int j = 0; j < w; j++)                                                                                                                                           
      cout << hoge[w*i+j];                                                                                                                                                
  */
  cout << hoge[w*h-1] << endl;
  return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define inc(i,a,b) for(register int i=a;i<=b;i++)
using namespace std;
string s[110];
long long g[110];
int main(){
	int n;
	cin>>n;
	long long ans=0;
	inc(i,1,n){
		cin>>s[i]>>g[i];
		ans+=g[i];
	}
	string goal; cin>>goal;	
	inc(i,1,n){
		ans-=g[i];
		if(goal==s[i]){
			break;
		}
	}
	cout<<ans;
}

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

int cmpnum(const void * n1, const void * n2)
{
	if (*(long *)n1 > *(long *)n2)
	{
		return -1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main(void){

  long n,m;
  scanf("%ld %ld", &n, &m);
  long x[m];
  for (long i = 0; i < m; i++) {
    scanf("%ld", &x[i]);
  }
  if (n >= m) {
    printf("0\n");
    return 0;
  }
  qsort(x, m, sizeof(long), cmpnum);
  long dif[m-1];
  for (long i = 0; i < m-1; i++) {
    dif[i] = x[i]-x[i+1];
  }
  qsort(dif, m-1, sizeof(long), cmpnum);
  long answer = x[0]-x[m-1];
  for (long i = 0; i < n-1; i++) {
    answer -= dif[i];
  }
  printf("%ld\n", answer);

  return 0;
}

Measured memory_bytes: 2284
N = int(input())
cities = []
for i in range(N):
    x,y = list(map(int, input().split()))
    cities.append((x,y))

import itertools
import math
average_dist = 0
patterns = math.factorial(N)

for path in itertools.permutations(range(N)):
    dist = 0
    for i in range(N-1):
        st = cities[path[i]]
        en = cities[path[i+1]]
        dist += math.sqrt((en[1]-st[1])**2 + (en[0]-st[0])**2)
    average_dist += dist/patterns

print(average_dist)

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 check[100005];
int waCheck[100005];

int main() {
    int n, m;
    cin >> n >> m;
    int ac = 0, wa = 0;
    rep(i,m) {
        int p; 
        string s;
        cin >> p >> s;
        if (check[p] == 0) {
            if (s == "WA") waCheck[p]++;
            else if (s == "AC") {
                ac++;
                check[p] = 1;
            }
        }
    }
    rep(i,100005) {
        if (check[i] == 1) wa += waCheck[i];
    }
    
    printf("%d %d", ac, wa);

    return 0;
}

Measured memory_bytes: 1024
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include<bits/stdc++.h>
#include<chrono>
#include<unordered_map>
#include<random>
#include<complex> 
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned ll 
#define endl '\n'
#define mk make_pair
void fast_in_out() {
	std::ios_base::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
}
int dx[] = { 0,0,-1,1,-1,1,-1,1,0 };
int dy[] = { -1,1,0,0,-1,-1,1,1,0 };
int lx[] = { 2, 2, -1, 1, -2, -2, -1, 1 };
int ly[] = { -1, 1, 2, 2, 1, -1, -2, -2 };
const ld eps = 1e-9;
const int N = 1e5 + 50, M = 1e5 + 10, mod = 1e9 + 7;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll t = gcd(a, b); return t ? (a / t * b) : 0; }
int main() {
	fast_in_out();
//	cout << fixed << setprecision(6);
	int n, m;
	cin >> n >> m;
	if (n < m)
	{
		for (int i = 0; i < m; i++)
			cout << n;
		cout << endl;
	}
	else {
		for (int i = 0; i < n; i++)
			cout << m;
		cout << endl;
	}

	return 0;
}

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



string S;
string SS = "CODEFESTIVAL2016";
//-----------------------------------------------------------------
int main() {
	cin >> S;
	int ans = 0;
	rep(i, 0, SS.length()) if (S[i] != SS[i]) ans++;
	cout << ans << endl;
}

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

#include <math.h>
#include <stdlib.h>


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


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    string s; cin >> s;
    int q; cin >> q;

    vector<set<int>> al(26);

    for(int i = 0; i < n; i++){
      int p = int(s[i]-'a');
      al[p].insert(i);
    }


    for(int k = 0; k < q; k++){
      int qt; cin >> qt;
      if(qt == 1){
        int iq; cin >> iq;
        iq--;
        char cq; cin >> cq;
        
        int p = int(cq-'a');       
        int op = int(s[iq]-'a');
        al[op].erase(iq);
        al[p].insert(iq);
        s[iq] = cq;

      } else {
        int l, r; cin >> l >> r;
        l--; 

        int cnt = 0;
        for(int i = 0; i < 26; i++){
          auto itr = al[i].lower_bound(l);
          if(itr != al[i].end() && *itr < r) cnt++;
  
        }
        cout << cnt << endl;
      }

    }


    return 0;
}


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

int gcd(int a, int b){
  if (a<b){
    a ^= b;
    b ^= a;
    a ^= b;
  }
  return b ? gcd(b, a % b) : a;
}

int main(){
  int n; cin >> n;
  int H[n];
  for (int i=0; i<n; i++){
    cin >> H[i];
  }
  int temp = H[0];
  for (int i=1; i<n; i++){
    temp = gcd(temp, H[i]);
  }
  cout << temp << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int n[] = new int[20000];
		 n[0] = 1;
		for(int i=1;i<=1000;i++) {
			n[i]=n[i-1]+i+1;
		}
		for(int j=0;j<1000;j++) {
			if(n[j+1]-n[j]==b-a) {
				System.out.println(n[j]-a);
			}
		}

}
}

Measured memory_bytes: 22100
n = int(input())
p = [tuple(map(int,input().split())) for _ in range(n)]
d = {}
m = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        fx = p[i][0] - p[j][0]
        fy = p[i][1] - p[j][1]
        f = (fx, fy)
        if f not in d:
            d[f] = 0
        d[f] += 1
        m = max((m, d[f]))

print(n - m)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define fi first
#define se second
#define All(x) (x).begin(),(x).end()
#define TYPE(x) typeid(x).name()
vector<int>nums(2000000);
int main(){
	int n;
	unordered_map<int,int>node;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;++i){
		int tt;
		cin>>tt;
		nums[i]=tt;
		++node[i-tt];
	}
	for(int i=1;i<=n;++i){
		ans+=node[nums[i]+i];
	}
	cout<<ans;
}


Measured memory_bytes: 26400
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using vi = vector<int>;
using vl = vector<i64>;
using vd = vector<double>;
using pi = pair<int, int>;
using pl = pair<i64, i64>;
using pd = pair<double, double>;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

int main() {
 int a, p;
  cin >> a >> p;
  cout << (a * 3 + p) / 2 << endl;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};

template<ll mod>
struct RollingHash{
  vector<ll> hash,p;
  ll base;
  RollingHash(string s, ll b){
    ll n = (ll)s.size();
    base = b;
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(ll i=0;i<n;i++){
      hash[i+1]=(hash[i]*base+s[i])%mod;
      p[i+1]=(p[i]*base)%mod;
    }
  }
  ll get(ll l, ll r){
    ll ret=hash[r+1]-(hash[l]*p[r-l+1])%mod;
    if(ret<0)ret+=mod;
    return ret;
  }
};

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  const ll tmp_mod=608396398;
  using RH = RollingHash<tmp_mod>;
  ll base = 100000;
  ll n;cin>>n;
  string s;cin>>s;
  RH rh(s,base);
  /*auto v=vec(n,n,0LL);
  rep(i,0,n)rep(j,0,n){
    if(i+j<n)v[i][j]=rh.get(i,i+j);
  }*/
  rep(i,0,n-1)rep(j,i+1,n){
    if(s[i]!=s[j])continue;
    ll l=i,r=j;
    while(r-l>=2){
      ll mid=(l+r)/2;
      if(j+mid-i>=n||rh.get(i,mid)!=rh.get(j,j+mid-i)){
        r=mid;
      }
      else l=mid;
    }
    chmax(res,l-i+1);
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N;
    void solve()
    {
        WriteLine(new string(cin.next.Select((x, y) => new { x, y }).Where(i => i.y % 2 == 0).Select(i => i.x).ToArray()));
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 14684
#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 3e3 + 33, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >>  s;
	for(int i = 0; i < s.size(); i+=2)
		if(s[i]!='h') return cout << "No", 0;
	for(int i = 1; i < s.size(); i+=2)
		if(s[i]!='i') return cout << "No", 0;
	if(s.size()&1) return cout << "No", 0;
	cout << "Yes";
}



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

int main(void){
    int N,M,X;
    cin>>N>>M>>X;
    vector<int> A(M);
    for(int i=0;i<M;i++){
        cin>>A[i];
    }
    int count_1=0;
    int count_2=0;
    for(int i=0;i<M;i++){
        if(A[i]<X) count_1++;
        if(A[i]>X) count_2++;
    }
    cout<<min(count_1,count_2)<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
	char s;
	int n,m;
	cin >> n >> s >> m;
	cout << (s == '+' ? n+m : n-m) << endl;
}

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

int N, M;
vector<vector<int>> G;
int dp[100100];

int rec(int v)
{
    if (dp[v] != -1)
    {
        return dp[v];
    }

    int res = 0;
    for (auto nv : G[v])
    {
        res = max(res, rec(nv) + 1);
    }

    return dp[v] = res;
}

int main()
{
    // 入力受け取り
    cin >> N >> M;
    G.assign(N, vector<int>());

    for (int i = 0; i < M; i++)
    {
        int x, y;
        cin >> x >> y;
        --x, --y;
        G[x].push_back(y);
    }

    // 初期化
    for (int v = 0; v < N; v++)
    {
        dp[v] = -1;
    }

    // 全ノードを一通り更新しながら答えを求める
    int res = 0;
    for (int v = 0; v < N; v++)
    {
        res = max(res, rec(v));
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 8192
from collections import defaultdict
import heapq

def get_dikstra(graph_data, weigh_data, node_num, start):
    dist_data = [-1 for i in range(node_num + 1)]
    check_num = [(0, start)]

    while len(check_num) > 0:
        now_dist, now_node = heapq.heappop(check_num)
        if dist_data[now_node] != -1:
            continue
        dist_data[now_node] = now_dist
        for next_node in graph_data[now_node]:
            if dist_data[next_node] != -1:
                continue
            heapq.heappush(check_num, (now_dist + weigh_data[(now_node, next_node)], next_node))

    return dist_data


def main():
    node_num, edge_num, start, goal = map(int, input().split())
    graph_data = defaultdict(set)
    yen_data = defaultdict(int)
    knoke_data = defaultdict(int)

    for i in range(edge_num):
        a, b, c, d = map(int, input().split())
        graph_data[a].add(b)
        graph_data[b].add(a)
        yen_data[(a, b)] = c
        yen_data[(b, a)] = c
        knoke_data[(a, b)] = d
        knoke_data[(b, a)] = d

    yen_dist = get_dikstra(graph_data, yen_data, node_num, start)
    knoke_dist = get_dikstra(graph_data, knoke_data, node_num, goal)

    ans_list = [0 for i in range(node_num + 1)]

    ans_list[node_num] = yen_dist[node_num] + knoke_dist[node_num]
    for i in range(1, node_num)[::-1]:
        ans_list[i] = min(ans_list[i + 1], yen_dist[i] + knoke_dist[i])

    first = 10 ** 15
    for i in range(1, node_num + 1):
        print(first - ans_list[i])





if __name__ == '__main__':
    main()

Measured memory_bytes: 133612
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C;
    cin >> A >>B>>C;
    int D[10];
   D[0]=A*C-B;
   cout << D[0]<<endl;
   for(int i=1;i<10;i++){
       D[i]=D[i-1]*A-B;
       cout <<D[i]<<endl;
   }
   
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> b(N);
    for(int i = 0; i < N; i++) {
        cin >> b.at(i);
        b.at(i)--;
    }
    
    vector<int> ans;
    for(int i = 0; i < N; i++) {
        for(int j = b.size()-1; j >= 0; j--) {
            if(b.at(j)==j) {
                ans.push_back(j);
                b.erase(b.begin() + j);
                break;
            }
        }
    }
    
    if(ans.size()!=N) cout << -1 << endl;
    else {
        for(int i = N-1; i >= 0; i--) cout << ans.at(i) + 1 <<endl;
    }
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int mcnt=0,mn=1e9;
	int64_t ans=0;
	for(int i=0;i<n;++i){
		int a; cin>>a;
		int A=abs(a);
		if(a<0)++mcnt;
		ans+=A;
		mn=min(mn,A);
	}
	cout<<((1&mcnt)?ans-mn*2:ans)<<"\n"s;
}

Measured memory_bytes: 256
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	vector<ll>arr(n);
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	arr[0]--;
	for(ll i=1;i<n;i++)
	{
		if(arr[i]<arr[i-1])
		{
			cout<<"No";
			return 0;
		}
		else if(arr[i]>arr[i-1])
		{
			arr[i]--;
		}
	}
	cout<<"Yes";
    return 0;
}


//252908XL

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
using namespace std;

int main() {
	int N, i = 1, j;
	vector<long long> NN;
	cin >> N;

	while (N >= 0) {
		NN.push_back(i);
		N -= i;
		//cout << i << endl;
		i++;
	}
	for (j = 0; j < i - 1; j++) {
		if (NN[j] != N*-1) {
			cout << NN[j] << endl;
		}
	}

	return 0;
}

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

int main() {
  string S;
  int month;
  cin >> S;
  month = stoi(S.substr(5, 2));
  if (month < 5) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
  return 0;
}

Measured memory_bytes: 760
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

struct Card{
    char suit;
    char value;
};

void bubble(Card c[], int n){
    for(int i = 0; i < n; i++){
        for(int j = n-1; j >= i; j--){
            if(c[j].value < c[j-1].value){
                Card tmp = c[j-1];
                c[j-1] = c[j];
                c[j] = tmp;
            }
        }
    }
}

void selection(Card c[], int n){
    for(int i = 0; i < n-1; i++){
        int minidx = i;
        for(int j = i; j < n; j++){
            if(c[minidx].value > c[j].value){
                minidx = j;
            }
        }
        if(minidx != i){
            Card tmp = c[i];
            c[i] = c[minidx];
            c[minidx] = tmp;
        }
    }
}

void print(Card c[], int n){
    for(int i = 0; i < n; i++){
        if(i > 0) cout << " ";
        cout << c[i].suit << c[i].value;
    }
    cout << endl;
}

bool isStable(Card c1[], Card c2[], int n){
    bool flag = true;
    for(int i = 0; i < n; i++){
        if(c1[i].suit != c2[i].suit){
            flag = false;
            break;
        }
    }
    return flag;
}

int main() {
    Card c1[100], c2[100];
    int n; cin >> n;

    for(int i = 0; i < n; i++){
        cin >> c1[i].suit >> c1[i].value;
        c2[i] = c1[i];
    }

    bubble(c1, n);
    print(c1, n);
    cout << "Stable" << endl;
    selection(c2, n);
    print(c2, n);
    cout << (isStable(c1,c2,n)?"Stable":"Not stable") << endl;
}


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

using namespace std;

using ll = long long;
using db = double;
using vi = vector<int>;
#define pb push_back

ll h, w; 

ll maxOF(ll a, ll b, ll c) {
	if (a > b) swap(a, b); 
	if (a > c) swap(a, c); 
	if (b > c) swap(b, c); 
	return c-a; 
}

int main() { 
	cin>>h>>w;
	ll ans = h*w; 
	for (ll i = 0; i <= h; ++i) {
		ans = min(ans,maxOF((h-i)*w,i*(w/2),i*((w+1)/2))); 
		ans = min(ans,maxOF((h-i)*w,i/2*w,(i+1)/2*w)); 
	}
	swap(h, w); 
	for (ll i = 0; i <= h; ++i) {
		ans = min(ans,maxOF((h-i)*w,i*(w/2),i*((w+1)/2))); 
		ans = min(ans,maxOF((h-i)*w,i/2*w,(i+1)/2*w)); 
	}
	cout<<ans<<endl; 
	return 0;
}


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

using namespace std;

int main() {
    int t;
    cin >> t;
    if (t >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <math.h>

long long getsum(long long b, long long n){
    if (n<b) return n;
    else return getsum(b, n/b) + n % b;
}

int p_max(long long n, long long s){
    int sq = sqrt(n);
    if (s < sq) return s;
    else if (sq*sq < n) return sq;
    else return sq-1;
}

int main(){
    
    long long n, s;
    
    scanf("%lld %lld", &n, &s);
    
    if (s == n){
        printf("%lld\n", n+1);
        return 0;
    }
    if (s > n){
        printf ("%d\n", -1);
        return 0;
    }
    for (int b=2; b<=sqrt(n); b++){
        if (getsum(b, n) == s){
            printf("%d\n", b);
            return 0;
        }
    }
    for (int p=p_max(n, s); p>=1; p--){
        if ((n-s) % p == 0){
            if (getsum((n-s)/p+1, n) == s){
                printf("%lld\n", (n-s)/p+1);
                return 0;
            }
        }
    }
    
    printf("%d\n", -1);
    return 0;
}

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

int main(){
  ll n;  
  cin>>n;
  ll keta=1;
  while(1){
    if(n-powl(26,keta)<=0) break;
    n-=powl(26,keta);
    keta++;
  }
  n--;
  //cout<<n<<endl;
  string s(keta,'a');
  ll i=keta-1;
  while(n>0){
    s[i]='a'+n%26;
    n/=26;
    i--;
    //cout<<n<<endl;
  }
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main()
{int a,b,c,d;cin>>a>>b>>c>>d;int x=min(b,d);
if(a==c)
{cout<<x-a;}
if(c>a)
{
if(c>=b)
{cout<<"0";}
else
{cout<<x-c;}
}
if(a>c)
{
if(a>=d)
{cout<<"0";}
else
{cout<<x-a;}
}
return 0;
}

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

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int n; string s; cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < 1000; i++) {
        string pin;
        string tmp = to_string(i);
        for (int i = 0; i < 3 - (int)tmp.length(); i++) {
            pin.push_back('0');
        }
        pin += tmp;
        // cout << pin << '\n';

        for (int j = 0, k = 0; j < s.length(); j++) {
            if (s[j] == pin[k]) {
                k++;
                if (k == 3) {
                    ans++;
                    break;
                }
            }
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 384
import collections
S = input()

even = collections.defaultdict(int)
odd = collections.defaultdict(int)

for i in range(len(S)):
    if i % 2 == 0:
        odd[S[i]] += 1
    else:
        even[S[i]] += 1

odd = list(odd.keys())
even = list(even.keys())

if "R" in odd:
    if odd.index("R") >= 0:
        odd.pop(odd.index("R"))
if "U" in odd:
    if odd.index("U") >= 0:
        odd.pop(odd.index("U"))
if "D" in odd:
    if odd.index("D") >= 0:
        odd.pop(odd.index("D"))

if len(odd) != 0:
    print("No")
    exit(0)

if "L" in even:
    if even.index("L") >= 0:
        even.pop(even.index("L"))
if "U" in even:
    if even.index("U") >= 0:
        even.pop(even.index("U"))
if "D" in even:
    if even.index("D") >= 0:
        even.pop(even.index("D"))

if len(even) != 0:
    print("No")
else:
    print("Yes")


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

int main () {
  string S;
  cin >> S;
  int p = 0;
  int m = 0;
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) == '+'){
      p++;
    }
    if(S.at(i) == '-'){
      m++;
    }
  }
  cout << p - m << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#define rep(i,s,e) for(int i = s;i<e;i++)
using namespace std;
int dx[4] = {0,0,-1,1};
int dy[4]  = {-1,1,0,0};
int main()
{
   int r,c;
   while(cin>>r>>c){
        char vis[r][c];
        rep(i,0,r) cin>>vis[i];
        int flag = 1;
        rep(i,0,r)
            rep(j,0,c){
                if(vis[i][j]=='#'){
                    int f = 0;
                    rep(k,0,4){
                        int x = i+dx[k];
                        int y = j+dy[k];
                        if(x>=0&&x<r&&y>=0&&y<=c){
                            if(vis[x][y]=='#'){
                              f = 1;
                            }
                        }
                    }
                    if(f==0) flag = 0;
                }
            }
        if(flag) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e30
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q, H, W, L, R, K, X, A, B, C, Z;
ll ans;
string S;
ll a[200];
ll x[100000000];
ll y[100000000];
ll nowcost = 1;
ll twopow[202020];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll DP[1000001];
int main() {
	cin>>N;
	ans =INF;
	rep(i,0,N)cin>>a[i];
	rep(i,-100,101){
		ll tmp=0;
		rep(j,0,N){
			tmp+=(a[j]-i)*(a[j]-i);
		}
		ans = min(ans,tmp);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
using namespace std;

main() {
    int N,M; cin >> N >> M;
    cout << N-M+1 << endl;
}

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

using namespace std;

void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

typedef pair<int,int> pii;
typedef long long int ll;
typedef long double ld;

inline int two(int n) { return 1 << n; }
inline int test(int n, int pos) { return (bool) (n & two(pos)); }
inline void set_bit(int &n, int b) { n |= two(b); }
inline void unset_bit(int &n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }

const int DMAX = 1e5+10;

vector <int> vec;
vector <int> arb[DMAX];

char s[DMAX];

int V[DMAX];

int n;

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

    int t,i,j,lg;

    cin>>s;
    lg=strlen(s);
    for(i=0;i<lg && s[i] != 'C';i++);
    if(i == lg){
       cout<<"No\n";
       return 0;
    }
    for(;i<lg && s[i] != 'F';i++);
    if(i == lg){
       cout<<"No\n";
       return 0;
    }
    cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 2560
require "date"
ma= gets.chomp.split(" ").map(&:to_i)
mb= gets.chomp.split(" ").map(&:to_i)
day_a=Date.new(2019,ma[0],ma[1])
day_b=Date.new(2019,mb[0],mb[1])
if (day_a)+1 == day_b && mb[1]==1
    puts 1
else
    puts 0
end

Measured memory_bytes: 2040
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
const int MAXN = 234567;
bool visit[MAXN];
int dis[MAXN];

int main() {
    int K;
    scanf("%d", &K);
    if (K == 1) return !printf("1\n");
    priority_queue<pii, vector<pii>, greater<pii>> pq;
    pq.push(make_pair(1, 1));
    while (!pq.empty()) {
          auto tp = pq.top();
          pq.pop();
          int cur = tp.second, cost = tp.first;
          if (visit[cur]) continue;
          visit[cur] = 1;
          dis[cur] = cost;
          pq.push(make_pair(cost + 1, (cur + 1) % K));
          pq.push(make_pair(cost, (cur * 10) % K));
    }
    printf("%d\n", dis[0]);
    return 0;
}


Measured memory_bytes: 1912
import numpy as np
 
n,X = map(int,input().split())
xs = np.array(list(map(int,input().split())))
cumsumx =np.insert(np.cumsum(xs),0,0)
 
cut = np.int_(3000000000000000000)
 
def cutsum(array):
    acm = np.int_(0)
    for i in array:
        if acm <= cut:
            acm += i
        else:
            acm = cut
            break
    return(acm)
 
def energy(k):
    nok = n//k
    offset = (n+k)*X
    acm = (n+k)*X + 3*cumsumx[-1] - 2*cumsumx[-k-1]
    acm += 2*cutsum(cumsumx[::-k])
    return(acm)
 
ans = (n+1)*X+2*cutsum(cumsumx)+3*cumsumx[-1]-2*cumsumx[-2]
for j in range (2,min(n//2+4,n+1)):
    tmp = energy(j)
    if tmp < ans:
        ans =tmp
 
print(ans)
 
 
 

Measured memory_bytes: 34768
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 202000;
int n,a[MAXN],fr[MAXN],need[MAXN];

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> n;
  int ans = 0;
  for(int i=0;i<=n;i++){
    cin >> a[i];
    ans+=a[i];
  }

  if(n==0){
    if(a[0]!=1){
      cout << -1 << endl;
    }
    else {
      cout << 1 << endl;
    }
    return 0;
  }
  if(a[0]!=0){
    cout << -1 << endl;
    return 0;
  }

  int cur = 1;
  fr[0]=1;
  for(int i=1;i<=n;i++){
    cur*=2;
    cur = min(cur,(int)1e18);
    // fr[i] = cur;
    if(cur<a[i]){
      cout << -1 << endl;
      return 0;
    }
    cur-=a[i];
    fr[i]=cur;
    // cerr << fr[i] << endl;
  }
  // cur = 1;
  // for(int i=1;i<=n;i++){
  //   cur*=2;
  //   cur = min(cur,(int)1e12);
  //   fr[i] = cur;
  // }
  need[n]=a[n];
  fr[n]=0;
  for(int i=n-1;i>=0;i--){
    int give = min(fr[i],fr[i+1]+a[i+1]);
    // need[i] = min(fr[i],need[i+1]);
    ans+=give;
    fr[i]=give;
    // cerr << give << endl;
  }
  cout << ans << endl;


return 0;
}
///....


Measured memory_bytes: 5220
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int n,s[10001]={},q,t,cnt=0;
  cin>>n;
  for(int i=0;i<n;i++)scanf("%d",&s[i]);
  cin>>q;
  for(int i=0;i<q;i++){
    scanf("%d",&t);
    s[n+1]=t;
    int j;
    for(j=0;s[j]!=t;j++);
    if(j!=(n+1))cnt++;
  }
  cout<<cnt<<endl;

  return 0;
}



Measured memory_bytes: 3256
#include<iostream>
#include<vector>
#include<string>
#define rep(i,n) for(int i = 0;i < (int)(n);i++)
using namespace std;
using ll = long long;
const ll INF = 1LL << 31;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
	int n, m, a = 0;
	ll dp[100010];
	cin >> n;
	rep(i, n + 10)dp[i] = 0;
	dp[0] = 1;
	cin >> m;
	rep(i, m) { 
		cin >> a;
		dp[a] = -1; 
	}

	for (int i = 0; i < n; i++) {
		if (dp[i] != -1) {
			if (dp[i + 1] != -1)dp[i + 1] += (dp[i]);
			if (dp[i + 2] != -1)dp[i + 2] += (dp[i]);
			if (dp[i + 1] != -1)dp[i + 1] %= mod;
			if (dp[i + 2] != -1)dp[i + 2] %= mod;
		}
	}
	cout << dp[n] << endl;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll 				long long
#define ld 				long double
#define fastio 			ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) 		cerr<<#x<<" "<<x<<endl
#define cina(a,n) 		for(ll i = 0;i<n;i++)	cin>>a[i];
#define couta(a,n) 		for(ll i = 0;i<n;i++) cout<<a[i]<<" ";
#define fauto(ar)		for(auto x : ar)	cout<<x<<" ";
#define mod 			1000000007
#define siz 			1005 
#define f 				first
#define s 				second
#define pb 				push_back
#define endl 			"\n"
#define ci 				cin.ignore()
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	if((s.length() == t.length()-1) && (s == t.substr(0,s.length())))
	{
		cout<<"Yes";
	}
	else
	cout<<"No";
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int d=N/2-1;
  int a[N];
  vector<int> s;
  for(int i=0;i<N;i++){
    cin>>a[i];
      s.push_back(a[i]);
  }
    sort(s.begin(),s.end());
    cout<<s[d+1]-s[d]<<endl;
}

Measured memory_bytes: 4196
n = int(input())
a = list(map(int, input().split()))
import copy
b = copy.copy(a)
tall = a[0]
for i in range(n):
    if a[i]<tall:
        a[i] = tall
    elif a[i]>tall:
        tall = a[i]
print(sum(a)-sum(b)) 

Measured memory_bytes: 32224
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

int main (void) {

  int n; std::cin >> n;
  std::vector<int> p(n);
  for(int i=0; i<n; i++) std::cin >> p[i];


  int ans = 0;
  for(int i=1; i<n-1; i++) {
    if ( (p[i] < p[i-1] && p[i+1] < p[i]) || (p[i] > p[i-1] && p[i+1] > p[i]) ) {
      ans++;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}

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

#define ll long long
#define vi vector<int>
#define vc vector<char>
#define vt vector<string>
#define si set<int>
#define sc set<char>
#define st set<string>
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back;

using namespace std;
int main()
{
    int n;
    cin>>n;
    vi v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    vi s;
    for(auto e:v)
        s.push_back(e);
        sort(s.begin(),s.end());
        int cnt=0;
    for(int i=0;i<n;i++)
        if(s[i]!=v[i])
        cnt++;
    if(cnt<=2)
        cout<<"YES";
    else cout<<"NO";
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
typedef long long ll;

using namespace std;


int main() {
	ll N;
	
	cin >> N;
	ll a = 10000000000000;
	for (ll i = 1; i < 5000001; i++) {
		if (N%i == 0) {
			if (a > (i + (N / i) - 2)) {
				a = i;
				a += (N / i) - 2;
			}
		}
	}

	cout << a;

	return 0;
}


Measured memory_bytes: 256
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <bitset>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

ll gcd(ll a, ll b)
{
    if (a > b)
        std::swap(a, b);

    while (true)
    {
        auto m = b % a;
        if (m == 0)
            return a;
        b = a;
        a = m;
    }
}

int main()
{
    using namespace std;

    int n, k;
    string s;
    cin >> n >> k >> s;

    s[k - 1] = tolower(s[k - 1]);

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
words = [input() for i in range(N)]
preword =words[0]
se = set([words[0]])
hantei = True
for w in words[1:]:
  if w in se:
    hantei = False
  if preword[-1] != w[0]:
    hantei = False
  se.add(w)
  preword = w
print('Yes' if hantei else 'No')

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int a[100005];
int main() {
	int n,m,cnt=0;
	cin >> n>>m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= n; i++) {
		if (a[i] >= m)
			cnt++;
	}
	cout << cnt;
	return 0;
}

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

using namespace std;
int ans=-1, d,mod =1e9+7, dp[10004][3][101];
string x;

int solve (int i , int t, int cnt){
if (i == x.size()-1) {
    if (cnt) return 0;
    return 1;
}

if (dp[i][t][cnt]!=-1) return dp[i][t][cnt];
int v =0;

for (int j=0; j<10; j++){
    if (t==0 && j == x[i+1]-48) v = (v+solve(i+1, 0, (cnt+j)%d))%mod;
    else if (t==0 && j > x[i+1]-48) break;
    else v = (v+solve(i+1, 1, (cnt+j)%d))%mod;
}

return dp[i][t][cnt]=v;
}

int main()
{
memset(dp , -1, sizeof dp);
    cin >> x >> d;
    int first = x[0]-48;

    for ( int i=0; i<first; i++)  ans=  (ans+solve(0, 1, i%d))%mod;
    ans=  (ans+solve(0, 0, first%d))%mod;

    cout << ans%mod;
    return 0;
}


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

int main(){
    ll n, k, q; cin >> n >> k >> q;
    ll a[q];

    //参加者iの正答数を保持
    map<ll,ll> mp;

    for (int i=0;i<q;i++){
        cin >> a[i];
        mp[a[i]-1]++;
    }

    for (int i=0;i<n;i++){
        if ( mp.find(i) == mp.end() ) {
        // 正解したことがない
            if ((k-q) <= 0){
                cout << "No" << endl;
            } else {
                cout << "Yes" << endl;
            }
        } else {
            //　正解したことがある
            if ((k-q+mp[i]) <= 0){
                cout << "No" << endl;
            } else {
                cout << "Yes" << endl;
            }
        } 
    }

    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int main()
{
    int n, k; cin >> n >> k;
    int sum = 0;
    int arr[n];
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr, arr + n);
    for (int i = 0; i < k; i++)
        sum += arr[i];
    cout << sum << '\n';
    return 0;
}

Measured memory_bytes: 3592
r,c = map(int,input().split())
l = []
for i in range(r):
    l1 = list(map(int,input().split()))
    l.append(l1)
#给每一行加和
for i in range(r):
    tmp = 0
    for j in range(c):
        tmp += l[i][j]
        
    l[i].append(tmp)

tmpl = []
#给每一列加
for i in range(c+1):
    tmp = 0
    for j in range(r):
        tmp+=l[j][i]
    tmpl.append(tmp)
l.append(tmpl)

for i in range(r+1):
    for j in range(c+1):
        if j!=c:
            print(l[i][j],end = ' ')
        else:
            print(l[i][j])


Measured memory_bytes: 6224
N  = int(input())
a = [int(i) for i in input().split()]
a.append(N+1)
dupe = []

temp = 1
for i in range(N):
    if a[i] == a[i+1]:
        temp += 1
    elif temp != 0:
        dupe.append(temp)
        temp = 1

b = [int(i/2) for i in dupe]
print(sum(b))

Measured memory_bytes: 3064
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
a = III()

ans = 0
for i in range(N):
    while a[i]%2==0:
        a[i] = a[i]//2
        ans += 1

print(ans)

Measured memory_bytes: 40688
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
int64_t INF = 1000000007;
// int64_t INF = 9223372036854775807;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,c;
    cin >> a >> b >> c;
    int64_t res = 0;
    if(a%2==0 || b%2==0 || c%2==0){
        res = 0;
    }else{
        if(b<c) swap(b,c);
        if(a<b) swap(a,b);
        res = b*c;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n,l[200],s,t,temp,x=0;
  scanf("%d",&n);
  for(s=0;s<2*n;s++){
    scanf("%d",&l[s]);
  }
  for(s=0;s<2*n-1;s++){
    for(t=s+1;t<2*n;t++){
      if(l[s]>l[t]){
        temp=l[s];
        l[s]=l[t];
        l[t]=temp;
      }
    }
  }
  for(s=0;s<2*n;s=s+2){
    x=x+l[s];
  }
  printf("%d",x);
  return 0;
}

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

int main() {
  int N,K;
  string S;
  cin>>N>>K>>S;
  if(S.at(K-1)=='A'){
    S.at(K-1)='a';
    cout<<S<< endl;
  }
  if(S.at(K-1)=='B'){
    S.at(K-1)='b';
    cout<<S<< endl;
  }
  if(S.at(K-1)=='C'){
    S.at(K-1)='c';
    cout<<S<< endl;
  }
}

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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') ch = getchar(), f = -1;
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> void out(Tp x) {
	if (x > 9) out(x / 10);
	putchar(x % 10 + '0');
	return;
}

template <typename Tp> Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;}
template <typename Tp> Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;}
template <typename Tp> bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);}
template <typename Tp> bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);}

const int MAXN = 110;

int n;
int dis[MAXN], tot[MAXN];

void error()
{
	puts("Impossible");
	exit(0);
}

int main()
{
	in(n);
	FOR(i, 1, n) in(dis[i]), tot[dis[i]]++;

	int maxx = -1;
	FOR(i, 1, n) chkmax(maxx, dis[i]);
	
	if (maxx == 1 && n > 2) error();
	FOR(i, 1, (maxx + 1) / 2 - 1) if (tot[i]) error();

	if (maxx % 2 == 0 && tot[maxx / 2] != 1) error();
	if (maxx % 2 != 0 && tot[(maxx + 1) / 2] != 2) error();
	FOR(i, (maxx + 1) / 2 + 1, maxx) if (tot[i] < 2) error();

	puts("Possible");
	
	return 0;
}


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

class AtCoder {
  public static void Main() {
    var inputs = Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToList();
    var N = inputs[0];
    var K = inputs[1];
    var ans = 0;
    for(; N > 0; ans++) {
      N = N / K;
    }    
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 11220