akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int h,w;
string s[110];
bool ha[110],li[110];

int main()
{
	cin>>h>>w;
	for(int i=0; i<h; i++)cin>>s[i];
	for(int i=0; i<h; i++)
	{
		bool f=1;
		ha[i]=1;
		for(int j=0; j<w; j++)
		{
			if(s[i][j]=='#')
			{
				f=0;
				break;
			}
		}
		if(f)ha[i]=0;
	}
	for(int i=0; i<w; i++)
	{
		bool f=1;
		li[i]=1;
		for(int j=0; j<h; j++)
		{
			if(s[j][i]=='#')
			{
				f=0;
				break;
			}
		}
		if(f)li[i]=0;
	}
	for(int i=0; i<h; i++)
	{
		bool f=0;
		for(int j=0; j<w; j++)
		{
			if((ha[i])&&(li[j]))
			{
				cout<<s[i][j];
				f=1;
			}
		}
		if(f)puts("");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	for (int i = 0; i+2 < N; i++)
	{
		if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C')ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
<?php
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++){
  list($a,$b,$c)=explode(' ',trim(fgets(STDIN)));
  if($b<$a){$d=$a;$a=$b;$b=$d;}
  if($c<$b){$d=$b;$b=$c;$c=$d;}
  $a*=$a;
  $b*=$b;
  $c*=$c;
  echo ($a+$b==$c)?'YES':'NO',PHP_EOL;
}

Measured memory_bytes: 15256
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

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

   int ans = min(a*n,b);

   cout << ans << endl;


   return 0;
}

Measured memory_bytes: 256
def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


n = int(input())

ans = 0
for i in [2 * x + 1 for x in range((n + 1) // 2)]:
    if len(make_divisors(i)) == 8:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;

int main() {
	int h, n;
	cin >> h >> n;
	int sum = 0;
	rep(i, n){
		int a;
		cin >> a;
		sum += a;
	}
	string ans = "No";
	if(sum >= h) ans = "Yes";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var s = ReadLine();
            var n = s.Length;
            for (var i = 1; ; ++i)
            {
                var num = n / 2 - i;
                var t = s.Take(num).ToArray();
                var tt = s.Skip(num).Take(num).ToArray();
                var flg = true;
                for (var j = 0; j < num; ++j)
                {
                    if (t[j] != tt[j])
                        flg = false;
                }
                if (flg)
                {
                    WriteLine(num * 2);
                    return;
                }
            }
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 26700
N = int(input())
lank = [0, 0, 0, 0, 0, 0, 0, 0]
a = list(map(int, input().split()))
cnt = 0

for i in range(N):
    if 1 <= a[i] <= 399:
        lank[0] = 1
    elif 400 <= a[i] <= 799:
        lank[1] = 1
    elif 800 <= a[i] <= 1199:
        lank[2] = 1
    elif 1200 <= a[i] <= 1599:
        lank[3] = 1
    elif 1600 <= a[i] <= 1999:
        lank[4] = 1
    elif 2000 <= a[i] <= 2399:
        lank[5] = 1
    elif 2400 <= a[i] <= 2799:
        lank[6] = 1
    elif 2800 <= a[i] <= 3199:
        lank[7] = 1
    else:
        cnt += 1

number_min = max(1, lank.count(1))
number_max = lank.count(1) + cnt

print(number_min, number_max)

Measured memory_bytes: 9048
def palin(x):
    #print(x)
    if x == x[::-1]: return True
    return False
 
a = input()
n = len(a)
if palin(a) and palin(a[:int((n-1)/2)]) and palin(a[int((n+3)/2)-1:]):
    print("Yes")
else: print("No")

Measured memory_bytes: 9064
#include <cstdio>
#include <set>
typedef long long int64;
static const int MAXN = 1e5 + 5;

int n, l[MAXN], r[MAXN], len[MAXN];
int64 min;
int64 dec_offset = 0, inc_offset = 0;
std::multiset<int64, std::greater<int64>> dec;
std::multiset<int64> inc;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d%d", &l[i], &r[i]), len[i] = (r[i] - l[i]);

    dec.insert(l[0]);
    inc.insert(l[0]);
    for (int i = 1; i < n; ++i) {
        dec_offset -= len[i];
        inc_offset += len[i - 1];
        int64 p = l[i];
        if (p <= *dec.begin() + dec_offset) {
            min += (*dec.begin() + dec_offset - p);
            inc.insert(*dec.begin() + dec_offset - inc_offset);
            dec.erase(dec.begin());
            dec.insert(p - dec_offset);
            dec.insert(p - dec_offset);
        } else if (p >= *inc.begin() + inc_offset) {
            min += (p - *inc.begin() - inc_offset);
            dec.insert(*inc.begin() + inc_offset - dec_offset);
            inc.erase(inc.begin());
            inc.insert(p - inc_offset);
            inc.insert(p - inc_offset);
        } else {
            dec.insert(p - dec_offset);
            inc.insert(p - inc_offset);
        }
    }

    printf("%lld\n", min);
    return 0;
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, 0, x.size()-1) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
string S,T;
vector<int> A;
vector<int> B;
//=============================
void input()
{
    cin>>N;
    A.resize(N+1);
    A[0] = 0;
    rep(i,1,N){
        cin>>A[i];
    }
    A.push_back(0);

}
//=============================
void func(){}
//=============================


void solve()
{
    B.resize(N+2);

    B[0] = abs(A[0]);
    rep(i,1,N+1){
        B[i] = B[i-1] + abs(A[i]-A[i-1]);
    }
    int s = B[N+1];
    //debugv(B);

    rep(i,1,N){
        int a;
        a = s + abs(A[i+1]-A[i-1]) - (
        abs(A[i]-A[i-1]) + abs(A[i]-A[i+1]));
        cout<<a<<endl;
    }


}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 2800
#include <iostream>

using namespace std;

int isOK(int a, int d[], int size);

int main()
{
    int n;
    int k;
    int d[10];

    cin >> n >> k;
    for (int i = 0; i < k; i++) {
        cin >> d[i];
    }

    int ans = n;
    while(!isOK(ans, d, k)) {
        ans++;
    }

    printf("%d\n", ans);

    return 0;
}

int isOK(int a, int d[], int size)
{
    int rec = 1;

    while(a != 0) {
        int cmp = a % 10;
        a /= 10;

        for (int i = 0; i < size; i++) {
            if (cmp == d[i]) {
                rec = 0;
            }
        }
    }

    return rec;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 998244353;

     signed main(){
     
int n,a,ans=0;
map<int,int>mp;
cin>>n;
for(int i=0;i<n;i++){
   cin>>a;
   mp[a]++;
   ans+=a;
}
int q;
cin>>q;
int b,c;
for(int i=0;i<q;i++){
   cin>>b>>c;
   ans+=(c-b)*mp[b];
   mp[c]+=mp[b];
   mp[b]=0;
   cout<<ans<<endl;
}
     }


 


 






    





      

        


Measured memory_bytes: 9356
import java.io.*;
public class Main{
    public static void main(String args[]){
        try{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        String[] array = str.split(" ");
        int x = Integer.parseInt(array[0]);
        int y = Integer.parseInt(array[1]);

        System.out.println(x*y + " " + 2*(x+y));

        }catch(IOException e){
        e.printStackTrace();
        }
    }

}

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

using namespace std;

int main(void){
	int n;
	scanf("%d", &n);
	int s = 0;
	for(int i = 0;i < n;++i){
		int a, b;
		scanf("%d %d", &a, &b);
		s += b - a + 1;
	}
	printf("%d\n", s);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	public static void main(String aeg[])
	{
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext())
		{
			int n=sc.nextInt();
			int ans = n%39;
			if(ans == 0)
				ans = 39;
			if(ans>=10)
				System.out.println("3C"+ans);
			else
				System.out.println("3C0"+ans);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n, L, Q;
llint x[100005];
llint succ[17][100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i];
	cin >> L;
	
	x[n+1] = inf;
	for(int i = 1; i <= n; i++){
		succ[0][i] = upper_bound(x, x+n+2, x[i]+L) - x - 1;
	}
	
	for(int i = 1; i < 17; i++){
		for(int j = 1; j <= n; j++){
			succ[i][j] = succ[i-1][succ[i-1][j]];
		}
	}
	
	cin >> Q;
	llint s, t;
	for(int q = 0; q < Q; q++){
		cin >> s >> t;
		if(s > t) swap(s, t);
		llint ans = 0, v = s;
		for(int i = 16; i >= 0; i--){
			if(succ[i][v] < t){
				v = succ[i][v];
				ans |= 1<<i;
			}
		}
		ans++;
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 14848
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef long long ll;
const int inf=1<<30;

string s;

int main(){
	cin>>s;
	vi a(6);
	s+="+";
	s="+"+s;
	int t=0,I;
	for(int i=1;i<s.size();i++) if(s[i]=='+'||s[i]=='-'){
		int t_=i;
		bool flag=0;
		for(int j=t;j<i;j++) if(s[j]=='x') flag=1;
		if(!flag) I=0;
		else if(s[i-1]=='x'){
			I=1;
			t_--;
		}
		else{
			I=s[i-1]-'0';
			t_-=3;
		}
		bool tmp=(s[t]=='+'||!t);
		int num=0;
		if(t+1==t_) num=1;
		else for(int j=t+1;j<t_;j++) (num*=10)+=s[j]-'0';
		a[I]=(tmp?1:-1)*num;
		t=i;
	}
	for(int i=2000;i>=-2000;i--) if(i){
		ll sum=0;
		for(int j=0;j<6;j++){
			ll num=1;
			for(int k=0;k<j;k++) num*=i;
			sum+=a[j]*num;
		}
		if(sum==0){
			int I=i*(-1);
			cout<<"(x";
			if(I>0) cout<<'+';
			cout<<I<<')';
		}
	}
	cout<<endl;
}

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

int N;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        char c;
        scanf(" %c",&c);
        if(c == 'Y')
        {
            printf("Four\n");
            return 0;
        }
    }
    printf("Three\n");
    return 0;
}


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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while(A>0 && C>0){
        C -= B;
        A -= D;
        //cout << A << " " << C << endl;
    }

    if(C<=0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3556
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner S = new Scanner(System.in);
		
		int N = S.nextInt();
		int[] data = new int[N];
		
		for(int i = 0;i < N;i++){
			data[i] = S.nextInt();
		}
		
		for(int i = N - 1;i >= 0;i--){
			if(i == 0)
				System.out.println(data[i]);
			else
				System.out.print(data[i]+" ");
		}
		
	}
}

Measured memory_bytes: 17204
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

string S;

int main()
{
    cin >> S;
    int ans = inf;
    rep(i, 0, S.length() - 2)
    {
        int n1 = S[i] - '0';
        int n2 = S[i + 1] - '0';
        int n3 = S[i + 2] - '0';
        int n = n1 * 100 + n2 * 10 + n3;
        chmin(ans, abs(753 - n));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//g++ -std=c++11 -Wall -O2 -o main.exe main.cpp

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
//最大公約数: gcd()
//最小公倍数: lcm()

using namespace std;

template <typename T>
void in(T &t){ //標準入力
    cin >> t;
    return;
}

template <typename T>
void sortasc(vector<T> &v){ //vectorを昇順にソート
    sort(v.begin(), v.end(), std::greater<int>());
    return;
}

template <typename T>
void sortdesc(vector<T> &v){ //vectorを降順にソート
    sort(v.begin(), v.end(), std::less<int>());
    return;
}

int main(){
    int a;

    cin >> a;

    if(a < 1200) printf("ABC\n");
    else if(a < 2800) printf("ARC\n");
    else printf("AGC\n");
    return 0;
}

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string s; cin >> s;
    string t=s;
    long long k; cin >> k;

    if(s.size()==1){
        long long ans=k/2;
        cout << ans << endl;
        return 0;
    }
    sort(t.begin(),t.end());
    if(t[0]==t[s.size()-1]){
        long long ans=s.size()*k/2;
        cout << ans << endl;
        return 0;
    }
    
    long long ans1=0;
    long long cnt=1;
    for(int i=0;i<s.size();i++){
        if(s[i]==s[i+1]) cnt++;
        else{
            ans1+=cnt/2;
            cnt=1;
        }
    }
    long long x=1;
    long long y=1;
    long long ans2=0;
    if(s[0]==s[s.size()-1]){
        for(int i=0;i<s.size();i++){
            if(s[i]==s[i+1]) x++;
            else break;
        }
        for(int i=s.size()-1;i>=0;i--){
            if(s[i]==s[i-1]) y++;
            else break;
        }
        if(x%2==1&&y%2==1) ans2++;
    }
    long long ans;
    ans=ans1*k+ans2*(k-1);
    cout << ans << endl;
}


Measured memory_bytes: 256
import math

n, d = map(int, input().split())
x = [list(map(int, input().split(" "))) for i in range(n)]

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        dist = math.sqrt(dist)
        if dist.is_integer():
            ans += 1

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
signed main(){
	int a,b;
	cin>>a>>b;
	if(a==1&&b==1)puts("-1");
	else if(a==1&&b==0)puts("0 0 1 1");
	else if(b<pow(2,a)){
		bool bo=false;
		f(i,pow(2,a)){
			if(bo&&i!=b)cout<<" ";
			if(i!=b){
				cout<<i;
				bo=true;
			}
		}
		cout<<" "<<b;
		for(int i=pow(2,a)-1;i>=0;i--){
			if(i!=b)cout<<" "<<i;
		}
		cout<<" "<<b;
	}else puts("-1");
	return 0;
}


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

#define LLINF (1LL<<60)
typedef long long ll;

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

//C++14 (GCC 5.4.1)
int main() {
    int N,M;
    cin >>N>>M;

    int k,l;
    vector<int> S(M,0),P(M);
    rep(i,M){
        cin >> k;
        rep(j ,k){
            cin >>l;
            S[i]|=1<<(l-1);
        }
    }
    rep(i,M)cin>>P[i];
   //-----------------------------------
    int ans=0;
    bool isok;
    rep(bit,1<<N){
        isok=true;
        rep(i,M){
            isok=(__builtin_popcount(bit & S[i])%2==P[i]);
            if(!isok)break;
        }
        if(isok)ans++;
    }

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

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        //??\???
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[100];
        for(int i=0;i<N;i++) {
            A[i] =sc.nextInt();
        }
        // ??????
        trace(A, N);
        insertionSort(A, N);
    }

    public static void trace(int[] A, int N){
        for(int i = 0; i < N; i++){
            if(i > 0) System.out.print(" ");
            System.out.print(A[i]);
        }
        System.out.println();
    }

    public static void insertionSort(int[] A, int N){
        for(int i=1;i<N;i++){
            int v=A[i];
            int j=i-1;
            while(j>=0 && A[j]>v){
                A[j+1]=A[j];
                j--;
            }
            A[j+1]=v;
            trace(A, N);
        }
    }
}

Measured memory_bytes: 33516
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

int f(vi a) {
  int n = sz(a);
  int l = n/2, r = n/2;
  while (l > 0 && a[l] != a[l-1]) --l;
  while (r < n-1 && a[r] != a[r+1]) ++r;
  if (r-l&1) return (n/2-l < r-n/2)?a[l]:a[r];
  return a[l];
}

int main() {
  int m;
  scanf("%d",&m);
  int n = m*2-1;
  vi a(n);
  rep(i,n) a[i] = in();
  int l = 1, r = n+1;
  while (l+1<r) {
    int c = (l+r)/2;
    vi b;
    rep(i,n) b.pb(a[i]>=c);
    if (f(b)) l = c; else r = c;
  }
  cout<<l<<endl;
  return 0;
}







Measured memory_bytes: 2916
n = int(input())
A = list(map(int,input().split()))
cnt = 0
flag = True
while flag:
    flag = False
    for i in range(n-1,0,-1):
        if A[i] < A[i-1]:
            A[i],A[i-1] = A[i-1],A[i]
            cnt += 1
            flag = True
print(" ".join(map(str,A)))
print(cnt)


Measured memory_bytes: 5600
import sys, math
from functools import lru_cache
from collections import deque

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    H, W = mi()
    S = [input().split() for i in range(H)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == 'snuke':
                print(chr(ord('A')+j)+str(i+1))
                return


        

if __name__ == '__main__':
    main()


Measured memory_bytes: 9540
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        d: usize,
        xss: [[i64; d]; n],
    }
    fn distance_pow2(xss: &Vec<Vec<i64>>, i: usize, j: usize) -> i64 {
        let mut d = 0;
        for k in 0..xss[0].len() {
            let tmp = xss[i][k] - xss[j][k];
            d += tmp * tmp;
        }
        d
    }
    let mut hashset = std::collections::HashSet::new();
    for i in 1..40 * 40 * 11 {
        hashset.insert(i * i);
    }
    fn is_integer(n: i64, hashset: &std::collections::HashSet<i64>) -> bool {
        hashset.get(&n).is_some()
    }
    let mut count = 0;
    for i in 0..n {
        for j in i + 1..n {
            if is_integer(distance_pow2(&xss, i, j), &hashset) {
                count += 1;
            }
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define inf 1000000000000


long long dp[101][101];
long long dist[101][101][21];

long long solve(int n,int m,int c,int s,int g){
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			dp[i][j] = inf;
		}
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			for(int k=0;k<=c;k++){
				dist[i][j][k] = inf;
				if(i==j){
					dist[i][j][k] =0;
				}
			}
		}
	}
	long long  x,y,z,w;
	for(int i=0;i<m;i++){
		cin >> x >> y >> z >> w;
		dist[x][y][w] = min(dist[x][y][w],z);
		dist[y][x][w] = min(dist[y][x][w],z);
	}
	for(int q=1;q<=c;q++){
		for(int k=1;k<=n;k++){
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					dist[i][j][q] = min(dist[i][j][q],dist[i][k][q]+dist[k][j][q]);
				}
			}
		}
	}
	vector<int>p(c+1);
	for(int i=1;i<=c;i++){
		cin >> p[i];
	}
	for(int i=1;i<=c;i++){
		vector<int>q(p[i]);
		for(int j=1;j<p[i];j++){
			cin >> q[j];
		}
		vector<long long>r(p[i]+1,0);
		for(int j=1;j<=p[i];j++){
			cin >> r[j];
		}
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				long long  dis = dist[j][k][i];
				long long  cost=0;
				for(int l=1;l<=p[i];l++){
					if(l==p[i]){
						cost += r[l]*(dis-q[l-1]);
						break;
					}
					if(dis<=q[l]){
						cost += r[l]*(dis-q[l-1]);
						break;
					}else{
						cost += r[l]*(q[l]-q[l-1]);
					}
				}
				dp[j][k] =  min(dp[j][k],cost);
			}
		}
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}
	if(dp[s][g]==inf){
		dp[s][g]=-1;
	}
	return dp[s][g];
}



