akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>

#define max 5

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}
int int_sort( const void * a , const void * b ) {
  return strcmp(( char * )a , ( char * )b );
}

int main()
{
    int n, k, i, j, t;
    double kaku=0;
    
    scanf("%d%d", &n, &k);
    
    for (i=1; i<=n; i++) {
        j=0;
        while (i*powl(2.0, j)<k) {
            j++;
        }
        kaku+=powl(0.5, j)*1/n;
    }

    
    printf("%.16lf", kaku);
    
    return 0;
}



Measured memory_bytes: 256
$data = []
ans = []
def culc ope, level
	case ope
	when '+'
		result = 0
		exe = "+="
	when '*'
		result = 1
		exe = "*="
	end
	loop{
		if $data.empty? || $data.first.length < level 
			return result
		else
			tmp = $data.first.split("").last.to_s
			if tmp == '*' || tmp == '+'
				ans = culc $data.shift.split("").last.to_s, level + 1
			else
				ans = $data.shift.split("").last.to_i
			end
		end
		eval("result"+exe+"ans")
	}
end

loop{
	num = gets.to_i
	break if num == 0
	num.times do
		$data << gets.chomp 
	end
	if num == 1
		ans << $data.shift
	else
		ans << culc($data.shift, 2)
	end
}
ans.each do |a|
	puts a
end

Measured memory_bytes: 9748
#include <stdio.h>

