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

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define verify(x) if(x >= MOD) x -= MOD;

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void print_case(int tn) {cout<<"Case #"<<tn<<": ";}

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;
/*----------------------------------------------------------------------*/

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    clock_t clk = clock();

    int k,x; cin>>k>>x;
    if(500*k >= x) {
        cout<<"Yes";
    } else {
        cout<<"No";
    }

    cerr << endl << "Time (in ms): " << double(clock() - clk) * 1000.0 / cps << endl;
    return 0;
}

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

int main(void) {
    char S[200001], T[200001];
    int i = 0, sum = 0;
    scanf("%s", S);
    scanf("%s", T);

    for(i = 0; i < strlen(S); i++) {
        if(S[i] != T[i]) {
            sum++;
        }
    }
   
    printf("%d\n", sum);
}

Measured memory_bytes: 2488
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

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


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

	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	ll ans = 0;

	// 隣り合う二つの正負を反転する
	ll minusNum = 0;
	rep(i, n) {
		if (a[i] < 0) minusNum++;
		a[i] = abs(a[i]);
	}

	sort(allof(a));
	minusNum %= 2;

	rep(i, n) {
		if (i < minusNum) ans -= a[i];
		else ans += a[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+50; 
int n,k;
int a[maxn];
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;++i) cin>>a[i];
	sort(a,a+n);
	int sum=0;
	for(int i=0;i<k;++i) sum+=a[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3628
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n";
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

int main(){
    long long n;
    cin >> n;
    cout << (n*(n-1))/2 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

constexpr int inf = 1e9;
template<class T> struct edge { int to; T cap; int rev; edge(int t, T c, int r) : to(t), cap(c), rev(r) {} };

void add_edge(int from, int to, auto cap, auto& g) {
  g[from].emplace_back(to, cap, g[to].size());
  g[to].emplace_back(from, 0, g[from].size() - 1);
}

template<class T> T dinic(int s, int t, VV< edge<T> > g) {
  int n = g.size();
  V<> dist, i;

  auto bfs = [&]() {
    dist.assign(n, -1);
    queue<int> q;
    dist[s] = 0; q.push(s);
    while (!q.empty()) {
      int v = q.front(); q.pop();
      for (auto&& e : g[v]) if (dist[e.to] == -1 and e.cap > 0) {
        dist[e.to] = dist[v] + 1; q.push(e.to);
      }
    }
  };

  auto dfs = [&](int v, T f, auto& dfs) {
    if (v == s) return f;
    for (; i[v] < g[v].size(); i[v]++) {
      edge<T>& e = g[v][i[v]];
      if (dist[e.to] < dist[v] and g[e.to][e.rev].cap > 0) {
        T d = dfs(e.to, min(f, g[e.to][e.rev].cap), dfs);
        if (d > 0) {
          g[e.to][e.rev].cap -= d;
          e.cap += d;
          return d;
        }
      }
    }
    return (T) 0;
  };

  T res = 0;
  while (true) {
    bfs();
    if (dist[t] == -1) return res;
    i.assign(n, 0);
    while (true) {
      T f = dfs(t, inf, dfs);
      if (f == 0) break;
      res += f; 
    }
  }
}

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  V<string> a(h); for (int i = 0; i < h; i++) cin >> a[i];
  int s, t;
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
    if (a[i][j] == 'S') s = 2 * (i * w + j) + 1;
    if (a[i][j] == 'T') t = 2 * (i * w + j);
  }
  VV< edge<int> > g(2 * h * w);
  for (int i = 0; i < h; i++) {
    for (int jl = 0; jl < w; jl++) for (int jr = 0; jr < w; jr++) {
      if (jl != jr and a[i][jl] != '.' and a[i][jr] != '.') add_edge(2 * (i * w + jl) + 1, 2 * (i * w + jr), inf, g);
    }
  }
  for (int j = 0; j < w; j++) {
    for (int il = 0; il < h; il++) for (int ir = 0; ir < h; ir++) {
      if (il != ir and a[il][j] != '.' and a[ir][j] != '.') add_edge(2 * (il * w + j) + 1, 2 * (ir * w + j), inf, g);
    }
  }
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) add_edge(2 * (i * w + j), 2 * (i * w + j) + 1, 1, g);
  int res = dinic<int>(s, t, g);
  cout << (res >= inf ? -1 : res) << '\n';
}


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

#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long int lli;

