akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <queue>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 2000000000000LL
using namespace std;

typedef long long Weight;
typedef pair<Weight,pair<int,int> >Edge;

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

bool shortestPath(Graph &g,
    Matrix &dist, vector<vector<int> > &prev) {
  int n = g.size()-1;
  Array h(n+1);
  h.assign(n,INF);
  REP(k,n+1) REP(i,n+1) FOR(e,g[i]) {
    if (h[e->second.first]<INF && e->first<INF && h[e->second.second] > h[e->second.first] + e->first) {
      h[e->second.second] = h[e->second.first] + e->first;
      if (k == n) return false; // negative cycle
    }
  }
  REP(i,n) FOR(e,g[i]) e->first += h[i] - h[e->second.second];
  dist.assign(n, Array(n, INF));
  prev.assign(n, vector<int>(n, -2));
  REP(s, n) {
    priority_queue<Edge> Q;
    Q.push(make_pair(0,make_pair(s, s)));
    while (!Q.empty()) {
      Edge e = Q.top(); Q.pop();
      if (prev[s][e.second.second] != -2) continue;
      prev[s][e.second.second] = e.second.first;
      FOR(f,g[e.second.second]) {
        if (e.first<INF && f->first<INF && dist[s][f->second.second] > -e.first + f->first) {
          dist[s][f->second.second] = -e.first + f->first;
          Q.push(make_pair(-(-e.first + f->first),make_pair(f->second.first, f->second.second)));
        }
      }
    }
    REP(u, n) {
      if(dist[s][u]<INF)dist[s][u] += h[u] - h[s];
    }
  }
  return true;
}

int main(){
	int r,T,V,E,s,t,e,i,j;
	//for(scanf("%d",&T);T;putchar(--T?' ':'\n')){
		scanf("%d%d",&V,&E);
		Graph g(V+1);
		Matrix dist;
		vector<vector<int> > prev;
		for(i=0;i<V;i++)g[i].push_back(make_pair(0,make_pair(i,i)));
		for(i=0;i<V;i++)g[V].push_back(make_pair(0,make_pair(V,i)));
		for(;E--;)scanf("%d%d%d",&s,&t,&e),g[s].push_back(make_pair(e,make_pair(s,t)));
		if(!shortestPath(g,dist,prev))puts("NEGATIVE CYCLE");
		else for(i=0;i<V;i++)for(j=0;j<V;j++){
			/*if(i==j)printf("0");
			else*/ if(dist[i][j]>=INF)printf("INF");
			else printf("%lld",dist[i][j]);
			printf(j<V-1?" ":"\n");
		}
	//}
}

