akhauriyash/Code-Regression huggingface dataset:
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];puts("");}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

int dp[310][310][310];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,m;
	cin>>n>>m;
	vi co(m);
	rep(i,n){
		int a;cin>>a;
		rep(j,a){
			int b;cin>>b;
			co[b-1]++;
		}
	}
	int c=0;
	rep(i,m)if(n==co[i])c++;
	cout<<c<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a;
scanf("%d",&a);
int b[a],c[a];
int d=0;
for(int i=0; i<a; i++){
scanf("%d",&b[i]);
}
for(int i=0; i<a; i++){
scanf("%d",&c[i]);
}
for(int i=0; i<a; i++){
if(b[i]>c[i]){d+=b[i]-c[i];}
}
printf("%d",d);
return 0;}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
int table[365][26];
int main()
{
	int D;
	cin >> D;
	vec(C);
	vec(Las);
	fx(26) {
		vecp(C);
		Las.push_back(0);
	}

	fx(D) {
		fy(26) {
			cin >> table[x][y];
		}
	}
	ll ans = 0;
	fx(D) {
		ll sum = 0;
		ll res = 0, index = 0;
		fy(26) {
			sum += table[x][y];
			fz(26) {
				if (y == z) { continue; }
				sum -= C[z] *(x + 1 - Las[z]);
			}
			if (sum>res) {
				res = sum;
				index = y;
			}
		}
		Las[index] = x + 1;
		ce(index+1)
	}
	
    return 0;
}



Measured memory_bytes: 3648
#include <stdio.h>

int main() {
    int n, min, max=-1e30, tmp;
    scanf("%d", &n);
    scanf("%d", &min);
    
    for(int i=0; i<n-1; i++) {
        scanf("%d", &tmp);
        if(max < tmp-min) max = tmp-min; 
        if(tmp < min) min = tmp;
    }
    
    printf("%d\n", max);
    
    return 0;
}


Measured memory_bytes: 2764
s=input()
for _ in range(int(input())):
    o=input().split()
    a,b=map(int,o[1:3]);b+=1
    c=o[0][2]
    if c=='p':s=s[:a]+o[3]+s[b:]
    elif c=='i':print(s[a:b])
    elif c=='v':s=s[:a]+s[a:b][::-1]+s[b:]


Measured memory_bytes: 5612
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    int A,B,C;cin >> A >> B >> C;
    if((C-B)%2 == 0){
        cout << "Alice" << endl;
    }
    else{
        cout << "Borys" << endl;
    }

}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
template<typename T>
struct BIT{
    vector<T> arr;
   int n;
BIT(int n=0){
   init(n);
}
void init(int nin){
    n=nin;
    arr.resize(n,0);
}
T sum(int i){
    T s=0;
    while(i>=0){
        s+=arr[i];
        i=(i&(i+1))-1;
    }
    return s;
}
T sum_bet(int i,int j){
    return sum(j)-sum(i-1);
}
void plus(int i,T x){
    while(i<n){
        arr[i]+=x;
        i|=i+1;
    }
}
int lb(T x){
 int ret=-1;
 int k=1;
 while(2*k<=n)k<<=1;
 for(;k>0;k>>=1){
     if(ret+k<n&&arr[ret+k]<x){
         x-=arr[ret+k];
         ret+=k;
     }
 }
 return ret+1;
}
};
int main(){
    int q;
    cin>>q;
    vector<ll> t(q),a(q),b(q);
    map<int,int>mp;
    for(int i=0;i<q;i++){
         cin>>t[i];
         if(t[i]==1){
             cin>>a[i]>>b[i];
             mp[a[i]]=0;
         }
    }
    vector<int> tmp;
    int cnt=0;
    for(auto p:mp){
        mp[p.fi]=cnt++;
        tmp.push_back(p.fi);
    }
    BIT<ll> bit_num(cnt),bit_sum(cnt);
    ll bsum=0;
    int s=0;
    for(int i=0;i<q;i++){
        if(t[i]==1){
            s++;
            bsum+=b[i];
            bit_num.plus(mp[a[i]],1);
            bit_sum.plus(mp[a[i]],a[i]);
        }
        else{
           int mid=bit_num.lb((s+1)/2);
           ll s1=bit_num.sum_bet(0,mid);
           ll med=tmp[mid];
           ll ans=s1*med-bit_sum.sum_bet(0,mid)+bit_sum.sum_bet(mid+1,cnt-1)-(s-s1)*med+bsum;
           cout<<med<<" "<<ans<<endl;
        }
    }
}



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

using namespace std;

typedef long long ll;

int l[100005];
int dp[100005];
int n;