int main(void)
{
	int a, b, c, tmp;

	scanf("%d%d%d", &a, &b, &c);

	tmp = a;
	a = b;
	b = tmp;

	tmp = a;
	a = c;
	c = tmp;

	printf("%d %d %d", a, b, c);

	return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int a[maxn], b[maxn], a1[maxn], b1[maxn];
int  v[maxn], match[maxn];
int n;//12321321321
vector < int > g[maxn];
bool dfs(int x)
{
	int y;
	for(int i = 0; i < g[x].size(); i++){
		y = g[x][i];
		if(!v[y]){
			v[y] = 1;
			if(!match[y] || dfs(match[y])){
				match[y] = x;
				return true;
			}
		}
	}
	return false;
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d %d", a + i, b + i);
	}
	for(int i = 1; i <= n; i++){
		scanf("%d %d", a1 + i, b1 + i);
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(a[i] < a1[j] && b[i] < b1[j]){
				g[i].push_back(j);
			}
		}
	}
	int ans = 0;
	for(int i  = 1; i <= n; i++){
		memset(v, 0, sizeof(v));
		if(dfs(i))ans++;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
intervals = []
(n - 1).times do
  intervals << gets.split.map(&:to_i)
end

(n - 1).times do |start|
  time = 0
  intervals[start..n - 1].each do |interval|
    time = [time, interval[1]].max
    time += interval[2] - (time % interval[2]) if time % interval[2] != 0
    time += interval[0]
  end
  puts time
end
puts 0


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

int main()
{
    ll N;
    cin >> N;
    ll maxHeight=0;
    ll totalHeight=0;

    while(N--)
    {
        ll height;
        cin >> height;
        if(height >= maxHeight)
        {
            maxHeight = height;
        }
        else if(height < maxHeight)
        {
            totalHeight += maxHeight - height;
        }
    }
    cout << totalHeight;
    return 0;
}

Measured memory_bytes: 3632
// Author : Radhesh Sarma
   #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #pragma comment(linker, "/stack:200000000")
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast")
  #pragma GCC optimize("unroll-loops")
    using namespace std;
  using namespace __gnu_pbds;
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define endl "\n"
    #define int long long
    #define all(v) v.begin(),v.end()
    #define rep(i,a,b) for(int i = a; i <=b; i++)
    #define rep2(i,a,b) for(int i = a; i>=b; i--)
    #define f first
    #define s second
    #define PB push_back
    #define MP make_pair
    #define db long double
    #define trace1(x)                cerr<<#x<<": "<<x<<endl
    #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
    #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
    #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
    #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
    #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
    #define cases int testcases;cin>>testcases; while(testcases--)
    #define INF 2000000000
    const double PI = acos(-1);
    const int N =  200005;

    int dp[N];
    int wt[105];
    int v[105];

    bool vis[105];
  int32_t main() 
  {
    IOS

        
      
    // dp[i] denotes the maximum possible sum of values that can be in Knapsack of weight i


    dp[0] = 0;
    

    //dp[i] = max(dp[i],dp[i-w[j]] + v[j])



    int n,W;
    cin >> n >> W;


    for(int i = 1;i <= n; i++)
    {
      cin >> wt[i] >> v[i];
    }


    
    for(int i = 1; i <= n; i++)
    {
      for(int j = W; j >=0; j--)
      {
        if(j + wt[i] <= W)
               dp[j+wt[i]] = max(dp[j + wt[i]],dp[j] + v[i]);
      }
    }

    cout << dp[W];
    return 0;
  }

Measured memory_bytes: 1024
# move all A's to the back whenever you see ABC i.e it becomes BCA
# Example ABCBCBC after operation it becomes BCBCBCA
# Count the consecutive no of BC and whenever u see a A add the count to answer that many moves required to move A to last
# if it's not A or any other string make cnt as 0
def main():
	s = input()
	cnt = 0
	prev =0
	ans = 0
	i = len(s)-1
	while i>=0:
		if s[i]=='C' and s[i-1]=='B':
			cnt = cnt+1
			i = i-2
		else:
			if s[i]=='A':
				ans = ans+cnt
			else:
				cnt = 0
			i = i-1
	print(ans)
if __name__=="__main__":
	main()

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

#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back
#define int long long

const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9 + 10;

typedef pair<int, int> ii;

int n, m, L = 1, R = oo;
ii val[N];
bool visit[N];
vector<ii> vi[N];

void load(int u)    {
    if(val[u].fi == 1) L = max(L, 1 - val[u].se);
    else R = min(R, val[u].se - 1);
    if(L > R)   {
        cout << "0";
        exit(0);
    }
}

void trace(int pre, int u)  {
	if(val[u].fi <= 0) {
		cout << "0"; exit(0);
	}
    visit[u] = true;
    for(auto v: vi[u]) if(v.fi != pre) {
        if(visit[v.fi]) {
            if(val[v.fi].fi + val[u].fi != v.se) {
                cout << "0"; exit(0);
            }
        } else {
            val[v.fi].fi = v.se - val[u].fi;
            trace(u, v.fi);
        }
    }
}

void calc(int cur)  {
    FOR(i, 1, n) visit[i] = false;
    val[1] = ii(cur, 0);
    trace(1, 1);
    cout << "1"; exit(0);
}

void dfs(int pre, int u)    {
    visit[u] = true;
    load(u);
    for(auto v: vi[u]) if(v.fi != pre)  {
        if(visit[v.fi] == true)    {
            if(val[v.fi].fi != val[u].fi)  {
                if(v.se != val[v.fi].se + val[u].se) {
                    cout << "0"; exit(0);
                }
            } else {
                int a = val[v.fi].fi * 2;
                int b = val[v.fi].se + val[u].se;
                if((v.se - b) % 2 || (v.se - b) / a <= 0)  {
                    cout << "0"; exit(0);
                }
                calc((v.se - b) / a); exit(0);
            }
        } else {
            val[v.fi].fi = -val[u].fi;
            val[v.fi].se = v.se - val[u].se;
            dfs(u, v.fi);
        }
    }
}

signed main()
{
    //freopen("test.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    FOR(i, 1, m)    {
        int u, v, s; cin >> u >> v >> s;
        vi[u].pb(ii(v, s));
        vi[v].pb(ii(u, s));
    }
    val[1] = ii(1, 0);
    dfs(1, 1);
    cout << R - L + 1;
    // :D
    return 0;
}

Measured memory_bytes: 16256
s = input()
flg = 1
if (s[0] != 'A'):
    flg = 0
cnt = 0
for i in s[2:-1]:
    if (i == 'C'): cnt+= 1
if (cnt != 1):
    flg = 0 

cap = 0
for i in s:
    if ('A' <= i <= 'Z'): cap += 1
if (cap != 2):
    flg = 0
if (flg): print("AC")
else: print("WA")

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

int main() {
	int N;
	cin >> N;
	if (N < 10) {
		cout << N << endl;
	}
	else if (N < 100) {
		cout << 9 << endl;
	}
	else if (N < 1000) {
		cout << 9 + (N - 99) << endl;
	}
	else if (N < 10000) {
		cout << 9 + 900 << endl;
	}
	else if (N < 100000) {
		cout << 9 + 900 + (N - 9999) << endl;
	}
	else {
		cout << 9 + 900 + (99999 - 9999) << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a,b;cin >> n >> a >> b;
	cout << min(a*n,b) << endl;
}


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

int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h.at(i);
    }
    int ans=1;
    int saidai=h.at(0);
    for(int i=1;i<n;i++){
        if(h.at(i)>=saidai){
            ans++;
        }
        saidai=max(saidai,h.at(i));
    }
    cout<<ans<<endl;
}


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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;



