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

const int MAX = 2e5 + 3;
const long long mod = 998244353;

struct BinomialCoefficient {
  vector<long long> fac, finv, inv;

  BinomialCoefficient(int N) : fac(N), finv(N), inv(N) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < N; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }

  long long combination(int n, int k) {
    if ( n < k ) { return 0; }
    if ( n < 0 || k < 0 ) { return 0; }
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
  }
};

long long pow_mod(long long n, long long  k) {
  if ( k == 0 ) { return 1; }
  if ( k%2 == 0 ) {
    long long t = pow_mod(n, k/2);
    return t*t % mod;
  }
  return n * pow_mod(n, k-1) % mod;
}

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  BinomialCoefficient BC(n);

  long long ans = 0;
  for ( int i = 0; i <= k; i++ ) {
    long long now = m;
    now = now * BC.combination(n-1, i) % mod;
    now = now * pow_mod(m-1, n-1-i) % mod;
    ans = (ans + now) % mod;
  }

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


Measured memory_bytes: 7912
#include<bits/stdc++.h>
using namespace std;
struct Rest
{
	string city;
	int number,rating;
	const bool operator < (const Rest &R)
	{
		if(R.city!=city)
			return city<R.city;
		return rating>R.rating;
	}
}R[110];
int main()
{
	int N;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>R[i].city>>R[i].rating;
		R[i].number=i+1;
	}
	sort(R,R+N);
	for(int i=0;i<N;i++)
		cout<<R[i].number<<endl;
	return 0;
}

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

vector< queue<int> > A(1000);
set<int> q, q2;

int main() {
  int64_t N;
  cin >> N;
  int64_t ans = 0;
  for( int i=0; i<N; ++i) {
    for( int j=0; j<N-1; ++j) {
      int ain;
      cin >> ain;
      A[i].emplace( --ain );
    }
    q.emplace(i);
  }

  int M = N * (N-1) / 2;
  int d = 0;
  while( !q.empty() ) {
//    cout << d << endl;
    int hit = 0;
//    cout << "- "; for( auto i: q ) cout << i << " "; cout << endl;

    while( !q.empty() ) {
      int i = *( q.begin() );
//      cout << i << ":";
      q.erase(i);
//      cout << "-- "; for( auto i: q ) cout << i << " "; cout << endl;
      int tgt = A[i].front();
//      cout << tgt << " " <<  A[tgt].front() <<endl;
      if( !A[tgt].empty() && A[tgt].front() == i && (q2.count(tgt)==0)) {
//        cout <<  "  Hit" << endl;
        A[i].pop();
        A[tgt].pop();
        q.erase(tgt);
//        cout << "-- "; for( auto i: q ) cout << i << " "; cout << endl;
        if ( !A[i].empty() ) q2.emplace(i);
        if ( !A[tgt].empty() ) q2.emplace(tgt);
//        for( auto aa: q2 ) cout << aa << ":" << endl;
        M--;
      }
    }
    d++;
    if ( M==0) break;
    q.clear();
    swap(q,q2);
    q2.clear();
  }
  if (M) d = -1;

  cout << d << endl;

}


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

using namespace std;

