akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  int k,n;
  cin >> k >> n;
  vector<int> a(n);
  REP(i,n)cin >> a[i];
  vector<ll> v;
  REP(i,n-1){
    v.push_back(abs(a[i]-a[i+1]));
  }
  v.push_back(abs(a[0]+k-a[n-1]));
  sort(ALL(v),greater<ll>());
  ll res = 0;
  REP(i,n)if(i)res += v[i];
  cout << res << endl;


  return 0;
}


Measured memory_bytes: 3188
datas = input().split(" ")

h = int(datas[0])
w = int(datas[1])


if( h==1 ):
  print(1)
elif( w== 1):
  print(1)
elif( h % 2 == 0  and w % 2 == 0):
  print( h * w//2 )
elif( h % 2 == 0 ):
  print( (h * (w-1))//2 + h // 2  )
elif( w % 2 == 0):
  print( (w * (h-1))//2 + w // 2  )
else:
  print( ((h-1) * (w-1))//2 + (h-1) // 2 + w // 2 +1  )

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

int main() {
	int n;cin>>n;
  	vector<int> a(n);
  	for(int i=0;i<n;i++){
    	cin>>a[i];
    }
  	int cnt=0;
  	int temp=0;
  	for(int i=0;i<n;i++){
    	if(temp<a[i]){
        	cnt+=a[i]-temp;
        }
      	temp=a[i];
    }
  	cout<<cnt<<endl;
}

Measured memory_bytes: 256
def resolve()

    s=gets.strip
    while s!= ""

        if s.end_with?("dream")
            s=s.slice!(0,s.length-5)
            next
        end


        if s.end_with?("dreamer")
            s=s.slice!(0,s.length-7)
            next
        end

        if s.end_with?("erase")
            s=s.slice!(0,s.length-5)
            next
        end

        if s.end_with?("eraser")
            s=s.slice!(0,s.length-6)
            next
        end

        puts "NO"
        return

    end
    puts "YES"



end



resolve()

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

int main(){
    int H, W;
    
    while(1){
        cin >> H >> W;
        if(W == 0 && H == 0)break;
        
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                cout << "#";
            }
            cout << "\n";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
import java.util.Scanner;
 
public class Main {

	public static final MyScanner in = new MyScanner();

	public static void main(String[] args) {

		int A = in.nextInt();
		int B = in.nextInt();

		System.out.println(work(A,B));

	}

	static long work (int a, int b) {
		int temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

	public static class MyScanner{
		Scanner sc = new Scanner(System.in);
		String nextLine() {return sc.nextLine();}
		String next() {return sc.next();}
		int nextInt() {return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next());}
	}
}

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

const int inf = (1 << 28);

struct Network {
    struct Arc {
        int from, to, cap, cost, rev;
        Arc() {}
        Arc(int from, int to, int cap, int cost, int rev) :
            from(from), to(to), cap(cap), cost(cost), rev(rev) {}
    };

    int n;
    vector<vector<Arc>> graph;

    Network(int n = 0) : n(n), graph(n) {}

    void addArc(int from, int to, int cap) {
        graph[from].emplace_back(from, to, cap, 0, graph[to].size());
        graph[to].emplace_back(to, from, 0, 0, graph[from].size() - 1);
    }

    int findBlockingFlow(vector<Arc*>& hist, int s, int t) {
        vector<int> dist(n, inf), limit(n, inf);
        fill(hist.begin(), hist.end(), nullptr);

        queue<int> que;
        dist[s] = 0;
        que.push(s);

        while (!que.empty()) {
            int u = que.front(); que.pop();

            for (Arc& arc : graph[u]) {
                if (dist[arc.to] > dist[u] + 1 and arc.cap > 0) {
                    dist[arc.to] = dist[u] + 1;
                    hist[arc.to] = &arc;
                    limit[arc.to] = min(limit[u], arc.cap);
                    que.push(arc.to);

                    if (arc.to == t) break;
                }
            }
        }
        return limit[t];
    }

    int findMaximumFlow(int s, int t) {
        vector<Arc*> hist(n, nullptr);
        int sumFlow = 0, flow;

        while (flow = findBlockingFlow(hist, s, t), hist[t] != nullptr) {
            Arc* flowPtr = hist[t];
            while (flowPtr != nullptr) {
                flowPtr->cap -= flow;
                graph[flowPtr->to][flowPtr->rev].cap += flow;
                flowPtr = hist[flowPtr->from];
            }
            sumFlow += flow;
        }
        return sumFlow;
    }
};

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

    int n, m;
    cin >> n >> m;

    Network network(n);
    for (int i = 0; i < m; i++) {
        int u, v, c;
        cin >> u >> v >> c;
        network.addArc(u, v, c);
    }
    cout << network.findMaximumFlow(0, n - 1) << endl;

    return 0;
}


Measured memory_bytes: 3296
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

void solve()
{
    int n,W;
    cin>>n>>W;
    vl w(n),v(n);
    vector<vl> dp(n+1,vl(W+1,0));
    for(int i=0;i<n;i++) {
        cin>>w[i];
        cin>>v[i];
    }

    for(int i=0;i<n;i++) {
        for(int j=1;j<=W;j++) {
            if(j-w[i]>=0) {
                dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i]);
            }
            else {
                dp[i+1][j] = dp[i][j];
            }
        }
    }

    cout<<dp[n][W];
    
}

int main()
{
    fastio;
    int t;
    t = 1;
    //cin >> t;
    //int test=t;
    
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 83076
#include <iostream>
#include <string>
#include <queue>
#include <map>

using namespace std;

const int inf = 99999;

struct St{
  string worm;
  int cnt;
};

typedef map<string, bool> Mp;

bool check(string str)
{
  bool f = true;  

  for(int i = 1; i < str.size(); i++){
    if(str[i] != str[0]){
      f = false;
      break;
    }
  }

  return f;
}

char getC(char s, char t)
{
  if((s == 'r' && t == 'g') || (s == 'g' && t == 'r')){
    return 'b';
  }
  if((s == 'r' && t == 'b') || (s == 'b' && t == 'r')){
    return 'g';
  }

  return 'r';
}

int bfs(string str)
{
  int r = inf+1;
  queue<St> que;
  map<string, bool> mpp;
  St st1, st2;
  st1.worm = str;
  st1.cnt = 0;
  que.push(st1);
  mpp[str] = true;

  while(!que.empty()){
    st1 = que.front();
    que.pop();
    if(check(st1.worm) || st1.cnt > inf){
      r = st1.cnt;
      break;
    }

    for(int i = 0; i < (st1.worm).size()-1; i++){
      string s1 = st1.worm;
      if(s1[i] != s1[i+1]){
	s1[i] = s1[i+1] = getC(s1[i], s1[i+1]);
	if(!mpp[s1]){
	  mpp[s1] = true;
	  st2.worm = s1;
	  st2.cnt = st1.cnt+1;
	  que.push(st2);
	}
      }
    }
  }


  return r;
}

int main()
{
  int t;
  string str;

  while(cin>>str && str != "0"){
    t = bfs(str);
    if(t > inf){
      cout << "NA" << endl;
    } else {
      cout << t << endl;
    }
  }

  return 0;
}

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

int main() {
    map<string, int> m;
    m["SUN"] = 0; m["SAT"] = 1; m["FRI"] = 2; m["THU"] = 3; m["WED"] = 4; m["TUE"] = 5; m["MON"] = 6; m["SUN"] = 7;
    string s;
    cin >> s;
    cout << m[s];

    return 0;
}

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

int main(){
  int x = 0;
  int i = 0;
  int total = 0;

  scanf("%d", &x);

  for(i = 0;i < x; i++){
    int start = 0;
    int end = 0;
    scanf("%d %d", &start, &end);
    total = total + (end - start + 1);
  }

  printf("%d\n", total);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
    #include <string>
    #include <math.h>
    #include<algorithm>
    using namespace std;
     
    int main(){
      int N;
      cin >> N;
      string S[N];
      for(int i=0;i<N;i++){
       cin >> S[i]; 
      }
      long long ans=0;
      char march[5]={'M','A','R','C','H'};
      long long num[5]={};
      for(int i=0;i<N;i++){
        for(int j=0;j<5;j++){
         if(S[i][0]==march[j]){
          num[j]++; 
         }
        }
      }
      for(int i=0;i<5;i++){
       for(int j=0;j<i;j++){
        for(int k=0;k<j;k++){
         ans+=num[i]*num[j]*num[k]; 
        }
       }
      }
      cout << ans << endl;
      return 0;}

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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

string s, t;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s >> t;
    string sub = t.substr(0,s.length());
    cout << (s == sub ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        if (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            boolean isNotAll9 = false;
            for (int i = 1; i < line.length(); ++i) {
                if (line.charAt(i) != '9') {
                    isNotAll9 = true;
                    break;
                }
            }
            int ret = line.charAt(0) - '0' + 9 * (line.length() - 1);
            if (isNotAll9) {
                --ret;
            }
            System.out.println(ret);
        }
    }
}

Measured memory_bytes: 21972
N = int(input())

c = 0
ans = 'No'
for i in range(N):
    D1, D2 = map(int, input().split())
    if D1 == D2:
        c += 1
    
    else:
        c = 0
        
    if c == 3:
        ans = 'Yes'
        break

print(ans)

Measured memory_bytes: 9164
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
multiset<int> a[N];
int deg[N];

int main() {
  int n;
  scanf("%d", &n);
  map<ii, int> cnt;
  set<ii> A;
  for (int i = 0; i < 2 * (n - 1); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x > y) swap(x, y);
    --x; --y;
    a[x].insert(y);
    a[y].insert(x);
    if (++cnt[{x, y}] == 2) {
      A.insert({x, y});
    }
  }
  int k;
  for (k = 1; k < n; ++k) {
    if (A.empty()) break;
    ii cur = *A.begin();
    A.erase(cur);
    int x = cur.first, y = cur.second;
    if (a[x].size() < a[y].size()) swap(x, y);
    // trace(x, y);
    a[x].erase(y);
    for (auto& v : a[y]) {
      if (v == x) continue;
      a[x].insert(v);
      a[v].insert(x);
      int s = min(x, v), t = max(x, v);
      if (++cnt[{s, t}] == 2) {
        A.insert({s, t});
      }
      s = min(y, v), t = max(y, v);
      A.erase({s, t});
      a[v].erase(y);
    }
  }
  puts(k == n ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 44288
fun main(args: Array<String>) {
    while (true) {
        val dest = readLine()!!.toInt()

        if (dest == 0) break

        var bottom = 1
        var top = 1
        var r = 1

        while (true) {
            if (r == dest) {
                println("${bottom} ${top - bottom + 1}")
                break
            } else if (r < dest) {
                top += 1
                r += top
            } else {
                r -= bottom
                bottom += 1
            }
        }
    }
}




Measured memory_bytes: 26820
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set> 
#include<cmath>
using namespace std;
long long p  = 998244353;
//long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)
#define upper(h,val) upper_bound(h.begin(),h.end(),val)
#define mint modint<998244353>
#define end_s(a) cout <<a<<endl;return 0
template <std::uint_fast64_t Modulus> class modint {
	using u64 = std::uint_fast64_t;

public:
	u64 a;

	constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
	constexpr u64 &value() noexcept { return a; }
	constexpr const u64 &value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint &operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint &operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint &operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint &operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) {pa[x] = y;}
}
signed main(){
	int a, b; cin >> a >> b;
	cout << max(a, 2 * b) - 2 * b << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
 

//result = Math.pow(num1, num3)
//StringBuffer str = new StringBuffer(hoge1);
//String hoge2 = str.reverse().toString();
//map.containsKey(A)

//Map<String, Integer> map = new HashMap<String, Integer>(n);
/*for ( キーのデータ型 key : マップの名前.keySet() ) {
	データのデータ型 data = マップの名前.get( key );
	
	// keyやdataを使った処理;
}*/

//ArrayList<String> cc = new ArrayList<>(n);
//Collections.sort(list);
//Array.sort(list);
//Arrays.asList(c).contains("a")
//list.set(1,"walk");
public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	//static String eikomoji[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
	static long N;
	public static void main(String[] args) {
		int n=sc.nextInt();
		int a[]=new int[n];
		int nextMin=1;
		int ctn=0;
		for(int i=0;i<n;i++) {
			int v=sc.nextInt();
			if(v==nextMin) {
				nextMin++;
			}else {
				ctn++;
			}
		}
		if(nextMin==1) {
			p(-1);
		}else {
			p(ctn);
		}

	}
	

	
	
	
}


Measured memory_bytes: 76660
import copy

h = []
w = []

def countSharp(work):
    cnt = 0
    for row in work:
        for col in row:
            if col == '#':
                cnt += 1
    return cnt

def makeH(current, end):
  if len(current) == end:
    h.append(copy.copy(current))
    return
  else:
    current.append(True)
    makeH(current, end)
    current.pop(len(current) - 1)

    current.append(False)
    makeH(current, end)
    current.pop(len(current) - 1)

def makeW(current, end):
  if len(current) == end:
    w.append(copy.copy(current))
    return
  else:
    current.append(True)
    makeW(current, end)
    current.pop(len(current) - 1)

    current.append(False)
    makeW(current, end)
    current.pop(len(current) - 1)

H, W, K = map(int, input().split())

makeH([], H)
makeW([], W)

# print(h)
# print(w)

matrix = []
for i in range(0, H):
    row = []
    for c in input():
        row.append(c)
    matrix.append(row)

# for i in range(0, H):
# 	print(matrix[i])

answer = 0

for hh in h:
    for ww in w:
        work = []
        for h in range(0, H):
            work.append(copy.copy(matrix[h]))

        for i in range(0, H):
            for j in range(0, W):
                if hh[i] == True:
                    for jjj in range(0, W):
                        work[i][jjj] = 'r'
                if ww[j] == True:
                    for iii in range(0, H):
                        work[iii][j] = 'r'

        count = countSharp(work)
        if count == K:
            answer += 1

print(answer)


Measured memory_bytes: 9372
#include <stdio.h>

int main()
{
	double a, x, y[10];
	int b, i;

	while(scanf("%lf", &a) != EOF){
		x = 0;
		b = 0;
		y[0] = a;

		for (i = 1; i < 10; i++){
			if(b == 0) {y[i] = y[i-1]*2; b = 1;}
			else {y[i] = y[i-1]/3; b = 0;}
		}

		for (i = 0; i < 10; i++){
			x += y[i];
		}

		printf("%f\n", x);
	}

	return 0;
}

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

namespace ACLBeginnerContest
{
    class Program
    {
        static void Main(string[] args)
        {
            // 課題A - Repeat ACL(2020/9/26)

            int K = int.Parse(Console.ReadLine());

            string str = "ACL";
            if (K == 1)
            {
                Console.Write(str);
                return;
            }

            for (int i = 0; i < K - 1; i++)
            {
                str = str + "ACL";
            }
            Console.Write(str);
        }
    }
}


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

int main()
{
  int n;
  cin>>n;
  int k;
  cin>>k;
  int heights[n];
  for(int i=0;i<n;i++)
  {
    cin>>heights[i];
  }
  int count=0;
  for(int i=0;i<n;i++)
  {
    if(heights[i]>=k)
    {
      count++;
    }
  }
  cout<<count;
  
  
 return 0; 
}

Measured memory_bytes: 3984
#include <iostream>
#include <algorithm>

using namespace std;

#define int long long

const int N = 2e5 + 10;

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);    
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max({a * c, b * d, a * d, b * c});
  return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <math.h>
int main(){

  int N;
  scanf("%d",&N);
  long H[N];
  for (int i=0; i<N; i++){
    scanf("%ld", &H[i]);
  }
  int ans = 0;
  /*for (int i=0; i<N; i++){
    int j=i;
    int cnt = 0;
    while (H[j]>=H[j+1] && j<N){
      cnt++;
      j++;
    }
    if (cnt>ans){
      ans=cnt;
    }
  }*/
  int cnt[N];
  cnt[N-1]=0;
  for (int i=N-2; i>=0; i--){
    if (H[i]>=H[i+1]){
      cnt[i] = cnt[i+1]+1;
      if (cnt[i]>ans){
        ans=cnt[i];
      }
    } else {
      cnt[i]=0;
    }
  }
  printf("%d\n",ans);


  return 0;
}

Measured memory_bytes: 1408
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Attention solver = new Attention();
        solver.solve(1, in, out);
        out.close();
    }

    static class Attention {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            char[] s = in.next().toCharArray();

            int cost = 0;
            int maxcost = 0;
            int pos = 0;

            int result = 0;
            for (int i = 0; i < n; i++) {
                if (s[i] == 'W') {
                    cost--;
                } else if (s[i] == 'E') {
                    cost++;
                }
                if (maxcost < cost) {
                    maxcost = cost;
                    pos = i;
                }
            }

            for (int i = 0; i < n; i++) {
                if (i < pos) {
                    if (s[i] == 'W') {
                        result++;
                    }
                } else if (pos < i) {
                    if (s[i] == 'E') {
                        result++;
                    }

                }
            }

            out.println(result);
        }

    }
}