void solve()
{
	int n;
	cin >> n;
	int arr[n];
	lop(i, 0, n) cin >> arr[i];

	int ans = 0;
	lop(i, 0, n)
	{
		lop(j, i + 1, n)
		{
			lop(k, j + 1, n)
			{
				int a = arr[i], b = arr[j], c = arr[k];

				set<int> st = {a, b, c};
				if ( (int)st.size() != 3 ) continue;
				if ( a + b > c and b + c > a and a + c > b ) ans++;
			}
		}
	}

	cout << ans << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

	int test = 1;
	// cin >> test;
	while (test--)solve();


}





















Measured memory_bytes: 3644
N = int(input())

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

c = 0
max_c = 0
i = 0

while i < N-1:
    j = i+1
    while j < N:
        if H[i] < H[j]:
            i = j
            break
        else:
            c += 1
            j += 1
            i += 1
    if max_c < c:
        max_c = c
    c = 0

print(max_c)

Measured memory_bytes: 14228
#include <stdio.h>
int main(void)
{
     int x, y;
     while(1){
     scanf("%d %d",&x,&y);
     if(x==0 && y==0)   break;
     else if(x>y)  printf("%d %d\n",y,x);
     else  printf("%d %d\n",x,y); 
    }
     return 0;
}



Measured memory_bytes: 2052
/*
 _____ ____ _____   ___   ___   ___   ___ 
|_   _/ __ \_   _| |__ \ / _ \ |__ \ / _ \
  | || |  | || |      ) | | | |   ) | | | |
  | || |  | || |     / /| | | |  / /| | | |
 _| || |__| || |_   / /_| |_| | / /_| |_| |
|_____\____/_____| |____|\___/ |____|\___/ 
*/
#include <bits/stdc++.h>
#include <fstream>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
// pair<int,int>ert(x==y); gives run time when false
using namespace std;
int main()
{
    CIN;
    vi v= {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << v[k-1];
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		String s = sc.next();

		long count_plus = s.chars().filter(c -> c == '+').count();
		long count_minus = s.chars().filter(c -> c == '-').count();

		System.out.println(count_plus - count_minus);
	}
}

Measured memory_bytes: 27476
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long 
const int N=1e5+5;
int n,cou=0;
string s;
vector<int>a,b, test;
int ind_a=-1, ind_b=-1, ind=1;

int32_t main(){
	IOS;
	
	//code
	cin>>n;
	test.resize(n);
	a.resize(n);
	b.resize(n);
	for(int i=0;i<n;i++)
		test[i]=i+1;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>b[i];
	do{
	
		int flag1=0, flag2=0;
		if(ind_a==-1){
			for(int i=0;i<n;i++){
				if(test[i]!=a[i])
					flag1=1;
			}
		}
		if(!flag1 && ind_a==-1)
			ind_a=ind;
		
		if(ind_b==-1){
			for(int i=0;i<n;i++){
				if(test[i]!=b[i])
					flag2=1;
			}
		}
		if(!flag2 && ind_b==-1)
			ind_b=ind;
		
		ind++;
	}while(next_permutation(test.begin(), test.end()) );
	cout<<abs(ind_a-ind_b)<<endl;
	//code
	
	return 0;

}

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

int main(void){
    int n;cin>>n;
    string tmp="";
    map<string, int> m;
    for(int i=0;i<n;i++){
        cin>>tmp;
        m[tmp]++;
    }
    int value = -1;
    for(auto i=m.begin();i!=m.end();++i){
        if(i->second>value)value=i->second;
    }
    vector<string> ans;
    for(auto i=m.begin();i!=m.end();++i){
        if(i->second==value){ans.push_back(i->first);}
    }
    for(auto itr=ans.begin();itr!=ans.end();++itr){
        cout<<*itr<<endl;
    }
}