Measured memory_bytes: 1376
//yewala
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)        (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define mod 1000000007 
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;

inline LL moduloMultiplication(LL x, LL y) { return (x%mod * 1LL * y%mod) % mod; }
inline LL power(LL a, LL b) {
	LL x = 1 % mod;
	while (b) {
		if (b & 1) x = moduloMultiplication(x, a);
		a = moduloMultiplication(a, a);
		b >>= 1;
	}
	return x % mod;
}

inline LL add(LL x, LL y) { x += y; if (x >= mod) x -= mod; return x; }
inline LL inv(LL a) { return power(a, mod - 2) % mod; }


int main()
{
	fastio;
	int n;
	cin >> n;
	VI v1(n);
	VI v2(n);
	VI v3;
	rep(i, n)cin >> v1[i];
	rep(i, n)cin >> v2[i];
	v3 = v1;
	sort(all(v3));
	int pos1 = -1, pos2 = -1;
	int count = 0;
	do {
		count++;
		if (v3 == v1)pos1 = count;
		if (v3 == v2)pos2 = count;
		if (pos1 != -1 && pos2 != -1)break;
	} while (next_permutation(all(v3)));
	cout << abs(pos1 - pos2) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)

int main(){
    int A,B,res;
    cin >> A >> B;

    if(A >= 13)res = B;
    else if(A >= 6 && A <= 12)res = B/2;
    else{
        res = 0;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>
#include<cassert>
#include<map>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)

using namespace std;

struct P
{
  string field;
  int cur,phase,cost;
  P(string field="$",int cur=inf,int phase=inf,int cost=inf):field(field),cur(cur),phase(phase),cost(cost){}
  bool operator < (const P& a)const
  {
    return phase > a.phase;
  }
};

int n,ans;
int dx[] = {-1,-1,+0,+1,+1,+1,+0,-1};//LTRB
int dy[] = {+0,-1,-1,-1,+0,+1,+1,+1};
map<string,int> mincost;

int infect(string &s)
{
  int cost = 0;
  string ns = string(n*n,'.');
  rep(y,n)
    {
      rep(x,n)
	{
	  if(s[x+y*n] == '@')
	    {
	      ns[x+y*n] = '@';
	      continue;
	    }
	  int cnt = 0;
	  rep(k,8)
	    {
	      int nx = x + dx[k];
	      int ny = y + dy[k];
	      if(!(0 <= nx && nx < n && 0 <= ny && ny < n))continue;
	      if(s[nx+ny*n] != '.')cnt++;
	    }
	  if(cnt == 3)ns[x+y*n] = '#',cost++;
	  if(s[x+y*n] == '#' && cnt == 2)ns[x+y*n] = '#',cost++;
	}
    }
  s = ns;
  return cost;
}

void pr(string s)
{
  rep(i,n)
    {
      rep(j,n)
	{
	  cout << s[j+i*n];
	}
      cout << endl;
    }
  cout << endl;
}

void bfs(string bfield,int bcur,int bphase,int bcost)
{
  priority_queue<P> Q;
  Q.push(P(bfield,bcur,bphase,bcost));

  while(!Q.empty())
    {
      P p = Q.top(); Q.pop();
      if(p.cost == 0)
	{
	  cout << p.phase << endl;
	  return;
	}


      int x = p.cur%n;
      int y = p.cur/n;
      int cur = p.cur;
      rep(i,8)
	{
	  int nx = x + dx[i];
	  int ny = y + dy[i];
	  if(!(0 <= nx && nx < n && 0 <= ny && ny < n))continue;
	  if(p.field[nx+ny*n] == '#')continue;
	  string nfield = p.field;
	  cur = nx + ny * n;
	  nfield[x+y*n] = '.';
	  nfield[nx+ny*n] = '@';
	  int ncost = infect(nfield);
	  if(mincost.find(nfield) == mincost.end())
	    {
	      mincost[nfield] = p.phase + 1;
	      Q.push(P(nfield,cur,p.phase+1,ncost));
	    }	  
	  else if(mincost[nfield] > p.phase + 1)
	    {
	      mincost[nfield] = p.phase + 1;
	      Q.push(P(nfield,cur,p.phase+1,ncost));
	    }
	}

    }
  cout << -1 << endl;
}

int main()
{
  while(cin >> n,n)
    {
      mincost.clear();
      int sp;
      string field = "";
      int cost = 0;
      rep(i,n)
	{
	  string line;
	  cin >> line;
	  rep(j,n)
	    if(line[j] == '@')sp = i*n + j;
	    else if(line[j] == '#')cost++;
	  field += line;
	}

      if(cost == 0)
	{
	  cout << 0 << endl;
	  continue;
	}

      ans = inf;

      bfs(field,sp,0,cost);

    }
  return 0;
}

Measured memory_bytes: 4664
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<utility>

using namespace std;
using Int = long long;

int main(){
    int H, W;
    char V[500][500];
    vector<tuple<int, int, int, int>> move;
    cin >> H >> W;

    for (int h=0;h<H; h++){
        for (int w=0;w<W; w++){
            cin >> V[h][w] ; 
        }
    }

    for (int i=H-1;i>=0; i--){
        if (i % 2 == 1){
            for (int j=0; j<W; j++){
                if (V[i][j] % 2 == 1){
                    V[i][j]--;
                    if (j == W-1){
                        V[i-1][j]++;
                        move.emplace_back(i, j, i-1, j);
                    }else{
                        V[i][j+1]++;
                        move.emplace_back(i, j, i, j+1);
                    }
                }
            }
        }else{
            for (int j=W-1; j>=0; j--){
                if (V[i][j] % 2 == 1){
                    V[i][j]--;
                    if (j==0 && i-1 > 0){
                        V[i-1][j]++;
                        move.emplace_back(i, j, i-1, j);
                    }else if (j ==0 && i ==0){
                        V[i][j]++;
                    }else{
                        V[i][j-1]++;
                        move.emplace_back(i, j, i, j-1);
                    }
                }
            }
        }
    }

    // move.emplace_back(1, 1, 2, 3);
    cout << move.size() << endl;
    for (int i=0; i<move.size(); i++){
        int a, b, c, d;
        tie(a, b, c, d) = move[i];
        cout << a+1 << " " << b+1 << " " << c+1 << " " << d+1 << endl;
    }
}

Measured memory_bytes: 4464
import math

a, b, x = input().split(" ")
a = int(a)
b = int(b)
x = int(x)

taiseki = a * a * b

if taiseki - x < x:
    takasa = (taiseki - x) * 2 / (a * a)
    # print(takasa)
    print(math.degrees(math.atan(takasa/a)))
else:
    takasa = x * 2 / (a * b)
    # print(takasa)
    print(math.degrees(math.atan(b/takasa)))


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

string S;
char C[9] = { 'A', 'K', 'I', 'H', 'A', 'B', 'A', 'R', 'A' };

int main() {
    cin >> S;

    int pos = 0;
    for(int i = 0; i < S.size(); i++) {
        while(pos >= 9 || S[i] != C[pos]) {
            if(pos >= 9 || C[pos] != 'A') {
                printf("NO");
                return 0;
            }
            pos++;
        }
        if(pos >= 9) {
            printf("NO");
            return 0;
        }
        pos++;
    }
    while(pos < 9 && C[pos] == 'A') pos++;
    if(pos == 9) printf("YES");
    else printf("NO");
}


Measured memory_bytes: 256
import functools as ft
import heapq
import itertools as it
import logging
import unittest
from collections import (
    OrderedDict,
    defaultdict,
    namedtuple,
    Counter,
)

import numpy as np

_ = [ft, it, np, heapq, namedtuple, Counter, defaultdict, OrderedDict]

debug = logging.getLogger(__name__).debug


def input_ints():
    return list(map(int, input().strip().split()))


def _main():
    n, d = input_ints()
    x = [input_ints() for _ in range(n)]
    x = np.array(x)
    print(sum(
        d == np.round(d)
        for i in range(n)
        for j in range(i)
        for d in [np.sqrt(np.sum((x[i] - x[j]) ** 2))]
    ))


class Test(unittest.TestCase):
    def setUp(self):
        import run
        self._test = run

    def test_main(self):
        self._test.test_files(self, _main)


if __name__ == '__main__':
    _main()


Measured memory_bytes: 21316
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int M;

	cin >> M;

	cout << 48-M << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import Counter
import itertools
import fractions
from decimal import Decimal
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################


D=II()
if D == 25 :
    print('Christmas')
elif D == 24:
    print('Christmas Eve')
elif D == 23:
    print('Christmas Eve Eve')
else:
    print('Christmas Eve Eve Eve')

Measured memory_bytes: 5116
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

const int MA=430;
string s[888];

int d[888][888];

int ru(int a, int b){
	int r=a/b;
	if (a%b) r++;
	return r;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h,w,k;
	cin>>h>>w>>k;
	pair<int, int> sp;
	for (int i=0;i<h;i++){
		cin>>s[i];
		for (int ii=0;ii<w;ii++){
			d[i][ii]=(w*h+2)*2;
			if (s[i][ii]=='S'){
				d[i][ii]=0;
				sp={i, ii};
			}
		}
	}
	queue<pair<int, int> > bfs;
	bfs.push(sp);
	int ans=1e9;
	while (!bfs.empty()){
		auto x=bfs.front();
		bfs.pop();
		if (d[x.F][x.S]<=k){
			int dd=min(min(ru(x.F, k), ru(x.S, k)), min(ru(h-x.F-1, k), ru(w-x.S-1, k)));
			if (dd+1<ans){
				ans=dd+1;
			}
		}
		for (int j=-1;j<=1;j++){
			for (int jj=-1;jj<=1;jj++){
				if ((j==0)^(jj==0)){
					int ny=x.F+j;
					int nx=x.S+jj;
					if (ny<0||ny>=h) continue;
					if (nx<0||nx>=w) continue;
					if (s[ny][nx]=='#') continue;
					if (d[ny][nx]>d[x.F][x.S]+1){
						d[ny][nx]=d[x.F][x.S]+1;
						bfs.push({ny, nx});
					}
				}
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int A[5][2];
int main(){
    while(cin >> A[0][0] >> A[0][1]){
        if(A[0][0] + A[0][1] == 0){
            return 0;
        }
        cin >> A[1][0] >> A[1][1] >> A[2][0] >> A[2][1] >> A[3][0] >> A[3][1] >> A[4][0] >> A[4][1];
        int a0 = A[0][0] + A[0][1], a1 = A[1][0] + A[1][1], a2 = A[2][0] + A[2][1], a3 = A[3][0] + A[3][1], a4 = A[4][0] + A[4][1];
        if(a0 >= a1 && a0 >= a2 && a0 >= a3 && a0 >= a4){
            cout << "A " << a0 << endl;
        }
        if(a1 >= a0 && a1 >= a2 && a1 >= a3 && a1 >= a4){
            cout << "B " << a1 << endl;
        }
        if(a2 >= a0 && a2 >= a1 && a2 >= a3 && a2 >= a4){
            cout << "C " << a2 << endl;
        }
        if(a3 >= a0 && a3 >= a1 && a3 >= a2 && a3 >= a4){
            cout << "D " << a3 << endl;
        }
        if(a4 >= a0 && a4 >= a1 && a4 >= a2 && a4 >= a3){
            cout << "E " << a4 << endl;
        }
    }
    //cout << 654231 << endl;
    return 0;
}

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

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

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

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

//main code
int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL c(n-1),s(n-1),f(n-1);
	for (int i = 0; i < n-1; i++) {
		cin >> c[i] >> s[i] >> f[i];
	}

	VL ans(n,0);
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n-1; j++) {
			ans[i] += (s[j] <= ans[i] ? (((ans[i] - 1)/f[j]) + 1) * f[j] - ans[i] : s[j] - ans[i]) + c[j];
		}
	}
	for (int i = 0; i < n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}



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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    string w;
    cin >> w;

    set<char> roop;
    multiset<char> key;

    rep(i,w.size())
    {
        roop.insert(w[i]);
        key.insert(w[i]);
    }

    for( set<char>::iterator itr = roop.begin(); itr != roop.end(); itr++ )
    {
        if( key.count(*itr)%2 != 0 )
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 998244353
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000

int main(void) {
	int n; cin >> n;
	vint s(4);

	rep(i, n) {
		string x;
		cin >> x;
		if (x == "AC") {
			s[0]++;
		}
		if (x == "WA") {
			s[1]++;
		}
		if (x == "TLE") {
			s[2]++;
		}
		if (x == "RE") {
			s[3]++;
		}
	}

	cout << "AC x " << s[0] << endl;
	cout << "WA x " << s[1] << endl;
	cout << "TLE x " << s[2] << endl;
	cout << "RE x " << s[3] << endl;

	return 0;

}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1<<20)
#define NIL -1

struct RUQ {
	int N;
	int a[N_SIZE];
	int seg[N_SIZE * 2];
	int lazy[N_SIZE * 2];
	int gt;
	void init(int n) {
		N = n;
		gt = 1;
		while (N > gt)gt *= 2;
		REP(i, n)a[i] = (1LL << 31) - 1;
		REP(i, N_SIZE) {
			seg[i] = (1LL << 31) - 1;
			lazy[i] = NIL;
		}
		REP(i, n)seg[i + gt - 1] = a[i];
	}

	void lazy_evaluate(int k) {
		seg[k] = lazy[k];
		if (k < gt) {
			lazy[2 * k + 1] = lazy[k];
			lazy[2 * k + 2] = lazy[k];
		}
		lazy[k] = NIL;
	}

	void update(int a, int b, int x) {
		update(a, b, 0, 0, gt, x);
	}
	void update(int a, int b, int k, int l, int r, int x) {
		if (r <= a || b <= l)return;
		if (a <= l&&r <= b) {
			lazy[k] = x;
		}
		else {
			if (lazy[k] != NIL)lazy_evaluate(k);
			update(a, b, 2 * k + 1, l, (l + r) / 2, x);
			update(a, b, 2 * k + 2, (l + r) / 2, r, x);
		}
	}

	ll query(int a, int b) {
		return query(a, b, 0, 0, gt);
	}
	ll query(int a, int b, int k, int l, int r) {
		ll res = NIL;
		if (r <= a || b <= l)return res;
		if (a <= l&&r <= b) {
			//cout << k << endl;
			if (lazy[k] != NIL)lazy_evaluate(k);
			return seg[k];
		}
		else {
			if (lazy[k] != NIL) {
				//cout << k << endl;
				lazy_evaluate(k);
			}
			ll num[2] = { query(a, b, 2 * k + 1, l, (l + r) / 2),
				query(a, b, 2 * k + 2, (l + r) / 2, r) };
			REP(i, 2) {
				if (num[i] != NIL)res = num[i];
			}
		}
		return res;
	}

	void print() {
		REP(i, gt * 2) {
			cout << "!" << i << " " << seg[i] << " " << lazy[i] << endl;
		}
	}
};

RUQ ruq;

int n, q;

int main() {
	cin >> n >> q;
	ruq.init(n);
	REP(i, q) {
		int s, t, x;
		bool f;
		cin >> f;
		if (!f) {
			cin >> s >> t >> x;
			ruq.update(s, t + 1, x);
		}
		else {
			cin >> x;
			cout << ruq.query(x, x + 1) << endl;
		}
		//ruq.print();
	}
}

Measured memory_bytes: 11692
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    A.sort()

    S = A[0]
    ans = 1
    for a in A[1:]:
        if S * 2 < a:
            ans = 0
        S += a
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  vector<vector<ll>> ans(1, a);
  while (1) {
    priority_queue<ll, vector<ll>, greater<ll>> q0;
    for (int i = 0; i < n; i++) q0.push(a.at(i));
    if (q0.top() == 1) {
      cout << 1 << endl;
      return 0;
    }
    for (int i = 0; i < n; i++) {
      if (a.at(i) % q0.top() == 0) a.at(i) = q0.top();
      else a.at(i) %= q0.top();
    }
    if (a == ans.at(ans.size() - 1)) {
      priority_queue<ll, vector<ll>, greater<ll>> qend;
      for (int i = 0; i < n; i++) qend.push(a.at(i));
      cout << qend.top() << endl;
      return 0;
    }
    ans.push_back(a);
  }
}

Measured memory_bytes: 5220
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = "aiueo";
            var c = Read()[0];
            if (str.Contains(c))
            {
                Console.WriteLine("vowel");
            }
            else
            {
                Console.WriteLine("consonant");
            }

        }

        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

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

const int maxn=2005;
int d[maxn][maxn],x,y,n,cnt[maxn];

int main()
{
	scanf("%d %d %d",&n,&x,&y);
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j) {
			d[i][j]=min(j-i,abs(x-i)+abs(j-y)+1);
			cnt[d[i][j]]++;
		}
	for(int i=1;i<n;++i) printf("%d\n",cnt[i]);
}

Measured memory_bytes: 15360
#include <iostream>
using namespace std;
int main(void){
   int a,b,c,i;
    std::cin >> i;
   for(int j = 0; j < i;  j++){
       std::cin >> a >> b >> c;
       if(a > b && a > c){
           if(a * a == b * b + c * c)
           {
               std::cout << "YES" << std::endl;
           }
           else
           std::cout << "NO" << std::endl;
       }
       
        else if(b > a && b > c){
           if(b * b == a * a + c * c)
           {
               std::cout << "YES" << std::endl;
           }
           else
           std::cout << "NO" << std::endl;
       }
       
       else if(c > b && c > a){
           if(c * c == b * b + a * a)
           {
               std::cout << "YES" << std::endl;
           }
           else
           std::cout << "NO" << std::endl;
       }
       
       else
       std::cout << "NO" << std::endl;
   }
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int ans=-1;

int ex(string::iterator &it,int r){
    if(r==0){
        int res=ex(it,r+1);
        if(res==-1)return -1;
        while(true){
            if(*it=='+'){
                it++;
                int x=ex(it,r+1);
                if(x==-1)return -1;
                res+=x;
            }
            else if(*it=='-'){
                it++;
                int x=ex(it,r+1);
                if(x==-1)return -1;
                res-=x;
            }
            else break;
            if(res<0||res>=1024)return -1;
        }
        return res;
    }
    if(r==1){
        int res=ex(it,r+1);
        if(res==-1)return -1;
        while(true){
            if(*it=='*'){
                it++;
                int x=ex(it,r+1);
                if(x==-1)return -1;
                res*=x;
            }
            else break;
            if(res<0||res>=1024)return -1;
        }
        return res;
    }
    if(r==2){
        if(*it=='('){
            it++;
            int res=ex(it,0);
            it++;
            return res;
        }
        return ex(it,r+1);
    }
    if(r==3){
        if(!isdigit(*it))return -1;
        int res=0;
        while(isdigit(*it)){
            res=res*2+*it-'0';
            it++;
            if(res>=1024)return -1;
        }
        return res;
    }
}

void solve(string s){
    stack<int>st;
    vint beet(s.size(),-1);
    for(int i=0;i<s.size();i++){
        if(s[i]=='('){
            st.push(i);
        }
        else if(s[i]==')'){
            if(st.size()==0)return;
            int t=st.top();
            beet[t]=i;
            st.pop();
            if(s[t+1]=='('&&beet[t+1]==i-1)return;
            bool ok=false;
            for(int j=t+1;j<i;j++)if(s[j]=='+'||s[j]=='-'||s[j]=='*')ok=true;
            if(!ok)return;
        }
    }
    if(st.size())return;
    s+="=";
    auto it=s.begin();
    int tmp=ex(it,0);
    if(*it!='=')return;
    if(tmp==56)cout<<s<<endl;
    chmax(ans,tmp);
}

void dfs(int n,string &S){
    if(n==S.size()){
        solve(S);
        return;
    }
    if(S[n]=='.'){
        rep(i,7){
            S[n]="01+-*()"[i];
            dfs(n+1,S);
        }
        S[n]='.';
    }
    else{
        dfs(n+1,S);
    }
}

signed main(){
    string S;
    cin>>S;
    dfs(0,S);

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

Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <cctype>
#include <cstring>
using namespace std;

int tr[26], ans[26];
vector<string> split(string s) 
{
	vector<string> res;
	stringstream ss(s);

	string a;
	while(ss >> a) { res.push_back(a); }

	return res;
}

bool check(char a, char b)
{
	if(tr[a - 'A'] != -1 && tr[a - 'A'] != b) return false;
	if(tr[b - 'A'] != -1 && tr[b - 'A'] != a) return false;

	return true;
}

bool match(string w, string msg)
{
	for(int i=0; i<msg.size(); i++) {
		if(!check(w[i], msg[i])) return false; 
	}

	return true;
}

int dfs(int p, vector<string>& words, vector<string>& msg) 
{
	if(p == msg.size()) {
		memcpy(ans, tr, sizeof(ans));
		return 1;
	}
	
	int res = 0;	
	for(int i=0; i<words.size(); i++) {
		if(res >= 2) return 1192;
	
		if(msg[p].size() != words[i].size()) continue;
		if(!match(words[i], msg[p])) continue;
		
		bool valid = true;
		int t[26];
		memcpy(t, tr, sizeof(t));
		for(int j=0; j<msg[p].size(); j++) {
			if(!check(words[i][j], msg[p][j])) { valid = false; break; } 
			tr[msg[p][j] - 'A'] = words[i][j];
			tr[words[i][j] - 'A'] = msg[p][j];
		}
		if(valid) {
			res += dfs(p+1, words, msg);
		}
		memcpy(tr, t, sizeof(tr));
	}

	return res;
}

bool comp(const string& a, const string& b)
{
	if(a.size() != b.size()) return a.size() > b.size();
	return a > b;
}


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

		string str;
		getline(cin, str);
		getline(cin, str);
	
		str.erase(str.end() - 1);

		sort(words.begin(), words.end(), comp);

		vector<string> msg = split(str);
		sort(msg.begin(), msg.end());
		msg.erase(unique(msg.begin(), msg.end()), msg.end());
		sort(msg.begin(), msg.end(), comp);

		for(int i=0; i<26; i++) tr[i] = -1;

		int res = dfs(0, words, msg);
		if(res != 1) cout << "-." << endl;
		else {
			for(int i=0; i<str.size(); i++) {
				if(isalpha(str[i])) cout << (char)ans[str[i]-'A'];
				else cout << str[i];
			}

			cout << "." << endl;
		}
	}
	
}

Measured memory_bytes: 944
from copy import copy
import sys
from collections import Counter
n = int(input())
d = sorted(list(map(int, input().split())))
if d[0] == 0:
	print(0)
	sys.exit()
c = Counter(d)
if max(c.values()) >= 3:
	print(0)
	sys.exit()
if c[12] >= 2:
	print(0)
	sys.exit()

reserved = []
alternatives = []
for k, v in c.items():
	if v == 2:
		reserved.append(k)
		reserved.append(24-k)
	elif k == 12:
		reserved.append(12)
	else:
		alternatives.append(k)

m = len(alternatives)
#print(m)
ans = 0
for i in range(2**m):
	zones = copy(reserved)
	for j, a in enumerate(alternatives):
		if (i>>j)&1:
			zones.append(24-a)
		else:
			zones.append(a)
	zones.sort()
	zones = [0] + zones + [24]
	#print(zones)
	res = 24
	for j in range(len(zones)-1):
		res = min(res, zones[j+1]-zones[j])
	ans = max(ans, res)

print(ans)

Measured memory_bytes: 3444
#include <iostream>
#include <iomanip>

int GreatestCommonDivisor(int a, int b) {
	int x = a > b ? a : b;
	int y = a > b ? b : a;
	while (y != 0) {
		int tmp = x;
		x = y;
		y = tmp % y;
	}
	return x;
}

int main()
{
	int a, b;
	std::cin >> a >> b;
	std::cout << GreatestCommonDivisor(a, b) << std::endl;
}



Measured memory_bytes: 3092
import java.util.Scanner;

public class Main {

	static int n;
	static boolean[][] adj;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = Integer.parseInt(sc.next());
		adj = new boolean[n][n];
		for (int i = 0; i < n; i++) {
			Integer.parseInt(sc.next());
			int m = Integer.parseInt(sc.next());
			for (int j = 0; j < m; j++) {
				int to = Integer.parseInt(sc.next()) - 1;
				adj[i][to] = true;
			}
		}
		print();
	}

	public static void print() {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n - 1; j++) {
				System.out.print(adj[i][j] ? 1 : 0);
				System.out.print(" ");
			}
			System.out.println(adj[i][n - 1] ? 1 : 0);
		}

	}

}



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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


