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

//#define int long long
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, h, a[100000], b[100000], bs, bt, am, r;

signed main() {
	cin >> n >> h;
	rep(i,n) cin >> a[i] >> b[i];
	am = *max_element(a, a+n);
	rep(i,n) if (am<b[i]) bs += b[i], bt++;
	if (h>bs) r = (ll)ceil(1.*(h-bs)/am) + bt;
	else {
		sort(b, b+n);
		repr(i,n-1) {
			h -= b[i];
			r++;
			if (h<=0) break;
		}
	}
	cout << r << ln;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
        int a,b,c,i,y;
        scanf("%d %d %d",&a,&b,&c);
        for(i=a;i<=b;i++){
         if(c%i==0){
          y++;
         }
        }
        printf("%d\n",y);
	return 0;
}

Measured memory_bytes: 1860
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    long long a[5]={0};
    string A="MARCH";
    cin>>N;
    //cin.ignore();
    string S[N];
    for(int i=0;i<N;i++){
        //getline(cin,S[i]);
        string s;
        cin>>s;
        for(int j=0;j<5;j++){
            if(A[j]==s[0])a[j]++;
        }
    }
    long long ans=0;
    for(int i=0;i<5;i++)
        for(int j=i+1;j<5;j++)
            for(int k=j+1;k<5;k++)
        ans+=a[i]*a[j]*a[k];
    cout<<ans<<"\n";
}

Measured memory_bytes: 1024
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	if n <= 9:
		return 0
	
	counter = collections.defaultdict(lambda :0)
	for i in range(2,n+1):
		v=i
		for ww in range(2,100):
			if v < ww:
				break
			while v%ww==0:
				counter[ww]+=1
				v=v//ww
				
	#for k in counter:
	#	print(k,counter[k])
	
	ret = 0
	#a**74
	for k in counter:
		if counter[k] >= 74:
			ret += 1
	
	#a**24 * b** 2
	n24 = 0
	n2 = 0
	for k in counter:
		if counter[k] >= 24:
			n24 += 1
		elif counter[k] >= 2:
			n2 += 1
	ret += (n24 * (n24-1))
	ret += n24 * n2
		
	#a**14 * b**4
	n14 = 0
	n4 = 0
	for k in counter:
		if counter[k] >= 14:
			n14 += 1
		elif counter[k] >= 4:
			n4 += 1
	ret += (n14 * (n14-1))
	ret += n14 * n4
	
	#a**4 * b**4 * c**2
	n4 = 0
	n2 = 0
	for k in counter:
		if counter[k] >= 4:
			n4 += 1
		elif counter[k] >= 2:
			n2 += 1
	ret += (n4 * (n4-1) * (n4 - 2)) // 2
	ret += ((n4 * (n4-1)) // 2 ) * n2
	
	return ret
	
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

using namespace std;

bool kaibun (string a)
{
    bool is_kaibun = true;
    for (int i = 0; i < a.size(); i++)
    {
        if(a[i] == a[a.size()-1-i])
        {
            continue;
        }
        else
        {
            is_kaibun = false;
        }
    }
    return is_kaibun;
}

int main()
{
    string S;
    cin >> S;
    string S2 = S.substr(0,(S.size()-1)/2);
    string S3 = S.substr((S.size()+3)/2-1);
    if(kaibun(S) && kaibun(S2) && kaibun(S3))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

int main() {
  int c5=0,c7=0;
  vector<int> A(3);
  for(int i=0;i<3;i++){
    cin >> A.at(i);
    if(A.at(i) == 5){
      c5++;
    }
    else if(A.at(i) == 7){
      c7++;
    }
  }
  if(c5 == 2 && c7 == 1){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));

		long n = sc.nextLong();
		long happiness = 0;
		if(n < 5)
			System.out.println("0");
		if(n >= 5 && n < 500) {
			happiness = n / 5;
			System.out.println((happiness * 5));
		}
		if(n >= 500) {
			long a = n / 500;
			long rem = n % 500;
			long b = rem / 5;
			happiness = (a * 1000) + (b * 5);
			System.out.println(happiness);
		}
		out.close();
	}

	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}

}


Measured memory_bytes: 20436
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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