Measured memory_bytes: 26868
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, x) for(ll i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9+7;
const ll N = 5e5+5, inf = 1e9+5000;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n; cin >> n;
  string s; cin >> s;
  
  int rr = 0;
  rep (i, n) {
    if (s[i] == 'R') {
      rr++;
    }
  }
  int r_inplace = 0;
  for (int i = 0; i < rr; i++) {
    if (s[i] == 'R') r_inplace++;
  }
  cout << rr-r_inplace << endl;

  return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

using namespace std;

int main()
{
	long long int x, y; cin >> x >> y;
	int ans = 0;
	while (y >= x)
	{
		x *= 2;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	static int n,k;
	static string s[10010];
	
	cin >> n >> k;
	rep(i,n)cin >> s[i];
	
	int cnt[30] = {};
	rep(i,n)cnt[s[i][0]-'A'] ++;
	
	for(int i = n ; i >= 0 ; i --){
		int sum = 0;
		rep(j,26)sum += min ( cnt[j] , i );
		if(sum >= i*k){
			cout << i << endl;
			return 0;
		}
	}
}



Measured memory_bytes: 896
import math
a,b,h,m = map(int, input().split())
mi = m + h*60 
x = 2*math.pi /(12*60)
y = 2*math.pi /60
an = abs(x-y)*mi
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(an))
print(c)

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

int main()
{
    long long n, k;
    std::cin >> n >> k;

    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    const int mod = 1000000007;
    long long p = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i] > a[j]) {
                p++;
                p %= mod;
            }
        }
    }

    long long q = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i] > a[j]) {
                q++;
                q %= mod;
            }
        }
    }

    long long p_ans = p * k % mod;
    long long q_ans = k * (k - 1) / 2 % mod;
    q_ans *= q;
    q_ans %= mod;

    long long ans = p_ans + q_ans;
    ans %= mod;

    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
import heapq
import sys
input = sys.stdin.readline
 
 
def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))

    M = min(N, K)
    ans = 0
    for m in range(1, M+1):
        for l in range(m+1):
            Q = []
            for i in range(l):
                Q.append(V[i])
            r = m-l
            for i in range(r):
                Q.append(V[N-1-i])
            heapq.heapify(Q)

            for _ in range(K-m):
                if len(Q)==0:
                    break
                q = heapq.heappop(Q)
                if q>=0:
                    heapq.heappush(Q, q)
                    break
            
            ans = max(ans, sum(Q))
    
    print(ans)

 
if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

/*bool operator<(const data &d)const{
	return hoge;
}*/

void merge(set<int>&a,set<int>&b){
	for(auto e:a)b.insert(e);
	for(auto e:b)a.insert(e);
}

 
signed main(){
	IOS();
	int N;
	vector<int>ans;
	while(cin>>N,N){
		vector<int>v[30];
		rep(i,0,N){
			int t;
			cin>>t;
			rep(j,0,t){
				int tt;
				cin>>tt;
				tt--;
				v[tt].push_back(i);
			}
		}
		set<int>st[N];
		rep(i,0,N)st[i].insert(i);
		int flg = 0;
		rep(i,0,30){
			rep(j,0,v[i].size()){
				rep(k,j+1,v[i].size()){
					merge(st[v[i][j]],st[v[i][k]]);
					if(st[v[i][j]].size()==N||st[v[i][k]].size()==N){
						flg = 1;
						break;
					}
				}
				if(flg)break;
			}
			if(flg){
				ans.push_back(i+1);
				break;
			}
			if(i==30-1)ans.push_back(-1);
		}
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define P 998244353

using namespace std;

typedef long long ll;

int n;

ll powmod(ll x, ll y = P - 2, ll p = P) {
	x %= p;
	ll ans = 1;
	while(y) {
		if(y & 1) ans = ans * x % p;
		x = x * x % p;
		y >>= 1;
	}
	return ans;
}

ll A[1 << 18];

int main() {
	scanf("%d", &n);
	ll tot = 0;
	for(int i = 0; i < (1 << n); i++) scanf("%lld", &A[i]), tot += A[i];
	ll rtot = powmod(tot);
	for(int i = 0; i < (1 << n); i++) A[i] = A[i] * rtot % P;
	for(int i = 1; i < (1 << n); i *= 2)
		for(int j = 0; j < (1 << n); j += i + i)
			for(int k = 0; k < i; k++) {
				ll a = A[j + k], b = A[j + i + k];
				A[j + k] = (a + b) % P;
				A[j + i + k] = (a - b) % P;
			}
	for(int i = 0; i < (1 << n); i++) A[i] = powmod(1 - A[i]);
	for(int i = 1; i < (1 << n); i *= 2)
		for(int j = 0; j < (1 << n); j += i + i)
			for(int k = 0; k < i; k++) {
				ll a = A[j + k], b = A[j + i + k];
				A[j + k] = (a + b) % P;
				A[j + i + k] = (a - b) % P;
			}
	for(int i = 0; i < (1 << n); i++) printf("%lld\n", ((A[0] - A[i]) % P + P) % P);
	return 0;
}

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

namespace ABC163
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_B();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var r = Ex.ReadInt;
            Ex.Cw(r * 2 * Math.PI);
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
            // i番目の宿題をやるにはAi日間

            var l1 = Ex.ReadLongArray();
            var l2 = Ex.ReadLongArray();

            // 夏休みはN日間
            var n = l1[0];
            // 宿題がM個
            var m = l1[1];

            for (int i = 0; i < m; i++) n -= l2[i];

            Math.Max(-1, n).Cw();

        }
    }
    public class ABC_C
    {
        public ABC_C()
        {

        }
    }
    public class ABC_D
    {
        public ABC_D()
        {
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {
        }
    }
    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }

        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static string yesno(this bool b) { return b ? "yes" : "no"; }
        public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        public static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 20488
