akhauriyash/Code-Regression huggingface dataset:
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "random"
#include        "chrono"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          pb push_back
#define          N (int)2e5+5
#define          PI acos(-1.0)
#define          int long long 
#define          vi vector<int>
#define          mod 1000000007
#define          ld long double
#define          eb emplace_back
#define          mii map<int,int>
#define          vpii vector<pii>
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) x.rbegin(),x.rend()
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q,d;
string s;
vi adj[N];
int vis[N],par[N],a[N];

ld dist( ld x , ld y )
{
    return ( ld )sqrt( x*x + y*y );
}

void go()
{
    cin >> n;
    cin >> d;
    int ans =0;
    fo(i,0,n)
    {
        ld x , y;
        cin >> x >> y;

        ans += ( dist( x , y) <= d );
    }
    cout << ans << endl;
}

int32_t main()
{
    FAST;     
    int t=1; 
    // cin>>t;
    test(t) go();
}

 

Measured memory_bytes: 8536
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<char> d;
  rep(i,k){
    char a;
    cin >> a;
    d.push_back(a);
  }
  srep(i,n,100000){
    string s = to_string(i);
    bool ok = true;
    rep(j,sz(s)){
      for(auto di:d) ok &= (s[j] != di);
    }
    if(ok){
      cout<<i<<endl;
      return 0;
    }
  }
  return 0;
}

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

int main(){
  long long N, M;
  long long l_max, r_min;
  cin >> N >> M;
  for(int i=0; i<M; i++){
    if(i==0){
      cin >> l_max >> r_min;
      continue;
    }
    long long l, r;
    cin >> l >> r;
    if(l>l_max)l_max = l;
    if(r<r_min)r_min = r;
  }
  long long ans = r_min - l_max+1;
  if(ans <0)cout << 0 << endl;
  else{
    cout << ans << endl;
  }
  return 0;
}

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

