akhauriyash/Code-Regression huggingface dataset:
// OURL: https://atcoder.jp/contests/abc138/tasks/abc138_a
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));  }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v);  }

template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", ";  } first = false; res += to_string(x);  } res += "}"; return res;  }

string to_string(string s) { return '"' + s + '"';  }
string to_string(const char* s) { return to_string((string) s);  }
string to_string(bool b) { return (b ? "true" : "false");  }
string to_string(vector<bool>::reference b) { return to_string(bool(b));  }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";  }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res; }

void debug_out() { cerr << endl;  }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...);  }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

  int a;
  string s;
  cin >> a >> s;
  if (a < 3200) {
    cout << "red" << endl;
  } else {
    cout << s << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  int num[3];
  for(int i=0;i<1000;i++){
    int dummy = n;
    num[0] = dummy%10;
    dummy /= 10;
    num[1] = dummy%10;
    dummy /= 10;
    num[2] = dummy%10;
    if(num[0] == num[1] && num[0] == num[2]){
      cout << n << endl;
      return 0;
    }
    n++;
  }
}

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

int main(){
    while(true){
        string Red,Green,Out;
        // cin>>Red;
        getline(cin,Red);
        if(Red[0]=='-') return 0;
        // cin>>Green>>Out;
        getline(cin,Green);
        getline(cin,Out);
        if(!Out.size()){
            cout<<Green<<endl;
            continue;
        }
        // cout<<Red<<' '<<Green<<' '<<Out<<endl;
        queue<char> R,G,O;
        for(auto c:Red) R.push(c);
        for(auto c:Green) G.push(c);
        for(auto c:Out) O.push(c);

        char centre = G.front(); G.pop();
        int cnt = Green.size();
        while(true){
            // cout<<'?'<<centre<<' '<<O.front()<<endl;
            if(!O.empty()&&centre==O.front()){
                centre=R.front(); R.pop();
                O.pop();
            }else{
                cout<<centre;
                cnt--;
                if(!cnt){
                    cout<<endl;
                    break;   
                }
                centre=G.front(); G.pop();                    
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3164
using System;
using System.Linq;

namespace ABC127
{
    class D
    {
        static void Main(string[] args)
        {
            var hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var h = hw[0]; var w = hw[1];
            var map = Enumerable.Repeat(0, h).Select(_ => Console.ReadLine().ToCharArray()).ToArray();

            // 行
            for (int i = 0; i < h; i++)
            {
                var start = 0;
                var end = 0;
                for (int j = 0; j < w; j++)
                {
                    var count = 0; // . が連続している回数
                    if (map[i][j] == '#') continue;

                    count++;
                    start = j;
                    while (j + 1 < w && map[i][j + 1] == '.')
                    {
                        count++;
                        j++;
                    }
                    end = j;

                    for (int k = start; k <= end; k++)
                    {
                        map[i][k] = (char)(count + '0');
                    }
                }
            }

            // 列
            for (int j = 0; j < w; j++)
            {
                var start = 0;
                var end = 0;
                for (int i = 0; i < h; i++)
                {
                    var count = 0; // . が連続している回数
                    if (map[i][j] == '#') continue;

                    count++;
                    start = i;
                    while (i + 1 < h && map[i + 1][j] != '#')
                    {
                        count++;
                        i++;
                    }
                    end = i;

                    for (int k = start; k <= end; k++)
                    {
                        map[k][j] = (char)(((map[k][j] - '0') + count - 1) + '0');
                    }
                }
            }

            var res = 0;
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    res = Math.Max(res, map[i][j] - '0');
                    //Console.Write(map[i][j]);
                }
                //Console.WriteLine();
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 27012
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

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

void rec(vi &pre, vi &in, vi &post, int l, int r, int &pos) {
  if (l >= r) return;

  int root = pre[pos++];
  int m = distance(in.begin(), find(in.begin(), in.end(), root));
  rec(pre, in, post, l, m, pos);
  rec(pre, in, post, m + 1, r, pos);
  post.push_back(root);
}

int main() {
  int n, pos = 0;
  cin >> n;

  vi pre(n), in(n), post;
  rep(i, n) cin >> pre[i];
  rep(i, n) cin >> in[i];
  
  rec(pre, in, post, 0, n, pos);

  rep(i, n) printf(i != n - 1 ? "%d " : "%d\n", post[i]);
}



Measured memory_bytes: 3300
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1e5 + 5;
int main()
{
	int dp[maxn];
	int h[maxn];
	int n,k;
	while(~scanf("%d %d",&n,&k)){
		for(int i=1;i<=n;i++)
			scanf("%d",&h[i]);
		dp[1] = 0;
	    for(int i=2;i<=n;i++){
	    	dp[i]=1e9;
			for(int j=1;j<=k;j++){
				if(i==j) break;
			    dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
				}
	}
	printf("%d\n",dp[n]);
	}
	return 0;
}


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

int main()
{
    int n,m;

    cin >> n >> m;

    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= n-i;j++){
            int k = n-i-j;
            if(k >= 0 && 10000*i+5000*j+1000*k == m){
                printf("%d %d %d\n", i, j, k);
                return 0;
            }
        }
    }
    printf("-1 -1 -1\n");
    return 0;
}

Measured memory_bytes: 256
import numpy as np
import sys
import math

n=int(input())
W=[input() for i in range(n)]
if len(W)!=len(set(W)):
    print('No')
    sys.exit()
ans='Yes'
for i in range(n-1):
    if W[i][-1]!=W[i+1][0]:
        ans='No'
        break
print(ans)

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

string a, b;
int dp[2000][2000];

int solve(int xi=0, int yi=0) {
    if (xi == a.size() and yi == b.size()) {
        return 0;
    }
    int& res = dp[xi][yi];
    if (~res) return res;

    if (a[xi] == b[yi]) {
        res = solve(xi+1, yi+1) + 1;
    }
    else {
        if (xi < a.size()) res = max(res, solve(xi+1, yi));
        if (yi < b.size()) res = max(res, solve(xi, yi+1));
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    while (n--) {
        cin >> a >> b;
        fill(dp[0], dp[2000], -1);
        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 18872
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int [] h = new int[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
		}
		int cnt = 1;
		int max = h[0];
		for(int i = 0;i < n-1;i++){
			if(max <= h[i+1]){
				cnt++;
				max = h[i+1];
			}
		}
		System.out.println(cnt);
	}
}

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

#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define fr                first
#define sc                second
#define vc                vector
#define endl              '\n'
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define LSB(i)            ((i)&-(i))

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve()
{
    int h, n;
    cin >> h >> n;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        sum += a;
    }
    if (sum >= h)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

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

long f(int a[], int n, bool plus) {
    long ans = 0;
    int sum = a[0];

    if (plus && sum <= 0) {
        ans = -sum + 1;
        sum = 1;
    } else if (!plus && sum >= 0) {
        ans = sum + 1;
        sum = -1;
    }

    for (int i = 1; i < n; i++) {
       sum += a[i];

       if ((plus && sum < 0) || (!plus && sum > 0)) {
           plus = !plus;
           continue;
       }

       if (plus) {
           ans += (sum + 1);
           sum = -1;
       } else {
           ans += (-sum + 1);
           sum = 1;
       }
       plus = !plus;
    }

    return ans;
}

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

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

    long ans1 = f(a, n, true);
    long ans2 = f(a, n, false);

    cout << min(ans1, ans2) << endl;

    return 0;
}


Measured memory_bytes: 640
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")
 
 
def main():
    R = int(input())
    G = int(input())
 
    print(G + (G - R))
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
//77B
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
    int n;
    cin >> n;
    for(int i=n; i>0; i--){
        if(sqrt(i) == floor(sqrt(i))){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();
		int t1 = a / b;
		int t2 = a % b;
		double t3 = (double) a / b;
		if(b == 1) {
			System.out.println(t1 + " " + t2 + " " + t1);
		}else {
			System.out.println(t1 + " " + t2 + " " + BigDecimal.valueOf(t3).toPlainString());
		}
	}
}


Measured memory_bytes: 26540
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int num[200005];
int pos[200005];
int main()
{
	ll n,i,q,a,b,sum=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
    	cin>>num[i];
    	sum+=num[i];
    	pos[num[i]]++;
	}
	cin>>q;
	while(q--)
	{
		cin>>a>>b;
		if(pos[a]==0) 
		{
			cout<<sum<<endl;
			continue;
		}
		else
		{
			int tmp=pos[a];
			pos[a]=0;
			pos[b]+=tmp;
			sum-=tmp*a;
			sum+=tmp*b;
			cout<<sum<<endl;
			continue;
		}
	}
	return 0;
}

Measured memory_bytes: 4384
import sys
import  math
from heapq import *
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()
A.sort(reverse=True)

mod=10**9+7
keta=[0]*60

for i in range(N):
    for j in range(60):    
        keta[j]+=((A[i]>>j)&1)

ans=0

mod_div2=[0]*60
mod_div2[0]=1
for i in range(1,60):
    mod_div2[i]=(2*mod_div2[i-1])%mod
    
for i in range(len(A)):
    keta_max=0
    for j in range(60):
        if((A[i]>>j)&1):
            keta_max=j+1
    for j in range(keta_max):
            if((A[i]>>j)&1):
                keta[j]-=1
                ans+=mod_div2[j]*(len(A)-i-1-keta[j])
            else:
                ans+=mod_div2[j]*keta[j]
            ans%=mod


print(ans%mod)

Measured memory_bytes: 119980
let [| N; K |] = stdin.ReadLine().Split() |> Array.map int
let p = stdin.ReadLine().Split() |> Array.map int

let mutable m =
    p
    |> Array.take K
    |> Array.sum

let mutable t = m

for i in [ 1..N - K ] do
    t <- t + p.[i + K - 1] - p.[i - 1]
    m <- max t m

((m + K) |> float) / 2.0 |> stdout.WriteLine

Measured memory_bytes: 35544
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
d=0
ans=0
for _ in range(n):
    a=list(map(int,input().split()))
    for j in range(m):
        d+=a[j]*b[j]
    if d+c >0:
        ans+=1
        d=0
    else:
        d=0
print(ans)

    


Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
	char s[202]={0}, p[100]={0};
	int i, j, k, result;
	for(i=0; i<101; i++){
		s[i]=getchar();
		if(s[i]=='\n') {
			k=i;
			break;
		}
	}
	for(i=0; i<101; i++){
		p[i]=getchar();
		if(p[i]=='\n') {
			break;
		}
	}
	for(i=0; i<k; i++){
		s[k+i]=s[i];
	}
	s[2*k]='\n'; 
	for(i=0; i<202; i++){
		if(s[i]=='\n'){
			result=0;
			break;
		} else if(s[i]==p[0]){
			for(j=1; j<101; j++){
				if(p[j]=='\n'){
					result=1;
					i=202;
					break;
				} else if(p[j]!=s[i+j]){
					result=0;
					break;
				}
			}
		}
	}
	if(result==0){
		printf("No\n");
	} else {
		printf("Yes\n");
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

ll last_check(ll n, ll k)
{
    if (n > k - n) {
        return k - n;
    } else {
        return n;
    }
}

int main()
{
    ll N, K;
    cin >> N >> K;
    if (K == 1) {
        cout << 0 << endl;
        return 0;
    }
    if (N == K) {
        cout << 0 << endl;
        return 0;
    } else if (N < K) {
        cout << last_check(N, K) << endl;
        return 0;
    }
    ll tmp = N / K;
    cout << last_check(N - (tmp * K), K) << endl;
}

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

typedef long long int ll;
// priority_queue<pi, vector<pi>, greater<pi> > pq; //min heap

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

	ll n;
	cin>>n;

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

	ll co = 0;
	for(int i=0;i<n;++i)
	{
		// cout<<i<<"=";
		for(int j=i+1;j<n;++j)	
			{
				// cout<<j<<" ";
				co += A[i]*A[j];
			}
		// cout<<"\n";
	}

	cout<<co<<"\n";

	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);
		
		String s;
		s = sc.next();
		sc.close();
		
		int x, min, ans = 753, k = 0;
		min = 753;
		String s2[];
		s2 = new String[9];
		
		for(int i = 0; i < s.length() - 2; ++i) {
			s2[k] = "";
			for(int j = i; j < i + 3; ++j) {
				s2[k] += s.charAt(j);
			}
			++k;
		}
		
		for(int i = 0; i < 9; ++i) {
			if(s2[i] != null) {
				x = Integer.parseInt(s2[i]);
				x = Math.abs(x - 753);
				min = Math.min(min, x);
			}
		}
		
		System.out.println(min);
	}

}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
// 1110100011010100101001010001000000000000
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n, k;
  cin >> n >> k;
  VEC<LL> a(n);
  REP(i, 0, n) cin >> a[i];
  LL siz = n * (n + 1) / 2;
  VEC<LL> sum(siz, 0);
  int cnt = 0;
  REP(i, 0, n) {
    LL s = 0;
    REP(j, i, n) {
      s += a[j];
      sum[cnt] = s;
      ++cnt;
    }
  }
  //DUMP(siz, sum);
  sort(ALL(sum));
  reverse(ALL(sum));

  VEC<LL> ans(k, 0);
  LL lim = 0b10000000000000000000000000000000000000000;
  //DUMP(lim);
  for (LL i = lim; i > 0; i = (i >> 1)) {
    int count = 0;
    REP(j, 0, siz) {
      if ((sum[j] & i) > 0) {
        ++count;
      }
    }
    //DUMP(i, "count", count);
    if (count == k) {
      // ans
      break;

    } else if (count > k) {
      // continue, cand limited
      //DUMP("limit");
      auto newlast = sum.begin();
      REP(j, 0, siz) {
        if ((sum[j] & i) <= 0) {
          break;
        }
        ++newlast;
      }
      sum = VEC<LL>(sum.begin(), newlast);
      //DUMP("    ", sum);
      siz = sum.size();

    } else {
      // continue, cand no info
      //DUMP("no info");
      REP(j, 0, siz) {
        if ((sum[j] & i) > 0) {
          sum[j] -= i;
        }
      }
    }
    sort(ALL(sum), greater<LL>());
    //DUMP(i, count, sum);
  }

  REP(j, 0, k) { ans[j] = sum[j]; }
  LL z = ans[0];
  REP(i, 1, k) { z = z & ans[i]; }
  cout << z << endl;

  return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  vector<ll> dp(N,1000);
  REP(i, N) {
    ll money = dp[i];  //今日の所持金
    ll kabu = money / A[i];
    money = money % A[i];
    if (kabu == 0) continue;
    for (int j = i + 1; j < N; j++) {
      if (dp[j] < money + kabu * A[j]) {
        dp[j] = money + kabu * A[j];
      }
    }
    for (int j = i + 1; j < N; j++) {
      if (dp[j] < dp[i]) {
        dp[j] = dp[i];
      }
    }
  }
  cout << dp[N - 1] << endl;
}