import java.util.*;

class Main{
  public static void main(String[] args){
    try(Scanner sc = new Scanner(System.in)){
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      int c = Integer.parseInt(sc.next());
      int d = Integer.parseInt(sc.next());
      System.out.println(Math.min(a, b) + Math.min(c, d));
    }
  }
}
        

Measured memory_bytes: 23764
unittest
{
	assert( [ "aab", "xyz" ].solve == "No" );		// 追加ケース
	assert( [ "xyz", "aab" ].solve == "No" );		// 追加ケース
	
	assert( [ "azzel", "apple" ].solve == "Yes" );
	assert( [ "chokudai", "redcoder" ].solve == "No" );
	assert( [ "abcdefghijklmnopqrstuvwxyz", "ibyhqfrekavclxjstdwgpzmonu" ].solve == "Yes" );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	input.popFront;
	auto t = input.front.to!( dchar[] );
	
	dchar[ dchar ] sts;
	dchar[ dchar ] tss;
	foreach( sc, tc; lockstep( s, t ) )
	{
		if( ( sc in sts && sts[ sc ] != tc ) || ( tc in tss && tss[ tc ] != sc ) ) return "No";
		sts[ sc ] = tc;
		tss[ tc ] = sc;
	}
	return "Yes";
}


Measured memory_bytes: 6084
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
A = get_ints

sa = 0
A.combination(2) do |a, b|
  x = (a - b).abs
  sa = x if x > sa
end

puts sa


Measured memory_bytes: 14496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


struct edge{ ll to,cost; };
ll V;
vector<edge> G[500010];
ll d[500010];

void dijkstra(ll s){
    fill(d,d+500010,inf);
    d[s]=0;
    priority_queue<l_l,vector<l_l>,greater<l_l>> que;
    que.push(l_l(0,s));
    while(!que.empty()){
        l_l p=que.top();que.pop();
        ll v=p.second;
        if(d[v]<p.first)continue;
        if(G[v].size()>0){
            rep(i,0,G[v].size()-1){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(l_l(d[e.to],e.to));
                }
            }
        }
    }
}


int main(){fastio
    ll h,w;cin>>h>>w;
    ll c[10][10];
    rep(i,0,9)rep(j,0,9)cin>>c[i][j];
    edge e;
    rep(i,0,9){
        rep(j,0,9){
            e.to=i;
            e.cost=c[i][j];
            G[j].pb(e);
        }
    }
    d[1]=0;
    dijkstra(1);
    ll a[h][w];rep(i,0,h-1)rep(j,0,w-1)cin>>a[i][j];
    ll ans=0;
    rep(i,0,h-1){
        rep(j,0,w-1){
            if(a[i][j]==-1)continue;
            ans+=d[a[i][j]];
        }
    }
    cout<<ans<<endl;
    
    return 0;
}



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

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int> dp(N+1);
	for (int i = 0; i < N+1; ++i) {
		dp[i] = i;
	}
	for (int i = 0; i < N+1; ++i) {
		for (int j = 6; i+j < N+1; j *= 6) {
			dp[i+j] = min(dp[i+j],dp[i]+1);
		}
		for (int j = 9; i+j < N+1; j *= 9) {
			dp[i+j] = min(dp[i+j],dp[i]+1);
		}
	}
	cout << dp[N] << endl;
	return 0;
}


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

def solve(S: str):
    ans = ["x"] * len(S)
    print("".join(ans))


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

if __name__ == '__main__':
    main()


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

