akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>N>>A;
    vec c(N), t(N);
    rep(i,N) cin>>c[i]>>t[i];
    ll ans = 10000;
    rep(i,N){
        if(t[i] > A) continue;
        ans = min(ans,c[i]);
    }
    if(ans == 10000){
        cout<<"TLE"<<endl;
    }else{
        cout<<ans<<endl;
    }
}


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

#1以上N以下の奇数のうち, 正の約数をちょうど8個持つようなものの個数を求めよ.
#素因数のペアとして、357,3511,3513, 3335,3337
#105,165,195

if N < 105:
  ans = 0
elif N < 135:
  ans = 1
elif N < 165:
  ans = 2
elif N < 189:
  ans = 3
elif N < 195:
  ans = 4
else:
  ans = 5
  
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
    int a,b,c,d,ans,tmp;
    string s;
 
    a = b = c = d = ans = tmp = 0;
    //vector<int>a();

    cin >> a;
    if(a >=30){
        cout << "Yes";
    }else{
        cout << "No";
    }

}


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

namespace AtCoder
{
	class Program
	{
		public static void Main()
		{
			var radius = IO.ReadDouble();
			IO.Write(2 * radius * Math.PI);
		}
	}

	public static class IO
	{
		public static string   Read()								 { return Console.ReadLine(); }
		public static string[] ReadArray(char iSplitter = ' ')		 { return Read().Split(iSplitter); }
		public static int	   ReadInt()							 { return int.Parse(Read()); }
		public static int[]	   ReadIntArray(char iSplitter = ' ')	 { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); }
		public static long	   ReadLong()							 { return int.Parse(Read()); }
		public static long[]   ReadLongArray(char iSplitter = ' ')	 { return ReadArray().Select(iText => long.Parse(iText)).ToArray(); }
		public static double   ReadDouble()							 { return double.Parse(Read()); }
		public static double[] ReadDoubleArray(char iSplitter = ' ') { return ReadArray().Select(iText => double.Parse(iText)).ToArray(); }
		public static char[]   ReadCharArray()						 { return Read().ToCharArray(); }

		public static void Write(string iValue)									   { Console.WriteLine(iValue); }
		public static void Write(int iValue)									   { Console.WriteLine(iValue); }
		public static void Write(IEnumerable<int> iValue , string iJoinWord = " ") { Console.WriteLine(string.Join(iJoinWord , iValue)); }
		public static void Write(long iValue)									   { Console.WriteLine(iValue); }
		public static void Write(double iValue)									   { Console.WriteLine(iValue); }
		public static void Write(decimal iValue)								   { Console.WriteLine(iValue); }
		public static void Write(bool iValue)									   { Console.WriteLine(iValue ? "Yes" : "No"); }
	}

	public static class Util
	{
		public static long Gcd(long i0 , long i1) { return (i0 > i1) ? _Gcd(i0 , i1) : _Gcd(i1 , i0); }
		public static long Lcm(long i0 , long i1) { return (i0 * i1) / Gcd(i0 , i1); }
		public static long ModPow(long iBaseNumber , long iPow , long iModNumber)
		{
			var num = 1L;
			while(iPow != 0)
			{
				if((iPow & 0x1) != 0)
				{
					num = (num * iBaseNumber) % iModNumber;
				}
				iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
				iPow >>= 1;
			}
			return num;
		}

		private static long _Gcd(long i0 , long i1)	{ return (i1 == 0) ? i0 : _Gcd(i1 , i0 % i1); }
	}
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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; }



