akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<cctype>
#include <fstream>
#include <time.h>
#include <iterator>





#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define fil(x,y) memset(x,y,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 500000;

int W, H;
int p[100010], q[100010];
vector<P>v;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> W >> H;
	v.resize(W + H );
	REP(i, W) {
		int x; cin >> x;
		v[i] = { x,0 };
	}
	REP(j, H) {
		int y; cin >> y;
		v[j + W] = { y,1 };
	}
	int ans = 0;
	VSORT(v);
	int X = W, Y = H;
	REP(i, H + W) {
		if (v[i].second == 0) {
			ans += v[i].first*(Y + 1);
			X--;
		}
		else {
			ans += v[i].first*(X + 1);
			Y--;
		}
	}
	print(ans);
}

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

int main()
{
	while (true)
	{
		int n, x;
		cin >> n >> x;
		if (n == 0 && x == 0) break;
		int ans = 0;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j < i; j++)
				for (int k = 1; k < j; k++)
					if (i + j + k == x) ans++;
		cout << ans << endl;
	}
}


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

using namespace std;
#define ll long long
const long double EPS = 1e-8;
const long double PI = acos(-1);
const int N = 3000 + 9;
ll mem[N][N];
int n, m;
string s1, s2;
const ll inf = 1e14 + 7LL;

ll solve(int i = 0, int j = 0) {
    if (i == n || j == m)return 0;
    if (~mem[i][j])return mem[i][j];
    if (s1[i] == s2[j])return mem[i][j] = solve(i + 1, j + 1) + 1;
    return mem[i][j] = max(solve(i + 1, j), solve(i, j + 1));
}

void print(int i = 0, int j = 0) {
    if (i == n || j == m)return;
    if (s1[i] == s2[j])cout << s1[i], print(i + 1, j + 1);
    else if (mem[i][j] == solve(i + 1, j))print(i + 1, j);
    else print(i, j + 1);
}

int main() {
    cin >> s1 >> s2;
    n = s1.size();
    m = s2.size();
    memset(mem, -1, sizeof mem);
    solve();
    print();
}


Measured memory_bytes: 71296
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;
typedef long long ll;


// %% begin matrix %%

typedef vector<int> vec;
typedef vector<vec> mat;

void pretty_print(mat g) {
  rep (i, g.size()) {
    rep (j, g[0].size()-1) {
      cout << g[i][j] << ' ';
    }
    cout << g[i][g[0].size()-1] << endl;
  }
}