int main(){
	int n,m,c,s,g;
	while(1){
		cin >> n >> m >> c >> s >> g;
		if(n==0)break;
		cout << solve(n,m,c,s,g) << endl;
	}
	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int x,n; cin>>x>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    int ans=x, an=x;
    rep(i,200){
        if(find(btoe(p), ans)!=p.end()){
            ans++;
        }
        else break;
    }
    rep(i,200){
        if(find(btoe(p), an)!=p.end()){
            an--;
        }
        else break;
    }
    if((ans-x)>=(x-an)){
        ans=an;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


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

    ll sum = 0, xorsum=0, res=0;
    int right=0;
    for(int left=0;left<N;left++){
        while(right<N&&(sum+A[right])==(xorsum^A[right])){
            sum+=A[right];
            xorsum^=A[right];
            right++;
        }
        res+=(right-left);

        if(left==right){
            right++;
        }else{
            sum-=A[left];
            xorsum^=A[left];
        }
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		
		//double[] a = new double[n];
		double sum =0;
		for(int i=0;i<n;i++) {
			sum += 1/sc.nextDouble();
			
		}
		System.out.println(1/sum);
		
	}

	}

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

int main() {
  int n, q;
  cin >> n >> q;
  dsu d(n);
  for (int i = 0; i < q; i++) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0) {
      d.merge(u, v);
    } else {
      cout << d.same(u, v) << "\n";
    }
  }
}