int n;
vector<int> v[101010];
int used[101010];
void solve(){
	cin >> n;
	for(int i = 0; i < n-1; i++){
		int a,b;
		cin >> a >> b;
		a--; b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	
	queue<pair<int,P>> q;
	q.push({0,{1,1}});
	q.push({n-1,{2,1}});
	used[0] = 1;
	used[n-1] = 2;
	while(!q.empty()){
		pair<int,P> p = q.front(); q.pop();
		int pos = p.first, b = p.second.first, c = p.second.second;
		for(int i = 0; i < v[pos].size(); i++){
			int I = v[pos][i];
			if(used[I]) continue;
			used[I] = b;
			q.push({I,{b,c+1}});
		}
	}
	int cnt = 0;
	for(int i = 0; i < n; i++){
		if(used[i] == 1) cnt++;
	}
	if(cnt > n/2) cout << "Fennec" << endl;
	else cout << "Snuke" << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 6784
#include <iostream>
#include <cmath>
int GCD(int a, int b) {
	while (b != 0) {
		int r = a%b;
		a = b;
		b = r;
	}
	return a;
}
int main() {
	int a, b;
	while (std::cin >> a >> b) {
		int gcd = GCD(a, b);
		int lcm = round((double)a/gcd*b);
		std::cout << gcd << ' ' << lcm << std::endl;
	}
	return 0;
}

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

long long BIT[100010], bit_size;

void bit_init( int n ) {

	fill( BIT, BIT+n, 0);
	bit_size = n;

}

long long bit_max( int n ) {

	long long ans = 0;
	
	while ( n > 0 ) {
	
		ans = max( ans, BIT[n] );
		n &= n - 1;
		
	}
	
	return ans;
	
}

void bit_setmax( int n, long long v ) {

	while ( n < bit_size ) {
	
		BIT[n] = max( BIT[n], v );
		n += n & (-n);
		
	}
	
}

long long N, x;

int main() {

	cin >> N;
	
	bit_init( N+1 );
	
	for ( int i = 0; i < N; ++i ) {
	
		cin >> x;
		long long cost = bit_max( x );
		bit_setmax( x, cost + x );
		
	}
	
	cout << ( 1 + N ) * N / 2 - bit_max( N ) << endl;

}

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

int main (void) {

  int N, A, B, C, D; std::cin >> N >> A >> B >> C >> D;
  std::string S; std::cin >> S;

  int g_max = std::max(C,D);
  int cnt_stone = 0;
  for(int i=(A-1); i<=(g_max-1); i++) {
    if ( S[i] == '.' ) cnt_stone = 0;
    if ( S[i] == '#' ) cnt_stone++;
    if ( cnt_stone >= 2 ) {
      std::cout << "No" << std::endl;
      return 0;
    }
  }

  if ( C < D ) {
    std::cout << "Yes" << std::endl;
    return 0;
  }

  S[B-1] = '#';
  S[D-1] = '#';
  cnt_stone = 0;
  for(int i=(A-1); i<=(C-1); i++) {
    if ( S[i] == '.' ) cnt_stone++;
    if ( S[i] == '#' ) cnt_stone = 0;
    if ( cnt_stone >= 3 ) {
      std::cout << "Yes" << std::endl;
      return 0;
    }
  }

  S[B-1] = '.';
  S[D-1] = '.';
  cnt_stone = 0;
  for(int i=(A-1); i<=(C-1); i++) {
    if ( S[i] == '.' ) cnt_stone++;
    if ( S[i] == '#' ) cnt_stone = 0;
    if ( cnt_stone >= 3 && (S[B] == '.' || S[D-2] == '.') ) {
      std::cout << "Yes" << std::endl;
      return 0;
    }
  }

  std::cout << "No" << std::endl;

  return 0;
}

Measured memory_bytes: 640
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'
 
let lines: string[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
 
reader.on('line', function (line: string) {
    lines.push(line);
});
reader.on('close', function () {
    /* let [n, d] = lines[0].split(' ').map( _ => parseInt(_)) */
    let n = parseInt(lines[0])

    console.log(n + n**2 + n**3)
});

Measured memory_bytes: 30012
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip> 
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int dp[N] , ans = 0;
vector <int> vc[N];
void dfs(int x){
    dp[x] = 1;
    for(auto y : vc[x]){
        if(dp[y]) continue;
        dfs(y);
        dp[x] += dp[y];
    }
}
void solve(){
    int n, m ;
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        int u , v;
        cin >> u >> v;
        vc[u].pb(v);
        vc[v].pb(u);
    }
    for(int i = 1 ; i <= n ; i++){
        if(!dp[i]) dfs(i);
    }
    for(int i = 1 ; i <= n ; i++){
        // cout << dp[i] << " ";
        ans = max(ans,dp[i]);
    }
    cout << ans << '\n';
}
int main(){
fcin;
solve();

}

Measured memory_bytes: 90336
#!/usr/bin/env python3

def main():
    sa = input().split(' ')
    X = int(sa[0])
    Y = int(sa[1])

    i = 0
    while True:
        i += 1
        X = X << 1
        if Y < X:
            break

    print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main(){
   int n;
   cin >> n;
   vector<int> a(n);
   rep(i,n) cin >> a[i];
   double sum=0;
   rep(i,n) sum += 1.0/a[i];
   sum = 1/sum;
   cout <<fixed<< sum << endl;
   return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x) {
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

int n;
int inp[N];

int main(){
  fastScan(n);
  int sum = 0;
  for(int i = 0; i < n; i++){
    fastScan(inp[i]);
    sum += inp[i];
  }
  int idx = 0, dist = 1e9;
  for(int i = 0; i < n; i++){
    if(abs(sum - n * inp[i]) < dist){
      idx = i;
      dist = abs(sum - n * inp[i]);
    }
  }
  printf("%d\n", idx);
}


Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define ll long long
#define reg register
using namespace std;
string s;
int main()
{
	cin>>s;
	puts((s[0]==s[s.length()-1])^(s.length()&1)?"First":"Second");
	return 0;
}

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

int main()
{
    int d,n,x[10][10],sum,ans = 0;
    double distance;
    scanf("%d %d",&n,&d);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < d; j++)
        {
            scanf("%d",&x[i][j]);
        }
    }
    
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            sum = 0;
            for (int k = 0; k < d; k++)
            {
                sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            distance = sqrt(sum);
            if (distance == (int)distance)
            {
                ans ++;
            }
        }
        
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// END NO SAD

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

const int MOD = 1000000007;
void solve() {
  int n;
  cin >> n;
  map<state, int> dp;
  dp[state(0, {0, 0})]++;
  while(n--) {
    int x;
    cin >> x;
    map<state, int> ndp;
    for(auto out: dp) {
      state key = out.first;
      if(key.first == x) {
        ndp[state(key.first+1, key.second)] += out.second;
        ndp[state(key.first+1, key.second)] %= MOD;
      }
      if(key.second.first == x) {
        ndp[state(key.first, {key.second.first+1, key.second.second})] += out.second;
        ndp[state(key.first, {key.second.first+1, key.second.second})] %= MOD;
      }
      if(key.second.second == x) {
        ndp[state(key.first, {key.second.first, key.second.second+1})] += out.second;
        ndp[state(key.first, {key.second.first, key.second.second+1})] %= MOD;
      }
    }
    dp = ndp;
  }
  int ret = 0;
  for(auto out: dp) {
    ret += out.second;
    ret %= MOD;
  }
  cout << ret << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int solve(int n) {
	// 1000000000
	// 0777555333
	// 0777777777
	int res = 0;
	for (int sevenCnt = 1; sevenCnt <= 9; sevenCnt++) {
		for (int fiveCnt = 1; fiveCnt <= 9; fiveCnt++) {
			for (int threeCnt = 1; threeCnt <= 9; threeCnt++) {
				if (sevenCnt + fiveCnt + threeCnt > 9) {
					continue;
				}

				string s = string(sevenCnt, '7');
				s += string(fiveCnt, '5');
				s += string(threeCnt, '3');

				sort(begin(s), end(s));
				do {
					if (stoi(s) > n) {
						continue;
					}
					res++;
				} while (next_permutation(begin(s), end(s)));
			}
		}
	}

	return res;
}

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

	int n;
	cin >> n;

	cout << solve(n) << endl;
	return 0;
}


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

int main(){
    int n; cin >> n;
    ll half_of_water = 0;
    vector <ll> gusu_sum, kisu_sum;
    vector <ll> A(n);
    rep(i, n) {
        cin >> A.at(i);
        half_of_water += A.at(i);
    }

    gusu_sum.push_back(A.at(0));
    kisu_sum.push_back(A.at(1));
    rep(i, n){
        if (i <= 1) continue;
        if (i % 2 == 0){
            gusu_sum.push_back(gusu_sum.back() + A.at(i));
        }
        else{
            kisu_sum.push_back(kisu_sum.back() + A.at(i));
        }
    }

    half_of_water /= 2;
    vector <ll> ans(n);

    rep(i, n){
        int first_index;
        ll min_sum = 0;
        if (i % 2 == 0){
            first_index = i - 2;
            if (first_index >= 0){
                min_sum += gusu_sum.at(first_index / 2);
            }
            min_sum += (kisu_sum.at(kisu_sum.size() - 1));
            if (i != 0){
                min_sum -= kisu_sum.at((i - 1) / 2);
            }
        }
        else{
            if (i >= 3){
                min_sum += kisu_sum.at((i - 2) / 2);
            }
            min_sum += (gusu_sum.at(gusu_sum.size() - 1));

            min_sum -= gusu_sum.at((i - 1) / 2);
        }

        cout << (half_of_water - min_sum) * 2 << " ";
    }
    cout << endl;
}

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

using namespace std;

#define INF 1000000007
#define LINF 1000000000000000007

typedef long long Int;
typedef pair<Int,Int> P;

Int gcd(Int x, Int y){
	if(y == 0) return x;
	return gcd(y, x%y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x,y);
}

bool sosuu(Int x){
	bool b = 1;
	if(x == 1) b = 1;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0){b = 0; break;}
	}
	return b;
}