int main()
{
	fio;
	int n;
	cin>>n;
	vector<int> a(n),b(n),c(n);
	for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
	vector<vector<int> > dp(n, vector<int> (3));
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for(int i=1;i<n;i++)
	{
		dp[i][0] = a[i] + max(dp[i-1][1],dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][0],dp[i-1][2]);
		dp[i][2] = c[i] + max(dp[i-1][0],dp[i-1][1]);
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
	return 0;
}

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

public class Main {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader() throws FileNotFoundException {
            // reader = new BufferedReader(new FileReader("count.in"));
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }

        String next() { // reads in the next String
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() { // reads in the next int
            return Integer.parseInt(next());
        }

        public long nextLong() { // reads in the next long
            return Long.parseLong(next());
        }

        public double nextDouble() { // reads in the next double
            return Double.parseDouble(next());
        }

        public int[] nextIntArr(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) arr[i] = nextInt();
            return arr;
        }

        public long[] nextLongArr(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) arr[i] = nextLong();
            return arr;
        }

        public double[] nextDoubleArr(int size) {
            double[] arr = new double[size];
            for (int i = 0; i < size; i++) arr[i] = nextDouble();
            return arr;
        }

    }

    public static void main(String[] args) throws IOException, FileNotFoundException {
        InputReader in = new InputReader();
        PrintWriter pw = new PrintWriter(System.out);

        int n = in.nextInt();
        int k = in.nextInt();

        int[] pts = in.nextIntArr(n);
        int[] dp = new int[n];

        dp[0] = 0;
        dp[1] = Math.abs(pts[1] - pts[0]);
        for (int i = 2; i < dp.length; i++) {
            int best = Integer.MAX_VALUE;
            // System.out.println("for i: " + i);
            for (int j = 1; j <= Math.min(k, i); j++) {
                // System.out.println("Option " + j + ": " + dp[i - j] + Math.abs(pts[i] - pts[i - j]));
                best = Math.min(best, dp[i - j] + Math.abs(pts[i] - pts[i - j]));
            }
            dp[i] = best;
        }
        // System.out.println(Arrays.toString(dp));

        pw.println(dp[n - 1]);

        pw.close();
    }
}


Measured memory_bytes: 44380
import java.io.IOException; 
import java.io.InputStream; 
import java.io.PrintWriter; 

class Main{ 

	static void solve(){
		int n = ni(), k=ni();
		long[] x = nla(n);
		long ans = Long.MAX_VALUE;
		if(k==1){
			for(int i=0;i<n;++i)ans=Math.min(ans, Math.abs(x[i]));
		}else{
			for(int i=0;i+k<=n;++i){
				ans = Math.min(ans, x[i+k-1] - x[i] + Math.min(Math.abs(x[i+k-1]), Math.abs(x[i])));
			}
		}

		System.out.println(ans);
 
	} 
 
 
 
 
	public static void main(String[] args){ 
		 solve(); 
		 out.flush(); 
	 } 
	 private static InputStream in = System.in; 
	 private static PrintWriter out = new PrintWriter(System.out); 
 
	 private static final byte[] buffer = new byte[1<<15]; 
	 private static int ptr = 0; 
	 private static int buflen = 0; 
	 private static boolean hasNextByte(){ 
		 if(ptr<buflen)return true; 
		 ptr = 0; 
		 try{ 
			 buflen = in.read(buffer); 
		 } catch (IOException e){ 
			 e.printStackTrace(); 
		 } 
		 return buflen>0; 
	 } 
	 private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} 
	 private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} 
	 private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} 
 
	 private static double nd(){ return Double.parseDouble(ns()); } 
	 private static char nc(){ return (char)skip(); } 
	 private static String ns(){ 
		 StringBuilder sb = new StringBuilder(); 
		 for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); 
		 return sb.toString(); 
	 } 
	 private static int[] nia(int n){ 
		 int[] res = new int[n]; 
		 for(int i=0;i<n;++i)res[i]=ni(); 
		 return res; 
	 } 
	 private static long[] nla(int n){ 
		 long[] res = new long[n]; 
		 for(int i=0;i<n;++i)res[i]=nl(); 
		 return res; 
	 } 
	 private static int ni(){ 
		 int res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	 } 
	 private static long nl(){ 
		 long res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	} 
} 



Measured memory_bytes: 21844
n = int(input())
al = list(map(int, input().split()))

cnt = [0]*(10**6+10)
for a in al:
    if cnt[a]>1:
        continue
    for i in range(0,10**6+10,a):
        cnt[i] += 1