#print(make_divisors(3141))
#N, N-1, 2
#%*==1
ans=[2]
if N not in ans:
    ans.append(N)
if (N%(N-1)!=0) and (N-1 not in ans):
    ans.append(N-1)
D=make_divisors(N)
for d in D:
    now=N
    if d==1:
        continue
    while now%d==0:
        now=now//d
    if now%d==1:
        if d not in ans:
            ans.append(d)
#print(ans)

ans2=[]
for a in ans:
    i=1
    while a**i<=N:
        x=a**i
        now=N
        while now%x==0:
            now=now//x
        if now%x==1:
            if x not in ans2:
                ans2.append(x)

        i+=1
#print(ans2)
d2=make_divisors(N-1)
for d in d2:
    if d!=1 and (d not in ans2):
        ans2.append(d)
#print(ans2)
print(len(ans2))

Measured memory_bytes: 9516
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000004
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
#define fin ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{fin;

  ll n,i,W,j,k;
  cin>>n>>W;
  ll w[n];
  ll c[n];
  for(i=0;i<n;i++)
    cin>>w[i]>>c[i];
  ll dp[W+1][n];
  for(i=0;i<=W;i++)
  {
    for(j=0;j<n;j++)
      dp[i][j]=0;
  }
  for(i=1;i<=W;i++)
  {
    for(j=0;j<n;j++)
    {
      if(w[j]>i)
        dp[i][j]=0;
      else
        {
          dp[i][j]=c[j];
          for(k=0;k<j;k++)
            dp[i][j]=max(dp[i][j],dp[i-w[j]][k]+c[j]);
        }
    }
  }
  ll ans=-1;
  for(i=0;i<n;i++)
    ans=max(ans,dp[W][i]);
  cout<<ans;
}