int n, a[2][100];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[0][i];
	}
	for(int i = 0; i < n; i++){
		cin >> a[1][i];
	}
	int cnt = 0, ans = 0;
	for(int i = 0; i < n; i++){
		cnt = 0;
		for(int j = 0; j <= i; j++){
			cnt += a[0][j];
		}
		for(int j = i; j < n; j++){
			cnt += a[1][j];
		}
		ans = max(ans, cnt);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t a, b, c;
  cin >> a >> b >> c;
  int64_t x = c - a - b;
  if(x >= 0 && 4 * a * b < x * x){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  
  string str;
  cin>>str;
  cout<<str.substr(0,4)<<" "<<str.substr(4)<<endl;; 

  return;
}



int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;

const long long MOD = (long long)1e9 + 7;
int n, W, w[109], v[109], V;
long long dp[100009];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> W;
	V = 100000;
	for (int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}
	memset(dp, 0x3f, sizeof(dp));
	dp[v[0]] = w[0]; dp[0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = V; j > 0; j--) {
			if (j >= v[i])
				dp[j] = min(dp[j - v[i]] + w[i], dp[j]);
		}
	}
	long long ans = 0;
	for (int i = 100000; i > 0; i--) {
		if (dp[i] <= W) {
			ans = i;
			break;
		}
	}
	cout << ans << "\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