int main() {
    vector<int> v(2);
    cin >> v[0] >> v[1];

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

    if (v[0] == 2)
        cout << 1 << endl;
    else if (v[1] == 2)
        cout << 3 << endl;
    else
        cout << 2 << endl;

    return 0;
}


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll n;
    cin >> n;
    REP(a,1,3501){
        REP(b,1,3501){
            if(4*a*b-b*n-a*n !=0 && (a*b*n) % (4*a*b-b*n-a*n)==0){
                ll c = (a*b*n) / (4*a*b-b*n-a*n);
                if(c>=1){
                    cout << a << ' ' << b << ' ' << c << "\n";
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int t;
		while ((t = in.nextInt()) > 0) {
			int n = in.nextInt();
			while (n-- > 0) {
				t += in.nextInt();
				t -= in.nextInt();
			}
			System.out.println((t <= 0) ? "OK" : t);
		}
	}
}

Measured memory_bytes: 23752
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    string S;
    cin >> N >> S >> K;
    char c = S[K - 1];
    for(int i = 0;i < N;i++){
        if(S[i] != c){
            S[i] = '*';
        }
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()

m = float("Inf")
for i in range( 1,int(n**(1/2))+1 ):
	if n%i == 0:
		note = len(str(max(i,n//i)))
		if note < m:
			m = note
print(m)

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

int main(void)
{
        double x1, y1, x2, y2, distance;

        scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

        distance = pow(x2 - x1, 2) + pow(y2 - y1, 2);
        distance = sqrt(distance);

        printf("%lf\n", distance);

        return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define MAX_N 305

typedef long long ll;
const ll INF = 1e17;
// using Matrix = vector<vector<ll>>;
using Matrix = ll[MAX_N][MAX_N];

Matrix matrix;

void warshall_floyd(Matrix &matrix, int n) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                if (matrix[j][i] != INF && matrix[i][k] != INF) {
                    matrix[j][k] = min(matrix[j][k], matrix[j][i] + matrix[i][k]);
                }
            }
        }
    }
}

int main(void) {
    int n, m, l;
    cin >> n >> m >> l;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            matrix[i][j] = INF;
        }
        matrix[i][i] = 0;
    }

    for (int i = 0; i < m; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        matrix[a-1][b-1] = c;
        matrix[b-1][a-1] = c;
    }

    warshall_floyd(matrix, n);

    // for (int i = 0; i < n; i++) {
    //     for (int j = 0; j < n; j++) {
    //         cout << matrix[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i != j) {
                if (matrix[i][j] <= l) {
                    matrix[i][j] = 1LL;
                } else {
                    matrix[i][j] = INF;
                }
            }
        }
    }

    warshall_floyd(matrix, n);

    // for (int i = 0; i < n; i++) {
    //     for (int j = 0; j < n; j++) {
    //         cout << matrix[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        int s, t;
        cin >> s >> t;
        if (matrix[s-1][t-1] != INF) {
            cout << (matrix[s-1][t-1] - 1) << endl;
        } else {
            cout << -1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1280
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);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = 1;
            while (T-- > 0)
            {
                solveOne(in, out);
            }
        }

        private void solveOne(Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            int M = in.nextInt();
            UnionFind unionFind = new UnionFind(N);
            while (M-- > 0)
            {
                unionFind.union(in.nextInt() - 1, in.nextInt() - 1);
            }
            int ans = 0;
            for (int root_size : unionFind.root_size)
            {
                ans = Math.max(ans, root_size);
            }
            out.println(ans);
        }

    }

    static class UnionFind
    {
        int conf[];
        int[] root_size;
        int n_components = 0;

        UnionFind(int n)
        {
            conf = new int[n];
            root_size = new int[n];
            for (int i = 0; i < n; i++)
            {
                conf[i] = i;
                root_size[i] = 1;
                n_components++;
            }
        }

        private int root(int i)
        {
            while (i != conf[i])
            {
                i = conf[i];
            }
            return i;
        }

        public void union(int a_id, int b_id)
        {
            int root_a = root(a_id);
            int root_b = root(b_id);
            if (root_a == root_b) return;

            int size_a = root_size[root_a];
            int size_b = root_size[root_b];
            if (size_a < size_b)
            {
                conf[root_a] = root_b;
                root_size[root_a] = 0;
                root_size[root_b] += size_a;
                n_components--;
            } else
            {
                conf[root_b] = root_a;
                root_size[root_b] = 0;
                root_size[root_a] += size_b;
                n_components--;
            }
        }

    }
}



Measured memory_bytes: 51568
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;
const double PI = acos(-1.0);

using namespace std;

int main()
{
    char ans;
    cin >> ans;

    cout << (char)(ans + 1) << endl;
    return 0;
}

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