int main() {
	long long int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		long long int d, p;
		vector<P> dd;
		for (long long int i = 0; i < n; i++) {
			cin >> d >> p;
			dd.push_back(P(p, d));
		}
		sort(dd.begin(), dd.end(), greater<P>());
		long long int ans = 0;
		for (long long int i = 0; i < n; i++) {
			P pp = dd[i];
			long long int p2 = pp.first;
			long long int d2 = pp.second;
			if (m >= d2) {
				m -= d2;
			}
			else if (m > 0){
				ans += p2*(d2 - m);
				m = 0;
			}
			else {
				ans += p2*d2;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

const long long int MOD = 1e9+7;

long long int dp[51][51][2510] = {};

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

    int n, K;
    cin >> n >> K;

    if ( K % 2 == 1) {
        cout << 0 << "\n";
        return 0;
    }
    
    dp[0][0][0] = 1;

    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            for (int k = 2 * j; k <= K; k++) {
                dp[i][j][k] = ((2 * j + 1) * dp[i-1][j][k - 2 * j] + ((i-1 >= j+1) ? (j + 1) * (j + 1) * dp[i-1][j+1][k-2*j] : 0) + ((j > 0) ? dp[i-1][j-1][k-2*j] : 0)) % MOD;
            }
        }
        
    }
    
    cout << dp[n][0][K] << "\n";
}


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

int main() {

    int n;
    cin>>n;

    int arr[n], temp[n], mx, mx2;
    for(int i = 0; i < n; i++){
        cin>>arr[i];
        temp[i] = arr[i];
    }

    sort(arr,arr+n);

    mx = arr[n-1];
    mx2 = arr[n-2];

    for(int i = 0; i < n; i++){
        if(temp[i] == mx) printf("%d\n",mx2);
        else printf("%d\n",mx);
    }

    return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>
int main(void)
{
    int a,b;
    a = 0;
    b = 0;
    char s[5000];
    scanf("%s", s);
    if(s[0] == '0' && s[1] != '0'){
        a ++;
    }
    else if(s[0] == '1' && s[1] <= '2'){
        a ++;
    }
    if(s[2] == '0' && s[3] != '0'){
        b ++;
    }
    else if(s[2] == '1' && s[3] <= '2'){
        b ++;
    }
    if(a < b){
        printf("YYMM");
    }
    else if(a > b){
        printf("MMYY");
    }
    else if(a == 1 && b == 1){
        printf("AMBIGUOUS");
    }
    else if(a == 0 && b == 0){
        printf("NA");
    }
    
    return 0;
}

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

int main() {
  int N, Z, W;
  cin >> N >> Z >> W;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  if (N == 1) cout << abs(W-a[0]) << endl;
  else cout << max(abs(W-a[N-1]), abs(a[N-2]-a[N-1]));
}


Measured memory_bytes: 3644
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <numeric>
#include <bitset>
#include <stack>
#include <cstring>
using namespace std;

const int INF = 1 << 30;
const double EPS = 1e-10;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int e[12][12][12][12][12][11];

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

  memset(e, sizeof(e), 0);
  vector<int> log(5, 0);
  for (int i = 0; i < 1000; ++i) {
    int v = -INF;
    for (int i = 0; i < N; ++i)
      v = max(v, e[log[0]][log[1]][log[2]][log[3]][log[4]][i]);
    vector<int> r;
    for (int i = 0; i < N; ++i) {
      if (e[log[0]][log[1]][log[2]][log[3]][log[4]][i] == v)
        r.push_back(i);
    }

    int hand = r[rand()%r.size()];
    printf("%d\n", hand+1);
    fflush(stdout);

    int opp;
    scanf("%d", &opp);
    --opp;

    for (int i = 0; i < N; ++i) {
      if (a[i][opp] == 'o')
        e[log[0]][log[1]][log[2]][log[3]][log[4]][i] += 3;
      else if (a[i][opp] == '-')
        e[log[0]][log[1]][log[2]][log[3]][log[4]][i] += 1;
    }

    log.push_back(opp+1);
    log.erase(log.begin());
  }

  return 0;
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
template<typename T>
T minch(T& l, T r) {
    return l = min(l, r);
}
template<typename T>
T maxch(T& l, T r) {
    return l = max(l, r);
}
template<typename T>
void output(const T& val) {
    cout << val << endl;
}
template<typename T>
void output(const vector<T>& vec, const bool newline = false) {
    for (const T& val : vec)cout << val << (newline ? '\n' : ' '); cout << endl;
}
template<typename T>
void output(const vector<vector<T>>& mat) {
    for (const auto& row : mat)output(row);
}
// ============ template finished ============

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    vector<vector<int>> edges(N);
    rep(i, N)cin >> H[i];
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    int res = 0;
    rep(i, N) {
        for (int next : edges[i]) {
            if (H[next] >= H[i]) {
                goto end;
            }
        }
        res++;
end:;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 8804
#include <cstdio>
using namespace std;

int a[12];

bool binary(int left,int right,int i);

int main()
{
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<10;j++)
		scanf("%d",&a[j]);

		if(binary(0,0,0))
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

bool binary(int left,int right,int i)
{
	if(i == 10) return true;
	if(right < a[i]) return binary(left,a[i],i+1);
	if(left < a[i]) return binary(a[i],right,i+1);
	return false;
}

Measured memory_bytes: 1008
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n+1];

  int tmp;
  for ( int i = 1; i <= n; i++){
    cin >> tmp;
    a[i] = tmp - i;
  }

  sort(a + 1, a + n + 1);

  long long ans = 0;
  for ( int i = 1; i <= n; i++){
    ans += abs(a[i] - a[(n + 1) / 2]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int n,k;
ll a[N],sum;
bool cmp(ll a,ll b){
	return a>b;
}
int main(){
	read(n),read(k);
	for(int i=1;i<=n;i++)read(a[i]);
	sort(a+1,a+1+n,cmp);
	for(int i=k+1;i<=n;i++)sum+=a[i];
	cout<<sum<<endl;
	return 0;
}


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

int main() {
  unsigned int week;
  cin >> week;
  float debt = 100;  // in unit of 1000.

  for(int i=0; i<week; i++) {
    debt *= 1.05;
    debt = ceil(debt);
  }

  cout << (int)debt*1000 << endl;

  return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    int n;cin>>n;
    V<int>x(n),y(n);
    for(int i=0;i<n;i++)cin>>x[i];
    for(int i=0;i<n;i++)cin>>y[i];

    for(int p=1;p<=3;p++){
        double D=0;
        for(int i=0;i<n;i++){
            D+=(double)pow((double)abs(x[i]-y[i]),p);
        }

        D=pow(D,(double)1/p);
        printf("%.10lf\n",D);
    }
    double D=0;
    for(int i=0;i<n;i++){
        chmax(D,(double)abs(x[i]-y[i]));
    }
    printf("%.10lf\n",D);
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


































Measured memory_bytes: 3444
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n,n){
        int t;
        rep(i,9){cin>>t;n-=t;}
        cout<<n<<endl;
    }
}

Measured memory_bytes: 3096
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[100001];

		long sm = 0l;
		for ( int i=0; i<n; i++ ) {
			int a1 = sc.nextInt();
			sm += (long)a1;
			a[a1]++;
		}

		int q = sc.nextInt();

		for ( int i=0; i<q; i++ ) {
			int b = sc.nextInt();
			int c = sc.nextInt();

			sm = sm + (long)(c-b)*(long)a[b];
			System.out.println(sm);

			a[c] += a[b];
			a[b] = 0;
		}

	}
}


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