void solve() {
  cin >> n;
  int k;
  cin >> k;
  for(int i = 0; i < n; i++) {
    cin >> l[i];
    dp[i+1] = 1e9;
  }
  for(int i = 0; i < n; i++) {
    for(int j = 1; j <= k && i+j < n; j++) {
      dp[i+j] = min(dp[i+j], dp[i] + abs(l[i] - l[i+j]));
    }
  }
  cout << dp[n-1] << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Map.Entry;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int inp_num = sc.nextInt();
        int[] history = new int[inp_num];
        HashMap<Integer,Long> counter = new HashMap<>();
        for(int i = 0;i < inp_num; i++){
            int num = sc.nextInt();
            history[i] = num;
            if(counter.containsKey(num)){
                counter.put(num,counter.get(num)+1);
            }else{
                counter.put(num, 1L);
            }
        }

        long total = 0;
        for(Entry<Integer,Long> key_value :counter.entrySet()){
            total += (key_value.getValue()*(key_value.getValue()-1))/2;
        }
        for(int num: history){
            System.out.println(total-(counter.get(num)-1));
        }
    }
}

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

int main(){
    ll h;
    cin >> h;
    ll kai = 1;
    ll sum = 0;
    ll cnt = 0;
    while(h){
        h = h/2;
        cnt++;
    }
    for(ll i = 0;i < cnt;i++){
        sum += kai;
        kai = kai * 2;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int mu=924844033;
int n,k,f[2][4005][2],cnt,p[2005],a[4005],now,ans;
int main(){
	scanf("%d%d",&n,&k);
	p[0]=1;
	for(int i=1;i<=n;i++) p[i]=p[i-1]*1ll*i%mu;
	for (int i=1;i<=k;i++){
		a[cnt]=-1;
		for(int j=i;j<=n;j+=k) cnt++;
		a[cnt]=-1;
		for(int j=i;j<=n;j+=k) cnt++;
	}
	now=1,f[now][0][0]=1;
	for (int i=1;i<cnt;i++){
		now=now^1;
		memset(f[now],0,sizeof(f[now]));
		for (int j=0;j<=i;j++){
			f[now][j][0]=(f[now][j][0]+f[now^1][j][1]+f[now^1][j][0])%mu;
			if (j && !a[i]) f[now][j][1]=(f[now][j][1]+f[now^1][j-1][0])%mu;
		}
	}
	ans=p[n];
	for (int i=1;i<=n;i++){
		ans=(ans+(f[now][i][0]+f[now][i][1])*(i&1?-1:1)*1ll*p[n-i]%mu+mu)%mu;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 384
#include<cstdio>
#include<vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const static int MOD = 1000000007;
const static int MAX_N = 1000;
bool is_prime[MAX_N+1];

int main(){
	int N;
	scanf("%d", &N);
	vector<ull> prime;
	is_prime[2] = true;
	for (ull i = 3; i <= N; i += 2) is_prime[i] = true;
	for (ull i = 3; i*i <= N; i += 2){
		if(is_prime[i]){
			for (ull j = i*i; j <= N; j += i << 1) is_prime[j] = false;
		}
	}
	for (int i = 2; i <= N; ++i){
		if(is_prime[i]) prime.push_back(i);
	}
	ull answer = 1;
	for (int i = 0; i < prime.size(); ++i){
		int _N = N, count = 1;
		while(_N /= prime[i]){
			count += _N;
		}
		answer = answer*count %MOD;
	}
	printf("%llu\n", answer);
	return 0;
}

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

int r,s,p;

//dpでやったけどうまくいかなかったので解説見て貪欲法で




int main(){
	cin>>n>>k>>r>>s>>p;
	int a=0,b=0;
	int t[k][(n+k-1)/k+1]={};
	int g=(n+k-1)/k+1;
	char h;
	for(int i=0;i<n;i++){
		cin>>h;
		if(h=='r'){
			t[a][b]=3;
		}else if(h=='s'){
			t[a][b]=1;
		}else{
			t[a][b]=2;
		}
		//cout<<a<<" "<<b<<endl;
		if(a>=k-1){
			b++;
			a=0;
		}else{
			a++;
		}
		
	}
	//cout<<"A"<<endl;
	int ans=0;
	for(int i=0;i<k;i++){
		int c=0,e=0;
		while(t[i][c]!=0){
			//cout<<e<<endl;
			if(e!=t[i][c]){
				if(t[i][c]==1){
					ans+=r;
				}else if(t[i][c]==2){
					ans+=s;
				}
				if(t[i][c]==3){
					ans+=p;
				}
				e=t[i][c];
			}else{
				e=0;
			}
			c++;
		}


	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4460
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll arr[120];
ll nCr(ll n, ll r)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));
    C[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1]);

    }
    return C[r];
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll tot=0;
    long double ans=0,sum=0,cnt=0;
    map<ll,int>N,R;
    int n,a,b;
    cin>>n>>a>>b;
    for(int i=0; i<n; i++)
        cin>>arr[i],N[arr[i]]++;
    sort(arr,arr+n);
    for(int i=n-1; i>=0; i--)
    {
        sum+=arr[i];
        R[arr[i]]++;
        cnt++;
        if(cnt>b)
            break;
        if(cnt==a)
        {
            ans=sum/cnt;
        }
        if(cnt>=a)
        {
            long double cur=(sum/cnt);
            if(ans==cur)
                tot+=nCr(N[arr[i]],R[arr[i]]);
        }
    }
    cout<<setprecision(18)<<fixed<<ans<<endl;
    cout<<tot<<endl;
    return 0;
}


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

int main(void) {
  int n;
  cin >> n;
  vector<int> s(n);
  for(auto& tmp:s){
  	cin >> tmp;
  }
 
  int L[n],R[n];
  L[0] = s[0];
  R[n-1] = s[n-1];
  
  for (int i = 1; i < n; i++) {
    L[i] = __gcd(L[i - 1], s[i]);
  }
 
  for (int i = n - 2; i >= 0; i--) {
    R[i] = __gcd(R[i + 1], s[i]);
  }
  int m = max(R[1],L[n-2]);
  for (int i = 1; i < n - 1; i++) {
    m = max(m, __gcd(L[i - 1], R[i + 1]));
  }
  cout << m << endl;
  
  return 0;
}

Measured memory_bytes: 1408
t=int(input())
def jump(n):
    A=list(map(int,input().split()))
    dp=[0]*t
    dp[0]=0
    if n==0:
        return dp[0]
    else:
        if n==1:
            return abs(A[0]-A[1])
        else:
            dp[1]=abs(A[0]-A[1])
            if n>2:
                for i in range(2,n):
                    dp[i]=min([dp[j]+abs(A[i]-A[j]) for j in range(i-2,i)])
        return dp[n-1]

print(jump(t))

Measured memory_bytes: 13924
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
prev = -10
for i in range(n):
    ind = a[i] - 1
    ans += b[ind]
    if prev + 1 == ind:
        ans += c[prev]
    prev = ind
print(ans)

Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x;
    cin>>x;
    for(int i=1;i<=360;i++){
        if(x*i%360==0){
            cout<<i<<endl;
            return 0;
        }
    }   
    return 0;
}

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

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>


