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

int main() {
  string S;
  int64_t K;
  cin >> S >> K;
  for (int i = 0; i < K; i++) {
    if (S.at(i) != '1') {
      cout << S.at(i) << endl;
      break;
    }
    else if (i == K - 1) {
      cout << 1 << endl;
    }
  }
}

Measured memory_bytes: 3624
#include<iostream>
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define rep(i, j) FOR(i, 0, j, 1)
#define rrep(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout<<"##"<<x<<"##"<<endl;
void solve()
{
    int s,w;
cin>>s>>w;
    if(w>=s)
        cout<<"unsafe";
    else
        cout<<"safe";
}

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


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc099a
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            Console.WriteLine(n<1000?"ABC":"ABD");
        }
    }
}


Measured memory_bytes: 11092
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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

	ll H, W;
	cin >> H >> W;

	if (H == 1) co(1);
	else if (W == 1) co(1);
	else co((H * W + 1) / 2);


	Would you please return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n,m,res;
long long k,a[200100],b[200100];
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=m;i++) cin>>b[i];
	for(int i=1;i<=n;i++) a[i]+=a[i-1];
	for(int i=1;i<=m;i++) b[i]+=b[i-1];
	for(int i=0;i<=n;i++){
		if(a[i]>k) break;
		res=max(res,i+(int)(upper_bound(b+1,b+m+1,k-a[i])-b)-1);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 6776
#include<iostream>

using namespace std;

int main(void)
{
	int n;
	int s[100];
	int total = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> s[i];
		total += s[i];
	}

	if (total % 10 != 0) {
		cout << total << endl;
		return(0);
	}

	int min = 101;
	for (int i = 0; i < n; i++) {
		if (s[i] % 10 != 0 && s[i] < min){
			min = s[i];
		}
	}

	if (min != 101) {
		cout << total - min << endl;
	} else {
		cout << "0" << endl;
	}

	return(0);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a[105],n,m,x,cost1,cost2;
bool flag[105];
int main()
{
    scanf("%d%d%d",&n,&m,&x);
    for(int i=1;i<=m;i++)
    {scanf("%d",&a[i]);flag[a[i]]=1;}
    for(int i=x;i>=1;i--)
    {
        if(flag[i])cost1++;
    }
    for(int i=x;i<=n;i++)
    {
        if(flag[i])cost2++;
    }
    printf("%d",min(cost1,cost2));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int read() {
	int ans = 0, flag = 1;
	char ch = getchar();
	while(ch > '9' || ch < '0') {if(ch == '-') flag = - flag; ch = getchar();}
	while(ch >= '0' && ch <= '9') {ans = ans * 10 + ch - '0'; ch = getchar();}
	return ans * flag;
}
const int N = 200010;
const int mod = 924844033;
const int G = 5;
struct Edge {
	int t, n;
}e[N << 1];
int head[N], Etot;

int siz[N];
int cnt[N << 2], invProRev[N << 2], rev[N << 2];
int inv[N], invPro[N], pro[N];
int n;

void addedge(int u, int v) {
	e[++ Etot] = {v, head[u]};
	head[u] = Etot;
}
void dfs(int x, int f) {
	siz[x] = 1;
	for(int i = head[x]; i; i = e[i].n) {
		if(e[i].t == f) continue;
		dfs(e[i].t, x);
		++ cnt[siz[e[i].t]];
		siz[x] += siz[e[i].t];
	}
	if(n - siz[x]) ++ cnt[n - siz[x]];
}
int qpow(int a, int b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = 1ll * ans * a % mod;
		a = 1ll * a * a % mod;
		b >>= 1;
	}
	return ans;
}

void dft(int *a, int n, int f) {
	for(int i = 0; i < n; ++ i)
		if(i < rev[i])
			swap(a[i], a[rev[i]]);
	for(int i = 1; i < n; i <<= 1) {
		int gn = qpow(G, (mod - 1) / (i << 1));
		if(f == - 1) gn = qpow(gn, mod - 2);
		for(int j = 0; j < n; j += (i << 1)) {
			int g = 1, x, y;
			for(int k = 0; k < i; ++ k, g = 1ll * g * gn % mod) {
				x = a[j + k]; y = 1ll * a[i + j + k] * g % mod;
				a[j + k] = (x + y) % mod;
				a[i + j + k] = (x - y + mod) % mod;
			}
		}
	}
	if(f == - 1) {
		int ny = qpow(n, mod - 2);
		for(int i = 0; i < n; ++ i)
			a[i] = 1ll * a[i] * ny % mod;
	}
}
int main() {
	n = read();
	for(int i = 1; i < n; ++ i) {
		int u = read(), v = read();
		addedge(u, v);
		addedge(v, u);
	}
	dfs(1, 0);
	pro[0] = invPro[0] = 1;
	pro[1] = inv[1] = invPro[1] = 1;
	for(int i = 2; i <= n; ++ i) {
		pro[i] = 1ll * pro[i - 1] * i % mod;
		inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
		invPro[i] = 1ll * invPro[i - 1] * inv[i] % mod;
	}

	for(int i = 1; i <= n; ++ i) {
		cnt[i] = 1ll * cnt[i] * pro[i] % mod;
		invProRev[i] = invPro[n - i];
	}
	int nn, l = 0;
	for(nn = 1; nn < 2 * n; nn <<= 1) ++ l;
	for(int i = 1; i < nn; ++ i)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (l - 1));
	dft(cnt, nn, 1); dft(invProRev, nn, 1);
	for(int i = 0; i < nn; ++ i)
		cnt[i] = 1ll * cnt[i] * invProRev[i] % mod;
	dft(cnt, nn, - 1); 
	for(int i = 1; i <= n; ++ i) {
		int sum = 1ll * n * pro[n] % mod * invPro[i] % mod * invPro[n - i] % mod;
		sum = (sum - 1ll * invPro[i] * cnt[n + i] % mod + mod) % mod;
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 26496
import numpy as np
import sys
from typing import Callable, NoReturn


def main() -> NoReturn:
    scan: Callable[[], str] = sys.stdin.readline

    n, k = map(int, scan().rstrip().split())  #type: int, int

    counter: np.ndarray = np.zeros((n, k))

    for i in range(k):
        input()
        for a in map(int, scan().rstrip().split()):
            counter[a - 1][i] += 1

    print(np.sum(counter @ np.ones((k,1)) == 0))


if __name__ == '__main__':
    main()


Measured memory_bytes: 27648
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
i = 0
n = 0
for gift in a:
  n += 1
  x -= gift
  if n < len(a):
    if x < 0:
      break
    else:
      i += 1
  elif n == len(a):
    if x == 0:
      i += 1
    else:
      break


print(i)

Measured memory_bytes: 9060
#include<bits/stdc++.h>
#define MAXN 1000005
using namespace std;
int n,p,ans,head,tail,q[MAXN];
char s[MAXN],t[MAXN];
int main()
{
    scanf("%d%s%s",&n,s+1,t+1);
    if(!strcmp(s+1,t+1))
	{
	    cout<<0<<endl;
		return 0;
	}
    p=n;
    head=1; 
    for(int i=n;i>0;i--)
    {
        if(t[i]==t[i-1]) 
		    continue;
        p=min(p,i);
        while(p and t[i]!=s[p]) 
		    p--;
        if(!p) 
		{
		    cout<<"-1"<<endl;
			return 0;
		}
        while(head<=tail)
        {
            if(q[head]-(tail-head+1)+1>i) 
			       head++;
            else break;
        }
        q[++tail]=p;
        if(i!=p) 
		   ans=max(ans,tail-head+1);
    }
    cout<<ans+1<<endl;
    return 0;
}

Measured memory_bytes: 6144
#include <iostream>

using namespace std;

long int count(long int n, long int x);

int main(){
    long int a, b, x;
    cin >> a >> b >> x;

    cout << count(b, x) - count(a - 1, x) << endl;
}

long int count(long int n, long int x)
{
    //cout << n << endl;
    if (n == -1)
        return 0;
    return (n / x + 1);
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for(int i = m; i < (n); i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p){
    os<<"("<<p.first<<","<<p.second<<")";
    return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v){
    os<<"{";
    rep(i, v.size()){
        if (i) os<<",";
        os<<v[i];
    }
    os<<"}";
    return os;
}

const ll MOD = 998244353;
const int MN = 200010;

// 1-indexed, [1, n]
template<class T>
class BIT{
    T bit[MN];
    int n;
public:
    BIT(){
        n = MN;
        memset(bit, 0, sizeof(bit));
    }
    T sum(int i){
        ++i;
        T s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(int i, T x){
        ++i;
        while(i < n){
            bit[i] += x;
            i += i & -i;
        }
    }
};

int num[MN][4];
ll p2[MN];

void init(){
    p2[0] = 1;
    for(int i = 1; i < MN; ++i) p2[i] = p2[i - 1] * 2 % MOD;
}

int main(){
    
    init();
    int N;
    scanf("%d", &N);
    vector<pii> vec(N);
    vi xs, ys;
    
    rep(i, N){
        int x, y;
        scanf("%d %d", &x, &y);
        vec[i] = mp(x, y);
        xs.pb(x); ys.pb(y);
    }
    
    sort(ALL(xs)); sort(ALL(ys));
    rep(i, N){
        int x = vec[i].fi, y = vec[i].se;
        x = lower_bound(ALL(xs), x) - xs.begin();
        y = lower_bound(ALL(ys), y) - ys.begin();
        vec[i] = mp(x, y);
    }
    
    sort(ALL(vec));
    rep(t, 2){
        BIT<int> T;
        rep(i, N) {
            int a = T.sum(vec[i].se - 1), b = i - T.sum(vec[i].se);
            if(t == 0){
                num[i][0] = a;
                num[i][1] = b;
            }else{
                num[N - 1 - i][2] = a;
                num[N - 1 - i][3] = b;
            }
            T.add(vec[i].se, 1);
        }
        reverse(ALL(vec));
    }
    
    ll ans = 0;
    rep(i, N) {
        ll a = (p2[num[i][0]] + p2[num[i][3]] - 1) % MOD;
        ll b = (p2[num[i][1]] + p2[num[i][2]] - 1) % MOD;
        ll v = (p2[N] - a * b) % MOD;
        if (v < 0) v += MOD;
        ans = (ans + v) % MOD;
    }
    
    printf("%llu", ans);
    return 0;
}

Measured memory_bytes: 9068
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) A[i] = scanner.nextInt();

    if (possible(N, A)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }

  private static boolean possible(int N, int[] A) {
    long sum = 0;
    for (int i = 0; i < N; i++) sum += A[i];
    long NS = (long) N * (N + 1) / 2;
    if (sum % NS != 0) return false;
    long K = sum / NS;
    long count = 0;
    for (int i = 0; i < N; i++) {
      int j = i == 0 ? N - 1 : i - 1;
      long d = K - (A[i] - A[j]);
      if (d < 0 || d % N != 0) return false;
      count += d / N;
    }
    return count == K;
  }
}


Measured memory_bytes: 50200
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

class ArtPoint
{
public:
  int nv, ne;
  vector<bool> visited;
  vector<vector<int>> adj;
  vector<int> lowest;
  vector<int> prenum;
  vector<int> parent;
  ArtPoint(){}
  ArtPoint( int v, int e ) : nv(v), ne(e), visited(v, false), adj(v), lowest(v), prenum(v), parent(v){}
  void setAdj();
  void solve();
  int dfs( int u, int pa, int &pn );
};

void ArtPoint::setAdj()
{
  for ( auto i = 0; i < ne; ++i )
    {
      int s, t;
      cin >> s >> t;

      adj[s].push_back( t );
      adj[t].push_back( s );
    }
}

int ArtPoint::dfs( int u, int pa, int &pn )
{
  visited[u] = true;
  parent[u] = pa;
  prenum[u] = pn++;
  lowest[u] = prenum[u];
  int n = adj[u].size();
  
  for ( auto i = 0; i < n; ++i )
    {
      int v = adj[u][i];
      if ( ! visited[v] )
        {
          int cl = dfs( v, u, pn );
          lowest[u] = min( lowest[u], cl );
        }
      else
        if ( v != parent[u] )
          lowest[u] = min( lowest[u], prenum[v] );
    }
  return lowest[u];
}

void ArtPoint::solve()
{
  
  set<int> ret;
  int pn = 0;
  int root = 0;
  
  setAdj();

  dfs( root, -1, pn );
  
  int pc = 0;
  
  for ( auto i = 0; i < nv; ++i )
    {
      if ( i == root  ) continue;
      if ( parent[i] == root )
        ++pc;
      else
        {
          if ( prenum[parent[i]] <= lowest[i] )
            ret.insert( parent[i] );
        }
    }

  if ( pc > 1 ) ret.insert( root );
  
  for ( auto it = ret.begin(); it != ret.end(); ++it )
    cout << *it << endl;
}

int main()
{
  int nv, ne;
  cin >> nv >> ne;
  
  if ( nv == 1 ) return 0;

  ArtPoint ap( nv, ne );
  
  ap.solve();

  return 0;
}

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

#define ll long long
#define ar array

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

	string s;
	cin >> s;

	// sort(s.begin(), s.end());
	if (s[2] == s[3] && s[4] == s[5])
		cout << "Yes";
    else
		cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	for (int i = k; i < n; i++) {
		if (a[i] > a[i - k]) {
			cout << "Yes\n";
		} else {
			cout << "No\n";
		}
	}
}

Measured memory_bytes: 3560
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b;
    cin >> a >> b;
    int res = b;
    if (a >= 13) {
        res = b;
    } else if (a >= 6) {
        res = b / 2;
    } else {
        res = 0;
    }

    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 256
a = [int(c) for c in input().split()]
N = a[0]
M = a[1]
C = a[2]
B = [int(c) for c in input().split()]
A = [list(map(int,input().split())) for c in range(N)]

result = []

for i in range(N):
    cnt = C
    for j in range(M):
        cnt += A[i][j]*B[j]
    
    if cnt > 0:
        result.append(1)
    else:
        result.append(0)

print(sum(result))

Measured memory_bytes: 9108
<?php
  $tmp = explode(" ",trim(fgets(STDIN)));
  $h = $tmp[0];
  $n = $tmp[1];
 
  $sum = array_sum(explode(" ",trim(fgets(STDIN))));
 
  if($sum>=$h){
    echo "Yes\n";
  }else{
    echo "No\n";
  }

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

ll gcd(int x,int y){
  if (y==0){
    return x;
  }
  else{
    return gcd(y,x%y);
  }
}

int main(){
  ll n;
  cin>>n;
  vector<ll> v(n),x(n);
  rep(i,n){
    cin>>v.at(i);
    x.at(i) = v.at(i);
  }
  sort(v.begin(),v.end());
  ll big = v.at(n/2),small = v.at(n/2-1);
  rep(i,n){
    if (x.at(i) <= small){
      cout << big << endl;
    }
    else if (big <= x.at(i)){
      cout << small << endl;
    }
  }
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B){
    int answer = 0, cnt = 0;
    ll l=-1, r=-1, sum=0;
    rep(i,0,N) {
        if (sum + A[i] > K) break;
        sum += A[i];
        cnt++;
        l = i;
    }
    rep(i,0,M) {
        if (sum + B[i] > K) break;
        sum += B[i];
        cnt++;
        r = i;
    }
    answer = cnt;
    rrep(i,0,l+1) {
        sum -= A[i];
        cnt--;
        while (true) {
            if (r>=M-1 || sum + B[r+1] > K) break;
            r++;
            sum += B[r];
            cnt++;
        }
        answer = max(answer, cnt);
    }
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&B[i]);
    }
    solve(N, M, K, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 6424
n = int(input())
red = []
blue = []
for _ in range(n):
    red.append(list(map(int, input().split())))
for _ in range(n):
    blue.append(list(map(int, input().split())))

# 赤はy座標が大きい順に取っていくので、yで降順
red.sort(key=lambda x: x[1], reverse=True)
# 青はx座標が小さい順に探していくので、xで昇順
blue.sort()

pair_count = 0
for i in range(n):
    for j in range(len(red)):
        if red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:
            pair_count += 1
            red.pop(j)
            break

print(pair_count)

Measured memory_bytes: 3064
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>
using namespace std;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	vector<int> v(n);
	for(auto &x : v){
		cin>>x;
	}
	int cnt = 1;
	for(int i=0;i<n;i++){
		if(v[i] == cnt){
			cnt++;
		}
	}
	if(cnt == 1){
		cout<<-1;
		return 0;
	}
	cout<<(n-cnt+1);
	return 0;
}
//.........