Measured memory_bytes: 3620
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<vector<int>> F(N, vector<int>(10)), P(N ,vector<int>(11));
	for (int i = 0; i < N; i++) for (int j = 0; j < 10; j++) cin >> F[i][j];
	for (int i = 0; i < N; i++) for (int j = 0; j <= 10; j++) cin >> P[i][j];


	int ans = -INF;
	for (int bit = 0b1; bit < (1 << 10); bit++) {
		int sum = 0;
		for (int i = 0; i < N; i++) {

			int popcnt = 0;
			for (int j = 0; j < 10; j++) {
				if (((1 << j) & bit) & (F[i][j] << j)) popcnt++;
			}
			sum += P[i][popcnt];

		}
		ans = max(ans, sum);
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

from collections import deque
    
N, M = mi()
#U = UnionFind(N)
rel = [[] for _ in range(N)]

mark = [-1]*N
flag = [0]*N
mark[0] = 0
l = deque([0])
'''
def dfs(s):
    print(mark)
    if rel[s]:
        for num in rel[s]:
            if mark[num] == -1:
                mark[num] = s
        for num in rel[s]:
            if rel[num]:
                dfs(num)   
'''
for i in range(M):
    s, t = mi()
    s -= 1
    t -= 1
    rel[s].append(t)
    rel[t].append(s)

#dfs(0)
flag[0] = 1
while l != deque([]):
    a = l.popleft()
    for num in rel[a]:
        if not flag[num]:
            mark[num] = a
            flag[num] = 1
            l.append(num)

if sum(flag) != N:
    print('No')
    exit()
print('Yes')
for i in range(1, N):
    print(mark[i]+1)

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

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

ll a = 0, n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0;
string s;
char c;
bool flag;

//----------------------------------------------------------------------

ll prime[100000];

void AllPrime(ll max) {
  bool flag;

  ll prime_count = 1;
  prime[0] = 2;

  FOR(i, 3, max + 1) {
	flag = true;

	FOR(j, 0, prime_count) {
	  if (sqrt(i) < prime[j]) {
		break;
	  }
	  else if (i % prime[j] == 0) {
		flag = false;
		break;
	  }
	}

	if (flag) {
	  prime[prime_count] = i;
	  prime_count++;
	}
  }
}

bool IsPrime(ll x) {
  if (x < 2) {
	return false;
  }

  for (ll i = 0;prime[i] <= sqrt(x);i++) {
	if (x%prime[i] == 0) {
	  return false;
	}
  }
  return true;
}

int main(void) {
  vll l(110000), r(110000), a(110000);
  vb b(110000);

  cin >> n;

  FOR(i, 0, n) {
	cin >> l[i] >> r[i];
  }

  AllPrime(110000);

  FOR(i, 0, 110000) {
	if (IsPrime(i) && IsPrime((i + 1) / 2)) {
	  b[i] = true;
	}
	else {
	  b[i] = false;
	}
  }

  FOR(i, 1, 110000) {
	if (b[i]) {
	  a[i] = a[i - 1] + 1;
	}
	else {
	  a[i] = a[i - 1];
	}
  }

  FOR(i, 0, n) {
	if (b[l[i]]) {
	  cout << a[r[i]] - a[l[i]] + 1 << endl;
	}
	else {
	  cout << a[r[i]] - a[l[i]] << endl;
	}
  }
  
  return 0;
}

Measured memory_bytes: 3328
#include<iostream> 
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
	int a[10];
	
	int b=99999999,c=-99999,d,e,f,g,h;
	cin>>a[1]>>a[2]>>a[3];
	if(a[2]>=a[1])
	{
		d=a[2];
		a[2]=a[1];
		a[1]=d;
	}
	if(a[3]>=a[1])
	{
		d=a[3];
		a[3]=a[1];
		a[1]=d;
	}
	if(a[3]>=a[2])
	{
		d=a[3];
		a[3]=a[2];
		a[2]=d;
	}

	//cout<<a[1]<<" "<<a[2]<<" "<<a[3];	
	e=a[1]-a[3];
	cout<<e;
	
}

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