int main(){
    string s;
    int i,sum;
    cin >> s;
    sum =700;
    for(i=0;i<3;i++){
        if(s.at(i) =='o'){
            sum=sum+100;
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
int n,d;

void solve()
{
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;i++)
        ans+=(i%d==0);
    cout<<ans;

}
int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve();




}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
const ll INF=1e18+7;
int main(){
	ll N;
	vector<ll> A(3);
	cin >> N >> A[0] >> A[1] >> A[2];
	vector<ll> L(N);
	FOR(i,0,N)cin>>L[i];
	ll ans = INF;
	ll K = 1;
	FOR(i,0,N)K*=3;
	FOR(i,0,K){
		ll p = i;
		vector<ll> a[3];
		FOR(j,0,N)a[p%3].push_back(L[j]),p/=3;
		vector<P> dp[3];
		FOR(j,0,3){
			for(auto x:a[j]){
				vector<P> dpp;
				dpp.push_back({x,0});
				for(auto y:dp[j]){
					dpp.push_back(y);
					dpp.push_back({y.first+x,y.second+10});
				}
				dp[j] = dpp;
			}
		}
		vector<ll> mina(3,INF);
		FOR(j,0,3)
			for(auto x:dp[j])
				mina[j] = min(mina[j],x.second+abs(x.first-A[j]));
		ans = min(ans,mina[0]+mina[1]+mina[2]);
	}
	cout << ans << endl;
}

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

#define MP make_pair
#define PB push_back
#define ll long long int
#define F first
#define S second
#define MAX(x,y) (x)>(y)?(x):(y)
#define MIN(x,y) (x)<(y)?(x):(y)
#define REP(i,n) for(i=0;i<(n);i+=1)
#define REPr(i,n) for(i=n-1;i>=0;i-=1)
#define REP1(i,n) for(i=1;i<=(n);i+=1)

typedef vector<ll> vll;
typedef set<int>::iterator sit;
typedef unordered_set<int>::iterator usit;
typedef multiset<int>::iterator msit;
typedef unordered_multiset<int>::iterator umsit;
typedef vector<ll>::iterator vllit;

//cin.ignore(numeric_limits<streamsize>::max(),'\n');

const int N = 100001;

ll dp[N];
int h[N];
int n,k;

void solve(){
    int i,x;
    REP1(i,n){
        for(x=1; x<=min(i,k) ;x+=1){
            dp[i] = min(dp[i-x]+ abs(h[i]-h[i-x]), dp[i]);
        }
    }
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    dp[0] = 10000000;
    cin>>n>>k;
    int i;
    REP1(i,N)
        dp[i] = LLONG_MAX;
    dp[1] = 0; 
    REP(i,n)
        cin>>h[i+1];
    solve();
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1408
def solve():
    n = int(input())
    a = map(int, input().split())

    a = sorted(a)[::-1]

    alice = 0
    bob = 0
    for i in range(len(a)):
        if i % 2 == 0:
            alice += a[i]
        else:
            bob += a[i]

    print(alice - bob)

solve()

Measured memory_bytes: 3060
def main():
    import sys
    input = sys.stdin.buffer.readline
    #n = int(input())
    #l = list(map(int, input().split()))
    '''
    A=[]
    B=[]
    for i in range():
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)'''

    n,m = map(int, input().split())
    r=[[]for i in range(n)]
    start = [0, 0]
    #print(bfs(h, w, m, start))
    for i in range(m):
        a,b=map(int, input().split())
        r[a-1].append(b-1)
        r[b-1].append(a-1)
    #print(r)
    
    from collections import deque
    d = [0 for i in range(n)]
    visited=[False for i in range(n)]
    flg = True
    queue=deque([0])
    dd=0
    while queue:
        now=queue.popleft()
        visited[now]=True
        #print(now)
        for i in r[now]:
            if visited[i]:
                continue
            queue.append(i)
            visited[i]=True
            d[i]=now

    print("Yes")
    for i in range(1,n):
        print(d[i]+1)


if __name__ == "__main__":
     main()


Measured memory_bytes: 34884
n, m = input().split()
a = list(map(int, input().split()))
list.sort(a, reverse=True)

n = 0
ninki = sum(a)/4/int(m)

for w in a:
    #print(sum(a))

    if w < ninki:
        n = 1

    if a.index(w) + 1 == int(m):
        break


if n == 0:
    print("Yes")
if n == 1:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <map>
#include <vector>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

// 最長共通部分列 ... len(s) == m, len(t) == n とすると, O(mn)
int lcs(std::string s, std::string t) {
  std::vector<std::vector<int> > dp(s.size() + 1, std::vector<int>(t.size() + 1, 0));

  for (int i = 1; i <= s.size(); ++i) {
    for (int j = 1; j <= t.size(); ++j) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      }
      else if (dp[i - 1][j] >= dp[i][j - 1]) {
        dp[i][j] = dp[i - 1][j];
      }
      else {
        dp[i][j] = dp[i][j - 1];
      }
    }
  }

  return dp[s.size()][t.size()];
}

