akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;

int main(){
    int n, m, x; cin >> n >> m >> x;
    int c[n], a[n][m];
    rep(i, n){
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }
    int min_cost = 10000000;
    for(int i=0; i<1<<n; i++){
        int cost = 0;
        vector<int> rikai(m, 0);
        rep(j, n){
            if(i & 1<<j){
                rep(k, m) rikai[k] += a[j][k];
                cost += c[j];
            }
        }
        bool ok = true;
        rep(j, m){
            //cout << rikai[j] << " ";
            if(rikai[j] < x) ok = false;
        }
        //cout << "cost="<<cost<<endl;
        if(ok) min_cost = min(min_cost, cost);
    }
    if(min_cost == 10000000) cout << -1 << endl;
    else cout << min_cost << endl;
}

Measured memory_bytes: 3568
#include <iostream>
using namespace std;
int point[100],team[100],rank[100];
int main(){
	int n,i,j,a,b,c,d,tmp;
	cin >> n;
	for(i = 0;i < 100;i++){
		team[i] = i+1;
		point[i] = 0;
	}
	for(i = 0;i < (n*(n-1)/2);i++){
		cin >> a >> b >> c >> d;
		if(c > d){
			point[a - 1] += 3;
		}
		else if(c < d){
			point[b - 1] += 3;
		}
		else if(c == d){
			point[a - 1]++;
			point[b - 1]++;
		}
	}
	for(i = 0;i < n - 1;i++){
		for(j = n - 1;j > i;j--){
			if(point[i] < point[j]){
				tmp = point[j];
				point[j] = point[i];
				point[i] = tmp;
				tmp = team[j];
				team[j] = team[i];
				team[i] = tmp;
			}
		}
	}
	for(i = 0;i < n;i++){
		if(i != 0){
			if(point[i - 1] == point[i]){
				rank[team[i] - 1] = rank[team[i - 1] - 1];
			}
			else {
				rank[team[i] - 1] = i + 1;
			}
		}
		else rank[team[i] - 1] = i + 1;
	}
	for(i = 0;i < n;i++){
		cout << rank[i] << endl;
	}
	return 0;
}

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

using namespace std;

const int N = 1e5 + 5;
int n, x[N], jump[N][20], l, q;

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> x[i];
    cin >> l;

    for (int i = 1; i <= n; ++i) {
        int pos = upper_bound(x + 1, x + n + 1, x[i] + l) - x;
        jump[i][0] = pos - 1;
    }
    for (int j = 1; j < 20; ++j) {
        for (int i = 1; i <= n; ++i) {
            jump[i][j] = jump[ jump[i][j - 1] ][j - 1];
        }
    }
    cin >> q;
    while(q--) {
        int ans = 0, a, b; cin >> a >> b;
        if(a > b) swap(a, b);
        for (int i = 19; i >= 0; --i) if(jump[a][i] < b) ans += (1 << i), a = jump[a][i];
        cout << ans + 1 << '\n';
    }

    return 0;
}


Measured memory_bytes: 9088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
    static ArrayList<Integer> primeList;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            int[] t = ai(br);
            int[] list = new int[25 * 60];
            if (t[0] == 0 && t[1] == 0 && t[2] == 0) {
                break;
            }
            int n = t[0];
            int start = toMinutes(t[1]);
            int finish = toMinutes(t[2]);
            for (int i = 0; i < n; i++) {
                int m = ip(br);
                int[] ct = ai(br);
                for (int j = 0; j < m * 2; j += 2) {
                    int ts = toMinutes(ct[j]);
                    int tf = toMinutes(ct[j + 1]);
                    list[ts]++;
                    list[tf]--;
                }
            }
            for (int i = start; i < finish; i++) {
                list[i] += list[i - 1];
            }
            int max = 0;
            for (int i = start; i < finish; i++) {
                if (list[i] == n) {
                    list[i] = 0;
                } else {
                    list[i] = list[i > 0 ? i - 1 : 0] + 1;
                }
                max = Math.max(max, list[i]);
            }
            System.out.println(max);
        }

    }

    private static int[] ai(BufferedReader br) throws IOException {
        String[] lines;

        lines = br.readLine().split(" ");
        int a = lines.length;
        int[] l = new int[a];
        while (a-- > 0) {
            l[a] = Integer.parseInt(lines[a]);
        }
        return l;
    }

    static int ip(BufferedReader br) throws IOException {
        return Integer.parseInt(br.readLine());
    }

    static int toMinutes(int t) {
        return t / 100 * 60 + t % 100;
    }

}
/*
1 2100 2400
1
2130 2200
3 2100 2400
3
2100 2130 2200 2230 2300 2330
2
2130 2200 2330 2400
2
2100 2130 2330 2400
0 0 0
*/