Measured memory_bytes: 43220
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main() {
  string s;
  cin>>s;
  if(s.size()<26){
    vector<bool>ch(26);
    rep(i,s.size()){
      ch.at(s.at(i)-'a')=true;
    }
    char c;
    rep(i,26){
      if(!ch.at(i)){
        c='a'+i;
        break;
      }
    }
    cout<<s<<c<<endl;
  }
  else{
    int n=-1;
    rep(i,s.size()-1){
      if(s.at(i)<s.at(i+1)){
        n=i+1;
      }
    }
    if(n==-1){
      cout<<-1<<endl;
    }
    else{
      vector<char>ch;
      rep2(i,n,s.size()){
        ch.push_back(s.at(i));
      }
      sort(ch.begin(),ch.end());
      rep(i,n-1){
        cout<<s.at(i);
      }
      rep(i,ch.size()){
        if(ch.at(i)>s.at(n-1)){
          cout<<ch.at(i);
          break;
        }
      }
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<functional>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
  int n, k;
  cin >> n >> k;
  int ans = k;
  rep(i, 1, n) {
    ans *= (k - 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
#define pb push_back
#define mp make_pair
#define inf 0x7fffffff
#define inff 100000
#define ff first
#define ss second
#define sz(x) ((int) (x).size())
#define fast cin.sync_with_stdio(0);cin.tie(0)
#define rep(i,N) for(int i = 0;i < N;i++)
#define frep(i,a,b) for(int i = a;i <= b;i++)
#define pii pair<int , int>
#define pll pair<ll , ll>
#define vii vector<int>
#define vpii vector< pii >
#define fill(A,v) memset(A,v,sizeof(A))
#define setbits(x) __builtin_popcountll(x)
#define print(A,j,k) for(int ii=j;ii<k;ii++)cout<<A[ii]<<" ";cout<<"\n"
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
#define SQRT 350
#define CASES int t;cin>>t;while(t--)
#define FILE freopen("inp.txt" , "r" , stdin);
#define ld long double

const int MOD = 1e9 + 7;
const int N = 1e6 + 500;
const int lgN = 20;
const ll INF = 1e16;

int main(int argc, char const *argv[])
{
	fast;

	int n;
	cin >> n;

	string a , b;
	cin >> a >> b;
	string ans = a;

	for(int i = 0;i < n;i++) {
		bool f = true;
		for(int j = 0 , k = i;max(j , k) < n;j++,k++)
			if (a[k] != b[j]) {
				f = false;
				break;
			}
		if (f) {
			// cout << "i " << i << '\n';
			int ret = 0;
			ret += a.size();
			// cout << a;
			ret += i;
			cout << ret << '\n';
			return 0;
		}
	}

	cout << 2 * n << '\n';

	return 0;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll a,b; cin >> a >> b;
    ll res = max(a+b,a-b);
    res = max(a*b,res);
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

ll dp[200200][2]; // dp[i][j]:i番目のグループで(j==0:左、j==1:右)を取った時の最大値
ll dp2[200200][2][2]; // dp2[i][j][k]:i番目のグループで(j==0:左、j==1:右)を取った時の最大値
                      // kは既に1グループ飛ばしたかどうか

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<=n;i++){
        // 初期化
        dp[i][0]=dp[i][1]=-1e18;
        dp2[i][0][0]=dp2[i][0][1]=dp2[i][1][0]=dp2[i][1][1]=-1e18;
    }
    int m=n/2;
    if(n%2==0){
        dp[1][0]=a[0],dp[1][1]=a[1];
        for(int i=1;i<m;i++){
            for(int j=0;j<2;j++){
                if(j==0){
                    dp[i+1][0]=max(dp[i+1][0],dp[i][j]+a[2*i]);
                }
                dp[i+1][1]=max(dp[i+1][1],dp[i][j]+a[2*i+1]);
            }
        }
        cout << max(dp[m][0],dp[m][1]) << endl;
    }
    else{
        // a[n-1]を使わない場合　上の偶数の場合と一緒
        dp[1][0]=a[0],dp[1][1]=a[1];
        for(int i=1;i<m;i++){
            for(int j=0;j<2;j++){
                if(j==0){
                    dp[i+1][0]=max(dp[i+1][0],dp[i][j]+a[2*i]);
                }
                dp[i+1][1]=max(dp[i+1][1],dp[i][j]+a[2*i+1]);
            }
        }
        // a[n-1]を使う場合
        dp2[1][0][0]=a[n-1]+a[0],dp2[1][1][0]=a[n-1]+a[1];
        dp2[1][0][1]=a[n-1];
        for(int i=1;i<m;i++){
            for(int j=0;j<2;j++){
                for(int k=0;k<2;k++){
                    if(k==0){
                        dp2[i+1][0][1]=max(dp2[i+1][0][1],dp2[i][j][k]);
                    }
                    if(j==0){
                        dp2[i+1][0][k]=max(dp2[i+1][0][k],dp2[i][j][k]+a[i*2]);
                    }
                    // a[n-2]は使えない事に注意！
                    if(i!=m-1)dp2[i+1][1][k]=max(dp2[i+1][1][k],dp2[i][j][k]+a[i*2+1]);
                }
            }
        }
        cout << max({dp[m][0],dp[m][1],dp2[m][0][1],dp2[m][1][1]}) << endl;
    }
}

Measured memory_bytes: 14292
#include <stdio.h>

int main()
{
    int a,b,c,count = 0;
    scanf("%d %d %d",&a,&b,&c);

    if(c <= b + a + 1)
    {
        printf("%d",b + c);
    }
    else
    {
        printf("%d",b * 2 + a + 1);
    }
    
}

Measured memory_bytes: 128
# coding: utf-8

def main():
    N = 0
    H = int(input())
    ans = 0

    while (True):
        H //= 2
        if H == 0:
            break
        N += 1

    for i in range(N + 1):
        ans += pow(2, i)

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 8796
N,M=map(int,input().split())

L=[0 for i in range(N+1)]
for i in range(M):
    a,b=map(int,input().split())
    L[a]+=1
    L[b]+=1
for _ in range(N+1):
    if L[_]%2==1:
        print("NO")
        exit()
print("YES")

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

int main(){
    int n, k, s;
    cin >> n >> k >> s;

    int tmp = s + 1;
    if(s == (int)pow(10, 9)) tmp = 1;

    for (auto i = 0; i < k; i++) {
        cout << s << " ";
    }
    for (auto i = k + 1; i <= n; i++) {
        if(i == n) cout << tmp << endl;
        else cout << tmp << " ";
    }
    return 0;
}

Measured memory_bytes: 1280
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 1/27/2019, 9:02:52 PM
# Powered by Visual Studio Code
#

n = gets.to_i
ary = []
3.times{
  ary << gets.chomp
}
n = ary[0].size
cnt = 0
for i in 0...n
  hash = {}
  for j in 0...3
    c = ary[j][i]
    if hash.has_key?(c)
      hash[c] += 1
    else
      hash[c] = 1
    end
  end
  maxi = hash.values.max
  cnt += 3 - maxi
end
puts cnt


Measured memory_bytes: 1788
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
lis=LI()
i=0
x=0
plot=[0]
while i<n:
    x=lis[x]-1
    i+=1
    plot.append(x)
#print(plot)
y=plot[-1]
for i in range(n):
    j=n-i-1
    if y==plot[j]:
        t=i+1
        break
#print(t)
for i in range(n):
    if plot[i]==plot[i+t]:
        am=i
        break
#print(am)
if k<=am:
    print(plot[k]+1)
else:
    print(plot[am+(k-am)%t]+1)

Measured memory_bytes: 95492
import itertools
n,m = map(int,input().split())

K = []

for i in range(m):
    l = list(map(int,input().split()))
    K.append(l[1:])
res = 0
p = list(map(int,input().split()))
for s in itertools.product([0,1],repeat=n):
    cnt = [0]*m
    for j in range(len(s)):
        if s[j] == 0:
            continue
        for k in range(len(K)):
            if (j+1) in K[k]:
                cnt[k]+=1
    flag = True

    for j in range(len(cnt)):
        if cnt[j]%2 != p[j]:
            flag = False
            break
    if flag:
        res += 1 
print(res)


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

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int s, t;
    scanf("%d%d", &s, &t);
    s--, t--;
    vector<vector<pair<int, int>>> g(n);
    for (int i = 0; i < m; ++i) {
        int u, v, w;
        scanf("%d%d%d", &u, &v, &w);
        u--, v--;
        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
    }

    constexpr int kMod = 1'000'000'000 + 7;

    auto Dijkstra = [&](int r) {
        constexpr int64_t kInf = 1'000'000'000'000'000'000;
        vector<pair<int64_t, int>> sp(n, make_pair(kInf, 0));
        vector<int> used(n);
        priority_queue<pair<int64_t, int>> pq;
        sp[r] = make_pair(0, 1);
        pq.emplace(0, r);
        while (!pq.empty()) {
            int x = pq.top().second;
            pq.pop();
            if (used[x]++) continue;
            for (auto e : g[x]) {
                if (sp[e.first].first > sp[x].first + e.second) {
                    sp[e.first].first = sp[x].first + e.second;
                    sp[e.first].second = sp[x].second;
                    pq.emplace(-sp[e.first].first, e.first);
                } else if (sp[e.first].first == sp[x].first + e.second) {
                    sp[e.first].second += sp[x].second;
                    if (sp[e.first].second >= kMod) sp[e.first].second -= kMod;
                }
            }
        }
        return sp;
    };

    auto ds = Dijkstra(s);
    auto dt = Dijkstra(t);
    const int64_t dist = ds[t].first;
    assert(dt[s].first == dist);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (auto e : g[i]) {
            if (ds[i].first + e.second + dt[e.first].first == dist && ds[i].first * 2 < dist && ds[e.first].first * 2 > dist) {
                int ways = 1LL * ds[i].second * dt[e.first].second % kMod;
                ways = 1LL * ways * ways % kMod;
                (ans += ways) >= kMod ? ans -= kMod : 0;
            }
        }
        if (ds[i].first == dt[i].first && ds[i].first * 2 == dist) {
            int ways = 1LL * ds[i].second * dt[i].second % kMod;
            ways = 1LL * ways * ways % kMod;
            (ans += ways) >= kMod ? ans -= kMod : 0;
        }
    }
    assert(ds[t].second == dt[s].second);
    ans = (1LL * ds[t].second * ds[t].second % kMod + kMod - ans) % kMod;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 15444
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> vec;
    for(int i = 0; i < n; i++)
    {
        int q, x;
        cin >> q;
        if(q == 0)
        {
            cin >> x;
            vec.push_back(x);
        }
        else if(q == 1)
        {
            cin >> x;
            cout << vec[x] << "\n";
        }
        else if(q == 2) vec.pop_back();
    }
    return 0;
}




Measured memory_bytes: 3992
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> point(N,K - Q);

	REP(i, Q) {
		int A;
		cin >> A;
		point[A - 1]++;
	}
	int cnt = 0;
	REP(i, N) {
		if (point[i] >= 1) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 1024
# include <bits/stdc++.h>
using namespace std;
# define int long long
const int N = 2e5 + 10, mod = 1e9 + 7, INF = 8e18;
main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	int x = min(n, k);
	n -= x;
	k -= x;
	if(k > 0) m = max(0ll, m - k);
	cout << n << ' ' << m << '\n';
}

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

int main()
{
	unordered_map<int,int> m;
	int n,x;
	cin>>x>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		m[a[i]]++;
	}
	int t=x;
	while(m.find(t)!=m.end())
		t--;
	int ans=t;
	t=x;
	while(m.find(t)!=m.end())
		t++;
	if(t-x<x-ans)
		ans=t;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll a;
	string s;
	cin >> a >> s;
	s.erase(s.end() - 3);
	ll b = stoll(s);
	cout << a * b / 100 << endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=2e5+10;
int n;
ll a[MAXN],tot[MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		{
			scanf("%lld",&a[i]);
			tot[i]=tot[i-1]+a[i];
		}
	int L=0,R=2;
	ll ans=1000000000000000000;
	for(int i=2;i<=n-2;++i)
		{
			while(tot[L]<tot[i]-tot[L])
				++L;
			if(tot[i]-2*tot[L-1]<tot[L]*2-tot[i])
				--L;
			while(tot[R]-tot[i]<tot[n]-tot[R])
				++R;
			if(tot[n]+tot[i]-2*tot[R-1]<2*tot[R]-tot[n]-tot[i])
				--R;
			ll max1=max(tot[L],tot[i]-tot[L]);
			ll max2=max(tot[R]-tot[i],tot[n]-tot[R]);
			ll min1=min(tot[L],tot[i]-tot[L]);
			ll min2=min(tot[R]-tot[i],tot[n]-tot[R]);
			ll max3=max(max1,max2);
			ll min3=min(min1,min2);
			ans=min(ans,max3-min3);
		}	
	printf("%lld",ans);
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    long long cnt = 0;
    long long sum = 0;
    int right = 0;
    for (int left = 0; left < n; left++) {
        while (right < n && (sum ^ a[right]) == (sum + a[right])) {
            sum += a[right];
            right++;
        }

        cnt += right - left;
        if (left == right) right++;
        else sum -= a[left];
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

S = input()
if S[2] == S[3] and S[4] == S[5]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 7876
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
    }
    println!("{}", (n as i32).pow(3));
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)

int main() {
	int A, B; cin >> A >> B;
	int cnt = 0;
	rep(i, A, B + 1) {
		if (i / 10000 == i % 10 && i / 1000 % 10 == i / 10 % 10)cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
S_dash = input()
T = input()

DEBUG = False

reversed_S_dash = S_dash[::-1]
reversed_T = T[::-1]

for i in range(len(S_dash)-len(T)+1):
    flag = True
    for j in range(len(T)):
        if DEBUG:
            print("i: {}, j: {}".format(i, j))
            print("S_dash[i+j]: {}, T[j]: {}".format(reversed_S_dash[i+j], reversed_T[j]))
        if reversed_S_dash[i+j] != reversed_T[j] and reversed_S_dash[i+j] != '?':
            if DEBUG:
                print("miss match")
            flag = False
            break
    if flag:
        if DEBUG:
            print("find")
            print("from {} to {}".format(i, i+len(T)-1))
        ans = reversed_S_dash[:i]+reversed_T+reversed_S_dash[i+len(T):]
        ans = ans.replace('?', 'a')
        print(ans[::-1])
        exit(0)

print("UNRESTORABLE")


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e5+23;
int inv[N], cnt[N];

void solve() {
  int n; scanf("%d", &n);
  for (int p, i = 0; i < n; ++i) {
    scanf("%d", &p);
    inv[--p] = i;
    cnt[i] = 1;
  }
  int ans = n-1;
  for (int i = n-2; i >= 0; --i) {
    if (inv[i] < inv[i+1]) {
      cnt[i] = 1+cnt[i+1];
      ans = min(n-cnt[i], ans);
    }
  }
  printf("%d", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 5424
from collections import defaultdict

INF = 10 ** 9 + 7
N = int(input())
S = input()

d = defaultdict(int)
for key in S:
    d[key] += 1

ans = 1
for i in d.items():
    ans *= (i[1] + 1)

print((ans - 1) % INF)

Measured memory_bytes: 3444
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
long long a,b;
int main(){
    scanf("%lld%lld",&a,&b);
    if(b<2*a)printf("%lld\n",b/2);
    else printf("%lld\n",a+(b-a*2)/4);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<boost\lexical_cast.hpp> 

#define ll long long
#define ld long double
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int> 
#define vvi vector< vi >
#define vl vector<ll>
#define vpi vector<pi> 
#define vpl vector<pl>

#define PB emplace_back
#define MP make_pair
#define SZ(x) (ll)x.size()
#define SS second
#define FF first


#define DEB(x) cout << #x << "=" << x << endl
#define DEB2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define DEB3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define DEB4(x, y, z, k) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," <<#k << "=" << k<< endl
#define DEBC(a) for(auto x:a) cout<<x<<" ";
#define DEBP(name,a) cout<<name<<endl;for(auto x:a){ cout<<x.first<<"\t"<<x.second<<endl;}

#define INF 0x7fffffff
#define LINF 2000000000000000007
#define endl "\n"
#define MOD 1000000007
#define MAX 100010

#define FILL(a,x) memset(x,a,sizeof x)
#define ALL(x) x.begin(),x.end()
#define REP(i,a,n) for(ll i=a;i<n;++i)
#define REPR(i,n,b) for(ll i=n;i>=b;i--)
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

using namespace std;
//using boost::lexical_cast;
//using boost::bad_lexical_cast;
int main(){
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    int test=1;
    //cin>>test;
    while(test--){
       ll n, m;
       cin>>n>>m;
       if(n%m==0){
            cout<<n/m<<endl;
       } 
       else{
            cout<<n/m+1<<endl;
       }
    }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
const int N=200000;
int main(){
	long long i,j,n,a[N],b[N],c[N];
	cin>>n;
	cin>>a[0]>>b[0]>>c[0];
	for(i=1;i<n;++i){
		cin>>a[i]>>b[i]>>c[i];
		a[i]+=max(b[i-1],c[i-1]);
		b[i]+=max(a[i-1],c[i-1]);
		c[i]+=max(a[i-1],b[i-1]);
	}
	cout<<max(a[n-1],max(b[n-1],c[n-1]));
}

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

int main() {
  int N,X;
  scanf("%d %d", &N,&X);
 
  int l[N];
  for (int i = 0; i < N; ++i) {
    scanf("%d", &l[i]);
  }

  int count = 0;
  int ans = 1;

  for (int i = 0; i < N; ++i){
    count += l[i];
    if(count <= X) ++ans;
  }

  cout << ans << endl;
}



Measured memory_bytes: 256
N = int(input())
S = input()
R = 0
G = 0
B = 0
notToAllow = 0


for i in range(0,N):
    if S[i] == "R":
        R = R + 1
    elif S[i] == "G":
        G = G + 1
    else:
        B = B + 1

total = R*G*B

for i in range(0,N):
    for j in range(0,(N//2)+1):
        if(j+j+i < N):
            if ((S[i] != S[i+j])):
                if(S[i] != S[i+j+j]):
                    if(S[i+j] != S[i+j+j]):
                        notToAllow = notToAllow + 1

print(R*G*B - notToAllow)


Measured memory_bytes: 73704
#include <iostream>

using namespace std;
int main() {

	int a, b, c, r = 0;
	cin >> a >> b >> c;

	for (int i = a; i <= b; ++i) {
		if (c % i == 0)
			++r;
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 3100
from math import gcd
n = int(input())
a = list(map(int, input().split()))
g = a[0]
for i in range(1, n):
    g = gcd(g, a[i])
if g == 1:
    p = [1] * (10 ** 6 + 1)
    r = [0] * (10 ** 6 + 1)
    p[0], p[1] = 0, 0
    r[0] = 0
    r[1] = 1
    for i in range(2, 10 ** 6 + 1):
        if p[i]:
            r[i] = i
            for j in range(i * 2, 10 ** 6 + 1, i):
                p[j] = 0
                if r[j] == 0:
                    r[j] = i
    t = [0] * (10 ** 6 + 1)
    for x in a:
        ps = []
        while x > 1:
            if t[r[x]]:
                print('setwise coprime')
                exit(0)
            ps.append(r[x])
            x //= r[x]
        for p in ps:
            t[p] = 1
    print('pairwise coprime')
else:
    print('not coprime')


Measured memory_bytes: 197200
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int A[100011];

bool wins() {
    int even = 0;
    REP (i, N) if (A[i] % 2 == 0) even++;
    if (even % 2) return true;
    if (even + 1 != N) return false;

    REP (i, N) {
	if (A[i] == 1) return false;
	if (A[i] % 2) A[i]--;
    }
    int g = 0;
    REP (i, N) g = __gcd(g, A[i]);
    REP (i, N) A[i] /= g;
    return !wins();
}

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);

    bool fst = wins();
    puts(fst? "First": "Second");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 640