akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 1000000
int W,H,G[32][32][4],r,t,i,j,Q[MAX][3],f,e,mc[32][32];
int mh[4]={0,1,0,-1},mw[4]={1,0,-1,0};
int main()
{
	for(;scanf("%d%d",&W,&H),W;)
	{
		memset(G,0,sizeof(G));
		memset(mc,-1,sizeof(mc));
		for(i=0;i<2*H-1;i++)
			for(j=0;j<W-1+(i%2);j++)
			{
				scanf("%d",&t);
				if(!t)G[i/2][j][i%2]=G[i/2+i%2][j+(!(i%2))][i%2+2]=1;
			}
		for(f=r=Q[0][0]=Q[0][1]=0,Q[0][2]=e=1;f<e;f++)
		{
			int nh=Q[f][0],nw=Q[f][1],nc=Q[f][2];
			if(f==MAX-1)
				break;
			if(nc>H*W)
				continue;
			if(nh==H-1&&nw==W-1)
			{
				r=nc;break;
			}
			
			for(i=0;i<4;i++)
				if(G[nh][nw][i]&&mc[nh+mh[i]][nw+mw[i]]==-1)
				{
					Q[e][0]=nh+mh[i];
					Q[e][1]=nw+mw[i];
					Q[e][2]=mc[nh+mh[i]][nw+mw[i]]=nc+1;
					e++;
				}
		}
		printf("%d\n",r);
	}
	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  int d[n];
  for(int i = 0; i < n; i++)
    cin >> d[i];
  
  sort(d, d + n);
  
  int count = 1;
  int max = d[0];
  for(int i = 0; i < n; i++)
  {
     if(max < d[i])
     {
       max = d[i];
       count++;
     }
  }
  
  cout << count << endl;
  return (0);
}

Measured memory_bytes: 256
L1 = list(map(int,input().split()))
L2 = list(map(int,input().split()))
L3 = list(map(int,input().split()))

a1 = 0
b1 = L1[0]
b2 = L1[1]
b3 = L1[2]
a2 = L2[1]-b2
a3 = L3[2]-b3

if a1+b1==L1[0] and a1+b2==L1[1] and a1+b3==L1[2] and a2+b1==L2[0] and a2+b2==L2[1] and a2+b3==L2[2] and a3+b1==L3[0] and a3+b2==L3[1] and a3+b3==L3[2]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key){
  int left = 0;
  int right = n;
  int mid;
  while(left < right){
    mid = (left + right)/2;
    if(key == A[mid]) return 1;
    if(key > A[mid]) left = mid +1;
    else if(key < A[mid]) right = mid;
  }
  return 0;
}

int main(){
  int i,q,k,sum = 0;

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

  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d", &k);
    if(binarySearch( k )) sum++;
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 2108
#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.at(i);
  sort(a.begin(),a.end());
  
  int p=0;
  int q=0;
  for (int i=0;i<(N+1)/2;i++)
    p+=a.at(2*i);
  for (int i=0;i<N/2;i++)
    q+=a.at(2*i+1);
  cout<<max(p,q)-min(p,q)<<endl;
}

Measured memory_bytes: 3644
#!/usr/bin/env python3
import sys


def solve(K: int):
    hai = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    print(hai[K-1])


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
# coding: utf-8
# Your code here!
def wa(n):
    cnt=0
    for i in range(n):
        cnt+=1+i
    return cnt

def wa_arr(a):
    cnt=0
    for i in range(0,len(a),2):
        cnt+=wa(a[i])+wa(a[i+1])-min(a[i],a[i+1])
    return cnt

a=input()
cnt=0
res=[]
for i in range(len(a)):
    if i==0:
        now=a[i]
        cnt+=1
    else:
        if a[i]==now:
            cnt+=1
        else:
            res.append(cnt)
            now=a[i]
            cnt=1
res.append(cnt)
#print(res)

if a[0]=="<":
    if len(res)%2==0:
        c=wa_arr(res)
    else:
        c=wa_arr(res[:-1])+wa(res[-1])
        #print(res[:-1],wa_arr(res[:-1]),wa(res[-1]))
else:
    if len(res)%2==1:
        c=wa_arr(res[1:])+wa(res[0])
    else:
        c=wa_arr(res[1:-1])+wa(res[0])+wa(res[-1])

print(c)