Measured memory_bytes: 24176
#include<stdio.h>
int main(){
    int N,i,j,time,min;
    int A[100];
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    for(i=0;i<N;i++){
        min = i;
        for(j=i;j<N;j++){
            if(A[min] > A[j]){
                min = j;
            }
        }
        if(A[i] != A[min]){
        int temp = A[i];
        A[i] = A[min];
        A[min] = temp;
        time++;
        }
    }
    for(i=0;i<N;i++){
        printf("%d",A[i]);
        if(i<N-1){
            printf(" ");
        }
    }
    printf("\n%d\n",time);
    return 0;
}


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

using namespace std;


int main(){
  int n, l;

  cin >> n >> l;
  vector<string> list(n);

  for (int i = 0; i < n; i++)
  {
    cin >> list[i];
  }
  sort(list.begin(), list.end());

  for (int i = 0; i < n; i++)
  {
    cout << list[i];
  } 
}

Measured memory_bytes: 256
/*
题意：问能否构造出一棵树，使得对于某点i，到其他所有点的距离和为Di。Di各不相同。 
如果已知x的size，那么x的父亲的Di=Dx-n+2*size[x],唯一还原
我们需要从底往上构造
由于一棵树一定有一个点到其他所有点的距离最小，其余点离此点距离越远，Di越大
将Di从大到小排序，父亲一定在儿子之后被统计 
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
const int N=100005;
int n,size[N],fa[N];
map<ll,int> mp;
struct node{int id;ll dis;}p[N];
bool cmp(const node &A,const node &B){return A.dis>B.dis;}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%lld",&p[i].dis),p[i].id=i,mp[p[i].dis]=i;
	sort(p+1,p+n+1,cmp);
	for (int i=1;i<n;i++)
	{
		size[p[i].id]++;
		ll fa_Di=p[i].dis-n+2*size[p[i].id];
		if (!mp.count(fa_Di)) return puts("-1"),0;else fa[p[i].id]=mp[fa_Di];
		if (fa[p[i].id]==p[i].id) return puts("-1"),0;
		size[fa[p[i].id]]+=size[p[i].id];
	}
	for (int i=1;i<n;i++) p[n].dis-=size[p[i].id];
	if (p[n].dis) return puts("-1"),0;
	for (int i=1;i<=n;i++) 
	  if (fa[i]) printf("%d %d\n",i,fa[i]); 
	return 0;
}

Measured memory_bytes: 9984
(function() {
    'use strict';

    var lines = [];
    require('readline').createInterface({
      input: process.stdin,
      output: process.stdout
    }).on('line', function(line) {
      lines.push(line);
    });
    process.stdin.on('end', function() {
      //lines.forEach(function(line) {
        //var tokens = line.split(' ').map(Number);
        //    console.log(tokens[0] + ' ' + tokens[1]);
      //}
      //)
      ;

    // ToDo start
      var C1 = lines[0]
      var C2 = lines[1]

      if(C1[0]==C2[2] && C1[1]==C2[1] && C1[2]==C2[0]) {
          console.log("YES")
        }else {
            console.log("NO")
        }
      
//      console.log( Math.pow(parseInt(lines[0]),2) - parseInt(lines[1])  )
    // ToDo end

    });


})();



Measured memory_bytes: 21444
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean ans = false;
        for (int i = 1; i < 10; i++) {
            if(n % i == 0 && n / i < 10){
                ans = true;
                break;
            }
        }
        if(ans) System.out.println("Yes");
        else System.out.println("No");
        sc.close();

    }

}


Measured memory_bytes: 21844
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int max = 0;
        int aa = a + (a - 1);
        int bb = b + (b - 1);
        int ab = a + b;
        
        if (max <= aa) {
            max = aa;
        }
        if (max <= bb) {
            max = bb;
        }
        if (max <= ab) {
            max = ab;
        }
        
        System.out.println(max);
        
    }
}

Measured memory_bytes: 22228
N,K,*as=$<.read.split.map(&:to_i)
mod = 10**9+7

x = 0
y = 0
as.each.with_index do |a,i|
    x += as.count {|b| a > b}
    y += as[i+1..-1].count {|b| a > b}
end

puts (x * (K-1)*K/2 + y * K) % mod 


Measured memory_bytes: 3836
# 092

# 1.値を正しく取得
a =int(input())
b =int(input())
c =int(input())
d =int(input())

# 2.正しく処理
if a > b :
    resalt1=int(b)
else :
    resalt1=int(a)

if c > d :
    resalt2=int(d)
else :
    resalt2=int(c)

print(resalt1 + resalt2)

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e3 + 5;

int32_t main()
{
	IOS;
	int a,p;
	cin >> a >> p;
	int tot= a*3 + p;
	cout << tot/2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int>coun;
int a[100002],elemin=1000000,elemax=-1;

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        elemin=min(a[i],elemin);
        elemax=max(a[i],elemax);
    }
    for(int i=1;i<=n;i++){
        coun[a[i]]++;
    }
    for(int i=elemin;i<=elemax;i++){
        if(coun[i]>2){
            if(coun[i]%2==0)
                coun[i]=2;
            else
                coun[i]=coun[i]%2;
        }
        //cout<<i<<" "<<coun[i]<<endl;
    }
    int j=elemin;
    for(int i=elemin;i<=elemax;i++){
        if(coun[i]==2){
            j=i+1;
            while((j<=elemax)&&(coun[j]<2)){
                j++;
            }
            if(j>elemax)
                break;
            if(coun[j]==2){
                coun[i]--;
                coun[j]--;
                //cout<<i<<" "<<coun[i]<<" "<<j<<coun[j]<<endl;
            }
            
        }
    }
    int ans=0;
    int res=0;
    for(int i=elemin;i<=elemax;i++){
        if(coun[i]==1){
            ans++;
            //cout<<i<<" ";
        }
    }
    cout<<ans;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

bool ispa(string s)
{
    ll n = s.length();
    bool pos = 1;
    rep(n)
        if(s[i]!=s[n-1-i])
            pos = 0;
    return pos;        
}

int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   ll arr[n];
   rep(n)
        cin>>arr[i];
   map<ll,ll> ma;
   rep(n)
        ma[arr[i]]++;
   ll ans = 0;
   autoit(ma,it)
       ans+=(it->ss*(it->ss-1))/2;
   rep(n)
   {
       ll p1 = ma[arr[i]];
       ans-=(p1*(p1-1))/2;
       p1--;
       ans+=(p1*(p1-1))/2;
       cout<<ans<<"\n";
       ans-=(p1*(p1-1))/2;
       p1++;
       ans+=(p1*(p1-1))/2;
   }
   
   return 0;        
}  
   

Measured memory_bytes: 11136
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

int main(void){
    int A, B, C;
    cin >> A >> B >> C;
    if(A + B >= C){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

ll h,w;

bool in(ll y, ll x){
	return 0 <= y && y < h && 0 <= x && x < w;
}

int main(){
	cin >> h >> w;
	char s[25][25];
	rep(i,h) rep(j,w) cin >> s[i][j];
	ll ans = 0;
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='#') continue;
			vvl d(h,vl(w,inf));
			d[i][j] = 0;
			queue<P> q;
			q.emplace(i,j);
			while(!q.empty()){
				P p = q.front(); q.pop();
				ll y = p.first; ll x = p.second;
				rep(i,4){
					ll ny = y + dy[i];
					ll nx = x + dx[i];
					if(in(ny,nx) && s[ny][nx]!='#' && d[ny][nx]==inf){
						d[ny][nx] = d[y][x] + 1;
						q.emplace(ny,nx);
					}
				}
			}
			rep(k,h){
				rep(l,w){
					if(d[k][l]==inf) continue;
					chmax(ans,d[k][l]);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
s = gets

f = s[0..1].to_i
l = s[2..3].to_i

(f >= 1 && f <= 12) ? f_type = '1' : f_type = '2'
(l >= 1 && l <= 12) ? l_type = '1' : l_type = '2'

if f_type == '2' && l_type == '2'
  puts 'NA'
elsif f_type == '1' && l_type == '2'
  puts 'MMYY'
elsif f_type == '2' && l_type == '1'
  puts 'YYMM'
elsif f_type == '1' && l_type == '1'
  puts 'AMBIGUOUS'
end


Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<algorithm>
#include<functional>
#include<cmath>
#include<ctime>
#include<cstdlib>
using namespace std;
char s[100005];
int Left[10][10],Right[10][10];
struct array
{
    int x,y;
}ans[10];
int sum=0;
int main()
{
    int i,j,k;
    ans[1].x=3;ans[1].y=1;
    ans[2].x=3;ans[2].y=2;
    ans[3].x=3;ans[3].y=3;

    ans[4].x=2;ans[4].y=1;
    ans[6].x=2;ans[6].y=3;

    ans[7].x=1;ans[7].y=1;
    ans[8].x=1;ans[8].y=2;
    ans[9].x=1;ans[9].y=3;

    for(i=1;i<=9;i++)
    {
        if(i==5)continue;
        for(j=1;j<=9;j++)
        {
            if(j==5)continue;
            if(i==j)continue;
            if(ans[j].y<=ans[i].y)Left[i][j]=1;
            if(ans[j].y>=ans[i].y)Right[i][j]=1;
        }
    }
//    for(i=1;i<=9;i++)
//    {
//        for(j=1;j<=9;j++)
//            cout<<Left[i][j]<< " ";
//        cout<<endl;
//    }
    while(scanf("%s",s)!=EOF)
    {
        if(s[0]=='#')break;
        int len = strlen(s);
        sum = 0;
        int ans = len+1;
        int flag=1;
        for(i=1;i<len;i++)
        {
            int a = s[i-1]-'0',b = s[i]-'0';
            //cout<<a<<"*"<<b<<endl;
            if(flag==1)
            {
               // cout<<Right[a][b]<<"****"<<endl;
                if(Right[a][b])
                {
                    flag=2;
                    continue;
                }
                else
                {
                    sum++;
                    continue;
                }
            }
            else if(flag==2)
            {
                //cout<<Left[a][b]<<"-*-*-*"<<endl;
                if(Left[a][b])
                {
                    flag=1;
                }
                else
                {
                    sum++;
                    continue;
                }
            }
        }
        ans = min(ans,sum);
        //cout<<sum<<endl;
        sum=0;
        flag=2;
        for(i=1;i<len;i++)
        {
            int a = s[i-1]-'0',b = s[i]-'0';
            if(flag==1)
            {
                if(Right[a][b])
                {
                    flag=2;
                }
                else
                {
                    sum++;
                    continue;
                }
            }
            else if(flag==2)
            {
                if(Left[a][b])
                {
                    flag=1;
                }
                else
                {
                    sum++;
                    continue;
                }
            }
        }
        //cout<<sum<<endl;
        ans = min(ans,sum);
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> vec(n);
  for (auto &v : vec)
    cin >> v;

  sort(vec.begin(), vec.end());
  int ans = accumulate(vec.begin(), vec.begin()+k, 0);

  cout << ans << endl;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>

using namespace std;

bool res() {
	int n;
	cin >> n;
	if (!cin) return false;

	vector<int> v(n);

	int m1 = -1, m2 = -1, p1;

	for (int i = 0; i < n; ++i) {
		int act;
		cin >> act;

		if (act > m1) {
			m2 = m1;
			m1 = act;
			p1 = i;
		}
		else if (act > m2) {
			m2 = act;
		}
	}
		
	for (int i = 0; i < n; ++i) {
		if (i == p1) cout << m2 << '\n';
		else cout << m1 << '\n';
	}

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>

using namespace std;
long long a[1000005] = {};
long long calc(long long *, long long, struct calc_data);
long long get_sign(long long);

struct calc_data
{
	long long tmp;
	long long sign;
	long long cnt;
};

int main()
{
	struct calc_data calc_data = {0, 0, 0};
	long long n, ans, ans2;
	cin >> n;
	for (long long i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	//最初を正
	calc_data.sign = 1;
	if (a[0] > 0)
	{
		calc_data.tmp = a[0];
		calc_data.cnt = 0;
	}
	else
	{
		calc_data.tmp = 1;
		calc_data.cnt = (-1 * a[0]) + 1;
	}
	ans = calc(a, n, calc_data);
	//最初を負
	calc_data.sign = 0;
	if (a[0] < 0)
	{
		calc_data.tmp = a[0];
		calc_data.cnt = 0;
	}
	else
	{
		calc_data.tmp = -1;
		calc_data.cnt = a[0] + 1;
	}
	ans2 = calc(a, n, calc_data);
	if (ans2 < ans) ans = ans2;
	cout << ans << endl;
	return 0;
}

long long calc(long long *a, long long n, struct calc_data calc_data)
{
	for (long long i = 0; i < n - 1; i++)
	{
		calc_data.tmp = calc_data.tmp + a[i + 1];
		if (calc_data.sign == 1)
		{
			if (calc_data.tmp >= 0)
			{
				calc_data.cnt += calc_data.tmp + 1;
				calc_data.tmp = -1;
			}
		}
		else
		{
			if (calc_data.tmp <= 0)
			{
				calc_data.cnt += (-1 * calc_data.tmp) + 1;
				calc_data.tmp = 1;
			}
		}
		calc_data.sign = get_sign(calc_data.tmp);
	}
	return calc_data.cnt;
}

long long get_sign(long long tmp)
{
	if (tmp < 0) return 0;
	else return 1;
}

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

int main() {
  string s; cin >> s;
  if(s[0]=='7' || s[1]=='7' || s[2]=='7') cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  int result = 0;
  int i;
  for (i = 0; i < s.length(); i++) {
    if (s.at(i) == t.at(i)) {
      result++;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
n,a,b=map(int,input().split())
kei=0

for i in range (n+1):
  u=i//10000
  v=(i-10000*u)//1000
  x=(i-10000*u-1000*v)//100
  y=(i-10000*u-1000*v-100*x)//10
  z=(i-10000*u-1000*v-100*x-10*y)
  if a<=u+v+x+y+z<=b:
    kei+=i
print(kei)

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

int main() {
	string S;
	string T;
	cin >> S >> T;
	int count=0;
	for (int i = 0; i < 3; i++) {
		if (S.at(i) == T.at(i)) {
			count++;
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static String line;
	static int res;
	public static void main(String[] args) {
		while(read()){
			slove();
		}
		System.out.println(res);
	}
	static boolean read(){
		if(!sc.hasNext())
			return false;
		line = sc.next();
		return true;
	}
	static void slove(){
		if(line.equals(new StringBuffer(line).reverse().toString())){
			res++;
		}
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<complex>
#include<set>
using namespace std;

long long int n,num[200005],res=0;
int main(){
	cout << fixed << setprecision(18);
	string str,tmp;
	cin>>n;
	set<long long int>st{0,n+1};
	typedef pair<long long int,long long int>P;
	priority_queue<P,vector<P>,greater<P> >pq;
	for(int i=1;i<=n;i++)
	{
		cin>>num[i];
		pq.push({num[i],i});
	}
	for(int i=1;i<=n;i++)
	{
		long long int pl=pq.top().second;
		st.insert(pl);
		auto itrl =--st.find(pl);
		auto itrr =++st.find(pl);
		
		res+=(*itrr-pl)*(pl-*itrl)*i;
		
		pq.pop();
	}
	cout<<res;
}


Measured memory_bytes: 14956
N = int(input())
lsA = list(map(int,input().split()))
sum1 = sum(lsA)
ans = 0
for i in range(N):
    sum1 = sum1 - lsA[i]
    ans += lsA[i] * (sum1 % (10**9+7))
    ans = ans % (10**9+7)
print(ans)

Measured memory_bytes: 31568
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

int is_ok[2048][2048];
int h[2048][2048];

void solve(ll H, ll W, vector<string> S) {
  REP(i,H-1) REP(j,W-1)
    is_ok[i][j] = ((S[i][j] == S[i][j+1]) == (S[i+1][j] == S[i+1][j+1]));
  REP(i,H-1) REP(j,W-1) {
    if (i == 0) h[i][j] = is_ok[i][j] + 1;
    else {
      if (is_ok[i][j]) h[i][j] = h[i-1][j] + 1;
      else h[i][j] = 1;
    }
  }
  int res = 0;
  REP(i,H-1) {
    vector<pair<int,int>> left;
    left.emplace_back(-1, -1);
    REP(j,W) {
      int pos = j;
      while (h[i][j] < left.back().second) {
        int val = left.back().second * (j - left.back().first + 1);
        chmax(res, val);
        pos = left.back().first;
        left.pop_back();
      }
      if (h[i][j] > left.back().second) {
        left.emplace_back(pos, h[i][j]);
      }
    }
  }
  chmax(res, int(H)); chmax(res, int(W));
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll W;
	ll H;
	scanf("%lld", &H);
	vector<string> S(H-1+1);
	scanf("%lld", &W);
	for (int i = 0 ; i <= H-1 ; i++) {
	  cin >> S[i];
	}
	solve(H, W, S);
	return 0;
}


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

#define M 1000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char);
long long getKey(char[]);
int key(int);
int key(int);
int insert(char[]);

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

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

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

int find(char str[]){
 long long key;
 int i,x,y,sum;

 key = getKey(str);
 x = h1(key);
 y = h2(key);

 for( i = 0 ; i < M ; i++ )
   {
     sum = (x+i*y)%M;
     if( strcmp(H[sum],str) == 0 )
       return 1;
     else if( H[sum][0] == '\0' )
         return 0;
   }
 return 0;
}

int insert(char str[]){
 long long key;
 int i,x,y,sum;

 key = getKey(str);
 x = h1(key);
 y = h2(key);

 for( i = 0 ; i < M ; i++ )
   {
     sum = (x+i*y)%M;
     if( strcmp(H[sum],str) == 0 )
       return 1;
     else if( H[sum][0] == '\0' )
       {
	 strcpy(H[sum],str);
	 return 0;
       }
   }
 return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

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

typedef long long ll;

using namespace std;

void solve() {
    int n, k;

    cin >> n >> k;
    vector<int> dp(n, INT_MAX);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    dp[0] = 0;

    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i - j >= 0) {
                dp[i] = min(dp[i-j]+abs(a[i]-a[i-j]), dp[i]);
            }
        }
    }

    cout << dp[n-1] << endl;
}


int main() {
    solve();
	return 0;
}


Measured memory_bytes: 1024
#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; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll t,n,i,j,k,l,c,f;
	cin>>n;
	if(n>=400&&(n<600))cout<<8;
	else if(n>=600&&(n<800))cout<<7;
	else if(n>=800&&(n<1000))cout<<6;
	else if(n>=1000&&(n<1200))cout<<5;
	else if(n>=1200&&(n<1400))cout<<4;
	else if(n>=1400&&(n<1600))cout<<3;
	else if(n>=1600&&(n<1800))cout<<2;
	else if(n>=1800&&(n<2000))cout<<1;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<string> words(n);
  string s;
  for(int i = 0; i<n; i++){
    cin >> s;
    sort(s.begin(), s.end());
    words.at(i) = s;
  }
  sort(words.begin(), words.end());
  long long cont=1;
  long long ans = 0;
  for(int i = 1; i < n; i++){
    if(words.at(i) == words.at(i-1)){
      cont++;
    }
    else{
      ans += cont * (cont-1) / 2;
      cont = 1;
    }
  }
  ans += cont * (cont-1) / 2;
  cout << ans << endl;
}
        

Measured memory_bytes: 5760
#include <iostream>
#define LEN 10000
using namespace std;

int T[LEN];

int parent(int i) {return i/2;}
int left(int i) {return 2*i;}
int right(int i) {return 2*i+1;}

int main()
{

    int n,i,A[LEN+1];
    cin>>n;
    for(int i=1;i<=n;i++) cin>>A[i];

    for(int i=1;i<=n;i++){
        cout<< "node " << i << ": key = " << A[i] << ", ";
        if(parent(i)>=1) cout<< "parent key = " << A[parent(i)] << ", ";;
        if(left(i)<=n) cout << "left key = " << A[left(i)] << ", ";
        if(right(i)<=n) cout<< "right key = " <<A[right(i)] << ", ";
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define psp printf(" ")
#define endc printf("\n")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

const int maxn = 1e5 + 7; 

int dp[maxn];
vector<int> G[maxn];

inline bool dpsort(int x,int y) {
	return dp[x] > dp[y];
}

void dfs(int x) {
	dp[x] = 0;
	for (int j = 0; j < G[x].size(); j++) dfs(G[x][j]);
	sort(G[x].begin(), G[x].end(), dpsort);
	for (int i = 0; i < G[x].size(); i++) {
		dp[x] = max(dp[x], i+1+dp[G[x][i]]);
		
	}
}

int main() {
	int n; sd(n);
	for (int i = 2; i <= n; i++) {
		int x; sd(x); G[x].pb(i);
	}
	dfs(1);
	pd(dp[1]); endc;
}


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

int main(){
  int h,w; cin >> h >> w;
  vector<vector<char>> a(h,vector<char>(w));
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cin >> a[i][j];
    }
  }
  for(int i=0; i<h+2; i++){
    for(int j=0; j<w+2; j++){
      if(i==0||i==h+1||j==0||j==w+1) cout << "#";
      else cout << a[i-1][j-1];    
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
#define forn(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define FORR(i,a,b) for(int i = a; i >= b; i--)

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;

bool isPalim(string str){
    string op = str;
    reverse(all(op));
    //cout << "reverse -> " << op << endl;
    for(int i = 0; i < str.size(); i++){
        if(str.size() & 1 && str.size()/2 == i) continue;
        if(str[i] != op[i]) return false;
    }
    return true;
}

void solve(){
    string str;
    cin >> str;
    int n = str.size();
    string l, r;
    for(int i = 0; i < (n-1)/2; i++)
        l += str[i];
    for(int i = (n+2)/2; i < n; i++)
        r += str[i];

    //cout << l << " " << r << endl;
    //cout << str << endl;
    bool a = isPalim(l);
    bool b = isPalim(r);
    if(isPalim(str) && a && b)
        cout << "Yes\n";
    else
        cout << "No\n";
}

int main(){
    //int t; cin >> t;
    //while(t--) solve();

    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			String s=sc.next();
			String r="CODEFESTIVAL2016";
			int ans=0;
			for(int i=0;i<r.length();i++) if(s.charAt(i)!=r.charAt(i)) ans++;
			System.out.println(ans);


			/*
			 * CODEFESTIVAL2016
			 */
		}
	}
}