Measured memory_bytes: 1792
#define scanf_s scanf
//#define sscanf_s sscanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 11
#define HO 6
int main(void)
{
	int n;
	while (1) {
		scanf_s("%d", &n);
		if (n == 0) break;
		int date[MAX][MAX] = { 0 };
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				scanf_s("%d", &date[i][j]);
				date[i][n] += date[i][j];
				date[n][j] += date[i][j];
				date[n][n] += date[i][j];
			}
		}
		for (int i = 0; i <= n; ++i) {
			for (int j = 0; j <= n; ++j) {
				printf("%5d", date[i][j]);
			}
			printf("\n");
		}
		
	}
}

Measured memory_bytes: 1200
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

struct item
{
	int kind, value;
	item()
	{
		kind = 0;
		value = 0;
	}
};

int main()
{
	//X = roulette_num, Y = box_num, Z = event_num
	int X, Y, Z;
	while(cin >> X >> Y >> Z, X)
	{
		int R[4];
		item F[51];
		double dp[51][5001];
		for(int i = 0; i < X; i++)
		{
			cin >> R[i];
		}
		int a, b, c;
		for(int i = 0; i < Z; i++)
		{
			cin >> a >> b >> c;
			
			F[a].kind = b; F[a].value = c;
		}
		double prob = 1.0/X;
		memset(dp, 0, sizeof(dp)); 
		dp[0][0] = 1.0;
		for(int i = 0; i < Y; i++)
		{
			for(int j = 0; j < 5001; j++)
			{
				if(dp[i][j] == 0)
				{
					continue;
				}
				for(int k = 0; k < X; k++)
				{
					int next = i+R[k];
					if(next > Y)
					{
						next = Y;
					}
					if(F[next].kind == 0)
					{
						dp[next][j] += dp[i][j]*prob;
					}
					else if(F[next].kind == 1)
					{
						next += F[next].value;
						if(next > Y)
						{
							next = Y;
						}
						dp[next][j] += dp[i][j]*prob;
					}
					else if(F[next].kind == 2)
					{
						int next_val = j+F[next].value;
						dp[next][next_val] += dp[i][j]*prob;
					}
					else if(F[next].kind == 3)
					{
						int next_val = j-F[next].value;
						if(next_val < 0)
						{
							next_val = 0;
						}
						dp[next][next_val] += dp[i][j]*prob;
					}
				}
			}
		}

		double res = 0;
		for(int i = 0; i < 5001; i++)
		{
			res += dp[Y][i]*i;
		}

		cout << int(res) << endl;

	}
}