mat mul(mat A, mat B) {
  mat C(A.size(), vec(B.size()));
  rep (i, A.size()) {
    rep (k, B.size()) {
      rep (j, B[0].size()) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }
  return C;
}

// %% end matrix %%


int main() {

  ll a, b, c;
  cin >> a >> b >> c;

  ll ans = 1001001001;
  
  if (a % 2 == 0 or b % 2 == 0 or c % 2 == 0) {
    ans = 0;
  }
  else {
    // ans = min(ans, a*b);
    // ans = min(ans, b*c);
    // ans = min(ans, c*a);
    ans = min({a*b,b*c,c*a});
  }

  cout << ans << endl;
}


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

int main () {
  long long a,b,c,d;
  cin >> a >> b >> c >> d;
  vector <long long> num(4);
  num.at(0) = a*c;
  num.at(1) = a*d;
  num.at(2) = b*c;
  num.at(3) = b*d;
  sort(num.begin(), num.end());
  cout << num.at(3) << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>

using namespace std;

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

    vector<bool> exists(x + 200, false);
    exists[0] = true;

    for (int i = 0; i <= x; i++) {
        if (exists[i]) {
            exists[i + 100] = true;
            exists[i + 101] = true;
            exists[i + 102] = true;
            exists[i + 103] = true;
            exists[i + 104] = true;
            exists[i + 105] = true;
        }
    }

    cout << (exists[x] ? "1" : "0") << endl;
}


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

const int mod = 1e9+7;

int n;
vector<int> node[100005];
vector<pair<long long, long long>> dp;
vector<bool> visited;

long long dfs(int cur, long long &w, long long &b)
{
    visited[cur] = true;
    for(auto v : node[cur]) {
        long long w1, b1, x;
        if(!visited[v]){
            x = dfs(v, w1, b1);
            dp[cur].first *= x;
            dp[cur].first %= mod;
            dp[cur].second *= w1;
            dp[cur].second %= mod;
        }
    }
    w = dp[cur].first;
    return (dp[cur].first + dp[cur].second)%mod;
}

int main()
{
    scanf("%d", &n);
    dp = vector<pair<long long, long long>>(n+1, {1, 1});
    visited = vector<bool>(n+1, false);
    for(int i = 0; i < n-1; i++){
        int x, y;
        scanf("%d%d", &x, &y);
        node[x].push_back(y);
        node[y].push_back(x);
    }
    long long w, b;
    printf("%lld\n", dfs(1, w, b));
}


Measured memory_bytes: 17168
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef string str;
typedef std::pair<ll,ll> pl;
typedef std::map<string, ll> msl;
typedef std::map<ll, ll> mll;
typedef std::vector<ll> vl;
const long double EPS = 1e-9;
 
#define rep(i, n) for(ll (i) = 0; (i) < (n) ; (i)++ )
#define For(i, a, b) for(ll (i) = (a); (i) < (b) ; (i)++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tol(c) char((c)+0x20)
#define tou(c) char((c)-0x20)
#define pb push_back
#define mp make_pair
#define pr(a) cout << (a)
#define prl(a) cout << (a) << endl
#define prl2(a,b) cout << (a) << " " << (b) << endl
#define prs(a) cout << (a) << " "
#define yn(condition) if ((condition)) prl("Yes"); else prl("No");
#define YN(condition) if ((condition)) prl("YES"); else prl("NO");
#define rpr(i,n,ans) rep((i),(n)) prs((ans[(i)]))
#define cpr(i,n,ans) rep((i),(n)) prl((ans[(i)]))
#define in1(a) cin >> (a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define rin1(i,n,a) rep((i),(n)) cin >> (a[(i)])
#define rin2(i,n,a,b) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)])
#define rin3(i,n,a,b,c) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)]) >> (c[(i)])
#define e1 first
#define e2 second
#define ctol(c) ll((c)) - ll('0')
#define ltos(n) to_string((n))
#define items(kv, v) for(auto &(kv): (v))
#define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)]))
#define beto(a,b,c) (a) < (b) && (b) < (c)
#define betc(a,b,c) (a) <= (b) && (b) <= (c)
#define rsort(a,n) sort(a,a+n,greater<>())
 
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
const ll MAX_N = 100;
 
int main(void){
    ll a,b;
    str s,op;

    in3(a,op,b);
    if (op[0] == '+') prl(a+b);
    else prl(a-b);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int i, n, min, max;
    long long int sum;
    min = 1000000;
    max = -1000000;
    sum = 0;
    scanf("%d", &n);

    for(i=0;i<n;i++) {

        int tmp;
        scanf("%d", &tmp);

        if(tmp < min) {
            min = tmp;
        }

        if(max < tmp) {
            max = tmp;
        }

        sum = sum + tmp;

    }

    printf("%d %d %lld\n", min, max, sum);

    return(0);
}



Measured memory_bytes: 2112
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b){
		a = b;
		return true;
	}
	return false;
}

const long long INF = 1LL << 60;


long long h[100010];

long long dp[100100];

int main() {
	int N;
	cin >> N;
	int K;
	cin >> K;
	for (int i = 0; i < N; i++) cin >> h[i];
	for (int i = 0; i < 100100; i++) dp[i] = INF;
	dp[0] = 0;

	for (int i = 0;i < N;i++) {
		for (int j = 1;j <=K;j++) {
			chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}

	}

	cout << dp[N - 1] << endl;

}

Measured memory_bytes: 1792
N = int(input())
a = list(map(int, input().split())) 

import fractions

#最小公倍数
ans = a[0]
for i in range(1, N):
    ans = ans * a[i] // fractions.gcd(ans, a[i])


res = ans
denominator = 0

for i in range(N):
    denominator += ans/a[i]

print(res/denominator)

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

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

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

    int minv = INT_MAX;
    int maxv = INT_MIN;
    rep(i, n){
        int value; cin >> value;
        if(value - minv > maxv){
            maxv = value - minv;
        }
        if(value < minv){
            minv = value;
        }
    }
    cout << maxv << endl;
}



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

s=list(input())

memo_ss = ['S','S']
memo_sw = ['S','W']
memo_ws = ['W','S']
memo_ww = ['W','W']

def check(memo_ss):
    for i in range(1,n):
        if s[i] == 'o' :
            if memo_ss[i] == 'S':
                if memo_ss[i-1] == 'S':
                    memo_ss.append('S')
                elif memo_ss[i-1] == 'W':
                    memo_ss.append('W')
            elif memo_ss[i] == 'W':
                if memo_ss[i-1] == 'S':
                    memo_ss.append('W')
                elif memo_ss[i-1] == 'W':
                    memo_ss.append('S')
        elif s[i] == 'x' :
            if memo_ss[i] == 'S':
                if memo_ss[i-1] == 'S':
                    memo_ss.append('W')
                elif memo_ss[i-1] == 'W':
                    memo_ss.append('S')
            elif memo_ss[i] == 'W':
                if memo_ss[i-1] == 'S':
                    memo_ss.append('S')
                elif memo_ss[i-1] == 'W':
                    memo_ss.append('W')
    return memo_ss