int main() {
  char c;
  cin >> c;
  if (c == 'a') {
    cout << "vowel" << endl;
    }
  else if (c == 'i') {
    cout << "vowel" << endl;
    }
  else if (c == 'u') {
    cout << "vowel" << endl;
    }
  else if (c == 'e') {
    cout << "vowel" << endl;
    }
  else if (c == 'o') {
    cout << "vowel" << endl;
    }
  else {
    cout << "consonant" << endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

struct UnionFind {
    vector<int> d;

    UnionFind(int N=0) : d(N, -1){} 

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }

    bool unite(int x, int y) {
        x = find(x); 
        y = find(y); 
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x; 
        return true;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x){
        return -d[find(x)];
    }
};

int main(){
    int N,M; cin >> N >> M;
    vector<int> p(N);
    rep(i,N) cin >> p[i];
    UnionFind uf(N+1);
    vector<vector<int>> edges(N);
    rep(i,M){
        int x, y; cin >> x >> y;
        uf.unite(x, y);
    }

    int ans = 0;
    rep(i,N){
        if (uf.same(i+1, p[i])) ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 6384
main = do
    [n,a,b] <- map read . words <$> getLine
    h <- map read . words <$> getContents
    print $ solve h a b
inf = 10^9+1
solve h a b = bs inf 0 (f h a b)
  where bs ok ng f
          | abs (ok-ng) <= 1 = ng + 1
          | f mid = bs mid ng f
          | otherwise = bs ok mid f
            where mid = (ok + ng) `div` 2
        f h a b c = s <= c
          where s = sum [max 0 (hi - b*c + a - b - 1) `div` (a-b) | hi <- h]


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

using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string a, b;
  cin >> a >> b;

  if (a.size() > b.size()) {
    cout << "GREATER";
  } else if (a.size() < b.size()) {
    cout << "LESS";
  } else {
    int cmp = memcmp(a.data(), b.data(), a.size());
    if (cmp < 0) {
      cout << "LESS";
    } else if (cmp > 0) {
      cout << "GREATER";
    } else {
      cout << "EQUAL";
    }
  }
  cout << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

long  a[100005];
long  s[100005];

int main(int argc, char* argv[])
{
    char str[5]={0};
    scanf("%s", str); 

    if(str[0]==str[1] && str[1]==str[2]) {
        printf("Yes\n");
    }
    else if (str[2]==str[3] && str[1]==str[2]) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }   
 
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

class Graph{
	private:
	int V;
	vvp List;
	void bfs(vi a,int s,vb& b,vb used){
		queue<P> que;
		for(int i=0;i<a.size();i++){
			que.push(P(a[i],0));
			b[a[i]]=used[a[i]]=1;
		}
		while(!que.empty()){
			P p=que.front();
			que.pop();
			if(p.second==s) continue;
			for(int i=0;i<List[p.first].size();i++){
				int v=List[p.first][i].first;
				if(!used[v]){
					b[v]=used[v]=1;
					if(p.second<s-1) que.push(P(v,p.second+1));
				}
			}
		}
	}
	ll DIJ(int s,int t){
		priority_queue<pair<ll,ll> > que;
		vector<ll> d(V,INF);
		d[s]=0;
		que.push(P(0,s));
		while(!que.empty()){
			pair<ll,ll> p=que.top();
			que.pop();
			int v=p.second;
			if(d[v]<-p.first) continue;
			for(int i=0;i<List[v].size();i++){
				ll F=List[v][i].first,S=List[v][i].second;
				if(d[F]>d[v]+S){
					d[F]=d[v]+S;
					que.push(pair<ll,ll>(-d[F],F));
				}
			}
		}
		return d[t];
	}
	public:
	Graph(int v){
		V=v;
		List=vvp(v);
	}
	void add_edge(int s,int t,int c){
		List[s].push_back(P(t,c));
	}
	ll solve(vp e,int s,int p,int q,vi a){
		vb b(V),used(V);
		bfs(a,s,b,used);
		Graph sg(V);
		set<int> Set;
		for(int i=0;i<a.size();i++) Set.insert(a[i]);
		for(int i=0;i<e.size();i++){
			vi st(2);
			st[0]=e[i].first;
			st[1]=e[i].second;
			if(Set.find(st[0])!=Set.end()||Set.find(st[1])!=Set.end()) continue;
			for(int j=0;j<2;j++){
				int S=st[j],T=st[(j+1)%2];
				if(T==0||T==V-1) sg.add_edge(S,T,0);
				else if(b[T]) sg.add_edge(S,T,q);
				else sg.add_edge(S,T,p);
			}
		}
		return sg.DIJ(0,V-1);
	}
};

int n,m,k,s,p,q;
vi a;
vp e;

int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m>>k>>s>>p>>q;
	a=vi(k);
	e=vp(m);
	Graph g(n);
	for(int i=0;i<k;i++){
		cin>>a[i];
		a[i]--;
	}
	for(int i=0;i<m;i++){
		int S,T;
		cin>>S>>T;
		g.add_edge(S-1,T-1,0);
		g.add_edge(T-1,S-1,0);
		e[i]=P(S-1,T-1);
	}
	cout<<g.solve(e,s,p,q,a)<<endl;
}

Measured memory_bytes: 24012
import java.util.*;
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int count = 0;
    for(int i = 1; i <= N; i++) {
      int test = i;
      int num = 0;
      while( test > 0 ) {
        test /= 10;
        num++;
      }
      if( num % 2 != 0 ){
        count++;
      }
    }
    System.out.println(count);
  }
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    for (int i = 0; i < N; i++)
        cin >> V[i];

    long long res = 0;
    for (int l = 0; l <= K; l++) {
        for (int r = 0; r <= K - l; r++) {
            if (l + r > N) break;

            int d = K - (l + r);

            long long sum = 0;
            vector<int> chosen;
            for (int i = 0; i < l; i++) {
                sum += V[i];
                chosen.push_back(V[i]);
            }
            for (int i = N - r; i < N; i++) {
                sum += V[i];
                chosen.push_back(V[i]);
            }
            sort(chosen.begin(), chosen.end());
            for (int i = 0; i < d; i++) {
                if (i >= chosen.size()) break;
                if (chosen[i] < 0)
                    sum -= chosen[i];
            }
            res = max(res, sum);
        }
    }
    cout << res << endl;
    return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

ll  fct[2000020], inv[2000020];
void finit(int cmx, ll mod){
	auto bin_pows =[](ll x, ll n, ll mod){
		ll res = 1LL;
		for(; n > 0; n >>=1, x = x*x %mod) if(n & 1) res = res * x %mod;
		return res;
	};
	fct[0] = fct[1] = inv[1] = 1;
	for(int i=2;i<cmx+3;i++) fct[i] = fct[i-1] * i % mod;
	inv[cmx] = bin_pows(fct[cmx], mod-2, mod);
	for(int i=cmx;i>=1;i--) inv[i-1] = inv[i] * i % mod;
}
ll nCk(ll n, ll k, ll mod) {
	if(k > n) return 0;
	ll ret =fct[n] * inv[k] % mod * inv[n-k] % mod;
	return ret;
}

int main() {
	//cin.tie(0); ios_base::sync_with_stdio(false);
	finit(2000010, MD);
	int x, y;
	cin >>x >>y;
	
	if((x+y)%3){puts("0"); return 0;}
	
	//a + 2b= x, 2a +b = y
	int a = (2*y -x)/3;
	int b = y - 2*a;
	if(a<0 || b<0 ) {puts("0"); return 0;}
	
	cout << nCk(a+b, a, MD) <<"\n";
	return 0;
}


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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for (int i = 0; i < M; i++) cin >> B[i];
  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    int tmp = 0;
    for (int j = 0; j < M; j++) {
      tmp += A[i][j]*B[j];
    }
    if (tmp+C > 0) res++;
  }
  cout << res;
}


Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;
const int maxn = 2000100;