Measured memory_bytes: 10188
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

void dfs(int x, int pred, vector<int> &a, vector<vector<int>> &g) {
    if (pred != -1) a[x] += a[pred];

    for (int i : g[x]) {
        if (i != pred) dfs(i, x, a, g);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    vector<vector<int>> g(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> a(n);
    rep(i, q) {
        int x, y;
        cin >> x >> y;
        --x;
        a[x] += y;
    }

    dfs(0,-1, a, g);

    rep(i, n) {
        if (i >= 1) cout << " " ;
        cout << a[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 26624
a, b, c, d = (int(i) for i in input())
op = ["+", "-"]
for op_1 in op:
    ans_1 = eval("{}{}{}".format(a, op_1, b))
    for op_2 in op:
        ans_2 = eval("{}{}{}".format(ans_1, op_2, c))
        for op_3 in op:
            if eval("{}{}{}".format(ans_2, op_3, d)) == 7:
                print("{}{}{}{}{}{}{}=7".format(a, op_1, b, op_2, c, op_3, d))
                exit()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


const int N = (int) 1e5 + 100;
long long x[N], d[N], ad[N];
int p[N];

const int LOG = 60;
int up[N][LOG];

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%lld", &x[i]);
    
    for (int i = 0; i < n - 1; i++)
    {
        p[i] = i;
        d[i] = x[i + 1] - x[i];
    }


    int m;
    long long k;
    scanf("%d%lld", &m, &k);
    for (int i = 0; i < m; i++)
    {
        int xx;
        scanf("%d", &xx);
        xx -= 2;
        swap(p[xx], p[xx + 1]);
    }

    for (int i = 0; i < n - 1; i++)
        up[p[i]][0] = i;

    for (int j = 1; j < LOG; j++)
        for (int i = 0; i < n - 1; i++)
            up[i][j] = up[up[i][j - 1]][j - 1];

    for (int i = 0; i < n - 1; i++)
    {
        int np = i;
        for (int j = 0; j < LOG; j++)
            if (k & (1LL << j))
                np = up[np][j];
        ad[np] = d[i];
    }

    for (int i = 0; i < n - 1; i++)
        x[i + 1] = x[i] + ad[i];

    for (int i = 0; i < n; i++)
        printf("%lld\n", x[i]);

	return 0;
}




Measured memory_bytes: 27392
/*Saidur Rahman Sajol:A weirdo*/
  /*Dept. of CSE,IUBAT(162)*/
/*---------------------------*/

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

#define PI 2*acos(0.0)
#define l long long
#define ll long long 
#define ul unsigned long
#define ull unsigned long long

ull minimum(ull a,ull b){
  return (a<b)?a:b;
}
ull maximum(ull a,ull b){
  return (a>b)?a:b;
}
ull great(ull a,ull b){
	if(b==0) return a;
  return great(b,a%b);
}

int main(){
	char s[101];
    scanf("%s",s);
	int len=strlen(s);
	vector<char>pb;
	vector<char>::iterator ps;
	for(int i=len-9;i>=0;i--){
		pb.push_back(s[i]);
	}
	reverse(pb.begin(),pb.end());
	for(ps=pb.begin();ps!=pb.end();ps++){
		cout<<*ps;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N, M;
  cin >> N >> M;
  VEC<int> A(N);
  LL sum = 0;
  REP(i, 0, N) {
    cin >> A[i];
    sum += A[i];
  }
  int cnt = 0;
  REP(i, 0, N) {
    if ((double)sum / (4 * M) > A[i]) {
      continue;
    } else {
      cnt++;
    }
  }
  Yes(cnt >= M);

  return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	rep (i, 5) {
	  int x;
	  cin >> x;
	  if (x == 0) {
		cout << i + 1 << endl;
		return 0;
	  }
	}
    
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    string s;
    cin >> s;
    ll k;
    cin >> k;
    ll n = s.size()-1;
    ll ans = 0;
    bool same = true;
    ll now = 1;
    vector<ll> can;
    bool all = true;
    for(ll i = 0; i < n; i++){
        if(s[i] == s[i+1] && same){
            now++;
        } else if(s[i] == s[i+1]){
            now++;
            same = true;
        } else {
            all = false;
            can.push_back(now);
            now = 1;
        }
    }
    if(all){
        cout << s.size()*k/2 << endl;
        return 0; 
    }
    if(n > 0 && s[n-1] == s[n]) can.push_back(now);
    same = false;
    if(s[0] == s[n]) same = true;
    for(auto p:can){
        ans += p/2;
    }
    ans *= k;
    if(can.empty()){
        cout << k/2 << endl;
        return 0;
    }
    if(can[0]%2 != 0 && can.back()%2 != 0 && same) ans += k-1;
    cout << ans << endl;
}

Measured memory_bytes: 3556
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int n;
    int m;
 
   cin >> n >> m;
  
   cout << n+m/2 << endl;
   //cout << m << endl;
  
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
ans=0
for i in range(1,n+1):
    if(i>=k):
        ans+=(1/n)
    else:
        val=1
        ab=i
        while(ab<k):
            ab*=2
            val*=2
        val*=n
        ans+=(1/val)
print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int cnt,temp;
bool check;
char a[4]={'A','C','G','T'};
string S;

int main(){
    cin>>S;
    rep(i,S.length()){
        check=true;
        rep(j,4){
            if(a[j]==S[i]){
                temp++;
                check=false;
                break;
            }
        }
        if(check){
            cnt=max(cnt,temp);
            temp=0;
        }
    }
    cnt=max(cnt,temp);
    out(cnt);    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()


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

  if(x==3 || x==5 || x==7){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
## 2
#N, M = 314, 15
#A = [9, 26, 5, 35, 8, 9, 79, 3, 23, 8, 46, 2, 6, 43, 3]
N, M = map(int, input().split())
A = list(map(int, input().split()))


rest = N
for i in range(M):
    rest -= A[i]
    
if rest<0:
    print('-1')
else:
    print(rest)

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

using namespace std;

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

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<int> A;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    for (int i = N; i >= 1; --i) {
        int a = A[i-1];
        int j = i;
        int tmp = 0;
        while (j <= N){
            tmp += A[j-1];
            j += i;
        }

        if (tmp % 2 == 0){
            if (a == 0) {
                continue;
            }else{
                A[i-1] = 0;
            }
        }else{
            if (a == 0) {
                A[i-1] = 1;
            }else{
                continue;
            }
        }
    }

    ll M = 0;
    for (int k = 0; k < N; ++k) {
        M += A[k];
    }

    cout << M<< endl;

    for (int l = 0; l < N; ++l) {
        if (A[l] != 0) {
            cout << l+1 << endl;
        }
    }
}

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


Measured memory_bytes: 1908
#11_A
import random
class Dice:
    def __init__(self):
        self.dice=[i for i in range(6)]
        self.workspace=[i for i in range(6)]
        self.top=self.dice=[0]
        
    def set(self,numbers):
        self.dice=[i for i in numbers]
        self.workspace=[i for i in numbers]
        
    def rotate(self,command):
        if command == "W":
            self.workspace=[self.dice[2], self.dice[1], self.dice[5], self.dice[0], self.dice[4], self.dice[3]]
            self.dice=self.workspace
        elif command == "E":
            self.workspace=[self.dice[3], self.dice[1], self.dice[0], self.dice[5], self.dice[4], self.dice[2]]
            self.dice = self.workspace
        
        if command == "S":
            self.workspace=[self.dice[4], self.dice[0], self.dice[2], self.dice[3], self.dice[5], self.dice[1]]
            self.dice=self.workspace
        elif command == "N":
            self.workspace=[self.dice[1], self.dice[5], self.dice[2], self.dice[3], self.dice[0], self.dice[4]]
            self.dice=self.workspace
            
    def get_top(self):
        self.top=self.dice[0]
        print(self.top)
        
    def predict(self, num):
        for i in range(num):
            top, front = map(int, input().split())
            while(True):
                if top == self.dice[0] and front == self.dice[1]:
                    break
                command_num=random.randint(1,4)
                if command_num == 1:
                    self.rotate("W")
                elif command_num == 2:
                    self.rotate("E")
                elif command_num == 3:
                    self.rotate("S")
                elif command_num == 4:
                    self.rotate("N")
            print(self.dice[2])
            
    def getter(self):
        return self.dice[0], self.dice[1], self.dice[2]
    
    def predict_same(self, top, front, right):
        for n in range(30):
            if top ==self.dice[0] and front== self.dice[1] and right ==self.dice[2]:
                print("Yes")
                break
            command_num=random.randint(1,4)
            if command_num == 1:
                    self.rotate("W")
            elif command_num == 2:
                    self.rotate("E")
            elif command_num == 3:
                    self.rotate("S")
            elif command_num == 4:
                    self.rotate("N")
        
        if top!=self.dice[0] or front!=self.dice[1] or front!=self.dice[2]:
            print("No")
        
            
                
    
        
numbers=list(map(int,input().split()))
dice=Dice()
dice.set(numbers)
# commands=input()
# for i in range(len(commands)):
#     dice.rotate(commands[i])
# dice.get_top()
q=int(input())
dice.predict(q)


Measured memory_bytes: 8200
sx, sy, tx, ty  = map(int, input().split())

ans = ''
ans += 'R'*(tx-sx)+'U'*(ty-sy)
ans += 'L'*(tx-sx)+'D'*(ty-sy)

ans += 'D'+'R'*(tx-sx+1)+'U'*(ty-sy+1)+'L'
ans += 'U'+'L'*(tx-sx+1)+'D'*(ty-sy+1)+'R'

print(ans)


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


int main() {
    string a, b;
    cin >> a >> b;
    if (a.size() > b.size()) {
        cout << "GREATER" << endl;
    } else if (a.size() < b.size()) {
        cout << "LESS" << endl;
    } else if (a == b) {
        cout << "EQUAL" << endl;
    } else {
        for (int i = 0; i < a.size(); i++) {
            if (a[i] > b[i]) {
                cout << "GREATER" << endl;
                break;
            } else if (a[i] < b[i]) {
                cout << "LESS" << endl;
                break;
            }
        }
    }


    return 0;
}


Measured memory_bytes: 256
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, W; std::cin >> n >> W;
  int geta;
  int four = 4;
  std::vector<std::vector<lint>> data(four);
  rep(i,0,n) {
    int w, v; std::cin >> w >> v;
    if (i==0) geta = w;
    data.at(w-geta).emplace_back(v);
  }
  for (auto& v : data) {
    std::sort(all(v), std::greater<>{});
    std::partial_sum(all(v), v.begin());
    v.insert(v.begin(), 0);
  }
  debug(data);

  lint ans = 0;
  std::vector<std::size_t> sz(four);
  std::vector<std::size_t> ind(four);
  rep(i,0,4) sz[i] = data[i].size();
  for (ind[0]=0; ind[0]<sz[0]; ind[0]++)
  for (ind[1]=0; ind[1]<sz[1]; ind[1]++)
  for (ind[2]=0; ind[2]<sz[2]; ind[2]++)
  for (ind[3]=0; ind[3]<sz[3]; ind[3]++) {
    lint wt = 0, val = 0;
    rep(i,0,four) {
      wt += ind[i] * (geta+i);
      val += data[i].at(ind[i]);
    }
    debug(ind, wt, val);
    if (W < wt) continue;
    cmx(ans, val);
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256