memo_ss = check(memo_ss)
memo_sw = check(memo_sw)
memo_ws = check(memo_ws)
memo_ww = check(memo_ww)

for memo in [memo_ss,memo_sw,memo_ws,memo_ww]:
    if memo[0] == memo[-1]:
        if s[0] == 'o':
            if memo[0] == 'S' and memo[1] == memo[n-1]:
                print(''.join(map(str,memo[:n])))
                exit()
            elif memo[0] == 'W' and memo[1] != memo[n-1]:
                print(''.join(map(str,memo[:n])))
                exit()
        elif s[0] == 'x':
                if memo[0] == 'S' and memo[1] != memo[n-1]:
                    print(''.join(map(str,memo[:n])))
                    exit()
                elif memo[0] == 'W' and memo[1] == memo[n-1]:
                    print(''.join(map(str,memo[:n])))
                    exit()
print(-1)

Measured memory_bytes: 110840
import java.util.*;

public class Main {
    static int[] values;
    static int[] prevs;
    static long[] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        prevs = new int[n];
        PriorityQueue<Area> queue = new PriorityQueue<>();
        for (int i = 0; i < m; i++) {
            queue.add(new Area(sc.nextInt() - 1, sc.nextInt() - 1));
        }
        for (int i = 0; i < n; i++) {
            while (queue.size() > 0 && queue.peek().right < i) {
                queue.poll();
            }
            if (queue.size() == 0 || queue.peek().left > i) {
                prevs[i] = i - 1;
            } else {
                prevs[i] = queue.peek().left - 1;
            }
        }
        dp = new long[n];
        Arrays.fill(dp, Long.MIN_VALUE);
        for (int i = 0; i < n; i++) {
            dfw(i);
        }
        System.out.println(dfw(n - 1));
     }
     
     static long dfw(int idx) {
         if (idx < 0) {
             return 0;
         }
         if (dp[idx] >= 0) {
             return dp[idx];
         }
         return dp[idx] = Math.max(dfw(idx - 1), dfw(prevs[idx]) + values[idx]);
     }
     
     static class Area implements Comparable<Area> {
         int left;
         int right;
         
         public Area(int left, int right) {
             this.left = left;
             this.right = right;
         }
         
         public int compareTo(Area another) {
             return left - another.left;
         }
     }
}


Measured memory_bytes: 171656
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()

int main(){
    int N, K;
    cin >> N >> K;
    double ans = 0;
    for(int i = 1; i <= N; i++){
        double prob = 1.0/N;
        for(int k = i; k < K; k = k * 2){
            prob = prob / 2;
        }
        ans += prob;
    }
    cout << setprecision(11) << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int MAXN = 1e5 + 5;
const int MOD = 1e9+7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}

int N;
int A[MAXN];
int ans[MAXN];

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];

    for (int i = 0; i < N; i++) 
        ans[0] += (i%2==0) ? A[i] : -A[i];

    for (int i = 1; i < N; i++) 
        ans[i] = A[i-1]*2-ans[i-1];
    
    for (int i = 0; i < N; i++) cout << ans[i] << ' ';
    cout << endl;
    
    return 0;
}


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