struct queue_tag;
typedef struct queue_tag queue_t;
extern queue_t *queue_create(const size_t len);
extern void queue_destroy(queue_t *const q);
extern size_t queue_get_size(const queue_t *const q);
extern bool queue_enqueue(queue_t *const q, void *data, size_t len);
extern bool queue_dequeue(queue_t *const q, void *data, size_t len);

struct queue_tag {
  uint8_t *data;
  size_t size;
  size_t top;
  size_t buttom;
  size_t max_size;
};

queue_t *queue_create(const size_t len)
{
  queue_t *q = (queue_t *)malloc(sizeof(queue_t));
  if (q == NULL) goto err;

  q->data = (uint8_t *)malloc(len);
  if (q->data == NULL) goto err;

  q->size = 0;
  q->top = 0;
  q->buttom = 0;
  q->max_size = len;

  return q;

err:
  perror("memeory is full\n");
  exit(1);
}

void queue_destroy(queue_t *const q)
{
  if (q != NULL) {
    free(q->data);
  }
  free(q);

  return;
}

size_t queue_get_size(const queue_t *const q)
{
  if (q == NULL) {
    return 0;
  }

  return q->size;
}

static bool enqueue_check_params(queue_t *const q, size_t len)
{
  if (q == NULL) return false;

  if (q->max_size < len) return false;

  if (q->max_size < (q->size + len)) return false;

  return true;
}

bool queue_enqueue(queue_t *const q, void *data, size_t len)
{
  if (!enqueue_check_params(q, len)) {
    return false;
  }
  uint32_t i;
  for (i = 0; i < len; i++) {
    q->data[q->top++] = ((uint8_t *)data)[i];
    q->top %= q->max_size;
    q->size++;
  }

  return true;
}

static bool dequeue_check_params(queue_t *const q, size_t len)
{
  if (q == NULL) return false;

  if ((int32_t)((int32_t)q->size - len) < 0) return false;

  return true;
}

bool queue_dequeue(queue_t *const q, void *data, size_t len)
{
  if (!dequeue_check_params(q, len)) {
    return false;
  }
  uint32_t i;
  for (i = 0; i < len; i++) {
    ((uint8_t *)data)[i] = q->data[q->buttom++];
    q->buttom %= q->max_size;
    q->size--;
  }

  return true;
}

#if !defined(TEST)
typedef struct {
  char name[16];
  int32_t time;
} process_t;

int32_t main(void)
{
  int32_t num = 0;
  int32_t quantum = 0;
  scanf("%d %d", &num, &quantum);

  queue_t *q = queue_create(sizeof(process_t) * 256 * 1000);

  int32_t i;
  for (i = 0; i < num; i++) {
    process_t process;
    scanf("%s %d", process.name, &process.time);
    queue_enqueue(q, (void *)&process, sizeof(process));
  }

  int32_t elapsed = 0;
  while (queue_get_size(q)) {
    process_t process;
    queue_dequeue(q, (void *)&process, sizeof(process));
    if ((process.time - quantum) <= 0) {
      elapsed += process.time;
      printf("%s %d\n", process.name, elapsed);
    } else {
      process.time -= quantum;
      queue_enqueue(q, (void *)&process, sizeof(process));
      elapsed += quantum;
    }
  }
  queue_destroy(q);
  return 0;
}
#endif