Measured memory_bytes: 4040
#include <bits/stdc++.h>
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#define fst first
#define snd second
#define fore(i,a,n) for(ll i=a;i<n;i++)
#define rfore(i, a, b) for(ll i = b - 1; i >= (ll)a; i--)
#define pb push_back
#define mp make_pair
#define bs binary_search
#define mm(a,b) memset(a,b,sizeof(a));
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int) (n).size())
#define INFI ((ll)1e15)
#define MINI ((ll)-1e15)
#define EPS 1e-9
#define endl "\n"
using namespace std;
typedef long long ll;  
typedef long double ld;
const ll MOD = 1e9+7;     
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const ll MAXN =300005;
ll n,t,q,x,s,k,m;
ll sum[MAXN], a[MAXN];
int main(){
    cin >> n >> k;
    fore(i,0,n)cin>>a[i];
    sort(a,a+n);
    fore(i,0,n)sum[i+1]=a[i]+sum[i];
    ll j = n-1;
    while(k)k--,j--;
    cout << sum[j+1];
    return 0;
}

Measured memory_bytes: 3840
#include<iostream>
#include<vector>
using namespace std;
#define MAX_N 1000
vector<int> G[MAX_N];
int visited[MAX_N];
int n,m,ans;

void dfs(int pos,int depth){
  if(depth==3)return;
  if(!visited[pos])ans++;
  visited[pos]=true;
  for(int i=0;i<(int)G[pos].size();i++){
    int w=G[pos][i];
    dfs(w,depth+1);
  }
}