using namespace std;

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main(void){
    long long k;
    cin >> k;
    long long ans = 0;
    
    for (int a = 1; a <= k; a++){
        for (int b = 1; b <= k; b++){
            for (int c = 1; c <= k; c++){
                long long temp = GCD(b,c);
                ans += GCD(a,temp);
            }
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3652
import unittest


class TestA(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(3, 3), 'Yes')

    def test_2(self):
        self.assertEqual(think(3, 2), 'No')


def solve():
    n, m = read()
    result = think(n, m)
    write(result)


def read():
    return read_int(2)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, m):
    if n == m:
        return 'Yes'
    return 'No'


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 51056
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<lol, lol>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int x, y;
  cin >> x >> y;
  cout << abs(x, y) << '\n';
  return 0;
}



Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,h;
    cin>>n>>h;
    vector<ll> a(n),b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    sort(begin(a),end(a),greater<ll>());
    sort(begin(b),end(b),greater<ll>());
    vector<ll> sum(n+1,0);
    rep(i,n) sum[i+1]=sum[i]+b[i];
    ll ans=inf,ma=a[0];
    rep(i,n+1){
        ll now=i,ret=h-sum[i];
        if(ret>0) now+=(ret+ma-1)/ma;
        chmin(ans,now);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5548
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
	long r,d,x;
	cin>>r>>d>>x;
	for(int i=0;i<10;i++)
	{
		x=r*x-d;
		cout<<x<<endl;
	}
	return 0;
}


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

#define HAS_TEST_CASE 0

namespace rG{

typedef long long ll;

const int N=5e5;

int n,m,k,a[N+10];
char s[N+10];

inline void main(){
	ll a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	if(a>c)std::swap(a,c),std::swap(b,d);
	printf("%lld\n",std::max(std::max(a*d,a*c),std::max(b*c,b*d)));
}

} // namespace rG

int main(){
#if defined(LOCAL)&&HAS_TEST_CASE
	freopen("tmp.out","w",stdout);
#endif
#if HAS_TEST_CASE
	int T;
	scanf("%d",&T);
	while(T--)rG::main();
#else
	rG::main();
#endif
	return 0;
}


Measured memory_bytes: 3824
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from bisect import bisect_left

N = I()
a = III()

d = defaultdict(list)
for i in range(N):
    d[a[i]].append(i)

now = 0
ans = N
for i in range(1,N+1):
    p = bisect_left(d[i], now)
    if p<=len(d[i])-1:
        now = d[i][p]
        ans -= 1
    else:
        if i==1:
            print(-1)
            exit()
        break

print(ans)

Measured memory_bytes: 106076
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int s = sc.nextInt() - 1;
		int t = sc.nextInt() - 1;
		int[] damage = new int[n];
		for (int i=0;i<n;i++) {
			damage[i] = sc.nextInt();
		}
		ArrayList<ArrayList<Integer>> magic = new ArrayList<ArrayList<Integer>>();
		for (int i=0;i<n;i++) {
			ArrayList<Integer> lst = new ArrayList<Integer>();
			magic.add(lst);
		}
		for (int i=0;i<m;i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			magic.get(a).add(b);
		}
		int[] dist = new int[n];
		for (int i=0;i<n;i++) {
			dist[i] = Integer.MAX_VALUE;
		}
		PriorityQueue<Node> que = new PriorityQueue<Node>();
		for (int i=0;i<=s;i++){
			que.add(new Node(0, i));
			dist[i] = 0;
		}
		int limit = s + 1;
		while (!que.isEmpty()) {
			Node node = que.poll();
			if (node.id == t) {
				System.out.println(node.cost);
				break;
			}
			ArrayList<Integer> lst = magic.get(node.id);
			for (int to: lst) {
				if (node.cost + damage[to] < dist[to]) {
					dist[to] = node.cost + damage[to];
					que.add(new Node(node.cost + damage[to], to));
				}
			}
			for (int i=limit;i<node.id;i++) {
				if (dist[i] > node.cost) {
					dist[i] = node.cost;
					que.add(new Node(node.cost, i));
				}
			}
			if (limit < node.id) limit = node.id;
		}
	}
}
class Node implements Comparable<Node> {
	int cost, id;
	Node (int cost, int id) {
		this.cost = cost;
		this.id = id;
	}
	public int compareTo(Node node) {
		return Integer.compare(cost, node.cost);
	}
}


Measured memory_bytes: 114136
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 n = ReadLine().Split().Select(long.Parse).ToArray();
        WriteLine(Max(Max(n[0] * n[2], n[0] * n[3]), Max(n[1] * n[2], n[1] * n[3])));
	}
}


Measured memory_bytes: 19056
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define lol long long
#define in(n,s) insert(n,s)//ノート参照
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
int gcd(int x,int y){//最大公約数
  if(y>x) swap(x,y);
  int r=x%y;
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }
  return y;
}
int Lcm(int x,int y){//最小公倍数
  int t=x*y;
  return t/gcd(x,y);
}
priority_queue<int> i[300000];
bool ma[100],ma2[100];
lol a,b,c,d,g,h;
bool can(int n,int m){
  if(n<0) return false;
  if(m<0) return false;
  if(n>=a) return false;
  if(m>=b) return false;
  return true;
}
int dfs(int n,int m){
  if(n==g&&m==h) return true;
  //if(i[n][m]!=i[c][d]||!can(n,m)||ii[n][m]) return false;
  //ii[n][m]=true;
  return dfs(n+1,m)+dfs(n,m+1)+dfs(n-1,m)+dfs(n,m-1);
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long e=0,f=0,j=1;
  string w,p;
  cin >>w;
  for(int n=0;n<w.size();n++){
    int o;
    if(w[n]=='1') o=9;
    else o=1;
    f=f*10,f+=o;
  }
  cout <<f<<'\n';
  return (0);
}


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

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

	int a;
	cin >> a;

	long sum;
	int min, max;

	sum = a;
	min = a;
	max = a;

	while (--n) {
		cin >> a;

		sum += a;
		if (a < min) min = a;
		if (max < a) max = a;
	}

	cout << min << ' ' << max << ' ' << sum << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define loINF (long)10000000000
#define shINF (short)10000
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define DEBUG