Measured memory_bytes: 4720
import Data.List

main = do
    n <- readLn
    print . sum . filter (check n) . map pred $ divisor n

check n m | m == 0 = False
          | otherwise = p == q
          where (p,q) = n `divMod` m

divisor n = foldr f [] $ takeWhile ((<= n) . (^ 2)) [1 .. n]
  where
    f x ds
      | r == 0
      , q /= x = x : q : ds
      | r == 0 = x : ds
      | otherwise = ds
      where
        (q, r) = n `divMod` x

Measured memory_bytes: 892
# -*- coding: utf-8 -*-
n, k = map(int,input().split())
h = []
for i in range(n):
    h.append(int(input()))

h.sort()
ans = 10 ** 5 * 10 ** 10
for i in range(n - k + 1):
    #print(i, i + k - 1)
    if h[i + k - 1] - h[i] < ans:
        ans = h[i + k - 1] - h[i]
print(ans)


Measured memory_bytes: 7384
N = int(input())
tarou = 0
hanako = 0
for _ in range(N):
    t,h = input().split()
    if t == h:
        tarou += 1
        hanako += 1
    elif [t,h] != sorted([t,h]):
        tarou += 3
    else:
        hanako += 3
print(tarou, hanako)


Measured memory_bytes: 5596
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	int h,w ;
	cin >> h >> w ;
	string s ;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> s ;
			if(s=="snuke"){
				cout << (char)('A'+j) << i+1 << endl ;
				return 0 ;
			}
		}
	}
}


Measured memory_bytes: 256
#include<cstdio>
#include<utility>
#include<algorithm>
using namespace std;

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int N = 1e5 + 5;
const int P = 1e9 + 7;

int x[N], y[N], b[N], n, m, tot;
pair<int, int> a[N];

int seg[N];

void add(int x, int t)
{
	for (; x <= tot; x += x & -x)
		(seg[x] += t) %= P;
}

int query(int x)
{
	int res = 0;
	for (; x; x -= x & -x)
		(res += seg[x]) %= P;
	return res;
}

int main()
{
	n = read();
	m = read();
	
	for (int i = 1; i <= n; ++i) x[i] = read();
	for (int i = 1; i <= m; ++i) y[i] = read();
	
	for (int i = 1; i <= n; ++i)
	{
		int nxt = upper_bound(y + 1, y + m + 1, x[i]) - y;
		int pre = nxt - 1;
		
		if (pre <= 0 || nxt > m) continue;

		nxt = y[nxt] - x[i];
		pre = x[i] - y[pre];
		
		a[++tot] = make_pair(pre, nxt);
		b[tot] = nxt;
	}
	
	n = tot;
	
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	tot = unique(b + 1, b + n + 1) - b;
	
	add(1, 1);
	
	for (int i = 1, j = 1; i <= n; i = j)
	{
		while (j <= n && a[i].first == a[j].first) ++j;
		
		for (int k = j - 1; k >= i; --k)
		{
			a[k].second = lower_bound(b + 1, b + tot, a[k].second) - b;
			if (k < j - 1 && a[k].second == a[k + 1].second) continue;
			add(a[k].second + 1, query(a[k].second));
		}
	}
	
	printf("%d\n", query(tot));
	
	return 0;
}


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

int main() {
    int K;
    int S;
    cin >> K >> S;
    int c=0;
    for(int x=0;x<=K;x++){
        for(int y=0;y<=K;y++){
            if(x+y>=S-K && x+y<=S){
                c++;
            }
        }            
    }
    cout << c << endl;
}
		

Measured memory_bytes: 256
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

from heapq import heapify, heappush, heappop, heappushpop, heapreplace
from bisect import bisect_left, bisect_right

n, k = map(int, input().split())
if n % k == 0:
    print(0)
    exit()
if n < k:
    print(min(n, abs(n-k)))
    exit()
print(min(n%k, abs(n%k-k)))

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int p[]=new int[N];
		int n[]=new int[N];
		int z=0,ans=0;
		while(z<N){
			p[z]=stdIn.nextInt();
			n[z]=p[z];
			z++;
		}z=0;
		Arrays.sort(n);
		while(z<N){
			if(p[z]!=n[z])
				ans++;
			if(ans>3)
				break;
			z++;
		}z=0;
		if(ans<3)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}

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