res = 0
for a in al:
    if cnt[a]==1:
        res += 1
print(res)

Measured memory_bytes: 121808
def e_this_message_will_self_destruct_in_5s():
    from bisect import bisect_left
    N = int(input())
    A = [int(i) for i in input().split()]

    add = [j + a for j, a in enumerate(A, 1)]
    diff = sorted([k - a for k, a in enumerate(A, 1)])
    ans = 0
    for p in add:
        ans += bisect_left(diff, p + 1) - bisect_left(diff, p)
    return ans

print(e_this_message_will_self_destruct_in_5s())

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, 0, n) cin >> a[i];
  
  if(n%2==0) {
    for(ll i = n-1; i > 0; i -= 2) cout << a[i] << " ";
    for(ll i = 0; i < n-1; i += 2) cout << a[i] << (i==n-2 ?"" :" ");
  }
  else {
    for(ll i = n-1; i >= 0; i -= 2) cout << a[i] << " ";
    for(ll i = 1; i < n-1; i += 2) cout << a[i] << (i==n-2 ?"" :" ");
  }
  cout << "\n";
}

Measured memory_bytes: 5376
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = list(input())
for i in range(K,N,1) :
    if T[i]==T[i-K]:
        T[i] = "NG"
        
R2=T.count("r")
S2=T.count("s")
P2=T.count("p")
print(P*R2+R*S2+S*P2)


Measured memory_bytes: 4084
from itertools import accumulate



def expectation(n):
    return (n + 1) / 2


def main():
    n, k = map(int, input().split())
    p = [0] + list(map(int, input().split()))
    n += 1
    for i in range(1, n):
        p[i] = expectation(p[i])
    p = list(accumulate(p))
    answer = 0
    for i in range(n - k + 1):
        answer = max(answer, p[i + k - 1] - p[i - 1])
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 25152
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        // list[i]: i日後に報酬がもらえる各仕事の報酬
        List<Integer>[] list = new List[100101];
        for (int i = 0; i < 100101; i++) {
            list[i] = new ArrayList<Integer>();
        }
        
        // a日後にb円もらえる仕事をリストに入れる
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            list[a].add(b);
        }
        
        // que: 今できる仕事のキュー(報酬の大きい順に並んでいる)
        PriorityQueue<Integer> que = new PriorityQueue<>(Collections.reverseOrder());
        
        long ans = 0;
        for (int i = 1; i <= m; i++) {
            // 残りi日でできる仕事の報酬bをキューに入れる
            for (Integer b : list[i]) {
                que.add(b);
            }
            
            // 今できる仕事のうち、最大の報酬の仕事を選ぶ
            if (!que.isEmpty()) {
                ans += que.poll();
            }
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 91104
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int read(){
	int x=0;
	char ch=getchar();
	while (!isdigit(ch))
		ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
int n,m;
vector <int> e[N],a1,a2;
int vis[N];
void dfs(int x,vector <int> &a){
	vis[x]=1;
	a.push_back(x);
	for (auto y : e[x])
		if (!vis[y])
			return dfs(y,a);
}
int main(){
	n=read(),m=read();
	int k1,k2;
	for (int i=1;i<=m;i++){
		int a=read(),b=read();
		e[a].push_back(b);
		e[b].push_back(a);
		if (i==1)
			k1=a,k2=b;
	}
	vis[k1]=vis[k2]=1;
	dfs(k1,a1);
	dfs(k2,a2);
	reverse(a1.begin(),a1.end());
	cout << (int)(a1.size()+a2.size()) << endl;
	for (auto x : a1)
		cout << x << " ";
	for (auto x : a2)
		cout << x << " ";
	return 0;
}

Measured memory_bytes: 9720
import java.util.Scanner;

class Main{
	public static void main(String[] args) 	{
		Scanner sc = new Scanner(System.in);
		int num[];
		int nagasa = sc.nextInt();
		num = new int[nagasa];
		for(int i = 0; i < nagasa ; i++) {
			num[i] = sc.nextInt();
		}
		for(int j = nagasa - 1; j >= 0 ; j--) {
			System.out.printf("%d", num[j]);
			if(j != 0) System.out.printf(" ");
		}
		System.out.printf("\n");
		sc.close();
	}	
}


Measured memory_bytes: 26692
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer(x) cout<<endl<<"answer : "<<x<<endl<<endl;
#define op(x) cout<<x<<endl;
#define maxn 500005
#define lld_max 5000000000000000000
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0,l=0,r=0,mid=0,lo=0,hi=0;string s;bool flag=false;
        cin>>n;
        lld dp[2001]; memset(dp,0,sizeof(dp));
        dp[0]=1; dp[1]=0; dp[2]=0;
        for(i=3;i<=n;i++)
        {
            for(j=0;j<=i-3;j++)
                dp[i]=(dp[i] + dp[j])%mod;
        }
        op(dp[n]);
    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/


Measured memory_bytes: 3676
//long time no ac
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     SPEED       ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	hell        1000000007
#define 	rep(i,n)    for(i=0;i<n;i++)
#define 	repe(i,a,b) for(i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search
#define 	mp          make_pair

ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2);
	if(b%2==0)
		return((c%hell)*(c%hell))%hell;
	return ((((c%hell)*(c%hell))%hell)*(a%hell))%hell;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());