multiset<int> LS, RS;
int L[100010], R[100010];
signed main(){
	int n, fl = 0, fr = 0, ans = 0;
	scanf("%lld", &n);
	for(int i = 0;i < n;i++)scanf("%lld%lld", &L[i], &R[i]);
	
	LS.insert(-1e17);
	RS.insert(1e17);
	for(int i = 0;i < n;i++){
		fl -= R[i]-L[i];
		fr += R[i-1]-L[i-1];
		
		if(L[i] < *LS.rbegin()+fl){
			ans += *LS.rbegin()+fl-L[i];
			RS.insert(*LS.rbegin()+fl-fr);
			LS.erase(LS.find(*LS.rbegin()));
			LS.insert(L[i]-fl);
			LS.insert(L[i]-fl);
		}else if(*RS.begin()+fr < L[i]){
			ans += L[i]-(*RS.begin()+fr);
			LS.insert(*RS.begin()+fr-fl);
			RS.erase(RS.begin());
			RS.insert(L[i]-fr);
			RS.insert(L[i]-fr);
		}else{
			LS.insert(L[i]-fl);
			RS.insert(L[i]-fr);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin>>n;
    vector<vector<int>> F(n,vector<int>(10));
    REP(i,n) {
        REP(j,5) {
            REP(k,2) {
                cin>>F[i][j*2+k];
            }
        }
    }
    vector<vector<int>> P(n,vector<int>(11));
    REP(i,n) {
        REP(j,11) {
            cin>>P[i][j];
        }
    }

    int ans=-INF;
    REP(i,1<<10) {
        if(__builtin_popcount(i)==0) continue;
        int tmp=0;
        REP(j,n) {
            int cnt=0;
            REP(k,10) {
                if(F[j][k] && ((i>>k)&1)) {
                    cnt++;
                }
            }
            tmp+=P[j][cnt];
        }
        chmax(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
    
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner inti = new Scanner(System.in);
		int a = inti.nextInt();
		int b = inti.nextInt();
		int c = inti.nextInt();
		int d = inti.nextInt();
		int d1 = b-a;
		int d2 = c-b;
		int d3 = c-a;
		if(d1<0){
			d1 = d1*-1;
		}
		if(d2<0){
			d2 = d2*-1;
		}
		if(d3<0){
			d3 = d3*-1;
		}
		if(d3<=d){
			System.out.println("Yes");
		}
		else if(d2<=d && d1<=d){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 20948
N, D = map(int, input().split())
X_list = []
result = 0

for _ in range(N):
    X = list(map(int, input().split()))
    X_list.append(X)

def euclidian(l1, l2): 
    d = 0
    for i in range(D):
        d += (l1[i] - l2[i])**2
    return d**0.5

for i in range(N):
    for j in range(i+1, N):
        list_1 = X_list[i]
        list_2 = X_list[j]
        if euclidian(list_1, list_2).is_integer():
            result += 1

print(result)
         

Measured memory_bytes: 3064
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};

fn main() {
    input! {
        s: String,
        t: String,
    };

    let sc = s.chars().collect::<Vec<char>>();
    let tc = t.chars().collect::<Vec<char>>();
    let mut minv = std::i64::MAX;

    for i in 0..s.len() - t.len() + 1 {
        let mut cnt = 0;
        for j in 0..t.len() {
            if sc[i + j] != tc[j] {
                cnt += 1;
            }
        }
        minv = min(minv, cnt);
    }
    println!("{}", minv);
}


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

int main() {
  long long int N, A, B;
  cin >> N >> A >> B;

  long long int ans = 0;
  if (A > B) {
    ans = 0;
  } else if (N == 1) {
    if (A != B) ans = 0;
    else ans = 1;
  } else if (N == 2) {
    ans = 1;
  } else {
    ans = (N - 2) * (B - A) + 1;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*; 
import java.io.*;

public class Main {
    static StringTokenizer st;
    static BufferedReader br;  
    static PrintWriter out;
 
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));

        int x = nextInt();

        if( x == 0) {
            System.out.println("1");
        }
        else{
            System.out.println("0");
        };

        

    }
    
      
    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}

Measured memory_bytes: 32732
K=int(input())
num1=[[1,2,3,4,5,6,7,8,9]]
num2=[]
sm=0
for j in range(10):
    li=[]
    for k in range(len(num1[j])):
        if num1[j][k]%10!=0:
            li.append(num1[j][k]*10+num1[j][k]%10-1)
        li.append(num1[j][k]*10+num1[j][k]%10)
        if num1[j][k]%10!=9:
            li.append(num1[j][k]*10+num1[j][k]%10+1)
    li.sort()
    num1.append(li)
for j in range(len(num1)):
    sm+=len(num1[j])
    num2+=num1[j]
print(num2[K-1])


Measured memory_bytes: 33912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using vl = vector<ll>;

const vl base{1009,1021};
const ll MOD = 1000000009;
// const vl mod{1000000009,1000000007};

// 2次元ハッシュ
// sの各P*Q部分のハッシュを計算
vector<vl> calc_hash(const vector<string> &s, int P, int Q){
    int n = s.size(), m = s[0].size();

    vector<vector<ll>> tmp(n,vl(m)), hash(n,vl(m));

    ll t0 = 1;
    rep(j,Q) (t0 *= base[0]) %= MOD;

    // 行方向
    rep(i,n){
        ll e = 0;
        rep(j,Q) e = (e*base[0] + s[i][j]) % MOD;

        for(int j=0; j+Q<=m; ++j){
            tmp[i][j] = e;
            if(j+Q < m) e = (e*base[0] - (t0*s[i][j])%MOD + MOD + s[i][j+Q]) % MOD;
        }
    }

    ll t1 = 1;
    rep(i,P) (t1 *= base[1]) %= MOD;

    for(int j=0; j+Q<=m; ++j){
        ll e = 0;
        rep(i,P) e = (e*base[1] + tmp[i][j]) % MOD;

        for(int i=0; i+P<=n; ++i){
            hash[i][j] = e;
            if(i+P < n) e = (e*base[1] - (t1*tmp[i][j])%MOD + MOD + tmp[i+P][j]) % MOD;
        }
    }

    return hash;
}

string f(char c){
    int a;
    if('A'<=c && c<='Z') a = c-'A';
    else if('a'<=c && c<='z') a = c-'a'+26;
    else if('0'<=c && c<='9') a = c-'0'+52;
    else if(c=='+') a=62;
    else a=63;

    string r = "";
    rep(i,6){
        if(a%2==1) r = "1"+r;
        else r = "0"+r;
        a/=2;
    }
    return r;
}

string decode(const string &s, int L){
    string t = "";
    rep(i,s.size()) t += f(s[i]);
    t.resize(L);
    return t;
}

int main(){
    int w,h,p;
    while(cin >>w >>h >>p,w){
        vector<string> img,pat;

        rep(i,h){
            string s;
            cin >>s;
            img.pb(decode(s,w));
        }

        rep(i,p){
            string s;
            cin >>s;
            pat.pb(decode(s,p));
        }

        // rep(i,h) cout << img[i] << endl;
        // rep(i,p) cout << pat[i] << endl;

        auto rotate = [&](const vector<string> &s){
            vector<string> ret(s);
            rep(i,p)rep(j,p) ret[p-1-j][i] = s[i][j];
            return ret;
        };

        vector<vl> hs_i = calc_hash(img,p,p);
        set<ll> hs_pat;
        rep(_,2){
            vector<string> t(pat);
            rep(i,p)rep(j,p) pat[i][p-j-1] = t[i][j];

            rep(i,4){
                vector<vl> vv = calc_hash(pat,p,p);
                hs_pat.insert(vv[0][0]);
                pat = rotate(pat);
            }
        }

        int ans = 0;
        rep(i,h-p+1)rep(j,w-p+1){
            if(hs_pat.count(hs_i[i][j])) ++ans;
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 20392
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef long long ll;
typedef pair<ll,ll> pint;
int main(){
  string n;cin>>n;
  if(n[0]=='7' ||n[1]=='7'||n[2]=='7'){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3612
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2012

#include <stdio.h>

int main(void) {
	while(1) {
		
		int e;
		int mmin = 10000000;
		
		scanf("%d", &e);
		if ( e == 0 ) { break; }
		
		for(int z=0; z<=100; z++) {
			int r = e - z*z*z;
			for(int y=0; y<=1000; y++) {
				int x = r - y*y;
				if ( x<0 ) { break; }
				
				int sum = x+y+z;
				if ( mmin > sum ) { mmin = sum; }
			}
		}
		
		printf("%d\n", mmin);
	}
}

Measured memory_bytes: 1028
import itertools
 
n=int(input())
H,L=[[] for _ in range(n)],[[] for _ in range(n)]
 
for i in range(n):
  m=int(input())
  for j in range(m):
    x,y=map(int,input().split())
    if y==1:
      H[i].append(x-1)
    else:
      L[i].append(x-1)
      
N=set(range(n))
ans=0
pat=set()
for num in range(1,n+1):
  pat=pat|set(itertools.combinations(range(n),num))
for h in pat:
    h=set(h)
    num=len(h)
    nh=N-h
    t=sum([H[i] for i in h],[])
    l=sum([L[i] for i in h],[])
    if set(t)<=h and set(l)<=nh:
      ans=max(ans,num)
print(ans)

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

int main(){
  ll n,sum=0,ans=1e9,sum1=0,sum2=0;
  cin >> n;
  vector<ll> v(n);
  r(i,n){
    cin >> v[i];
    sum+=v[i];
  }
  int a=0;
  while(sum1<(sum+1)/2){
    sum1+=v[a];
    a++;
  }
  ans=sum1-(sum-sum1);
  
  reverse(v.begin(),v.end());
  int b=0;
  while(sum2<(sum+1)/2){
    sum2+=v[b];
    b++;
  }
  ans=min(ans,sum2-(sum-sum2));
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P  = pair<ll, ll>;
int main() {
    int n;
    cin >> n;
    vector<P> v(n);
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        v[i].first  = x - y;
        v[i].second = x + y;
    }
    ll al, au, bl, bu;
    al = au = v[0].first;
    bl = bu = v[0].second;
    for (int i = 0; i < n;++i){
        al = min(al, v[i].first);
        au = max(au, v[i].first);
        bl = min(bl, v[i].second);
        bu = max(bu, v[i].second);
    }
    cout << max(au - al, bu - bl);
}

Measured memory_bytes: 6360
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    s = list(str(input().rstrip('\n')))
    s = collections.deque(s)
    ds = collections.deque(s)
    while s:
        while True:
            ll = len(s)
            s = collections.deque(list("".join(s).replace("()", "")))
            if ll == len(s):
                break
        if len(s) != 0:
            if s[0] == "(":
                s.append(")")
                ds.append(")")
            else:
                s.appendleft("(")
                ds.appendleft("(")
        else:
            print("".join(ds))


if __name__ == '__main__':
    solve()


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

int main(void){
  int acc[100010];
  string str;
  int n,q,l,r;
  
  cin >> n >> q;
  cin >> str;
  acc[0] = 0;
  for (int i=1; i<n; i++){
    acc[i] = acc[i-1] + (str[i-1]=='A'&&str[i]=='C'?1:0);
  }
  for (int i=0; i<q; i++){
    cin >> l >> r;
    cout << (acc[r-1]-acc[l-1]) << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main(){
  int H,N;
  cin >> H >> N;
  int scores [N];
  int totalscores = 0;
  for(int i=0;i<N;i++){
    cin >> scores[i];
    totalscores += scores [i];}
  if (totalscores >= H){
    cout << "Yes";
  }
   else {cout << "No";}
    return 0;
 }

Measured memory_bytes: 640
#include<stdio.h>
int main(){
	int n,k,x,y,s;
	while(~scanf("%d %d %d %d",&n,&k,&x,&y)){
		if(n<=k){
			printf("%d",n*x);
		}else{
			s=(n-k)*y+k*x;
			printf("%d",s);
		}
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,K,Q;cin >> N >> K >> Q;
    vector<int> A(Q);
    rep(i,Q)cin >> A[i];

    vector<int> B(N+1,0);
    rep(i,Q){
        B[A[i]]++;
    }

    rep(i,N+1){
        if(i == 0)continue;
        int ch = K - Q + B[i];
        if(ch > 0)cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


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

#define PI 3.141592
struct xy{
  double x;
  double y;
};

double cos(double x);


int kock(int,struct xy,struct xy);

int main(){
  int n;
  struct xy p1={0.0,0.0},p2={100.0,0.0};

  scanf("%d",&n);
  printf("%f %f\n",p1.x,p1.y);
  kock(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);
  return 0;
}

int kock(int n,struct xy p1,struct xy p2){
  struct xy s,t,u;
  
  if(n==0) return 0;
  
  s.x=(2*p1.x+1*p2.x)/3;
  s.y=(2*p1.y+1*p2.y)/3;
  kock(n-1,p1,s);
  printf("%f %f\n",s.x,s.y);

  t.x=(1*p1.x+2*p2.x)/3;
  t.y=(1*p1.y+2*p2.y)/3;

  u.x=(t.x-s.x)*cos(PI/3)-(t.y-s.y)*sin(PI/3)+s.x;
  u.y=(t.x-s.x)*sin(PI/3)+(t.y-s.y)*cos(PI/3)+s.y; 

  kock(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
  
  
  kock(n-1,u,t);
  printf("%f %f\n",t.x,t.y);

  kock(n-1,t,p2);

}

Measured memory_bytes: 636
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var sc = NewScanner(os.Stdin, 1000000)

func main() {
	X := sc.readInt()
	A := sc.readInt()
	B := sc.readInt()
	rest := X - A
	rest2 := rest % B
	fmt.Println(rest2)
}

type Scanner struct {
	*bufio.Scanner
}

func (scn *Scanner) readInt() int {
	scn.Scanner.Scan()
	i, _ := strconv.Atoi(scn.Scanner.Text())
	return i
}

func NewScanner(r io.Reader, bufSize int) *Scanner {
	buf := make([]byte, bufSize)
	scn := bufio.NewScanner(r)
	scn.Buffer(buf, bufSize)
	scn.Split(bufio.ScanWords)
	return &Scanner{scn}
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] num = Stream.of(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    int n = num[0];
    int x = num[1];
    int[] l = Stream.of(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    int[] d = new int[n + 1];
    d[0] = 0;
    for (int i = 0; i < n; i++) {
      d[i + 1] = d[i] + l[i];
    }
    int count = 0;
    for (int i = 0; i <= n; i++) {
      count += d[i] <= x ? 1: 0;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 27092
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
vector <int> g[100001];
int store[100001];

void dfs(int u,int *count)
{
	//vis[u] = 1;
	if(g[u].size()==0){
		store[u]=0;
		return;
	}
	for(int i=0; i<g[u].size(); i++)
	{	
		if(store[g[u][i]]==-1)
			dfs(g[u][i],count);
		if(store[g[u][i]]+1>store[u]){
			store[u]=store[g[u][i]]+1;
		}
		
	}
	
}
main()
{
	int n,e;
	cin>>n>>e;
	for(int i=1; i<=e; i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
//		g[b].pb(a);
	}
	memset(store,-1,sizeof(store));
	int max=0;
	for(int i=1;i<=n;i++){
		int count=0;
		dfs(i,&count);
		if(store[i]>max)
			max=store[i];
	}
	cout<<max<<endl;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    cin >> N;
    N--;
    long long cnt = 1;
    long long sum = 0;
    long long pow26 = 26;
    while(sum + pow26 <= N) {
        sum += pow26;
        pow26 *= 26;
        cnt++;
    }
    N -= sum;
    string ans;
    while(N) {
        cnt--;
        char c = N % 26 + 'a';
        N /= 26;
        ans = c + ans;
    }
    for(int i = 0; i < cnt; i++) {
        ans = 'a' + ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    int M =0;
    int S =0;
    for(int i=0; i<N; i++){
        cin >> vec.at(i);
        M = max(M, vec.at(i));
        S += vec.at(i);
    }
    if(S-2*M>0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#!python3

iim = lambda: map(int, input().rstrip().split())

inf = 10**18 + 1

def cnt_val(a, b, x):
    ans = 0
    la, lb = len(a), len(b)
    J = (i for i in range(lb)) if a == b else (-1 for i in range(la))

    j = lb - 1
    for i, k in enumerate(J):
        xa = a[i]

        for j in range(j, k, -1):
            x1 = b[j] * xa
            if x1 <= x:
                break
        else:
            break
        ans += j - k

    return ans

def resolve():
    N, K = iim()
    A = [[] for i in range(3)]
    for x in input().split():
        x = int(x)
        if x < 0:
            i = 0
        elif x == 0:
            i = 1
        else:
            i = 2

        A[i].append(x)

    a0 = len(A[0]) * len(A[2])
    s1 = len(A[1])
    a1 = s1 * (2*N - s1 -1) // 2
    K1 = K - 1

    if a0 < K1 < a0 + a1:
        print(0)
        return

    if K1 < a0:
        A[0].sort()
        A[2].sort(reverse=True)
        #print(A[0], A[2])
        lo, hi = A[0][0]*A[2][0], A[0][-1] * A[2][-1] + 1
        #print((lo, hi), K1)
        while lo < hi:
            mid = (lo + hi) // 2
            k = cnt_val(A[0], A[2], mid)
            #print((lo, hi), mid, k, K1)
            if k <= K1:
                lo = mid + 1
            else:
                hi = mid
        print(lo)
        return

    A[0].sort(reverse=True)
    A[2].sort()
    K3 = K - a0 - a1 - 1
    #print(A[0], A[2], a0, a1, K3)
    lo, hi = 0, 10**18
    while lo < hi:
        mid = (lo + hi) // 2
        k3 = cnt_val(A[0], A[0], mid) + cnt_val(A[2], A[2], mid)
        #print((lo, hi), k3, K3)
        if k3 <= K3:
            lo = mid + 1
        else:
            hi = mid
    print(lo)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 85844
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int MAX = 1e9;
const ll LLMAX = 1e18;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

int main() {
    int H, W; cin >> H >> W;
    vector<string> S(H); rep(i, H) cin >> S[i];

    const int di[4] = {-1, 0, 0, 1};
    const int dj[4] = {0, -1, 1, 0};

    int all_ok = true;
    rep(i, H) {
        rep(j, W) {
            if (S[i][j] == '#') {
                int ok = false;
                rep(k, 4) {
                    int ni = i + di[k];
                    int nj = j + dj[k];
                    if (ni < 0 || ni >= H) continue;
                    if (nj < 0 || nj >= W) continue;
                    if (S[ni][nj] == '#') ok = true;
                }
                if (!ok) all_ok = false;
            }            
        }
    }

    if (all_ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
use io::*;
use std::cmp::{max, min};

fn solve(rs: &Vec<(i64, i64, usize)>, b: bool) -> i64 {
    let n = rs.len();
    let mut ans = 0;

    let mut rr = rs.clone();
    rr.sort();
    let mut ll = rs.clone();
    ll.sort_by(|a, b| (a.1, a.0).cmp(&(b.1, b.0)));

    // println!("{:?}", rr);
    // println!("{:?}", ll);

    let mut used = vec![false; n];
    let mut ri = n;
    let mut li = 0;
    let mut pos = 0;

    fn mov(p: i64, l: i64, r: i64) -> i64 {
        if l <= p && p <= r {
            p
        } else if p < l {
            l
        } else {
            r
        }
    }

    for i in 0..n {
        if (i % 2 == 0) == b {
            while used[rr[ri - 1].2] {
                ri -= 1;
            }
            let npos = mov(pos, rr[ri - 1].0, rr[ri - 1].1);
            ans += (pos - npos).abs();
            pos = npos;

            used[rr[ri - 1].2] = true;
            ri -= 1;
        } else {
            while used[ll[li].2] {
                li += 1;
            }

            let npos = mov(pos, ll[li].0, ll[li].1);
            ans += (pos - npos).abs();
            pos = npos;

            used[ll[li].2] = true;
            li += 1;
        }
    }

    ans += pos.abs();

    ans
}

fn main() {
    let con = read_string();
    let mut sc = Scanner::new(&con);

    let n: usize = sc.next();
    let rs: Vec<(i64, i64, usize)> = (0..n)
        .map(|i| {
            let l = sc.next();
            let r = sc.next();
            (l, r, i)
        })
        .collect();

    let ans = max(solve(&rs, true), solve(&rs, false));

    println!("{}", ans);
}

//-----

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 20880
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

const double pie = acos(-1.0);

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a / gcd(a, b) * b;
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

const ll MOD = 1e9 + 7;

void solve() {
    ll n, k; cin >> n >> k;
    vector<pair<ll, ll>> vp(n);
    rep(i, 0, n) cin >> vp[i].first >> vp[i].second;
    sort(ALL(vp));
    rep(i, 0, n){
        k -= vp[i].second;
        if(k <= 0){
            cout << vp[i].first << endl;
            return;
        }
    }
}

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

    solve();
    return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int n, cnt = 0;
	cin >> n;
	rep(i, n) {
		int a;
		cin >> a;
		if (a != i + 1) cnt++;
	}
	if (cnt <= 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n, p[22], br = 0;
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> p[i];
	for(int i = 1; i < n - 1; ++i){
		if(p[i] != min(min(p[i - 1], p[i]), p[i + 1]) and p[i] != max(max(p[i - 1], p[i]), p[i + 1])) ++br;
	}
	cout << br;

	return 0;
}



Measured memory_bytes: 256
from operator import itemgetter


N, M = map(int, input().split(' '))
data = []
for i in range(M):
    Pi, Yi = map(int, input().split(' '))
    data.append([i,Pi,Yi])

sorted_data = sorted(data, key=itemgetter(1,2))

codes = []
prev_p = 0
for i,p,y in sorted_data:
    if p!=prev_p:
        x = 1
        prev_p = p
    else:
        x+=1

    code = '{0:06d}{1:06d}'.format(p,x)
    codes.append([i,code])

sorted_codes = sorted(codes, key = itemgetter(0))

for code in sorted_codes:
    print(code[1])

Measured memory_bytes: 42952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=500+5;
const int N=200000+5;
const ll oo=1e18+5;
const ll mod=998244353;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	vector<pair<int,int>> val;
	vector<pair<int,int>> val2;
	int sum=0;
	for(int i=0;i<n;++i){
		string s;
		cin>>s;
		int cur=0;
		int minn=0;
		for(int j=0;j<(int)s.size();++j){
			if(s[j]=='('){
				++sum;
				++cur;
			}
			else{
				--sum;
				--cur;
			}
			minn=min(minn,cur);
		}
		if(cur>0) val.emplace_back(minn,cur);
		else val2.emplace_back(minn-cur,-cur);
	}
	if(sum!=0) return cout<<"No",0;
	auto cmp=[&](const pair<int,int>& a,const pair<int,int>& b){
		if(a.first==b.first){
			return a.second>b.second;
		}
		return a.first>b.first;
	};
	sort(val.begin(),val.end(),cmp);
	sort(val2.begin(),val2.end(),cmp);
	int cur=0;
	for(int i=0;i<(int)val.size();++i){
		if(cur+val[i].first<0) return cout<<"No",0;
		cur+=val[i].second;
	}
	cur=0;
	for(int i=0;i<(int)val2.size();++i){
		if(cur+val2[i].first<0) return cout<<"No",0;
		cur+=val2[i].second;
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 11244
import static java.lang.Math.*;
import static java.util.Arrays.*;

import java.util.*;
import java.io.*;

public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if( n == 0 ) break;
			boolean[][] ok = new boolean[n][31];
			for(int i=0;i<n;i++) for(int j=0, m=sc.nextInt();j<m;j++) 
				ok[i][sc.nextInt()] = true;
			
			long[] dp = new long[n];
			int i=1;
			boolean f = false;
			for(i=1;i<=30;i++) {
				long meet = 0;
				for(int j=0;j<n;j++) if( ok[j][i] ) meet |= 1L<<j|dp[j];
				for(int j=0;j<n;j++) if( ok[j][i] ) {
					dp[j] |= meet;
					if( dp[j] == (1L<<n)-1 ) f = true;
				}
//				debug(dp);
				if( f ) break;
			}
			System.out.println((i==31? -1: i));
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 95496
#include <algorithm>
#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
#include <string>
//#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
//#include <string.h>
#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
#define pii pair<int,int>
using namespace std;
const LL MOD=1e9+7;
bool b[200010];
int main()
{
	int n,k=0,mx=0;
	cin>>n;
	vector <int> a(n),x(n+2,0);
	rep(i,n) 
	{
		cin>>a[i];
		if(x[a[i]-1]==0) x[a[i]]=1;
		else x[a[i]]=x[a[i]-1]+1;
	}
	rep(i,n+1) if(x[i]>mx) mx=x[i];
	cout<<n-mx;
    rt0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 1000010

ll f(ll n){
	ll c=0;
	while(n>0){
		n/=10;c++;
	}
	return c%2;
}

int main(){
	IOS;
	ll n;cin>>n;
	ll ans=0;
	rep(i,1,n+1){
		if(f(i))ans++;
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int nn;
  cin >> nn;
  REP(datan,nn) {
    int n;
    cin >> n;
    
    char c[n][n];
    memset(c,' ',sizeof(c));
    if (n==2) c[1][0] = '#';
    int dx[] = {0,1,0,-1};
    int dy[] = {-1,0,1,0};

    int x = 0, y = n - 1;

    c[x][y] = '#';
    int h = n-1;
    int d = 0;
    int j = 0;
    while(h>0) {
      REP(i,h) {
        x += dx[d];
        y += dy[d];
        c[x][y]=  '#';
      }

      if (h==1) break;
      d = (d+1)%4;
      if (j>=2 && j%2==0)
        h-=2;
      j++;
    }
    if (datan) cout << endl;
    REP(y,n) {
      REP(x,n) {
        cout << c[x][y];
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>

using namespace std;
string st="CODEFESTIVAL2016",st1;
int h;
int main()
{
	cin>>st1;
	for(int i=0;i<16;i++)
	{
		if(st[i]!=st1[i])h++;
	}
	cout<<h<<endl;
	return 0;
}

Measured memory_bytes: 256
#coding:utf-8

inf = 1000000
n = int(input())
M = [[inf for i in range(n)] for j in range(n)]

for i in range(n):
    data = list(map(int,input().split()))
    u = data[0]
    k = data[1]
    for j in range(0,2*k,2):
        v, w = data[j+2], data[j+3]
        M[u][v] = w

def dijkstra(s):
    color = ["white" for i in range(n)]
    d = [inf for i in range(n)]
    p = [-1 for i in range(n)]
    d[s] = 0
    while True:
        mincost = inf
        for i in range(n):
            if color[i] != "black" and d[i] < mincost:
                mincost = d[i]
                u = i
        if mincost == inf:
            break
        color[u] = "black"

        for v in range(n):
            if color[v] != "black" and M[u][v] != inf:
                if d[u] + M[u][v] < d[v]:
                    d[v] = d[u] + M[u][v]
                    p[v] = u
                    color[v] = "gray"
    return d

dList = dijkstra(0)
for i, d in enumerate(dList):
    print(i,d)


Measured memory_bytes: 5872
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <cstring>

#define LP(i,n) for(int i=0;i<n;i++)
#define Mset(x,v) memset(x,v,sizeof(x))

using namespace std;
using LL=long long;

int A[110][110];

int main(){
    int n,m,a,b;
    cin>>n;
    LP(i,n){
        cin>>a>>m;
        LP(j,m){
            cin>>b;
            A[a-1][b-1]=1;
        }
    }
    LP(i,n){
        LP(j,n){
            if(j==n-1) cout<<A[i][j]<<endl;
            else cout<<A[i][j]<<" ";
        }
    }
    return 0;
}



Measured memory_bytes: 3080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        String s = in.next();
        if (s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) {
            out.println("Yes");
        } else {
            out.println("No");
        }
    }
}


Measured memory_bytes: 22484
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

char x, y;
int main()
{
	cin >> x >> y;
	if (x == y) cout << "=" << endl;
	else if (x < y) cout << "<" << endl;
	else cout << ">" << endl;
	return 0;
}

Measured memory_bytes: 256
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,m = map(int,ipt().split())
    way = [[] for i in range(n+1)]
    for _ in range(m):
        l,r,c = map(int,ipt().split())
        way[l].append((r,c))
    for i in range(1,n):
        way[i+1].append((i,0))
    hq = [(0,1)]
    dst = [10**18]*(n+1)
    dst[1] = 0
    while hq:
        di,qi = hpq.heappop(hq)
        for j,cj in way[qi]:
            if dst[j] > di+cj:
                dst[j] = di+cj
                hpq.heappush(hq,(di+cj,j))
    print((dst[n]+1)%(10**18+1)-1)
    
    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 96976