void init(){
  for(int i=0;i<MAX_N;i++)G[i].clear(),visited[i]=false;
}
int main(){
  while(cin>>n>>m&&n&&m){
    init();
    for(int i=0;i<m;i++){
      int a,b;
      cin>>a>>b;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    ans=0;
    dfs(1,0);
    cout<<ans-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define pb push_back
#define si second
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  mod 1000000007
#define double long double
#define all(o) o.begin(),o.end()
using namespace std;
int power(int x, int y)
{
    int res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1; // y = y/2
        x = (x*x) % mod;
    }
    return res%mod;
}
int inv(int n)
{
    return power(n,mod-2)%mod;
}
int32_t main(){
	fast
	int x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	int q=x/d;
	int rem=k-q;
	if(rem<=0)
	{
		cout<<x-k*d<<"\n";
		return 0;
	}
	int ans=x-q*d;
	if(rem%2)
		ans=ans-d;
	cout<<abs(ans)<<"\n";

}




Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, p;
    cin >> x >> p;
    if(p == 100){
        printf("%.12lf\n",(double)((x+1)/2));
        return 0;
    }
    printf("%.12lf\n",100.0*((x+1)/2)/p);
    return 0;
}


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

int main()
{
    long long I, O, T, J, L, S, Z;
    cin >> I >> O >> T >> J >> L >> S >> Z;
    auto result = 2*(I/2) + 2*(J/2) + 2*(L/2);
    if (I >= 1 && J >= 1 && L >= 1)
    {
        I--; J--; L--;
        result = max(result, 3 + 2*(I/2) + 2*(J/2) + 2*(L/2));
    }
    cout << result + O << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define pll pair<ll,ll>
#define pii pair<int,int>
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
 
ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b) ;} 