ll ho[100005];
ll he[100005];
int main()
{
	SPEED;
	ll n,k,t,c=0,i,j,m,cs=0;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n;
		// n=s.length();
		ll v[n];
		vll o,e;
		rep(i,n)
		{
			cin>>v[i];
			if(i%2) o.pb(v[i]);
			else e.pb(v[i]);
		}
		rep(i,o.size())
		{
			ho[o[i]]++;
		}
		rep(i,100001)
		{
			if(c<ho[i])
			{
				m=i;
				c=ho[i];
			}
		}
		k=(n/2)-c;
		rep(i,e.size())
		{
			he[e[i]]++;
		}
		rep(i,100001)
		{
			if(cs<he[i])
			{
				j=i;
				cs=he[i];
			}
		}
		// debug3(m,c,j);
		if(m==j)
		{
			ll o1=0,e1=0,oo,ee;
			rep(i,100001)
			{
				if(i==m) continue;
				if(o1<ho[i])
				{
					oo=i;
					o1=ho[i];
				}
			}
			k=(n)-o1-cs;
			// debug3(o1,oo,k);
			rep(i,100001)
			{
				if(i==m) continue;
				if(e1<he[i])
				{
					ee=i;
					e1=he[i];
				}
			}
			k=min(k,n-e1-c);
		}
		else k+=(n/2)-cs;
		cout<<k;
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
ll n,m;
int main(void){
	scanf("%lld%lld",&n,&m);
	if(abs(n-m)>1) printf("0\n");
	else{
		ll ans=1;
		for(int i=2;i<=n;++i) ans*=i, ans-=(ans/modn)*modn;
		for(int i=2;i<=m;++i) ans*=i, ans-=(ans/modn)*modn;
		if(abs(n-m)==0){
			ans*=2, ans-=(ans/modn)*modn;
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(v) for (int i = 0; i < v.size(); i++)
#define SORT(i,v) sort(v.begin(), v.end())
typedef long long ll;
typedef unsigned long long ull;
const ull INF = 1e7;

int main()
{
  string o, e, ans = "";
  cin>>o>>e;

  REP(i,o.size()) {
    ans += o[i];
    if (e.size() == i) break;
    ans += e[i];
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int N,W;
  cin >> N >> W;
  P a[N];
  rep(i,N) cin >> a[i].first >> a[i].second;
  int dp[W+1];
  memset(dp,-1,sizeof(dp));
  dp[0]=0;
  rep(i,N) {
    for(int j=W; j>=0; j--) {
      if(dp[j]!=-1 && j+a[i].second<=W) dp[j+a[i].second]=max(dp[j+a[i].second],dp[j]+a[i].first);
    }
  }
  int ans=0;
  rep(i,W+1) ans=max(ans,dp[i]);
  pr(ans);
  return 0;
}


Measured memory_bytes: 1208
import java.util.*;

public class Main {
  public static void main(String[] args) {
    int i, number_n, number_x, current_point = 0, count = 1;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    number_x = Integer.parseInt(sc.next());
    int[] length = new int[number_n];
    for(i = 0; i < number_n; i++) {
      length[i] = Integer.parseInt(sc.next());
      current_point += length[i];
      if(current_point <= number_x) count++;
      else break;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21844
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        List<Integer> x = new ArrayList<>();
        List<Integer> y = new ArrayList<>();
        List<Integer> h = new ArrayList<>();
        int xx = 0;
        int yy = 0;
        int hh = 0;

        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            int c = Integer.parseInt(sc.next());
            x.add(a);
            y.add(b);
            h.add(c);
            if (c >= 1) {
                xx = a;
                yy = b;
                hh = c;
            }
        }

        // (Cx, Cy) について、(0, 0) から (100, 100) まで全探索
        for (int i = 0; i <= 100; i++) {
            for (int j = 0; j <= 100; j++) {
                boolean ok = true;
                int ch = Math.abs(xx - i) + Math.abs(yy - j) + hh;
                ch = Math.max(ch, 0);
                for (int k = 0; k < n; k++) {
                    int tmp = ch - Math.abs(x.get(k) - i) - Math.abs(y.get(k) - j);
                    tmp = Math.max(tmp, 0);
                    if (tmp != h.get(k)) {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    System.out.printf("%d %d %d\n", i, j, ch);
                }
            }
        }
    }
}


Measured memory_bytes: 23764
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

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

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    m: usize,
    a: [usize; n],
  }
  let sum: usize = a.iter().sum();
  let mut c = 0;
  for &x in &a {
    if x * 4 * m < sum {
      continue;
    }
    c += 1;
  }

  puts!("{}\n", if c >= m {"Yes"} else {"No"});
}


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

using namespace std;

int n;

double a[1010];
int main(){
    while(true){
        cin >> n;
        double m = 0;
        if(n == 0) break;
        memset(a,0,sizeof(a));
        for(int i = 0;i<n;i++){
            scanf("%lf",&a[i]);
        }
        for(int i = 0;i<n;i++){
            m += a[i];
        }
        m/=n;
        double x = 0;
        for(int i = 0;i<n;i++){
            x += ((a[i]-m)*(a[i]-m));
        }
        x = sqrt(x/n);
        printf("%.8f\n",x);
    }
}


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

int main() {
	int a, b, c,i;
	int Count = 0;

	cin >> a >> b >> c;
	if (a <= b) {
		i = a;
		while (1) {
			if (i > b)break;
			if (c % i == 0)Count++;
			i++;
		}
		cout << Count << endl;

		return 0;
	}
	else {
		return 0;
	}
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int a,b,c; cin>>a>>b>>c;
    cout<<min(b/a,c)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    int ans = 0;
    vector<vector<char>> c(h, vector<char>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> c[i][j];
        }
    }

    for (int hi = 0; hi < (1 << h); hi++) {
        for (int wj = 0; wj < (1 << w); wj++) {
            int black = 0;
            for (int i = 0; i < h; i++) {
                if ((1 << i) & hi) continue;
                for (int j = 0; j < w; j++) {
                    if ((1 << j) & wj) continue;
                    if (c[i][j] == '#') black += 1;
                }
            }
            if (black == k) ans += 1;
        }
    }
    cout << ans << endl;
}


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        s: String
    }
    let a = vec![("SUN", 7), ("MON", 6), ("TUE", 5), ("WED", 4), ("THU", 3), ("FRI", 2), ("SAT", 1)];
    let mut answer = 0;
    for i in a {
        if i.0 == s {
            answer = i.1;
        }
    }
    println!("{}", answer);
}


Measured memory_bytes: 4352
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W, A, B = MAP()

for i in range(H-B):
    print("0"*A+"1"*(W-A))
for i in range(B):
    print("1"*A+"0"*(W-A))


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

int main(){
    
    int N;
    cin>>N;
    int quotient = N / 1000;
    if(N % 1000 == 0) cout<<0;
    else 
        cout<<1000*(quotient + 1) - N;
    return 0;
}

Measured memory_bytes: 3624
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let mut tasks = vec![];
    let n: usize = sc.read();
    for _ in 0..n {
        let a: usize = sc.read();
        let b: usize = sc.read();
        tasks.push((b, a));
    }
    tasks.sort();

    let mut cur = 0;
    for (b, a) in tasks.into_iter() {
        cur += a;
        if cur > b {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 9284
n=int(input())
k=0
lst=input().split()
answer=''
lst.reverse()
for i in range(2*n):
    k=i
    if i%2==0:
        answer+=lst[i//2]
    else:
        if k==2*n-1:
            break
        else:
            answer+=' '
print(answer)


Measured memory_bytes: 5592
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// スペース区切りの整数の入力
		int k = sc.nextInt();
        int[] h = new int[n];
		for(int i=0;i<n;i++)
		  h[i] = sc.nextInt();
      
        int count =0;
        for(int i=0;i<n;i++)
          if(h[i]>=k)count++;
		// 出力
		System.out.println(count);
	}
}

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

int main () {
  int N;
  cin >> N;
  vector <int> p(N);
  for(int i = 0; i < N; i++){
    cin >> p.at(i);
  }

  int answer = 0;
  for(int i = 0; i < N; i++){
    if(i + 1 != p.at(i)){
      answer++;
    }
  }

  if(answer == 0 || answer == 2){
    cout << "YES" << endl;
  }

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

Measured memory_bytes: 256
import java.util.*;

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

        int N = sc.nextInt();
        if(N==1){
            System.out.println("Hello World");
        }
        else if(N==2){
            int A = sc.nextInt();
            int B = sc.nextInt();
            System.out.println(A + B);
        }
    }
}

Measured memory_bytes: 21716
/*
問題C：Minimal_Backgammon

・案


*/

#include <iostream>
#include <iomanip>
#include <cstring> 

using namespace std;

int N, T, L, B;
int stop[100], start[100];
double dp[100][101];

double rec(int idx, int tern){
  if(tern > T) return(0.0);
  if(idx == N) return(1.0);
  if(idx > N) return(rec(N + N - idx, tern));
  if(dp[idx][tern] != -1.0) return(dp[idx][tern]); 
  if(start[idx]) return(dp[idx][tern] = rec(0, tern));
  double val = 0.0;
  for(int i = 1; i <= 6; i++) {
    val += rec(idx + i, tern + 1 + stop[idx]) / 6;
  }
  return(dp[idx][tern] = val);
}

int main(){
  while(cin >> N >> T >> L >> B, N) {
    memset(stop, false, sizeof(stop));
    memset(start, false, sizeof(start));
    while(L--) {
      int k;
      cin >> k;
      stop[k] = true;
    }
    while(B--) {
      int k;
      cin >> k;
      start[k] = true;
    }
    fill_n(*dp, 100 * 101, -1.0);
    cout << fixed << setprecision(10) << rec(0, 0) << endl;
  }
}


Measured memory_bytes: 3380
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int x,y;
    cin >> x >> y;
    if(y < 2*x or 4*x < y) {
        Yes(0);
        return 0;
    }
    y -= 2*x;
    Yes(y%2 == 0);
}