int main() {
  int q;
  std::string s, t;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> s >> t;
    cout << lcs(s, t) << endl;
  }

  return 0;
}


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

int main()
{
	int n;cin>>n;
	string s;cin>>s;
	if(n==1)
	{
		cout<<1<<endl;
		return 0;
	}


	int ans=1;
	for(int i=1;i<n;i++)
	{
		if(s[i]!=s[i-1])
		{
		ans++;
			
		}
	}
	cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int A[N];

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

  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (A[i] * 4 * M >= sum) {
      ++cnt;
    }
  }

  if (cnt >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
typedef long long ll;
const int MOD = 7 + 1000000000;
const int MAXN = 5 + 3000;
const int MAXF = 5 + 2 * 100000;

int fact[MAXF];

int fpow(int base, int exp) {
    int ans = 1, power = base;
    while(exp) {
        if(exp & 1) ans = (1LL * ans * power) % MOD;
        power = (1LL * power * power) % MOD;
        exp >>= 1;
    }
    return ans;
}

int ans[MAXN];
int inv(int k) {
    return fpow(k, MOD - 2);
}

int f(const pair<int,int>& p, const pair<int,int>& q) {
    int dx = abs(p.first - q.first), dy = abs(p.second - q.second);
    return (1LL * fact[dx+dy] * inv((1LL * fact[dx] * fact[dy]) % MOD)) % MOD;
}

void sub(int& p, const int& q) {
    assert(p >= 0 && p < MOD);
    assert(q >= 0 && q < MOD);
    p -= q;
    if(p < 0) p += MOD;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int H,W,N;
    cin >> H >> W >> N;
    vector<pair<int,int>> v; v.reserve(1+N);
    foi(i,0,N) {
        int x,y; cin >> x >> y;
        v.emplace_back(x,y);
    }
    fact[0] = 1;
    foi(i,1,MAXF) {
        fact[i] = (1LL * i * fact[i - 1]) % MOD;
    }
    v.emplace_back(H,W);
    sort(v.begin(),v.end());
    foi(i,0,v.size()) {
        ans[i] = f({1,1},v[i]);
    }
    foi(i,0,v.size()) {
        foi(j,1+i,v.size()) {
            if(v[i].first <= v[j].first && v[i].second <= v[j].second) {
                sub(ans[j], (1LL * ans[i] * f(v[i],v[j])) % MOD);
            }
        }
    }
    cout << ans[v.size() - 1] << '\n';
    return 0;
}


Measured memory_bytes: 1024
//ProblemE

//#define USE_STDIO
//#define USE_LOG
//#define FILE_ERR

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#ifndef debug
#define debug(...)
#endif // !LOG

//include
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;

//for
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forbe(i, begin, end) for(decltype(begin) i = (begin); i != (end); ++i)
#define forbes(i, begin, end, step) for(decltype(begin) i = (begin); i != (end); i += (step))

//int
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;

//pair
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
#define fi first
#define se second

//vector
template <typename Value>
static inline void fillv(Value& x, const Value& val) { x = val; }
template <typename Vector, typename Value>
static inline void fillv(Vector& v, const Value& val) { for (auto& x : v) fillv(x, val); }

static inline void Solve();

int main(int argc, char* argv[]) {
#ifdef REDIRECT_STDIO
	REDIRECT_STDIO;
#endif // REDIRECT_STDIO

	Solve();
	return 0;
}

constexpr int MAXN = 700;
int matrix[MAXN][MAXN];
int n, m;

//ProblemE
void Solve() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		matrix[x][y] = 1;
		matrix[y][x] = 1;
	}

	vector<vector<int>> groups;
	vector<int> color(n, 2);

	for (int i = 0; i < n; i++) {
		if (color[i] == 2) {
			int c = 0;
			groups.push_back({ 0, 0 });
			auto& last = groups.back();

			vector<int> q{ i };
			color[i] = c;
			last[c] += 1;

			c = 1 - c;
			while (!q.empty()) {
				vector<int> q2;
				for (auto j : q) {
					for (int k = 0; k < n; k++) {
						if (k == j || matrix[j][k] == 1) continue;
						if (color[k] == 2) {
							color[k] = c;
							q2.push_back(k);
							last[c] ++;
						} else if (color[k] != c) {
							cout << -1 << endl;
							return;
						}
					}
				}
				q = std::move(q2);
				c = 1 - c;
			}
		}
	}

	set<int> poss{ 0 };
	for (auto& group : groups) {
		set<int> poss_next;
		for (auto i : poss) {
			poss_next.insert(i + group[0]);
			poss_next.insert(i + group[1]);
		}
		poss = std::move(poss_next);
	}

	int ans = m;
	for (auto i : poss) {
		int j = n - i;
		ans = min(ans, i*(i - 1) / 2 + j * (j - 1) / 2);
	}
	cout << ans << endl;
}


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