const int INF = 1e18;

int arr[maxn], dp[maxn][maxn] = {};
int n;

int sum(int l, int r) {
    return arr[r] - arr[l - 1];
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> arr[i];
        arr[i] += arr[i - 1];
    }
    for(int len = 2; len <= n; len++) {
        for(int l = 1, r = len; r <= n; l++, r++) {
            dp[l][r] = INF;
            for(int i = l; i < r; i++) {
                dp[l][r] = min(dp[l][r], dp[l][i] + dp[i + 1][r]);
            }
            dp[l][r] += sum(l, r);
        }
    }
    cout << dp[1][n] << '\n';
    return 0;
}


Measured memory_bytes: 4900
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
using namespace std;
int main(void){

    int n;
    while(cin>>n,n){
        int a[10020];
        bool flg = true;
        for(int i = 0;i < n;i++){cin>>a[i];if(a[i]>=2)flg = false;}
        if(flg){cout<<"NA"<<endl;continue;}
        int ans = 0;
        for(int i = 0;i < n;i++)if(a[i]!=0)ans++,a[i]--;

        for(int i = 0;i < n;i++){
            if(a[i]!=0){
                cout<<ans+1<<endl;
                break;
            }
        }
    }


    return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  
  for(i=0; i<=VMAX; i++) C[i]=0;
   
  for(i=0; i<n; i++){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }
 
  for(i=1; i<=VMAX; i++) C[i]=C[i]+C[i-1];
 
  for(j=1; j<=n; j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
 
  for(i=1; i<n; i++){
    printf("%d ",B[i]);
  
  }
  printf("%d\n",B[i]);

  return 0;
}




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

int main()
{
	int n,m;
	cin>>n>>m;
	if (n<2 || m<2)
	 cout<<0<<"\n";
	else
	 {
	 	cout<<(n-1)*(m-1)<<"\n";
	 }
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("~/Downloads/02.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;


int main() {


    int a, b;
    cin >> a >> b;

    int keta = log10(b);

    a = a * pow(10, keta + 1);

    int r = a + b;

    int sq = sqrt(r);
    int sqr = sq * sq;

    if (sqr == r) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int custo[] = {100, 101, 102, 103, 104, 105};
vector<int> resto;
int fpd(int resta){
	if(resto[resta] != -1)
		return resto[resta];
	if(resta < 100)
		return resto[resta] = resta;
	if(resta == 0)
		return resto[resta] = 0;
	for(int i = 0; i < 6; ++i){
		if(resta >= custo[i]){
			if (resta - custo[i] < 0) continue;
			if(fpd(resta - custo[i]) == 0)
				return resto[resta] = 0;
		}
	}
	return resto[resta] = 1;
}
int main(){
	int x;
	cin >> x;
	resto.resize(x + 10, -1);
	cout << !fpd(x) << '\n';
}

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

int N,W;
int N_MAX = 100; int W_MAX = 100000;
vector<int> w(N_MAX),v(N_MAX);
vector<vector<long long>> dp(N_MAX + 1,vector<long long>(W_MAX));

int main(){
    cin >> N >> W;
    for(int i = 0;i < N;i++) cin >> w[i] >> v[i];
    dp[0][0] = 0;
    for(int i = 0;i < N;i++){
        for(int j = 0;j <= W;j++){
            if(j < w[i])
                dp[i+1][j] = dp[i][j];
            else 
                dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]] + v[i]);
        }
    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;

int main() {

rep(i,5){
  int N;
  cin >> N ;
  if(N==0) cout << i+1 <<endl;
}

return 0;

}

Measured memory_bytes: 3572
#include <iostream>
#include <cstring>
using namespace std;
const int maxn=(int)1e5+10;

int a[maxn];

struct node{
    int l,r;
    long long sum,lazy;
    void update(long long val){
        sum+=val*(r-l+1);
        lazy+=val;
    }
}tree[maxn<<2];

void push_up(int x){
    tree[x].sum=tree[x<<1].sum+tree[x<<1|1].sum;
}

void push_down(int x){
    long long val=tree[x].lazy;
    if(val){
        tree[x<<1].update(val);
        tree[x<<1|1].update(val);
        tree[x].lazy=0;
    }
}

void build(int x,int l,int r){
    tree[x].l=l,tree[x].r=r,tree[x].lazy=0;
    if(l==r)
        tree[x].sum=a[l];
    else{
        int mid=(l+r)>>1;
        build(x<<1,l,mid);
        build(x<<1|1,mid+1,r);
        push_up(x);
    }
}

void update(int x,int l,int r,long long val){
    int L=tree[x].l,R=tree[x].r;
    if(l<=L&&R<=r)
        tree[x].update(val);
    else{
        push_down(x);
        int mid=(L+R)>>1;
        if(l<=mid) update(x<<1,l,r,val);
        if(r>mid) update(x<<1|1,l,r,val);
        push_up(x);
    }
}

long long query(int x,int l,int r){
    int L=tree[x].l,R=tree[x].r;
    if(l<=L&&R<=r)
        return tree[x].sum;
    else{
        long long sum=0;
        push_down(x);
        int mid=(L+R)>>1;
        if(l<=mid) sum+=query(x<<1,l,r);
        if(r>mid) sum+=query(x<<1|1,l,r);
        push_up(x);
        return sum;
    }
}

int main(){
    int n,m;
    while(cin>>n>>m){
        memset(a,0,sizeof(a));
        int l,r;
        build(1,1,n);
        for(int i=0;i<m;i++){
            cin>>l>>r;
            update(1,l,r,1);
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            if(query(1,i,i)==m)
                ans++;
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 8832
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

def make_divisors(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
n = int(input())
cnt = 0
for i in range(1,n+1):
    if i%2 == 0:
        continue
    a = make_divisors(i)
    if len(a) == 8:
        cnt+=1
print(cnt)


Measured memory_bytes: 3420
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const char* dates[7] = { "sat", "sun", "mon", "tue", "wed", "thu", "fri" };

int main(void) {
  int date;
  scanf("%d", &date);
  printf("%s\n", dates[(((date - 9) % 7) + 7) % 7]);
  return 0;
}



Measured memory_bytes: 2140
#include<iostream>
#include<cstdio>
#include<deque>
#include<algorithm>

using namespace std;

typedef pair<int,int>P;

const int maxn=1e3+5;
int inf=500;

int h,w,n,sx,sy;
char s[maxn][maxn];
int book[maxn][maxn],goal[10];
int Next[4][2]={{0,1},{1,0},{-1,0},{0,-1}};

int judge(int row,int col)
{
    if(row>=0&&row<h&&col>=0&&col<w){
        return 1;
    }
    return 0;
}

int bfs()
{
    int res=0;
    deque<P>q;
    for(int ci=0;ci<n;ci++){
        fill(book[0],book[0]+maxn*maxn,inf);
        q.push_back(P(sx,sy));
        book[sx][sy]=0;
        while(!q.empty()){
            int x=q.front().first;
            int y=q.front().second;
            q.pop_front();
            if((int)s[x][y]==49+ci){
                goal[ci]=book[x][y];
                sx=x;
                sy=y;
                break;
            }
            for(int i=0;i<4;i++){
                int nx=x+Next[i][0];
                int ny=y+Next[i][1];
                if(judge(nx,ny)&&s[nx][ny]!='X'&&book[nx][ny]==inf){
                    q.push_back(P(nx,ny));
                    book[nx][ny]=book[x][y]+1;
                }
            }
        }
        q.clear();
        res+=goal[ci];
    }
    return res;
}

int main()
{
    cin>>h>>w>>n;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>s[i][j];
            if(s[i][j]=='S'){
                sx=i;
                sy=j;
            }
        }
    }
    int goalnum=bfs();
    cout<<goalnum<<endl;
    return 0;
}



Measured memory_bytes: 8076
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    map<char,int> mp;
    rep(i, s.size()) {
        mp[s[i]]++;
    }
    int mn = min(mp['0'],mp['1']);
    ct(mn*2);


}



Measured memory_bytes: 512
a=[],m=l=0,n=c='';require("fs").readFileSync("/dev/stdin","utf8").trim().split(' ').some(function(i){a[j=i.toLowerCase()]?(++a[j]>m?m=a[n=j]:0):a[j]=1;(t=j.length)>l?(c=j,l=t):0});console.log(n+' '+c)

Measured memory_bytes: 7644
#include <stdio.h>

int main(){
	int a,b;
	int hasil1, hasil2, hasil3;
	scanf("%d %d", &a, &b);
	hasil1=a+b;
	hasil2=a-b;
	hasil3=a*b;
	
	if(hasil1>=hasil2 && hasil1>=hasil3){
		printf("%d\n", hasil1);
	} else if(hasil2>=hasil1 && hasil2>=hasil3){
		printf("%d\n", hasil2);
	} else if(hasil3>=hasil2 && hasil3>=hasil1){
		printf("%d\n", hasil3);
	}
}

Measured memory_bytes: 128
import bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
sa = [0 for _ in range(n)]
sb = [0 for _ in range(m)]
x = 0
for i in range(n):
  x += a[i]
  sa[i] = x
y = 0
for j in range(m):
  y += b[j]
  sb[j] = y
si = -1
for i in range(n):
  if sa[n-1-i] <= k:
    si = n-1-i
    break
if si == -1:
  ki = bisect.bisect_right(sb,k)
  print(ki)
else:
  ans = si+1
  for i in range(0,si+1):
    ki = bisect.bisect_right(sb,k-sa[i])
    if ki+i+1 > ans:
      ans = ki+i+1
  ki = bisect.bisect_right(sb,k)
  if ki > ans:
    ans = ki
  print(ans)
  
      
    
    

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// }}} 1

int main() {

    int a,b,c;
    Scd3(a,b,c);

    if( a + b == c || a + c == b || b + c == a )
        printf ("Yes\n");
        else
            printf("No\n");
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a,total1,total2;
	scanf("%d",&a);
	
		if (a% 2==0){
			total1 = a/2;
			printf ("%d",total1);
		}
		else{
			total2 = (a/2)+1;
			printf ("%d",total2); 	
		}
	return 0;
}

Measured memory_bytes: 2128
n = int(input())
a = list(map(int, input().split()))

a.sort()

num = len(a)-1
alice, bob = 0, 0

while num >= 0:
  alice += a[num]
  num -= 1
  if num < 0:
    break
  bob += a[num]
  num -= 1
  
print(alice-bob)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, S):
    s1 = list(map(lambda x: len(x), filter(lambda x: x != '', S.split('0'))))
    s0 = list(map(lambda x: len(x), filter(lambda x: x != '', S.split('1'))))
    if len(s0) <= K:
        return N

    if S[0] == '0':
        s1.insert(0, 0)
    if S[-1] == '0':
        s1.append(0)

    q = deque()
    q.append(s1.pop())
    q.append(s0.pop())
    q.append(s1.pop())
    tmp = sum(q)
    ans = tmp
    while s1 or s0:
        if len(q) >= 2*K + 1:
            tmp -= q.popleft()
            tmp -= q.popleft()
        q.append(s0.pop())
        tmp += q[-1]
        q.append(s1.pop())
        tmp += q[-1]
        ans = max(ans, tmp)

    return ans


def main():
    N, K = read_int_n()
    S = read_str()
    print(slv(N, K, S))

    # N = 20
    # K = random.randint(1, 10)
    # S = ''.join(random.choices('01', k=N))
    # rS = ''.join(['0' if c == '1' else '1' for c in S])
    # print(max(slv(N, K, S), slv(N, K-1, rS)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 7136
#include "bits/stdc++.h"
using namespace std;

int main(){
	long long int n;
	cin>>n;
	map<long long int,long long int> mp;
	
	int ans=0;
	
	for(int i=0;i<n;i++){
		long long int a;
		cin>>a;
		if(mp[a]==0){
			mp[a]++;
			ans++;
		}else{
			mp[a]=0;
			ans--;
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6528
import math
a,b,c,d=[int(x) for x in input().split()]

def div(n,p):
  return n//p

def lcm(x, y):
  return (x * y) // math.gcd(x, y)

ans=b-a+1
ans-=(div(b,c)-div(a-1,c))
ans-=(div(b,d)-div(a-1,d))
e=lcm(c,d)
ans+=(div(b,e)-div(a-1,e))
print(ans)

Measured memory_bytes: 9200
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>

#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007

using namespace std;


void solve()
{
    int S, W;
    cin >> S >> W;

    if (W >= S)
    {
        cout << "unsafe\n";
    }
    else {
        cout << "safe\n";
    }
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    // cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3616
def main():
  import sys
  input = sys.stdin.readline
  N, M = map(int, input().split())
  A = []
  C = []
  for _ in range(M):
      a, _ = map(int, input().split())
      A.append(a)
      C_ = list(map(int, input().split()))
      c = 0
      for c_ in C_:
          c |= 1<<c_-1
      C.append(c)
  dp = [float("inf")] * (1<<N)
  dp[0] = 0
  for a, c in zip(A, C):
      dp_new = dp[:]
      for s, d in enumerate(dp):
          dp_new[s|c] = min(d+a, dp_new[s|c])
      dp = dp_new
  #print(dp)
  ans = dp[(1<<N)-1]
  print(ans if ans != float("inf") else -1)

main()

Measured memory_bytes: 3364
#include<stdio.h>

void run() {
	int N, i, j, cnt1 = 0, cnt2 = 0;
	scanf("%d", &N);
	for(j = 0; j < N; ++j){
		for(i = 1; i <= N-j; ++i) {
			if((N-j)%2 == 0) continue;
			if(((N-j) % i) == 0) cnt1++;
			if(cnt1 == 8) cnt2++;
			if(cnt1 == 9) cnt2--;
		}
		cnt1 = 0;
	}
	printf("%d", cnt2);
}
int main() {
	run();
	return 0;
}

Measured memory_bytes: 128
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

na, nb = [0], [0]
for i in range(n):
    na.append(na[i] + a[i])
for j in range(m):
    nb.append(nb[j] + b[j])

ans, j = 0, m
for i in range(n + 1):
    if na[i] > k:
        break
    while nb[j] > k - na[i]:
        j -= 1
    ans = max(ans, i + j)
    
print(ans)
  
  
      

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

const ll mod = 1e9 + 7;

int main() {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  cout << a[0] + a[1] << endl;
  return 0;
}


Measured memory_bytes: 3568
def gcd(a,b):
	while b:
		a, b = b, a % b
	return a
n = input()
t = input()
list = []
for i in range(0,n-1):
	list.append(input())
list.sort()
for i in range(0,n-1):
	t = list[i] * t // gcd(list[i], t)
print t

Measured memory_bytes: 2692
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define tam 100347
#define offset 50000
using namespace std;
typedef long long  ll;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
const ll INF=1e11;
ll go(ll b,ll n)
{
    if (b==1)return 0;
    if (b>n)return n;
    return go(b,n/b)+n%b;
}
int main()
{
    //ios::sync_with_stdio(false);cin.tie(0);
    ll n,s,ans=-1;
    cin>>n>>s;
    if (n<=100)
    {
        forr(i,2,n+100)
        {
            //cout<<go(i,n)<<" "<<i<<endl;
            if (go(i,n)==s&& ans==-1)
                ans=i;
        }
        cout<<ans<<endl;
    }
    else
    {
        //cout<<go((n/3),n)<<endl;
        if (s>n)
        {
            cout<<-1<<endl;
            return 0;
        }
        set<ll> s2;
        s2.insert(s);
        ll posult;
        for(ll i=1;i*i<=max(n,s);i++)
        {
            if (s%i==0)
                s2.insert(i),s2.insert(s/i);
            if (n%i==0)
                s2.insert(i),s2.insert(n/i);
            if ((n-s)%i==0)
                s2.insert(i+1),s2.insert(((n-s)/i)+1);
            posult=i;
        }
        /*forr(i,posult,posult+100)
        cout<<go(i,n)<<" ";
        cout<<endl;*/
        for(ll i=2;i*i<=max(n,s);i++)
        {
            if (go(i,n)==s&& ans==-1)
                ans=i;
        }
   //     cout<<s2.size()<<endl;
        for(set<ll>::iterator ite=s2.begin();ite!=s2.end();ite++)
        {
            if (go(*ite,n)==s&& ans==-1)
                ans=*ite;
        }
        if (ans==-1&& go(n,n)==s)
            ans=n;
        if (ans==-1&& go(n+1,n)==s)
            ans=n+1;
        cout<<ans<<endl;    
    }
    
}


Measured memory_bytes: 15104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n % 1000 == 0) {
			System.out.println(0);
		} else {
			System.out.print(1000 - n % 1000);
		}
	}
}

Measured memory_bytes: 35676
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    string s;
    cin >> s;
    int N = s.size();
    ll a[N], b[N];
    ll x = s[0]-'0';
    a[0] = min(x, 11-x), b[0] = min(x+1, 11-x-1);
    rep2(i, 1, N-1){
        x = s[i]-'0';
        a[i] = min(a[i-1]+x, b[i-1]+10-x);
        b[i] = min(a[i-1]+x+1, b[i-1]+9-x);
    }
    cout << a[N-1] << endl;
}

Measured memory_bytes: 17028
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
int N, Xsize, Ysize, ans, mi;
	mi = 0;

	cin >> N;
	string S, X, Y;
	cin >> S;
	for (int i = 1; i < N; i++) {
		ans = 0;
		int cou = 0;
		X = S.substr(0, i);
		Y = S.substr(i);

		Xsize = X.length();
		Ysize = Y.length();
		sort(X.begin(), X.end());
		sort(Y.begin(), Y.end());


		for (int j = 0; cou < Xsize - 1; j++) {

			if (X[j] == X[j + 1]) {
				X.erase(j + 1, 1);
				j--;
				cou++;
			}
			else cou++;
		}
		cou = 0;
		for (int j = 0; cou < Ysize - 1; j++) {

			if (Y[j] == Y[j + 1]) {
				Y.erase(j + 1, 1);
				j--;
				cou++;
			}
			else cou++;
		}
		Xsize = X.length();
		Ysize = Y.length();


		for (int j = 0; j < Xsize; j++) {
			for (int k = 0; k < Ysize; k++) {
				if (X[j] == Y[k])ans++;
			}
		}
		cou = 0;
		mi = max(mi, ans);
	
	}

	cout << mi << endl;



}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	double x,d;
	scanf("%lld%lf%lf",&n,&x,&d);
	double ans=0;
	ll m=2*n;
	while(m){
		ans+=(2*x+(m-1)*d)*1.0/2;
        x=((m+2)*x+5*d)*1.0/m;
        d=(m+4)*d*1.0/m;
        m-=2;
	}
	printf("%.10f",ans);
}


Measured memory_bytes: 128
n, m = gets.split(' ').map(&:to_i)
s = []
m.times do |i|
    tmp = gets.split(' ').map(&:to_i)
    s << tmp[1..tmp[0]]
end
p = gets.split(' ').map(&:to_i)

def solve(bit, n, m, s, p)
    m.times do |i|
        k = 0
        s[i].each do |j|
            k += 1 if (bit & (1<<j-1)) > 0
        end
        return 0 unless p[i] == (k%2)
    end
    1
end

ans = 0
(0...2**n).each do |bit|
    ans += solve(bit, n, m, s, p)
end

puts ans

Measured memory_bytes: 3836
import java.util.Scanner;

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

        long pow=(long)(Math.log(h) / Math.log(2));
        long num= (long)(Math.pow(2,(pow+1)))-1;
        System.out.println(num);

    }
}


Measured memory_bytes: 21844