int main(void){
	short N;
	short F[105][15];
	long P[105][15];
	long i,k;
	short j;
	long count,tmp_ans;
	long long ans;

	scanf("%hd",&N);

	REP(i,N){
		REP(j,10){
			scanf("%hd",&F[i][j]);
		}
	}

	REP(i,N){
		REP(j,11){
			scanf("%ld",&P[i][j]);
		}
	}
	count = 0;
	tmp_ans = 0;
	ans = -10000000000000;

	FOR(i,1,1<<10){
		REP(k,N){
			REP(j,10){
				if ((F[k][j]) & (i >> j))
					count += 1;
			}
			tmp_ans += P[k][count];
			count = 0;
		}

		if (ans < tmp_ans){
			ans = tmp_ans;
		}
		tmp_ans = 0;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
import random

random.seed(1)

def calc_point(point_list, interval, choice):
    point = 0

    for i, day in enumerate(interval):
        point -= c[i] * day

    point += point_list[choice - 1]

    return point

d = int(input())

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

s = []

for _ in range(d):
    temp = list(map(int,input().split()))

    s.append(temp)

choices = [(i % 26) + 1 for i in range(d)]

interval = [0] * 26
result = 0

for i in range(d):
    choice = choices[i]

    interval = [x + 1 for x in interval]

    interval[choice - 1] = 0

    result += calc_point(s[i], interval, choice)

for _ in range(10000):
    temp_choices = choices.copy()
    temp_result = 0

    temp_choices[random.randint(0, d - 1)] = random.randint(1, 26)

    interval = [0] * 26
    
    for i in range(d):
        choice = temp_choices[i]

        interval = [x + 1 for x in interval]

        interval[choice - 1] = 0

        temp_result += calc_point(s[i], interval, choice)

    if temp_result > result:
        choices = temp_choices
        result = temp_result

for choice in choices:
    print(choice)


Measured memory_bytes: 88792
import math
A,B,H,M = map(int,input().split())

theta_l = 2 * math.pi * M /60
theta_s = 2 * math.pi * (H/12 + M/720)
theta = theta_l - theta_s

l = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta))
print(l)

Measured memory_bytes: 9448
//
// Created on 2020/01/12.
//

#include <istream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

const int MAX = 510000;//nCkのn,kの取りうるMAX
const int MOD = 1000000007;



//階乗のテーブルを作る
void COM_initialize(vector<long long>& fac,vector<long long >& finv,vector<long long>& inv){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2 ; i < MAX ; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD -inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

//二項係数計算,nCkのn,kを引数として渡す
long long COM(int n, int k,vector<long long>& fac,vector<long long >& finv,vector<long long>& inv){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD)% MOD;
}

int main() {

    int n;
    int k;
    cin>>n>>k;
    vector<ll>A_array(n);
    for (int i = 0; i < n; ++i) {
        cin>>A_array[i];
    }
    sort(all(A_array));
    vector<long long> fac(MAX);
    vector<long long> finv(MAX);
    vector<long long> inv(MAX);
    COM_initialize(fac,finv,inv);
    ll sum_max = 0;
    for (int j = 0; j < n; ++j) {
        sum_max += COM(j,k-1,fac,finv,inv)*A_array[j]%MOD;
    }

    ll sum_min = 0;
    reverse(all(A_array));
    for (int j = 0; j < n; ++j) {
        sum_min += COM(j,k-1,fac,finv,inv)*A_array[j]%MOD;
    }

    ll ans;
    ans = sum_max  - sum_min;
    cout<<ans%MOD<<endl;
}


Measured memory_bytes: 13056
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int a[100000];
int b[100000];

