akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 60);

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<ll> dp(2, -INF);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    vector<ll> ndp(2, -INF);
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        int d = (j ^ k ? -a[i] : a[i]);
        ndp[k] = max(ndp[k], dp[j] + d);
      }
    }
    dp = move(ndp);
  }
  cout << dp[0] << endl;
  return 0;
} 

Measured memory_bytes: 3784
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)


template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }
template<class T> inline ll gcd(T a, T b){ if (a % b == 0){ return b; } else{ return gcd(b, a%b); } }
template<class T> inline ll lcm(T a, T b){ return a * b / gcd(a, b); }
template<class T> inline ll fact(T a){ if (a <= 1){ return 1; } else{ return a * fact(a - 1); } }
template<class T> inline ll comb(T a, T b){ return a == 0 ? 0 : fact(a) / fact(b) / fact(a - b); }

int main(){
    ll N;
    vector<string> s;
    map<string, ll> cnt;
    cin >> N;
    rep(i, 0, N){
        string temp;
        cin >> temp;
        sort(begin(temp), end(temp));
        cnt[temp]++;
    }
    ll ans = 0;
    for (pair<string, ll> ele : cnt){
        if (ele.second >= 2){
            ans += (ele.second * (ele.second - 1) / 2);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}

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

int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int n;
int h[M],a[M];

int ans=0;

int fenwick[M];
int update(int p, int val){
    for(int i=p; i<=M; i+=((i)&(-i))) fenwick[i]=max(fenwick[i],val);
}
int sum(int p){
    int res=0;
    for(int i=p; i; i-=((i)&(-i))) res=max(res,fenwick[i]);
    return res;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    rep(i,1,n+1) cin >> h[i];
    rep(i,1,n+1) cin >> a[i];
    for(int i=1; i<=n; i++){
        int x=sum(h[i]-1);
        trace(x);
        ans=max(ans,x+a[i]);
        update(h[i],x+a[i]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 5120
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class BDigits {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n,k,d=0;
        in >> n >> k;
        while(n!=0){
            n/=k;
            d++;
        }
        out << d << endl;
	}
};


int main() {
	BDigits solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    int n;
    n = sc.nextInt();
    int d[]=new int[n];
    for(int i=0;i<n;i++)
      d[i]=sc.nextInt();
   	int ans=0;
    for(int i=0;i<n-1;i++)
    {
      for(int j=i+1;j<n;j++)
        ans+=(d[i]*d[j]);
    }
    System.out.print(ans);
  }
}

Measured memory_bytes: 24148
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int ans = a * (a - 1) / 2 + b * (b - 1) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#リストの中身を全て足したり、書けたりしてくれる関数
#gcdは最大公約数を求める関数。こんな便利なものがあったのか！
from functools import reduce
from fractions import gcd


N,X = map(int, input().split())
x = list(map(int, input().split()))

"""
出発地点Xは決まっている
一番近いところと、一番遠いところを考えたとき、最大公約数を求めればいいのでは？
これが全部の公約数になってないといけないかな？

まず、一番近いところを決める
この約数を求める
一番大きいやつに決定する
"""

#abs()は絶対値を返す関数

x.append(X)

sa = [abs(x[i+1]-x[i]) for i in range(N)]
#それぞれの値の差（距離）を取ってあるので、全ての数値の最大公約数を求める
answer = reduce(gcd, sa)

print(answer)

Measured memory_bytes: 16204
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
 
int main(){
 int N,A;
 cin >> N >> A;
 int num=0;
 while(1){
   
   N-=A;
   num++;
   if(N<=0)break;
   
 }
  cout <<  num << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,tot=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		tot+=a[i];
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		ans=ans+a[i]-1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lli=long long int;
using vi=vector<int>;  using vs=vector<string>; using gi=greater<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define soao(c) sort((c).begin(),(c).end()) //昇順
#define sodo(c) sort((c).begin(),(c).end(),gi()) //降順
#define rev(c) reverse((c).begin(), (c).end())


int main(){
    int n,k; cin>>n>>k;
    set<int> S;
    
    rep(i,k){
        int d; cin>>d;
        vi a(d); 
        rep(i,d){
            cin>>a.at(i);
            S.insert(a.at(i));
        }
    }

    cout<<n-S.size()<<endl;
}


Measured memory_bytes: 3640
import sys
N, Y = map(int, input().split())
Y = Y // 1000

for i in range(N+1):
  for j in range(N-i+1):
    k = N - i - j
    money = 10 * i + 5 * j + k
    if money == Y:
      print(i,j,k)
      sys.exit()

print(-1,-1,-1)

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

int main() {
	char s;
	cin >> s;

	if (s == 'a' || s == 'i' || s == 'u' || s == 'e' || s == 'o') cout << "vowel" << endl;
	else cout << "consonant" << endl;

	return 0;
}

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

//std::vector<int> rgb[3];
int rgb[4040][3]; // 1-indexed

int func(char c1, char c2){
    int t = 3;
    if(c1 == 'B' || c2 == 'B') t -= 2;
    if(c1 == 'G' || c2 == 'G') t--;
    return t;
}

int main(){
    int n;
    std::string s;
    std::cin >> n >> s;
    s = " "+s; // 1-indexed
    for(int i = 1; i <= n; i++){
        char c = s[i];
        if(c == 'R'){
//            rgb[0].push_back(i);
            rgb[i][0] = rgb[i-1][0]+1;
            rgb[i][1] = rgb[i-1][1];
            rgb[i][2] = rgb[i-1][2];
        }else if(c == 'G'){
//            rgb[1].push_back(i);
            rgb[i][0] = rgb[i-1][0];
            rgb[i][1] = rgb[i-1][1]+1;
            rgb[i][2] = rgb[i-1][2];
        }else{
//            rgb[2].push_back(i);
            rgb[i][0] = rgb[i-1][0];
            rgb[i][1] = rgb[i-1][1];
            rgb[i][2] = rgb[i-1][2]+1;
        }
    }
    long long ans = 0;
    for(int i = 1; i <= n-2; i++){
        for(int j = i+1; j <= n-1; j++){
            if(s[i] != s[j]){
                int index = func(s[i], s[j]);
                bool flag = false;
                if(2*j-i <= n){
                    flag = rgb[2*j-i][index] != rgb[2*j-i-1][index];
                }
                ans += (rgb[n][index] - rgb[j][index]);
                if(flag) ans--;
            }
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC120_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            int a = int.Parse(strs[0]);
            int b = int.Parse(strs[1]);
            int k = int.Parse(strs[2]);

            int divAnsIndex = 0;

            int div = 100;

            if (a < b)
            {
                div = a;
            }
            else
            {
                div = b;
            }

            int i = div;
            for (; i >= 1; --i)
            {
                if (a % i == 0 && b % i == 0)
                {
                    divAnsIndex++;

                    if (divAnsIndex == k) break;
                }
            }

            Console.WriteLine("{0}", i);
        }
    }
}


Measured memory_bytes: 13268
var
	n,m,i,a,b:Longint;
	used:array[1..8]of Boolean;
	c:array[1..8]of Longint;
	G:array[1..8,1..8]of Longint;
function f(u,cnt:Longint):Longint;
var i,ret:Longint;
begin
	if cnt=n then begin
		f:=1;
		exit;
	end;
	ret:=0;
	for i:=1 to c[u] do begin
		if not used[G[u,i]]then begin
			used[G[u,i]]:=True;
			inc(ret,f(G[u,i],cnt+1));
			used[G[u,i]]:=False;
		end;
	end;
	f:=ret;
end;
begin
	read(n,m);
	for i:=1 to m do begin
		read(a,b);
		if b<>1 then begin
			inc(c[a]);
			G[a,c[a]]:=b;
		end;
		if a<>1 then begin
			inc(c[b]);
			G[b,c[b]]:=a;
		end;
	end;
	used[1]:=True;
	writeln(f(1,1));
end.

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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef long double ld;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};





int main(){

    bool flag=false;
    ll ans=0,sum=0;

    string s;
    cin>>s;


    cout<<s.substr(0,3)<<endl;
    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REPR(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define FOR(i, x, n) for (int i = x; i < (int)(n); ++i)
#define ALL(n) begin(n), end(n)
#define ll long long
#define INF 1e9

int ansfunc(int x, int y, int z) {
    return (x + y + z) * (x + y + z) - (x * y + y * z + z * x);
}

int main() {
    int N;
    cin >> N;
    vector<int> ans(N);
    REP(n, N) {
        FOR(i, 1, 100) {
            // if (ansfunc(i, 1, 1) > n) continue;
            FOR(j, 1, i + 1) {
                // if (ansfunc(i, j, 1) > n) continue;
                FOR(k, 1, j + 1) {
                    // if (ansfunc(i, j, k) > n) continue;
                    if (ansfunc(i, j, k) == n + 1) {
                        if (i == j && j == k && k == i)
                            ans[n]++;
                        else if (i != j && j != k && k != i)
                            ans[n] += 6;
                        else
                            ans[n] += 3;
                    }
                }
            }
        }
    }
    REP(i, N) cout << ans[i] << endl;
    return 0;
}

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

using namespace std;

int main(){
    int N; cin >> N;
    for(int i = 0; i*4 <= N; ++i){
        for(int j = 0; j*7 <= N; ++j){
            if(i*4+j*7 == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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

int main() {
  int n;
  cin >> n;
  int num_min = 0;
  long min_num = 10e9;
  long sum=0;
  for (int i = 0; i < n; i++) {
    int aa;
    cin >> aa;
    if (aa<0) {
      num_min++;
    }
    int aaa  = abs(aa);
    if (min_num > aaa) {
      min_num = aaa;
    }
    sum += aaa;
  }
  if (num_min%2==0) {
    cout << sum << endl;
  } else {
    cout << sum - min_num*2 << endl;
  }
  return 0;
}

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

class Point{public:double x,y;};
class Vector{public:double x,y;};

int main(void){
	while( true ){
		Point a, b, c, d;
		Vector vAB, vCD;
		double production;

		cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> d.x >> d.y;
		if(cin.eof())break;
		
		vAB.x = a.x - b.x;
		vAB.y = a.y - b.y;
		vCD.x = c.x - d.x;
		vCD.y = c.y - d.y;
		production = vAB.x * vCD.x + vAB.y * vCD.y;
		
		if( production == 0 ) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

int main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans=(a*c);
	ans=max(ans,a*d);
	ans=max(ans,b*d);
	ans=max(ans,b*c);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int a,b,c,d;
 	cin>>a>>b>>c;
 	d=a+b+c;
 	if(d>=22)
 		cout<<"bust"<<endl;
 	else
 		cout<<"win"<<endl;
 	return 0;
}
 	
 					

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> P;
constexpr auto INF = INT_MAX/2;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	string s;
	cin >> s;

	deque<char> dq;
	rep(i, s.size())dq.push_back(s[i]);

	int q;
	cin >> q;

	int cnt = 0;
	rep(i, q) {
		int t;
		cin >> t;
		if (t == 1)cnt++;
		else {
			int f;
			char c;
			cin >> f >> c;
			if ((f == 1) ^ (cnt % 2))dq.push_front(c);
			else dq.push_back(c);
		}
	}

	int n = dq.size();
	if (cnt % 2)rep(i, n) { cout << dq.back();dq.pop_back(); }
	else rep(i, n) { cout << dq.front();dq.pop_front(); }
	cout << endl;

}

Measured memory_bytes: 896
use proconio::marker::*;
use proconio::*;

type Link = Option<Box<Node>>;

const F: usize = 26;

#[derive(Default)]
struct Node {
    cnt: [u32; F],
    next: [Link; F],
}

impl Node {
    fn insert(&mut self, s: &[u8]) -> (usize, usize) {
        if s.is_empty() {
            return (0, 0);
        }
        let k = (s[0] - b'a') as usize;
        let (mut bit, mut ans) = self.next[k]
            .get_or_insert_with(|| Box::new(Node::default()))
            .insert(&s[1..]);
        if s.len() == 1 {
            ans += self.cnt[k] as usize;
        }
        bit |= 1 << k;
        for (i, c) in self.cnt.iter_mut().enumerate() {
            *c += (bit >> i & 1) as u32;
        }
        (bit, ans)
    }
}

fn run() {
    input! {
        n: usize,
        mut s: [Bytes; n],
    }
    let mut root = Box::new(Node::default());
    s.sort_by_key(|s| s.len());
    let mut ans = 0;
    for s in s.iter_mut().rev() {
        s.reverse();
        ans += root.insert(s).1;
    }
    println!("{}", ans);
}

fn main() {
    let stack_size = 1 << 30;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| run()).unwrap().join().unwrap();
}


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

signed main() 
{
	int n , x , count = 1; cin >> n;
	for(int i = 0 ; i < n && cin >> x; ++i) if(x == count) count++;
	cout << ((count==1)?-1:n-count+1) << endl;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    ll s,c;
    while(sf("%lld %lld",&s,&c)==2)
    {
        if(s>=c)pf("%lld\n",c/2);
        else
        {
            if(2*s<=c)
            {
                ll ans=s;
                c-=(2*s);
                ans+=(c/4);
                pf("%lld\n",ans);
            }
            else pf("%lld\n",c/2);
        }
    }
    return 0;
}
 









 




























Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int NS = 1e5 + 100;
ll N, m, a[NS];
typedef pair <ll, ll> cn;

void bp() {
}

int main() {
	ll sum = 0;
	std::vector<cn> z;
	cin >> N >> m;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	sort(a, a + N);
	for (int i = 0; i < m; ++i) {
		cn a;
		cin >> a.first >> a.second;
		z.push_back(a);
	}
	std::sort(z.begin(), z.end(), [](const cn &p1, const cn &p2) {
			return p1.second < p2.second;
			});
	int i = 0;
	for (; i < N; ++i) {
		cn t = z.back();
		if (a[i] >= t.second) { break; }
		sum += t.second;
		if (t.first == 1) {
			z.pop_back();
			if (z.size() == 0) {
				++i;
				break;
			}
			continue;
		}
		z.pop_back();
		t.first -= 1;
		z.push_back(t);
	}
	for (;i < N; ++i) {
		sum += a[i];
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll K, N;
    cin >> K >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll ans = 1e18;
    rep1(i, N - 1){
        ans = min(ans, K - abs(A[i] - A[i - 1]));
    }
    ans = min(ans, K - abs(A[0] + K - A[N-1]));

    print(ans);

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int X;
	cin >> X;
	if(X<1200){
		cout << "ABC" << endl;
	}
	else{
		cout << "ARC" << endl;
	}
}

Measured memory_bytes: 256
import sys
def main():
    n,k = map(int, input().split())
    a = [[0]*40 for _ in range(n)]
    a_ = []
    for i,x in enumerate(map(int, input().split())):
      j=0
      while x>0:
        if x%2==1: a[i][j]=1
        x = x//2
        j += 1
    ans=0
    x = 0
    for i in range(39,-1,-1):
      b = 0
      for y in a:
        b+=y[i]
      if b<=n//2 and x+2**i<=k:
        ans += (n-b)*2**i
        x+=2**i
      else:
        ans += b*2**i
          
    print(ans)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 51996
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl = vector<ll>; using vvl = vector<vl>;
using vc = vector<char>; using vvc = vector<vc>;
using vp = vector<pair<int,int>>;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main(){
  string s,t;cin >> s >> t;
  int ANS = t.size();
  rep(i,s.size()) {
    int ans = 0;
    rep(j,t.size()) {
      if(i+j >= s.size()) goto skip;
      if(s[i+j] != t[j]) ans++;
    }
    ANS = min(ANS,ans);
  }
  skip:
  cout << ANS << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
struct ttt{
	long long a, b;
}t[100005];
inline bool cmp(ttt x, ttt y){
	return x.a < y.a;
}
int main(){
	long long n, m, ans = 0, i;
	scanf("%d %d", &n, &m);
	for(i = 1 ; i <= n ; ++i)
		scanf("%lld %lld", &t[i].a, &t[i].b);
	sort(t + 1, t + 1 + n, cmp);
	for(i = 1 ; i <= n ; ++i){
		if(m >= t[i].b) ans += t[i].b * t[i].a;
		else ans += m * t[i].a;
		m -= m >= t[i].b ? t[i].b : m;
		if(!m) break;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
//
//AtCoder Beginner Contest 087
//B
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int A,B,C,X;
    cin >> A >> B >> C >> X;

    int ans=0;
    REP(a, A+1){
        REP(b, B+1){
            REP(c, C+1){
                if (a*500 + b*100 + c*50 == X) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<cctype>
using namespace std;

int main(){
	string target,inp;
	int count=0;
	cin >> target;
	for(int i=0;i<target.size();i++)	target.at(i)=tolower(target.at(i));
	while(1){
		cin >> inp;
		if(inp=="END_OF_TEXT") break;
		for(int i=0;i<inp.size();i++)	inp.at(i)=tolower(inp.at(i));
		if(target==inp)		count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1192
#include<stdio.h>


int main(void)
{
    int n,a[100]={-1},i,s=0,max,j;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        max=0;
        for(j=0;j<n;j++){
            if(a[j]>a[max]) max=j;
        }
        if(i%2==0) s+=a[max];
        else s-=a[max];
        a[max]=0;
    }
    printf("%d\n",s);




    return 0;
}


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

#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)
#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL9_MOD = 1000000009;
static constexpr ll LL7_MOD = 1000000007;
static constexpr ll INF = 1LL << 60;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

static map<type_index, const char *const> scanType = {
  { typeid(int), "%d" }, { typeid(ll), "%lld" }, { typeid(double), "%lf" }, { typeid(char), "%c" }};

template <class T> static void scan(vector<T>& v);
static void scan(vector<string>& v, bool isWord = true);
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; }
template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val){ std::fill((T*)arr, (T*)(arr + N), val); }

ll dp[3001][3001];

int main(int argc, char *argv[]) {
  //INFILE();

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

  int sl = s.size(), tl = t.size();

  REP(i, 1, sl + 1) {
    REP(j, 1, tl + 1) {
      chmax(dp[i][j], dp[i][j - 1]);
      chmax(dp[i][j], dp[i - 1][j]);
      chmax(dp[i][j], dp[i - 1][j - 1] + ll(s[i - 1] == t[j - 1]));
    }
  }

  string result;
  while (dp[sl][tl] != 0) {
    if (s[sl - 1] == t[tl - 1] && dp[sl - 1][tl - 1] == dp[sl][tl] - 1) {
      result.push_back(s[sl - 1]);
      sl--;
      tl--;
      continue;
    }

    dp[sl - 1][tl] == dp[sl][tl] ? sl-- : tl--;
  }

  reverse(ALL(result));
  cout << result << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}



Measured memory_bytes: 70656
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;
int MOD = 1000000007;

signed main(){
    int n,a,b;
    cin >> n >> a >> b;
    
    int x =0;
    int y =0;
    int z =0;

    rep(i,n){
        int p;
        cin >> p;
        if(p <= a)x++;
        else if(p >= b+1)z++;
        else y++;
        
    }
    cout << min({x,y,z}) << endl;

    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 
// rm -r -f test;oj dl http://arc074.contest.atcoder.jp/tasks/arc074_b

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <stdio.h>

#define BUF_SIZE 120000

using namespace std;

int main(){

	int n;
	scanf("%d",&n);

	int S[n];

	for(int i = 0; i < n; i++){
		scanf("%d",&S[i]);
	}

	int q;
	scanf("%d",&q);

	int count = 0;
	int tmp;

	for(int i = 0; i < q; i++){
		scanf("%d",&tmp);
		for(int k = 0; k < n; k++){
			if(tmp == S[k]){
				count++;
				break;
			}
		}
	}

	printf("%d\n",count);

}



Measured memory_bytes: 3232
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>


using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 9 & b <= 9) {
		cout << a * b << endl;
	}
	else {
		cout << -1<< endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    ll n;
    cin >> n;
    ll h[n];
    rep(i,n) cin >> h[i];
    ll ans=1;
    ll max=h[0];
    for(ll i=1;i<n;i++){
        if(max <= h[i]){
            ans++;
            max=h[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ZYCSwing
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            Set<Character> set = new HashSet<>();

            int n = in.nextInt();
            String ch;
            for (int i = 0; i < n; ++i) {
                ch = in.next();
                set.add(ch.charAt(0));
            }

            out.println(set.size() == 3 ? "Three" : "Four");
        }

    }
}



Measured memory_bytes: 21844
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
	    int length = scanner.nextInt();
		int A[] = new int[length];
        for(int i = 0; i < length; i++)
        	A[i] = scanner.nextInt();
        
        int key = 1000;
		int mini = 0;
		int count = 0;
		for (int i = 0; i < length; i++) {
			mini = i;
			for (int j = i; j < length; j++) {
				if (A[j] < A[mini])
					mini = j;
			}
			if (i != mini){
			key = A[mini];
			A[mini] = A[i];
			A[i] = key;
			count++;
			}
		}
		out_put(A);
		System.out.println(count);	
	}
	
	private static void out_put(int A[]){
        System.out.printf("%d", A[0]);
        for(int i = 1; i < A.length; i++){
            System.out.printf(" %d", A[i]);
        }
        System.out.printf("\n");
    }
}


Measured memory_bytes: 26628
package main

import (
	"bufio"
	"fmt"
	"os"
)

var bw = bufio.NewWriter(os.Stdout)

func isOdd(n int) bool { return n%2 != 0 }

func printf(format string, a ...interface{}) { fmt.Fprintf(bw, format, a...) }

func main() {
	defer bw.Flush()

	var s string
	fmt.Scan(&s)
	n := len(s)

	splited := make([]string, 0, n)
	t := s + "R"
	prev := 0
	for i := 0; i <= len(t)-1; i++ {
		if t[i] == 'L' && t[i+1] == 'R' {
			splited = append(splited, t[prev:i+1])
			i++
			prev = i
		}
	}
	// fmt.Println(splited)

	ans := make([]int, 0, n)
	// fmt.Println(ans)
	for _, sp := range splited {
		// fmt.Println(sp)
		leftIdx, rightIdx := -1, -1
		for i, v := range sp {
			if v == 'L' {
				leftIdx, rightIdx = i-1, i
				break
			}
		}
		// fmt.Println(leftIdx, rightIdx)

		left, right := 1, 1
		x := leftIdx - 0
		left += x / 2
		right += x / 2
		if isOdd(x) {
			right++
		}
		y := (len(sp) - 1) - rightIdx
		left += y / 2
		right += y / 2
		if isOdd(y) {
			left++
		}

		tmp := make([]int, 0, len(sp))
		tmp = append(tmp, make([]int, x)...)
		tmp = append(tmp, left)
		tmp = append(tmp, right)
		tmp = append(tmp, make([]int, y)...)

		// fmt.Println(tmp)
		ans = append(ans, tmp...)
	}
	// fmt.Println(ans)

	for i := 0; i <= len(ans)-2; i++ {
		printf("%v ", ans[i])
	}
	printf("%v\n", ans[len(ans)-1])
}


Measured memory_bytes: 4224
s = input()
s = s[::-1]
s += '0'
ans = 0
dp = [0, 10**9]
for c in s:
    i = int(c)
    a = dp[0]+i
    if i<9 and a>dp[1]+i+1:
        a = dp[1]+i+1
    b = dp[1]+9-i
    if i>0 and b>dp[0]+10-i:
        b = dp[0]+10-i
    dp = [a, b]
print(dp[0])

Measured memory_bytes: 5492
#include<bits/stdc++.h>
    #include <ext/pb_ds/tree_policy.hpp> 
    #include <functional> // for less 
    using namespace __gnu_pbds; 
    using namespace std;
    //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;    
    #define ll            long long
    #define pb            push_back
    #define ppb           pop_back
    #define si            set <ll>
    #define endl          '\n'
    #define fr            first
    #define sc            second
    #define mii           map<ll,ll>
    #define msi           map<string,ll>
    #define mis           map<ll,string>
    #define rep(i,a,b)    for(ll  i=a;i<b;i++)
    #define all(v)        v.begin(),v.end()
    #define sort(v)       sort(all(v))
    #define pii           pair<ll ,ll >
    #define vi            vector<ll >
    #define vii           vector<pair<ll,ll>>
    #define vs            vector<string>
    #define sz(x)         (ll)x.size()
    #define M             1000000007
    #define bs            binary_search
    #define rev(a)        reverse(all(a));
    #define sp(n)         setprecision(n)
    #define spl           " "
    #define arr(a,n)      rep(i,0,n) cin>>a[i]
    #define mod           998244353
    #define print_vector(a)  for(auto t:a) cout<<t<<" ";cout<<endl;
    #define print_arr(a,n)   rep(i,0,n) cout<<a[i]<<" "; cout<<endl;        
    #define show(a,n)     for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
    #define debug(x)      cout << #x << " is " << x << endl;
    #define time          cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    #define INF           1ll<<31
    #define hi            cout<<"hi"<<endl;
    const ll maxn=int(3e5)+500;
    const ll maxa=(1<<20)+3;
    ll bpow(ll a, ll b, ll mm = M)
    {
        ll res = 1;
     
        while(b)
        {
            if(b & 1)
                res = (res * a) % mm;
            a = (a * a) % mm;
     
            b >>= 1;
        }
     
        return res;
    }
    
    void solve()
    {
     ll n;
     cin>>n;
     map<string,ll> mp;
     rep(i,0,n) {string s; cin>>s; mp[s]++;}
     cout<<sz(mp)<<endl;
    } 
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t=1;
        //cin>>t;
        while(t--) solve();
    }

  

Measured memory_bytes: 19252
A,B = map(int,input().rstrip().split())

n = m = 1
flg = 0
an = A
bm = B

while flg ==0:
  an = A * n
  bm = B* m
  if an == bm :
    flg = 1
    res = an
  elif an < bm:
    n += 1
  else :
    m += 1 
  
print(an)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);


        StringBuilder s = new StringBuilder();

        while(inp.hasNext()){
            s.append(inp.nextLine());
        }

        count(s.toString());
    }

    public static void count(String s) {
        for (int alpha = 0; alpha < 26; alpha++) {
            String letter;
            int counter = 0;

            switch (alpha) {
                case 0: letter = "a";
                        break;
                case 1: letter = "b";
                        break;
                case 2: letter = "c";
                        break;
                case 3: letter = "d";
                    break;
                case 4: letter = "e";
                    break;
                case 5: letter = "f";
                    break;
                case 6: letter = "g";
                    break;
                case 7: letter = "h";
                    break;
                case 8: letter = "i";
                    break;
                case 9: letter = "j";
                    break;
                case 10: letter = "k";
                    break;
                case 11: letter = "l";
                    break;
                case 12: letter = "m";
                    break;
                case 13: letter = "n";
                    break;
                case 14: letter = "o";
                    break;
                case 15: letter = "p";
                    break;
                case 16: letter = "q";
                    break;
                case 17: letter = "r";
                    break;
                case 18: letter = "s";
                    break;
                case 19: letter = "t";
                    break;
                case 20: letter = "u";
                    break;
                case 21: letter = "v";
                    break;
                case 22: letter = "w";
                    break;
                case 23: letter = "x";
                    break;
                case 24: letter = "y";
                    break;
                default: letter = "z";
                    break;
            }
            String letterUp = letter.toUpperCase();

            for (int i = 0; i < s.length(); i++) {
                if ((""+s.charAt(i)).equals(letter) || (""+s.charAt(i)).equals(letterUp)) {
                    counter++;
                }
            }

            System.out.println(letter + " : " + counter);
        }
    }
}



Measured memory_bytes: 34096
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

const int MAX_N = 10000010;
bool isPrime[MAX_N];
void eratosthenes(int n){
    for(int i=0; i<=n; i++) isPrime[i] = true;
    isPrime[0] = false, isPrime[1] = false;

    for(int i=2; i*i<=n; i++){
        if(isPrime[i]){
            for(int j=2; i*j<=n; j++){
                isPrime[i*j] = false;
            }
        }
    }
}

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

    eratosthenes(10000005);

    vector<int> ans(10000005);
    ans[13] = 13;
    for(int i=14; i<=10000000; i++){
        ans[i] = ans[i-1];
        if(isPrime[i] && isPrime[i-2] && isPrime[i-6] && isPrime[i-8]) ans[i] = i;
    }

    while(1){
        int n; cin>>n;
        if(n == 0) return 0;

        cout << ans[n] << endl;
    }

    return 0;
}


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

using namespace std;

int main(){
    string s;
    int n;
    cin >> n >> s;
    for (int i = 0; i < s.size(); i++)
    {
        int ans = (int)(s[i]-'A' + n)%(26)+'A';
        cout << (char)ans;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  vector<int> C(M);
  rep(i, M) {
    cin >> A[i] >> B[i];
    int cbyte = 0;
    rep(j, B[i]) {
      int c;
      cin >> c;
      c--;
      cbyte += (1<<c);
    }
    C[i] = cbyte;
  }
  vector<vector<int> > dp(1<<N, vector<int>(M+1, inf));
  rep(i, M+1) dp[0][i] = 0;
  REP(i, 1, M+1) {
    rep(j, 1<<N) {
      dp[j|C[i-1]][i] = min(dp[j|C[i-1]][i], dp[j][i-1]+A[i-1]);
      dp[j][i] = min(dp[j][i], dp[j][i-1]);
    }
  }
  cout << (dp[(1<<N)-1][M] == inf ? -1 : dp[(1<<N)-1][M]) << endl;
  return 0;
}



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

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

  if(N<=1) {
      ans=(M*(M-1))/2;
  } else if(M<=1) {
      ans=(N*(N-1))/2;
  } else {
      ans=(M*(M-1))/2+(N*(N-1))/2;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll ; 
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 2e5 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;

int main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    ll a, b, k;
    cin >> a >> b >> k;
    ll t = min(a, k);
    a -= min(a, k);
    k -= t;
    b -= min(k, b);
    cout << a << ' ' << b ;
    return (0) ;
}

Measured memory_bytes: 256
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
int main()
{
   ll n,m;
   cin>>n>>m;
   if(n%m==0) {
   	cout<<"0"<<endl;
   	return 0; }
   
   
   	ll mid=n%m;
   	ll mid3=abs(n-m);
    mid=min(mid,mid3);
   	ll mid2=n/m;
   	mid2=mid2+1;
   	mid2=m*mid2;
   	ll ans=min(mid,mid2-n);
   	cout<<ans<<endl;
   
}

Measured memory_bytes: 256
using System;

class ManyFormulas
{
	static long result = 0;
	static string S;

	static public void Main(string[] args)
	{
		S = Console.ReadLine();
		calc(0, 0, 0);
		Console.WriteLine(result);
	}

	static void calc(int i, long sum, long val)
	{
		if(i == S.Length - 1)
		{
			val = val*10 + int.Parse(S.Substring(i, 1));
			sum += val;
			result += sum;
			return;
		}
		val = val*10 + int.Parse(S.Substring(i,1));
		calc(i+1, sum, val);
		calc(i+1, sum+val, 0);
	}
}


Measured memory_bytes: 2648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args) throws IOException {
        Pattern space = Pattern.compile(" ");
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        int[] first = space.splitAsStream(stdin.readLine()).mapToInt(Integer::parseInt).toArray();
        int n = first[0];
        int k = first[1];
        long[] a = space.splitAsStream(stdin.readLine()).mapToLong(Long::parseLong).toArray();

        long[] b = new long[n + 1];
        for (int i = 0; i < n; i++) b[i + 1] = a[i] + b[i];

        List<Long> sums = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                sums.add(b[j + 1] - b[i]);
            }
        }


        long ans = 0L;
        for (long i = 40L; i >= 0; i--) {
            List<Long> nxts = new ArrayList<>();
            for (long sum : sums) {
                if ((sum & (1L << i)) != 0L) nxts.add(sum);
            }

            if (nxts.size() >= k) {
                ans |= 1L << i;
                sums = nxts;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 52976
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		double answer;
		Scanner sc = new Scanner(System.in);
		double N = sc.nextDouble();
		if(N%2 == 0) {
			answer = N/(2*N);
		}else {
			answer = (N+1)/(2*N);
		}
		System.out.println(String.format("%.10f", answer));
	}
}

Measured memory_bytes: 23252
///Coder ---->>>> Kael (Joan Marcos Rivera)
///Team ACM : CyberSpace ____ IPVCE FEDERICO ENGELS
///KingOfString
///Copyright

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;

typedef long long ll;
typedef pair < string , int > par;

#define pb push_back
#define s second
#define mp make_pair
#define f first
#define maxn 100010
#define eps 1e-9
#define mod 50010
#define less(n) order_of_key(n)
#define en_pos(n) find_by_order(n) /// --- >> iterador --- >> empieza en 0

int a[maxn][3],dp[maxn][5];
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    for(int i=1;i<=n;i++)
        cin >> a[i][1] >> a[i][2] >> a[i][3];

    dp[1][1]=a[1][1];
    dp[1][2]=a[1][2];
    dp[1][3]=a[1][3];

    for(int i=2;i<=n;i++){
        for(int j=1;j<=3;j++){
            for(int k=1;k<=3;k++){
                if(j != k)dp[i][j]=max(dp[i][j],dp[i-1][k] + a[i][j]);
            }
        }
    }

    int sol=max(dp[n][1],max(dp[n][2],dp[n][3]));
    cout << sol;
}


Measured memory_bytes: 3328
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


from collections import defaultdict

h, w, n = li()
dic = defaultdict(int)

drs = [-1, 0, 1]
dcs = [-1, 0, 1]

ans = [0]*10
ans[0] = (h-2)*(w-2)

for _ in range(n):
    a, b = li_()
    for dr in drs:
        for dc in dcs:
            if 0 < a+dr < h-1 and 0 < b+dc < w-1:
                dic[(a+dr, b+dc)] += 1

for _, val in dic.items():
    ans[val] += 1
    ans[0] -= 1

print(*ans, sep="\n")

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

int main(){
  deque<char> dq;
  char c;
  while(cin >> c){
    if(c!='B'){
      dq.push_back(c);
    }
    else if(c=='B' && !dq.empty()){
      dq.pop_back();
    }
  }
  while(!dq.empty()){
    cout << dq.front();
    dq.pop_front();
  }
  cout << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	int H, W; cin >> H >> W;
	map<char, int> mp;
	rep(i, H*W) {
		char x;
		cin >> x;
		mp[x]++;
	}
	// 回文を構成するために4つ必要な英字の数
	int square = (H/2) * (W/2);
	// HもWも奇数であれば、最後に英字1つが残っている必要がある
	bool odd = (H%2!=0 && W%2!=0) ? true : false;

	int sq_cnt = 0, odd_cnt = 0;
	for(const auto& m: mp) {
		if (m.second%2==1) odd_cnt++;
		sq_cnt += m.second/4;
	}

	if ((sq_cnt>=square) && ((odd&&odd_cnt==1) || (!odd&&!odd_cnt))) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256