akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

template<class In>
void print_array(In begin, In end) {
  cout << (*begin);
  begin++;
  for (; begin != end; begin++)
  {
    cout << " " << (*begin);
  }
  cout << endl;
}

int main()
{
  ll N, K;
  cin >> N >> K;

  ll res;
  if (K == 1)
    res = 0;
  else
    res = N - K;


    cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool qwq[10];
bool truly(int w)
{
	while(w>0)
	{
		if(!qwq[w%10]) return true;
		w/=10;
	}
	return false;
}
int main()
{
	memset(qwq,true,sizeof(qwq));
	int t,k;
	cin>>t>>k;
	for(int i=0;i<k;i++)
	{
		int q;
		cin>>q;
		qwq[q]=false;
	}
	while(truly(t))
	{
		t++;
	}
	cout<<t;
}

Measured memory_bytes: 3628
n = int(input())
while n > 0:
  l = [int(i) for i in input().split()]
  m1 = [0]
  m2 = [0]
  for i in l:
    M1 = max(m1)
    M2 = max(m2)
    if i < M1 and i < M2:
      print('NO')
      break
    elif M1 <= i <= M2:
      m1.append(i)
    elif M2 <= i <= M1:
      m2.append(i)
    elif M2 <= M1 <= i:
      m1.append(i)
    elif M1 <= M2 <= i:
      m2.append(i)
  else:
    print('YES')
  n -= 1

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

void solve() {

}

ll calc(ll L, ll R, ll x) {
  ll v = R / x;
  if( L - 1 >= 0 ) {
    ll w = ( L - 1LL ) / x;
    v -= w;
  }
  return v;
}

int main() {
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll sum = b - ( (a-1>=0) ? (a-1) : 0 );
  sum -= calc(a,b,c);
  sum -= calc(a,b,d);
  sum += calc(a,b,c/__gcd(c,d)*d);
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=y;i>=x;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
//	ios::sync_with_stdio(false);
//	cin.tie(0);
const int maxx = 2e5+7;
const int maxn = 1e9+7;
typedef long long ll;
using namespace std;
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
ll k,n,m;
int main(){
	cin>>k>>n>>m;
	rept(i,0,1000){
		if(i*k>=n&&i*k<=m){
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int p[20];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> p[i];

    int s = 0;
    for (int i = 1; i < n - 1; ++i)
    {
        int a[3] = {p[i], p[i - 1], p[i + 1]};
        sort(a, a + 3);
        if (p[i] == a[1])
            s++;
    }
    cout << s;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#define ll long long 
#include <string>
#define pb push_back
#define mp make_pair
# define pi 3.14159265358979323846
#define mod 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define repk(i,k,n) for(i=k;i<n;i++)
using namespace std;
void fastio()
{
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

}
ll int multiply(ll int a,ll int b)
{
	ll int ans=(a%mod*b%mod)%mod;
	return ans;
}
ll int add(ll int a, ll int b)
{
	ll int ans=(a%mod+b%mod)% mod;
	return ans;
}
ll int l(ll int k)
{
	ll int l=1,r=1e9,ans;
	while(l<=r)
	{
		ll int mid=l+(r-l)/2;
		ll int v=mid*(mid+1)/2;
		if (v>=k)
		{
			ans=mid;
			r=mid-1;
		}
		else
		{
			l=mid+1;
		}
	}
	return ans;

}
 
void solve()
{
	ll int x;cin>>x;
	ll int ans=l(x);
	cout<<ans<<endl;

}

int main()
{ 
	fastio();
    ll int t;
    // cin>>t;
    t=1;
    while(t--)
    {
    	solve();
    }
}

	
		
	
	
	
	





Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
  int n;
  int x;
  int y;
  int s=0;
  cin>>n;
  for(int i=10;i>0;i--){
    x=pow(10,i);
    y=pow(10,i-1);
    x=n/x;
    y=n/y;
    s+=(y-10*x);
  }
  if(n%s==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

int main(){
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> l(N);
    for(int i=0; i<N; i++) cin >> l[i];

    int ans = 1e9;
    for(int i=0; i<pow(4,N); i++){
        int n = i;
        int a = 0, b = 0, c = 0;
        int tmp = 0;
        int bam = 0;
        while(n>0){
            if(n%4==1){
                if(a!=0) tmp+=10;
                a += l[bam];
            }else if(n%4==2){
                if(b!=0) tmp+=10;
                b += l[bam];
            }else if(n%4==3){
                if(c!=0) tmp+=10;
                c += l[bam];
            }
            n/=4;
            bam++;
        }
        if(a==0 || b==0 || c==0) continue;
        tmp += abs(a-A) + abs(b-B) + abs(c-C);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner yomi = new Scanner(System.in);
        int suuzi = yomi.nextInt();
        String mojiretu = yomi.next();
        if (suuzi >= 3200) System.out.println(mojiretu);
        else System.out.println("red");

    }
}


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

int main(){
    vector<string> s(3);
    vector<int> idx(3,0);
    int turn = 0;
    cin >> s[0] >> s[1] >> s[2];
    while(idx[turn] != s[turn].length()){
        int next_turn = s[turn][idx[turn]]-'a';
        idx[turn]++;
        turn = next_turn;
    }
    cout << char('A'+turn)<< endl;
    return 0;
}


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

#define Khaled ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lli long long int
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define FOR(i, n) for (i = 0; i < n; i++)
#define FO(i,k,n) for(i = k; i <= n; i++)
#define ALL(arr) arr.begin(), arr.end()
#define PI acos(-1)
#define MAX 1100106
 
using namespace std;

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<lli> vlli;

void solve()
{
    lli i, j, n, m, q, b, k, x, a, l;
    cin >> n;
    x = 100;
    double carry = 0.0;
    lli res = 0;
    while(x < n) {
        a = x/100;
        x += a;
        carry += (x/100) - (a*1.0);
        // if(carry >= 1) {
        //     carry = carry - 1.0;
        //     x++;
        // }
        res++;
    }
    cout << res << endl;
    return;
}

int main()
{
    Khaled
    // freopen("input", "r", stdin);
    // freopen("output" , "w" , stdout);
    int t = 1,i;
    // cin >> t;
    FO(i,1,t) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#define HAVE_STRUCT_TIMEPSEC
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int a[100007],inv[100007];
int Pow(int p,int q){
    int s=1;
    for(;q;q>>=1,p=1ll*p*p%mod)
        if(q&1) 
            s=1ll*s*p%mod;
    return s;
}
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i) 
        scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<=n;++i) 
        inv[i]=Pow(i,mod-2); 
    long long p=1,ans=a[k];
    for(int i=k+1;i<=n;++i){
         p=p*(i-1)%mod;
         p=p*inv[i-k]%mod;
         ans=(ans+a[i]*p%mod)%mod;
    }
    ans-=a[n-k+1];
    p=1;
    for(int i=k+1;i<=n;++i){
         p=p*(i-1)%mod;
         p=p*inv[i-k]%mod;
         ans=(ans-a[n-i+1]*p%mod)%mod;
    }
    if(ans<0) 
        ans+=mod;
    printf("%d",ans);
}

Measured memory_bytes: 1024
def solve(n, arr):
    d = {}
    for i in range(n):
        d[i] = (0)
    for i in arr:
        d[i-1] += 1
    for v in d.values():
        print(v)

if __name__ == "__main__":
    n = int(input())
    arr = [int(s) for s in list(input().split())]
    solve(n ,arr)

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

namespace add 
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = (a + b);
            int d = (a - b);
            int e = (a * b);

            if (c >= d && c >= e && a >= -1000 && b <= 1000)
            {
                Console.WriteLine("{0}", c);
            }
            else if (d >= c && d >= e && a >= -1000 && b <= 1000)
            {
                Console.WriteLine("{0}", d);
            }
            else if (e >= c && e >= d && a >= -1000 && b <= 1000)
            {
                Console.WriteLine("{0}", e);
            }
            
        }
    }
}

Measured memory_bytes: 13140
//52
#include<iostream>

using namespace std;

#define S(X) ((X)*(X))

int main(){
  int N;
  cin>>N;
  while(N--){
    double x[2],y[2],r[2];
    for(int i=0;i<2;i++){
      cin>>x[i]>>y[i]>>r[i];
    }
    double ds=S(x[0]-x[1])+S(y[0]-y[1]);
    int ans;
    if(r[0]>r[1]&&ds<S(r[0]-r[1])){
      ans=2;
    }else if(r[1]>r[0]&&ds<S(r[1]-r[0])){
      ans=-2;
    }else if(ds<=S(r[0]+r[1])){
      ans=1;
    }else{
      ans=0;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <math.h>
#include <bitset>

#define X first
#define Y second
#define vsort(v) sort(v.begin(), v.end())
#define vrev(v) reverse(v.begin(), v.end())
#define vmax_p(v) max_element(v.begin(), v.end())
#define vmin_p(v) min_element(v.begin(), v.end())
#define vmax_idx(v) distance(v.begin(), vmax_p(v))
#define vmin_idx(v) distance(v.begin(), vmin_p(v))
#define vcopy(src, dst) copy(src.begin(), src.end(), back_inserter(dst))
#define P pair

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

// floor(x): truncate

// 2進数変換
// string s = bitset<20>(x).to_string();

using namespace std;
using ll = long long;

void displayVec(vector<int> v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cout << v[i] << endl;
    }
    cout << endl;
}

int binarySearch(vector<int> v, int target)
{
    int left = -1;
    int right = v.size();

    while (right - left > 1)
    {
        int mid = left + (right - left) / 2;

        if (v[mid] >= target)
        {
            right = mid;
        }
        else
        {
            left = mid;
        }
    }

    if (right < v.size() && v[right] == target)
    {
        return right;
    }
    return -1;
}

int main(int argc, const char *argv[])
{
    int n;
    cin >> n;
    vector<int> v(n * 2);
    for (int i = 0; i < n * 2; i++)
    {
        cin >> v[i];
    }
    vsort(v);

    int sum = 0;
    for (int i = 0; i + 1 < 2 * n; i += 2)
    {
        sum += min(v[i], v[i + 1]);
    }
    cout << sum << endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long

int main(){
  string S, T;
  cin >> S >> T;
  int flag = 0;
  char esc;
  int N = S.length();
  FOR(i, 0, N){
    if(S == T) flag = 1;
    esc = S[N-1];
    FOR(j, 0, N-1) S[N-1-j] = S[N-2-j];
    S[0] = esc;
  }
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;


int main(){
    ll n; cin >> n;
    double x;
    string u;
    double ans=0.0;
    rep(i,n){
        cin >> x >> u;
        if(u == "JPY"){
            ans += x;
        }else{
            ans += x * 380000.0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    bool flag = true;
    ll ans = 0;
    while (flag)
    {
        flag = false;
        rep(i, n)
        {
            if (a[i] >= n)
            {
                flag = true;
                ll cnt = a[i] / n;
                ans += cnt;
                a[i] %= n;
                rep(j, n)
                {
                    if (j == i)
                    {
                        continue;
                    }
                    a[j] += cnt;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();
		double xx = x2 - x1;
		double yy = y2 - y1;
		double xxyy = xx * xx + yy * yy;
		System.out.println(Math.sqrt(xxyy));
	}
}


Measured memory_bytes: 27988
from functools import *
import sys
sys.setrecursionlimit(100000)
import numpy as np

def acinput():
    return list(map(int, input().split(" ")))


X,Y=acinput()


for x in range(0,101):
    for y in range(0,101):
        if x+y==X and 2*x+4*y==Y:            
            print("Yes")
            sys.exit()
            
print("No")


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

int main(){
  int l, r, ml, mr, ans;
  cin >> l >> r;
  
  if(r-l >= 2019 || r % 2019 == 0 || l % 2019 ==0){
    ans = 0;
  }
  else{
    ans = 2019;
    ml = l % 2019;
    mr = r % 2019;
    for(int i = ml; i < mr; i++){
      for(int j = i+1; j <= mr; j++){
        if((i*j) % 2019 < ans){
          ans = (i * j) % 2019;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    int N;
    cin >> N;
    unordered_map <string, int> num;
    long r = 0;
    
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        if (num.find(s) == num.end()) {
            num[s] = 1;
        } else {
            r += num[s];
            num[s]++;
        }
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 10660
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int N;
  cin >> N;
  
  vector<int> a(N);
  for (int i=0; i<N ;i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(),a.end());

  int alice=0;
  int bob=0;
  for (int i=0; i<N;i +=2){
  	alice += a.at(i);
  }
  for (int i=1; i<N; i +=2){
  	bob += a.at(i);
  }
  
  cout << abs(alice-bob) << endl;
  
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define UM unordered_map
#define MP map
#define ST set
#define US unordered_set
#define V vector
#define S string
#define D deque
#define L list
#define Q queue
#define PQ priority_queue
#define DB double
#define LDB long double
#define FOR(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define FFOR(i, n) for (int(i) = 0; (i) <= (n); ++(i))
#define RFOR(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))
#define all(v) (v).begin(), (v).end()

const int dr[] = {0, 1, 0, -1};
const int dc[] = {1, 0, -1, 0};

int nxt()
{
    int n;
    cin >> n;
    return n;
}

LL llnxt()
{
    LL l;
    cin >> l;
    return l;
}

LDB ldbnxt()
{
    LDB n;
    cin >> n;
    return n;
}

DB dbnxt()
{
    DB n;
    cin >> n;
    return n;
}

void bfs(VVI &graph, int start)
{
    int n = graph.size();
    Q<int> q;
    V<bool> visited(n);
    q.push(start);
    visited[start] = true;
    while (not q.empty())
    {
        auto curr = q.front();
        q.pop();
        for (auto i : graph[curr])
        {
            if (not visited[i])
            {
                q.push(i);
                visited[i] = true;
            }
        }
    }
}
bitset<2000010> visited;
VI cycle;
int dfs(VI &v, int node, LL k)
{
    // cout << node << "\n";
    if (k == 0)
    {
        return node;
    }
    if (visited[node])
    {
        cycle.push_back(node);
        return -1;
    }
    visited[node] = true;
    if (int tmp = dfs(v, v[node] - 1, k - 1); tmp != -1)
    {
        return tmp;
    }
    if (cycle.size() and cycle[0] == node)
    {
        return cycle[int(cycle.size()) - 1 - (k - 1) % (LL)(cycle.size())];
    }
    if (cycle.size())
    {
        cycle.push_back(node);
        return -1;
    }
    return INT_MAX;
}

int main()
{
    int n;
    LL k;
    cin >> n >> k;
    VI v(n);
    generate(all(v), nxt);
    cout << dfs(v, 0, k)+1 << "\n";
    // for (auto i : cycle) cout << i << " ";
}

Measured memory_bytes: 9052
n,k=map(int,input().split())

ans=0
for i in range(1,n+1):
  if i>=k:
    ans+=1/n
  else:
    dcnt=0
    while i<k:
      i*=2
      dcnt+=1
    ans+=(1/n)*(2**(-dcnt))
print(ans)

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main(){
    int n,d,ans;
    cin >> n >> d;
    if(n%(2*d+1) != 0){
        ans = (n/(2*d+1))+1;
    }else{
        ans = n/(2*d+1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main()
{
    std::string str;
    std::cin >> str;

    int strLen = str.length();
    bool flag = 0;

    for(int i = 0; i < strLen; i++)
    {
        if((i+1)%2 != 0)
        {
            if(str[i] == 'L')
            {
                flag = 0;
                break;
            }
            else
            {
                flag = 1;
            }
        }
        else
        {
            if(str[i] == 'R')
            {
                flag = 0;
                break;
            }
            else
            {
                flag = 1;
            }
        }

    }

    if(flag == 1)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
def main():
  N, K = map(int, input().split())
  H = list(map(int,input().split()))
  dp = [0]*N
  for i in range(1,N):
    dp[i] = min([dp[j]+abs(H[i]-H[j]) for j in range(max(0,i-K),i)])
  print(dp[-1])

main()

Measured memory_bytes: 13980
# jsc2019-qualB - Kleene Inversion
from collections import Counter
from itertools import accumulate


def main():
    N, K = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))
    MOD = 10 ** 9 + 7
    C = list(Counter(A).values())
    ac = list(accumulate(C[:-1]))
    x = sum(i * j for i, j in zip(C[1:], ac))
    y = 0
    for i, a in enumerate(A[:-1]):
        y += sum(b > a for b in A[i + 1 :])
    ans = (x * (1 + K) * K // 2) % MOD
    ans -= y * K
    ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

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

int main()
{
  int n;
  while (scanf("%d", &n) != EOF) {
    int cnt = 0;
    for (int a = 0; a <= 9; a++) {
      for (int b = 0; b <= min(n - a, 9); b++) {
        for (int c = 0; c <= min(n - a - b, 9); c++) {
          if (0 <= n - a - b - c && n - a - b - c <= 9) cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

struct rlcnt {
  ll id;
  ll rcnt;
  ll lcnt;
};

int main() {
  string s;
  cin >> s;
  vector<rlcnt> d;
  ll rc = 0;
  ll lc = 0;
  bool rl = true;  // true r false l
  rep(i, s.size() - 1) {
    if (s[i] == 'R' && rl) rc++;
    if (s[i] == 'L' && rl) rl = false;
    if (s[i] == 'R' && !rl) {
      rl = true;
      rc = 1;
    }
    if (s[i] == 'R' && s[i + 1] == 'L') {
      rlcnt tmp;
      tmp.id = i;
      tmp.rcnt = rc - 1;
      d.push_back(tmp);
    }
  }
  ll index = 0;
  rep(i, s.size() - 1) {
    if (s[i] == 'L' && s[i + 1] == 'R') {
      d[index].lcnt = i - d[index].id - 1;
      index++;
    }
  }
  d[d.size() - 1].lcnt = s.size() - 1 - d[d.size() - 1].id - 1;

  vector<ll> ans(s.size());
  index = 0;
  rep(i, s.size()) {
    if (i == d[index].id) {
      ans[i] = d[index].rcnt / 2 + d[index].lcnt / 2 + (d[index].lcnt % 2) + 1;
      ans[i + 1] =
          d[index].lcnt / 2 + d[index].rcnt / 2 + (d[index].rcnt % 2) + 1;
      index++;
    }
  }
  // rep(i, d.size()) cout << "(" << d[i].id << ", " << d[i].rcnt << ", "
  //                        << d[i].lcnt << ")"
  //                       << ", ";
  // cout << endl;

  // rep(i, s.size()) cout << ans[i] << ", ";
  // cout << endl;
  rep(i, s.size()) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 5452
//B - Mix Juice


	#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		int n,k;
		cin>>n>>k;
		vi p(n);
		for (int i = 0; i < n; ++i)
		{
			cin>>p[i];
		}
		sort(p.begin(), p.end());
		int ans =0;
		for (int i = 0; i < k; ++i)
		{
			ans = ans+p[i];
		}
		cout<<ans<<endl;
		return 0;
	}


Measured memory_bytes: 3588
from itertools import accumulate
import bisect
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
c = list(accumulate(a))
ans = bisect.bisect_right(c, x)
if not ans:
  print(ans)
else:
  print(ans if c[N - 1] >= x else ans - 1)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n,ans;
string a,b,c;
int main()
{
	cin>>n>>a>>b>>c;
	for(int i=0;i<n;i++)
	{
		if(a[i]==b[i]||a[i]==c[i]||b[i]==c[i])
		{
			if(!(a[i]==b[i]&&b[i]==c[i]))
			{
				ans++;
			}
		}
		else
		{
			ans+=2;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

var isPrime [10000 + 1]bool

func isPrimeInit() {
	for i := 2; i < len(isPrime); i++ {
		isPrime[i] = true
	}
	for i := 2; i*i < int(1e8)+1; i++ {
		for j := i * 2; j < len(isPrime); j += i {
			isPrime[j] = false
		}
	}
}

func main() {
	isPrimeInit()
	var n int
	fmt.Scan(&n)
	set := make(map[int]int, n)
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		set[t]++
	}
	// fmt.Println("n", n, "set", set)
	ans := 0
	for k := range set {
		// fmt.Println("k", k)
		if 1 < k && k < len(isPrime) && isPrime[k] {
			// fmt.Println("d00 - ans k", k)
			ans++
		} else if k != 1 {
			ok := true
			for i := 2; i < len(isPrime); i++ {
				if isPrime[i] && k%i == 0 {
					ok = false
					break
				}
			}
			if ok {
				// fmt.Println("d01 - ans k", k)
				ans++
			}
		}
	}
	fmt.Println(ans)
}



Measured memory_bytes: 2180
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n,sum=0,i,cnt;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cnt=(n/i)*(2*i+(n/i-1)*i)/2;
        //cout<<cnt<<" ";
        sum+=cnt;
    }
    cout<<sum;
    return 0;
}


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

#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define pb push_back

using namespace std;

const ll mod = 1000 * 1000 * 1000 + 7;

ll n, a, b, s[200000], dp[200000][3], f[200000];
set < ll > s1, s2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++) cin >> s[i];
    s[n + 1] = 2e18 + 1;
    for (int i = 1; i <= n; i++){
        if (s[i + 1] - s[i] < a) s2.insert(i);
        if (s[i + 1] - s[i] < b) s1.insert(i);
    }
    for (int i = n; i >= 1; i--){
        int l = i, r = n + 1;
        while (r - l > 1){
            int mid = (r + l) / 2;
            if (s[mid] - s[i] < a) l = mid; else r = mid;
        }
        if (r == i + 1) dp[i][1] = r; else{
            auto it = s1.upper_bound(i);
            if (it != s1.end() && *it < r - 1){
                dp[i][1] = -1;
            } else{
            if (s[r] - s[r - 1] >= b) dp[i][1] = r; else
            dp[i][1] = dp[r - 1][2];
            }
        }
        l = i, r = n + 1;
        while (r - l > 1){
            int mid = (r + l) / 2;
            if (s[mid] - s[i] < b) l = mid; else r = mid;
        }
        if (r == i + 1) dp[i][2] = r; else{
            auto it = s2.upper_bound(i);
            if (it != s2.end() && *it < r - 1){
                dp[i][2] = -1;
            } else{
            if (s[r] - s[r - 1] >= a) dp[i][2] = r; else
            dp[i][2] = dp[r - 1][1];
            }
        }
      //  cout << i << " " << dp[i][1] << " " << dp[i][2] << endl;
    }
  //  cout << endl;
    f[n + 1] = 1;
    for (int i = n; i >= 1; i--){
        if (dp[i][1] != -1) f[i] = (f[dp[i][1]] + f[i]) % mod;
        if (dp[i][2] != -1) f[i] = (f[dp[i][2]] + f[i]) % mod;
    //    cout << f[i] << " " << f[dp[i][1]] << " " << f[dp[i][2]] << endl;
    }
    cout << f[1];
}


Measured memory_bytes: 13568
N = int(input())
table = [[0]*9 for _ in range(9)]
for n in range(1,N+1):
    tail = str(n)[-1]
    if tail == '0':
        continue
    head = str(n)[0]
    table[int(head)-1][int(tail)-1] += 1
ans = 0
# for i in range(9):
#     print(table[i])
for i in range(9):
    for j in range(i+1):
        #print(i,j)
        if i == j:
            temp = table[i][j]*table[j][i]
        else:
            temp = 2*table[i][j] * table[j][i]
        ans += temp

# if N <= 10:
#     print(N+1)
#     exit()
print(ans)

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

int main() {
  float N, X;
  int point;
  
  cin >> N;
  point = 0;
  
  for(int i=0; i < 50000; i++){
    if(N == floor(i * 1.08)){
      X = floor(i);
      point = 1;
      break;
    }
  }
  if(point == 1){
    cout << X << endl;
  }else{
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for a in range(A + 1):
  for b in range(B + 1):
    for c in range(C + 1):
      total = 500 * a + 100 * b + 50 * c
      if total == X:
        count +=1
print(count)

Measured memory_bytes: 3060
n, m, l = map(int, input().split())
a = [[0] * m for i in range(n)]
b = [[0] * l for i in range(m)]
c = [[0] * l for i in range(n)]

for i in range(n):
    list = input().split()
    for j in range(m):
        a[i][j] = int(list[j])
for i in range(m):
    list = input().split()
    for j in range(l):
        b[i][j] = int(list[j])

for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j] += a[i][k] * b[k][j]
        print(c[i][j], end='')
        if j < l-1:
            print(' ', end='')
    print()




Measured memory_bytes: 7136
def selectionSort(A,N):
    cnt=0
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if A[minj]>A[j]:
                minj=j
        if A[i]!=A[minj]:
            A[i],A[minj]=A[minj],A[i]
            cnt+=1
    return A,cnt

N = int(input())
A = list(map(int,input().split()))
A,cnt = selectionSort(A,N)
print(*A)
print(cnt)


Measured memory_bytes: 5604
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using vvll = vector<vll>;
const double EPS = 1e-9;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define SZ(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll MOD=1000000007LL;

ll H,W;
vvll dp;
bool isout( ll y, ll x){
  return y<0 || y>=H || x<0 || x>=W;
}
ll dfs(vector<string> &field, ll y, ll x){
  if(dp[y][x] >= 0) return dp[y][x];
  if(y==H-1&&x==W-1) return 1LL;
  ll cnt=0;
  if(!isout(y+1,x) && field[y+1][x]=='.'){
    cnt+=dfs(field,y+1,x);
    cnt%=MOD;
  }
  if(!isout(y,x+1) && field[y][x+1]=='.'){
    cnt+=dfs(field,y,x+1);
    cnt%=MOD;
  }
  return dp[y][x] = cnt;
}
int main(){
  cin>>H>>W;
  dp.assign(H,vll(W,-1));
  vector<string> field(H);
  rep(i,H){
    string s; cin>>s;
    field[i]=s;
  }
  ll ans=dfs(field,0,0);
  cout<<ans<<endl;
}

Measured memory_bytes: 12560
use proconio::{fastout, input};

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

#[fastout]
fn main() {
    input! {
        a: i64, b: i64, c: i64, x: i64, y: i64,
    }
    let mut ans = a * x + b * y;
    for z in 0..=max(x, y) {
        ans = min(ans, a * max(0, x - z) + b * max(0, y - z) + c * z * 2);
    }
    println!("{}", ans);
}


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

int sum(int n){
  if(n == 0){
    return 0;
  }
  int x = sum(n - 1);
  return x + n;
}

int main() {
  int n;
  cin >> n;
  int ans = sum(n);
  cout << ans <<endl;
}


Measured memory_bytes: 256
import math
a,b,h,m = list(map(int,input().split()))

long_h = (60 * h + m) / 720
short_m = m / 60

angle = abs(long_h - short_m) * 360
if angle > 180:
  angle = 360 - angle

cos_x = math.cos(math.radians(angle))
ans = math.sqrt(a*a + b*b - 2*a*b*cos_x)
print(ans)

Measured memory_bytes: 9420
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std ;
using namespace __gnu_pbds;

template <typename T> // *s.find_by_order(0), s.order_of_key(2) ;
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define reMin(a, b) a = min(a, b)
#define reMax(a, b) a = max(a, b)

#define lint long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define SET(x, val) memset(x, val, sizeof(x))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

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

const int N = 51 ;
const int MOD = 1e9 + 7 ;
const lint INF = 1e18 ;
const int K = 5201 ;
const int OFF = 2600 ;
const int OFF2 = 2500 ;

void _add(lint& x, lint y)
{
    x += y ; x %= MOD ;
}

int n, oddness ;
lint dp1[N][K], dp2[N][K] ;

int main()
{
    fastio; cin >> n >> oddness ; SET(dp2, 0); SET(dp1, 0);
    dp2[0][OFF + oddness] = 1 ;

    for(int i = n; i > 0; i--)
    {
        for(lint j = i-1; j >= 0; j--)
        {
            for(int k = -OFF2; k <= OFF2; k++)
            {
                if(j) _add(dp1[j][OFF + k], j * j * dp2[j - 1][OFF + k + 2*i]);
                _add(dp1[j][OFF + k], j * dp2[j][OFF + k]);
                _add(dp1[j][OFF + k], j * dp2[j][OFF + k]);
                _add(dp1[j][OFF + k], dp2[j + 1][OFF + k - 2*i]);
                _add(dp1[j][OFF + k], dp2[j][OFF +k]);
            }
        }
        for(int j = 0; j < N; j++)
            for(int k = 0; k < K; k++)
                dp2[j][k] = dp1[j][k], dp1[j][k] = 0 ;
    }
    cout << dp2[0][OFF + 0] ;
}



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

using namespace std;

#define endl '\n'

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  int k;
  cin >> k >> s;

  for(int i=0;i<min((int)s.size(),k);i++)
    cout << s[i];

  if(s.size() > k)
    cout << "...";

  cout << endl;
  

  return 0;
}

Measured memory_bytes: 3612
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    const char B = '<';
    const char E = '=';
    const char S = '>';

    char X[2];
    char Y[2];

    if (scanf("%s%s", X, Y) < 2) return 0;

    printf("%c\n", 0 == strcmp(X, Y) ? E : 0 < strcmp(X, Y) ? S : B);
    return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	
	string s; int a, b;
	while (cin >> s >> a >> b) {
		cout << s << " " << a + b << " " << a * 200 + b * 300 << endl;
	}
}


Measured memory_bytes: 3112
import sys
input = sys.stdin.readline
n = int(input())
b = sorted([list(map(int,input().split())) for i in range(n)])
d = {}
for i in range(n):
    for j in range(i+1,n):
        x = (b[j][0]-b[i][0],b[j][1]-b[i][1])
        if x in d:
            d[x]+=1
        else:
            d[x]=1
if n==1:
    print(1)
else:
    print(n-max(d.values()))

Measured memory_bytes: 3188
#d
n,a,b = map(int,input().split())

def power(x, n, mod):
    """
    x**n mod in  O(log n)
    """
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = K * x % mod
            x = x ** 2 % mod
            n = (n - 1) // 2
        else:
            x = x ** 2 % mod
            n = n // 2
    return K * x % mod
 
def nCrMOD(a,b,m):
    c = 1
    for i in range(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = egcd(a, m)
    return inv % m

m=10**9+7

ans = power(2,n,m) -1 - nCrMOD(n,a,m) -nCrMOD(n,b,m)
print(ans%m)

Measured memory_bytes: 40812
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define mod1 998244353 
#define inf 1000000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'




int main()
{
    fastio;
    #ifdef APNA_IO
        start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);    
    #endif

    ll n,x,ans=1;cin>>n>>x;
    ll val=0;
    for(ll i=0;i<n;i++)
    {
        ll a;cin>>a;
        val+=a;
        if(val<=x) ans++;
    }
    cout<<ans;

    #ifdef APNA_IO
        end_routine();  
    #endif
}

Measured memory_bytes: 256
n = int(input())
A = map(int, input().split())

rate = set()
free = 0
for a in A:
    if a < 3200:
        rate.add(a // 400)
    else:
        free += 1

if len(rate) == 0:
    color_min, color_max = 1, n
else:
    color_min, color_max = len(rate), len(rate) + free

print(color_min, color_max)

Measured memory_bytes: 9056
#include<bits/stdc++.h>
using namespace std;
#define  vi vector<long long int>
#define  set1 set<long long int>
#define  pb push_back
#define  map1 map<long long int,long long int>
#define  ll    long long int
#define  mp make_pair
#define  inf 1e17
#define  minf INT_MIN
#define  setbits(x) __builtin_popcountll(x)
#define  pres(x,y) fixed<<setprecision(y)<<x
#define  pair1 pair<long long int,long long int>
#define  mk(arr,n,type) type *arr=new type[n];
#define  mod 1000000007
#define  pi  3.1415926535897932384626433832
#define  ins insert
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//find_by_order() --> returns an iterator to the k-th largest element (counting from zero)
//order_of_key()  --> the number of items in a set that are strictly smaller than our item.
#define  w(t) long long int t;t=1;while(t--)

map<ll, list<ll>> l;

ll dp[100005];

ll dfs(ll src) {

	if (dp[src] != -1) {
		return dp[src];
	}
	ll mx = 0;
	bool leaf = 1;
	for (auto x : l[src]) {
		leaf = 0;
		mx = max(mx, dfs(x));
	}
	if (leaf) {
		return dp[src]=0;
	}
	return dp[src]=1 + mx;

}
void solve() {

	ll n, m;
	cin >> n >> m;
	for (ll i = 0; i < m; i++) {
		ll a, b;
		cin >> a >> b;
		l[a].pb(b);
	}

	ll ans = 0;
	memset(dp, -1, sizeof(dp));
	for (ll i = 1; i <= n; i++) {
		ans = max(ans, dfs(i));
	}
	cout << ans << "\n";


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

Measured memory_bytes: 19340
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define ll long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int ret = 1;
	bool find = false;
	rep(i, n) {
		if (a[i] == ret) {
			ret++;
			find = true;
		}
	}
	if (!find)print(-1);
	else {
		print(n - ret+1);
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll N,A,B;
  cin >> N >> A >> B;
  if((A+B)%2==0)
  {
    cout << (B - A) / 2 << endl;
  }
  else
  {
    cout << min({B-1,N-A,A+((B-A)/2),N-B+1+((B-A)/2)}) << endl;
  }
  return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#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()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> bool chmax(T& t, const U& u) { if (t < u) { t = u; return 1; } return 0; }
template<class T, class U> bool chmin(T& t, const U& u) { if (t > u) { t = u; return 1; } return 0; }

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 int INF = TEN(9);

int main() {
	int N; cin >> N;
	V<int> A;
	A.reserve(N + 2);
	A.pb(0);
	rep(i, N) { int x; cin >> x; A.pb(x); }
	A.pb(0);
	N++;

	int dp0 = 0;
	V<int> pos({0});

	for (int i = 1; i <= N; ++i) {
		V<int> ns({A[i]});
		ns.pb(A[i-1]);
		if (A[i-1] > 0) {
			ns.pb(A[i-1]-1);
		}
		rep(j, pos.size()) {
			ns.pb(pos[j]);
			if (pos[j] > 0) {
				ns.pb(pos[j]-1);
			}
			if (pos[j] + A[i] - A[i-1] > 0) {
				ns.pb(pos[j] + A[i] - A[i-1]);
				ns.pb(pos[j] + A[i] - A[i-1] + 1);
			}
		}
		sort(ALL(ns));
		ns.erase(unique(ALL(ns)), ns.end());
		V<int> dp(ns.size(), INF);

		rep(j, ns.size()) if (ns[j] <= A[i-1]) {
			int p = upper_bound(ALL(pos), ns[j]) - pos.begin() - 1;
			rep(k, ns.size()) if (ns[k] <= A[i]) {
				int val = dp0 - p + (j > k) + (A[i-1] - ns[j] < A[i] - ns[k]);
				chmin(dp[k], val);
			}
		}
		dp0 = dp[0];
		V<int> npos({0});
		for (int j = 1; j < ns.size(); ++j) {
			if (dp[j] != INF && dp[j] != dp[j-1]) {
				npos.pb(ns[j]);
			}
		}
		pos = npos;
		dump(dp0);
		dump(pos);
	}
	cout << dp0 + 1 - pos.size() << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>ii;
typedef pair<int,ii>iii;
typedef vector<int>vi;
vector<vi>adjlist;
vector<iii>edge;
const int N=1e5+5;
int ans[N],lazy[N];
int pa[N],sz[N];
void unionset(int x,int y,int w)
{
    x=pa[x];
    y=pa[y];
    if(sz[x]<sz[y]){
        lazy[y]+=sz[x]*w;
        for(int i=0;i<adjlist[x].size();++i){
            int v=adjlist[x][i];
            pa[v]=y;
            adjlist[y].push_back(v);
            ans[v]+=lazy[x];
            ans[v]+=sz[y]*w;
            ans[v]-=lazy[y];
        }
        sz[y]+=sz[x];
    }
    else{
        lazy[x]+=sz[y]*w;//chu y ko phai cong trc vi co the no da qua may doi chua tru
        for(int i=0;i<adjlist[y].size();++i){
            int v=adjlist[y][i];
            pa[v]=x;
            adjlist[x].push_back(v);
            ans[v]+=lazy[y];
            ans[v]+=sz[x]*w;
            ans[v]-=lazy[x];
        }
        sz[x]+=sz[y];
    }
}
signed main()
{
    int n;
    scanf("%lld",&n);
    adjlist.assign(n+1,vi());
    for(int i=1;i<=n;++i){
        adjlist[i].push_back(i);
        pa[i]=i;
        sz[i]=1;
    }
    for(int i=1;i<n;++i){
        int u,v,w;
        scanf("%lld%lld%d",&u,&v,&w);
        edge.push_back(iii(w,ii(u,v)));
    }
    sort(edge.begin(),edge.end());
    reverse(edge.begin(),edge.end());
    for(int i=0;i<edge.size();++i){
        unionset(edge[i].second.first,edge[i].second.second,edge[i].first);
    }
    int root=0;
    for(int i=1;i<=n;++i)if(pa[i]==i)root=i;
    for(int i=0;i<adjlist[root].size();i++)ans[adjlist[root][i]]+=lazy[root];
    for(int i=1;i<=n;++i)printf("%lld\n",ans[i]);
}


Measured memory_bytes: 20592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

ll divt[10000000];

void make_div(ll n){
    for (ll i = 1; i < n+1;i++){
        for (ll j = i; j < n+1; j+=i)
        {
            divt[j]++;
        }
    }
}
int main()
{
    ll x;
    cin >> x;
    make_div(x);
    ll ans = 0;
    for (ll i = 1; i <= x;i++){
        ans += i * divt[i];
    }
    cout << ans;
}

Measured memory_bytes: 81696
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
  int i,j,cnt;
  int n;
  ll k;
  cin>>n>>k;
  ll a[n],b[n];
  for(i=0;i<n;i++)cin>>a[i]>>b[i];
  vector<pair<ll,ll>> v;
  for(i=0;i<n;i++)v.push_back({a[i],b[i]});
  sort(v.begin(),v.end());
  for(i=0;i<n;i++){
    if(k<=v[i].second){
      cout<<v[i].first;
      return 0;
    }
    k-=v[i].second;
  }
}

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

int main()
{
	int n,count=0;
	while(cin>>n)
	{
		for(int i=0;i<=9;i++)
			for(int j=0;j<=9;j++)
				for(int k=0;k<=9;k++)
					for(int l=0;l<=9;l++)
						if(i+j+k+l==n)
							count++;
	cout<<count<<endl;
	count=0;
	}
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var n = int.Parse(input[0]);
            var m = int.Parse(input[1]);

            var broken = new HashSet<int>();

            for (var i = 0; i < m; i++)
            {
                broken.Add(int.Parse(Console.ReadLine()));
            }

            var step = new int[n + 1];

            step[0] = broken.Contains(0) ? 0 : 1;
            step[1] = broken.Contains(1) ? 0 : 1;

            for (var i = 2; i <= n; i++)
            {
                step[i] = broken.Contains(i) ? 0 : (step[i - 1] + step [i -2]);
                step[i] %= 1000000007;
            }

            Console.WriteLine(step[n]);

        }

        static int getStep(HashSet<int> broken, int[] step, int i)
        {
            return broken.Contains(i) ? 0 : step[i];
        }
    }
}


Measured memory_bytes: 19808