Measured memory_bytes: 52552
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (998244353ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

int main(void){
	int n;
	cin >> n;
	cout << ((n/1000)?"ABD":"ABC") << endl;
	return 0;
}


Measured memory_bytes: 256
import numpy as np

n, d = map(int, input().split())
x = np.array([list(map(int, input().split())) for _ in range(n)])
square_numbers = [i * i for i in range(1, 127)]
count = 0
for i in range(n-1):
  cur_x = x[i]
  for j in range(i+1, n):
    if np.sum((x[j] - cur_x) ** 2) in square_numbers:
      count += 1
print(count)

Measured memory_bytes: 12968
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int result = 0;
        for(int i = 0;i<n;i++){
            int a = sc.nextInt();
            while(a%2==0){
                result++;
                a = a / 2;
            }
        }
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 32200
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int main() {
	double a,b;
	char c;
	double S=0.0,A=0.0;
	int sum,avg;
	double n=0.0;
	while(true){
		cin>>a>>c>>b;
		if (cin.eof())break;
		S+=a*b;
		A+=b;
		n++;
	}
	A=A/n;
	sum=S;
	avg=A+0.5;
	cout<<sum<<endl;
	cout<<avg<<endl;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

// http://arc079.contest.atcoder.jp/tasks/arc079_c

int64_t run()
{
  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  cin >> a;

  // const int64_t acc = accumulate(begin(a), end(a), (int64_t)0);
  bool loop = true;
  int64_t k = 0;
  while(loop)
  {
    loop = false;
    vector<int64_t> cnt(n, 0);

    for(int64_t i = 0; i < n; ++i)
      if(n < a[i] + 1)
      {
        cnt[i] = a[i] / n;
        k += cnt[i];
        a[i] %= n;
        loop = true;
      }

    const int64_t acc = accumulate(begin(cnt), end(cnt), (int64_t) 0);
    for(int64_t i = 0; i < n; ++i) a[i] += acc - cnt[i];
  }

  return k;
}

int main(const int argc, char * argv [])
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << run();

  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <cmath>
#include <list>
#include <iomanip>
#include <set>
#include <map>
#include <sstream>
#include <string.h>
#include <fstream>
#include <stdio.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;

#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define RFOR(i,a,b) for(int (i)=(a)-1;(i)>=(b);--(i))
#define MP make_pair
#define MOD 1000000007
#define INF 1000000001
#define PB push_back
#define eps 1e-5
#define X first
#define Y second

int a, b;
int X[200000+47];

LL C(int num, int t)
{
    if (t > num) return 0;
    LL res = 1;
    FOR (i,1,num-t+1) res = res*(num-i+1)/i;
    return res;
}

void backtr(int num, int a, int b) {
    if (!b) return;

    //cout << num<<" "<<a<<" "<<b<<endl;
    if (!a) {
        X[num] += 2;
        backtr(num+1,a,b-1);
        backtr(num+1,a,b-1);
        return;
    }
    
    X[num] += 1;
    backtr(num+1,a-1,b);
    backtr(num+1,a,b-1);
}

LL mpower(LL a, LL step)
{
    if (!step) return 1;
    if (step % 2 == 1) return (a*mpower(a,step-1))%MOD;
    LL g = mpower(a,step/2);
    return (g*g)%MOD;
}

int main()
{
    /*cin >> b >> a;
    backtr(0,a,b);
    FOR (i,0,a+b) cout << X[i]<<" "; cout << endl;
    X[0] = 1;
    LL s1 = 0, s2 = 0;
    FOR (i,1,a+b) {
        X[i] = X[i-1]*2;
    }
    FOR (i,1,a+b) {
        s2 = s2*2+C(i-1,b-1);
        s1 = s1*2+C(i-1,a-1);
        X[i] += s1-s2;
    }
    cout << C(5,3) << " "<<C(6,3)<<endl;
    FOR (i,0,a+b) cout << X[i]<<" ";*/
    
    cin >> b >> a;
    if (a == 0) {
        FOR (i,0,b) cout << "1 ";
        return 0;
    }
    
    if (b == 0) {
        FOR (i,0,a) cout << "0 ";
        return 0;
    }
    
    X[0] = 1;
    FOR (i,1,a+b) {
        X[i] = X[i-1]*2%MOD;
    }
    
    LL s1 = 0, s2 = 0;
    LL q1 = 1, q2 = 1;
    FOR (i,1,a+b) {
        if (i == b) s2 = 1;
        if (i == a) s1 = 1;
        if (i > b) {
            s2 = (2*s2)%MOD;
            q2 *= (i-1);
            q2 %= MOD;
            q2 *= mpower(i-b,MOD-2);
            q2 %= MOD;
            s2 = (s2+q2)%MOD;
        }
        if (i > a) {
            s1 = (2*s1)%MOD;
            q1 *= (i-1);
            q1 %= MOD;
            q1 *= mpower(i-a,MOD-2);
            q1 %= MOD;
            s1 = (s1+q1)%MOD;
        }

        X[i] = (X[i] + s1 + MOD - s2)%MOD;
    }
    
    LL d = 1;
    //FOR (i,0,a+b) cout << X[i]<<endl;
    FOR (i,0,a+b)
    {
        d = (d*500000004)%MOD;
        cout << (X[i]*d)%MOD<<"\n";
    }
}


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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class T> map<T, int> factorize(T n) {
  map<T, int> res;
  for (T i = 2; i * i <= n; ++i)
    while (n % i == 0) ++res[i], n /= i;
  if (n != 1) ++res[n];
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  int res = 0;
  for (auto [p, e] : factorize(n)) {
    int cur = -1;
    for (int m = 0; ; ++m) {
      if (m * (m + 1) / 2 <= e) {
        cur = m;
      } else {
        break;
      }
    }
    res += cur;
  }
  cout << res << '\n';
}


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

vector<int> node, sz, rk;
int root(int x){
	if(node[x] == x) return x;
	else return node[x] = root(node[x]);
}

int main(){
	long long N, M; cin >> N >> M;

	for(int i=0; i<N+1; ++i) node.push_back(i);
	sz.resize(N+1, 1);
	rk.resize(N+1, 1);

	vector<int> A(M), B(M);
	for(int i=M-1; i>=0; --i) cin >> A[i] >> B[i];

	vector<long long> ans(M);
	long long sum = N*(N-1)/2;
	for(int i=0; i<M; ++i){
		ans[i] = sum;
		int L = root(B[i]), R = root(A[i]);
		if(L != R){
			if(rk[L] <= rk[R]) swap(L, R);
			sum -= (long long)sz[L] * sz[R];
			sz[L] += sz[R];
			node[R] = node[L];
			rk[L] = max(rk[L], 1+rk[R]);
		}
	}

	for(int i=M-1; i>=0; --i) cout << ans[i] << endl;
}


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

int main(void)
{
	int a, b, c, z;

	cin >> a >> b >> c;
	if (a > b)
	{
		z = a;
		a = b;
		b = z;
	}
	if (b > c)
	{
		z = b;
		b = c;
		c = z;
	}
	if (a > b)
	{
		z = a;
		a = b;
		b = z;
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}

Measured memory_bytes: 3092
N, M = map(int, input().split())
ab=[]
for _ in range(M):
    ab.append(tuple(map(int, input().split())))


def func(n):
    seen[n]=True
    for val in lst[n]:
        if seen[val] == False:
            todo.append(val)
    if todo:
        func(todo.pop(-1))
    else:
        return None

count=0
for edge_to_check in ab:
    lst = [[] for _ in range(N+1)]
    seen = [False] * (N + 1)
    todo = []
    for el in ab:
        if el != edge_to_check:
            lst[el[0]].append(el[1])
            lst[el[1]].append(el[0])
    #print(lst)
    # DFS
    func(1)
    #print(edge_to_check, seen)
    if seen.count(False) > 1:
        count+=1
print(count)





Measured memory_bytes: 43612
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int r = cin.nextInt();
			int p = cin.nextInt();
			if(r+p==0){
				break;
			}
			Rule[] rule=new Rule[r];
			Pack[] pack=new Pack[p];
			for(int i = 0;i<r;i++){
				String s1 = cin.next();
				String s2 = cin.next();
				String s3 = cin.next();
				rule[i]=new Rule(s1,s2,s3);
			}
			for(int i = 0;i<p;i++){
				String s1 = cin.next();
				String s2 = cin.next();
				String s3 = cin.next();
				pack[i]=new Pack(s1,s2,s3);
			}
			for(int i = 0;i<p;i++){
				for(int j = r-1;j>=0;j--){
					if(rule[j].type==2){
						if(rule[j].deny(pack[i])){
							pack[i].isPermitted=false;;
							pack[i].isRuled=true;
						}
					}
					else if(rule[j].type==1){
						if(rule[j].permit(pack[i])){
							pack[i].isPermitted=true;;
							pack[i].isRuled=true;
						}

					}
					if(pack[i].isRuled){
						break;
					}
				}
			}
			int cnt=0;
			for(int i = 0;i<p;i++){
				if(pack[i].isPermitted){
					cnt++;
					
				}
			}
			System.out.println(cnt);
			for(int i = 0;i<p;i++){
				if(pack[i].isPermitted){
					System.out.println(pack[i]);
				}
			}
		}
	}
}
class Rule{
	int type;//1==permit 2==deny
	String source;
	String dest;
	boolean permit(Pack p){
		boolean res = true;
		for(int i = 0;i<8;i++){
			if(source.charAt(i)=='?'){
				continue;
			}
			if(source.charAt(i)!=p.source.charAt(i)){
				res = false;
			}
		}
		for(int i = 0;i<8;i++){
			if(dest.charAt(i)=='?'){
				continue;
			}
			if(dest.charAt(i)!=p.dest.charAt(i)){
				res = false;
			}
		}
		return res;
	}
	boolean deny(Pack p){
		boolean res=true;
		for(int i = 0;i<8;i++){
			if(source.charAt(i)=='?'){
				continue;
			}
			if(source.charAt(i)!=p.source.charAt(i)){
				res = false;
			}
		}
		for(int i = 0;i<8;i++){
			if(dest.charAt(i)=='?'){
				continue;
			}
			if(dest.charAt(i)!=p.dest.charAt(i)){
				res = false;
			}
		}
		return res;
	}
	Rule(String s1,String s2,String s3){
		if(s1.equals("permit")){
			type=1;
		}
		else{
			type=2;
		}
		source=s2;
		dest=s3;
	}
}
class Pack{
	String source;
	String dest;
	String body;
	boolean isPermitted=false;
	boolean isRuled=false;
	Pack(String s1,String s2,String s3){
		source=s1;
		dest=s2;
		body=s3;
		isPermitted=false;
		isRuled=false;
	}
	public String toString(){
		return source+" " +dest+" " +body;
	}
}

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