Measured memory_bytes: 78336
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#define INF 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
signed main(){
    int n;
    cin>>n;
    string s;
    s=to_string(n);
    int k=s.size();
    int ans=0;
    for(int i=1;i<k;i++){
        if(i%2==1)ans+=pow(10,i-1)*9;
    }
    if(k%2==1)ans+=n-pow(10,k-1)+1;
    cout<<ans<<endl;
}


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

int main() {
  
  char op;
  int A, B;
  cin >> A >> op >> B;
  
  //cout << A << op << B << endl; 
  
  //int value = A;
  
  if(op == '+'){
    cout << A + B << endl;
  }
  
  if(op == '-'){
    cout << A - B << endl;
  }

}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

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


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 200005
using namespace std;
inline int in(){
    int x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
struct edge{
	int to,nxt;
}e[MN];
int head[MN],a[MN],p[MN],ot[MN],q[MN];
int n,x,cnt;
bool vis[MN];
inline void ins(int x,int y){
	e[++cnt].to=y;e[cnt].nxt=head[x];head[x]=cnt;
}
inline void gmex(int u){
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;vis[a[v]]=1;
	}
	for (int i=0;;++i) if (!vis[i]) {a[u]=i;break;}
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;vis[a[v]]=0;
	}
}
inline bool check(int u){
	for (int i=p[u];i!=u;i=p[i]) gmex(i);
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;vis[a[v]]=1;
	}bool mk=1;
	for (int i=0;;++i) if (!vis[i]) {if (a[u]!=i) mk=0;break;}
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;vis[a[v]]=0;
	}return mk;
}
int main()
{
	n=in();memset(a,-1,sizeof(a));
	for (int i=1;i<=n;++i){
		p[i]=in();ins(p[i],i);++ot[p[i]];
	}int hd=1,tl=0;
	for (int i=1;i<=n;++i) if (!ot[i]) q[++tl]=i;
	while (hd<=tl){
		int u=q[hd++];gmex(u);
		if (!(--ot[p[u]])) q[++tl]=p[u];
	}
	for (int i=1;i<=n;++i) if (a[i]==-1) x=i;
	gmex(x);if (check(x)) {printf("POSSIBLE");return 0;}vis[a[x]]=1;
	gmex(x);if (check(x)) printf("POSSIBLE");else printf("IMPOSSIBLE");return 0;
}