int main() {
    int n, ans = 0, i;
    long long sum1 = 0, sum2 = 0, sum = 0;
    vector <int> v;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    for (i = 0; i < n; i++) scanf("%d", &b[i]);
    
    for (i = 0; i < n; i++) {
        sum1 += a[i];
        sum2 += b[i];
        if (a[i] < b[i]) {
            sum += b[i] - a[i];
            ans++;
        } else {
            v.push_back(a[i] - b[i]);
        }
    }
    
    if (sum1 < sum2) {
        puts("-1");
        
        return 0;
    }
    
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    
    for (i = 0; i < v.size() && sum > 0; i++) {
        sum -= v[i];
        ans++;
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 1660
n,m=map(int,input().split())
AdjacencyMatrix=[[0]*n for i in [0]*n]
for i in [0]*m:
  a,b=map(int,input().split())
  AdjacencyMatrix[a-1][b-1]=1
  AdjacencyMatrix[b-1][a-1]=1
#print(AdjacencyMatrix)

def DFS(point,TFlist):
#  print(TFlist)
  if not False in TFlist:
    return 1
  ans=0
  for i in range(n):
    if not AdjacencyMatrix[point][i]:
      continue  #AMの0なら処理せず
    if TFlist[i]:
      continue  #探索済みなら処理せず
    TFlist[i]=True #探索したのでTFlistをTrue
    ans+=DFS(i,TFlist) #再帰的にansを加算
    TFlist[i]=False #枝を戻すためにTFlistをFalse
  return ans

TFlist=[True]+[False]*(n-1)
print(DFS(0,TFlist))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

struct Segmenttree {
	static const int N = 1 << 18;
	vector<ll>seg;
	vector<ll>idx;
	void st(ll p, ll v) {
		p += N - 1;
		seg[p] = v;
		idx[p] = p - N + 1;
		while (p > 0) {
			p = (p - 1) / 2;
			seg[p] = max(seg[2 * p + 1], seg[2 * p + 2]);
			if (seg[2 * p + 1] < seg[2 * p + 2])idx[p] = idx[2 * p + 2];
			else if (seg[2 * p + 1] > seg[2 * p + 2])idx[p] = idx[2 * p + 1];
			else idx[p] = min(idx[2 * p + 1], idx[2 * p + 2]);
		}
	}
	pair<ll, ll> query(ll l, ll r, ll a, ll b, ll k) {
		if (r <= a || b <= l)return { -inf,inf };
		if (l <= a && b <= r)return { seg[k],idx[k] };
		ll m = (a + b) / 2;
		auto p1 = query(l, r, a, m, 2 * k + 1);
		auto p2 = query(l, r, m, b, 2 * k + 2);
		if (p1.first > p2.first) return p1;
		else if (p1.first < p2.first)return p2;
		else return { p1.first,min(p1.second,p2.second) };
	}

	void init() {
		seg.resize(2 * N);
		idx.resize(2 * N);
		for (int i = 0; i < 2 * N; i++)seg[i] = -inf;
	}
	//[l,r]
	ll get(int l, int r) {
		return query(l, r + 1, 0, N, 0).first;
	}
	ll getidx(int l, int r) {
		return query(l, r + 1, 0, N, 0).second;
	}
	pair<ll, ll>getp(int l, int r) {
		return query(l, r + 1, 0, N, 0);
	}
};

int N;
vector<pair<ll, ll>>v;

ll calc(ll r, ll l) {
	if (r < l)return 0;
	else return r - l + 1;
}

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

	cin >> N;
	for (int i = 0; i < N; i++) {
		ll L, R;
		cin >> L >> R;
		v.pb({R,L});
	}
	sort(all(v));

	Segmenttree seg = Segmenttree();
	seg.init();
	for (int i = 0; i < N; i++)seg.st(i,v[i].second);

	ll ans = 0;
	for (int i = 1; i < N;i++) {
		ll r1 = v[0].first;
		ll r2 = v[i].first;
		ll maA = seg.get(0, i - 1);
		ll maB = v[i].second;
		ll maC = seg.get(i + 1, N - 1);
		ll temp;

		if (i < N - 1)temp = max(calc(r1,max(maC,maA)) + calc(r2,maB),calc(r1,maA) + calc(r2,max(maB,maC)));
		else temp = calc(r1,maA) + calc(r2,maB);
		ans = max(ans,temp);
	}
	puts(ans);

	return 0;
}

Measured memory_bytes: 10096
(let ((a (read))
      (b (read))
      (c (read))
      (k (read))
      )
  (declare (ignore c))
  (format t "~A~%"
          (cond ((>= a k) k)
                ((>= (+ a b) k) a)
                (t (+ a a b (- k))))))

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*
*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

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

  int ans = 0;
  ans = (a+b-1)/b;
  cout << ans << endl;

  return 0;
}


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

int N;
long long T;
long long t[200010];
long long ans = 0;

int main()
{
    scanf("%d%lld",&N,&T);
    for(int i = 0; i < N; i++)scanf("%lld",t + i);
    for(int i = 0; i < N - 1; i++)ans += min(t[i + 1] - t[i],T);
    printf("%lld\n",ans + T);
    return 0;
}


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

bool is_valid(int num, const vector<bool> & NGs){
    while (num){
        if (NGs[num % 10]) return false;
        num /= 10;
    }
    return true;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<bool> NGs(N, false);
    for (int i = 0; i != K; ++i) {
        int d;
        cin >> d;
        NGs[d] = true;
    }
    int ans = N;
    while (not is_valid(ans, NGs)) ++ans;
    cout << ans << endl;
    return 0;
}

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


a = [0]*n

for i in range(n-1):
    if lis[i] < lis[i+1]:
        a[i+1] = 1
    elif lis[i] == lis[i+1]:
        a[i+1] = a[i]
    else:
        a[i+1] = -1


mon = 1000
kabu = 0