using namespace std;



int main() {

	SINT32 N = 0;
	

	cin >> N;
	SINT32 ans[N];

	vector<SINT32> CDATA(N-1);
	vector<SINT32> SDATA(N-1);
	vector<SINT32> FDATA(N-1);
	
	rep(i,0,N-1) {
		cin >> CDATA[i];
		cin >> SDATA[i];
		cin >> FDATA[i];
	}


	rep(i,0,N-1) {
		ans[i] = SDATA[i] + CDATA[i];
		rep(j,i+1,N-1) {
			if (SDATA[j] >= ans[i]) {
				ans[i] = SDATA[j] + CDATA[j];
			} else {
				if ((ans[i] % FDATA[j]) == 0) {
					ans[i] += CDATA[j];
				} else {
					ans[i] += CDATA[j] + FDATA[j]-(ans[i] % FDATA[j]);
				}
			}
		}
	}
	ans[N-1] = 0;

	rep(i,0,N) {
		cout << ans[i] << endl;
	}
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));	//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/
/* 文字列合成
	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;
	ans = stoi(N+M);
*/



/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 256
INF = 99999999999
n, m = map(int,input().split())
V = []
K = []
for _ in range(m):
    value, _ = map(int,input().split())
    V.append(value)
    tmp = [0] * n
    for i in map(int,input().split()):
        tmp[i-1] = 1
    tmp = int("".join(map(str, tmp)), 2)
    K.append(tmp)
dp = {}
import itertools
for flags in itertools.product([0,1], repeat=n):
    tmp = int("".join(map(str, list(flags))), 2)
    dp[tmp] = INF
for i in range(m):
    k = K[i]
    v = V[i]
    if v < dp[k]:
        dp[k] = v
    for dp_k, dp_v in dp.items():
        _k_sum = dp_k | k
        _v_sum = v + dp_v
        if _v_sum < dp[_k_sum]:
            dp[_k_sum] = _v_sum
_max = max(dp.keys())
if dp[_max] == INF:
    print(-1)