template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}
 
void solve(){
	ll n;
	cin>>n;
	ll modd = 1000000007;
	vector<ll> vec10(n+1,1),vec9(n+1,1),vec8(n+1,1);
	ll tt = 10,ttt = 9,tttt = 8;
	vec9[0] = 2;
	for(int i=1;i<=n;i++){
		vec10[i] = (tt*vec10[i-1])%modd;
		vec9[i] = (ttt*vec9[i-1])%modd;
		vec8[i] = (tttt*vec8[i-1])%modd;
	}
	ll ans = (vec10[n]  + vec8[n])%modd;
	ans = (modd + ans - vec9[n])%modd;
	// if(temp>=0){
	// 	temp = temp%modd;
	// }
	// else{
	// 	temp = (modd - temp)%modd;
	// }
	// cout<<(-1%3)<<endl;
	// ll ans = ((vec10[n] - (vec9[n] + vec9[n])%modd) + vec8[n])%modd;
 
	cout<<ans<<endl;
} 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	ll t;
	// cin>>t;
	t=1;
	while(t--){
		solve();
	}    
    return 0;
}

Measured memory_bytes: 26520
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
#pragma region DEBUG
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
lli arr[MAX]; 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    lli t;
    t =1 ;
    while(t--){
        lli n,x,T;
        cin>>n>>x>>T;
        cout<<(n+x-1)/x*T;
        
    }
}