int main(void){
    int a,b;
    cin>>a>>b;
    int m=a*b;
    if(m%2==0&&m!=0){
        cout<<"Even"<<endl;
        return 0;
    }else if(m%2==1){
        cout<<"Odd"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 400000 + 5;
int n;
long long a[N], sum[N], half, ans;
int main(){
	scanf("%d", &n);
	for( int i = 1; i <=n; i ++ ) cin >> a[i], sum[i] = sum[i - 1] + a[i];
	for( int i = 1; i <= n; i ++ ) if( sum[i] * 2LL <= sum[n] && sum[i + 1] * 2LL > sum[n] ){
		ans = min(  ( sum[n] - sum[i] * 2LL ),  ( 2LL * sum[i+1] - sum[ n ] ) );
		break;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
int a[10],k;bool qwq;
int main(){
	for(int i=1;i<=5;i++)cin>>a[i];
	cin>>k;sort(a+1,a+6);
	for(int i=1;i<=4;i++)
		for(int j=i+1;j<=5;j++)
			if(a[j]-a[i]>k)qwq=1;
	if(qwq==1)  cout<<":(";
	else cout<<"Yay!";
}

Measured memory_bytes: 256
// in the name of Allah

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

#define inf 1e9
#define max_n 123456
#define mod 1000000007

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

int n;
double p[3000];
bool seen[3000][3000];
double dp[3000][3000];

double memo(int idx, int need) {
	if(need < 0) return 0.0;
	if(idx == -1) {
		if(need == 0) return 1.0;
		else return 0.0;
	}
	if(seen[idx][need]) return dp[idx][need];
	double res = p[idx] * memo(idx-1, need-1) + (1 - p[idx]) * memo(idx-1, need);
	seen[idx][need] = 1;
	return dp[idx][need] = res;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i=0; i<n; i++) cin >> p[i];
	double res = 0.0;
	memset(seen, 0, sizeof seen);
	for(int i=n/2+1; i<=n; i++) res += memo(n-1, i);
	cout << fixed << setprecision(12) << res << endl;
	return 0;
}

Measured memory_bytes: 150016
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
map<int, int> dp;
int sum[200005];
int main(){
    int n, k, a;
    scanf("%d%d", &n, &k);

    LL ans = 0;
    dp[0] = 1;
    int l = 0;
    for(int i=1;i<=n;i++){
        while(i-l >= k){
            dp[sum[l]]--;
            l++;
        }
        scanf("%d", &a);
        sum[i] = sum[i-1] + a-1;
        sum[i] %= k;
        ans += dp[sum[i]];
        dp[sum[i]]++;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 10368
/*
ID: computerbox --> Huseyn Hajiyev
LANG: C++
TASK: AC_mode_on
*/
#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);cin.tie(0);
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 51000

using namespace std;

#define debug(args...)(Debugger()) , args
class Debugger
{
  public:
  Debugger(const std::string& _separator=", ") :
  first(true),separator(_separator){}
  template<typename ObjectType>
  Debugger& operator,(const ObjectType& v)
  {
        if(!first)cerr<<separator;
        cerr<<v;
        first=false;
        return *this;
  }
  ~Debugger() {cerr<<endl;}
  private:
    bool first;
    string separator;
};

template <typename T1, typename T2>
inline ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
   return os<<"("<<p.first<<", "<<p.second<<")";
}
template<typename T>
inline ostream &operator<<(ostream & os,const vector<T>& v)
{
    bool first=true;
    os<<"[";
    for(unsigned ll i=0;i<v.size();i++)
    {
        if(!first)os<<", ";
        os<<v[i];
        first=false;
    }
        return os<<"]";
}
template<typename T>
inline ostream &operator<<(ostream & os,const set<T>&v)
{
    bool first=true;
    os<<"[";
    for(typename set<T>::const_iterator ii=v.begin();ii!=v.end();++ii)
    {
        if(!first)os<<", ";
        os<<*ii;
        first=false;
    }
    return os<<"]";
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream & os,const map<T1, T2>&v)
{
        bool first=true;
        os<<"[";
        for(typename map<T1,T2>::const_iterator ii=v.begin(); ii!=v.end();++ii)
        {
            if(!first)os<<", ";
            os<<*ii;
            first=false;
        }
        return os<<"]";
}

string shift(string one)
{
  string tempp=one;
  for(ll i=0;i<one.size()-1;i++)
  {
    one[i]=tempp[i+1];
  }
  one[tempp.size()-1]=tempp[0];
  return one;
}

string one;
string two;
int main(){
FAST_READ;
cin>>one;
string tempp=one;
cin>>two;
if(one==two)
{
  cout<<"Yes"<<endl;
  return 0;
}
one=shift(one);
if(one==two)
{
  cout<<"Yes"<<endl;
  return 0;
}
while(one!=two && one!=tempp)
{
  one=shift(one);
  //debug(one);
  if(one==two)
  {
     cout<<"Yes"<<endl;
     return 0;
  }
}
cout<<"No"<<endl;

return 0;
}


Measured memory_bytes: 256
import bisect
import sys
import math
input = sys.stdin.readline
import functools

from collections import defaultdict

############ ---- Input Functions ---- ############

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

############ ---- Solution ---- ############


def gcd(a, b):
    if b > a:
        return gcd(b, a)
    m = a % b
    if m == 0:
        return b
    return gcd(b, m)

def solve():
    N = inp()
    AA = inlt()

    MAX = 10 ** 6 + 5
    freq = [0 for i in range(MAX)]
    cnt = [0 for i in range(MAX)]
    
    gcd_cum = AA[0]

    for i in range(N):
        freq[AA[i]] += 1
        gcd_cum = gcd(gcd_cum, AA[i])

    for i in range(2, MAX):
        for j in range(i, MAX, i):
            cnt[i] += freq[j]

    pairwise = True
    for i in range(2, MAX):
        if cnt[i] > 1:
            pairwise = False
            break
    
    if gcd_cum == 1 and pairwise:
        return "pairwise coprime"

    if gcd_cum == 1:
        return "setwise coprime"
    
    return "not coprime"
    

if len(sys.argv) > 1 and sys.argv[1].startswith("input"):
    f = open("./" + sys.argv[1], 'r')
    input = f.readline

res = solve()
print(str(res))


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

int  main()
{
	int a,b,t; cin >> a >> b >> t;
	int n = t/a;
	cout << n * b;
	return (0);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int swap(int *a, int *b){
    int buf;
    buf = *a;
    *a = *b;
    *b = buf;
}

int main(){
    
    int a,b,c;
    
    cin >> a >> b >> c;
    
    if (a > b){
        swap(a,b);
    }
    if (b > c){
        swap(b,c);
    }
    if (a > b){
        swap(a,b);
    }
    
    cout << a <<" "<< b <<" "<< c << endl;

return 0;
}


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

#define llint long long int

using namespace std;

int main(){
    llint N, A, B;

    cin >> N >> A >> B;

    if(A == 0){
        cout << 0 << endl;

        return 0;
    }
    llint ans = (N / (A + B)) * A;
    llint nokori = N - (N / (A + B)) * (A + B);

    if(nokori < A){
        cout << ans + nokori << endl;
    }else{
        cout << ans + A << endl;
    }
}

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

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

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

	return false;
}

const int MAX_N = 1e5 + 10;
const long long INF = 1LL << 60;

int n, event[MAX_N][3];
long long dp[MAX_N][3];
int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cin >> event[i][j];
		}
	}

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			for (int k = 0; k < 3; ++k)
			{
				if (j != k)
				{
					chmax(dp[i + 1][j], dp[i][k] + event[i][j]);
				}
			}
		}
	}

	long long res = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (res < dp[n][i])
		{
			res = dp[n][i];
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 3712
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7

X = int(input())
N = int(math.sqrt(2*X))-1

while True:
	if N*(N+1)//2 >= X:
		print(N)
		break
	N += 1

Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
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,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    ll n; cin >> n;
    set<string> ss;
    REP(i, n){
        string s; cin >> s;
        ss.insert(s);
    }
    cout << ss.size() << endl;
}

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