Measured memory_bytes: 3668
#include<stdio.h>
#define GROUP_1_MAX 7

typedef struct{
	int iNum;						//番号
	int aiGroup[GROUP_1_MAX];       //整数のグループ

}GROUP_t;

int judge(int aXY, GROUP_t* pstGroup);

int main(void) {
	int x, y;
	int GroupNoX, GroupNoY;
	int n;
	//x,yを入力
	scanf("%d %d",&x,&y);

	//構造体変数の定義
	GROUP_t m_Group[3] = {
		{0,{1,3,5,7,8,10,12}},
		{1,{4,6,9,11}},
		{2,{2}}
	};
			
	//x yの属するグループの比較を行う	
	for (n = 0;n < 3;n++) {
		GroupNoX = judge(x, &m_Group[n]);
		GroupNoY = judge(y, &m_Group[n]);
		//同じグループに属していた場合Yesを表示
		if (GroupNoX == GroupNoY && GroupNoX != -1 && GroupNoY != -1) {
			printf("Yes\n");
			return 0;
		}
		else {}
	}
	//異なるグループに所属していた場合Noを表示
	printf("No\n");

	return 0;
}
/******
*x,yの値がどの整数のグループに属するかを調べる関数
*[in]aXY			入力値であるxまたはyを入れる
*[in]* pstGroup		x,yと比較したい整数のグループの所属する構造体のを入れる
*
*/
int judge(int aXY, GROUP_t* pstGroup) {
	int i=0;
	int max = 0;
	//グループ内の整数の数によって繰り返す最大数を決める
	if (pstGroup->iNum == 0) {
		max = 6;
	}
	else if (pstGroup->iNum == 1) {
		max = 3;
	}
	else if (pstGroup->iNum == 2) {
		max = 0;
	}
	else {}

	/*グループ内の数と比較して一致するものがあればグループの割り当てた番号を返す
	そうでないときは一致無し(-1)を返す*/
	for (i = 0;i <= max;i++) {
		if (aXY == pstGroup->aiGroup[i]) {
			return (pstGroup->iNum);
		}
		else {}
	}
	return(-1);
}

