akhauriyash/Code-Regression huggingface dataset:
import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_3.txt', 'r')
# sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


MOD = 2  # type: int


if __name__ == '__main__':
    N, M = mi()
    s = []
    k = [0]*M
    for i in range(M):
        k[i], *tmp = lmi()
        # print(tmp)
        s.append(tmp)
    # print(s)
    p = lmi()
    cnt = 0
    for i in range(2 ** N):
        flag = True
        for num in range(M):
            tmp_cnt = 0
            for sw in s[num]:
                if ((i >> sw - 1) & 1):
                    tmp_cnt += 1
            if tmp_cnt % 2 == p[num]:
                continue
            else:
                flag = False
                break
        if flag:
            cnt += 1
    print(cnt)


Measured memory_bytes: 5712
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
const ll mod = 1000000007;
const ll INF = 1000000000000000;

ll bit[200010];
ll n;

string d[210];

ll jud[210];
bool D;
ll ans;
vector<int> G[210];

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= n)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll pow_mod(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y % 2 == 1)
		{
			(res *= x) %= mod;
		}
		(x *= x) %= mod;
		y /= 2;
	}
	return res;
}

ll div(ll x)
{
	return pow_mod(x, mod - 2);
}

int main(void)
{
	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> d[i];
		for (int j = 1; j <= n; j++)
		{
			if (d[i][j - 1] == '1')
			{
				G[i].push_back(j);
			}
		}
	}
	

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			jud[j] = INF;
		}
		
		D = false;

		priority_queue<P, vector<P>, greater<P>>que;
		que.push(P(1, i));
		while (que.size())
		{
			P p = que.top(); que.pop();
			if (jud[p.second] != INF)
			{
				if (jud[p.second] != p.first)
				{
					D = true;
				}
				continue;
			}
			jud[p.second] = p.first;
			for (int j = 0; j < G[p.second].size(); j++)
			{
				if (jud[G[p.second][j]] == INF)
				{
					que.push(P(p.first + 1, G[p.second][j]));
				}
				else
				{
					if (jud[G[p.second][j]] != p.first - 1)
					{
						D = true;
					}
				}
			}
		}

		for (int j = 1; j <= n; j++)
		{
			if (!D)
			{
				ans = max(ans, jud[j]);
			}
		}
	}

	if (ans == 0)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << ans << endl;
	}

	int www;
	cin >> www;
}


Measured memory_bytes: 1440
//2*10^9
//9*10^18
// __int128_t 
#include<bits/stdc++.h>
using namespace std;

#define ull unsigned long long int
#define ll long long int

const ll M=1e9+7;

//to handle when remainder is -neg we add + M
//but when rem is +pos that time also we add so use %M
//so it will work for both
ll mod(ll n){
    return (n%M + M)%M; 
}
ll modAdd(ll a, ll b){
    return mod(mod(a)+mod(b));
}
ll modMul(ll a, ll b){
    return mod(mod(a)*mod(b));
}
ll modMinus(ll a, ll b){
    return mod(mod(a)-mod(b));
}
ll modpow(ll x, ll n) 
{ 
    if (n == 0) 
        return 1%M;
    if (n == 1)
        return x%M; 
    ll u = modpow(x,n/2); 
    u = modMul(u,u); 
    if (n%2) 
        u = modMul(u,x); 
    return u; 
}
ll gcd(ll a,ll b){
    if(b==0)
        return a;
    return gcd(b,a%b);
}
bool isPrime(ll n){
    int end = sqrt(n);
    for(int i=2;i<=end;i++)
        if(n%i==0)
            return false;
    return true;
}

void travel(int start,vector<int> &visited,vector<vector<int>>&graph){
    visited[start]=1;
    for(int i=0;i<graph[start].size();i++){
        if(visited[graph[start][i]]==0)
            travel(graph[start][i],visited,graph);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
  
    
    int t=1;
    //cin>>t;

    while(t--){
        int n,m;
        cin>>n>>m;

        vector<vector<int>> graph(n+1);
        vector<int> visited(n+1);
        int ans=0,s,d;

        for(int i=0;i<m;i++){
            cin>>s>>d;
            graph[s].push_back(d);
            graph[d].push_back(s);
        }

        for(int i=1;i<=n;i++){
            if(visited[i]==0){
                ans+=1;
                travel(i,visited,graph);
            }
        }
        cout<<ans-1<<endl;
    }
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();
        var array = new int[32] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
        Console.WriteLine(array[int.Parse(input) - 1]);
    }
}

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

int main() {
	int n;
	cin >> n;
	if (n == 1) {
		puts("Hello World");
	} else {
		int a, b;
		cin >> a >> b;
		printf("%d\n", a + b);
	}
        return 0;
}


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