int main() {
 int n,k;
 cin >> n >> k;
  int x=1;
  for(int i=0;i<n;i++){
    if(x<k){
      x *= 2;
    }
    else{
      x += k;
    }
  }
  cout << x << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
#include <numeric>
#include <map>
#include <iomanip>
using namespace std;

int mypow(int a, int b){
	if(b == 0) return 1;
	if(b == 1) return a;
	if(b == 2) return a * a;
	if(b % 2 == 0) return mypow(mypow(a, b / 2), 2);
	return a * mypow(a, b - 1);
}

char solve(long long uf, long long vf, long long &u, long long &v, int d){
	if(uf - u >= 0 && vf - v >= 0){
		u += d; v += d;
		return 'R';
	}
	if(uf - u >= 0 && vf - v <= 0){
		u += d; v -= d;
		return 'U';
	}
	if(uf - u <= 0 && vf - v >= 0){
		u -= d; v += d;
		return 'D';
	}
	if(uf - u <= 0 && vf - v <= 0){
		u -= d; v -= d;
		return 'L';
	}
}

int main() {

	int N; cin >> N;
	vector<pair<int, int>> xy(N);
	for(int i = 0; i < N; i++) cin >> xy[i].first >> xy[i].second;

	int flag = -1;
	bool possible = true;
	for(int i = 0; i < N; i++){
		if(flag == -1){
			flag = abs(xy[i].first + xy[i].second) % 2;
		}else if(flag != abs(xy[i].first + xy[i].second) % 2){
			possible = false;
			break;
		}
	}

	if(!possible){
		cout << -1 << endl;
		return 0;
	}

	vector<pair<long long, long long>> uv(N);
	for(int i = 0; i < N; i++){
		uv[i].first = xy[i].first + xy[i].second;
		uv[i].second = xy[i].first - xy[i].second;		
	}

	

	int arms = 31;

	if(flag == 1){
		cout << arms << endl;
	}else{
		cout << arms + 1 << endl;
	}

	for(int i = arms - 1; i >= 0; i--){
		cout << mypow(2, i) << " ";
	}
	if(flag == 0) cout << 1;
	cout << endl;

	for(int i = 0; i < N; i++){
		long long u = 0, v = 0, uf = uv[i].first, vf = uv[i].second;
		for(int i = arms - 1; i >= 0; i--){
			cout << solve(uf, vf, u, v, mypow(2, i));
		}
		if(flag == 0){
			cout << solve(uf, vf, u, v, 1);
		}
		cout << endl;
	}

}

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

int main(){
    int a,b,c,d=0;
    cin>>a>>b>>c;
    for(int x=a;x<=b;++x){
        if(c%x==0){
            d++ ;
        }
    }
    cout<<d<<endl;
    return 0;
}


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

typedef long long ll;

ll N;
string R;

int main() {
  cin >> N;
  --N;
  ll pow = 1;
  for (ll i = 1;; ++i) {
    pow *= 26;
    if (N < pow) {
      for (ll k = 0; k < i; ++k) {
        R.push_back('a' + N % 26);
        N /= 26;
      }
      reverse(R.begin(), R.end());
      cout << R << endl;
      return 0;
    } else {
      N -= pow;
    }
  }
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, N) for (int i=0; i<(int)N; i++)
#define rep1(i, N) for (int i=1; i<(int)N; i++)

using namespace std;

int N, R;

int main() {
  cin >> N >> R;
  int ans;
  if (N >= 10) ans = R;
  else ans = R + 100 * (10 - N);
  cout << ans;
}


Measured memory_bytes: 256
N, K = map(int, input().split())

ans = 0
for b in range(K+1,N+1):
  if N%b==0:
    ans += (N//b)*(b-K)
  else:
    ans += (N//b)*(b-K)+max(N%b-K+1,0) if K!=0 else (N//b)*(b-K)+(N%b)
#  print(ans)
print(ans)

Measured memory_bytes: 3060
// Problem : Rabbo Loves Jumping
// Contest : CodeChef - ketek[i] QuickMatch 25
// URL : https://www.codechef.com/KQKM2020/problems/HRJMP
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

/*/ Author:Amar1503/*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ull unsigned long long
#define ll long long
#define inf 1e9
#define mninf INT_MIN
#define Mod 1000000007
#define endl "\n"
#define cp(x) cout<<(x)<<" "
#define cl(x) cout<<(x)<<endl
#define ct(x,y) cout<<(x)<<" "<<(y)<<endl;
#define nl   cout<<endl
//const double PI=3.1415926535897932384626433832;
//looping
#define For(i,a,b) for(int i=a;i<b;i++)
#define test(t)  int (t); cin>>(t); while((t)--)
#define array(a,n) int (n); cin>>(n); int a[n]; for(int i=0;i<(n);i++) cin>>a[i];
#define trace(x) clog<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) clog<<#x<<": "<<x<<"     "<<#y<<" "<<y<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define printv(v)  for(int i=0;i<(v).size();i++) cout<<v[i]<<" "
//containers
#define F first
#define S second
#define pb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define itr(it, a) for(auto it = (a).begin(); it != (a).end(); it++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ers(v)   sort(all(v)); (v).erase(unique(all(v)),(v).end())
#define printmatrix(a,n,m) for(int i=0;i<n;i++){ for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
typedef pair <int, int> pii;
typedef vector < pair <int, int> > vpii;
// cout<<"\nTime Elapsed : " << 1.0*clock() /CLOCKS_PER_SEC << " s\n";
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,1,-1,1,-1};
//#define int long long
/*/----------------------------Code begins----------------------------------/*/
int32_t main(){
fio;
array(h,n);
vector<int> dp(n,inf);
//dp[i] is the minimum cost to reach ith stone
dp[0]=0;
for(int i=0;i<n;i++){
	for(int j:{i+1,i+2}){
		if(j<n){
			dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
		}
	}
}
cout<<dp[n-1];
}










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

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

  map<string, int> mp;
  for (int i=0; i<n; i++) {
    string t;
    cin >> t;
    mp[t]++;
  }

  int m;
  cin >> m;
  for (int i=0; i<m; i++) {
    string t;
    cin >> t;
    mp[t]--;
  }

  int max=0;
  for (auto itr=mp.begin(); itr!=mp.end(); itr++) {
    if (itr->second>max) max=itr->second;
  }

  if (max<=0) {
    cout << 0;
  } else {
    cout << max;
  }
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int d;
  cin >> d;
  if (d == 22) {
    cout << "Christmas Eve Eve Eve" << endl;
  }

  else if (d == 23) {
    cout << "Christmas Eve Eve" << endl;
    /* code */
  }

  else if (d == 24) {
    cout << "Christmas Eve" << endl;
  /* code */}

  else{
    cout << "Christmas" << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

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

  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  n = a.size();

  if (k > a[n - 1]) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  vector<int> d;
  for (int i = 0; i < n - 1; i++) {
    d.push_back(a[i + 1] - a[i]);
  }
  sort(d.begin(), d.end());
  d.erase(unique(d.begin(), d.end()), d.end());

  copy(d.begin(), d.end(), back_inserter(a));
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  n = a.size();
  bool psbl = false;

  if (n == 1) {
    if (a[0] == k) {
      psbl = true;
    }
    if (psbl) {
      cout << "POSSIBLE" << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
    return 0;
  }

  if (d[0] == 1) {
    psbl = true;
  }

  if(k % a[0] == 0){
    psbl = true;
  }

  for (int i = 0; i < n; i++) {
    if (a[i] % a[0] != 0) {
      psbl = true;
      break;
    }
    if (a[i] == k) {
      psbl = true;
      break;
    }
  }

  if (psbl) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}


Measured memory_bytes: 1528
MOD = 998244353


def main():
    N, S = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    dp = [[0]*(S+1) for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        dp[i+1][0] += 1
        for j in range(S+1):
            dp[i+1][j] += dp[i][j]
            dp[i+1][j] %= MOD
            if j + A[i] <= S:
                dp[i+1][j+A[i]] += dp[i][j]
                dp[i+1][j+A[i]] %= MOD
    ans = 0
    for i in range(N+1):
        ans += dp[i][S]
    print(ans % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 111708
#include <bits/stdc++.h>
using namespace std;
int maxHappiness(const vector<int> &A, const vector<int> &B, const vector<int> &C){
    const int n = A.size();
    int prevA = 0, prevB = 0, prevC = 0;
    for(int i = 0; i<n; i++){
        int currA = A[i] + max(prevB, prevC);
        int currB = B[i] + max(prevA, prevC);
        int currC = C[i] + max(prevA, prevB);
        prevA = currA; prevB = currB, prevC = currC;
    }
    return max({prevA, prevB, prevC});
}
int main(){
    int n;
    cin>>n;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i<n ;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    cout<<maxHappiness(a,b,c)<<endl;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

int main() {
	int N; cin >> N;
	vvint A(N, vint(N-1)); cin >> A;
	for (auto &v : A) for (auto &u : v) u--;	

	int finish = 0;
	vint now(N, 0);
	vint cand(N);

	iota(begin(cand), end(cand), 0);
	int cnt;
	vint used(N, -1);
	for (cnt = 0; finish < N; cnt++) {
		vint ncand;
		queue<int> increase;
		for (auto &v : cand) {
			int u = A[v][now[v]];
			if (A[u][now[u]] == v && used[v] != cnt && used[u] != cnt) {
				increase.push(v);
				increase.push(u);
				used[v] = cnt, used[u] = cnt;
			}
		}
		if (increase.empty()) break;
		while (!increase.empty()) {
			int v = increase.front(); increase.pop();
			now[v]++;
			if (now[v] == N-1) finish++;
			else ncand.push_back(v);
		}
		cand = ncand;
	}
	cout << (finish == N ? cnt : -1) << endl;
	return (0);
}

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

int main()
{
    int N,ans=0;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N;i++)
    {
        cin >> a.at(i);
        if((i+1)%2==1&&a.at(i)%2==1)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
using System;
using System.Collections.Generic;

namespace dot
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            int n = int.Parse(input);
            var hash = new Dictionary<string, int>();
            long ans = 0;

            for (int i=0; i<n; i++) {
                var input2 = Console.ReadLine();
                char[] chars = input2.ToCharArray();
                Array.Sort(chars);
                string sorted = new string(chars);
                if (hash.ContainsKey(sorted)) {
                    ans += hash[sorted];
                    hash[sorted]++;
                } else {
                    hash.Add(sorted, 1);
                }
            }

            Console.WriteLine(ans);
        }
    }
}


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

int main() {
    int N; cin >> N;
    int ans = 0;
    bool exist = false;
    for (int i = 0; i < N; i++) {
        int D1, D2; cin >> D1 >> D2;
        if (D1 == D2) {
            ans++;
        } else {
            ans = 0;
        }
        if (ans == 3) {
            exist = true;
        }
    }
    if (exist) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int max(int a, int b)
{
    return a > b ? a : b;
}

int main()
{
    int n;
    scanf("%d", &n);
    int a[n][3];
    int dp[n][3];
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
    }
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for (int i = 1; i < n; i++)
    {
        dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = a[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = a[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
    }
    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
    printf("%d\n",ans);
}

Measured memory_bytes: 2560
# 解説放送
# 写経

def main():
    inf = 18 * (10 ** 6 + 1)

    s = input()
    s = '0' + s

    n = len(s)

    dp = [[inf] * 2 for _ in range(n + 1)]
    dp[0][0] = 0

    for i, c in enumerate(s[::-1]):
        for j in range(2):
            x = int(c) + j
            if x < 10:
                dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + x)  # a=x,b=0
            if x > 0:
                dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + (10 - x))  # a=0,bに繰り下がり

    print(dp[n][0])


if __name__ == '__main__':
    main()


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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>

using namespace std;

const int MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep2(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

vector<int> ans;
vector<vector<pair<ll, ll>>> graph(100000);

void dfs(int start, int color) {
    ans[start] = color;
    for (auto e : graph[start]) {
        if (ans[e.first] == -1) {
            if (e.second % 2 == 0) {
                dfs(e.first, color);
            } else {
                dfs(e.first, 1 - color);
            }
        }
    }
}


int main() {
    int N;
    cin >> N;
    rep(i, N - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        graph[u - 1].push_back({v - 1, w});
        graph[v - 1].push_back({u - 1, w});
    }

    ans.assign(N, -1);
    dfs(0, 1);

    rep(i, N){
        cout << ans[i] << endl;
    }

}


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

long long ans = 0;
long long n; 

void dfs(long long x, bool three, bool five, bool seven) {
    if(x>n) return;
    if(seven&&five&&three) ans ++;
    dfs(x*10+3, 1, five, seven);
    dfs(x*10+5, three, 1, seven);
    dfs(x*10+7, three, five, 1);
}

int main() {
    cin >> n;
    dfs(0, 0, 0, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#include<vector>
using namespace std;
int a[100100],b[100100],n,ans;
map<int,int> m;
bool no=false;
string s;
vector<char> v;
void out()
{
	for(int i=0;i<v.size();i++)
	{
		if(v[i]=='L')
		{
			int t=0,k=i,o=0;
			while(v[k]!='R')
			{
				t++;
				k--;
			}
			while(i!=v.size())
			{
				if((t+o)%2==1)
					a[k+1]++;
				else
					a[k]++;
				o++;
				i++;
			}
		}
		else
		{
			int t=0,k=i,o=0;
			while(v[k]!='L')
			{
				t++;
				k++;
			}
			while(v[i]!='L')
			{
				if((t+o)%2==1)
					a[k-1]++;
				else
					a[k]++;
				o++;
				i++;
			}
			i--;
		}
	}
	for(int i=0;i<v.size();i++)
	{
		cout<<a[i]<<" ";
		a[i]=0;
	}
	v.clear();
}
int main()
{
	cin>>s;
	int l=0,r=0;
	for(int i=0;i<s.size();i++)
	{
		char c=s[i];
		if(s[i]=='R' && l!=0)
		{
			l=r=0;
			out();
		}
		if(s[i]=='R')
		{
			r++;
			v.push_back(c);
		}
		if(s[i]=='L')
		{
			l++;
			v.push_back(c);
		}
		if(i==s.size()-1)
		{
			out();
			cout<<endl;
		}
	}
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,tmp;
  cin >> n;
  long long a[n],MAX=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    MAX=max(MAX,a[i]);
  }
  cout << MAX << ' ';
  for(int i=0;i<n;i++){
    if(i==0){
      tmp=abs(MAX/2-a[i]);
    }
    tmp=min(tmp,abs(MAX/2-a[i]));
  }
  for(int i=0;i<n;i++){
    if(a[i]==abs(MAX/2-tmp)&&abs(MAX/2-tmp)<MAX){
      cout << abs(MAX/2-tmp) << endl;
      return 0;
    }else if(a[i]==abs(MAX/2+tmp)&&abs(MAX/2+tmp)<MAX){
      cout << abs(MAX/2+tmp) << endl;
      return 0;
    }
  }
  return 0;  
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 28 02:20:36 2020

@author: liang
"""
S = input()
T = input()

S = S[::-1]
T = T[::-1]

res = list()

for i in range(len(S)-len(T)+1):
    flag = True
    for j in range(len(T)):
        if S[i+j] == "?" or S[i+j] == T[j]:
            continue
        else:
            flag = False
    if flag == True:
        ans = ""
        for k in range(len(S)):
            if i <= k <= i + len(T)-1:
                #print(T[k-i])
                ans += T[k-i]
            elif S[k] != "?":
                #print("B")
                ans += S[k]
            else:
                #print("C")
                ans += "a"
        ans = ans[::-1]
        print(ans)
        break
        #res.append(ans)
else:
    print("UNRESTORABLE")
"""
if res:
    res.sort()
    print(res[0])
else:
    print("UNRESTORABLE")
"""
#print(S)
#print(T)

Measured memory_bytes: 9100
MOD = 10**9+7
h, w = map(int, input().split())
S = [input() for _ in range(h)]
L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    if j > 0:
      if S[i][j-1] == ".":
        L[i][j] = L[i][j-1]+1
      if S[i][w-j] == ".":
        R[i][w-1-j] = R[i][w-j]+1
    if i > 0:
      if S[i-1][j] == ".":
        U[i][j] = U[i-1][j]+1
      if S[h-i][j] == ".":
        D[h-1-i][j] = D[h-i][j]+1
ans = 0
for i in range(h):
  for j in range(w):
    if S[i][j] == ".":
      temp = L[i][j]+R[i][j]+U[i][j]+D[i][j]+1
      ans = max(ans, temp)
print(ans)

Measured memory_bytes: 205744
X, N = map(int, input().split())
A = list(map(int, input().split()))
loki = 0
while loki >= 0:
    if A.count(X - loki) == 0:
        print(X - loki)
        loki = -1
    elif A.count(X + loki) == 0:
        print(X + loki)
        loki = -1
    else:
        loki += 1


Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,k,sum=0;
    cin>>a>>b>>c>>k;
    if(k>a){
    sum+=a*1;
    k=k-a;
    if(k>0)
    {
        if(b>k)
        {
            sum+=(b-k)*0;
        }
        else
        {
            sum+=b*0;
            k=k-b;
            if(k>0)
            {

                    sum+=(k)*(-1);


            }
        }
    }
    }
    else
    {
        sum+=k*1;
    }
    cout<<sum<<endl;

}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const int MAX_C = 100010;
bool t[MAX_C];
int t2[MAX_C];
void likeNumber() {

	fill(t, t + MAX_C, true);
	for (int i = 2; i * i <= 100000; i++)
	{
		if (!t[i]) continue;
		int j = i * 2;
		while (j <= 100000)
		{
			t[j] = false;
			j += i;
		}
	}
	t2[0] = 0;
	t2[1] = 0;
	for (size_t i = 2; i <= 50000; i++)
	{
		if (t[i]) {
			if (t[i * 2 - 1]) {
				t2[i * 2 - 1] = 1;
			}
		}
	}
	for (size_t i = 1; i <= 100000; i++)
	{
		t2[i] += t2[i - 1];
	}

	int q;
	cin >> q;
	for (size_t i = 0; i < q; i++)
	{
		int l, r;
		cin >> l >> r;
		cout << (t2[r] - t2[l - 1]) << endl;
	}
}
int main() {
	likeNumber();
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;



int main() {
  int n;
  scanf("%d",&n);
  vi a(n);
  cin>>a;
  vi b(n);
  rep(i,n) b[a[i]-1] = i;
  int ans = 0, now = 0;
  int pre = -1;
  rep(i,n) {
    if (pre > b[i]) {
      now = 0;
    }
    ++now;
    pre = b[i];
    maxs(ans,now);
  }
  ans = n-ans;
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 1920
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int a=stdIn.nextInt(),b=stdIn.nextInt(),m=-1000;
		if(a+b>m) m=a+b;
		if(a-b>m) m=a-b;
		if(a*b>m) m=a*b;
		System.out.print(m);
	}
}

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

string str, st;
int counter[MAX], pos[MAX], cs[MAX];

int main()
{
    int n, k;

    cin>>n>>k;
    cin>>str;

    char prev = str[0];
    st += str[0];
    int cnt = 1, idx = 0;
    for(int i = 1; i < n; i++){
        if(str[i] != prev){
            prev = str[i];
            counter[idx++] = cnt;
            st += str[i];
            cnt = 1;
        }
        else{
            cnt++;
        }
    }
    counter[idx++] = cnt;

    int c = 0;
    for(int i = 0; i < idx; i++){
        if(st[i] == '0'){
            pos[c++] = i;
        }
        cs[i+1] = cs[i] + counter[i];
    }

    if(k >= c){
        cout<<n<<endl;
        return 0;
    }

    int x = 0, y = k - 1, Max = 0;
    while(y < c){
        int res = cs[pos[y]+1] - cs[pos[x]];
        if(pos[x] - 1 >= 0)
            res += counter[pos[x]-1];
        if(pos[y] + 1 < idx)
            res += counter[pos[y]+1];
        if(res > Max)
            Max = res;
        x++, y++;
    }

    cout<<Max<<endl;

    return 0;
}


Measured memory_bytes: 1536
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
from bisect import *
ans = 0
for b in B:
  a = bisect_left(A,b)
  c = N-bisect_right(C,b)
  ans += a*c
print(ans)

Measured memory_bytes: 104324
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B,C;
    cin >>A>>B>>C;
    int maxa=max(max(A,B),C);
    int maxb=maxa;
    int maxc=maxa;
    maxa-=A;
    maxb-=B;
    maxc-=C;
    int count =maxa/2+maxb/2+maxc/2;
     if(maxa-maxa/2*2==0&&maxb-maxb/2*2==0&&maxc-maxc/2*2==0){
        cout<<count<<endl;
        return 0;
    }
    else if(maxa-maxa/2*2==1&&maxb-maxb/2*2==1){
        count++;
    }
    else if(maxb-maxb/2*2==1&&maxc-maxc/2*2==1){
        count++;
    }
    else if(maxa-maxa/2*2==1&&maxc-maxc/2*2==1){
        count++;
    }
    else{
        count++;
        count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3560
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair <int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const char nl = '\n';

void solve() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << s1[0] << s2[0] << s3[0];
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 256
from decimal import Decimal
def main():
    YES="Yes"
    NO="No"
    a,b,c = map(int, input().split())
    if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
        print(YES)
    else:
        print(NO)
    return

if __name__ == '__main__':
    main()

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

int main() {
 int N,M;
 cin >> N >> M;
  
 vector<int>A(N);
 
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  int sum=0;
  
  for(int i=0;i<N;i++){
    sum += A[i];
  }
  int count=0;
  
  for(int i=0;i<N;i++){
    if(A[i]*4*M >= sum){
      count++;
    }
  }
 // cout << count << endl;
  
  if(count >= M){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long

int linearSearch1(int A[], int n, int key)
{
    REP(i, n)
        if(A[i] == key)
            return 1;
    return 0;
}

int linearSearch2(int A[], int n, int key)
{
    int i = 0;
    A[n] = key;
    while(A[i++] != key);
    return i != n;
}

int main()
{
    int s[10001];
    int n, q, key;
    
    cin >> n;
    REP(i, n) cin >> s[i];
    cin >> q;

    int sum = 0;
    REP(i, q)
    {
        cin >> key;
        if(linearSearch1(s, n, key)) sum++;
    }
    cout << sum << endl;

}

Measured memory_bytes: 3056
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

int main() {
    int h, w, k;
    cin >> h >> w >> k;

    char c[h][w];
    int raw[h] = {};
    int col[w] = {};
    int all = 0;

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> c[i][j];
            if(c[i][j] == '#') {
                raw[i]++;
                col[j]++;
                all++;
            }
        }
    }

    /*
    cout << all << endl;
    for(int i = 0; i < h; i++) {
        cout << raw[i] << ' ';
    }
    cout << endl;
    for(int j = 0; j < w; j++) {
        cout << col[j] << ' ';
    }
    cout << endl;
    cout << "=====" << endl;
     */

    int ans = 0;

    for(int bitr = 0; bitr < (1<<h); bitr++) {
        for(int bitc = 0; bitc < (1<<w); bitc++) {
            int kuro = all;
            bool H[h] = {};
            bool W[w] = {};
            for(int i = 0; i < h; i++) {
                if(bitr & (1<<i)) {
                    H[i] = true;
                    kuro -= raw[i];
                    // cout << "raw: -" << raw[i] << " i = " << i << endl;
                }
            }

            for(int j = 0; j < w; j++) {
                if(bitc & (1<<j)) {
                    W[j] = true;
                    kuro -= col[j];
                    // cout << "col: -" << col[j] << " j = " << j << endl;
                }                
            }

            for(int i = 0; i < h; i++) {
                for(int j = 0; j < w; j++) {
                    if(H[i] && W[j] && c[i][j] == '#') kuro++;
                }
            }

            // cout << bitr << ' ' << bitc << ' ' << kuro << endl;
            if(kuro == k) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, M;
  cin >> N >> M;

  string S;
  cin >> S;
  bool ok = true;
  REP(i,N+M)
	if(i == N){
	  if(S[i] != '-')
		ok = false;
	}
	else if(!isdigit(S[i]))
	  ok = false;
  cout << (ok? "Yes": "No") << endl;

  return 0;
}


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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

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

  string alpha = "abcdefghijklmnopqrstuvwxyz";
  map<char,int> mp;
  for(int i = 0; i < alpha.size(); i++){
    mp[alpha[i]] = i;
  }

  vector<vector<int>> v(26);
  for(int i = 0; i < s.size(); i++){
    v[mp[s[i]]].push_back(i);
  }

  int cnt = 0,pos = 0;
  for(int i = 0; i < t.size(); i++){
    int c = mp[t[i]];
    auto p = lower_bound(v[c].begin(),v[c].end(),pos);
    if(p == v[c].end()){
      if(pos == 0){
        cout << -1 << endl;
        return 0;
      }
      cnt++;
      pos = 0;
      i--;
    }
    else {
      pos = *p + 1;
      //pos = p - v[c].begin() + 1;
    }
  }
  cout << cnt * s.size() + pos << endl;

  return 0;
}


Measured memory_bytes: 1724
#include <stdio.h>
#include <math.h>
int PNjudge(int);
#define N 10000
int main()
{
  int i,a,flag=0,count=0;
  int array[N];

  scanf("%d",&a);
  for(i=0;i<a;i++)
    {
      scanf("%d",&array[i]);
      flag=PNjudge(array[i]);
      if(flag) count++;
    }
  printf("%d\n",count);
  return 0;
}

int PNjudge(int x)
{
  int i=0;
  if(x==2) return 1;
  if(x<2||x%2==0) return 0;
  for(i=3;i<=sqrt(x);i=i+2)
    {
      if(x%i==0) return 0;
    }
  return 1;
}

Measured memory_bytes: 2668