Measured memory_bytes: 2048
IDENTIFICATION DIVISION.
        PROGRAM-ID. ABC150_A.
      
        ENVIRONMENT DIVISION.
      
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 K PIC 9(15).
        01 X PIC 9(15).
        01 TMP PIC 9(15).
        01 INPUT_LINE PIC X(15).
        01 P1 PIC 9 VALUE 1.
        01 P2 PIC 9.
      
        PROCEDURE DIVISION.
      	MAIN.
            ACCEPT INPUT_LINE.
            PERFORM VARYING P2 FROM 1 BY 1
                UNTIL INPUT_LINE(P1 + P2:1) = SPACE
            END-PERFORM
            MOVE INPUT_LINE(P1:P2) TO K
            ADD P2+1 TO P1

            PERFORM VARYING P2 FROM 1 BY 1
                UNTIL INPUT_LINE(P1 + P2:1) = SPACE
            END-PERFORM
            MOVE INPUT_LINE(P1:P2) TO X

            COMPUTE TMP = 500 * K.
      		IF TMP >= X THEN
                DISPLAY "Yes"
            ELSE
                DISPLAY "No"
            END-IF
		STOP RUN.


Measured memory_bytes: 764
//cod2017_qualB_b.cpp
//Sat Nov 10 21:07:59 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	unordered_map<int, int> hash;
	for (int i=0;i<n;i++){
		int temp;
		cin >> temp;
		auto itr = hash.find(temp);
		if (itr != hash.end()){
			hash[temp]++;
		}else {
			hash[temp] = 1;
		}
	}

	int m;
	cin >> m;

	int flag = 0;
	for (int i=0;i<m;i++){
		int temp;
		cin >> temp;
		auto itr = hash.find(temp);
		if (itr != hash.end()){
			if (hash[temp]==0){
				flag = 1;
				break;
			}else {
				hash[temp]--;
			}
		}else {
			flag = 1;
			break;
		}
	}

	if (flag == 1){
		cout << "NO" << endl;
	}else {
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 8520
n=gets.to_i
hs=gets.chomp.split(" ").map(&:to_i);

r=0
hs.each_with_index {|hi, i|
  if i==0
    r+=1
  else
    r+=1 if hs.slice(0,i).all? {|h| h<=hi}
  end
}

print(r)

Measured memory_bytes: 1788
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(ps: Vec<usize>) -> usize {

    if ps.len() == 1 {
        return 0
    }

    let mut qs = vec![0; ps.len()+1];

    for (i, &p) in ps.iter().enumerate() {
        qs[p] = i;
    }

    let mut cnt = 0;
    let mut max_cnt = 0;
    let mut last = 0;
    for &q in qs.iter().skip(1) {
        if q > last {
            cnt += 1;
            if cnt > max_cnt {
                max_cnt = cnt;
            }
        } else {
            cnt = 1;
        }
        last = q;
    }

    ps.len() - max_cnt
}

fn main() {
    let n = parse_line!(usize);

    let ps = (0..n).map(|_| parse_line!(usize)).collect();
    println!("{}", solve(ps));
}

#[test]
fn solve_test() {
    assert_eq!(solve(vec![1,3,2,4]), 2);
    assert_eq!(solve(vec![3,2,5,1,4,6]), 4);
    assert_eq!(solve(vec![6,3,1,2,7,4,8,5]), 5);
    assert_eq!(solve(vec![1]), 0);
}


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

typedef long long ll; 

int main()
{ 
    int n;
    ll ansa=0,ansb=0,suma=0,sumb=0;
    cin>>n;
    
    rep(i,n){
      
      ll c;
      cin>>c;
      suma+=c;
      sumb+=c;
      
      if(i%2==0){
      if(suma<=0){
        ansa+=(1-suma);
        suma=1;
        }
      if(sumb>=0){
        ansb+=(sumb+1);
        sumb=-1;
        }
      }
      else{
      if(suma>=0){
        ansa+=(suma+1);
        suma=-1;
        }
      if(sumb<=0){
        ansb+=(1-sumb);
        sumb=1;
        }
      }
      
      }
      
    cout<<min(ansa,ansb)<<endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険

#define rep(i,l,r)for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r)for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k)for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す
/*
   upll : (a<b)なら-1, (a=b)なら0, (a>b)なら1
 downll : (a<b)なら1, (a=b)なら0, (a>b)なら-1

 const void* a : 型を縛らずにconstをつける(=変数aが読み込み専用の変数であることを明示する)
        (ll*)a : 変数aがconst long long *型であると明示する
*/
// int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
// int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
// void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
// void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

ll dp[310][310];
ll cost[310][310];
void wf(ll n){
    rep(i,0,n) rep(j,0,n) dp[i][j] = cost[i][j];
    rep(k,0,n) rep(i,0,n) rep(j,0,n) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}

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

    rep(i,0,n) rep(j,0,n) cost[i][j] = INF;
    rep(i,0,m){
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        cost[a][b] = cost[b][a] = c;
    }
    wf(n);
    rep(i,0,n) rep(j,0,n) cost[i][j] = dp[i][j] <= l ? 1 : INF;
    wf(n);

    ll q; cin >> q;
    rep(i,0,q){
        ll s, t;
        cin >> s >> t;
        s--; t--;
        cout << (dp[s][t] == INF ? -1 : dp[s][t]-1) << endl;
    }

}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define N int(2e3+100)
#define pb push_back
#define ll long long int
#define pp pair<int,int>
#define pl pair<ll,ll>
#define fi first
#define si second
using namespace std;
int main() {
	ll n,m,r,x,y,i,j,k,sum=0;
	cin>>x>>y>>n>>m>>r;
	ll a[n],b[m],c[r];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	for(ll j=0;j<m;j++){
		cin>>b[j];
	}
	for(ll k=0;k<r;k++){
		cin>>c[k];
	}
	sort(a,a+n);
	sort(b,b+m);
	sort(c,c+r);
	for(ll k=r-1,i=n-x,j=m-y;k>=0;k--){
		if(i<n&&c[k]>a[i]){
			if(j<m&&a[i]>b[j]){
				b[j]=c[k];
				j++;
			}else{
				a[i]=c[k];
				i++;
			}
		}else if(j<m&&c[k]>b[j]){
			if(i<n&&b[j]>a[i]){
				a[i]=c[k];
				i++;
			}else{
				b[j]=c[k];
				j++;
			}
		}
	}
	for(ll i=n-x;i<n;i++){
		sum+=a[i];
	}
	for(ll j=m-y;j<m;j++){
		sum+=b[j];
	}
	cout<<sum<<endl;
    return 0;
}




Measured memory_bytes: 2560
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

	using i8 = std::int_fast8_t;
	using i32 = std::int_fast32_t;
	using i64 = std::int_fast64_t;
	using u8 = std::uint_fast8_t;
	using u32 = std::uint_fast32_t;
	using u64 = std::uint_fast64_t;
	using isize = std::ptrdiff_t;
	using usize = std::size_t;

	constexpr usize operator"" _z(unsigned long long x) noexcept {
		return static_cast<usize>(x);
	}

	class rep {
		const usize f, l;

	public:
		class itr {
			friend rep;
			usize i;
			constexpr itr(const usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { ++i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr rep(const usize first, const usize last) noexcept
			: f(first), l(last) {}
		constexpr itr begin() const noexcept { return itr(f); }
		constexpr itr end() const noexcept { return itr(l); }
	};
	class revrep {
		const usize f, l;

	public:
		class itr {
			friend revrep;
			usize i;
			constexpr itr(usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { --i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
		constexpr itr begin() const noexcept { return itr(l); }
		constexpr itr end() const noexcept { return itr(f); }
	};
	template <class T> using vec_alias = std::vector<T>;
	template <class T> auto md_vec(const usize n, const T& value) {
		return std::vector<T>(n, value);
	}
	template <class... Args> auto md_vec(const usize n, Args... args) {
		return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
	}
	template <class T> constexpr T difference(const T& a, const T& b) {
		return a < b ? b - a : a - b;
	}
	template <class T> T scan() {
		T ret;
		std::cin >> ret;
		return ret;
	}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>

namespace n91 {

	bool solve() {
		usize n;
		std::cin >> n;
		std::vector<u32> h(n);
		for (auto& e : h) {
			std::cin >> e;
		}
		u32 prev = h.back();
		for (const auto i : revrep(0_z, n - 1_z)) {
			if (h[i] > prev + 1) {
				return false;
			}
			else if (h[i] > prev) {
				--h[i];
			}
			prev = h[i];
		}
		return true;
	}

	void main_() { std::cout << (solve() ? "Yes" : "No") << std::endl; }

} // namespace n91

int main() {
	n91::main_();
	return 0;
}


Measured memory_bytes: 1024