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

#define int long long
#define REP(i, l, r) for (__typeof(l) i = (l); i != (r); (l)<(r)?++i:--i)
#define popcount __builtin_popcountll

const int INF = 1LL<<60;
const int MOD = 1000000007;

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";
}

template <typename A>
string to_string(vector<A> v) {
    bool first = true;
    string result = "[";
    for (A i : v) {
        if (!first) result += ", ";
        first = false;
        result += to_string(i); 
    }
    return result + "]";
}

template <typename A>
string to_string(A x[], signed n) {
    string result = "{";
    for (signed i=0; i<n; ++i) {
        if (i!=0) result += ", ";
        result += to_string(x[i]); 
    }
    return result + "}";
}

string bin_string(int x) {
    const int d = 64;
    string result(d, ' ');
    for (signed i=d-1; i>=0; --i) result[d-1-i] = '0'+((x&1LL<<i)!=0);
    return result;
}

int powa(int base, int exp) {
    if (exp<=0) return 1;
    if (base<=0) return 0;
    int val = powa(base, exp>>1);
    val = val*val % MOD;
    if (exp&1) {
        val = val*base % MOD;
    }
    return val;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int n;
    cin >> n;
    int a[3] = {};
    int res = 1;
    REP(i, 0, n) {
        int x;
        cin >> x;
        int poss = 0;
        REP(j, 0, 3) if (a[j] == x) ++poss;
        res *= poss;
        res %= MOD;
        REP(j, 0, 3) {
            if (a[j] == x) {
                ++a[j];
                break;
            }
        }
    }
    cout << res;
}


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