for i in range(n-1):
    if a[i+1] > a[i]:
        kabu = mon // lis[i]
        mon = mon % lis[i]
    elif a[i+1] < a[i]:
        mon += kabu * lis[i]
        kabu = 0

if kabu != 0:
    mon += kabu * lis[-1]

print(mon)



Measured memory_bytes: 9224
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	string s;
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';
	cout << s << endl;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */


int main(){
    double a,b,h,m; cin>>a>>b>>h>>m;
    h = (h+m/60)*M_PI/6;
    m *= M_PI/30;
    double t = abs(h-m);
    double c = sqrt(a*a+b*b-2*a*b*cos(t));
    setpre(10); out(c);
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cnt+=a[i];
    }
    int m;
    cin>>m;
    int x,y;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        cout<<y+cnt-a[x-1]<<endl;
    }
}


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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
 
////////////////////////////////////////////////////////////////////
 
const int N = 2e5 + 5;

bool B[N];
int n, A[N], SEG[N << 2];
vector<int> Q[N];

#define md ((s + e) >> 1)
#define lc (id << 1)
#define rc (lc ^ 1)
void Update(int p, int x, int id = 1, int s = 0, int e = n + 1) {
	if (e - s < 2) { SEG[id] = min(SEG[id], x); return; }
	if (p < md) Update(p, x, lc, s, md);
	else Update(p, x, rc, md, e);
	SEG[id] = min(SEG[lc], SEG[rc]);
}
int Get(int l, int r, int id = 1, int s = 0, int e = n + 1) {
	if (l >= e || s >= r) return INF;
	if (l <= s && e <= r) return SEG[id];
	return min(Get(l, r, lc, s, md), Get(l, r, rc, md, e));
}

int main() {
 
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));
	
	int zero = 0; cin >> n;
	for (int i = 1; i <= n; i++) cin >> B[i], A[i] = (B[i] ? +1 : -1), zero += !B[i];
	int q; cin >> q;
	while (q--) {
		int l, r; cin >> l >> r;
		Q[l].push_back(r);
	}
	memset(SEG, 63, sizeof SEG);
	// DP[l + 1][r] = min(DP[l][l], DP[l][l + 1], ... DP[l][r]);
	// DP[i + 1][i + 1] = min(DP[i][i + 1], DP[i][i] + (B[i + 1] ? +1 : -1));
	Update(0, 0);
	for (int i = 1; i <= n; i++) {
		sort(all(Q[i])), reverse(all(Q[i]));
		for (int r : Q[i]) Update(r, Get(i - 1, r + 1));
		Update(i, Get(i - 1, i) + A[i]);
	}
	cout << zero + Get(n, n + 1) << endl;

	return 0;
}


Measured memory_bytes: 16364
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

long N,ans;

void rec(long n,int flag){
  if(flag==7&&n<=N)ans++;
  if(n>=N)return;
  rec(n*10+3,flag|1);
  rec(n*10+5,flag|2);
  rec(n*10+7,flag|4);
}