///Convert string to int
template <typename T>
int to_int(T num)
{
    int val;
    stringstream stream;
    stream << num;
    stream >> val;
    return val;
}

int main(){
        _
        string a, b; cin >> a>> b;
        string c = a+b;
        int x = to_int(c);
        int sq = sqrt(x);
        if(sq*sq == x)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;


return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int n;
    int a, b, c, d;
    int count;
        
    while(scanf("%d", &n) != EOF){
        count = 0;
        for(a = 0; a < 10; a++){
            for(b = 0; b < 10; b++){
                for(c = 0; c < 10; c++){
                    for(d = 0; d < 10; d++){
                        if(a + b + c + d == n){
                            count++;
                            break;
                        }
                    }
                }
            }
        }
        printf("%d\n", count);
    }

    return 0;
}

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

cnt = 0
num = 1

while num < k:
    num *= 2
    cnt += 1

coin = 0

coin_num = k // 2


for i in range(1, n+1):
    num = i
    cnt = 0
    while num < k:
        num *= 2
        cnt += 1
    coin += float(0.5**cnt) 

print('{:.10f}'.format(coin / n))

Measured memory_bytes: 3188
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public class Main {
    private static final Scanner scanner = new Scanner(System.in);
    private static final Consumer<List<String>> consumer = solve();

    public static void main(String[] args) {
        consumer.accept(readInput());
    }

    private static List<String> readInput() {
        final List<String> lineList = new ArrayList<>();
        while (scanner.hasNextLine()) {
            lineList.add(scanner.nextLine());
        }
        return lineList;
    }

    static Consumer<List<String>> solve() {
        return args -> {
            Deque<Character> deque = new ArrayDeque<>();
            int cnt = 0;
            for (char c: args.get(1).toCharArray()) {
                if (c == '(') {
                    cnt++;
                    deque.addLast('(');
                } else {
                    if (cnt > 0) {
                        cnt--;
                        deque.addLast(')');
                    } else {
                        deque.addFirst('(');
                        deque.addLast(')');
                    }
                }
            }
            while (cnt-- > 0) {
                deque.addLast(')');
            }
            StringBuilder sb = new StringBuilder();
            for (char c: deque) {
                sb.append(c);
            }
            System.out.println(sb.toString());
        };
    }

}