Measured memory_bytes: 5376
#include<stdio.h> 

int compareInt(const void* a, const void* b)
{
    int aNum = *(int*)a;
    int bNum = *(int*)b;

    return bNum - aNum;
}

int main(void)
{
  int n,k;
  unsigned long int counter=0;
  scanf("%d %d",&n,&k);
  unsigned int e[n];
  for (int i=0; i < n; i++) {
    scanf("%u", &e[i]);
  }
  qsort(e, (sizeof(e)/sizeof(e[0])), sizeof(int), compareInt);
  for (int j = k; j < n; j++) {
    counter += e[j];
  }
  printf("%ld",counter);
}


Measured memory_bytes: 1788
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let mut ans = 0;
    for i in 1..n / 2 + 1 {
        let x = n - i;
        if x != i {
            ans += 1
        }
    }
    println!("{}", ans)
}


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

int main()
{
  ll n;
  cin>>n;
  map<pair<ll,ll>,ll> path;
  vector<vector<ll>> connect(n);
  for (int i = 0; i < n-1; ++i)
  {
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    path[make_pair(a,b)]=c;
    path[make_pair(b,a)]=c;
    connect[a].push_back(b);
    connect[b].push_back(a);
  }
  ll q,k;
  cin>>q>>k;
  k--;
  vector<ll> dist(n);
  dist[k]=0;
  vector<bool> seen(n,false);
  seen[k]=true;
  queue<ll> next;
  next.push(k);
  while(!next.empty())
  {
    ll now=next.front();
    next.pop();
    for(const auto& e: connect[now]) 
    {
      if(seen[e]) continue;
      dist[e]=dist[now]+path[make_pair(now,e)];
      seen[e]=true;
      next.push(e);
    }
  }
  for (int i = 0; i < q; ++i)
  {
    ll x,y;
    cin>>x>>y;
    x--;y--;
    cout<<dist[x]+dist[y]<<endl;
  }
}