int main() {
  int N;
  cin >> N;
  long long int ans = 0;

  vector<int> A(3 * N);
  for(int i = 0; i < 3 * N; i++) cin >> A[i];
  sort(A.begin(), A.end());

  for(int i = 0; i < N; i++) {
    ans += A[3 * N - (i + 1) * 2];
  }

  cout << ans << endl;
}

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

    int main() {
        long  double L;
        long  double tate,yoko,nana;
        cin >> L;
        tate = L/3;
        yoko = tate;
        nana = tate;
        cout << setprecision(999) << tate*yoko*nana <<endl;
        return 0;

    }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::cin >> n;
	std::vector<int> a(n, 0);
	for(int i = 0; i < n; i++) {
		int x;
		std::cin >> x;
		a[x-1]++;
	}
	std::sort(a.rbegin(), a.rend());
	while(a.back() == 0) a.pop_back();
	std::reverse(a.begin(), a.end());
	int pt = (int) a.size();
	int sum = n;
	int used = 0;
	for(int i = 1; i <= n; i++) {
		// a[pt-1] > n / i
		used++;
		while(pt > 0 && (long long) a[pt-1] * used > sum) {
			sum -= a[--pt];
			used--;
		}
		//std::cout << "at " << i << " got sum " << sum << ", using " << used << '\n';
		std::cout << (used == 0 ? 0 : sum / used) << '\n';
	}
}

Measured memory_bytes: 2048
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
N = inp.shift() * 1
A = inp.shift().split(" ").map(x => x - 0)
b = true
for (i=0; i<N; i++) {
    if (A[i] % 2 === 0) {
        if (A[i] % 3 === 0 || A[i] % 5 === 0) {
            
        } else {
            b = false
        }
    }
}
console.log(b ? "APPROVED" : "DENIED")


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

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) (int)x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-7

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(str) scanf("%s",str)
#define pi(x) printf("%d",x)
//#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define NL printf("\n")
#define Max 200005
#define INF 1e18
#define un(x) x.erase(unique( x.begin() , x.end() ), x.end())
#define mod 1000000007

#define FI freopen("z.txt","r",stdin)

#define D(x) cout << #x << " = " << x << endl
#define DD(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define DDD(x,y,z) cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl
#define all(x) x.begin(),x.end()
#define prntvctr(x) for(int i = 0; i < x.size(); i++) printf("%d%c", x[i], i + 1 == x.size() ? '\n' : ' ' );
#define pc(x) __builtin_popcount(x)

typedef long long LL;
typedef unsigned long long ULL;

const double PI = acos(-1.0);

using namespace std;

int setb(int n,int pos)
{
    return n=n | (1 << pos);
}
int resb(int n,int pos)
{
    return n=n & ~(1 << pos);
}
bool checkb(LL n,LL pos)
{
    return (bool)(n & (1ll << pos));
}

LL bigmod(LL b,LL p,LL m)
{
    if( p == 0 ) return 1;
    LL ret = bigmod(b,p/2,m);
    ret = ( ret * ret ) % m;
    if( p & 1 ) ret = ( ret * b ) % m;
    return ret;
}

LL n, ara[Max], sum[Max];

LL get_idx(LL l, LL r)
{
	LL low = l, high = r, mid, ans = l;
	LL tot = sum[r] - sum[l-1];
	while( low <= high )
	{
		mid = (low + high) / 2;
		LL my = sum[mid] - sum[l-1];
		if( my + my <= tot )
		{
			ans = mid;
			low = mid + 1;
		}
		else high = mid - 1;
	}
	return ans;
}

inline bool oka(LL idx) { return (1 <= idx && idx <= n); }

LL go(LL idx)
{
    LL l = get_idx(1,idx);
    LL r = get_idx(idx+1,n);
    LL ret = 1e18;
    for(LL i = l - 2; i <= l + 2; i++)
    {
		for(LL j = r - 2; j <= r + 2; j++)
		{
			if( oka(i) && oka(j) && i < idx && idx < j && j < n )
			{
				vector <LL> v;
				v.pb( sum[i] );
				v.pb( sum[idx] - sum[i] );
				v.pb( sum[j] - sum[idx] );
				v.pb( sum[n] - sum[j] );
				sort( all(v) );
				ret = min( ret , v.back() - v[0] );
			}
		}
    }
    return ret;
}

LL solve()
{
	LL ret = 1e18, i;
	rep(i,n) ret = min( ret , go(i) );
	return ret;
}

int main()
{
	//FI;
	LL i;
	sl(n);
	rep(i,n) sl(ara[i]), sum[i] = sum[i-1] + ara[i];
	LL ret = solve();
	pl( ret ); NL;
	return 0;
}


Measured memory_bytes: 3328
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
    string s; cin >> s;
    reverse(s.begin(), s.end());
    string rev = "FESTIVAL";
    reverse(rev.begin(), rev.end());
    int idx = s.find(rev);

    string ans = s.substr(idx + 8);
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

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

#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound 
 
namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) {int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) {  for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0;}
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void gp (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::gp;
 
void scan() {
	return;
}
 
template<class T, typename... Args>
void scan(T &a, Args&&... args) {
	gi(a);
	scan(args...);
	return;
}

template<typename T>
void scann(T a, T b) {
	for (auto it = a; it != b; ++it)
		scan(*it);
}
 
template<typename T>
void scerr(T a, T b) {
	for (auto it = a; it != b; ++it)
		cerr << *it << " ";
	cerr << '\n';
}

void print() {
	pc('\n');
	return;
}
 
template<class T, typename... Args>
void print(T a, Args... args) {
	gp(a);
	pc(' ');
	print(args...);
	return;
}
 
void cer() {
	return;
}
 
template<class T, typename... Args>
void cer(T a, Args... args) {
	cerr << " " << a;
	cer(args...);
	return;
} 

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, int> mll;
 
const int N = 2e5 + 2;
const int M = 1e6 + 2;
const int mod = 998244353;
const int inf = 2e9 + 3;
const ll INF = 1e16;

void data() {
	#ifdef PC
		freopen("a.in", "r", stdin);
		freopen("a.out", "w", stdout);
	#endif
}

string s;

int main() {
	data();
	cin >> s;
	reverse(all(s));
	if (s[0] == '3')
		cout << "bon";
	else if (s[0] == '0' || s[0] == '1' || s[0] == '6' || s[0] == '8')
		cout << "pon";
	else
		cout << "hon";		
}	


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
using llng = long long;
template<typename T> using v = vector<T>;
template<typename T> using vv = v<v<T> >;

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

    for (int n=0; n<=N; n++) {
        for (int m=0; m<=M; m++) {
            int cnt = n*(M-m) + (N-n)*m;
            if (cnt == K) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <iostream>
#include <set>
#include <utility>
#include <vector>

using namespace std;

int main(){
  int N, K;
  scanf("%d%d", &N, &K);
  vector<long long int> a(N, 0);
  long long int psum = 0;
  long long int sum = 0;
  for (int i = 0; i < N; i++){
    scanf("%lld", &(a[i]));
    psum += max(a[i], (long long int)0);
    sum += a[i];
  }
  //cerr << psum << ',' << sum << endl;
  long long int psumK = 0;
  long long int sumK = 0;
  for (int i = 0; i < K; i++){
    psumK += max(a[i], (long long int)0);
    sumK += a[i];
  }
  //cerr << sumK << ',' << psumK << endl;
  long long int maxsum = sum;
  for (int i = 0; i < N-K; i++){
    maxsum = max(maxsum, psum-psumK+max(sumK,(long long int)0));
    sumK += a[i+K]-a[i];
    psumK += max(a[i+K], (long long int)0)-max(a[i], (long long int)0);
    //cerr << i << ',' << sumK << ',' << psumK << ',' << maxsum << endl;
  }
  maxsum = max(maxsum, psum-psumK+max(sumK,(long long int)0));
  cout << maxsum;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI (acos(-1))
#define ct cout<<
#define cn cin>>
#define spc <<" "<<
#define nl puts("")
#define _fl(x) puts("FLAG " #x);
#define  _(x)  cout<< #x <<" is "<< x <<endl;
#define fs first
#define sc second
#define pb push_back
#define all(v)  (v).begin(), (v).end()
#define _109 (1000000000)
#define _0(arr) memset(arr,0,sizeof ( arr ) )
#define _1(arr) memset(arr,-1,sizeof ( arr ) )
#define _ninp(n,arr) for(int i=0; i<n;i++)cin>>arr[i];
#define _nout(n,arr) for(int i=0; i<n;i++)cout<<arr[i]<<" \n"[i==n-1];
double _eps = 1e-6;
long long gcd(long long a, long long b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}



int main()
{


    int n;
    cn n;
    int l = 1 << n;

    std::vector<pair<int, int>> v[n + 10];
    for (int i = 0; i < n; ++i)
    {
        int nn;
        cn nn;
        for (int j = 0; j < nn; ++j)
        {
            int a, b;
            cn a >> b;
            a--;
            b = (b == 0) ? -1 : 1;
            v[i].pb({a, b});
        }
    }

    int mx = 0;
    for (int i = 0; i < l; ++i)
    {

        int tmp[20];
        _0(tmp);

        int cm = i;
        int k = 0;
        while(cm && k < n )
        {
            tmp[k] = cm & 1;
            cm /= 2;
            k++;
        }

        int cnt = 0;
        int tmp2[20];
        _0(tmp2);
        int br = 0;
        for(int j = 0; j < n ; j++)
        {
            if(tmp[j])
            {
                cnt++;
                for(auto x : v[j])
                {
                    if(tmp2[x.fs] == 0)
                    {
                        tmp2[x.fs] = x.sc;
                    }
                    else if(tmp2[x.fs] != x.sc)
                    {
                        br = 1;
                        break;
                    }
                }
                if(br)break;

            }
        }
        if(br)continue;


        for (int j = 0; j < n; ++j)
        {
            if(tmp[j] && tmp2[j] && tmp2[j] !=1)
            {
                br = 1;
                break;

            }
            if(tmp[j]==tmp2[j] && tmp[j]==1)tmp2[j]=2;
        }

        for (int j = 0; j < n; ++j)
        {
            if(tmp2[j]==1){
                br=1;
                break;
            }
        }

         if(!br)mx = max(mx, cnt);


        }
        ct mx;
        nl;






        return 0;
    }


Measured memory_bytes: 256
for e in iter(input,'0 0'):
 a,b=map(int,e.split())
 m=[[0]*b for _ in[0]*a]
 for _ in[0]*int(input()):
  i,j=map(int,input().split())
  m[~-i][~-j]=-1
 for s in range(a):
  for t in range(b):
   u,v=m[s-1][t],m[s][t-1]
   if m[s][t]>=0:m[s][t]=(u*(u>0)+v*(v>0))+(s+t==0)
 print(m[~-a][~-b])


Measured memory_bytes: 5600
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
struct list{
    int key;
    struct list *next,*back;
};
 
struct list *list;
  
struct list * search(int key){
    struct list *x = list->next;
    while(x!=list && x->key!=key) x = x->next;
    return x;
}
 
void init(){
    list = (struct list *)malloc(sizeof(struct list));
    list->next = list;
    list->back = list;
}
 
void print(){
    struct list *x = list->next;
    int i = 0;
    while(1){
       if(x == list) break;
       if(i++ > 0) printf(" ");
        printf("%d", x->key);
        x = x->next;
    }
    printf("\n");
}
 
void insert(int key){
    struct list *x = (struct list *)malloc(sizeof(struct list));
    x->key = key;
    x->next = list->next;
    list->next->back = x;
    list->next = x;
    x->back = list;
}
 
void delete(struct list *x){
    if(x == list) return;
    x->back->next = x->next;
    x->next->back = x->back;
    free(x);
}
 
int main(){
    int key, n, i;
    char ins[20];
    scanf("%d", &n);
    init();
  
    for(i = 0; i < n; i++){
      scanf("%s %d", ins, &key);
      if(ins[0] == 'i'){
          insert(key);
      }
      else if(ins[0] == 'd'){
          if(strlen(ins) > 6){
              if(ins[6] == 'F') delete(list->next);
              else if(ins[6] == 'L') delete(list->back);
          }else {
              delete(search(key));
          }
      }
    }
    print();
    return 0;
}

Measured memory_bytes: 31784
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

MAX = 10 ** 5 + 10

fact = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact[i] = (fact[i-1] * i) % mod

inv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
    inv[i] = inv[mod % i] * (mod - mod // i) % mod

fact_inv = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact_inv[i] = fact_inv[i-1] * inv[i] % mod


def comb(n, r):
    if n < r:
        return 0

    return fact[n] * fact_inv[n-r] * fact_inv[r] % mod


c = Counter(a)
for key, val in c.items():
    if val == 2:
        break

idx = []
for i, e in enumerate(a):
    if e == key:
        idx.append(i)

l = idx[0]
r = n - idx[1]
for k in range(1, n + 2):
    ans = comb(n + 1, k) - comb(l + r, k - 1)
    ans %= mod
    print(ans)


Measured memory_bytes: 30048
package main

import (
	"fmt"
	"math"
)

func abs(a float64) float64 {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	var n, d int
	fmt.Scan(&n, &d)
	x := make([][]float64, n)
	for i := range x {
		x[i] = make([]float64, d)
		for j := range x[i] {
			fmt.Scan(&x[i][j])
		}
	}
	ans := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			sum := 0.0
			for k := 0; k < d; k++ {
				sum += abs(x[i][k]-x[j][k]) * abs(x[i][k]-x[j][k])
			}
			d := math.Sqrt(sum)
			if math.Ceil(d) == math.Floor(d) {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


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

int main() {
	int N, A, B, C, D;
	cin >> N >> A >> B;
	C = B - (N - A);
	D = A - (N - B);
	if (C < 0) {
		C = 0;
	}
	if (D < 0) {
		D = 0;
	}
	if (A >= B) {
		cout << B << " " << C << endl;
	}
	else {
		cout << A << " " << D << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int first = Integer.parseInt(scan.next());
        int second = Integer.parseInt(scan.next());
        //int third = Integer.parseInt(scan.next());
        //String s = scan.next();
        //String second = scan.next();
        //for (int i = 1; i <=input; i++) {
        //}
        if(first-(second*2) > 0) {
            System.out.println(first-(second*2));
        } else {
            System.out.println(0);
        }
    }

}


Measured memory_bytes: 23764
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

int main()
{
      ios::sync_with_stdio(0);

      int x, y, ans = 0;
      cin >> x >> y;

      for (int i = 0; i <= x; ++i)
      {
            if (i * 2 + (x - i) * 4 == y) 
                  ans++;
      }
      cout << ((ans>0)?"Yes":"No") << "\n";

      return 0;
}

Measured memory_bytes: 3628
<?php
const MOD = 1000000007;
const MAX = 2000000;   //
init();


[$K] = fscanf(STDIN, "%d");
[$s] = fscanf(STDIN, "%s");
$S = strlen($s);
//$S = 1000000;
$five = [];
$six = [];
$tf = 1;
$ts = 1;
for($i=0;$i<1000002;$i++){
    $five[$i] = $tf;
    $six[$i] = $ts;
    $tf *= 25;
    $tf %= MOD;
    $ts *= 26;
    $ts %= MOD;
}

$A = $S + $K;
$ans = 0;
for($i=0;$i<=$K;$i++){
    $tmp = ($five[$i] * $six[($K - $i)]) % MOD;
    $mul = Combination($i + $S-1, $S-1);
    $ans += $tmp * $mul;
    $ans %= MOD;
}
echo $ans;



function init(){
    global $fac, $finv, $inv;
    $fac[0] = $fac[1] = 1;
    $finv[0] = $finv[1] = 1;
    $inv[1] = 1;
    for($i=2;$i<=MAX; $i++){
        $fac[$i] = $fac[$i-1] * $i % MOD;
        $inv[$i] = MOD - $inv[MOD%$i] * intdiv(MOD , $i) % MOD;
        $finv[$i] = $finv[$i - 1] * $inv[$i] % MOD;

    }
    $a = 0;
}


function Combination($n, $k){
    global $fac,$finv;
    if($n == $k){
        return(1);
    }
    if($n < $k){
        return 0;
    }elseif($n < 0 || $k < 0){
        return 0;
    }
    return $fac[$n] * ($finv[$k] * $finv[$n-$k] % MOD) % MOD;

}


Measured memory_bytes: 301984
S = list(input())

N = len(S)
flag = 0
#回文か
for i in range(int(N/2)):
    if S[i] != S[N-i-1]:
        flag = 1
        break

for j in range(int(((N-1)/2)/2)):
    if S[i] != S[int(((N-1)/2)-i-1)]:
        flag = 1
        break

for k in range(int((N - ((N+3)/2)))):
    if S[int((N+3)/2 -1)] != S[N-i-1]:
        flag = 1
        break

if flag==0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38440
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9 + 5
#define ll long long

int main(){
	int n, w;
	cin >> n >> w;
	vector<ll> dp(w+1, 0);
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		ll weight, value;
		cin >> weight >> value;
		for(int weight_already = w - weight; weight_already >= 0; weight_already--){
			dp[weight_already + weight] = max(dp[weight_already] + value, dp[weight_already + weight]);		
		}
	}
	ll ans = 0;
	for(int i = 0; i <= w; i++){
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define int ll

using namespace std;
using ll = long long;
// #include "debug.h"
#define debug(...) 42

void solve() {
   ll a, b;
   cin >> a >> b;
   ll g = __gcd(a, b);
   int cnt = 1;
   ll G = g;
   for(int i = 2; i * 1LL * i <= G; i++) {
      cnt += !(g % i);
      while(g % i == 0) {
         g /= i;
      }
   }
   cnt += g > 1;
   // debug(g, cnt);
   cout << cnt << endl;
} 

signed main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve();
   }
   return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int SIZEN = 52;
LL f[1<<21];
struct Link{
    int to,next;
}link[SIZEN << 1];
int head[SIZEN],tot = 0;
int fa[SIZEN];
int deep[SIZEN];
int contain[SIZEN];
int N,M;
void add(int from,int to){
    link[++tot].to = to;
    link[tot].next = head[from];
    head[from] = tot;
}
void dfs(int x){
    for(int i = head[x];i;i=link[i].next){
        if(link[i].to == fa[x])continue;
        fa[link[i].to] = x;
        deep[link[i].to] = deep[x] + 1;
        dfs(link[i].to);
    }
}
void add(int u,int v,int id){
    while(deep[u] != deep[v]){
        if(deep[u] < deep[v])swap(u,v);
        contain[u] |= (1<<id-1);
        u = fa[u];
    }
    while(u != v){
        contain[u] |= (1<<id-1);
        contain[v] |= (1<<id-1);
        u = fa[u];
        v = fa[v];
    }
}
int main(){
    scanf("%d",&N);
    for(int i = 1;i < N;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        add(x,y);
        add(y,x);
    }
    dfs(1);
    scanf("%d",&M);
    for(int i = 1;i <= M;i++){
        int u,v;scanf("%d%d",&u,&v);
        add(u,v,i);
    }
    memset(f,0,sizeof f);
    f[0] = 1;
    for(int i = 2;i <= N;i++){
        int S0 = contain[i];
        for(int S = (1<<M)-1;S >= 0;S--){
            f[S|S0] += f[S];
        }
    }
    printf("%lld\n",f[(1<<M)-1]);
    return 0;
}

Measured memory_bytes: 18108
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

vector<pi> cnt[100005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	rep(i, m){
		int a, b;
		cin >> a >> b;
		cnt[a].pb(mp(b, i));
	}
	vector<string> id(m);
	repn(i, 1, n + 1) if(cnt[i].size()){
		sort(all(cnt[i]));
		int ind = 1;
		for(pi c : cnt[i]){
			//prefecture
			string s = to_string(i);
			int l = s.length();
			string s1 = "";
			rep(j, 6 - l) s1 += '0';
			string p1 = s1 + s;
			//city id
			string f = to_string(ind);
			int len = f.length();
			string f1 = "";
			rep(j, 6 - len) f1 += '0';
			string p2 = f1 + f;
			id[c.se] = p1 + p2;
			ind++;
		}
	}
	rep(i, m){
		cout << id[i] << endl;
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 12416
#include "bits/stdc++.h"
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 ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll a,b,c=0,d=0,n,m1,n2,m2,min=100000,k=0,ans=0;
    string s,s2;
    cin >> s >> s2;
    sort(ALL(s));
    sort(s2.rbegin(),s2.rend());
    if(s < s2)
        cout << "Yes" <<endl; 
    else cout << "No" <<endl; 
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  map<string,int> m;
  string S;
  for(int i=0;i<N;i++){
    cin >> S;
    if(m.count(S)){
      m.at(S)++;
    }else{
      m[S]=1;
    }
  }
  vector<string> vs={"AC", "WA", "TLE", "RE"};
  for(auto x:vs){
    cout << x << " x ";
    if(m.count(x)){
      cout << m.at(x) << endl;
    }else{
      cout << 0 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3636
A, B, C, K = map(int, input().split())

if K<A:
    result = 1*K
elif A<=K and K<=A+B:
    result = 1*A
elif A+B<K and K<=A+B+C:
    result = 1*A + (-1)*(K-A-B)
else:
    result = 1*A + (-1)*C

print(result)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define ll long long
#define MAX 5005
using namespace std;

int n, a[MAX];
ll f[MAX], A, B;

int main()
{
    cin >> n >> A >> B;
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
    }
    memset(f, 0x3f, sizeof(f));
    f[0] = 0;
    a[n+1] = n+1;
    n++;
    for(int i = 1; i <= n; i++){
        ll s = 0;
        for(int j = i-1; j >= 0; j--){
            if(a[i] > a[j]){
                f[i] = min(f[i], f[j]+s);
                s += B;
            }
            else s += A;
        }
    }
    cout << f[n] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define st first
#define nd second
#define turbo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define qi queue<int>
#define ld long double

using namespace std;

/*---------------------------------------------------------///CODE///---------------------------------------------------------*/

ld dp[3001][3001];
ld T[3001];

int main()
{
    turbo

    int n; cin >> n;

    for(int i = 1; i <= n; i++) 
        cin >> T[i];

    dp[1][1] = T[1];
    dp[1][0] = 1 - T[1];

    for(int i = 2; i <= n; i++)
        dp[i][0] = dp[i - 1][0]*(1 - T[i]);
    

    for(int i = 2; i <= n; i++)
        for(int j = 1; j <= i; j++)
            dp[i][j] = dp[i - 1][j - 1]*T[i] + dp[i - 1][j]*(1- T[i]);

    ld ans = 0;

    for(int i = n / 2 + 1; i <= n; i++)
        ans += dp[n][i];
    
    return cout << fixed << setprecision(10) << ans, 0;
}

Measured memory_bytes: 139136
n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]
c = [0] * n
for ai in a:
    c[ai - 1] += 1
ans = ['Yes' if k - q + ci > 0 else 'No' for ci in c]
print(*ans, sep='\n')

Measured memory_bytes: 15976
#include<bits/stdc++.h>
using namespace std;
int main()
{
      ios::sync_with_stdio(), cin.tie(0), cout.tie(0);
      string s;
      while(cin>>s)
      {
            if (s[2]==s[3]&&s[4]==s[5])
            {
                  cout << "Yes" << endl;
            }
            else
            {
                  cout << "No" << endl;
            }
      }
      return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 58;

int main()
{
  int N, M, K, A[20000];
  int64 dp[20001];
  
  scanf("%d %d %d", &N, &M, &K);
  for(int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }

  fill_n(dp, 20001, INF);
  dp[0] = 0;
  for(int i = 0; i < N; i++) {
    int small = A[i], large = A[i];
    for(int j = 0; j < min(M, N - i); j++) {
      small = min(small, A[i + j]);
      large = max(large, A[i + j]);
      dp[i + j + 1] = min(dp[i + j + 1], dp[i] + K + 1LL * (j + 1) * (large - small));
    }
  }
  cout << dp[N] << endl;
}

Measured memory_bytes: 1440
n = int(input())
a1list = list(map(int, input().split()))
a2list = list(map(int, input().split()))

countlist = []
for i in range(n):
  p = sum(a1list[0:i+1]) + sum(a2list[i:n])
  countlist.append(p)
  
print(max(countlist))


Measured memory_bytes: 3060
N = int(input())
A = sorted(list(map(int,input().split())))

if N%2==0:
  B = [1+2*(n//2) for n in range(N)]
else:
  B = [2*(n//2) for n in range(1,1+N)]

if A==B:
  print(pow(2,N//2,10**9+7))
else:
  print(0)

Measured memory_bytes: 20516
import sys
def input(): return sys.stdin.readline().strip()


def main():
    H, W, K = map(int, input().split())
    C = [input() for _ in range(H)]
    ans = 0
    for row in range(1 << H):
        for col in range(1 << W):
            cnt = 0
            for i in range(H):
                for j in range(W):
                    if (row & (1 << i)) or (col & (1 << j)): continue
                    if C[i][j] == '#':
                        #print(i, j)
                        cnt += 1
            #print("row={}, col={}, cnt={}".format(row, col, cnt))
            if cnt == K:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 68192
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	final boolean DEBUG = true;
	long d = 1000000007l;
	void run() {
		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		char[] txt = scan.next().toCharArray();
		char[] pat = scan.next().toCharArray();
		int tl = txt.length;
		int pl = pat.length;
		if (tl < pl)
			return;
		
		long h = 1, p = 0, t = 0;
		for (int i = 0; i < pl; i++) {
			h = h * d;
			p = d * p + pat[i];
			t = d * t + txt[i];
		}
		
		for (int i = 0; i <= tl - pl; i++) {
			if (p == t)
				sb.append(i + "\n");
			if (i + pl < tl)
				t = t * d + txt[i + pl] - txt[i] * h;
		}
		System.out.print(sb.toString());
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 91288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
    ll n, q;
    cin >> n >> q;
    ll t[n] = {};
    vector<pair<ll, vector<ll>>> p;
    set<ll> st;

    rep(i, n)
    {
        ll s, t, x;
        cin >> s >> t >> x;
        p.push_back({s - x, {1, x}});
        p.push_back({t - x, {0, x}});
    }
    ll d[q];
    rep(i, q)
    {
        cin >> d[i];
    }
    sort(p.begin(), p.end());
    ll fin = 0;
    ll co = 0;
    while (fin < q)
    {
        if (co==2*n||p[co].first > d[fin])
        {
            if (st.empty())
                cout << -1 << endl;
            else
            {
                auto itr = st.begin();
                cout << *itr << endl;
            }
            fin++;

            continue;
        }
        if (p[co].second[0] == 1)
        {
            st.insert(p[co].second[1]);
            co++;
        }
        else
        {
            st.erase(p[co].second[1]);
            co++;
        }
    }

    return 0;
}

Measured memory_bytes: 40036
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int H = Integer.parseInt(sc.next());
		int W = Integer.parseInt(sc.next());
		String[] S = new String[H];
		for(int i = 0; i < H; i++) {
			S[i] = sc.next();
		}
		
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				if(S[i].substring(j, j + 1).equals("#")) {
					System.out.print("#");
					continue;
				}
				int cnt = 0;
				for(int a = -1; a <= 1; a++) {
					for(int b = -1; b <= 1; b++) {
						if(a == 0 && b == 0) continue;
						if(i == 0 && a == -1) continue;
						if(i == H - 1&& a == 1) continue;
						if(j == 0 && b == -1) continue;
						if(j == W - 1 && b == 1) continue;
						if(S[i + a].substring(j + b, j + b + 1).equals("#")) {
							cnt++;
						}
					}
				}
				System.out.print(cnt);
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N,M;

int S,T;

struct edge{
  int to;
  i64 cost;
};

vector<vector<edge>> G;


i64 MOD = 1e9 + 7;

vector<i64> dij(int s){
  vector<i64> dist(N,1e17);
  dist[s] = 0;
  using P = pair<i64,i64>;
  priority_queue<P,vector<P>,greater<P>> que;

  que.push({dist[s],s});

  while(!que.empty()){
    int v = que.top().second;
    i64 d = que.top().first;
    que.pop();

    for(auto e : G[v]){
      if(dist[e.to] > dist[v] + e.cost){
        dist[e.to] = dist[v] + e.cost;
        que.push({dist[e.to],e.to});
      }
    }
  }

  return dist;

  return dist;
}

int main(){
  cin >> N >> M;
  cin >> S >> T;
  S--;
  T--;

  G.resize(N);

  vector<int> u(M),v(M);
  vector<i64> d(M);

  rep(i,0,M - 1){
    cin >> u[i] >> v[i] >> d[i];
    u[i]--;
    v[i]--;
    G[u[i]].push_back({v[i],d[i]});
    G[v[i]].push_back({u[i],d[i]});
  }
  auto D = dij(S);
  auto rD = dij(T);

  vector<i64> co(N,0),rco(N,0);
  co[S] = 1;
  rco[T] = 1;
  {

    vector<pair<i64,int>> vec;
    rep(i,0,N - 1){
      vec.push_back({D[i],i});
    }
    sort(vec.begin(),vec.end());
    for(auto p : vec){
      int v = p.second;
      for(auto e : G[v]){
        if(D[e.to] == D[v] + e.cost){
          (co[e.to] += co[v]) %= MOD;
        }
      }
    }
    reverse(vec.begin(),vec.end());
    for(auto p : vec){
      int v = p.second;
      for(auto e : G[v]){
        if(D[e.to] == D[v] - e.cost){
          (rco[e.to] += rco[v]) %= MOD;
        }
      }
    }
  }

  i64 sum = co[T] * rco[S] % MOD;

  i64 sub = 0;

  rep(i,0,N - 1){
    if(D[i] * 2 == D[T]){
      (sub += co[i] * rco[i] % MOD * co[i] % MOD * rco[i] % MOD) %= MOD;
    }
  }

  rep(i,0,M - 1){
    if(D[u[i]] > D[v[i]]) swap(u[i],v[i]);
    if(D[u[i]] * 2 < D[T] && D[v[i]] * 2 > D[T] && D[u[i]] + d[i] == D[v[i]]){
      (sub += co[u[i]] * rco[v[i]] % MOD * co[u[i]] % MOD * rco[v[i]] % MOD) %= MOD;
    }
  }

  cout << (sum + MOD - sub) % MOD << endl;
}


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

int main()
{
  int n, m, a;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a;
    n -= a;
  }
  cout << max(n, -1) << endl;

  return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int x, y;
    cin >> x >> y;
    int ans = 0;
    if (x == 1)
    {
        ans += 300000;
    }
    else if (x == 2)
    {
        ans += 200000;
    }
    else if (x == 3)
    {
        ans += 100000;
    }
    if (y == 1)
    {
        ans += 300000;
    }
    else if (y == 2)
    {
        ans += 200000;
    }
    else if (y == 3)
    {
        ans += 100000;
    }
    if (ans == 600000)
    {
        ans += 400000;
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 3636
N = int(input())
S = list(input())

C = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'
    ,'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

for i in range(len(S)):
    for j in range(len(C)):
        if S[i] == C[j]:
            S[i] = C[(j + N) % 26]
            break

print(''.join(S))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll mod = 1e9+7;
typedef pair<int,int> P;
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,m,N) for(int i=m;i<N;i++)
#define mm(n,m) memset(n,m,sizeof(n))

int main(){
    int n;
    double a;
    cin>>n;
    int c=0;
    for(int i=1;i<=n;i++){
        if(i%2==0){
            c++;
        }
    }
    a = 1 - ((double)c/(double)n);
    //cout<<c<<endl;
    cout<<a<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    string s;
    cin >> s;
    for (auto ch : s)
    {
        cout << 'x';
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* Written by Nishant Mittal aka nishantwrp */
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define modnum 1000000007
#define mp make_pair
#define pb push_back
#define PB pop_back
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define lcase(a) (char)tolower(a)
#define ucase(a) (char)toupper(a)
#define precise(a) fixed<<setprecision(a)<<
#define F first
#define S second
#define I insert
#define pii pair<int,int>
#define trav(a, x) for(auto& a : x)
#define rep(n) for(int i = 0;i<n;i++)
#define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define display(x) trav(a,x) cout<<a<<" "; cout<<endl;
#define ingrid(data,n,commands) for(int i = 0; i<n; i++){cin>>data[i];commands}
#define section(a,b,w) set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w) set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define copy(a,w) copy(a.begin(), a.end(),back_inserter(w));
#define all(data) data.begin(), data.end()
#define PI 3.14159265358979323844
#define endl '\n'

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

// Graph DFS
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};

//Returns index of first element not less than key and more than key respectively
#define lb(data,key) lower_bound(all(data),key) - data.begin();
#define up(data,key) upper_bound(all(data),key) - data.begin();
#define fnd(data,key) find(all(data),key) - data.begin();

/*

███╗   ██╗██╗███████╗██╗  ██╗ █████╗ ███╗   ██╗████████╗██╗    ██╗██████╗ ██████╗ 
████╗  ██║██║██╔════╝██║  ██║██╔══██╗████╗  ██║╚══██╔══╝██║    ██║██╔══██╗██╔══██╗
██╔██╗ ██║██║███████╗███████║███████║██╔██╗ ██║   ██║   ██║ █╗ ██║██████╔╝██████╔╝
██║╚██╗██║██║╚════██║██╔══██║██╔══██║██║╚██╗██║   ██║   ██║███╗██║██╔══██╗██╔═══╝ 
██║ ╚████║██║███████║██║  ██║██║  ██║██║ ╚████║   ██║   ╚███╔███╔╝██║  ██║██║     
╚═╝  ╚═══╝╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝   ╚═╝    ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝     
                                                                                                       
*/
int ans = 0;


signed main()
{
FAST
int n,d;
cin>>n>>d;
double f = (double)n/(2*d + 1);
if (f - (int)f == 0)
{
  cout<<(int)f;
} else {
  cout<<(int)f + 1;
}
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int main(){
	ll n;
	cin>>n;
	ll m;
	ll a[4];
	a[0]=a[1]=a[2]=a[3]=-1;
	cin>>m;
	ll f=1;
	while(m--){
		ll x,y;
		cin>>x>>y;
		if(f){
			if(a[x]!=-1&&a[x]!=y)
				f=0;
			else
				a[x]=y;
		}
	}
	ll i;
	if(f==0||(a[1]==0&&n>1))
		cout<<"-1";
	else{
		if(a[1]==-1&&n>1)
			a[1]=1;
		else if(a[1]==-1&&n==1)
			a[1]=0;
		for(i=2;i<=n;i++)
			if(a[i]==-1)
				a[i]=0;
		for(i=1;i<=n;i++)
			cout<<a[i];
	}
}


Measured memory_bytes: 256
def solve(n,mat):
    dp=[[0]*n for _ in range(n)]
    for kukan in range(1,n):
        for i in range(n-kukan):
            dp[i][i+kukan]=min([dp[i][mid]+dp[mid+1][i+kukan]+mat[i][0]*mat[mid+1][0]*mat[i+kukan][1] for mid in range(i,i+kukan)])
    return dp[0][n-1]

n=int(input())
mat=[tuple(map(int,input().split())) for _ in range(n)]
print(solve(n,mat))


Measured memory_bytes: 5724
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String s = sc.next();

		int red=0,blue=0;
		for(int i=0;i<n;i++) {
			if(s.charAt(i)=='R') {
				red++;
			}else {
				blue++;
			}
		}
		if(red-blue>0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


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

using namespace std;

int const N = 2e5 + 100;
int n, a[N];

int main(){
    scanf("%d", &n);
    for(int i = 0;i < n;++i) scanf("%d", &a[i]);
    
    int mn = 1e9;
    long long ans = 0;
    for(int i = n - 1;i >= 0;--i){
        if(i - a[i] < 0){puts("-1"); return 0;}
        
        if(i != n - 1 && a[i] == 0){
            if(a[i + 1] == 1 || a[i + 1] == 0) continue;
            else {puts("-1"); return 0;}
        }
        
        if(i != n - 1 && a[i + 1] == a[i] + 1) continue;
        mn = min(mn, i - a[i]);
        if(i - a[i] == mn) ans += a[i];
        else {puts("-1"); return 0;}
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024