inline void solve(){
  IN(N);
  rec(0,0);
  OUT(ans);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long s;
string S;
long long ans=0;
void solve(string x, int i){
	if(i>S.length()-1){
		//cout<<x<<endl;
		vector<char> C(x.begin(), x.end());
		long long tmp=0;
		for(char c : C){
			//cout<<tmp<<endl;
			if(c=='+'){
				ans+=tmp;
				tmp=0;
			}else{
				string sc(1,c);
				tmp=tmp*10+stoi(sc);
			}
		}
		ans+=tmp;
	}else{
		solve(x+"+"+S.substr(i,1),i+1);
		solve(x+S.substr(i,1),i+1);
	}
}
int main(){
	cin>>s;
	S=to_string(s);
	string ss(1,S[0]);
	solve(ss,1);
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[1005][10005];
 ll arr[10005];
 ll brr[10005];
 ll h,n;
ll recur(ll i, ll j)
{
    if(i==n)
    {
        if(j<=0)
        return 0;
        return 100000000000;
    }
    if(j<=0)
    return 0;
    
    if(dp[i][j]!=-1)
    return dp[i][j];
    return dp[i][j]= min(recur(i,j-arr[i])+brr[i],min(recur(i+1,j),recur(i+1,j-arr[i])+brr[i]));
}
int main()
{
    
    cin>>h>>n;
    memset(dp,-1,sizeof dp);
  /*  for(ll i=0;i<n;i++)
    dp[i][h]=0;
    for(ll i=0;i<n;i++)
    
    {
        ans=min(dp[i+1][j],dp[i+1][j-arr[i]]+brr[i]);
    }*/
   for(ll i=0;i<n;i++)
   {
       cin>>arr[i];
       cin>>brr[i];
       
   }
  cout<< recur(0,h)<<endl;


    return 0;
}


Measured memory_bytes: 79232
from itertools import combinations
N,M,Q = map(int,input().split())
B = []
for j in range(Q):
    b = list(map(int,input().split()))
    B.append(b)
cmax = 0
for k in range(1,N+1):
    for x in combinations(range(1,M+1),k):
        for y in combinations(range(N-1),k-1):
            A = [0 for _ in range(N)]
            curx = 0
            cury = 0
            for i in range(N):
                if cury==k-1 or i<=y[cury]:
                    A[i]=x[curx]
                else:
                    cury += 1
                    curx += 1
                    A[i] = x[curx]
            cnt = 0
            for j in range(Q):
                a,b,c,d = B[j]
                if A[b-1]-A[a-1]==c:
                    cnt += d
            cmax = max(cmax,cnt)
print(cmax)

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
    // (i) 全文単品
    // (ii) 全部AB
    // (iii) あるところまでAB, のちに単品
    vector<ll> ans(3);
    ans.at(0) = X * A + Y * B;
    ans.at(1) = 2 * max(X, Y) * C;
    ans.at(2) = 2 * min(X, Y) * C;
    if (X > Y){
        ans.at(2) += A * (X - Y);
    } else {
        ans.at(2) += B * (Y - X);
    }
    cout << *min_element(ans.begin(), ans.end()) << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = 1000000007;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    ll n, m;
    cin>>n>>m;
    vector<ll> pre(n);
    ll a[n];
    f(i, n) cin>>a[i];
    pre[0] = a[0];
    rep(i, 1, n - 1) pre[i] = pre[i - 1] + a[i];
    map<ll, ll> mp;
    ll ans = 0ll;
    f(i, n)
    {
        ll to = pre[i] % m;
        if(to == 0) ans++;
        ans += mp[to];
        mp[to]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>

int main(void){
  int n,i;
  long long int ans=0;
  scanf("%d",&n);
  int a[n+1],b[n];
  for(i=0;i<n+1;i++) scanf("%d",&a[i]);
  for(i=0;i<n;i++) scanf("%d",&b[i]);
  for(i=0;i<n;i++){
    if((a[i]+a[i+1])<=b[i]){
      ans += a[i]+a[i+1];
      a[i+1] = 0;
    }else{
      ans += b[i];
      if(a[i]<b[i]){
        a[i+1] = a[i+1] - (b[i]-a[i]);
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,t;
vector<pair<int,int> >a;
main()
{
	cin>>n>>m>>t;
	for(int i=0;i<n;i++)
	{
		int x;cin>>x;
		a.push_back(make_pair(x-m,x+m));
	}
	int cnt=0,now=0;
	for(int i=0;i<n;i++)
	{
		if(a[i].first>now)cnt+=a[i].first-now;
		now=a[i].second;
	}
	if(t>now)cnt+=t-now;
	cout<<cnt<<endl;
}



Measured memory_bytes: 3108
from itertools import combinations as comb

A = [[int(i) for i in input().split(' ')] for j in  range(3)]
n = int(input())
B = [int(input()) for i in range(n)]

flat = A[0] + A[1] + A[2]
ls = [b for b in B if b in flat]
ls = list(sorted(c) for c in comb(ls, 3))

bingo = [
	sorted(A[0]),
	sorted(A[1]),
	sorted(A[2]),
	sorted([A[0][0], A[1][0], A[2][0]]),
	sorted([A[0][1], A[1][1], A[2][1]]),
	sorted([A[0][2], A[1][2], A[2][2]]),
	sorted([A[0][0], A[1][1], A[2][2]]),
	sorted([A[0][2], A[1][1], A[2][0]])
]

ans = 'No'
for b in bingo:
  if b in ls:
    ans = 'Yes'
    break

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  if(s[0] != s[1] && s[1] != s[2] && s[2] != s[0])cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int L, R;
int cnt[2019];

int main() {
	//freopen(".inp", "r", stdin); freopen(".out", "w", stdout);
	scanf("%d %d", &L, &R);
	if (L == 0) return putchar('0'), 0;
	int qL = L / 2019, rL = L % 2019;
	int qR = R / 2019, rR = R % 2019;
	for (int i = 0; i < 2019; i++) cnt[i] = qR - qL + 1;
	for (int i = 0; i < rL; i++) cnt[i]--;
	for (int i = rR + 1; i < 2019; i++) cnt[i]--;
	int ans = 2019;
	for (int i = 0; i < 2019; i++)
		for (int j = i; j < 2019; j++) 
			if (i == j) {
				if (cnt[i] >= 2) ans = min(ans, i * i % 2019);
			}	else {
				if (cnt[i] >= 1 && cnt[j] >= 1) ans = min(ans, i * j % 2019);
			}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256