Measured memory_bytes: 21748
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    FOR(x,a,b){
        if (x % 10 == x / 10000 && (x / 10) % 10 == (x / 1000) % 10) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();

int main(){ 
  int x,y;//animals and legs
  cin>>x>>y;
  if(y%2!=0){
    cout<<"No"<<"\n";  
  }
  else if(y<=x*4&&y>=x*2){
    cout<<"Yes"<<"\n";  
  }
  else{
    cout<<"No"<<"\n";  
  }
  return 0;
}

Measured memory_bytes: 3628
# 34:14
from bisect import bisect_left


N = int(input())
L = sorted(map(int, input().split()))
ans = sum(
    j - bisect_left(L, L[i] - L[j] + 1, 0, j) for i in range(2, N) for j in range(i)
)
print(ans)


Measured memory_bytes: 3188
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const ll INF = 1e18;
const double pi = acos(-1);
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};


#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()


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





void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m; cin >> n >> m;
    ll sum = 0;
    rep(i,m){
        ll a; cin >> a;
        sum += a;
    }
    cout << ((n-sum>=0)?n-sum:-1) << endl;
    
    
}



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



Measured memory_bytes: 3664
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

pair<int, int> p[200010];

const int Z = (1<<18);
int sum[Z*2],pr[Z*2];