Measured memory_bytes: 19256
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    int start = 0;
    int end   = 0;
    for (int i = 0, e = s.size(); i < e; ++i) {
        if (s[i] == 'A') {
            start = i;
            break;
        }
    }
    for (int i = s.size() - 1, e = 0; i >= e; --i) {
        if (s[i] == 'Z') {
            end = i;
            break;
        }
    }
    cout << end - start + 1 << endl;
}


Measured memory_bytes: 3748
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//#include <algorithm>
//#include <vector>
 
int main(int argc, char* argv[])
{
    char str[11]={0};
    scanf("%s", str);

    long len = strlen(str);
    if(str[0]!='A') {
        printf("WA\n");
        return 0;
    }

    long count = 0;
    long i;
    for(i=2; i<len-1; i++) {
        if(str[i]=='C') {
            count ++;
        }
    }
    if(count!=1) {
        printf("WA\n");
        return 0;
    }

    for(i=0; i<len; i++) {
        if(str[i]!='A' && str[i]!='C') {
            if(str[i] < 'a' || str[i] > 'z') {
                printf("WA\n");
                return 0;
            }
        }
    }
    printf("AC\n");    

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
int main(void){
  int n;
  cin>>n;
  vector<P> red,blue;
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    red.push_back({a,b});
  }
  for(int i=0;i<n;i++){
    int c,d;
    cin>>c>>d;
    blue.push_back({c,d});
  }
  sort(blue.begin(),blue.end());
  vector<bool> tf(n,false);
  int cnt=0;
  for(int i=0;i<n;i++){
    int bx=blue[i].first;
    int by=blue[i].second;
    int y=-1000;
    int x=-1;
    for(int j=0;j<n;j++){
      if(tf[j]){
        continue;
      }
      int rx=red[j].first;
      int ry=red[j].second;
      if(bx<rx){
        continue;
      }
      if(by<ry){
        continue;
      }
      if(y<ry){
        x=j;
        y=ry;
      }
    }
    if(x!=-1){
      ++cnt;
      tf[x]=true;
    }
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3552
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		if (x >= 30) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

vector<int> makePrimeList(){
	int range = 1000000;
	vector<int> ret;
	vector<bool> notp(range);

	notp[0] = notp[1] = true;
	for(int i = 2;i < range;i++){
		if(!notp[i]){
			ret.PB(i);
			for(int j = 2 * i;j < range;j += i){
				notp[j] = true;
			}
		}
	}

	return ret;
}

void check(vector<ll> v, vector<ll> &ans, ll now){
	bool flag = true;
	int n = v.size();
	REP(i, n)if(v[i] % now)flag = false;
	if(flag)ans.PB(now);
}

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

	ll n;cin >> n;
	vector<ll> v(n+1);
	REV(i, n+1)cin >> v[i];

	auto p = makePrimeList();

	vector<ll> ans;
	for(ll i = 0;p[i] <= n;i++){
		if(!(v[0] == 0 || v[0] % p[i] == 0))continue;
		vector<ll> now(p[i]-1, 0);
		for(int j = 1;j <= n;j++){
			now[(j-1)%(p[i]-1)] += v[j];
		}
		bool flag = true;
		REP(j, p[i]-1){
			if(abs(now[j]) % p[i] != 0)flag = false;
		}
		if(flag)ans.PB(p[i]);
	}

	REP(i,n+1)v[i] = abs(v[i]);
	REP(i, p.size()){
		if(p[i] > n && v[n] % p[i] == 0){
			check(v, ans, p[i]);
		}
		while(v[n] != 0 && v[n] % p[i] == 0)v[n] /= p[i];
	}

	if(v[n] > 1){
		check(v, ans, v[n]);
	}

	REP(i, ans.size()){
		cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 1148
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const ll INF = 1LL << 50;

int main(){
    int N, K;
    cin >> N >> K;
    ll a[N + 1];
    a[0] = 0;
    for(int i = 0; i < N; i++) cin >> a[i + 1];

    //削除しない項のうち最も右がi, 削除しない項の集合のサイズがjのときのmin
    ll dp[N + 1][N + 1];
    fill(dp[0], dp[N + 1], INF);

    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            if(i == 0 && j == 0) dp[i][j] = 0;
            else if(j == 0) dp[i][j] = INF;
            else if(i < j) dp[i][j] = INF;
            else {
                //dp[i][j] = min(dp[0~i-1][j-1] + max(0, a[i] - a[x]));
                for(int k = 0; k < i; k++){
                    dp[i][j] = min(dp[i][j], dp[k][j - 1] + max(0LL, a[i] - a[k]));
                }
            }
        }
    }

    ll ans = INF;
    for(int i = 0; i <= N; i++){
        ans = min(ans, dp[i][N - K]);
    }

    //debug
    /*
    for(int i = 0; i <= N; i++){
        for(int j = 0; j < N; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/

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

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>

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

using namespace std;
typedef long long ll;

const int MAX = 1046527;
char H[MAX][14];

int getChar(char ch) {
   if (ch == 'A') return(1);
   else if (ch == 'C') return(2);
   else if (ch == 'G') return(3);
   else return(4);
}

int getKey(char *str) {
   int sum = 0, p = 1;

   for (ll i = 0; i < strlen(str); i++) {
      sum += p * getChar(str[i]);
      p *= 4;
   }
   return(sum);
}

int h1(int key) {
   return(key % MAX);
}

int h2(int key) {
   return(1 + key % (MAX - 1));
}

const char *find(char *str) {
   int h;
   int key = getKey(str);

   for (int i = 0;; i++) {
      h = (h1(key) + i * h2(key)) % MAX;
      if (strcmp(H[h], str) == 0)
         return("yes");
      else if (strlen(H[h]) == 0)
         return("no");
   }
}

void insert(char *str) {
   int h;
   int key = getKey(str);

   for (int i = 0;; i++) {
      h = (h1(key) + i * h2(key)) % MAX;
      if (strlen(H[h]) == 0) {
         strcpy(H[h], str);
         return;
      }
   }
   return;
}

int main() {
   int  n;
   char str[14], com[6];

   cin >> n;
   rep(i, n) {
      scanf("%s %s", com, str);
      if (com[0] == 'i')
         insert(str);
      else
         cout << find(str) << endl;
   }
   return(0);
}



Measured memory_bytes: 17436
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define UMap        std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    llong power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); }
    llong gcd   ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; }
    llong lcm   ( llong x, llong y ) { return ( x / gcd(x, y) * y ); }
    llong abs   ( llong n )          { return ( n < 0 ) ? -n : n; }
    template<class A, class B>inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B>inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    int sum;
    Vi vi;
    int cnt;

    signed call_of_Cthulhu( signed datum ) {

        int n;
        read n;
        for ( int i = 1; sum < n; i++ ) {
            vi.bash(i);
            sum += i;
            cnt++;
        }
        for ( int i = cnt-1; i != -1; i-- ) {
            if ( n <= sum - vi[i] ) {
                sum -= vi[i];
                vi[i] = 0;
            }
            if ( sum == n ) {
                for ( int t : vi ) {
                    if ( t ) {
                        echo t fin;
                    }
                }
                return 0;
            }
        }

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); echo std::fixed << std::setprecision(8); int main_result = Rlyeh::call_of_Cthulhu(114514); return main_result;}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#define REP(i, n) for(long long int i=0; i<(n); i++)
#define FOR(i, a, n) for(long long int i=(a); i<(n); i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;

int main(){
    int a,b,c,d;
    string s;
    cin >> a >> b >> c >> d;
    cout << 3*pow(a,2) << endl;
    return 0;
}

Measured memory_bytes: 764
#include<stdio.h>

int main(void)
{
   int a,b;
   int c = 0;
   int i,q;
   
   while(c == 0){
   
   scanf("%d", &a);
   scanf("%d", &b);
   
   if(a==0){
      if(b==0){
         break;}}
   
   for(i=1;i<=a;i++){
      for(q=1;q<=b;q++){
         printf("#");
         }
      printf("\n");
      }
   	printf("\n");}
   return 0;
}


Measured memory_bytes: 2092
#include<stdio.h>
#include<algorithm>
using namespace std;
int main() {
	int n, t[2], x[2], y[2];
	scanf("%d", &n);
	t[0] = x[0] = y[0] = 0;
	while (n--) {
		scanf("%d %d %d",&t[1], &x[1], &y[1]);
		if (t[1] - t[0] < abs(x[1] - x[0]) + abs(y[1] - y[0]) || (abs(t[1] - t[0]) - (abs(x[1] - x[0]) + abs(y[1] - y[0]))) % 2 != 0) {
			printf("No\n");
			return 0;
		}
		t[0] = t[1], x[0] = x[1], y[0] = y[1];
	}

	printf("Yes\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

template<typename T> //最大公約数
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T> //最小公倍数
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

struct Edge
{
    int to, cost;
};
struct Node
{
    int from, to, cost;
};

bool comp(const Node& n1, const Node& n2){
    return n1.cost < n2.cost;
}

struct UnionFind {
	vector<int> par, rank, cnt;
	UnionFind(int n) : par(n), rank(n, 0), cnt(n, 1){
		for(int i = 0; i < n; ++i) par[i] = i;
	}
 
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
 
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
 
		if (rank[x] < rank[y]) swap(x, y);
 
		par[y] = x;
		cnt[x] += cnt[y];
		if (rank[x] == rank[y]) rank[x]++;
	}
 
	bool same(int x, int y) {
		return find(x) == find(y);
	}
 
	int size(int x) {
		return cnt[find(x)];
	}
};



int main(){
    int N, M; cin >> N >> M;
    UnionFind uf(N);
    vector<int> p(N);
    for (int i = 0; i < N; i++){
        cin >> p[i]; p[i]--;
    }
    for (int i = 0; i < M; i++){
        int x, y; cin >> x >> y; x--; y--;
        uf.unite(p[x], p[y]);
    }
    int ans = 0;
    for (int i = 0; i < N; i++){
        if (uf.same(i, p[i])){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
N, K = map(int, input().split())
acc = [0.0]
for x in map(int, input().split()):
    acc.append((1 + x) / 2)
    acc[-1] += acc[-2]
ans = 0.0
for start in range(N - K + 1):
    ans = max(ans, acc[start + K] - acc[start])
print(ans)


Measured memory_bytes: 23652
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;


#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[0] < v2[0]; 
} 

 ll degit(ll n)
 {
 	ll t=0;
 	while(n>0)
 	{
 		t++;
 		n/=10; 	}
 		return t;
 }

void solve()
{
	char a,b;
	cin>>a>>b;
	if(b=='H')
	{
		cout<<a;
	}
	else
	{
		if(a=='H')
			cout<<"D";
		else
			cout<<"H";
	}
	return;
}

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
x1,k,d=map(int, input().split())
x = abs(x1)
if x >= d * k:
	print(x - d*k)
else:
	trans = x//d
	ans = 0
	if (k-trans)%2 == 0:
		ans = abs(x-(trans*d))
	else:
		ans = abs(x - (trans * d) - d)
	print(ans)

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
ll L;
ll a[MAXN];

bool read() {
    if (!(cin >> n >> L))
        return false;

    forn (i, n)
        cin >> a[i];
    
    return true;
}

void solve() {
    forn (i, n - 1)
        if (a[i] + a[i + 1] >= L) {
            cout << "Possible\n";

            for (int j = 0; j < i; ++j)
                cout << j + 1 << endl;

            for (int j = n - 2; j > i; --j)
                cout << j + 1 << endl;

            cout << i + 1 << endl;
            return ;
        }

    cout << "Impossible\n";
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 1664
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main() {
  using namespace std;

  int n, k;
  cin >> n >> k;

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

  sort(h.begin(), h.end());
  int min_diff_tree_height = int(pow(10, 9));
  for (int i = 0; i < n - (k-1); i++) {
    int diff_tree_height = abs(h.at(i) - h.at(i + (k-1)));
    min_diff_tree_height = min(min_diff_tree_height, diff_tree_height);
  }

  cout << min_diff_tree_height << endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
   int i,l,x,u=0,y=0;
cin>>i>>l;
for(int o = 0; o < l;o++){
 cin>>u;
 y =y+u;
}
x=i+1;
if(y%x!=0){
cout<<(y/(i+1))+1<<endl;
}
if(y%x==0){
cout<<(y/(i+1))<<endl;
}
}



Measured memory_bytes: 3084
import sys
N = int(input())
H = list(map(int, input().split()))
res = 0
while True:
    i = 0
    cnt = 0
    while i < N:
        while i < N and H[i] <= 0:
            i += 1
        if i >= N:
            break
        while i < N and H[i] > 0:
            H[i] -= 1
            i += 1
        cnt += 1
    if cnt == 0:
        print(res)
        sys.exit()
    else:
        res += cnt


Measured memory_bytes: 9188
//#include "StdAfx.h"
#include <vector>
#include <bitset>
#include <iostream>
#include <random>
#include <set>
#include <functional>
#include <algorithm>

using namespace std;

int main()
{
	int N, P;
	cin >> N >> P;
	int e = 0, o = 0;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		if (A & 1) {
			o++;
		} else {
			e++;
		}
	}
	uint64_t ans = 0;
	for (int i = P; i <= o; i += 2) {
		set<int> n;
		set<int> d;
		for (int j = 0; j < i; j++) {
			n.insert(o - j);
			d.insert(j + 1);
		}
		uint64_t nn = 1;
		uint64_t dd = 1;
		for (auto i : n) {
			if (d.find(i) == d.end()) nn *= i;
		}
		for (auto i : d) {
			if (n.find(i) == n.end()) dd *= i;
		}
		ans += nn / dd;
	}
	cout << ans * (1ULL << e);

	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int N; cin >> N;
    vector<Int> A(N), B(N), diff(N);
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> B[i];

    Int res = 0, negSum = 0, posSum = 0;
    rep(i, 0, N) {
        diff[i] = A[i]-B[i];
        if (diff[i] < 0) { ++res; negSum += -diff[i]; }
        if (diff[i] > 0) posSum += diff[i];
    }

    if (negSum > posSum) { cout << -1 << endl; return 0; }
    if (negSum == 0) { cout << 0 << endl; return 0; }

    sort(diff.begin(), diff.end(), greater<Int>());
    rep(i, 0, N) {
        negSum -= diff[i];
        ++res;
        if (negSum <= 0) break;
    }

    cout << res << endl;
}


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

int a[101];

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int n, m, x; cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        int v; cin >> v;
        a[v] = 1;
    }

    int ans1 = 0, ans2 = 0;
    for (int i = x; i >= 0; i--) {
        ans1 += a[i];
    }
    for (int i = x; i <= n; i++) {
        ans2 += a[i];
    }

    cout << min(ans1, ans2) << '\n';





    return 0;
}


Measured memory_bytes: 256
fun main() {
  val N = readInt()
  val AN = readInts()
  var cnt = 0
  for (i in 1..N) {
    val a = AN[i - 1]
    if (a % 2 == 1 && i % 2 == 1) cnt++
  }
  println(cnt)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 36448
#include <stdio.h>

int cto_num(const char c){
  return (c - 'A');
}
int main(){
  char line[5];
  int num=0;
  
  while(scanf("%s", line) != EOF){
    if(cto_num(line[0]) == num){
      num = cto_num(line[2]);
    }else if(cto_num(line[2]) == num){
      num = cto_num(line[0]);
    }
  }
  printf("%c\n", 'A'+num);
  return 0;
}

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

using namespace std;

#define MAX_Q 100010

int main()
{
	int N, Q;
	string S;
	int l[MAX_Q], r[MAX_Q];

	cin >> N >> Q;
	cin >> S;

	int ACcount[MAX_Q];

	for (int i = 0; i < Q; i++) {
		cin >> l[i] >> r[i];
    l[i]--;
    r[i]--;
	}

	ACcount[0] = 0;
	for (int i = 1; i < N; i++) {
		ACcount[i] = ACcount[i - 1];
		if (S[i - 1] == 'A' && S[i] == 'C') {
			ACcount[i]++;
		}
	}

	for (int i = 0; i < Q; i++) {
    int count = ACcount[r[i]] - ACcount[l[i]];
		cout << count << endl;
	}

	return 0;
}


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

int main(){
	int n,cnt=1;
	cin>>n;
	cout<<11;
	for(int i=21;; i+=10){
		int check=0;
		for(int j=3; j<=sqrt(i); j+=2){
			if(i%j==0){
				check=1;
				break;
			}
		}
		if(check==0)cout<<" "<<i,cnt++;
		if(cnt==n){
			cout<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;

int main(int argc, const char * argv[]) {
    int x;
    cin >> x;
    int b = 1;
    int p = 0;
    int max = 0;
    while(1){
        b++;
        p = 2;
        while(1){
            if(pow(b,p) > max && pow(b, p) <= x){
                max = pow(b, p);
            }
            if(pow(b, p) > x && p == 2){
                goto end;
            }
            if(pow(b,p) > x){
                break;
            }
            p++;
        }
    }
end:
    if(max == 0)
        max = 1;
    cout << max << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

using namespace std;
int main(){
	int N,dis;
	int T[100001],X[100001],Y[100001];
	T[0]=0;
	X[0]=0;
	Y[0]=0;
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>T[i]>>X[i]>>Y[i];
	}
	for(int i=0;i<N;i++){
		dis=abs(X[i]-X[i+1])+abs(Y[i]-Y[i+1]);
		if(T[i+1]-T[i]>=dis&&(T[i+1]-T[i]-dis)%2==0){
		
		}else{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, M;

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

  std::cin >> N >> M;

  int sum = 0;

  for(int i=0;i<M;++i){
      int A;
      std::cin >> A;

      sum += A;
  }

  int res = -1;

  if(sum <= N){
      res = N - sum;
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	static int count = 0;
	static Pair pair;
	static int num[][]=new int[100][10];

	public static void main(String[] args) {
		read();
		pair = new Pair(0, 0);
		for (int i = 0; i < n; i++) {
			dfs(i,0);
		}

	}
	public static void read(){
		n = sc.nextInt();
		for(int i = 0;i<n;i++){
			for(int j=0;j<10;j++){
				num[i][j]=sc.nextInt();
			}
		}
	}
	public static void dfs(int i,int j) {
		if (count >= 10) {
			System.out.println("YES");
			init();
			return;
		}
		count++;

		int nextNum = num[i][j];
		//?????£?????????????????????
		if (nextNum < pair.left && nextNum < pair.right) {
			System.out.println("NO");
			init();
			return;
		}
		
		//?????£????????\???
		if (nextNum > pair.left && nextNum > pair.right) {
			// ?????????????°???????
			if (nextNum - pair.left <= nextNum - pair.right) {
				pair.left = nextNum;
				dfs(i,++j);
				return;
			} else {
				// ????????????????????°????????£??????
				pair.right = nextNum;
				dfs(i,++j);
				return;
			}
		}
		// ?????£??????????????\?????????
		if (nextNum < pair.left || nextNum < pair.right) {
			if (nextNum > pair.left) {
				pair.left = nextNum;
				dfs(i,++j);
				return;
			} else {
				pair.right = nextNum;
				dfs(i,++j);
				return;
			}
		}

	}

	public static void init() {
		count = 0;
		pair.left = 0;
		pair.right = 0;
	}

}

class Pair {
	int left;
	int right;

	Pair(int a, int b) {
		left = a;
		right = b;
	}

}

Measured memory_bytes: 18652
n, k = map(int, input().split())
a = list(map(int, input().split()))

loop_counter = 0 # 何回目でループに達するか

start = 1
end = a[start-1]
is_checked = [0 for _ in range(n)]
is_checked[0] = 1
road = [1]
while True:
    if is_checked[end-1] == 1:
        # ループしている
        roop_start = end
        break
    else:
        road.append(end)
        is_checked[end-1] = 1
        start = end
        end = a[start-1]
roop_start_index = road.index(roop_start)
roop_length = len(road)-roop_start_index
if k <= roop_start_index+1:
    print(road[k])
else:
    k -= roop_start_index
    k %= roop_length
    print(road[roop_start_index+k])


Measured memory_bytes: 32372
#include <iostream>
using namespace std;
int main() {
    int a, b, s;
    cin >> a >> b;
    s = a + b;
    if (s < a - b) {
        s = a - b;
    }
    if (s < a * b) {
        s = a * b;
    }

    cout << s;

    return 0;
}

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

namespace ABC043A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            int s;
            int i;
            n = int.Parse(Console.ReadLine());
            s = 0;

            for (i = 1; i <= n; i++)

                s = s + i;
            Console.WriteLine(s);

            Console.ReadKey();


          


        }
    }
}


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

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n = SZ(s);
    //0,1
    int ans1 = 0;
    REP(i,n){
        if(s[i] != (i%2 == 0 ? '0' : '1'))ans1++; 
    }
    //1,0
    int ans2 = 0;
    REP(i,n){
        if(s[i] != (i%2 == 0 ? '1' : '0'))ans2++; 
    }
    PUTS(min(ans1, ans2));
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
ll read(){
	ll w=0;
	bool s=0;
	char c=getchar();
	while(!isdigit(c)){
		s=(c=='-');
		c=getchar();
	}
	while(isdigit(c)){
		w=w*10+c-'0';
		c=getchar();
	}
	return s?-w:w;
}
const int N=1000005;
const ll inf=1e15;
int x,y,z,n;
struct Data{
	ll a,b,c;
	friend bool operator < (Data a,Data b){
		return a.a-a.b>b.a-b.b;
	}
};
Data a[N];
ll sum,ans;
ll f[N],g[N];
struct Heap{
	#define fa (root>>1)
	#define ls (root<<1)
	#define rs (root<<1|1)
	ll h[N<<3];
	int siz;
	void clear(){
		siz=0;
		h[0]=-inf;
	}
	void insert(ll x){
		h[++siz]=x;
		int root=siz;
		while(root){
			if(h[root]<h[fa]){
				swap(h[root],h[fa]);
				root=fa;
			}
			else{
				return;
			}
		}
	}
	void remove(){
		swap(h[1],h[siz]);
		siz--;
		int root=1;
		while(ls<=siz){
			int son=ls;
			if(rs<=siz&&h[rs]<h[ls]){
				son=rs;
			}
			if(h[son]<h[root]){
				swap(h[son],h[root]);
				root=son;
			}
			else{
				return;
			}
		}
	}
	bool empty(){
		return !siz;
	}
	int size(){
		return siz;
	}
	void push(int x){
		insert(x);
	}
	void pop(){
		remove();
	}
	ll top(){
		return h[1];
	}
	#undef fa
	#undef ls
	#undef rs
};
Heap que;
int main(){
	x=read(),y=read(),z=read();
	n=x+y+z;
	ll u,v,w;
	for(int i=1;i<=n;i++){
		u=read(),v=read(),w=read();
		ans+=w;
		a[i]=(Data){u,v,w};
	}
	sort(a+1,a+1+n);
	que.clear();
	sum=0;
	for(int i=1;i<=n;i++){
		ll dt=a[i].a-a[i].c;
		que.push(dt);
		sum+=dt;
		if(que.size()>x){
			dt=que.top();
			que.pop();
			sum-=dt;
		}
		f[i]=sum;
	}
	que.clear();
	sum=0;
	for(int i=n;i>=1;i--){
		ll dt=a[i].b-a[i].c;
		que.push(dt);
		sum+=dt;
		if(que.size()>y){
			dt=que.top();
			que.pop();
			sum-=dt;
		}
		g[i]=sum;
	}
	sum=-inf;
	for(int i=x;i<=n-y;i++){
		sum=max(sum,f[i]+g[i+1]);
	}
	ans+=sum;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 9216
import java.lang.*;
import java.util.*;
 
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int kari = n+1;
        int keta = 1;
        while((int)(kari/10)!=0){
            keta++;
            kari = (int)(kari/10);
        }
        if(keta == 1){
            System.out.println(n);
        }else if(keta == 2){
            System.out.println(9);
        }else if(keta == 3){
            System.out.println((10+n-100));
        }else if(keta == 4){
            System.out.println(909);
        }else if(keta == 5){
            System.out.println((910+n-10000));
        }else{
            System.out.println(90909);
        }
        sc.close();
    }
}

Measured memory_bytes: 23252
from collections import defaultdict
N,A,B,C,D=map(int,input().split())

mod=10**9+7
table=[1]*(N+3)
t=1
for i in range(1,N+3):
    t*=i
    t%=mod
    table[i]=t
rtable=[1]*(N+3)
t=1
for i in range(1,N+3):
    t*=pow(i,mod-2,mod)
    t%=mod
    rtable[i]=t
dp=defaultdict(int)
dp[N]=1
for l in range(A,B+1):
    ndp=defaultdict(int)
    for mem,num in dp.items():
        ndp[mem]+=num
        for k in range(C,D+1):
            if mem-k*l<0:
                break
            t=(table[mem]*pow(rtable[l],k,mod)*rtable[mem-k*l]*rtable[k])%mod
            ndp[mem-k*l]+=(num*t)%mod
            ndp[mem-k*l]%mod
            #print(mem-k*l,(num*t)%mod)

    dp=ndp
    #print(dp)
print(dp[0]%mod)

Measured memory_bytes: 74076