akhauriyash/Code-Regression huggingface dataset:
#import <stdio.h>

#define MIN(a,b) (((a)<(b)) ? (a) : (b))

int main(){
    long long n,a,b,c,d,e;
    scanf("%lld %lld %lld %lld %lld %lld",&n,&a,&b,&c,&d,&e);
    long long min = MIN(a,b);
    min = MIN(min,c);
    min = MIN(min,d);
    min = MIN(min,e);
    long long u = n/min;
    if(n%min>0) u++;
    printf("%lld", u+4);
}


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

int main(){
	int n, m; cin >> n >> m;
	cout << (n-1) * (m-1) ;
}


Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    i64 n,k;
    cin>>n>>k;
    n -= ((n/k)*k);
    //cout<<n<<endl;
    //if(abs(n-k)>n){
    //    cout<<n<<endl;
    //    return 0;
    //}
    while(abs(n-k)<=n) {
        n = abs(n-k);
        //cout<<n<<endl;
        //if((n==1||n==0) && n<k) break;
    }
    cout<<n<<endl;
    return 0;
}



Measured memory_bytes: 3568
#include <iostream>
#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 <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */
template <typename T>
struct PrimeFact {
    vector<T> spf;
    PrimeFact(T N) { init(N); }
    void init(T N) { // 前処理。spf を求める
        spf.assign(N + 1, 0);
        for (T i = 0; i <= N; i++) spf[i] = i;
        for (T i = 2; i * i <= N; i++) {
            if (spf[i] == i) {
                for (T j = i * i; j <= N; j += i) {
                    if (spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    map<T, T> get(T n) { // nの素因数分解を求める
        map<T, T> m;
        while (n != 1) {
            m[spf[n]]++;
            n /= spf[n];
        }
        return m;
    }
};

int main() {
  
  lint n; cin >> n;
  PrimeFact<lint> pf(n);

  lint ans = 0;
  for (lint k = 1; k <= n; k++) {
    auto res = pf.get(k);
    lint cnt = 1;
    for (auto x : res) {
      cnt *= (x.second + 1);
    }
    ans += k * cnt;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 81376
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    int n;
    cin>>n;
    stack<string> t;
    rep(i,n){
        string s;
        cin>>s;
        if(s=="A"){
            t.push(s);
        }else{
            if(t.empty()){
                cout<<"NO"<<endl;
                return 0;
            }
            t.pop();
        }
    }

    if(t.empty()){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3160
n, m = gets.split.map(&:to_i)

neighbours = Array.new(n + 1).map {Array.new}
visited = Array.new(n + 1, false)

flags = Array.new(n + 1, nil)

m.times do
  a, b =  gets.split.map(&:to_i)
  neighbours[a] << b
  neighbours[b] << a
end

queue = []
queue << 1
visited[1] = true
while ! queue.empty?
  current = queue.shift
  
  neighbours[current].each do |next_pos|
    next if visited[next_pos]

    visited[next_pos] = true
    flags[next_pos] = current if flags[next_pos].nil?
    queue << next_pos
  end
end

puts 'Yes'
puts flags[2..-1].join("\n")

Measured memory_bytes: 34108
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>


#define fs first
#define sc second

using namespace std;

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

const ll mod = 1000000007;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}


template<typename V> struct ConvexHull {
    deque<pair<V,V>> Q;
    V calc(pair<V,V> p, V x) {
        return p.first*x+p.second;
    }
    int dodo(pair<V,V> A,pair<V,V> B, pair<V,V> C) { // max or min
        return ((A.second-C.second)*(B.first-A.first)<=(A.second-B.second)*(C.first-A.first));
    }
    void add(V a, V b) { // add ax+b
        Q.push_back({a,b});
        int v;
        while((v=Q.size())>=3 && dodo(Q[v-3],Q[v-2],Q[v-1]))
            Q[v-2]=Q[v-1], Q.pop_back();
    }
    V query(V x) {
        int L=-1,R=Q.size()-1;
        while(R-L>1) {
            int M=(L+R)/2;
            (((calc(Q[M],x)>=calc(Q[M+1],x)))?L:R)=M;
        }
        return calc(Q[R],x);
    }
};


ll C, h[210000];
ll dp[210000];
ConvexHull<ll> cvt;


int main(){
    int N;

    cin >> N >> C;

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

    vector<P> line;
    dp[0] = 0;
    for(int i = 1; i < N; i++){
        cvt.add(-2 * h[i-1], dp[i-1] + h[i-1] * h[i-1]);
        dp[i] = cvt.query(h[i]) + C + h[i] * h[i];
    }

    cout << dp[N-1] << endl;



    return 0;
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX=200005;
const ll MOD=1000000007;
ll fac[MAX],finv[MAX],inv[MAX];
ll ans;
void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<MAX;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll COM(ll i,ll j){
	if(i<j) return 0;
	if(i<0||j<0) return 0;
	return fac[i]*(finv[j]*finv[i-j]%MOD)%MOD;
}
int main(void){
	COMinit();
    ll n,m,k; cin>>n>>m>>k;
    //cout<<"AA"<<endl;
    for(int i=1;i<=n-1;i++){
		if(n*m-2>=MOD){
		}else{
			ans=(ans+i*m*m*(n-i)*COM(n*m-2,k-2))%MOD;
		}
		//cout<<ans<<endl;
	}
	for(int i=1;i<=m-1;i++){
		if(n*m-2>=MOD){
		}else{
			ans=(ans+i*n*n*(m-i)*COM(n*m-2,k-2))%MOD;
		}
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4992
from heapq import heappush,heapify,heappop
import sys
input = sys.stdin.readline
INF = 10**18

n = int(input())

es=[[] for _ in range(n)] # es[i] = (頂点iの(隣接する頂点,コスト)の組)
d = [INF]*n # 頂点sからの最短距離

# 入力
for i in range(n-1):
    a,b,c = map(int,input().split())
    a,b = a-1, b-1
    es[a].append((b,c))
    es[b].append((a,c))


def dijkstra(s):
    v = -1
    que = [(0,s)]
    heapify(que)
    d[s] = 0
    while que:
        p = heappop(que)
        v = p[1]
        if d[v] < p[0]:
            continue
        for e in es[v]:
            if d[e[0]] > d[v] + e[1]:
                d[e[0]] = d[v] + e[1]
                heappush(que, (d[e[0]], e[0])) 
q,k=map(int,input().split())
dijkstra(k-1)
for i in range(q):
    x,y=map(int,input().split())
    print(d[x-1]+d[y-1])

Measured memory_bytes: 46284
package main

import (
	"bufio"
	// "fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func nextInt() int {
	i, e := strconv.Atoi(nextString())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInt64() int64 {
	i, e := strconv.ParseInt(nextString(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func putInt64(i int64) {
	wr.WriteString(strconv.FormatInt(i, 10))
	wr.Flush()
}
func putString(s string) {
	wr.WriteString(s)
	wr.Flush()
}

func main() {
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

	var n int
	n = nextInt()

	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	var ans int64

	for i := 0; i < n; i++ {
		ans += int64(a[i])
		if i%2 == 1 {
			ans -= 2 * int64(a[i])
		}
	}

	for i := 0; i < n; i++ {
		putInt64(ans)
		ans = 2*int64(a[i]) - ans
		if i == n-1 {
			putString("\n")
		} else {
			putString(" ")
		}
	}
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define ll long long
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 +7;
const ll M=500006;
ll f[M],inv[M];
ll expo(ll base,ll exponent){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

vector<bool>  prime(1000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=1000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=1000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

bool check(string s,char c)
{
	for(auto x:s)
	{
		if(x==c) return true;
	}
	return false;
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
 //    #endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    ll tests=1;
   // cin>>tests;
    while(tests--)
    {
    	ll n,i,j,k;
    	cin>>n>>k;
    	vector<ll>a(n+1,0);
    	while(k--)
    	{
    		cin>>j;
    		while(j--)
    		{
    			ll z;
    			cin>>z;
    			a[z]++;
    		}
    	}
    	ll ans=0;
    	for(i=1;i<=n;i++)
    	{
    		if(a[i]==0) ans++;
    	}
    	cout<<ans;
    }

	return 0;
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 10000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
  string S;
  int x,y;
  cin >> S >> x >> y;
  int N = S.size();
  vector<ll> A(1,0);
  for(int i = 0;i < N;i++){
    if(S[i] == 'T')A.push_back(0);
    else A.back()++;
  }
  ll X = 0,Y = 0,a = 0;
  vector<ll> B,C;
  for(int i = 0;i < A.size();i++){
    if(i % 2 == 0){
      B.push_back(A[i]);
      X += A[i];
    }else{
      C.push_back(A[i]);
      Y += A[i];
    }
  }
  /*sort(B.begin(),B.end()); 
  sort(C.begin(),C.end());*/
  vector<bool> H(16010,0),V(16010,0);
  H[X+8000] = 1;V[Y+8000] = 1;
  for(int i = 1;i < B.size();i++){
    for(int j = 0;j <= 16000;j++){
      if(H[j]){
        //H[j-B[i]] = 1;
        H[j-2*B[i]] = 1;
      }
    }
  }
  for(int i = 0;i < C.size();i++){
    for(int j = 0;j <= 16000;j++){
      if(V[j]){
        //V[j-C[i]] = 1;
        V[j-2*C[i]] = 1;
      }
    }
  }
  if(H[8000+x] && V[8000+y]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 384
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

#define INF 1000000000

using namespace std;

int main() {
    int array[3][3];

    REP(i, 3)
    REP(j, 3)
    cin >> array[i][j];

    vector<int> p = {0, 1, 2};

    int sum = 0;
    REP(i, 3)
    sum += array[i][i];

    do {
        int ssum = 0;
        REP(i, 3) { ssum += array[i][p[i]]; }

        if (ssum != sum) {
            cout << "No" << endl;
            return 0;
        }
    } while (next_permutation(ALL(p)));

    cout << "Yes" << endl;

    return 0;
}


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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

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

  vector<ll> A(10, 0);
  vector<ll> stick = {2, 5, 5, 4, 5, 6, 3, 7, 6};
  for (int i = 0; i < M; i++) {
    int temp;
    cin >> temp;
    A[temp] = 1;
  }

  vector<string> dp(10001, "");

  for (int i = 1; i < 10; i++) {
    if (A[i] == 0) continue;

    ll s = stick[i - 1];
    for (int j = 0; j < N; j++) {
      if (j + s > N) break;

      if (dp[j] == "" && j > 0) continue;

      string oldString = dp[j + s];
      string newString = to_string(i) + dp[j];

      if ((newString.length() > oldString.length()) ||
          (newString.length() == oldString.length()) && (newString > oldString)) {

        dp[j + s] = newString;
      }
    }
  }

  cout << dp[N] << "\n";
  return 0;
}

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

int digit(int N, int K){
  int sum = 0;
  int count = 0;
  while(N>0){
    sum += N%K;
    N /= K;
    count ++;
  }
  return count;
}

int main(){
  int n,k;
  cin >> n >> k;
  int count = 0;
  count = digit(n,k);
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll var;cin>>var;vec.push_back(var);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define mod2 998244353
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod=1e9+7;
#define piii 3.14159265358979323846264338327950
#define print(a, n, m)     for (ll i = n; i < m; i++) {  cout << a[i] << " "; }  cout << endl
#define con continue

bool prime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
bool isPerfectSquare(ll x) {   
  long double sr = sqrt(x); 
  return ((sr - floor(sr)) == 0); 
} 
bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}
bool cmp(const pair<int,int> &a,  const pair<int,int> &b) 
{ 
    if(a.ff == b.ff)
        return a.ss < b.ss;
    return (a.ff > b.ff); 
}
//////////////////////////////////////////////////// Lets Do It ////////////////////////////////////////////////////////
int gcd(int p, int q){
if(p % q == 0)return q;
return gcd(q, p % q);
}

void solve()
{

    string s,t;
    cin>>s>>t;

    ll ans = t.length();
    loop(i,0,s.length()-t.length()+1)
    {   
        ll cnt = 0;
        loop(j,0,t.length())
        {
            if(t[j]!=s[i+j])
                cnt++;
        }
        ans = min(ans,cnt);
    }   

    cout<<ans;
    return;
}
 
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
    IOS;
    ll t;
    //cin>>t;
    t=1;

    while(t--){
        solve();
        cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
} 



Measured memory_bytes: 3680
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, A: "List[int]"):
    return max(A) - min(A)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    result = solve(N, A)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5124
N, m = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for __ in range(N)]
pay = 0

for v, n in sorted(AB):
    if m < n:
        pay += v * m
        break
    else:
        pay += v * n
        m -= n

print(pay)


Measured memory_bytes: 22376
<?php

$is_honban = 1;

if ($is_honban) {
  //----------------------------------------------------------------------------------
  // Input for honban
  //----------------------------------------------------------------------------------
  $sc = new Scanner();
  $a = $sc->nextInt();
  $b = $sc->nextInt();



} else {
  //----------------------------------------------------------------------------------
  // Input for test
  //----------------------------------------------------------------------------------
  error_reporting(E_ERROR | E_WARNING | E_PARSE);

  $s = '';



}
//----------------------------------------------------------------------------------
// Main
//----------------------------------------------------------------------------------

$ans = 0;

$ans = ($a * $b % 2 == 0) ? 'Even' : 'Odd';



//----------------------------------------------------------------------------------
// Output
//----------------------------------------------------------------------------------
out::println($ans);



//----------------------------------------------------------------------------------
// Ref: https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
//----------------------------------------------------------------------------------
class Scanner {
  private $arr = array();
  private $count = 0;
  private $pointer = 0;
  public function next() {
    if($this->pointer >= $this->count) {
      $str = trim(fgets(STDIN));
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->pointer = 0;
    }
    $result = $this->arr[$this->pointer];
    $this->pointer++;
    return $result;
  }
  public function hasNext() {
    return $this->pointer < $this->count;
  }
  public function nextInt() {
    return (int)$this->next();
  }
  public function nextDouble() {
    return (double)$this->next();
  }
}

class out {
  public static function println($str = "") {
    echo $str . PHP_EOL;
  }
}

?>


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


int main(){
  ll x;
  cin>>x;
  for(ll i=-5e3;i<=5e3;i++){
    ll b5=pow(i,5);
    ll a=pow(x+b5,0.2);
    if((ll)pow(a,5)==x+b5){
      cout<<a<<' '<<i;
      return 0;
    }
  }
  

  
 }


Measured memory_bytes: 4248
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int n, i, j, k, a, b, x, c, id;
	vector<int> ct(2, 0);
	cin >> n;
	vector<vector<int>> adj(n + 1);
	for (i = 0; i < n - 1; i++) {
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	vector<int> parent(n + 1, -1), depth(n + 1);
	parent[1] = 0;
	depth[1] = 0;
	ct[0] = 1;
	queue<int> q;
	q.push(1);

	while (!q.empty()) {
		id = q.front();
		q.pop();

		for (auto p : adj[id]) {
			if (parent[p] == -1) {
				parent[p] = id;
				q.push(p);
				depth[p] = 1 - depth[id];
				ct[depth[p]]++;
			}
		}
	}

	vector<int> ans(n + 1, -1);
	vector<bool> used(n + 1, false);
	x = n / 3;

	if ((ct[0] <= x) || (ct[1] <= x)){
		if (ct[0] <= x) id = 0;
		else id = 1;
		c = 0;
		for (i = 1; i <= n; i++) {
			if (depth[i] == id) {
				c += 3;
				ans[i] = c;
				used[c] = true;
			}
		}
		c = 1;
		for (i = 1; i <= n; i++) {
			if (ans[i] == -1) {
				while (used[c]) c++;
				ans[i] = c;
				used[c] = true;
				c++;
			}
		}
	}
	else {
		c = 1;
		for (i = 1; i <= n; i++) {
			if ((depth[i] == 0) && (c <= n)) {
				ans[i] = c;
				used[c] = true;
				c += 3;
			}
		}
		c = 2;
		for (i = 1; i <= n; i++) {
			if ((depth[i] == 1) && (c <= n)) {
				ans[i] = c;
				used[c] = true;
				c += 3;
			}
		}

		c = 1;
		for (i = 1; i <= n; i++) {
			if (ans[i] == -1) {
				while (used[c]) c++;
				ans[i] = c;
				used[c] = true;
				c++;
			}
		}

	}

	for (i = 1; i <= n; i++) cout << ans[i] << " ";
	cout << "\n";

	return 0;
}


Measured memory_bytes: 15984
#include <stdio.h>
#include <stdlib.h>

typedef struct{
  int A;
  int B;
}Job;

Job J[200000];

int Cmp(const void *a, const void *b){
  return ((Job *)a)->B - ((Job *)b)->B;
}

void Do(int N){
  int i, t;
  for(i = 0;i < N;i++) scanf("%d %d", &J[i].A, &J[i].B);
  qsort(J, N, sizeof(Job), Cmp);
  t = 0;
  for(i = 0;i < N;i++){
    t += J[i].A;
    if(t > J[i].B) break;
  }
  if(i < N) printf("No\n");
  else printf("Yes\n");
}

int main(void){
  int N;
  scanf("%d", &N);
  Do(N);
  return 0;
}


Measured memory_bytes: 3324
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int[] n=new int[3];
        n[0]=sc.nextInt();
        n[1]=sc.nextInt();
        n[2]=sc.nextInt();
        
        int a;
        if(n[0]>n[1]){
            a=n[0];
            n[0]=n[1];
            n[1]=a;
        }if(n[1]>n[2]){
            a=n[1];
            n[1]=n[2];
            n[2]=a;
        }if(n[0]>n[1]){
            a=n[0];
            n[0]=n[1];
            n[1]=a;
        }
        
        System.out.println(n[0]+" "+n[1]+" "+n[2]);
    }
}


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

int main(){
  while (true) {
    int m, f, r;
    cin >> m >> f >> r;

    if (m == -1 && f == -1 && r == -1) break;

    string g;
    if (m == -1 || f == -1) g = "F";
    else if (m + f >= 80) g = "A";
    else if (m + f >= 65) g = "B";
    else if (m + f >= 50) g = "C";
    else if (m + f >= 30 && r >= 50) g = "C";
    else if (m + f >= 30) g = "D";
    else g = "F";

    cout << g << endl;
  }
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int x; cin>>x;
	int ans=1;
	for(int i=2;i*i<=x;++i){
		int a=i*i;
		while(a<=x){
			ans=max(ans,a);
			a*=i;
		}
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //String str = sc.next();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int K= sc.nextInt();
        
        if((B-A) <= K){
            //System.out.println(A);
            for(int i=0; i<=B-A; i++){
                System.out.println(A+i);
            }
        }else if((B-A+1)/2 >= K){
            for(int i=0; i<K; i++){
                System.out.println(A+i);
            }
            for(int i=K; i>0; i--){
                System.out.println(B-i+1);
            }
        }else if((B-A+1)/2 < K){
            for(int i=0; i<=B-A; i++){
                System.out.println(A+i);
            }
        }
        
        //System.out.println();
    }
}


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

int main(){
  int N;
  cin>>N;
  string s;
  set<string> se;

    ll ans =0;
  rep(i,N){
    cin>>s;
    if(se.find(s) == se.end()){
      ans++;
      se.insert(s);
    }
    s="";
  }
cout<<ans;


}


Measured memory_bytes: 19144
s = int(input())

lis = [s]

i = 1
while True:
    
    if lis[i-1] % 2 == 0:
        lis.append(lis[i-1]/2)
    else:
        lis.append(3*lis[i-1]+1)
        
    if lis[i] in lis[:i-1]:
        print(i+1)
        break
    
    i += 1

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for (int i = 0; i < n; i++)
#define Rep(i,n) for (int i = n; i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define cend cout<<endl;
#define P pair<int, int>
#define prique priority_queue<P, vector<P>, greater<P>>
using namespace std;

string s,a="AKIHABARA";
vector<string>vec;
int b[4]={0,4,6,8};
signed main() {
	cin>>s;
	rep(i,16) {
		string c;
		rep(j,(int)a.size()) {
			bool can=false;
			rep(k,4) {
				if(((i>>k)&1)&&j==b[k]) can=true;
			}
			if(can) continue;
			c.push_back(a[j]);
		}
		vec.push_back(c);
	}
	rep(i,16) {
		if(s==vec[i]) {
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
}

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


int main() {
	string s;
	cin >> s;
	if (s == "ABC")
		cout << "ARC" << endl;
	else
		cout << "ABC" << endl;
	return 0;
}


Measured memory_bytes: 3604
/*  
    tanuj_johal :: gla_clg_sync_with_CSE(true);
    bonding.tie(true);
    hardwork.tie(true);
    
    ::::::::--------------------::::::::
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll          long long
#define fio         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define vi          vector<ll>
#define pp          push_pop
#define pll         pair<ll,ll>
#define in          insert
#define ff          first
#define ss          second
#define inf         10000000000000000
#define all(p)      p.begin(), p.end()
#define que_max     priority_queue <int>
#define que_min     priority_queue <int, vi, greater<int>>
#define print(a)    for(auto i:a){cout<<i<<" ";}
#define print1(a)   for(auto i:a){cout<<i.ff<<" "<<i.ss<<endl;}

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> Set;


const ll mod = 1e9+7;

ll power(ll x,ll y,ll p){ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;}

void solve()
{
    unordered_map<ll,ll> mp;          set<ll> st; 
    ll n,m,k=0;
    string s;
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll a;cin>>a;
        k+=a;
    }
    
    n-=k;
    if(n<0) cout<<-1<<endl;
    else    cout<<n<<endl;




}

int main()
{
    fio
    // int t;cin>>t;while(t--)
    {
        solve();
    }
    
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n;
    cin >> n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    ll ans1=a[n-1];
    ll ans2=a[0];
    ll judge=ans1/2;
    for(ll i=0;i<n-1;i++){
        ll x=a[i];
        if(abs(ans2-judge)>=abs(x-judge)){
            ans2=x;
        }
    }
    cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[100010], mp[100010];
int main(){
    int n;
    while(cin>>n){
        ll ans=0, sm=0;
        for(int i=0; i<n; ++i){
            scanf("%d",a+i);
            sm+=a[i];
            ++mp[a[i]];
        }
        int q;
        ll x, y;
        cin>>q;
        for(int i=0; i<q; ++i){
        	scanf("%lld%lld",&x,&y);
        	if(x==y){
        		printf("%lld\n",sm);
        		continue;
        	}
        	sm-=mp[x]*x;
        	sm+=mp[x]*y;
        	mp[y]+=mp[x];
        	mp[x]=0;
        	printf("%lld\n",sm);
        }
    }
  return 0;
}




Measured memory_bytes: 5356
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

int n;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	if(n % 1000 == 0) cout << "0\n";
	else cout << (1000 - n % 1000) << "\n";
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>

#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;
typedef long long int lli;

int main(void)
{
	string S; cin >> S;
	bool flag1 = false, flag2 = false, flag3 = true;

	if (S[0] == 'A')flag1 = true;

	int count = 0;
	rep(i, 2, S.size() - 1) {
		if (S[i] == 'C')count++;
	}
	if (count == 1)flag2 = true;

	count = 0;
	if (flag1&&flag2) {
		rep(i, 0, S.size()) {
			if (S[i] <= 'Z')count++;
		}
		if (count > 2)flag3 = false;
	}
	else flag3 = false;

	if (flag3)cout << "AC" << endl;
	else cout << "WA" << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
from copy import copy
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


INF = 10**18


def main():

    N, W = in_nn()
    w, v = [], []
    for i in range(N):
        a, b = in_nn()
        w.append(a)
        v.append(b)

    V = 10**5 + 1
    dp = [INF] * (V + 1)
    dp[0] = 0

    for i in range(N):
        next_dp = copy(dp)
        for j in range(V):
            if j + v[i] <= V:
                next_dp[j + v[i]] = min(next_dp[j + v[i]], dp[j] + w[i])
            else:
                break
        dp = next_dp

    ans = 0
    for i in range(V):
        if dp[i] <= W:
            ans = i

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 147476
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,result;
    cin>>x>>y;
    if(x>9 || y>9) cout<<"-1"<<endl;
    else
    {
        result=x*y;
        cout<<result<<endl;
    }
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int n;
vector<vi> G;
vi X;

int dfs(int v, int prev){
    set<int> s = {0};
    int sum = 0;
    for(auto& nv : G[v]){
        if(nv == prev) continue;
        int a = X[nv];
        int b = dfs(nv, v);
        sum += a + b;

        set<int> ns;
        for(auto& e : s){
            if(e + a <= X[v]) ns.insert(e + a);
            if(e + b <= X[v]) ns.insert(e + b);
        }
        s = ns;
    }

    int th = 0;
    for(auto& e : s) chmax(th, e);

    if(s.size() == (int)0){
        throw -1;
    }
    
    return sum - th;
}

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

    cin >> n;
    G = vector<vi>(n);
    X = vi(n);

    rep(a, 1, n){
        int b; cin >> b; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    for(auto& e : X) cin >> e;

    bool ok = true;
    try {
        dfs(0, -1);
    }
    catch(int e){
        ok = false;
    }

    cout << (ok ? "POSSIBLE":"IMPOSSIBLE") << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
const double PI=3.14159265358979323846;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "

int main(void){
    int ans=0;
    string s,t;cin>>s>>t;
    rep(i,3)if(s[i]==t[i])ans++;
    co(ans);
}






Measured memory_bytes: 256
#include<stdio.h>
int main(){
	long long int t;
	scanf("%lld",&t);
	long long int number[t]={0};
	long long int hasil=1;
	
	for(long long int i=0;i<t;i++){
		scanf("%lld",&number[i]);
	}
	for(long long int i=0;i<t;i++){
		if(number[i]==0){
			printf("0\n");
			return 0;
		}
	}
	for(int i=0;i<t;i++){
		if(number[i]<=1000000000000000000/hasil){
			hasil=hasil*number[i];
		}
		else{
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld",hasil);
	return 0;
}

Measured memory_bytes: 2500
#include <stdio.h>
#define N 100
#define swap(a,b) a^=b^=a^=b

int main(){

  int i, j, minj, flag = 0, length, a[N];
  
  scanf("%d", &length);
  for(i = 0; i < length; i++) scanf("%d",&a[i]);

  for(i = 0; i <= length - 1; i++){
    minj = i;
    for(j = i; j <= length - 1; j++){
	if(a[j] < a[minj]) minj = j;
      }
      if(a[i] != a[minj]){
	swap(a[i],a[minj]);
	flag++;
      }
    }

    for(i = 0; i < length; i++){
      printf("%d", a[i]);
      if(i != length - 1) printf(" ");
    }
    printf("\n%d\n", flag);

    return 0;

  }

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  ll N,W;
  cin >> N >> W;

  vector<vector<ll>> v(4, vector<ll>());
  vector<vector<ll>> vsum(4, vector<ll>());

  ll w1;
  REP(i,N){
    ll ww,vv;
    cin >> ww >> vv;

    if(i==0){
      w1=ww;
    }
    v[ww-w1].push_back(vv);
  }

  REP(i,4){
    sort(v[i].begin(),v[i].end(),::greater<ll>());
  }

  REP(i,4){
    vsum[i].push_back(0);
  }
  REP(i,4){
    REP(j,v[i].size()){
      vsum[i].push_back(vsum[i][j]+v[i][j]);
    }
  }


  ll ans = -1;
  REP(i1,vsum[0].size()){
    REP(i2,vsum[1].size()){
      REP(i3,vsum[2].size()){
        REP(i4,vsum[3].size()){
          if((ll)i1*1 + (ll)i2*2 + (ll)i3*3 + (ll)i4*4 + (w1-1)*(i1+i2+i3+i4) > W)continue;
          ans = max(ans, vsum[0][i1]+vsum[1][i2]+vsum[2][i3]+vsum[3][i4]);
        }
      }
    }
  }
  cout << ans << endl;
}



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

int main()
{
	int N, M, x, y, l, rx, ry;
	char d;
	while (cin >> N, N) {
		vector< vector<bool> > a(21, vector<bool>(21, false));
		rx = ry = 10;
		for (int i = 0; i < N; i++) {
			cin >> x >> y;
			a[x][y] = true;
		}
		cin >> M;
		for (int i = 0; i < M; i++) {
			cin >> d >> l;
			switch (d) {
			case 'N':
				for (int j = 0; j < l; j++) {
					ry++;
					if (a[rx][ry])
						a[rx][ry] = false;
				}
				break;
			case 'S':
				for (int j = 0; j < l; j++) {
					ry--;
					if (a[rx][ry])
						a[rx][ry] = false;
				}
				break;
			case 'E':
				for (int j = 0; j < l; j++) {
					rx++;
					if (a[rx][ry])
						a[rx][ry] = false;
				}
				break;
			case 'W':
				for (int j = 0; j < l; j++) {
					rx--;
					if (a[rx][ry])
						a[rx][ry] = false;
				}
				break;
			}
		}
		for (int i = 0; i < 21; i++) {
			for (int j = 0; j < 21; j++) {
				if (a[i][j]) {
					cout << "No" << endl;
					goto rabel;
				}
			}
		}
		cout << "Yes" << endl;
	rabel:
		;
	}
	return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
/*
ll GCD(ll A,ll B){
  return (B==0)?(A):(GCD(B,A%B));
}
ll LCM(ll A,ll B){
  return A/GCD(A,B)*B;
}
*/
int main(){
	int N,M;
	while(1){
		cin>>N>>M;
		if(N==0&&M==0){
			break;
		}
		int A[10000];
		int a[10000];
		fill(A,A+N,0);
		fill(a,a+N,0);
		FOR(i,0,M){
			int S,K,C;
			cin>>S>>K;
			FOR(j,0,K){
				cin>>C;
				C--;
				if(K==1){
					a[C]+=S;
					A[C]+=S;
				}else{
					A[C]+=S;
				}
			}
		}
		int ma=0,mem;
		FOR(i,0,N){
			if(ma<A[i]){
				ma=A[i];
				mem=i;
			}
		}
		int mi=INF;
		FOR(i,0,N){
			if(i!=mem){
				mi=min(mi,a[i]);
			}
		}
		cout<<ma-mi+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 3140
#include <iostream>
using namespace std;
int main(){
  int N, INF = 10000000;
  while(cin >> N, N){
    int T[N][N+1];
    for(int i = 0; i < N; ++i)
      for(int j = 0; j <= N; ++j)
	cin >> T[i][j];
    int M = (1<<N);
    int dp[M];
    fill(dp,dp+M,INF);
    dp[0] = 0;
    for(int i = 0; i < M; ++i){
      int t = dp[i];
      for(int j = 0; j < N; ++j){
	if(i & 1<<j){
	  t = min(t, dp[i-(1<<j)] + T[j][0]);	  
	  for(int k = 0; k < N; ++k){
	    if(k != j && (i & (1<<k)))
	      t = min(t, dp[i-(1<<j)] + T[j][k+1]);
	  }
	}
      }
      dp[i] = t;
    }
    cout << dp[M-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3236
#include<stdio.h>
int main(void)
{
    int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==5&&b==5&&c==7){
	    printf("YES\n");
	}
	else if(a==5&&b==7&&c==5){
	    printf("YES\n");
	}
	else if(a==7&&b==5&&c==5){
	    printf("YES\n");
	}
	else {
	    printf("NO\n");
	}
	return 0;
}

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

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

      int base[n];
      for(int i=0;i<n;i++)
       cin>>base[i];

      int case1[n-1];
      for(int i=0;i<n-1;i++)
       cin>>case1[i];

      int freq[n]={0};
        long int total=0;
       for(int i=0;i<n;i++)
       {
           total+=base[arr[i]-1];
            freq[arr[i]-1]=1;

              if(freq[arr[i]-2]==1 && arr[i]!=1 && arr[i-1]==arr[i]-1 && i>0)
                total+=case1[arr[i]-2];
       }
       cout<<total;
}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

int main()
{

    ll ans=1;
    ll n, k;
    cin >> n >> k;
    while(n--)
    {

        ans = min(ans+k, ans*2);
    }
    cout << ans;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! p {
    ($x:expr $(, $tail:expr)*) => {
        let mut s = String::new();
        s.push_str(format!("{:?}", $x).as_str());
        $(
            s.push_str(format!(", {:?}", $tail).as_str());
        )*
        println!("{}", s);
    };
}

#[allow(unused_macros)]
macro_rules! pl {
    ($($x:expr), *) => {
        $(println!("{:?}", $x);)*
    };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    println!("{}", solve(stdin!()));
}

fn solve(src: String) -> String {
    input! {
        source = src,
        a: i32,
        b: i32,
        c: i32,
        d: i32,
        e: i32,
    }
    let mut vec = vec![a,b,c,d,e];
    fn ceil10(x: i32) -> i32 {
        let mut x = x;
        while x % 10 != 0 {
            x += 1;
        }
        x
    }
    let last_i = {
        let mut index = 0;
        for i in 0..vec.len() {
            if vec[i] % 10 == 0 {
                continue;
            }
            if vec[i] % 10 < vec[index] % 10 {
                index = i;
            }
        }
        index
    };
    let last = vec[last_i];
    vec.remove(last_i);
    let partial_sum: i32 = vec.iter().map(|&x| ceil10(x)).sum();
    let ans: i32 = partial_sum + last;
    ans.to_string()
}

// Test Code

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    };
}

test! {
r"29
20
7
35
120
" => "215",
r"101
86
119
108
57
" => "481",
r"123
123
123
123
123
" => "643",
}


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

long long mod = 1e9 +7;
int main()
{
    int n, ara[1005];
    long long ans = 1;
    scanf("%d", &n);
    for(int i = 0; i <= n; i++)ara[i] = i;
    for(int i = 2; i <= n; i++)
    {
        if(ara[i] > 1)
        {
            int c = 1;
            for(int j = i+1; j <= n; j++)
            {
                while(ara[j]%ara[i] == 0)
                {
                    ara[j]/=ara[i];
                    c++;
                }
            }
            c = (c + 1)%mod;
            ans = (ans * c)%mod;
        }
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 256
//D
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    vector<ll> f(1000100,0);
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    ll res=0;
    rep(i,n){
        if(f[a[i]]==0&&i!=n-1&&a[i]!=a[i+1])res++;
        else if(f[a[i]]==0&&i!=n-1&&a[i]==a[i+1]){
            for(ll x=a[i];x<=1000000;x+=a[i]){
            f[x]++;
            }
            continue;
        }
        else if(i==n-1&&f[a[i]]==0)res++;
        else continue;
        //cout<<a[i]<<endl;
        for(ll x=a[i];x<=1000000;x+=a[i]){
            f[x]++;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 12768