Measured memory_bytes: 3584
#include<iostream>
#include<string>
using namespace std;
long long a[200100],sum;
int main()
{
    long long n,mod = 1e9+7;
    cin >> n;
    for(long long i=1;i<=n;i++)
    {
        cin >> a[i];
        sum = (sum%mod + a[i]%mod)%mod;
    }
    long long ans =0;
    for(long long i=1;i<=n;i++)
    {
        sum = (sum%mod - a[i]%mod + mod)%mod;
        ans += a[i] * sum %mod;
    }
    cout << ans%mod;
    return 0;
}

Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
typedef pair<int, int> Pr;
typedef tuple<int, int, int> Tp;
#define at(t, i) get<i>(t)

int h, w;
int sx, sy, gx, gy;
char grid[14][14];
int dist[14][14];
int group[14][14];
int size[1024];
bool visit[14][14];

bool search(int x, int y, int d)
{
	if (visit[x][y]) return false;
	if (dist[x][y] > d) return false;
	if (group[x][y] != -1 && size[group[x][y]] <= 1) return false;
	
	if (x == gx && y == gy) return true;
	
	visit[x][y] = true;
	if (group[x][y] != -1) size[group[x][y]]--;
	
	for (int dir = 0; dir < 4; dir++){
		int nx = x + dx[dir];
		int ny = y + dy[dir];
		if (grid[nx][ny] == '#') continue;
		if (visit[nx][ny]) continue;
		if (search(nx, ny, d - 1)) return true;
	}
	
	visit[x][y] = false;
	if (group[x][y] != -1) size[group[x][y]]++;
	
	return false;
}