else:
    print(dp[_max])

Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

long long int n;
long long int a, b;

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

    for (int i = 1; i < sqrt(n) + 1; ++i) {
        if (n % i != 0) {
            continue;
        }
        a = i;
        b = n / i;
    }

    cout << a + b - 2 << endl;
    return 0;
}


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

using namespace std;

#define N 200005

int n, k, c, maxn[N], f[N], g[N], p[N];

char s[N];

bool is[N];

int main()
{
	scanf("%d%d%d", &n, &k, &c);
	scanf("%s", (s + 1));
	for(int i = 1; i <= n; i++)
		if(s[i] == 'x')
		{
			is[i] = 1;
		}
	for(int i = 1; i <= n; i++)
	{
		maxn[i] = maxn[i - 1];
		f[i] = f[i - 1];
		if(i > maxn[i] && !is[i]) 
		{
			f[i]++;
			maxn[i] = i + c;
		}
	}
	p[n + 1] = n + 1;
	for(int i = n; i >= 1; i--)
	{
		g[i] = g[i + 1];
		p[i] = p[i + 1];
		if(i < p[i] && !is[i]) 
		{
			g[i]++;
			p[i] = i - c;
		}
	}
	for(int i = 1; i <= n; i++)
	{
		// cout << i << ' ' << f[i] << ' ' << g[i] << endl;
		if(!is[i])
		{
			if(f[i - 1] + g[max(maxn[i - 1] + 1, i + 1)] < k)
			{
				printf("%d\n", i);
			}
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 4864
#include<stdio.h>
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i;
	if (n % 2 > 0)
	{
		for (i = 1; i <= m; i++)
			printf("%d %d\n", i, n - i);
	}
	else
	{
		i = 1;
		while (i < n / 2 - i + 1)
		{
			printf("%d %d\n", i, n / 2 - i + 1);
			m--;
			i++;
			if (m == 0)
				break;
		}
		if (m > 0)
		{
			i = n / 2 + 1;
			while (m > 0)
			{
				printf("%d %d\n", i, n - i + n / 2);
				i++;
				m--;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll t;
    cin >> t;
    for (int iyya = 0; iyya < t; iyya++) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        if (a < b) {
            cout << "No" << endl;
            continue;
        }

        ll n = __gcd(b, d);
        if (b > d) {
            cout << "No" << endl;
            continue;
        }
        if (c >= b) {
            cout << "Yes" << endl;
            continue;
        }
        if ((((c+1 + n - (a % n))+n-1) / n * n - (n - (a % n)) >= b)){
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
using Graph = vector<vector<ll>>;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);


int main(){
    string s; cin >> s;
    ll ans = 0;
    if(s[1] == 'R'){
        rep(i, 3) if(s[i] == 'R') ans++;
    }
    else if(s[0] == 'R' || s[2] == 'R') ans = 1;
    cout << ans << endl;
}


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

int main(){
    int N,T,i,min_cost=1001;
    scanf("%d %d",&N,&T);
    int * c = malloc(sizeof(int)*N);
    int * t = malloc(sizeof(int)*N);
    for(i=0;i<N;i++){
        scanf("%d %d",&c[i],&t[i]);
    }

    for(i=0;i<N;i++){
        if(t[i]>T) continue;
        if(c[i]<min_cost) min_cost=c[i];
    }

    if(min_cost<=1000){
        printf("%d",min_cost);
    } else {
        printf("TLE");
    }
    return 0;
}

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

int main(){
	int M,T,P,R;
	while(cin>>M>>T>>P>>R,M){
		pair<int, int> team[60];
		int wa[60][20] = {};
		for(int i = 0;i < T;i++){
			team[i].first = team[i].second = 0;
		}
		for(int r = 0;r < R;r++){
			int m,t,p,j;
			cin>>m>>t>>p>>j;
			t--;
			if(j == 0){
				team[t].first++;
				team[t].second -= m + wa[t][p] * 20;
			}
			else{
				wa[t][p]++;
			}
		}
		int idx[60];
		for(int i = 0;i < 60;i++)idx[i] = i;

		for(int i = 0;i < T;i++){
			for(int j = i+1;j < T;j++){
				if(team[i] == team[j] ? idx[i] < idx[j] : team[i] < team[j]){
					swap(team[i],team[j]);
					swap(idx[i],idx[j]);
				}
			}
		}
		cout<<idx[0]+1;
		for(int i = 1;i < T;i++){
			if(team[i] == team[i-1]){
				cout<<"=";
			}
			else cout<<",";
			cout<<idx[i]+1;
		}
		cout<<endl;
	}

}

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

const int f=-1;

int binarySearch(int key,int A[],int n){
  int l=0;
  int r=n;
  while(l<r){
    int mid=(l+r)/2;
    if(A[mid]==key){
      return mid;
    }
    else if(key<A[mid]){
      r=mid;
    }else{
      l=mid+1;
    }
  }
  return f;
}

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

  int S[100000];
  for(int i=0;i<n;i++){
    cin>>S[i];
  }
  int q;
  cin>>q;
  int T[50000];
  for(int i=0;i<q;i++){
    cin>>T[i];
  }
  int C=0;
  for(int i=0;i<q;i++){
    if(binarySearch(T[i],S,n)!=f){
      C++;
    }
  }
  cout<<C<<endl;
  return 0;
}



Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef long long ll;  //ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<ll, ll> > PS;
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

// g++ -std=c++11 prac.cpp 
int main(){
    ll x,y,z,n,m=0,k,h,w,sum=0,ans=0,Max=-1e9,count=0,Min=1e9+1;
    string s,t,u;
    bool ok=true;
    cin >> n >> k;
    if(k%2==0){
        for(ll i=1; i<=n;i++){
            if(i%k==0){
                ans++;
            }
            if(i%k==k/2){
                sum++;
            }
        }
        ans =  pow(ans,3)+pow(sum,3);
        cout << ans << endl;
        return 0;
    }
    else {
        for(ll i=1; i<=n;i++){
            if(i%k==0){
                ans++;
            }
        }
        ans = pow(ans,3);
        cout << ans << endl;
        return 0;
    }
    return 0;
}

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

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

  vector<int64_t> deskA(N);
  vector<int64_t> deskB(M);
  for(int i=0; i<N; i++){
    cin >> deskA.at(i);
  }
  for(int j=0; j<M; j++){
    cin >> deskB.at(j);
  }

  vector<int64_t> cumsumA(N+1);
  vector<int64_t> cumsumB(M+1);
  for(int i=0; i<N; i++){
    cumsumA.at(i+1)= cumsumA.at(i)+ deskA.at(i);
  }
  for(int j=0; j<M; j++){
    cumsumB.at(j+1)= cumsumB.at(j)+ deskB.at(j);
  }
  
  int ans= 0;
  for(int i=0; i<=N; i++){
    int64_t csA= cumsumA.at(i);
    if(csA > Ttot){ break; }
    else{
      auto itr= upper_bound(cumsumB.begin(), cumsumB.end(), Ttot- csA);
      int cand= i+ distance(cumsumB.begin(), itr)- 1;
      ans= max(ans, cand);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 9592
#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL)
#define REP(i,a,b) for(int i=a,_b=b;i<=_b;i++)
#define rep(i,n) REP(i,0,n-1)
#define FORD(i,b,a) for(int i=b,_a=a;i>=_a;i--)
#define ford(i,n) FORD(i,n-1,0)
#define sqr(x) ((x)*(x))
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define vll vector<ll>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define add push_back
#define len(arr) arr.size()
#define print(x) cout<<(x)<<endl
using namespace std;



int main() {
	SPEED;
	//freopen("in.txt", "r", stdin);
	
	ll n; cin >> n;
	ll sum = 0, tmp = n;
	while(tmp){
		sum += tmp % 10;
		tmp /= 10;
	}
	
	print(n % sum == 0 ? "Yes" : "No");
	return 0;
}


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

int main()
{
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;

    if(0<= x-r && x+r <=W && 0<= y-r && y+r <= H){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    string S;
    cin >> S;
    int res;
    if(S=="SUN") res = 7;
    else if(S=="SAT") res = 1;
    else if(S=="FRI") res = 2;
    else if(S=="THU") res = 3;
    else if(S=="WED") res = 4;
    else if(S=="TUE") res = 5;
    else if(S=="MON") res = 6;
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;


class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i=1;i<n;i++){
      a[sc.nextInt()-1] += 1;
    }
    for(int i=0;i<n;i++){
      System.out.println(a[i]);
    }
  }
}

Measured memory_bytes: 62072
#include <iostream>

#define rep(i, n)  for (int i = 0; i < (n); i++)
#define ll long long;

using namespace std;

int main(void)
{
	int n, m;
		int a[1000];
		int cou=0;
		int sum=0;

		cin >> n >> m;


		rep(i, n)
	{
		cin >> a[i];
		cou += a[i];
	}

		rep(i, n)
		{
			if (cou <= a[i] * 4*m)
			{
				sum++;
			}
		}

		if(sum >= m)
		cout << "Yes"<< endl;
		else
			cout << "No" << endl;
}




Measured memory_bytes: 256
n = int(input())
slist = [list(input())for i in range(n)]
for s in slist:
    s.sort()

glist = slist[0]

for i in range(1,n):
    new = []
    k = 0
    l = 0
    j = 0
    while (j+k < len(glist)) and (j+l < len(slist[i])):
        if glist[j+k] == slist[i][j+l]:
            new.append(glist[j+k])
            j += 1

        elif glist[j+k] < slist[i][j+l]:
            k += 1

        else:
            l += 1

    glist = new[::]
print("".join(glist))


Measured memory_bytes: 3064
//The Number of Inversions
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>

using namespace std;

struct Weight {
    int id = 0;
    int weight = 0;
    bool searched = false;
    bool operator < (const Weight &w) const {
        return weight < w.weight;
    }
};

int main() {
    int n, s = INT_MAX;
    cin >> n;
    Weight W[n];
    for(int i=0; i<n; i++) {
        cin >> W[i].weight;
        W[i].id = i;
        s = min(s, W[i].weight);
    }

    sort(W, W+n);

    int cost = 0;
    for(int i=0; i<n; i++) {
        if(W[i].searched) continue;
        int id = i, c = 0, size = 0;
        while(1) {
            W[id].searched = true;
            c += W[id].weight;
            id = W[id].id;
            size++;
            if(id == i) break;
        }
        if(size != 1)
            cost += c + min((size-2)*W[i].weight, W[i].weight+(size+1)*s);
    }
    cout << cost << endl;
}


Measured memory_bytes: 3104
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
A, B = map(int, input().split())
C, D = prime_factorize(A), prime_factorize(B)
C.append(1)
D.append(1)
C = set(C)
D = set(D)
print(len(C & D))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF (2e9)
#define EPS (1e-7)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main() {
    int i, l, ans;
    vector<int>arr;
    REP(i, 3) {
        cin >> l;
        arr.push_back(l);
    }
    sort(ALL(arr));
    ans = arr[0] * arr[1] / 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
//endfold
#define  N  (200005)
#define MOD (1000000000l + 7l)
#define OO (1050000000)
#define OOL (1100000000000000000)

//global


int main(){
	//fold
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	//endfold
	ll a,b;
	cin >> a >> b;
	if(a <= 0 && b >= 0) return cout << "Zero",0;
	if(a < 0) cout << (((b-a+1)%2==0)?"Positive":"Negative");
	else cout << "Positive";
	return 0;
}

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

using namespace std;
int main(){
  string s;
  cin >> s;

  int n = s.length()-7;
  bool iFlg = false;
  for(int i=0;i<7;i++){
    string ans = s.substr(0, i) + s.substr(i+n);
    if(ans == "keyence"){
      iFlg = true;
      break;
    }
  }

  (iFlg)? ( cout << "YES"): (cout << "NO") << endl;

  return 0;
}

Measured memory_bytes: 256
k,s=map(int,input().split())
ans=0
for x in range(k+1):  #xは 0~kまで  x=0,1,2,.....k
  for y in range(x,k+1): #yはx~k+1まで, 
    z = s-(x+y)  #zはxとyできまる, このときxyzの組み合わせが確定して評価する.
    if z>k or z<y:
      continue
    if x == y and y == z: #x=y=z
      ans+=1
    elif x==y or y == z or z==x:
      ans+=3
    else:
      ans+=6


print(ans)

Measured memory_bytes: 9148
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cmath>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

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

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


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

    int ans = 0;
    int i = 1000;

    int tmp;
    while(i > 1){
        i /= 10;
        tmp = n / i;
        if(tmp == 1){
            ans += i * 9;
        }else if(tmp == 9){
            ans += i * 1;
        }else{
            ans += i * tmp;
        }
        n = n - i * tmp;
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;


int main(){
	int n;
	cin >> n;
	vector<ll> v(3*n);

	for(int i=0;i<3*n;++i){
		cin >> v[i];
	}

	vector<ll> dp_atama(3*n);
	vector<ll> dp_ushiro(3*n);

	priority_queue<ll> pq_atama;
	priority_queue<ll> pq_ushiro;

	ll atama = 0;
	for(int i=0;i<n;++i){
		pq_atama.push(v[i]*-1);
		atama += v[i];
	}
	dp_atama[n-1] = atama;
	for(int i=n;i<2*n;++i){
		dp_atama[i] = dp_atama[i-1];

		dp_atama[i] += v[i];
		pq_atama.push(v[i]*-1);
		ll m = pq_atama.top();pq_atama.pop();
		dp_atama[i] += m;
	}

	ll ushiro = 0;
	for(int i=2*n;i<3*n;++i){
		ushiro += v[i];
		pq_ushiro.push(v[i]);
	}
	
	dp_ushiro[2*n] = ushiro;
	for(int i=2*n-1;i>=n;--i){
		dp_ushiro[i] = dp_ushiro[i+1];

		dp_ushiro[i] += v[i];
		pq_ushiro.push(v[i]);
		ll m = pq_ushiro.top();pq_ushiro.pop();
		dp_ushiro[i] -= m;
	}

	ll res = -1e18;
	for(int i=n;i<=n*2;++i){
		ll tmp = dp_atama[i-1] -dp_ushiro[i];
		//cout << dp_atama[i-1] << " - " << dp_ushiro[i] << " = " << tmp <<endl;
		res = max(res,tmp);
	}


	cout << res <<endl;
	
	return 0;
}


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

int main(){
  ll A,B,C,X,Y;cin>>A>>B>>C>>X>>Y;
  ll ans=1e9;
  rep(c,max(2*X+1,2*Y+1)){
    ll a,b;
    a = max((2*X-c+1)/2,0ll);
    b = max((2*Y-c+1)/2,0ll);
    ans = min(ans,a*A+b*B+c*C);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
 
  int points[N] = {};
  for(int i =0 ;i<Q;i++){
    int answer;
    cin >> answer;
 
    points[answer-1]++; 
  }
  
  for(int i=0;i<N;i++){
    if(K-Q+points[i]>0) cout << "Yes"<< endl;
    else cout << "No"<< endl;
  }
  
}

Measured memory_bytes: 1024
#include <stdio.h>


int main(void){
  int i,cn;
  cn=0;
  char a[3],b[3];
  scanf("%s", a);
  scanf("%s", b);
  for(i=0;i<3;i++){
    if(a[i]==b[i]){
      cn++;
    }
  }
printf("%d\n",cn );

  return 0;
}


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

int main() {
	int N;
  	cin >> N;
  	int sen , hyaku , ju , ichi;
  	sen = N / 1000;
  	N = N % 1000;
  	hyaku = N / 100;
  	N = N % 100;
  	ju = N / 10;
  	N = N % 10;
  	ichi = N;
  	if(sen == hyaku && hyaku == ju){
    	cout << "Yes" << endl;
    }else if(hyaku == ju && ju == ichi){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl; 
    }
}


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

int main(void)
{
    int a, b, c, d, e, f, MAX;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    d = a - b;
    e = b - c;
    f = a - c;

    MAX = abs(d);
    if (abs(e) > MAX)
        MAX = abs(e);

    if (abs(f) > MAX)
        MAX = abs(f);

    printf("%d", abs(d) + abs(e) + abs(f) - MAX);
    return 0;
}


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

int main(){
  int N, A;
  int total = 0;
  cin >> N;

  int j=0;
  for (int i=0; i<N; i++){
    cin >> A;
    if(A!=j+1){
      total++;
      continue;
    }
    j++;
  }

  cout << (j==0?-1:total) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X),B(Y),C(Z);
    rep(i,X) cin >> A[i];
    rep(i,Y) cin >> B[i];
    rep(i,Z) cin >> C[i];

    vector<ll> AB;

    rep(i,X){
        rep(j,Y){
            AB.push_back(A[i] + B[j]);
        }
    }

    sort(AB.begin(),AB.end(),greater<ll>());
    sort(C.begin(),C.end(),greater<ll>());
    vector<ll> ABC;

    rep(i,Z){
        rep(j,min(K,X*Y)){
            ABC.push_back(AB[j] + C[i]);
        }
    }
    sort(ABC.begin(),ABC.end(),greater<ll>());
    rep(i,K) cout << ABC[i] << endl;
    return 0;
}

Measured memory_bytes: 43368
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl '\n'
#define maxl __LONG_LONG_MAX__
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define rep(i, n) for(int i = 0; i < n; i++)
#define rev(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i=1; i < n; i++)
#define rev1(i, n) for(int i=n ; i > 0; i--)
#define FOR(i, a, b) for(int i=a ; i < b; i++)
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define n_ones(x) __builtin_popcountll(x)
#define n_trailzero(x) __builtin_ctzll(x)
#define n_leadingzero(x) __builtin_clz(x)
#define sz(a) (ll)(a.size())

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef stack<ll> stk;
typedef queue<ll> que;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_setll;
typedef tree<char,null_type,less<char>,rb_tree_tag,
tree_order_statistics_node_update> indexed_setc;

ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);} 
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}

ll mod = 1e9 + 7;

void solve()
{
	ll n, k;
	cin>>n>>k;
	ll a[n];
	rep(i, n)
		cin>>a[i];
	vll dp(k+1, 0);
	// dp[i] -> true if fitst player wins if there are i stones remaining
	for(ll i = 0; i <= k; i++)
	{
		rep(j, n)
		{
			if(i - a[j] >= 0 && !dp[i - a[j]])
				dp[i]++;
		}
	}
	if(dp[k])
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
	return;
}

int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
	ll t = 1;
	//cin>>t;
	rep(i, t)
		solve();
	return 0;
	
}

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

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


def solve(a: str, b: str):
    r = math.sqrt(int(a+b))
    if int(r) == r:
        return YES
    else:
        return NO

# Generated by 1.1.6 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()
    a = next(tokens)
    b = next(tokens)
    print(solve(a, b))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m; cin>>n>>m;
	int a[n];
	int tot=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		tot+=a[i];
	}
//	cout<<tot;
	double p=(double)1/4;
	double sz=(double)p*tot;
//	cout<<sz;
	sz=(double)sz/m;
	//cout<<sz;
	int ct=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]>=sz)
		{
			ct++;
		}
	}
	if(ct>=m){cout<<"Yes";}else{cout<<"No";}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <complex>