Measured memory_bytes: 26704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  ll X;
  cin >> X;
  ll a = X /500;
  ll b = (X % 500) / 5;
  cout << 1000 * a + 5* b <<endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int n, p[100], i, j, a, b=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&p[i]);
    
    a=p[0];
    for(i=1;i<n;i++){
        if(p[i]>a){
            a=p[i];
            j=i;
        }
    }
    
    for(i=0;i<n;i++){
        b+=p[i];
        if(i==j) b=b-p[i]/2;
    }
    printf("%d\n",b);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<ll> X(N), Y(M);
  for (ll i = 0; i < N; i++)
  {
    cin >> X.at(i);
  }
  for (ll i = 0; i < M; i++)
  {
    cin >> Y.at(i);
  }

  ll ansx = 0;
  for (ll i = 0; i < N - 1; i++)
  {
    ll tmp = (i + 1) * (N - 1 - i) % MOD * (X.at(i + 1) - X.at(i)) % MOD;
    ansx += tmp;
    ansx %= MOD;
  }

  ll ansy = 0;
  for (ll i = 0; i < M - 1; i++)
  {
    ll tmp = (i + 1) * (M - 1 - i) % MOD * (Y.at(i + 1) - Y.at(i)) % MOD;
    ansy += tmp;
    ansy %= MOD;
  }

  //cerr << ansx << " " << ansy << endl;

  ll ans = ansx * ansy % MOD;
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#define REP(i,N) for(int i=0;i<(N);++i)
using namespace std;
class tree{
public:
  bool parent;
  vector<int> child;
};
vector<tree> t;
int N,K;
int ans;
int func(int place){
  if(t[place].child.empty()){
    ++ans;
    return 1;
  }
  if(t[place].parent){
    ++ans;
    REP(i,t[place].child.size()){
      func(t[place].child[i]);
    }
    return 0;
  }
  int dep = 1000000;
  REP(i,t[place].child.size()){
    dep = min(dep,func(t[place].child[i]));
  }
  if(dep < K)++ans;
  return dep + 1;
}
int main(){
  cin >> N >> K;
  t.resize(N+1);
  REP(i,N){
    int j = i + 1;
    int d;
    cin >> d;
    t[j].parent = d == 0;
    t[d].child.push_back(j);
  }
  REP(i,N){
    int j = i + 1;
    if(t[j].parent){
      func(j);
    }
  }
  cout << ans << endl;
  return 0;
}



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

const int N = 1e6 + 1;
bool good[N];
void Solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    map<int, int> mm;
    for(int i = 0; i < n; i++){
        cin>>v[i];
        ++mm[v[i]];
        if(mm[v[i]] > 1) good[v[i]] = true;
    }
    sort(v.begin(), v.end());
    if(v[0] == 1){
        if(good[1]) cout<<0<<'\n';
        else cout<<1<<'\n';
        return;
    }
    int res = 0;
    for(int i = 0; i < n; i++){
        if(!good[v[i]]) res++;
        int p = v[i];
        for(int j = 2 * p; j < N; j += p){
            good[j] = true;
        }
    }
    cout<<res<<'\n';
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    //cin>>T;
    while(T--){
        Solve();
    }
}

Measured memory_bytes: 13484
#include <stdio.h>

int main() {
    int N;
    scanf("%d",&N);
    int A[N];
    int B[N];
    int ans = 0;
    for (int i = 0; i<N-1; i++) {
        scanf("%d",&B[i]);
    }
    for (int i = 0; i<N-2; i++) {
        if (B[i] < B[i+1]) {
            A[i+1] = B[i];
        }else{
            A[i+1] = B[i+1];
        }
    }
    A[0] = B[0];
    A[N-1] = B[N-2];
    for (int i = 0; i<N; i++) {
        ans = ans + A[i];
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128