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

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 1e9 + 7;
const double eps = DBL_EPSILON;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef LOCAL_DEBUG
	freopen("input.txt", "r", stdin);
#endif
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	vector<int> a(n);
	for (int& i : a) cin >> i;
	sort(all(a), greater<int>());
	for (int i = k; i < n; i++) ans += a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
typedef vector<int> V;
typedef vector<V> VV;
const int INF = 1e9;

int kaijo(int x)
{
    /*
    if (x == 1) return 1;
    else return (x * kaijo(x - 1)) % MOD;
    */
    int ans = 1;
    for (int i=1; i<=x; i++) {
        ans *= i;
        ans %= MOD;
    }
    return ans;
}

signed main()
{
    int N, M;

    cin >> N >> M;
    if (abs(N - M) >= 2) {
        cout << 0 << endl;
        return 0;
    }

    if (N == M) {
       int ans = 2 * kaijo(N) * kaijo(M);
       ans %= MOD;
       cout << ans << endl;
    } else {
        int ans = kaijo(N) * kaijo(M);
        ans %= MOD;
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, num[250007], res[250007];
queue<int>q;
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int main()
{
	n = read();
	for (int i = 1; i <= n; i++)
		num[read()] = i;
	for (int i = 1; i <= n * n; i++)
	{
		if (num[i])
		{
			res[i] = num[i];
			if (q.size() < num[i] - 1)
			{
				cout << "No" << endl;
				return 0;
			}
			for (int j = 1; j <= num[i] - 1; j++)
			{
				res[q.front()] = num[i];
				q.pop();
			}
		}
		else q.push(i);
	}
	while (!q.empty())q.pop();
	for (int i = n * n; i >= 1; i--)
	{
		if (!res[i])q.push(i);
		if (num[i])
		{
			if (q.size() < n - num[i])
			{
				cout << "No" << endl;
				return 0;
			}
			for (int j = 1; j <= n - num[i]; j++)
			{
				res[q.front()] = num[i];
				q.pop();
			}
		}
	}
	cout << "Yes" << endl;
	for (int i = 1; i <= n * n; i++)
		printf("%d ", res[i]);
	cout << endl;
	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define mo 1000000007
#define next nxt
using namespace std;
int fac[400010],nifac[400010],e[400010];
int first[400010],next[400010],des[400010],w[400010];
int size[400010],ans,f[400010],vn,en,ed;
bool vis[400010];
int tt,n;
int C(int n,int m){return (long long)fac[n]*nifac[m]%mo*nifac[n-m]%mo;}
int getmi(int a,int x)
{
	int ans=1;
	while (x)
	{
		if (x&1) ans=(long long)ans*a%mo;
		a=(long long)a*a%mo;
		x>>=1;
	}
	return ans;
}
void dfs(int s,int pre)
{
	vis[s]=true;vn++;
	for (int k=first[s];k;k=next[k])
	{
		en++;
		if (!vis[des[k]]) {e[des[k]]=k^1;dfs(des[k],s);}
		else if (des[k]!=pre) ed=k;
	}
}
void dp(int s,int e)
{
	f[s]=1;size[s]=0;
	for (int k=first[s];k;k=next[k]) if (k/2!=ed/2&&((k^1)!=e))
	{
		dp(des[k],k);
		if (w[k]>w[e]) ans=(long long)ans*nifac[size[des[k]]]%mo*f[des[k]]%mo;
		else
		{
			size[s]+=size[des[k]];
			f[s]=(long long)f[s]*f[des[k]]%mo*C(size[s],size[des[k]])%mo;
		}
	}
	size[s]++;
}
int main()
{
	tt=1;scanf("%d",&n);n<<=1;
	fac[0]=nifac[0]=1;
	for (int i=1;i<=n;i++) {fac[i]=(long long)fac[i-1]*i%mo;nifac[i]=getmi(fac[i],mo-2);}
	for (int i=1;i<=n;i++)
	{
		int u,v;scanf("%d%d",&u,&v);v+=n/2;
		des[++tt]=v;next[tt]=first[u];first[u]=tt;
		des[++tt]=u;next[tt]=first[v];first[v]=tt;
		w[tt]=w[tt^1]=u+v;
	}
 
	int all=fac[n];
	for (int s=1;s<=n;s++) if (!vis[s])
	{
		vn=en=ed=0;dfs(s,0);en>>=1;
		if (vn!=en) {puts("0");return 0;}
		int u=des[ed],v=des[ed^1];
		for (;u!=v;u=des[e[u]]) if (w[e[u]]>w[ed]) ed=e[u];
		ans=1;dp(des[ed],ed);
		int p1=(long long)ans*nifac[size[des[ed]]]%mo*f[des[ed]]%mo;
		ans=1;dp(des[ed^1],ed);
		int p2=(long long)ans*nifac[size[des[ed^1]]]%mo*f[des[ed^1]]%mo;
		all=(long long)all*(p1+p2)%mo;
	}
	printf("%d\n",all);
}

Measured memory_bytes: 16128
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

ll gcd(ll a, ll b) {
	a = abs(a), b = abs(b);
	if (a < b)swap(a, b);
	while (b) {
		ll r = a % b; a = b; b = r;
	}
	return a;
}

LP plu(LP a, LP b) {
	ll d = a.second*b.second;
	ll r = a.first*b.second + a.second*b.first;
	ll g = gcd(d, r);
	d /= g; r /= g;
	return { r,d };
}
LP minu(LP a, LP b) {
	ll d = a.second*b.second;
	ll r = a.first*b.second - a.second*b.first;
	ll g = gcd(d, r);
	d /= g; r /= g;
	return { r,d };
}
LP normal(ll a, ll b) {
	ll g = gcd(a, b);
	a /= g; b /= g;
	return { a,b };
}
bool great(LP a, LP b) {
	return a.first*b.second >= a.second*b.first;
}
LP cc = { 360,1 };
LP zz = { 60,1 };
int n, h, m, s;
void solve() {
	int b = 119 * n - 1;
	int cur = 0;
	LP ma = { mod,1 };
	for (int k = -2; k <= 2; k++) {
		LP r = normal(-12 * s, 1);
		r = plu(r, normal(6 * m, 1));
		r = plu(r, normal(s, 10));
		r = plu(r, normal(360 * h, n));
		r = plu(r, normal(6 * m, n));
		r = plu(r, normal(s, 10 * n));
		r = plu(r, normal(360 * k, 1));
		r.first *= 10 * n;
		r.second *= 119 * n - 1;
		r = normal(r.first, r.second);
		if (r.first < 0)continue;
		LP cm = normal(6 * m, 1);
		cm = plu(cm, normal(s, 10));
		cm = plu(cm, normal(r.first, r.second * 10));
		while (great(cm, cc))cm = minu(cm, cc);
		LP ch = normal(360 * h, n);
		ch = plu(ch, normal(6 * m, n));
		ch = plu(ch, normal(s, 10 * n));
		ch = plu(ch, normal(r.first, r.second * 10 * n));
		while (great(ch, cc))ch = minu(ch, cc);
		if (ch == cm)continue;
		if (great(ma, r)) {
			//cout << k << endl;
			//cout << r.first << " " << r.second << endl;
			ma = r;
		}
	}
	ll d = b / ma.second;
	cur = ma.first*d;

	int ns = s + cur / b;
	LP xs = normal(s*b + cur,b);
	while (great(xs, zz))xs = minu(xs, zz);
	int nm = m + ns / 60;
	int nh = h + nm / 60;
	nm %= 60;
	nh %= n;
	cout << nh << " " << nm << " " << xs.first << " " << xs.second << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	while (cin >> n>>h>>m>>s,n)solve();
	//solve();
	//stop
	return 0;
}



Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int N[2], ca[2][100100], Q, a, b, c, d;
char buf[2][100100];

int g (int i, int x, int y) {
        int na = ca[i][y] - (x?ca[i][x-1]:0);
        int nb = y-x+1-na;
        return (999999 + na - nb) % 3;
}

int main () {
        scanf("%s %s %d", buf[0], buf[1], &Q);
        fo(i, 0, 2) N[i] = (int) strlen(buf[i]);
        fo(x, 0, 2) fo(i, 0, N[x]) {
                ca[x][i] = (buf[x][i] == 'A');
                if (i) ca[x][i] += ca[x][i-1];
        }
        fo(i, 0, Q) {
                scanf("%d %d %d %d", &a, &b, &c, &d);
                a--, b--, c--, d--;
                puts(g(0,a,b) == g(1,c,d) ? "YES" : "NO");
        }
        return 0;
}


Measured memory_bytes: 1536
H, W = map(int, input().split())
A = []
for i in range(H):
    a = input()
    A.append(a)

h = []
w = []
for i in range(H):
    if A[i].count(".") == W:
        h.append(i)

for i in range(W):
    qwe = 0
    for j in range(H):
        if A[j][i] == ".":
            qwe += 1
        else:
            break
    if qwe == H:
        w.append(i)

p = 0
for i in h:
    A.pop(i-p)
    p += 1

p = 0
for i in w:
    i = i - p
    for j in range(len(A)):
        A[j] = A[j][:i] + A[j][i+1:]
    p += 1


for i in A:
    print(i)

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)

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

    int ans;
    if (n % (2 * d + 1) == 0){
        ans = n / (2 * d + 1);
    } else
    {
        ans = n / (2 * d + 1) + 1;
    }
    


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

Measured memory_bytes: 256
import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            
            //入力
            int n = Integer.parseInt(sc.next());
            int count = 0;
            char[][] board = new char[n][n];
            int flag = 0;

sc.useDelimiter("");
            
            sc.next();
            
            for(int i=0; i<n; i++){
            	for(int j=0; j<n; j++){
            		board[i][j] = sc.next().charAt(0);
            	}
            	sc.next();
            }

            for(int i=0; i<n; i++){
            	flag = 0;
            	for(int j=0; j<n; j++){
            		for(int k=0; k<n; k++){
            			if(board[(j+i)%n][k] != board[(k+i)%n][j]){
            				flag = 1;
            				break;
            			}
            		}
            		if(flag == 1){
            			break;
            		}
            	}
            	if(flag == 0){
            		count++;
            	}
            }
            
            //出力
            System.out.println(n * count);
            sc.close();
        }
    }
	