class Dice{
public:
	Dice( int f, int b, int u, int r, int d, int l ) :
		face( f ), back( b ), up( u ), right( r ), down( d ), left( l ){};

	int roll( string& dir ){
		int tmp;
		switch( dir[ 0 ] ){
			case 'N':
				tmp = face; face = down; down = back; back = up; up = tmp; break;
			case 'E':
				tmp = face; face = left; left = back; back = right; right = tmp; break;
			case 'S':
				tmp = face; face = up; up = back; back = down; down = tmp; break;
			case 'W':
				tmp = face; face = right; right = back; back = left; left = tmp; break;
			case 'R':
				tmp = up; up = left; left = down; down = right; right = tmp; break;
			case 'L':
				tmp = up; up = right; right = down; down = left; left = tmp; break;
			default:
				cout << "unknown" << endl;
		}

		return face;
	}

private:
	int face, back, up, right, down, left;
};

int main()
{
	int n;

	while( cin >> n && n ){
		int sum = 1;
		Dice dice( 1, 6, 5, 3, 2, 4 );

		for( int i = 0; i < n; ++i ){
			string s;
			cin >> s;
			sum += dice.roll( s );
		}

		cout << sum << endl;
	}

	return 0;
}

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

map<char, int> charToInt = {{'R',1},{'G',2},{'B',4}};

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> t;
    ll r = 0, g = 0, b = 0;

    if (n < 3) {
        cout << 0 << endl;
        return 0;
    }

    rep(i, n) {
        if (s[i] == 'R') r++;
        else if (s[i] == 'G') g++;
        else b++;
        t.push_back(charToInt[s[i]]);
    }

    ll ans = r * g * b;
    for (int i = 0; i <= n - 3; ++i) {
        for (int j = i + 1; j <= n - 2; ++j) {
            int k = j + (j - i);
            if (k > n) continue;
            if (t[i] + t[j] + t[k] == 7) --ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-05-02 20:44:59
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int flag = 0;
  for (auto e : vec) os << (flag++ ? ", " : "{") << e;
  return os << (vec.empty() ? "{}" : "}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int flag = 0;
  for (auto e : st) os << (flag++ ? ", " : "{") << e;
  return os << (st.empty() ? "{}" : "}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int flag = 0;
  for (auto e : mp) os << (flag++ ? ", " : "{") << e;
  return os << (mp.empty() ? "{}" : "}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

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

  int k, a, b; cin >> k >> a >> b;

  for (int i = a; i <= b; ++i) {
    if (i % k == 0) {
      cout << "OK" << endl; return 0;
    }
  }

  cout << "NG" << endl;

  return 0;
}

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

using namespace std;


int main() {
    int N, K;
    cin >> N >> K;

    long long ans = 0;
    // K=0の時だけ計算が合わないので別対応
    if (K == 0) {
        ans = (long long)N * N;
    } else {
        for (int b = K + 1; b <= N; ++b) {
            ans += N / b * (b - K);
            ans += max(0, N % b - K + 1);
        }
    }

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

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from operator import itemgetter
INF = 10 ** 10

def main():
    N = int(readline())
    L = []
    for _ in range(N):
        x, l = map(int, readline().rstrip().split())
        L.append([x - l, x + l])

    L.sort(key=itemgetter(1))
    cur = -INF
    res = 0

    for left, right in L:
        if left >= cur:
            res += 1
            cur = right
    
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 21304
import math
N, D = map(int, input().split())
X=[]
for _ in range(N):
	x = list(map(int, input().split()))
	X.append(x)

count = 0
for i in range(len(X)):
	for j in range(i + 1, len(X)):
		power = 0
		for idx in range(len(X[i])):
			power += (X[i][idx] - X[j][idx])**2
		if(abs(int(math.sqrt(power))**2 - power ) < 0.001):
			count += 1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> price(n,0);
  for(int i=0;i<n;i++)cin>>price[i];
  sort(price.begin(),price.end());
  price[n-1]/=2;
  int sum=0;
  for(int i=0;i<n;i++)sum+=price[i];
  cout<<sum<<endl;
}

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

int main(void){
	int N;
	cin >> N;
	vector<vector<int>> to(N);
	vector<vector<int>> cost(N);
	for(int i=0;i<N-1;i++){
		int a,b,w;
		cin >> a >> b >> w;
		a--;
		b--;
		to[a].push_back(b);
		to[b].push_back(a);
		cost[a].push_back(w);
		cost[b].push_back(w);
	}
	vector<int>ans(N,0);
	set<int> st;
	st.insert(0);
	ans[0] = 0;
	for(int i=0;i<N;i++){
		queue<int> q;
		q.push(0);
		while(!q.empty()){
			int v = q.front();
			q.pop();
			for(int i=0;i<to[v].size();i++){
				int u = to[v][i];
				int w = cost[v][i];
				if(st.count(u))continue;
				ans[u] = (ans[v]+w)%2;
				st.insert(u);
				q.push(u);
			}
		}
	}
	for(int i=0;i<N;i++)cout << ans[i] << endl;
}

Measured memory_bytes: 16512
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    A,B = map(int, lines.pop(0).split(' '))
    print(max( A+B, A-B, A*B ))

#
# main
#

# 1. use list instead of stdin

#contents = '''\
#3 -4\
#'''
#lines = contents.split('\n')

# 2. use stdin

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define MAXN 100100
#define INF 0x3f3f3f3f
using namespace std;
int n,k,v[MAXN],dp[MAXN];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",v+i);
	}
	for(int i=0;i<n;i++){
		dp[i] = INF;
	}
	for(int i=1;i<=k;i++){
		dp[i] = abs(v[0]-v[i]);
	}
	for(int i=k+1;i<n;i++){
		for(int j=k;j>0;j--){
			dp[i] = min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
		}
	}
	printf("%d\n",dp[n-1]);
	return 0;
}

Measured memory_bytes: 1024
import heapq

N, M, R = map(int, input().split())
D = [int(a) - 1 for a in input().split()]
D.sort()
Dtod = {}
dtoD = {}
Dest = set()
for i, d in enumerate(D):
    Dtod[d] = i
    dtoD[i] = d
    Dest.add(d)
Map = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    Map[a].append((b, c))
    Map[b].append((a, c))

Roots = [[float('inf')] * R for _ in range(R)]
for i, d in enumerate(D):
    Roots[i][i] = 0
    Q = [d]
    Root = [float('inf')] * N
    Root[d] = 0
    while Q and (float('inf') in Roots[i]):
        q = heapq.heappop(Q)
        fatigue, now = divmod(q, 10**3)
        if now in Dest:
            Roots[i][Dtod[now]] = min(fatigue, Roots[i][Dtod[now]])
            Roots[Dtod[now]][i] = min(fatigue, Roots[Dtod[now]][i])
        for nex, cost in Map[now]:
            if Root[nex] > cost + fatigue:
                Root[nex] = cost + fatigue
                heapq.heappush(Q, (cost + fatigue) * 10**3 + nex)

DP = [[float('inf')] * (1 << R) for _ in range(R)]
bit_count = [0]
for _ in range(R):
    bit_count += [x+1 for x in bit_count]

for i in range(1 << R):
    cnt = bit_count[i]
    for j in range(R):
        if (i >> j) & 1 ==1:
            if cnt == 1:
                DP[j][i] = 0
            for k in range(R):
                if j == k:
                    continue
                DP[k][i|(1 << k)] = min(DP[k][i|(1 << k)], DP[j][i] + Roots[j][k])
ans = float('inf')
for i in range(R):
    ans = min(ans, DP[i][-1])
print(ans)



Measured memory_bytes: 77632
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;

public class Main {
	static List<Integer> path;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int ma = Integer.parseInt(sa[1]);
		int mb = Integer.parseInt(sa[2]);

		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			a[i] = Integer.parseInt(sa[0]);
			b[i] = Integer.parseInt(sa[1]);
			c[i] = Integer.parseInt(sa[2]);
		}
		br.close();

		int[][] dp = new int[401][401];
		for (int i = 0; i < 401; i++) {
			for (int j = 0; j < 401; j++) {
				dp[i][j] = Integer.MAX_VALUE;
			}
		}
		for (int k = 0; k < n; k++) {
			int ak = a[k];
			int bk = b[k];
			int ck = c[k];
			for (int i = 10 * k; i > 0; i--) {
				for (int j = 10 * k; j > 0; j--) {
					if (dp[i][j] != Integer.MAX_VALUE) {
						dp[i + ak][j + bk] = Math.min(dp[i + ak][j + bk], dp[i][j] + ck);
					}
				}
			}
			dp[ak][bk] = Math.min(dp[ak][bk], ck);
		}

		int ans = Integer.MAX_VALUE;
		for (int i = 0, j = 0; i < 401 && j < 401; i += ma, j += mb) {
			ans = Math.min(ans, dp[i][j]);
		}
		if (ans == Integer.MAX_VALUE) {
			System.out.println(-1);
		} else {
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 24880
#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;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	VI a(m);
	rep(i, m) cin >>a[i];
	ll sm = accumulate(all(a), 0LL);
	ll ans = n - sm;
	if(ans < 0) ans = -1;
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>


/* 
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end() 
#define mod 1000000007
//#define maxx 200006
#define ll long long 
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long > 
#define listi vector< int> 
#define pii   pair<int , int> 
#define pll pair<long long , long long > 
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


template < class T > using oset = tree< T , null_type, less  < T  > , rb_tree_tag , tree_order_statistics_node_update > ;


// end of #define 

// define globals ...
const int maxx = 2e5+26;

//write function from here ...



bool prime[2008000] ; 
vector < int > prm ;

void primes() 
{ 
	int n = 2008000;
    
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
		
        if (prime[p] == true) 
        { 
			 
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
  
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          prm.pb(p); 
} 


int Main(){


primes();

int n;
cin>>n;

vector < ll > arr(n);
ll ans =0 ;
for(int i = 0  ;  i < n;i++) 
{
cin>>arr[i];

 ans = gcd( ans,arr[i]);
 
}
if(ans!= 1){

cout<<"not coprime";
return 0;	
	
}


map < int , int > mp;

bool flag = 0 ;

for( auto it : arr){
	
	ll temp = it;
	
	int i =0 ; 
	while(true){
		
		
		if(temp%prm[i]==0)
		{
			if(mp[prm[i]] == 1)
			flag =1 ; 
		mp[prm[i]] =1;
     	} 
	while(temp%prm[i]==0){
		
		temp/=prm[i];
	} 
	
	
	
	if( temp == 1 || prime[temp]==1){
		
		if(temp!=1){
			if(mp[temp] == 1)
			flag =1;
		mp[temp]  = 1;
	  }
		
		break;
	}
	i++;
	
}


	
}






if( flag == 1)
cout<<"setwise coprime";
else
cout<<"pairwise coprime";
 






return 0;

}






int main(){
 quick;
int t =1; 
//cin>>t;
while(t-- )
 Main();

 return 0;


}


Measured memory_bytes: 17212
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  vector<long long> a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  long long total = 0;

  long long mae = a[0];
  for (int i = 1; i < n; i++) {
    long long fumidai = 0;
    if (mae <= a[i]) {
      fumidai = 0;
      mae = a[i];
    } else {
      fumidai = mae - a[i];
      mae = a[i] + fumidai;
    }
    total += fumidai;
  }
  cout << total << endl;

  return 0;
}

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

int main(){
  int k;
  string s;
  int size;

  cin >> k >> s;

  size = s.size();

  if (size <= k) {
    cout << s << endl;
  } else {
    for (int i = 0; i < k; i++){
      cout << s[i];
    }
    cout << "..." << endl;
  }

  return 0;
}


Measured memory_bytes: 3624
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n;
vi c;
int ans;
int sumd[200010];
ll powll(ll base,ll power){
    ll ans = 1;
    while (power){
        if (power&1) ans = (base*ans)%mod;
        base = (base*base)%mod;
        power >>= 1;
    }
    return ans;
}

signed main(){
    I(n);
    c.resize(n);
    REP(i,n) I(c[i]);
    sort(all(c));

    sumd[n-1] = powll(2,n-1);
    REPN(i,n-1) sumd[i] = (sumd[i+1] + powll(2,n-2)) % mod;
    REP(i,n){
        ans += sumd[i] * c[i];
        ans %= mod;
    }
    ans = ans * powll(2, n) % mod;
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
const int N=200;
typedef long long LL;
LL f[N][N];
int r[N],s[N],v[N];
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	for(int i=1;i<=n;++i){
		cin>>r[i]>>s[i];
		v[i]=v[i-1]+s[i];
	}
	memset(f,63,sizeof f);
	for(int i=n;i;--i){
		int d=v[n]-v[i-1];
		for(int j=0;j<=d;++j)
			f[i][j]=min(
			-f[i+1][d-j+1]-r[i]+1,
			max(f[i+1][j]+r[i]+1,1ll));
	}
	int ans=0;
	for(int i=0;i<=v[n];++i)
		if(f[1][i]<=a-b)
			ans=i;
	cout<<ans<<" "<<v[n]-ans<<endl;
}

Measured memory_bytes: 1492
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE UndecidableInstances #-}

module Main where

import Control.Category hiding (id, (.))
import Control.Exception (assert)
import Control.Monad
import Control.Monad.ST
import Control.Monad.State.Strict
import qualified Data.ByteString.Char8 as BS
import Data.List as List
import Data.Maybe
import Data.Set as Set
import Data.Vector.Unboxing ((!))
import qualified Data.Vector.Unboxing as U
import qualified Data.Vector.Unboxing.Mutable as UM
import Debug.Trace
import GHC.Generics

-- import System.TimeIt as Time

bsToInt = fst . fromJust . BS.readInt

bsToIntList = fmap bsToInt . BS.words

readInt = bsToInt <$> BS.getLine

readIntList = bsToIntList <$> BS.getLine

readVc = (U.fromList . BS.unpack) <$> BS.getLine

writeVcLn = putStrLn . U.toList

writeVc = putStr . U.toList

range begin end = [begin .. (end - 1)]

partitionIdx vec pred =
  assert (U.length vec >= 0) $
    if pred (vec U.! 0) == False
      then 0
      else loop 0 (U.length vec)
  where
    loop begin end =
      if end == begin + 1
        then end
        else
          let !mid = (begin + end) `div` 2
           in if pred (vec U.! mid) then loop mid end else loop begin mid

-- data Point = Pt {-# UNPACK #-} Int {-# UNPACK #-} Int
--   deriving (Generic)
--   deriving (U.Unboxable) via U.Generics Point

-- ptX :: Point -> Int
-- ptX (Pt x y) = x

-- ptY :: Point -> Int
-- ptY (Pt x y) = y

main :: IO ()
main = do
  n <- readInt
  s <- readVc
  let table = U.constructN (n + 1) f
        where
          f vec = case (U.length vec) of
            0 -> 0 :: Int
            i -> prev + diff
              where
                prev = vec ! (i - 1)
                paren = s ! (i - 1)
                diff = case paren of
                  '(' -> 1
                  ')' -> -1
      openCnt = - (U.minimum table)
      closeCnt = (table ! n) + openCnt
  writeVc . U.fromList $ replicate openCnt '('
  writeVc s
  writeVcLn . U.fromList $ replicate closeCnt ')'

Measured memory_bytes: 4496