bool read_data(std::complex<double>* points)
{
	double coords[8];
	for (int i = 0; i < 8; ++i) {
		if (scanf((i==0) ? "%lf" : ",%lf", &coords[i]) != 1) {
			return false;
		}
	}
	for (int i = 0; i < 4; ++i) {
		points[i] = std::complex<double>(coords[i*2], coords[i*2+1]);
	}
	return true;
}


int main()
{
	std::complex<double> points[4];
	while (read_data(points)) {
		double imag[4] = {};
		for (int i = 0; i < 4; ++i) {
			imag[i] = ((points[(i+2)%4]-points[(i+1)%4])/(points[i%4]-points[(i+1)%4])).imag();
		}
		if ((imag[0] > 0 && imag[1] > 0 && imag[2] > 0 && imag[3] > 0) || 
			(imag[0] < 0 && imag[1] < 0 && imag[2] < 0 && imag[3] < 0))
		{
			std::cout << "YES\n";
		} else {
			std::cout << "NO\n";
		}
	}

	return 0;
}

Measured memory_bytes: 1204
from collections import Counter
import itertools
n, k = map(int, input().split())
d = []
sunuke = []
for i in range(k):
    d.append(int(input()))
    sunuke.append(list(map(int, input().split())))

new = list(itertools.chain.from_iterable(sunuke))