int main() {
  char c;
  cin >> c;
  
  if(c == 'a'){
    cout << "vowel" << endl;
  }
  else if(c == 'i'){
    cout << "vowel" << endl;
  }
  else if(c == 'u'){
    cout << "vowel" << endl;
  }
  else if(c == 'e'){
    cout << "vowel" << endl;
  }
  else if(c == 'o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
s=input()
n=int(input())
t=True
a=str()
b=str()
for i in range(n):
    q=input().split()
    if(len(q)==1):
        t=not t
        continue
    if(int(q[1])==1):
        if(t):a=q[2]+a
        else:b=b+q[2]
    if(int(q[1])==2):
        if(t):b=b+q[2]
        else:a=q[2]+a
if(t):print(a+s+b)
else:print(b[::-1]+s[::-1]+a[::-1])

Measured memory_bytes: 4396
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string a;
    cin>>a;
    if(int(a.find('C'))!=-1 && int(a.rfind('F'))!=-1 && a.find('C')<a.rfind('F'))
        cout<<"Yes";
    else
        cout<<"No";
}

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


int main()
{
	int N;
	cin>>N;
	bool flag=true;
	rep(i,N)
	{
		int A;
		cin>>A;
		if(A%2==0&&A%3!=0&&A%5!=0)
		{
			flag=false;
			break;
		}
	}
	if(flag)
	{
		cout<<"APPROVED"<<endl;
	}
	else
	{
		cout<<"DENIED"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
MOD = 998244353
MAXN = 2*(10**5)+10
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod


N, M, K = map(int, input().split())
ans = 0
for i in range(K+1):
    tmp = pow(M-1, N-i-1, MOD) * M % MOD
    tmp *= nCr(N-1,i,MOD)
    ans += tmp % MOD
    ans %= MOD
print(ans)

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

int getMinCost(int n, int a[]){
	
	bool flag[n];
	int b[n];
	int mn = 1 << 30;
	int mx = mn * -1;
	for(int i=0; i<n; i++){
		flag[i]=false;
		b[i] = a[i];
		mn = min(mn, a[i]);
		mx = max(mx, a[i]);
	}
	sort(b, b+n);
	
	int p[mx+1];
	for(int i=0;i<n;i++){
		p[b[i]] = i;
	}
	
	int cost=0;
	for(int i=0; i<n; i++){
		if(flag[i]) continue;
		int idx=i;
		int m=mx;
		int sum=0;
		int cnt=0;
		while(true){
			flag[idx]=true;
			int val=a[idx];
			sum+=val;
			cnt++;
			m=min(m,val);
			idx=p[val];
			if(flag[idx]) break;
		}
		int c1=sum+(cnt-2)*m;
		int c2=c1+(2*(m+mn));
		c2 -= (cnt-1)*(m-mn);
		cost+=min(c1, c2);
	}
	return cost;
}

int main(){
	
	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	
	cout << getMinCost(n, a) << endl;
	return 0;
}



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

int main()
{
	double n;

	cin >> n;

	while (n >= 0) {

		if ((int)n >= 256 || (int)(n * 16) != n * 16)
			cout << "NA" << endl;
		else {
			int a[8];

			int na = (int)n;

			for (int i = 0; i < 8; i++) {
				a[7 - i] = na % 2;
				na /= 2;
			}

			for (int i = 0; i < 8; i++)
				cout << a[i];

			cout << ".";

			double nb = n - (int)n;

			for (int i = 0; i < 4; i++) {
				nb *= 2;
				cout << (int) nb;
				nb -= (int) nb;
			}
			cout << endl;
		}

		cin >> n;
	}

	return 0;
}



Measured memory_bytes: 3176
N,a,b = [int(i) for i in input().split()]
mod = 10**9+7
def power(x, n):
    ans = 1
    while(n > 0):
        if(bin(n & 1) == bin(1)):
            ans = ans*x%mod
        x = (x*x)%mod
        n = n >> 1 #ビットシフト
    return ans
def fact(m, n):
    val = 1
    for i in range(m, n+1):
        val = val*i % mod
    return val
    
def cmb1(N, r):
    A = fact(N-r+1, N)%mod
    B = fact(1, r)%mod
    return A, B, (A*power(B, mod-2))%mod
def cmb2(a, b, A, B):
    A = fact(N-a+1, N-b)*A%mod
    B = fact(b+1, a)*B%mod
    return (A*power(B, mod-2))%mod
if(a>N//2):
    a = N-a
if(b>N//2):
    b = N-b
tmp = max(a,b)
b = min(a,b)
a = tmp
A, B, K1 = cmb1(N, b)
K2 = cmb2(a, b, A, B)
print((power(2, N)-1-K1-K2)%mod)

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"math"
)

func main() {
	h, w := int2()
	h1 := h - h/2
	h2 := h - h1
	w1 := w - w/2
	w2 := w - w1

	if h == 1 || w == 1 {
		fmt.Println(1)
	} else {
		fmt.Println(h1*w1 + h2*w2)
	}
}

func str1() string {
	var s string
	fmt.Scan(&s)
	return s
}

func int1() int {
	var x int
	fmt.Scan(&x)
	return x
}

func int2() (int, int) {
	var x, y int
	fmt.Scan(&x, &y)
	return x, y
}

func int3() (int, int, int) {
	var x, y, z int
	fmt.Scan(&x, &y, &z)
	return x, y, z
}

func sliceInt(n int) []int {
	slice := make([]int, n)
	for i := range slice {
		fmt.Scan(&slice[i])
	}
	return slice
}

func sliceSum(slice []int) int {
	total := 0
	for i := range slice {
		total += slice[i]
	}
	return total
}

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func powInt(x, pow int) int {
	return int(math.Pow(float64(x), float64(pow)))
}


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	long long r, d, x;
	cin >> r >> d >> x;
	for (int i = 0; i < 10; i++) {
		x = r * x - d;
		cout << x << "\n";
	}
}


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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#define ll long long
#define mod 1000000007
using namespace std;
ll spf[1000009], n, arr[10009];
map<ll, ll>prime_factors;
ll fp(ll base, ll exp)
{
	if (exp == 0)
		return 1;
	ll ans = fp(base, exp / 2);
	ans = (ans * ans) % mod;
	if (exp % 2 != 0)
		ans = (ans * (base % mod)) % mod;
	return ans;
}
void sieve()
{
	spf[1] = 1;
	for (int i = 2; i <= 1000000; i++)
		spf[i] = i;
	for (int i = 2; i <= 1000000; i += 2)
		spf[i] = 2;
	for (int i = 3; i * i <= 1000000; i++)
	{
		if (spf[i] == i)
		{
			for (int j = i; j <= 1000000; j += i)
				spf[j] = i;
		}
	}
}
vector<ll>getFactorization(ll x)
{
	vector<ll> ret;
	while (x != 1)
	{
		ret.push_back(spf[x]);
		x = x / spf[x];
	}
	return ret;
}
int main()
{
	sieve();
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int i = 0; i < n; i++)
	{
		ll a = arr[i];
		vector<ll>v = getFactorization(a);
		for (auto x : v)
		{
			int c = 0;
			while (a % x == 0 && a > 1)
			{
				c++;
				a /= x;
			}
			if (c)
			{
				if (c > prime_factors[x])
					prime_factors[x] = c;
			}
		}
	}
	ll lcm = 1, sum = 0;
	for (auto m : prime_factors)
		lcm = (lcm%mod)*fp(m.first, m.second);
	for (int i = 0; i < n; i++)
		sum = (sum % mod) + ((lcm%mod) * fp(arr[i],mod-2)) % mod;
	cout << sum % mod;
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define DEBUG

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

const int oo = 1e9 + 7;
const ll mod = 998244353, maxn = 200200;
const double PI = acos(-1);

bool comp(pii a, pii b){
    return a.ss > b.ss;
}

int main (){
    int n;
    string s;
    bool can = true;
    cin >> n;

    vector<pii> v1, v2;


    for (int i=0; i<n; i++){
        cin >> s;
        int tam = s.size(), a = 0, b = 0, q = 0;

        for (int j=0; j<tam; j++){
            if (s[j] == ')'){
                if (q > 0) q--;
                else a++;
            }
            else ++q;
        }
        b = q;
        if (a < b) v1.emplace_back(a, b);
        else v2.emplace_back(a, b);
    }

    sort(all(v1));
    sort(all(v2), comp);

    int q = 0;

    for (auto x: v1){
        q -= x.ff;
        if (q < 0) can = false;
        q += x.ss;
    }

    for (auto x: v2){
        q -= x.ff;
        if (q < 0) can = false;
        q += x.ss;
    }
    if(q != 0) can = false;

    if (can){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;   
}

Measured memory_bytes: 19112
#include <bits/stdc++.h>
#define Maxn 200007
using namespace std;
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,k;
int a[Maxn],b[Maxn];
int main()
{
	n=read(),k=read();
	for (int i=1;i<=n;i++)
		a[i]=read(),b[i]=read();
	long long ans=0;
	for (int i=1;i<=31;i++)
		if (k&(1<<(i-1)))
		{
			long long cnt=0;
			for (int j=1;j<=n;j++)
			{
				bool check=true;
				for (int r=i+1;r<=31;r++)
					if ((k&(1<<(r-1)))<(a[j]&(1<<(r-1)))) check=false;
				if ((a[j]&(1<<(i-1)))) check=false;
				if (check) cnt+=b[j];
			}
			ans=max(ans,cnt);
		}
	long long cnt=0;
			for (int j=1;j<=n;j++)
			{
				if ((k&a[j])==a[j]) cnt+=b[j];
			}
	ans=max(ans,cnt);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> c(10, vector<ll>(10));
    vector<vector<ll>> a(h, vector<ll>(w));
    REP(i, 10)
    {
        REP(j,10){
            cin >> c[i][j];
        }
    }

    REP(i,h){
        REP(j,w){
            cin >> a[i][j];
        }
    }

    

    REP(k,10){
        REP(i,10){
            REP(j,10){
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }

    ll sum = 0;
    REP(i,h){
        REP(j,w){
            if(a[i][j] != -1){
                sum += c[a[i][j]][1];
            }
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 512
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[100005];
ll dp[100005];
#define ALL(v)  (v).begin(),(v).end()
std::set<int> st;
//#define MAX(a,b) if(a>b)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

    /*  ペア関連
    //vector<pair<long long, long long> > pairs(N);
    for(long long i=0; i<N; i++){
        long long a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    
    //sort(pairs.begin(), pairs.end(),greater<pair<int,int> >());
	sort(pairs.begin(), pairs.end());
    */

 	//stack<int> sta;   
    //queue<int> que;


int main(){
	
	long long N,M,K;
	string s;
    
	//std::cin >> N;
    //std::cin >> N >> M;
    std::cin >> N >> M >> K;
    
	//std::vector<long long> v(N);
	//std::vector<long long> w(N);
    //std::cin >> s;
    
    
    // 配列入力
    /*
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
	}
	*/
	/*
	for(long long i=0; i<N; i++){
		std::cin >> w[i];
	}
	*/
	
	
	//ソート
    //std::sort(v.begin(),v.end());//昇順ソート
    //std::sort(v.begin(),v.end(),std::greater<long long>());//降順ソート
    //std::sort(w.begin(),w.end());//昇順ソート
    //std::sort(w.begin(),w.end(),std::greater<long long>());//降順ソート
    /*
    
    //S.substr(i, 5);
    //S.size();
    */
	

    
    long long sum,sum1;
	sum=0;
	sum1=0;
	int flg,flg1,cnt,cnt1;
	flg=0;
	flg1=0;
	cnt=0;
	cnt1=0;
	int max;
	int max1;
	max=0;
	max1=0;
	int min;
	int min1;
	min=INF;
	min1=INF;

	int work1,work2,work3,work4;
	work1=0;
	work2=0;
	work3=0;
	work4=0;

	int a[4];
	int value;
	value=0;
	/*
	a[0] = (value % 10); 
	value /= 10;// 1桁目を取り出す
	a[1] = (value % 10); 
	value /= 10;// 2桁目を取り出す
	a[2] = (value % 10); 
	value /= 10;// 3桁目を取り出す
	a[3] = (value % 10); 
	value /= 10;// 4桁目を取り出す
    work1=a[0]+10*a[1];
    work2=a[2]+10*a[3];
    */
	
	
	//文字列入力
	/*
	for(long long i=0; i<s.length(); i++){
		
		if(s[i]!='1'){
	}
	*/
	int pre_sum;
	pre_sum=K;
    for(long long i=0; i<10; i++){
		//N,M,K
		sum=N*pre_sum-M;
		pre_sum=sum;
		printf("%d\n",sum);
	}


	return 0;
}


Measured memory_bytes: 256
n = int(input())
a=[]
b=[]
c=[]
for i in range(n):
    in1,in2,in3 = map(int,input().split())
    a.append(in1)
    b.append(in2)
    c.append(in3)

dp = [[0]*3 for _ in range(n)]#[0]*nではない
dp[0] = [a[0],b[0],c[0]] 
for i in range(1,n):
    dp[i][0] = max([dp[i-1][1],dp[i-1][2]])+a[i]
    dp[i][1] = max([dp[i-1][0],dp[i-1][2]])+b[i]
    dp[i][2] = max([dp[i-1][0],dp[i-1][1]])+c[i]
print(max(dp[n-1]))

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    map<ll, ll> cnt;
    rep(i, N) {
        cnt[A[i]]++;
    }

    ll ans = 0;
    for (P p : cnt) {
        ans += (p.second - 1) * p.second / 2;
    }
    // print(ans);

    rep(i, N) {
        ll a = A[i];
        ll t = cnt[a];
        ll minus = t * (t - 1) / 2;
        t--;
        ll plus = t * (t - 1) / 2;
        // print(minus, plus);
        cout << ans - minus + plus << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;


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

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; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

int main() {
	int a, b;
	double res = 0;
	cin >> a >> b;
	for (int i = 1; i <= a; i++) {
		double p = i;
		double num = 1.0/a;
		while (p < b) {
			p *= 2;
			num/=2;
		}
		res += num;
	}
	cout<< setprecision(12) << res << endl;
}


Measured memory_bytes: 256
n = int(input())

def checkMult9(m):
	ms = str(m)
	if len(ms) > 2:
		s = 0
		for letter in ms:
			s += int(letter)
		return checkMult9(s)
	return m%9 == 0

print('Yes' if checkMult9(n) else 'No')

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




int main(){

string s;
cin>>s;
int n=s.length()-1;
if(s[n]=='s'){
    cout<<s+"es"<<endl;
}
else{
    cout<<s+"s"<<endl;
}

}


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

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    int max_A = 0, nmax_A = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if (A[i] > max_A)
        {
            max_A = A[i];
        }
        else if (A[i] == max_A)
        {
            nmax_A = A[i];
        }
        else if (A[i] > nmax_A)
        {
            nmax_A = A[i];
        }
        
        
        
    }
    
    for (int i = 0; i < N; i++)
    {
        if (A[i] == max_A)
        {
            cout << nmax_A << endl;
        }
        else
        {
            cout << max_A << endl;
        }
    }
    
}

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

Measured memory_bytes: 4012
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
n = I()
l = LI()
l.sort()
ans = 0
for i in range(n):
    ans += l[2*i]
print(ans)
"""

#B
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n,x = LI()
print((n-gcd(n,x))*3)
#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 39152
import java.util.Scanner;

// B - I miss you...
// https://atcoder.jp/contests/abc154/tasks/abc154_b
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();
        scanner.close();

        int sLength = S.length();

        StringBuilder sb = new StringBuilder(S.length());
        for (int i = 0; i < sLength; i++) {
            sb.append("x");
        }

        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 22868
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>

int main(void) {
	int n;
	long long a[100001] = { 0 };
	long long b[100001] = { 0 };
	
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
		
	for (int i = 1; i <= n; i++) {
		if (i % 2)b[1] += a[i];
		else b[1] -= a[i];
	}
	
	for (int i = 2; i <= n; i++) {
		b[i] = 2 * a[i - 1] - b[i - 1];
	}
	for (int i = 1; i <= n; i++) printf("%lld ", b[i]);
	return 0;
}



Measured memory_bytes: 2816
#include <bits/stdc++.h>
int main()
{
    int N;
    std::cin >> N;
    using ll = long long;
    std::vector<ll> s(N);
    for(int i = 0; i < N; i++){std::cin >> s[i];}
    ll ans = 0LL;
    for(ll c = 1; c < N; c++){
        ll sum = 0;
        for(ll k = 0; c*k < (ll)N-1LL; k++){
            const ll A = N-1-c*k;
            if(A <=c){break;}
            if(2LL*c*k == N-1 or 2LL*c*k == N-1+c){break;}
            sum += s[c*k] + s[N-1-c*k];
            ans = std::max(ans, sum);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 1152
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Debug = System.Diagnostics.Debug;
using static System.Math;
using System.Runtime.CompilerServices;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    static int k;
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        k = nk[1];
        var a = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();

        var valid = -1;
        var invalid = a.Length;
        while (invalid - valid > 1)
        {
            var mid = (valid + invalid) / 2;
            if (IsValid(a, mid)) valid = mid;
            else invalid = mid;
        }
        Console.WriteLine(invalid);
    }

    static bool IsValid(int[] a, int targetInd)
    {
        bool[] canAchive = new bool[k];
        canAchive[0] = true;
        foreach (var item in a.Where((_, ind) => ind != targetInd))
        {
            for (int i = canAchive.Length - item - 1; i >= 0; i--)
            {
                if (canAchive[i]) canAchive[i + item] = true;
            }
        }
        if (canAchive.Skip(k - a[targetInd]).Any(x => x)) return false;
        return true;
    }
}


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

using namespace std;

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

#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=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=min((a), (b))

const int MOD=1000000007;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

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


Measured memory_bytes: 256
N, K = map(int, input().split())  # N個の数列, K以下の数字で構成される
gcd_sum = [0]*(K+1)
MOD = 10**9+7
# 最大公約数がKになる通りが何パターンあるかを求める
for i in reversed(range(1, K+1)):
    # パターン数にMODを取っても問題ない（結局掛け算しかしないので）
    gcd_sum[i] = pow(K//i, N, MOD)
    cur = 2*i
    while cur <= K:
        gcd_sum[i] -= gcd_sum[cur]
        cur += i
ans = 0
for i in range(1, K+1):
    ans += gcd_sum[i]*i
    ans %= MOD
print(ans)


Measured memory_bytes: 11064
#include <iostream>
#include <cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
#define MAX_B 1001001
#define NIL -1
const int MOD = 1e9+7;
const int INF = 1 << 29;
const ll INFTY=1000000000000000000LL;

int main(){
    int n,a[MAX_N];
    cin>>n;rep(i,n)cin>>a[i];
    ll sum[n+1];
    sum[0]=0;
    rep(i,n){
        sum[i+1]=sum[i]+a[i];
    }
    map<ll,ll>nums;
    rep(i,n+1){
        nums[sum[i]]++;
    }
    ll ans=0;
    for(auto p : nums){
        ll num=p.second;
        ans+=num*(num-1)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 15104
#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 ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,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; }

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

int main(){
  string S;
  cin >> S;
  reverse(ALL(S));

  int p=0;
  while(p<S.size()){
    if(p+5<= S.size() && S.substr(p,5)=="maerd"){
      p+=5;
    }else if(p+7<= S.size() && S.substr(p,7)=="remaerd"){
      p+=7;
    }else if(p+5<= S.size() && S.substr(p,5)=="esare"){
      p+=5;
    }else if(p+6<= S.size() && S.substr(p,6)=="resare"){
      p+=6;
    }else{
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}



Measured memory_bytes: 512
#include "bits/stdc++.h"
#define hhh printf("hhh\n")
#define see(x) (cerr<<(#x)<<'='<<(x)<<endl)
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 3e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;

int vis[4];

int main() {
    string l1, l2, l;
    int N=read();
    cin>>l1>>l2;
    for(int i=0; i<N; ++i) l+=l1[i], l+=l2[i];
    cout<<l<<endl;
}

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

int main() {
    int n;
    cin >> n;
    map<int, int> c;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        c[a]++;
    }
    string ans = "YES";
    for (auto& e : c) {
        if (e.second != 1) ans = "NO";
    }

    cout << ans << endl;
}


Measured memory_bytes: 9600
n, a, b = map(int, input().split())
MOD = 10**9+7


all_c = pow(2, n, MOD)-1
a_c = 1
b_c = 1
for i in range(n-a+1, n+1):
    a_c *= i
    a_c %= MOD
for i in range(1, a+1):
    a_c *= pow(i, MOD-2, MOD)
    a_c %= MOD
for i in range(n-b+1, n+1):
    b_c *= i
    b_c %= MOD
for i in range(1, b+1):
    b_c *= pow(i, MOD-2, MOD)
    b_c %= MOD

ans = (all_c - a_c - b_c) % MOD
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll, ll>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num, ll g, ll mod) {
	if (g == 0)return 1;
	if (g % 2 == 1)return (num * power((num * num) % mod, g / 2, mod)) % mod;
	return power( (num * num) % mod, g / 2, mod);
}

int main(){
	int n;
	cin >> n;
	if (n%10==3) cout << "bon";
	else if (n%10==0 || n%10==1 || n%10==6 || n%10==8) cout << "pon";
	else cout << "hon";
}

Measured memory_bytes: 3540
N=int(input())
a_list=list(map(int,input().split()))
b_list=sorted(a_list)
b_list.append("a")
ans=0
for i in range(N):
    if b_list[i]==b_list[i+1]:
        ans=+1
if ans==0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 25172
#include <stdio.h>
int main (){
  int a,b,c;
  scanf ("%d%d",&a,&b);
  c=(b-b%100)/100;
  if (a==0){
  printf ("%d",b+c);
  }
  else if (a==1){
  printf ("%d",100*(b+c));
  }
  else {
  printf ("%d",10000*(b+c));
  }
return 0;
}

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

int nnn(int N, int M) {
        vector<int> F(N);
        vector<int> S(M);
        int p = 0;
        int r;

        rep(n, N) {
                cin >> F.at(n);
        }
        rep(m, M) {
                cin >> S.at(m);
        }
        for (r = 0; r < M; r++) {
                p += S.at(r);
                if (p >= N-1) break;
//              cout << "p:" << p;
                p += F.at(p);
//              cout << "p2:" << p << endl;
                if (p < 0) p = 0;
                if (p >= N-1) break;
        }
        return r+1;
}

int main() {
        int N, M;
        while (1) {
                cin >> N >> M;
                if(N + M == 0) {
                        break;
                }
                cout << nnn(N, M) << endl;
        }
        return 0;
}


Measured memory_bytes: 3092
// A Dynamic Programming based solution for 0-1 Knapsack problem 
#include<bits/stdc++.h>

using namespace std;
  
// A utility function that returns maximum of two long integers 
long int max(long int a, long int b) { return (a > b)? a : b; } 
  
// Returns the maximum value that can be put in a knapsack of capacity W 
long int knapSack(long int W, long int wt[], long int val[], long int n) 
{ 
   long int i, w; 
   long int K[n+1][W+1]; 
  
   // Build table K[][] in bottom up manner 
   for (i = 0; i <= n; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   return K[n][W]; 
} 
  
int main()
{
	long int n,w,i,j;
	cin>>n>>w;
	long int arr[n+1][w+1],wt[n+1],val[n+1];
	for(i=0;i<n;++i)
	{
		cin>>wt[i]>>val[i];
	}
	cout<<knapSack(w,wt,val,n)<<endl;
	return 0;
}

Measured memory_bytes: 79104
use input::Input;

fn main() {
    let mut input = Input::default();

    let x: i32 = input.parse();
    let n = input.parse();
    let p = (0..n).map(|_| input.parse()).collect::<Vec<_>>();

    let mut ans = 400;
    for i in -200..=200 {
        if p.contains(&i) {
            continue;
        }
        if (x - ans).abs() > (x - i).abs() {
            ans = i;
        }
    }
    println!("{}", ans);
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 2112
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S):
    N = len(S)
    for i in range(0, N, 2):
        if S[i] not in "RUD":
            return False

    for i in range(1, N, 2):
        if S[i] not in "LUD":
            return False

    return True


def main():
    S = input()
    if solve(S):
        print(YES)
    else:
        print(NO)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3956
n = gets.to_i
a = gets.split.map(&:to_i)

h = Hash.new

sum = 0
a.each do |aa|
    h[aa] = 0 unless h.has_key?(aa)
    h[aa] += 1
    sum += aa
end

q = gets.to_i
q.times do
    b, c = gets.split.map(&:to_i)

    if h.has_key?(b) == false
        puts sum
        next
    end

    h[c] = 0 unless h.has_key?(c)

    sum -= b * h[b]
    sum += c * h[b]

    h[c] += h[b]
    h[b] = 0
    puts sum
end

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

int main(){
    int n,m,x; cin >> n >> m >> x;
    int c[n];
    vector<vector<int>> A(n,vector<int>(m));

    for(int i=0; i<n; i++){
        cin >> c[i];
        for(int j=0; j<m; j++) cin >> A[i][j];
    }

    long long int ans = pow(10,18);
    for(int bit=0; bit<(1<<n); bit++){
        long long sum = 0;
        vector<int> scores(m);

        for(int i=0; i<n; i++){
            if(bit & (1<<i)){
                for(int j=0; j<m; j++){
                    scores[j] += A[i][j];
                }
                sum += c[i];
            }
        }

        bool found = true;
        for(int i=0; i<m; i++){
            if(scores[i] < x) found = false;
        }

        if(found){
            ans = min(sum,ans);
        }
    }

    if(ans == pow(10,18)) cout << "-1" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
k = min(n, m)
f = 2
for i in range(k):
    if a[i] < b[i]:
        f = 1
        break
    if a[i] > b[i]:
        f = 0
        break
if f == 2:
    f = 0
    if n<m:
        f = 1
    
print(f)


Measured memory_bytes: 5628
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import deque

    a = input()
    b = input()
    c = input()

    aq = deque(a)
    bq = deque(b)
    cq = deque(c)

    turn = "a"

    while True:
        if turn == "a":
            if not aq:
                return print("A")
            turn = aq.popleft()
        elif turn == "b":
            if not bq:
                return print("B")
            turn = bq.popleft()
        else:
            if not cq:
                return print("C")
            turn = cq.popleft()


if __name__ == '__main__':
    main()


Measured memory_bytes: 65144
#include<iostream>
using namespace std;
int main() {
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	if (x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main(){
  int t;
  cin>>t;
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    s[i]=(s[i]-'A'+t)%26+'A';
  }
  cout<<s;
  return 0;
}

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

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

using ll = long long;
#define INF 1e9
#define mod 1e9+7 
vector<int> A, color(1, 0);
int binary(int key){
  int left = -1;
  int right = (int)color.size();

  while(right - left > 1){
    int mid = left + (right - left) /2;
    if(A[mid] < key){
      right = mid;
    }
    else{
      left = mid;
    }
  }
  return right;
}

int main(){
  int N;
  cin >> N;
  A.resize(N);

  REP(i, N){
    cin >> A[i];
  }
  color[0] = A[0];
  FOR(i, 1, N){
    auto it = lower_bound(color.begin(), color.end(), A[i]);
    if(it == color.end()){
      color.back() = A[i];
    }
    else if(it == color.begin()){
      color.insert(color.begin(), (A[i]));
    }
    else{
      it--;
      *it = A[i];
    }
  }

  cout << color.size() << endl;



  return 0;
}


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

int N;
pair<int, int> m[100010];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for (int i = 0 ; i < N; i++) {
        cin >> m[i].first;
        m[i].second = i;
    }
    sort(m, m + N);
    int ans = 0;
    for (int i = 0; i < N; i += 2) {
        if (m[i].second % 2) {
            ans ++;
        }
    }
    cout << ans << '\n';

}

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

int main(void){
    string t;
    int ans=0;
    cin >> t;
    rep(i,t.size())if(t.at(i)=='?')t.at(i)='D';
    rep(i,t.size())if(t.at(i)=='D')ans++;
    rep(i,t.size()-1)if(t.at(i)=='P' && t.at(i+1)=='D')ans++;
    cout << t;
    return 0;
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	os << "{";
	rep(i, (int)v.size()) {
		if (i)
			os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

	int n, m;
	std::cin >> n >> m;
	vi dp(1 << n, inf);
	dp[0] = 0;
	while (m--) {
		int a, b; std::cin >> a >> b;
		int t = 0;
		while (b--) {
			int c; std::cin >> c;
			c--;
			t |= 1 << c;
		}
		for (int s = 0; s < (1 << n); s++) {
			if (dp[s] >= inf) continue;
			dp[s | t] = min(dp[s | t], dp[s] + a);
		}
	}
	if (dp[(1 << n) - 1] < inf)
		std::cout << dp[(1 << n) - 1] << "\n";
	else
		std::cout << -1 << "\n";
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn bis<P>(ok: i64, ng: i64, p: P) -> i64
    where P: Fn(i64) -> bool {
    let mid = (ok + ng) / 2;
    if (ok - ng).abs() == 1 {
        ok
    } else if p(mid) {
        bis(mid, ng, p)
    } else {
        bis(ok, mid, p)
    }
}

fn main() {
    let Q: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let (A, B): (Vec<i64>, Vec<i64>) = {
        let (mut A, mut B) = (vec![], vec![]);
        for _ in 0..Q {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            A.push(iter.next().unwrap().parse().unwrap());
            B.push(iter.next().unwrap().parse().unwrap());
        }
        (A, B)
    };

    let ans = (0..Q).map(
        |i|
        {
            let a = std::cmp::min(A[i], B[i]);
            let b = std::cmp::max(A[i], B[i]);
            let s = bis(0, b + 1, |k| k * k < a * b);
            let res = if a == b {
                2 * (a - 1)
            } else if s * (s + 1) >= a * b {
                2 * (s - 1)
            } else {
                2 * (s - 1) + 1
            };
            res.to_string()
        }
    )
    .collect::<Vec<_>>()
    .join("\n");

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    std::string s;
    std::cin >> s;
    int ans = 0;
    if (s == "SUN") { ans = 7; }
    else if (s == "MON")
    {
        ans = 6;
    }
    else if (s == "TUE")
    {
        ans = 5;
    }
    else if (s == "WED")
    {
        ans = 4;
    }
    else if (s == "THU")
    {
        ans = 3;
    }
    else if (s == "FRI")
    {
        ans = 2;
    }
    else
    { // sat
        ans = 1;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////




int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    sort(a,a+n);
    ll ans=0;
    rep(i,0,n-1){
        ll c=1;
        while(i<=n-2&&a[i]==a[i+1]){
            c++;
            i++;
        }
        if(a[i]<=c){
            ans+=c-a[i];
        }else{
            ans+=c;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
string s;
int x,c;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]=='S')
			x++;
		else if(x)
			x--,c+=2;
	cout<<s.size()-c;
	return 0;
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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 nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};




int main(){
  ll n,d; cin >> n >> d; ll ans = 0;
  
  rep(i,n){
    ll x,y; cin >> x >> y;
    if(x*x + y*y <= d*d) ans++;
  }
  
  cout << ans << endl;
  
  
  
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair< int , int > P;
typedef tuple<int, int, int> T;



int main(){
    ll a,b,c,k;
    ll ans=0;
    cin>>a>>b>>c>>k;

    if(k<=a){
        ans=k;
    }
    else if(a+b>=k){
        ans=a;
    }
    else{
        ans=a-(k-a-b);
    }
    cout<<ans;
}

Measured memory_bytes: 3632
/*
10 4 8 5
7 2 3 6 1 6 5 4 6 5
*/

#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int n, m, v, p;
int a[100001];
bool check(int pos){
  int less = int(upper_bound(a, a+n, a[pos]+m)-a);
  if(n-less>=p)return false;
  ll vote=-ll(m);
  rep(i, less){
    if(less-i<p-(n-less))vote+=ll(m);
    else vote+=ll(min(a[pos]+m-a[i], m));
  }
  // cout<<pos<<" "<<vote<<" "<<less<<endl;
  return vote>=ll(v-n+less-1)*m;
}
int main(){
  cin>>n>>m>>v>>p;
  rep(i, n)cin>>a[i];
  sort(a, a+n);
  int l=0, r=n;
  while(r-l>1){
    int mid = (r+l)/2;
    if(check(mid)){
      r=mid;
    }else{
      l=mid;
    }
  }
  int ans=n-r;
  if(check(0))ans++;
  cout<<ans<<endl;
  // rep(i, n){
  //   cout<<check(i)<<endl;
  // }
  // system("read -n 1 -s -p \"Press any key to continue...\"");
  return 0;
}


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

long long r[100005],s[100005];
long long n,m;
pair<long long,long long> e[100005];
vector<long long> out;
long long ans;

long long fd(long long x){
    return x==r[x] ? x : r[x]=fd(r[x]);
}

void unite(long long x,long long y){
    long long rx=fd(x);
    long long ry=fd(y);
    if(rx==ry)return ;
    ans=ans-(n-s[rx])*s[rx]-(n-s[ry])*s[ry]+s[rx]*s[ry]+(n-s[rx]-s[ry])*(s[rx]+s[ry]);
    r[ry]=rx;
    s[rx]+=s[ry];
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>m;
    for(long long i=1;i<=n;i++){
        r[i]=i;
        s[i]=1;
    }
    ans=(n-1)*n/2;
    for(long long i=0;i<m;i++){
        cin>>e[i].first>>e[i].second;
    }
    for(long long i=m-1;i>=0;i--){
        out.push_back(ans);
        unite(e[i].first,e[i].second);
    }
    for(long long i=m-1;i>=0;i--){
        cout<<out[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 5364