void in(int x, int p)
{
	x += Z;
	sum[x] += p; pr[x] = min(0,p);
	x /= 2;
	while (x){
		sum[x] = sum[x * 2] + sum[x * 2 + 1];
		pr[x] = min(pr[x*2], sum[x*2] + pr[x*2+1]);
		x /= 2;
	}
}

int main()
{
	int N,M;
	scanf ("%d %d",&N,&M);
	for (int i=0;i<N;i++){
		scanf ("%d %d",&p[i].first,&p[i].second);
		p[i].second = -p[i].second;
	}
	sort(p,p+N);

	for (int i=1;i<=M;i++) in(i,-1);
	for (int i=0;i<N;i++){
		p[i].second = -p[i].second;
	}

	int l = 0, r = 0;
	vector<int> u;
	for (int i=0;i<N;i++){
		if (p[i].first >= l + 1){
			u.push_back(p[i].second);
			l++;
		}
		else{
			in(p[i].second,1);
			while (M+pr[1] >= r + 1) r++;
		}
	}

	int ans = l + r;
	sort(u.rbegin(),u.rend());
	for (auto &x : u){
		l--;
		in(x,1);
		while (M+pr[1] >= r + 1) r++;
		ans = max(ans,l+r);
	}
	if (ans > M) ans = M;
	if (ans > N) ans = N;

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

	return 0;
}

Measured memory_bytes: 6520
n = int(input())
whole_answers = []
for i in range(n):
    a = int(input())
    answers = []
    for j in range(a):
        x, y = map(int, input().split())
        answers.append((x, y))
    whole_answers.append(answers)

# print(whole_answers)

max_count = 0

conflict = False
for i in range(2 ** n):
    conflict = False
    for j, answers in enumerate(whole_answers):
        if i >> j & 1:
            for x, y in answers:
                if (y == 1 and i >> (x - 1) & 1 == 0) or (y == 0 and i >> (x - 1) & 1 == 1):
                    # print(bin(i))
                    conflict = True
                    break
            if conflict:
                break
    if not conflict:
        count = bin(i)[2:].count('1')
        max_count = max(max_count, count)