Measured memory_bytes: 3160
#pragma GCC optimize ("03")
#pragma GCC target("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
 
#define sz(x) (ll)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define nl "\n"
 
const int mod=10e7+7;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	char r, g, b;
	cin >> r >> g >> b;
	string s;
	s+=char(r);
	s+=char(g);
	s+=char(b);
	if(stoll(s)%4==0) {
		cout << "YES";
	}else {
		cout << "NO";
	}
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        boolean easy = true;
        for(int i=0; i<s.length(); i++) {
            char c = s.charAt(i);
            if(
                    (i%2==0&&c=='L')
                    || (i%2==1&&c=='R')
            ) {
                easy = false;
                break;
            }
        }
        System.out.println(easy ? "Yes" : "No");
    }
}


Measured memory_bytes: 23764
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef int64_t i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
//

#pragma endregion

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if(a + b >= 10) cout << "error" << endl;
	else cout << a + b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
    int n[100], x[100], i, a, b, c, count[100];

    for (i = 0; i < 100; i++) {
        scanf("%d %d", &n[i], &x[i]);
        if (n[i] == 0 && x[i] == 0) 
            break;
    }
   
    for (i = 0; i < 100 ; i++) {
        if (n[i] == 0 && x[i] == 0) 
            break;
        count[i] = 0;
        for (a = 1; a <= n[i]; a++) {
            for (b = a + 1; b <= n[i]; b++) {
                for (c = b + 1; c <= n[i]; c++) {
                    if (a + b + c == x[i])
                        count[i] += 1;
                }
            }
        }
    }

    for (i = 0; i < 100 ; i++) {
        if (n[i] == 0 && x[i] == 0) 
            break;
        printf("%d\n", count[i]);
    }

    return 0;
}