int solve()
{
	int color = 0;
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			if (compl group[i][j]) continue;
			if (grid[i][j] != 'X') continue;
			size[color] = 1;
			group[i][j] = color;
			
			queue<Pr> que;
			for (que.push(Pr(i, j)); que.size(); que.pop()){
				Pr p = que.front();
				int x = p.first, y = p.second;
				for (int dir = 0; dir < 4; dir++){
					int nx = x + dx[dir];
					int ny = y + dy[dir];
					if (group[nx][ny] == -1 && grid[nx][ny] == 'X'){
						group[nx][ny] = color;
						size[color]++;
						que.push(Pr(nx, ny));
					}
				}
			}
			
			size[color] = size[color] / 2 + 1;
			color++;
		}
	}
	
	{
		queue<Tp> que;
		dist[gx][gy] = 0;
		for (que.push(Tp(gx, gy, 0)); que.size(); que.pop()){
			Tp t = que.front();
			int x = at(t, 0), y = at(t, 1), d = at(t, 2);
			for (int dir = 0; dir < 4; dir++){
				int nx = x + dx[dir];
				int ny = y + dy[dir];
				if (grid[nx][ny] == '#') continue;
				if (dist[nx][ny] < INF) continue;
				dist[nx][ny] = d + 1;
				que.push(Tp(nx, ny, d + 1));
			}
		}
	}
	
	for (int d = 1; ; d++){
		if (search(sx, sy, d)) return d;
	}
}

int main()
{
	while (scanf("%d %d", &w, &h), h){
		fill_n(*grid, 14 * 14, '#');
		fill_n(*dist, 14 * 14, INF);
		fill_n(*group, 14 * 14, -1);
		fill_n(size, 1024, 0);
		fill_n(*visit, 14 * 14, false);
		
		for (int i = 1; i <= h; i++){
			for (int j = 1; j <= w; j++){
				scanf(" %c", &grid[i][j]);
				if (grid[i][j] == 'S'){
					sx = i;
					sy = j;
					grid[i][j] = '.';
				}
				else if (grid[i][j] == 'G'){
					gx = i;
					gy = j;
					grid[i][j] = '.';
				}
			}
		}
		
		printf("%d\n", solve());
	}
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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

    int b = 0;
    vector<int> a(m);
    rep(i, m) {
        cin >> a[i];
        b += a[i];
    }
    
    if (b > n) {
        cout << -1 << endl;
    }else{
        cout << (n - b) << endl;
    }

    
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    bool s[105];
    memset(s,0,sizeof(s));
    int n,x,ans=0;
    cin>>n;
    while(n--)
    {
        scanf("%d",&x);
        s[x]=1;
    }
    for(int i=0;i<101;i++)
        if(s[i]==1)
            ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, D; cin >> N >> D;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
	}
	int g = 0;
	rep(i, 0, N) {
		if (a[i] > 0)
			g ^= (a[i] - 1) % (D + 1);
		dump(i, g);
	}
	cout << (g > 0 ? "First" : "Second") << endl;
	return 0;
}


Measured memory_bytes: 4820
#include <stdio.h>
#include <math.h>
#define MAX 1000000

long long int flag[MAX];

int main(){

  long long int i,j,n,count=0;
  double num;

  num=sqrt(MAX);

  flag[0]=0;
  flag[1]=0;

  for(i=2;i<MAX;i++){
    flag[i]=1;
  }
  for(i=2;i<=num;i++){
    if(flag[i]==1){
      for(j=i;i*j<MAX;j++){
        flag[i*j]=0;
      }
    }
  }
  while(scanf("%lld",&n)!=EOF){
    count=0;
    for(i=0;i<=n;i++){
      if(flag[i]==1) count++;
    }
    printf("%lld\n",count);
  }
  return 0;
}