c = Counter(new)

print(n - len(c))


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

template <typename T> struct BinaryIndexedTree
{
	vector<T> data;

	BinaryIndexedTree(int sz)
	{
		data.assign(++sz, 0);
	}

	T sum(int k)
	{
		T ret = 0;
		for (++k; k > 0; k -= k & -k)
			ret += data[k];
		return (ret);
	}

	void add(int k, T x)
	{
		for (++k; k < data.size(); k += k & -k)
			data[k] += x;
	}
};

int main()
{
	int n, q;
	cin >> n >> q;
	vector<pair<int,int>> vp(q),in(n),pnt;
	for(int i = 0;i<n;i++)
	{
		cin >> in[i].first;
		in[i].second=i;
	}
	sort(in.begin(),in.end());
	for(int i = 0;i<n-1;i++)
	{
		if(in[i].first==in[i+1].first)
		{
			pnt.emplace_back(in[i].second,in[i+1].second);
		}
	}
	sort(pnt.begin(),pnt.end(),[&](auto a,auto b){return a.first<b.first;});
	//for(auto i:pnt)cout<<i.first<<' '<<i.second<<endl;
	for (int i = 0; i < q; i++)
		cin >> vp[i].first >> vp[i].second,vp[i].first--,vp[i].second--;
	auto oder = vp;
	map<pair<int, int>, int> ans;
	sort(vp.begin(),vp.end(),[&](auto a,auto b){return a.first<b.first;});
	BinaryIndexedTree<int> BIT(533333);
	while(vp.size())
	{
		
		
		if((!pnt.empty())&&vp.back().first<=pnt.back().first)
		{
			BIT.add(pnt.back().second,1);
			pnt.pop_back();
		}
		else
		{
			auto now = vp.back();
			ans[now] =1+now.second-now.first
				-BIT.sum(now.second);
			vp.pop_back();
		}
	}
	//出力
	for(int i = 0;i<q;i++)cout<<ans[oder[i]]<<endl;
}


Measured memory_bytes: 51996
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int x =0,a=0;
  for(int i =0;i <8;i++){
    a= pow(10,i);
    x+= (N/a)%10;
  }
  if(N%x == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 512