Measured memory_bytes: 600
mod = 998244353
n, a, b, k = map(int, input().split())
ans = 0
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
fa = [1] * (n + 1)
fi = [1] * (n + 1)
for i in range(1, n + 1):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
for i in range(n + 1):
    x = k - a * i
    if x >= 0 and x % b == 0:
        j = x // b
        if j <= n:
            ans += comb(n, i) * comb(n, j)
            ans %= mod
print(ans % mod)

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

int main(){
    while(1){
        int n, m;
        cin >> n >> m;

        if(n + m == 0)  break;

        vector<int> p[n+1];
        int x, y;
        for(int i = 0; i < m; i++){
            cin >> x >> y;
            p[x].push_back(y);
            p[y].push_back(x);
        }

        set<int> bef, after;
        for(int i = 0; i < p[1].size(); i++){
            bef.insert(p[1][i]);
        }
        for(int x : bef){
            for(int i = 0; i < p[x].size(); i++){
                after.insert(p[x][i]);
            }
        }
        for(int x : bef)    after.insert(x);
        after.insert(1);
        
        cout << after.size()-1 << endl;
    }
    return 0;
}


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

typedef unsigned long long ull;

ull effect[64];
void init(){
	for(int i=0;i<64;i++){
		int y=i/8,x=i%8;
		ull m=0;
		for(int j=-3;j<=3;j++){
			if(0<=y+j&&y+j<8)m |= 1ull<<(8*(y+j)+x);
			if(0<=x+j&&x+j<8)m |= 1ull<<(8*y+x+j);
		}
		effect[i]=m;
	}
}
int bitCount(ull x){
	x = (x>>1 & 0x5555555555555555ULL)+(x & 0x5555555555555555ULL);
	x = (x>>2 & 0x3333333333333333ULL)+(x & 0x3333333333333333ULL);
	x = (x>>4 & 0x0f0f0f0f0f0f0f0fULL)+(x & 0x0f0f0f0f0f0f0f0fULL);
	x = (x>>8 & 0x00ff00ff00ff00ffULL)+(x & 0x00ff00ff00ff00ffULL);
	x = (x>>16 & 0x0000ffff0000ffffULL)+(x & 0x0000ffff0000ffffULL);
	return ((int)(x>>32)+((int)x & 0xffffffff));
}
ull simulate(ull b,int y,int x){
	ull e=effect[8*y+x];
	while(e){
		ull hit = b&e;
		b &= ~hit;
		e=0;
		while(hit){
			e |= effect[bitCount((hit&-hit)-1)];
			hit &= hit-1;
		}
	}
	return b;
}
int main(){
	init();
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		ull b=0;
		for(int j=0;j<8;j++){
			for(int k=0;k<8;k++){
				char ch;
				cin>>ch;
				if(ch=='1')b|=1ull<<(8*j+k);
			}
			cin.ignore();
		}
		int x,y;
		cin>>x>>y;
		b = simulate(b,y-1,x-1);
		cout<<"Data "<<i<<':'<<endl;
		for(int j=0;j<8;j++){
			for(int k=0;k<8;k++){
				cout<<(b>>8*j+k&1);
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
n = int(input())

ls = list(map(int,input().split()))

def f(n,ls):
  if not ls[0] == 0: return 0
  ls = sorted(ls)
  mod = 998244353
  arr = [0]*(ls[-1]+1)
  
  for i in range(n):
    arr[ls[i]] += 1
  if arr[0] >1: return 0
  ans = 1
  for i in range(1,len(arr)):
    
    if arr[i] == 0:
      return 0
    ans *= arr[i-1]**arr[i]
  return ans%mod

print(f(n,ls))

Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  LL n; cin>>n;
  LL su = 0;
  for1(i,n){
  	if(i%3==0 && i%5==0) continue;
  	if(i%3==0) continue;

  	if(i%5==0) continue;
  	su+=i;
  }
  cout<<su<<endl;
  return 0;
}

Measured memory_bytes: 3652
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
void Dufaux()
{
    ll n,m;
    cin>>n>>m;
    pll a[200],b[200];
    for(int i=0;i<n;i++){
        cin>>a[i].ff>>a[i].ss;
    }
    for(int i=0;i<m;i++){
        cin>>b[i].ff>>b[i].ss;
    }
    for(int i=0;i<n;i++){
        ll mini=INT_MAX,idx=-1;
        for(int j=0;j<m;j++){
            ll distance=abs(a[i].ff-b[j].ff)+abs(a[i].ss-b[j].ss);
            if(distance<mini){
                mini=distance;
                idx=j;
            }
        }
        cout<<idx+1<<endl;
    }
    return;
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






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

int r[200005];

int main(){
  ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
  int n; cin >> n;
  for(int i = 1; i <= n ; i++){
      int tmp; cin >> tmp;
      r[tmp] = i;
  }
  for(int i = 1 ; i <= n ; i++){
    cout << 30000*i << ' ';
  }
  cout << '\n';
  for(int i = 1 ; i <= n ; i++){
    cout << 30000*(n-i)+r[i] << ' '; 
  }

}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

    int ans = 0;
    for (int i = 1; i < N + 1; i += 2)
    {
        int cnt = 0;
        for (int j = 1; j < N + 1; j += 2)
        {
            if (i % j == 0)
            {
                cnt++;
            }
        }
        if (cnt == 8)
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int n;
int data[13];
int sum;
vector<int> path;

bool solve(int t){
  if(t == n) return true;
  for(int i=0;i<13;i++){
    if(data[i] == 0) continue;
    if(sum % (i+1) != 0) continue;
    sum -= (i+1);
    data[i]--;
    if(solve(t+1)){
      path.push_back(i+1);
      return true;
    }
    data[i]++;
    sum += (i+1);
  }
  return false;
}

main(){
  while(cin >> n && n){
    fill(data, data+13, 0);
    sum = 0;
    path.clear();
    for(int i=0;i<n;i++){
      int in;
      cin >> in;
      data[in-1]++;
      sum += in;
    }
    if(solve(0)){
      cout << path[0];
      for(int i=1;i<path.size();i++){
        cout << ' ' << path[i];
      }
      cout << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 908
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
template <typename T> using rheap = priority_queue<T>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

i32  n;
i64 a[300000];
i64 t[300000][2];

i32 main()
{
	cin >> n;
	times(3*n, i) {
		cin >> a[i];
	}

	{
		heap<i64> m;
		i64 acc = 0, sumv = 0;
		times(n, i) {
			m.push(a[i]);
			sumv += a[i];
		}
		upto(n, 2 * n, c) {
			t[c][0] = sumv - acc;
			m.push(a[c]);
			acc += m.top();
			m.pop();
			sumv += a[c];
		}
	}
	{
		rheap<i64> m;
		i64 acc = 0, sumv = 0;
		range(2*n, 3*n, i) {
			m.push(a[i]);
			sumv += a[i];
		}
		downto(2*n, n, c) {
			t[c][1] = sumv - acc;
			m.push(a[c-1]);
			acc += m.top();
			m.pop();
			sumv += a[c-1];
		}
	}

	i64 ans = LLONG_MIN;
	upto(n, 2 * n, c) {
		ans = max(ans, t[c][0] - t[c][1]);
	}

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


Measured memory_bytes: 7540
def count(S, val):
    ret = 0
    for i in range(0, len(S)):
        if S[i] != val:
            ret = ret + 1
        if val == '0':
            val = '1'
        else:
            val = '0'
    return ret
  
def main():
    S = input()
    print(min(count(S,'0'),count(S,'1')))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N;
	cin>>N;
	int sum = 0;
	vector<int> pos(N+2,0);
	REP(i,N){
		int a;
		cin>>a;
		pos[i] = a;
		sum += abs(a-pos[i-1]);
	}
	sum += abs(pos[N]);
	REP(i,N){
		int rest = abs(pos[i+1]-pos[i]) + abs(pos[i]-pos[i-1]) - abs(pos[i+1]-pos[i-1]);
		cout<<sum-rest<<endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        int m, p, q, r;
        cin >> m >> p >> q >> r;

        vector<pair<int, int> > card;
        card.push_back(make_pair(1, r));

        while(--m >= 0){
            int x, y;
            cin >> x >> y;

            vector<pair<int, int> > nextCard;
            for(unsigned i=0; i<card.size(); ++i){
                int a, b;
                a = card[i].first;
                b = min(card[i].second, x);
                if(a <= b)
                    nextCard.push_back(make_pair(n-x+a, n-x+b));

                a = max(card[i].first, x+1);
                b = min(card[i].second, y);
                if(a <= b)
                    nextCard.push_back(make_pair(n-x-y+a, n-x-y+b));

                a = max(card[i].first, y+1);
                b = card[i].second;
                if(a <= b)
                    nextCard.push_back(make_pair(-y+a, -y+b));
            }

            card.swap(nextCard);
        }

        int ret = 0;
        for(unsigned i=0; i<card.size(); ++i){
            int a = max(card[i].first, p);
            int b = min(card[i].second, q);
            ret += max(b - a + 1, 0);
        }
        cout << ret << endl;
    }
}

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

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;
constexpr ll mod = 1e9+7;

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

    ll D, G;
    cin>>D>>G;
    vector<pair<ll, ll>> PC(D);
    for (int d = 0; d < D; d++) cin>>PC[d].first>>PC[d].second;

    ll ans = inf;
    for (int n = 0; n < (1<<D); n++) {
        ll maxp = 0;
        ll sum = 0;
        ll point = 0;
        for (int d = 0; d < D; d++) {
            if (n & (1<<d)) {
                sum += PC[D-d-1].first;
                point += PC[D-d-1].second + 100*(D-d)*PC[D-d-1].first;
            } else maxp = max(maxp, D-d-1);
        }
        if (G <= point + 100*(maxp+1) * PC[maxp].first) {
            if (G <= point) ans = min(ans, sum);
            else ans = min(ans, sum + (ll)ceil((double)(G-point)/100/(maxp+1)));
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())

print(a[k-1])

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var s = ReadLine();
        var ss = ReadLine();
        if(s == ss.Substring(0, ss.Length - 1))
            WriteLine("Yes");
        else
            WriteLine("No");
    }
}


Measured memory_bytes: 17364
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<62)-1
#define MAX 1000000000
signed main(){
    int N,K; cin>>N>>K;
    vi A(N+1);
    REP(i,1,N) cin>>A[i];
    int dp[N+1][K+1][K+1]={0};
    REP(i,1,N){
        REP(j,0,(min(i,K))){
            REP(k,1,j) dp[i][j][k]=dp[i-1][j-1][k-1];
            if(j<i){
                dp[i][j][0]=INF;
                if(j<i-1){
                    REP(k,0,j){
                        dp[i][j][0]=min(dp[i][j][0],dp[i-1][j][k]+max(0ll,A[i]-A[i-1-k]));
                    }
                }
                else dp[i][j][0]=dp[i-1][j][j]+A[i];
            }
        }
    }
    int ans=INF;
    REP(i,0,K) ans=min(ans,dp[N][K][i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 212608
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()


int main() {
  long long int n, ans = 0;
 
  scanf("%lld", &n);
 
  vector<long long int> a(3 * n);
 
  for (int i = 0; i < 3 * n; i++)
  {
    scanf("%lld", &a[i]);
}
    sort(a.begin(), a.end(), greater<int>());
 
  for (int i = 0; i < n; i++)
  {
    ans += a[2 * i + 1];
  }
 
  printf("%lld", ans);
}



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


def solve(s: str, K: int):
    pq = []
    for i, c in enumerate(s):
        heapq.heappush(pq, (c, i))

    ret = set()
    while len(ret) < K:
        cs, i = heapq.heappop(pq)
        ret.add(cs)
        if i < (len(s) - 1):
            heapq.heappush(pq, (cs + s[i+1], i+1))
    ret = sorted(list(ret))
    print(ret[K-1])


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  vector<int> num, point;
  int now = 0;
  char d = 'R';
  rep(i, n){
    if (s[i] == d) now++;
    else {
      num.push_back(now);
      if (d == 'R') point.push_back(i-1);
      d = s[i];
      now = 1;
    }
  }
  num.push_back(now);
  point.push_back(-1);
  
  int x = 0;
  rep(i, n){
    if (i != point[x]) cout << 0;
    else{
      int a = (num[x*2] + 1) / 2 + num[x*2+1] / 2;
      int b = num[x*2] / 2 + (num[x*2+1] + 1) / 2;
      cout << a << ' ' << b;
      x++;
      i++;
    }
    if (i == n-1) cout << endl;
    else cout << ' ';
  }
  
  return 0;
}

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

int main(){
	int a, b, c;
	cin>>a>>b>>c;

	if(a > b) swap(a, b);
	if(b > c) swap(b, c);
	if(a > b) swap(a, b);

	cout<<a<<" "<<b<<" "<<c<<endl;

	return 0;

	}


Measured memory_bytes: 3088
#include<stdlib.h>
#include<string>
#include <iostream>
using namespace std;
int main() {

    string a;
    cin >> a;
    //a = "AAA";
    bool aflag = false;
    bool bflag = false;
    for (int i = 0; i <= 2; i++) {
        if (a[i] == 'A') { aflag = true; }
        if (a[i] == 'B') { bflag = true; }
    }
    if (aflag and bflag) { printf("Yes"); }
    else { printf("No"); }

}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e9+7;
ll dp[260][20005];

signed
main(){
	int N,M;
	while(cin >> N >> M)
	{
		if(N==0) break;
		for(int i=0;i<260;i++)
			for(int j=0;j<20005;j++)
				dp[i][j] = INF;
		
		vector<int> c(M);
		for(int i=0;i<M;i++) cin >> c[i];
		
		dp[128][0] = 0;
		for(int i=0;i<N;i++)
		{
			int x;
			cin >> x;
			for(int k=0;k<256;k++)
			{
				if(dp[k][i]==INF) continue;
				for(int j=0;j<M;j++)
				{
					int tmp = k+c[j];
					if(tmp >= 255) tmp = 255;
					else if(tmp < 0) tmp = 0;
					dp[tmp][i+1] = min( dp[tmp][i+1], dp[k][i]+(tmp-x)*(tmp-x) );
				}

			}
		}
		int ans = INF;
		for(int k=0;k<256;k++)
			if(ans > dp[k][N])
				ans = dp[k][N];

		cout << ans << endl;
	}
}


Measured memory_bytes: 43728
#include <iostream>

using namespace std;

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

	int a[n];

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

	for (int j = (n -1); j >= 0; j--){
             if(j == 0)
cout << a[j] << endl;
else
cout << a[j] << " ";

}

	return 0;
} 


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// *st.find_by_order(index), 0-based
// order_of_key(e)

const int mod=1e9+7;

const int mx=2007;

int binom[mx][mx];

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	for (int i=0; i<mx; i++) {
		binom[i][0]=binom[i][i]=1;
		for (int j=1; j<i; j++)
			binom[i][j]=(binom[i-1][j]+binom[i-1][j-1])%mod;
	}	
	int S; cin>>S;
	ll ret=0;
	for (int k=1; 2*k+1<=S; k++)
		ret=(ret+binom[S-2*k-1][k-1])%mod;
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 17464
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

long long N;
vector<long long> a;

int main()
{
    cin >> N;
    long long ans = 0;
    a.resize(3 * N);
    for (int i = 0; i < 3 * N; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < N;i++)
    {
        ans += a[3 * N - 1 - 1 - 2 * i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
acount = 0
bcount = 0
ccount = 0

x, y = input().split()

for i in range(0, 7):
    if int(x) == a[i] or int(y) == a[i]:
        acount += 1

for i in range(0, 4):
    if int(x) == b[i] or int(y) == b[i]:
        bcount += 1

if int(x) == c[0]:
    ccount += 1
if int(y) == c[0]:
    ccount += 1


if acount == 2 or bcount == 2 or ccount == 2:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 9140
a, b, c, k = map(int, input().split())

ans = 0
if k <= a:
    ans = k
    k = 0
else:
    ans = ans + a
    k = k - a

if k > 0 and k <= b:
    k = 0
else:
    k = k - b

if k > 0:
    ans = ans + k*(-1)

print(ans)


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

int a[1000001];
int dp[1000001];
int it;

int fr(int p){
	if (p==it-1){
      return 0;
    }
	if(dp[p]!=-1){
      return dp[p];
    }
	int re=abs(a[p]-a[p+1])+fr(p+1);
	if(p!=it-2){
      re=min(re,abs(a[p]-a[p+2])+fr(p+2));
    }
	return dp[p]=re;
}
int main(){
	cin>>it;
	for(int i=0;i<it;i++){
    cin>>a[i];
    }

	memset(dp,-1,sizeof dp);
	cout<<fr(0)<<endl;
	return 0;
}


Measured memory_bytes: 9472