Measured memory_bytes: 8408
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    int maxi = -1; int ans = 0;
    for (int i = 0; i < n; i++) {
        if (maxi <= h[i]) {
            ans++; maxi = h[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	int n,m;
	map<int,int> q1,q2;
	vector<int> bj;
	int t;
	scanf("%d",&n);
	for(t=0;t<n;t++)
	{
		int a;
		scanf("%d",&a);
		q1[a]++;
	}
	scanf("%d",&m);
	for(t=0;t<m;t++)
	{
		int a;
		scanf("%d",&a);
		if(q2[a] == 0)
			bj.push_back(a);
		q2[a] ++;
	}
	for(t=0;t<bj.size();t++)
	{
		if(q2[bj[t]] > q1[bj[t]])
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 19828
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

char in[15];
int main() {
	int ans = 0, i;
	scanf("%s", in);
	for (i = 0; i < 6; i++) ans += in[i] - '0';
	return !printf("%d\n", ans);
}

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

int main(){

int n;
int64_t sum=1;
cin >> n;
vector<int64_t> vec(n);
for(int i=0;i<n;i++){
    cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    for(int i=0;i<n;i++){
    if(vec.at(i)<=1000000000000000000/sum&&vec.at(i)!=0){
    sum *= vec.at(i);
    }
    else if(vec.at(i)==0){
        sum = 0;
        break;
    }
    else{
        sum=-1;
        break;
    }
}

    cout << sum << endl;
}



Measured memory_bytes: 4052
#include<stdio.h>
#include<stdlib.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
int A[200000]={0},B[200000]={0};long K=0,p=0,m=0,z=0;
int compare(const int*a,const int*b){return *a-*b;}
static inline long IN(void)
{
  long x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline int check(long x)
{
  long count=0;
  if(x>=0)
  {
    int plus=p-1,minus=m-1;count+=z*(p+m)+z*(z-1)/2+p*m;
    rep(i,plus){while(1l*A[i]*A[plus]>x){plus--;}if(i>=plus){break;}count+=plus-i;}
    rep(i,minus){while(1l*B[i]*B[minus]>x){minus--;}if(i>=minus){break;}count+=minus-i;}
  }
  else{x=-x;int low=0;rep(i,m){while(1l*A[low]*B[m-1-i]<x&&low<p){low++;}count+=p-low;}}
  return count>=K;
}
int main(void)
{
  int N=IN(),x;long l=-2e18,r=-l,mid;K=IN();
  while(N--){x=IN();if(x>0)A[p++]=x;else if(x<0)B[m++]=-x;else z++;}
  qsort(A,p,sizeof(int),(int(*)(const void*,const void*))compare);
  qsort(B,m,sizeof(int),(int(*)(const void*,const void*))compare);
  while(l<=r){mid=(l+r)/2;if(check(mid))r=mid-1;else l=mid+1;}
  return printf("%ld",l),0;
}

Measured memory_bytes: 2624
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 1000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

const int MAXN = 16;
int cost[MAXN][MAXN], dp[MAXN][1 << MAXN];

vector<int> masktobits[1 << MAXN];

int n, m;

int mask(int x) {
    return 1 << x;
}

bool contains(int s, int x) {
    return s & mask(x);
}

int rec(int i, int j) {
    if (dp[i][j] != -1) return dp[i][j];

    int& res = dp[i][j];
    res = INF;

    for (int jj = j; jj > 0; jj = (jj-1) & j) {
        if (contains(jj, i)) {
            int jprev = j - jj;

            if (contains(jprev, 0)) {
                for (auto iprev : masktobits[jprev]) {
                    if (cost[iprev][i] != -1) {
                        int curr = rec(iprev, jprev) - cost[iprev][i];

                        for (auto x : masktobits[jprev]) {
                            for (auto y : masktobits[jj]) {
                                if (cost[x][y] != -1) {
                                    curr += cost[x][y];
                                }
                            }
                        }

                        res = min(res, curr);
                    }
                }
            }
        }
    }

    return res;
}

int main() {
    GI(n);
    GI(m);

    int a, b; int c;

    memset(cost, -1, sizeof cost);

    FORN(i, m) {
        GI(a);
        GI(b);
        GI(c);

        a--;
        b--;

        cost[a][b] = c;
        cost[b][a] = c;
    }

    FORN(j, mask(n)) FORN(i, n) if (contains(j, i)) masktobits[j].PB(i);

    memset(dp, -1, sizeof dp);

    FORN(j, mask(n-1)) dp[0][j] = 0;

    printf("%d\n", rec(n-1, mask(n)-1));

    return 0;
}


Measured memory_bytes: 7808