Measured memory_bytes: 44736
#include <bits/stdc++.h>
using namespace std ;
bool flag =false ;
int a[36] ={1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,28,30,32,35,36,40,42,45,48,49,54,64,72,81};
int main() {
 	int n ;
  	cin >> n ;
  	for(int i =0 ; i < 36 ; i++) {
    	if(a[i] == n) flag = true ; 
    }
  	if(flag) cout << "Yes" << endl ;
  	else cout << "No" << endl ;
	return 0 ;
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, C;
    cin >> N >> C;
    vector<vector<ll>> costs(C + 1, vector<ll>(C + 1)); //at(from).at(to)
    for (int i = 1; i <= C; i++)
    {
        for (int j = 1; j <= C; j++)
        {
            cin >> costs.at(i).at(j);
        }
    }
    vector<vector<ll>> colorCounts(3, vector<ll>(C + 1));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            ll color;
            cin >> color;
            colorCounts.at((i + j) % 3).at(color)++;
        }
    }
    ll answer = 1e12;
    for (int i = 1; i <= C; i++)
    {
        for (int j = 1; j <= C; j++)
        {
            if (i == j)
            {
                continue;
            }
            for (int k = 1; k <= C; k++)
            {
                if (i == k || j == k)
                {
                    continue;
                }
                ll tempAnswer = 0;
                for (int n = 1; n <= C; n++)
                {
                    tempAnswer += colorCounts.at(0).at(n) * costs.at(n).at(i);
                    tempAnswer += colorCounts.at(1).at(n) * costs.at(n).at(j);
                    tempAnswer += colorCounts.at(2).at(n) * costs.at(n).at(k);
                }
                answer = min(answer, tempAnswer);
            }
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string str;
  cin>>str;
  vector<int> v;
  int res=0;
  for(int i=0;i<3;i++)
  {
    if(str[i]=='R')
      res++;
   else
     res=0;
    v.push_back(res);
   }
  cout<<*max_element(v.begin(),v.end());
  return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

// 参考：https://iloveconviniboshi.hatenablog.com/entry/2019/11/19/013117
// 参考：https://par.hateblo.jp/entry/2018/04/01/205547

int main() {

    string s; cin >> s;

    if (s.length() != 26) {
        vector<int> c(26, 0);
        for (int i = 0; i < s.length(); ++i) {
            c[s[i] - 'a'] = 1;
        }

        for (int i = 0; i < 26; ++i) {
            if (c[i] == 0) {
                cout << s << char(i + 'a') << endl;
                return 0;
            }
        }
    } else {
        // 26文字の場合
        string next = s;
        if (next_permutation(next.begin(), next.end())) {
            for (int i = 0; i < 26; ++i) {
                if (next[i] == s[i]) {
                    cout << next[i];
                } else {
                    cout << next[i];
                    break;
                }
            }
            cout << endl;
        } else {
            cout << -1 << endl;
        }
    }
}

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

int main(){
    ll n,a=0,b=0;
    cin >> n;
    vector<ll> vec(n);
    rep(i,n) cin >> vec[i];
    sort(vec.begin(),vec.end(),greater<ll>());
    rep(i,n){
        if(i%2==0) a+=vec[i];
        else b+=vec[i];
    }
    
    cout << a-b << endl;
    
    return 0;
}










Measured memory_bytes: 256
# -*- coding: utf-8 -*-
l = []

for i in range(5):
    b = int(input())
    l.append(b)

ll = []
min = 10
index = 0
lll = []
for i in range(5):
    ll.append(int(l[i]*0.1)*10)
    ll[i] = l[i]-ll[i]
    if ll[i] > 0:
        lll.append(l[i]-ll[i]+10)
        if min > ll[i]:
            min = ll[i]
            index = i
    else:
        lll.append(l[i])
    
sum = 0
for i in range(5):
    if i != index:
        sum = sum + lll[i]
    else:
        sum = sum + l[i]

print(sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll X;
  cin >> X;
  vector<ll> pos;
  for (ll i = 0; i <= 1000; ++i) {
    pos.push_back(pow(i, 5));
  }
  for (ll i = 0; i < pos.size(); ++i) {
    for (ll j = 0; j < pos.size(); ++j) {
      if (pos.at(i) + pos.at(j) == X) {
        cout << i << ' ' << -(j) << "\n";
        return 0;
      }
      else if (pos.at(i) - pos.at(j) == X) {
        cout << i << ' ' << j << "\n";
        return 0;
      }
    }
  }
}


Measured memory_bytes: 4056
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
FirstBigList = []
newMoney = list(oldMoney)
 
 
def FindFirstBig(okLines, m, FirstBig):
    for i in okLines:
        if i > m:
            FirstBig.append(i)
            break
    return FirstBig
 
 
for i in range(10):
    if str(i) not in hateLines:
        okLines.append(str(i))
 
FirstFlag = -1
ProblemFlag = -1
for index, m in enumerate(oldMoney):
    if FirstFlag == -1:
        if m in hateLines:
            FirstBigList = FindFirstBig(okLines, m, FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[index] = FirstBigList[0]
                FirstFlag = index
            ProblemFlag = index
    elif FirstFlag != -1:
        newMoney[index] = okLines[0]
 
if oldMoney == newMoney:
    if ProblemFlag is not 0 and ProblemFlag is not -1:
        FirstBigList.clear()
        while ProblemFlag:
            FirstBigList = FindFirstBig(okLines, newMoney[ProblemFlag - 1], FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[ProblemFlag - 1] = FirstBigList[0]
                for i in range(ProblemFlag, len(newMoney), 1):
                    newMoney[i] = okLines[0]
            if oldMoney == newMoney:
                ProblemFlag -= 1
    if ProblemFlag is 0:
        if okLines[0] != '0':
            newMoney.insert(0, okLines[0])
        else:
            newMoney.insert(0, okLines[1])
        for i in range(ProblemFlag + 1, len(newMoney), 1):
            newMoney[i] = okLines[0]
resultnew = "".join(newMoney)
print(resultnew)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    print( 0 if N % K == 0 else 1  )
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	int l[N];
	rep(i, N) cin >> l[i];
	sort(l, l + N, greater<int>());
	int ans = 0;
	rep(i, K) ans += l[i];

	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int,input().split())
broken = [0]*(n+1)
for _ in range(m):
  a = int(input())
  broken[a]=1

dp = [0]*(n+2)
mod = int(1e9+7)
dp[n] = 1
for i in range(n-1, -1 , -1):
  if broken[i]:
    dp[i] = 0
  else:
    dp[i] = (dp[i+1] + dp[i+2]) % mod

print(dp[0])

Measured memory_bytes: 7668
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    vector<int> v[100100];
    rep(i,0,N){
        int a,b; cin >> a >> b;
        v[a].push_back(b);
    }
    rep(i,0,N) sort(v[i].begin(), v[i].end());
    priority_queue<int> que;

    ll ans = 0;
    reps(i,1,M){
        rep(j,0,SZ(v[i])){
            que.push(v[i][j]);
        }
        if(!que.empty()){
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << enld;
    return 0;
}


Measured memory_bytes: 8912
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>

int main(void) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        puts("Possible");
    }
    else {
        puts("Impossible");
    }
    return 0;
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    L = list(map(int,input().split()))

    L.sort()
    count=0
    for i in range(N-2):
        for j in range(i+1,N-1):
            if L[i] ==L[j]:
                continue

            for k in range(j+1,N):
                if L[i] +L[j] >L[k] and L[j] != L[k]:
                    count+=1

    print(count)

if __name__ == "__main__":
    main()


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

///////////////////////////////////////////
//const long long int INF = 1000000000000000000LL;
const long long int INF = 1000000;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(    v[0])>()) //降順でVをソート
///////////////////////////////////////////

ll get_nu(ll x,ll y,ll z){//zが余り、xが大きな数,yが割る数
    return (x+z) / y;
}

int main(){
    ll n,k;cin>>n>>k;
    ll ans =0;
    ll x = get_nu(n,k,0);
    ans = x*x*x;
   // cout<<ans<<endl;
    if(k%2==0){
        ll y = get_nu(n,k,k/2);
        //y += 1;
        ans += y*y*y;
    }
    //ll y = get_nu(n,)
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// schedule lectures codechef
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define clr clear()
#define ins insert
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define cusmem(x,val) for(auto &i:x) i=val;
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false);\
            cin.tie(NULL);\
            cout.tie(NULL);
using namespace std;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
string imp="Impossible\n";

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
clock_t startTime;
double getCurrentTime() {
    return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
// const int N=10;
const int N=2e4+5;
ll MOD=1e9+7;
ll m,k,i,j;
bool f0,f1,f2;
const int MAXN=2e3;
int main(){
    #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin); 
            freopen("output.txt","w",stdout);
    #endif
    fastio
	cout<<fixed<<setprecision(11);
    int tests=1;    
    // cin>>tests;
    while(tests--){
        ll n; cin>>n;
        ll a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        ll c=1000,cnt=0;
        for(int i=0;i+1<n;){
            int j=i+1;
            if(a[i]>=a[j]){
                while(j<n&&a[i]>=a[j]){
                    j++;
                    i++;
                }
                if(j!=n){
                    cnt=c/a[i];
                    c-=cnt*a[i];
                    c+=cnt*a[j];
                }
            }
            else{
                cnt=c/a[i];
                c-=cnt*a[i];
                c+=cnt*a[j];
            }
            i=j;
        }
        cout<<c<<"\n";
    }

    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main(){
long long a, b, c;
cin>>a>>b>>c;
vector<long long> vec;
vec.push_back(a);
vec.push_back(b);
vec.push_back(c);
sort(vec.begin(), vec.end());
cout<<vec[0]+vec[1]<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    char s[102];
    cin >> s;
    
    int i=0;
    while(s[i] != '\0'){
        s[i] = 'x';
        i++;
    }
    
    cout << s << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define sum accumulate
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 998244353LL;
int main(){
	int w,h,x,y,r;
	std::cin >> w>>h>>x>>y>>r;
	if(x-r<0||y-r<0||x+r>w||y+r>h)std::cout << "No" << std::endl;
	else std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
 
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
 
int main() {
	FASTIO

	string s;
	cin >> s;
	int sum = 0;
	for(char c : s) sum += c-'0';
	cout << ((sum%9 == 0) ? "Yes\n" : "No\n");
	
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  pqdesc<pair<int, int>> q;
  rep(i, n) {
    q.emplace(a[i], i);
  }
  vi64 ans(n);
  int cnt = 0;
  int ma = q.top().first;
  do {
    int idx;
    while (sz(q) && q.top().first == ma) {
      cnt += 1;
      idx = q.top().second;
      q.pop();
    }
    int next = 0;
    if (sz(q)) {
      next = q.top().first;
    }
    ans[idx] += (i64) (ma - next) * cnt;
    if (sz(q)) {
      ma = q.top().first;
      cnt -= 1;
      q.emplace(ma, idx);
    }
  } while (sz(q));
  rep(i, n) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>

using namespace std;

const int INF = (1<<30) - 1;


int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int N, M;
    while(cin>>N>>M, N|M){
        vector<pair<int, int>> S[10001];
        
        int r;
        cin >> r;
        while(r--){
            int t, n, m, s;
            cin >> t >> n >> m >> s;
            S[m].push_back(make_pair(t, s));
        }
        for(int i=1; i<=M; i++)
            sort(S[i].begin(), S[i].end());
        
        int q;
        cin >> q;
        while(q--){
            int s, e, m;
            cin >> s >> e >> m;
            int sum = 0;
            int count = 0;
            int time = s;
            
            for(auto p: S[m]){
                if(time <= p.first && count > 0){
                    sum += min(p.first, e) - time;
                }
                time = max(time, min(p.first, e));
                if(time == e)
                    break;
                count += p.second ? 1 : -1;
            }
            
            cout << sum << endl;
        }
    }
    
    return 0;
}

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

int main() {
  int a, b, c, d;
  
  cin >> a >> b >> c >> d;
  if(a+b < c+d) {
    cout << "Right" << endl;
  }else if(a+b == c+d) {
    cout << "Balanced" << endl;
  }else {
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100000
#define Q 50000

int main(){
        int i=0,n,q,var[N],var2[Q],f=0,a,b,c;
        scanf("%d",&n);

        while(i<n) {
                scanf("%d",&var[i]);
                i++;
        }

        i=0;
        scanf("%d",&q);
        while(i<q) {
                scanf("%d",&var2[i]);
                i++;
        }

        for(i=0; i<q; i++) {
                a=0;
                b=n;
                while(a<b) {
                        c=(a+b)/2;
                        if(var2[i]==var[c]) {
                                f++;
                                break;
                        }
                        if(var2[i]>var[c])
                                a=c+1;
                        else if(var2[i]<var[c])
                                b=c;
                }
        }
        printf("%d\n",f);


        return 0;
}

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

int main(){
    long long N, M, o;

    scanf("%lld%lld",&N,&M);

    if(N == 1 && M == 1) o = 1;
    else if(N == 1) o = M - 2;
    else if(M == 1) o = N - 2;
    else o = (M - 2) * (N - 2);

    printf("%lld\n",o);

    return 0;
}


Measured memory_bytes: 128
import javax.swing.plaf.IconUIResource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.IllegalCharsetNameException;
import java.util.*;
public class Main {

     public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        long a=sc.nextLong();
         long b=sc.nextLong();
         long c=sc.nextLong();
         long d=sc.nextLong();
        long ans1=a*c;
        long ans2=a*d;
        long ans3=b*c;
        long ans4=b*d;
        long ans=Math.max(ans1,Math.max(ans2,Math.max(ans3,ans4)));
         System.out.println(ans);






     }

    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }
    static void sortReverse(long[] a) {
        ArrayList<Long> l=new ArrayList<>();
        for (long i:a) l.add(i);
//        Collections.sort.(l);
        Collections.sort(l,Collections.reverseOrder());
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long[] readArrayLong(long n) {
            long[] a=new long[(int)n];
            for (int i=0; i<n; i++) a[i]=nextLong();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }


}

Measured memory_bytes: 32956
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int MAX_N = 1e5 + 5;
const int INF = 0x7fffffff;
const double eps = 1e-6;

int a, b, x;



int main()
{
#ifdef ANONYM
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    ios::sync_with_stdio(false);
    cin >> x >> a >> b;
    x -= a;
    cout << x % b << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>
#include <map>

#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
#define gmax(a,b) __gcd(a,b)
#define gmin(a,b) a/__gcd(a,b)*b
using namespace std;
//obj;
class binary{
public:
    bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}
int binary_search(int key,vi a) {
   
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key,a)) ok = mid;
        else ng = mid;
    }
    return ok;
}
}obj;

int main(){
int n;cin>>n;
int d;cin>>d;
ll ans=0;
rep(i,n){
    ll x,y;
    double k;
    cin>>x>>y;
  ll xi=x*x;
  ll yi=y*y;
  k=xi+yi;
  k=sqrt(k);
  ll di=d*d;

  if(k<=d)ans++;

}
cout<<ans<<endl;


return 0;

 }


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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    string ans;
    if (N==0) {
        cout << "0" << "\n";
        return 0;
    }
    while (N!=0){
        int p = abs(N);
        if (p%2==1) {
            ans.push_back('1');
            N -= 1;
        } else ans.push_back('0');
        N /= -2;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << "\n";
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int N;
    cin >> N;
    vi A(N);
    vi B(N);
    rep(i,N) cin >> A[i] >> B[i];
    
    sort(all(A));
    sort(all(B));
    int a,b;
    if(N%2 == 0){
        a = A[N/2-1] + A[N/2];
        b = B[N/2-1] + B[N/2];
        //cout << a csp b << endl;
        cout << b-a+1 << endl;
    }else{
        a = A[N/2];
        b = B[N/2];
        cout << b-a+1 << endl;
    }
    
    

    return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  
  map<ll, ll> mp;
  ll a;
  for(int i = 0; i < N; i++){
    cin >> a;
    mp[a]++;
  }

  vector<pair<ll, ll>> stick;
  ll num = 0;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    if(itr->second >= 2){
      stick.push_back(make_pair(itr->first, itr->second));
      num += itr->second;
    }
  }

  if(num < 4){
    cout << 0 << endl;
  }else{
    sort(stick.begin(), stick.end(), greater<pair<ll, ll>>());
    if(stick[0].second >= 4){
      cout << stick[0].first * stick[0].first << endl;
    }else{
      cout << stick[0].first * stick[1].first << endl;
    }
    
  }

  return 0;
}


Measured memory_bytes: 6528
#include <iostream>

int main()
{
	int res{0};
  	int n;
  	std::cin >> n;
  	int64_t d;
  	std::cin >> d;
  	std::pair<int64_t, int64_t> pr;
  	for(int i = 0; i < n; ++i)
    {
    	std::cin >> pr.first >> pr.second;
      	if(pr.first*pr.first + pr.second*pr.second <= d*d)
          	++res;
    }
  	std::cout << res;
  	return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	ll n , q ;
	cin >> n >> q;
	vector<vector<ll>> KI(n);
	rep(i,n-1)
	{
		ll foo,fooo;
		cin >> foo >>fooo;
		foo--;fooo--;
		if(foo>=fooo)return 1;
		KI[foo].push_back(fooo);
		KI[fooo].push_back(foo);
	}
	vector<ll> cost(n,0);
	rep(i,q)
	{
		ll foo,fooo;
		cin >> foo >> fooo;
		foo--;
		cost[foo]+=fooo;
	}
	stack<ll> S;

	vector<ll> ans(n,-1);
	S.push(0);
	ans[0]=cost[0];
	ll ncost=0;
	while(!S.empty())
	{
		ll now = S.top();
		//if(ans[now]==-1)ncost+=cost[now];
		//cout<<now<<endl;
		ll next = -1;
		rep(i,KI[now].size())
		{
			if(ans[KI[now][i]]==-1)
			{
				S.push(KI[now][i]);
				next = KI[now][i];
				cost[next] += cost[now];
				ans[KI[now][i]]=1;
			}
		}
		//cout<<next<<endl;
		if(next==-1)
		{
			S.pop();
		}
		
	}

	rep(i,n)
	{
		cout<<cost[i]<<' ';
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 19440
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    vector<vector<int>> c(M, vector<int>(0));

    set<int> can_be_opened;
    for(int i=0; i<M; i++){
        cin >> a[i] >> b[i];
        for(int j=0; j<b[i]; j++) {
            int tmp;
            cin >> tmp;
            tmp--;
            c[i].push_back(tmp);
            can_be_opened.insert(tmp);
        }
    }

    if(can_be_opened.size() < N) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> dp((1<<N), 1e9);
    for(int i=0; i<M; i++) {
        int flag = 0;
        for(int j=0; j<b[i]; j++)
            flag |= (1<<c[i][j]);
        dp[flag] = min(dp[flag], a[i]);
    }

    // cerr << "debug" << endl;
    // for(auto x: dp) cerr << x <<" "; cerr << endl;

    for(int i=0; i<(1<<N); i++) {
        for (int y = 0; ; y = (y - i) & i) {
            for(int z = 0; ; z = (z-i) & i ) {
                if(y!=z && (y|z)==i)
                    dp[i] = min(dp[i], dp[y] + dp[z]);
                if(z==i) break;
            }
            if (y == i) break;
        }
    }
    // cerr << "debug result" << endl;
    // for(auto x: dp) cerr << x <<" "; cerr << endl;
    cout << dp[(1<<N)-1] << endl;
    return 0;
}


Measured memory_bytes: 384
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int a, b;
    scan(a, b);

    auto map = new char[][](100, 100);
    fillAll(map, '.');

    foreach (i ; 0 .. 50) {
        foreach (j ; 0 .. 50) {
            map[i][j] = '#';
        }
    }

    a--;

    foreach (i ; 0 .. 25) {
        foreach (j ; 0 .. 25) {
            if (a == 0) {
                goto B1;
            }
            a--;
            map[2*i][2*j] = '.';
        }
    }

    B1:

    b--;

    foreach (i ; 0 .. 25) {
        foreach (j ; 0 .. 50) {
            if (b == 0) {
                goto B2;
            }
            b--;
            map[50 + 2*i + 1][2*j] = '#';
        }
    }

    B2:

    writeln("100 100");
    foreach (i ; 0 .. 100) {
        writeln(map[i]);
    }
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

int dp[401][401];

void solve() {
  int N, ma, mb;
  cin >> N >> ma >> mb;
  repc(i, 400) repc(j, 400) {
    dp[i][j] = 1e9;
  }
  dp[0][0] = 0;
  rep(i, N) {
    int a, b, c;
    cin >> a >> b >> c;
    rrepc(j, 400) rrepc(k, 400) {
      if (dp[j][k] == 1e9) continue;
      amin(dp[j + a][k + b], dp[j][k] + c);
    }
  }
  int ans = 1e9;
  for (int i = 1; i * ma <= 400 && i * mb <= 400; i++) {
    amin(ans, dp[i * ma][i * mb]);
  }
  if (ans == 1e9) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 896
# Problem E - Colorful Blocks

# input
N, M, K = map(int, input().split())

# initialization
MOD = 998244353
fact = [1, 1]
fact_inv = [1, 1]
inv = [0, 1]
# pow_list = [1, M-1]
for i in range(2, N+1):
    fact.append((fact[-1] * i)%MOD)
    inv.append((-inv[MOD%i] * (MOD//i))%MOD)
    fact_inv.append((fact_inv[-1] * inv[-1])%MOD)
    # pow_list.append(pow_list[i-1]*(M-1)%MOD)

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n-r)
    return fact[n] * fact_inv[r] * fact_inv[n-r] % p

ans = 0

# calc
for i in range(K+1):
    # tmp = ((M * cmb(N-1, i, MOD))%MOD * pow_list[N-(i+1)])%MOD
    tmp = ((M * cmb(N-1, i, MOD))%MOD * pow(M-1, N-(i+1), MOD))%MOD
    ans = (ans + tmp)%MOD

# output
print(ans)


Measured memory_bytes: 33304
m,d=map(int,input().split())

ans=0
for i in range(1,m+1):
    for j in range(1,d+1):
        d10=j//10
        d1=j%10
        if d10>1 and d1>1:
            if i==d1*d10:
                ans+=1
                
print(ans)

Measured memory_bytes: 39664