using namespace std;


int main() {
  int x;
  cin >> x;
  
  vector<bool> exp(1000); 
  exp[1] = true;
  for(int i=2; i<=1000; ++i){
    for(int j=2; pow(i, j)<=1000; ++j){
      exp[(int)pow(i, j)] = true;
    }
  }
  
  for(int i=x; i>=0; --i){
    if(exp[i]){
      cout << i << endl;
      return 0;
    }
  }
  
}


Measured memory_bytes: 3984
N,M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
B = []
for i in range(M-1):
    B.append(A[i+1] - A[i])
B.sort()

ans = 0
for i in range(M-N):
    ans += B[i]
print(ans)

Measured memory_bytes: 13968
N = int(input())
P = list(map(float, input().split()))

"""
dp[i][j]: i枚投げた時にj枚表の確率
"""
dp = [[0] * (N+1) for _ in range(N+1)]
dp[1][0] = 1 - P[0]
dp[1][1] = P[0]

for i in range(1, N+1):
    for j in range(1, N+1):
        dp[i][j] += dp[i-1][j-1] * P[i-1]
        dp[i][j-1] += dp[i-1][j-1] * (1-P[i-1])

ans = 0
for i in range(N+1):
    if N//2 < i:
        ans += dp[N][i]
print(ans)


Measured memory_bytes: 252296
//Traveling
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

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

	long long t[2] = {0,0};
    long long x[2] = {0,0};
    long long y[2] = {0,0};
	cin >> t[0] >> x[0] >> y[0];
  
	for (int i = 1; i <= n; ++i) {
		cin >> t[1] >> x[1] >> y[1];

		long long ss = abs(t[1] - t[0]) - abs(y[1] - y[0]) -  abs(x[1] - x[0]);
		if (ss < 0 || ss & 1) {
			cout << "No";
			return 0;
		}
		t[0] = t[1];
		x[0] = x[1];
		y[0] = y[1];
	}

	cout << "Yes";

	return 0;
}


Measured memory_bytes: 256
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)


def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: x - 1, map(int, input().split()))


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def functional(N, mod):
    F = [1] * (N + 1)
    for i in range(N):
        F[i + 1] = (i + 1) * F[i] % mod
    return F


def main():
    a, b, c = read_values()
    r = c - a - b
    if r <= 0:
        print("No")
        return
    
    print("Yes" if (c - a - b) ** 2 > 4 * a * b else "No")

if __name__ == "__main__":
    main()

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int N;
  while(cin >> N){
    vector<int> A(N); cin >> A;

    vector<i64> count(N+1);
    for(auto x : A){
      count[x] += 1;
    }

    i64 s = 0;
    for(auto x : count){
      s += x * (x - 1) / 2;
    }

    REP(i,N){
      i64 ans = s;

      i64 x = count[A[i]];
      ans -= x * (x-1) / 2;
      ans += (x-1) * (x-2) / 2;
      
      puts_all(ans);
    }
  }


  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main(void){
 
 
 
    int S,h,m,s;
 
    cin >> S;
    
 
    s=S/60/60;
    m=S-(s*3600);
    m=m/60;
    h=S-(s*3600)-(m*60);
    
 
    cout <<s<<":"<<m<<":"<<h<<endl;
 
 
 
    return 0;
 
}

Measured memory_bytes: 1164
#include<stdlib.h>
#include<stdio.h>
int a[10005];
int b[10005];
int main()
{
	int n, i, flag = 0;
	scanf("%d", &n);
	long long int p = 0, q = 0, sum = 0, sum1 = 0;
	for (i = 0;i < n;i++) 
	{
		scanf("%d", &a[i]);
		p += a[i];
	}
	for (i = 0;i < n;i++)
	{
		scanf("%d", &b[i]);
		q += b[i];
	}
	if (q == p)flag = 1;
	int k = 0;
	for (i = 0;i < n;i++)
	{
		if (a[i] > b[i])
		{
			k = a[i] - b[i];
			q += k;
			p += 2 * k;
			sum1 += k;
		}
		else
			sum += (b[i] - a[i]) / 2;
	}
	if (p <= q&& sum>=sum1)printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
# 深さ優先探索 Depth first search: DFS


def dfs(u):
    global time
    color[u - 1] = 0
    time += 1
    d[u - 1] = time
    for v in range(1, n + 1):
        if A[u - 1][v - 1] == 1 and color[v - 1] == -1:
            dfs(v)
    color[u - 1] = 1
    time += 1
    f[u - 1] = time


n = int(input())
A = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
    dat = [int(j) for j in input().split()]
    for j in range(dat[1]):
        A[dat[0] - 1][dat[2 + j] - 1] = 1

color = [-1 for i in range(n)]
d = [-1 for i in range(n)]
f = [-1 for i in range(n)]
time = 0
for i in range(n):
    if color[i] == -1:
        dfs(i+1)

for id in range(n):
    print(id + 1, d[id], f[id])



Measured memory_bytes: 5804
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).
*/