print(max_count)


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		long mod = (long) (Math.pow(10.0, 9.0) + 7);
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long k = in.nextInt();
		int a[] = new int[n];

		for ( int i = 0; i < a.length; i++ ) {
			a[i] = in.nextInt();
		}

		long inner = 0; // 内部で成立する転倒数の個数
		long outer = 0; // 他のｎとの関係で成立しうる転倒数の個数
		for ( int i1 = 0; i1 < n; i1++ ) {
			for ( int i2 = 0; i2 < n; i2++ ) {
				if ( a[i1] > a[i2] ) {
					outer++;
					if ( i1 < i2 ) {
						inner++;
					}
				}
			}
		}
		long kk = (k - 1) * k / 2 % mod;
		long ans = (inner * k) % mod + (outer * kk) % mod;
		System.out.println(ans % mod);
		in.close();
	}
}

Measured memory_bytes: 28284
typedef long unsigned int size_t;
extern int printf (const char *__restrict __format, ...);
extern int scanf (const char *__restrict __format, ...) ;
extern int getchar (void);
extern int putchar (int __c);
int nextInt(){int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
char nextChar(){char f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
short int nextShort(){short f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
long long int nextLong(){long long int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
void println(){putchar(10);}
void print(char *f){while(*f){putchar(*f);f++;}}
void printInt(int f){char c[10];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
void printLong(long long int f){char c[19];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
int n, i;
char s[200002], c;
long ans, now;
int main(void){
 s[0]=getchar();
 n=1;
 while((c=getchar())!=10){
  if(s[n-1]=='B'&&c=='C'){
   s[n-1]='D';
  }else{
   s[n]=c;
   n++;
  }
 }
 s[n]=0;
 for(i=0; i<n; i++){
  if(s[i]=='A'){
   now++;
  }else if(s[i]=='D'){
   ans+=now;
  }else{
   now=0;
  }
 }
 printLong(ans); println();
}


Measured memory_bytes: 384
import copy
import sys
input = sys.stdin.readline

n, m = map(int,input().split())
graph = [[] for i in range(n+1)]
for i in range(m):
    u, v = map(int,input().split())
    graph[u].append(v)
s, g = map(int,input().split())

INF = 10**7
ans = [[INF, INF, INF] for i in range(n+1)]
q = [s]
d = 0
while q:
    nq = []
    d += 1
    p = d % 3
    for cf in q:
        for ct in graph[cf]:
            if ans[ct][p] == INF:
                ans[ct][p] = d
                nq.append(ct)
    q = nq
if ans[g][0] == INF:
    print(-1)
else:
    print(ans[g][0]//3)

Measured memory_bytes: 42408
import java.util.*;
public class Main{
	public static void main(String[] args) {
		try(Scanner sc=new Scanner(System.in)){
			int w=sc.nextInt();
			int n=sc.nextInt();
			int[] values=new int[w];
			for(int i=0;i<values.length;i++) {
				values[i]=i+1;
			}
			for(int i=0;i<n;i++) {
				String str=sc.next();
				String[] ab=str.split(",");
				int a=Integer.parseInt(ab[0])-1;
				int b=Integer.parseInt(ab[1])-1;
				int temp=values[a];
				values[a]=values[b];
				values[b]=temp;
			}
			for(int i=0;i<values.length;i++) {
				System.out.println(values[i]);
			}
		}
	}
}



Measured memory_bytes: 26080
#include <bits/stdc++.h>
#include <math.h>
#include<map>
#include<algorithm>
using namespace std;
typedef long long int ll;
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; }
#define all(a)  (a).begin(),(a).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define vll vector<ll>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i]>>y[i];
const ll INF =1LL << 62;

int main(){
  ll N,Q; cin >> N>>Q;
  string s;
  cin >> s;
  vector<int> l(Q),r(Q);
  for(int i=0;i<Q;i++){
    cin >> l[i] >> r[i];
  }
  vector<int>sum(N+1,0);
  for(int i=1;i<N;i++){
    if(s[i-1] == 'A' && s[i] == 'C' ){
      sum[i+1] = sum[i] +1;
    }
    else
      sum[i+1] = sum[i] ;
  }
  for(int i=0;i<Q;i++){
    int ans = sum[r[i]] -sum[l[i]];
    cout << ans << endl;
  }
}


Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
using namespace std;
int a[1000],n,m;
long long b=0,k;
int main(){
  cin>>n>>m;
  bool ff=false;
  for(int i=0;i<n;i++){
	cin>>a[i];
    b+=a[i];
  }
  //sort(a,a+n);
  //double d=b/(4*m);
  //cout<<b<<endl;
	for(int i=n-1;i>=0;i--){
		if(a[i]*4*m>=b){
			k++;
		}
		if(k>=m){
			ff=true;break;
		}
	}
  if(ff){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
typedef long long ll;
ll x, d, k;
int main() {
    cin >> x >> k >> d;
    if(x < 0) x = -x;
    ll cnt = x / d;
    if(k <= cnt) {
        printf("%lld\n", abs(x - k * d));
    }
    else {
        ll tmp = k - cnt;
        if(tmp & 1) printf("%lld\n", abs(x - (cnt + 1) * d));
        else printf("%lld\n", abs(x - cnt * d));
    }
}


Measured memory_bytes: 3760
# -*- coding: utf-8 -*-
N = int(input())
As = list(map(int, input().split()))
res = 0
for i in range(N-1):
    if As[i] > As[i+1]:
        res += As[i] - As[i+1]
        As[i+1] = As[i]
print(res)


Measured memory_bytes: 104848