main :-
    get_number(A),
    get_string(S),
    (3200 =< A) -> writeln(S) ; writeln("red").


Measured memory_bytes: 8004
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);
const long double PI = atan2(0.0L,-1.0L);

#define l_ength size

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

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	long double a,b,x,t,ans;
	cin >> a >> b >> x;
	x /= a;
	if(x>=a*b/2.0){
		t = (a*b-x)/a;
		t *= 2;
		ans = atan2(t,a);
	}else{
		t = x/b;
		t *= 2;
		ans = atan2(b,t);
	}
	ans *= 180.0;
	ans /= PI;
	cout << fixed << setprecision(50) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
from itertools import accumulate
from collections import Counter

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

# 累積和とCounterを用いて各lについて、A_l + ... + A_r が M の倍数となるような
# rの個数をO(1)で求める
R = list(accumulate([0] + A, lambda acc, a: (acc + a) % M))
C = Counter(R)
s = 0
for i in range(N):
    C[R[i]] -= 1
    s += C[R[i]]
ans = s

print(ans)


Measured memory_bytes: 15916
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,-1,sizeof(i));
#define pb push_back

int main(){
    int n, k;
    cin >> n >> k;
    ll cont[55];
    f(n)cin >> cont[i];
    ll ans =0;
    for(int i=1;i<=min(k,n);i++){
        int lb = 0,rb= n-i;
        while(lb<=i){
            multiset<ll>st;
            for(int j=0;j<n;j++){
                if(j<lb||j>=rb){
                    st.insert(cont[j]);
                }
            }
            int left = k - i;
            /*for(auto z:st){
                cout<<z<<' ';
            }
            cout<<left<<endl;*/
            while(left && st.size()){
                if(*st.begin()>0)break;
                st.erase(*st.begin());left--;
            }
            ll s=0;
            for(auto z:st){
                s += z;
            }
            ans = max(s,ans);
            rb++,lb++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
a, b, c, d = list(input())
for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            tmp = a + op1 + b + op2 + c + op3 + d
            if eval(tmp) == 7:
                print(tmp+'=7')
                exit()


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#define LL long long
int A, B;
int ans;
int main() {
	std::cin >> A >> B;
	for (A; A <= B; A++) {
		int tmp = A;
		int a = tmp / 10000;
		tmp %= 10000;
		int b = tmp / 1000;
		tmp %= 100;
		int c = tmp / 10;
		tmp %= 10;
		int d = tmp / 1;
		if (a == d&&b == c) {
			ans++;
		}
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
    int n,n2,d=0,ans=0;
    
    scanf("%d",&n);
    
    n2=n;
    while(n!=0){
        n = n / 10;
        d++;
    }

    for(int i=0;i<d;i+=2){
        ans+=9*pow(10,i);
    }
    if(d%2)
        ans+=n2-pow(10,d)+1;
    printf("%d",ans);
  
  return 0;
}


Measured memory_bytes: 2596
#include<stdio.h>
int main()
{
  int f,h,d,s,a;
  scanf("%d",&f);
  h=f/3600;
  d=f%3600;
  s=d/60;
  a=d%60;
  printf("%d:%d:%d\n",h,s,a);
  return 0;
}

Measured memory_bytes: 2744
#include<stdio.h>
int main(void){
  int a[3],i,len=0,str=0;
  for(i=0;i<3;i++){
  scanf("%d",&a[i]);
  }
  
  for(i=0;i<3;i++){
    if(a[i]==5){
      len++;
    }
    else if(a[i]==7){
      str++;
    }
    else {
      printf("NO");
      return 0;
    }
  }
    if(str==1&&len==2) printf("YES");
  	else printf("NO");	
   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  int s=0;
  for(int i=0;i<N;i++){
    int c=0;
    for(int j=0;j<N;j++){
      if(vec.at(i)<=vec.at(j)){
        c++;
      }
    }
    for(int k=i;k<N;k++){
      if(vec.at(i)==vec.at(k)){
        c++;
      }
    }
    int a=1;
    for(int j=0;j<c;j++){
      a *= -1;
    }
    s+=vec.at(i)*a;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 384
#!/usr/bin/env/ python3
#S = input()
N = int(input())
#A, B, C = input().split()
#N, M = map(int, input().split())

#N = int(input())
#A = [int(x) for x in input().split()]

#H, W = map(int, input().split())
#S = [input() for _ in range(H)]
#print(S[0][1])
ans = N*N*N/27.0
print('{0:.12f}'.format(ans))

Measured memory_bytes: 3060
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int digit(ll num) {
	if (num < 10) {
		return 1;
	} else {
		return 1 + digit(num / 10);
	}
}

int main(void) {
	int N;
	scanf("%d", &N);
	ll res = 1;
	vector<ll> v(N);
	for (int i = 0; i < N; i++) {
		scanf("%ld", &v.at(i));
	}
	sort(v.begin(), v.end());
	if (v.at(0) == 0) {
		printf("0\n");
		return 0;
	}
	for (int i = 0; i < N; i++) {
		if (log10(res) + log10(v.at(i)) > 18) {
			printf("-1\n");
			return 0;
		}
		res *= v.at(i);
	}
	if (res > 1000000000000000000) {
		printf("-1\n");
		return 0;
	}
	printf("%ld\n", (ll) res);
	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    int n;
    scanf("%d", &n);  
    vector<int> q(n+1, 0);
    rep(i, n){
        int p;
        scanf("%d", &p);
        q[p] = q[p-1]+1;

    }
    int ans = accumulate(q.begin(), q.end(), 0, [](int a, int b){return max(a, b);});
    ppp(n-ans);

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  string s;cin>>s;
  if(s == "ABC"){
    cout << "ARC" << endl;
  }else{
    cout << "ABC" << endl;
  }
  return 0;
}

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

int N, dp[100001][3];

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

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


Measured memory_bytes: 1280
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

int main(void){
    int N, M;
    cin >> N >> M;
    //Ea = p * 1 + (i-p) * (Ea + 1)
    //Ea = 1 / p
    //Ea = 2^M
    cout << pow(2, M) * (100 * N + 1800 * M) << endl;
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] a=new int[3];
		for(int i=0;i<3;i++) {
			a[i]=scan.nextInt();
		}
		Arrays.sort(a);
		String s="";
		for(int i=2;i>0;i--) {
			s+=a[i];
		}
		System.out.println(Integer.parseInt(s)+a[0]);
	}

}


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

using namespace std;

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

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

    int find = 1;

    for (int i = 0; i < N; i++) {
        if (a[i] == find) find++;
    }

    cout << ((find == 1) ? -1 : N - (find - 1)) << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <memory.h>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)

//FILE *in = freopen("input.txt", "r", stdin);
//FILE *out = freopen("output.txt", "w", stdout);

int n;

struct node {
	string name;
	vector<node*> child;
	bool check;
	node(char *names) {
		name = string(names);
		check = false;
	}
};

map<string, node*> names;
string first;

void input(){
	for(int i = 0; i < n; i++) {
		getc(stdin);
		char c;
		char groupname[100];
		int gc = 0;
		while((c = getc(stdin)) != ':') {
			groupname[gc++] = c;
		}
		groupname[gc] = 0;
		node* group;
		auto grpfind = names.find(groupname);
		if(grpfind == names.end()) {
			group = new node(groupname);
			names[groupname] = group;
			if(i == 0) first = groupname;
		}else{
			group = grpfind->second;
		}
		do{
			char person[100];
			int pc = 0;
			while((c = getc(stdin)) != ',' && c != '.') {
				person[pc++] = c;
			}
			person[pc] = 0;
			node* pp;
			auto ppp = names.find(person);
			if(ppp == names.end()) {
				pp = new node(person);
				names[person] = pp;
			}else{
				pp = ppp->second;
			}
			group->child.push_back(pp);
		}while(c != '.');
	}
}

int back(string name) {
	node* pp = names[name];
	if(pp->check) return 0;
	pp->check = true;
	if(pp->child.size() == 0) {
		return 1;
	}
	int res = 0;
	REP(i, pp->child.size()) {
		res += back(pp->child[i]->name);
	}
	return res;
}

void process() {
	int res = back(first);
	printf("%d\n", res);
}

void output() {
}

int main() {
	while(scanf("%d", &n) > 0 && n) {
		names.clear();
		input();
		process();
		output();
	}
	return 0;
}

Measured memory_bytes: 2100