akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

int main() {
  ull n, x;
  cin >> n >> x;
  vector<ull> l;

  each(i, n) {
    ull tmp;
    cin >> tmp;
    l.push(tmp);
  }

  ull count = 0;
  ull prev = 0;
  vector<ull> tobi;
  tobi.push(0);
  each(i, l.size()) {
    tobi.push(tobi[i] + l[i]);
  }

  each(i, tobi.size()) {
    if (tobi[i] <= x)
      count++;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
import sys

def gcd(a, b):
    """Euclidean Algorithm"""
    while b != 0:
        a, b = b, a % b
    return a


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


def main():
    input = sys.stdin.readline
    A, B, C, D = map(int, input().split())
    E = lcm(C, D)

    total = B - (A-1)
    mul_c = B // C - (A-1) // C
    mul_d = B // D - (A-1) // D
    mul_e = B // E - (A-1) // E
    return total - (mul_c + mul_d - mul_e)


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=1e6+2;
int check[N];
int main()
{
	int n;
	cin>>n;
	ll a[n];
	map<ll,ll>m;
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=0;i<n;i++)
	{
		if(m[a[i]]==0)
		{
			for(ll j=a[i]+a[i];j<N;j+=a[i])
			check[j]=1;
		}
		m[a[i]]++;
		
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(check[a[i]]==0&&m[a[i]]==1)
		ans++;
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 21516
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n;
	cin>>n;
	if(n%2==1)cout<<0;
	else{
		ll ans=0;
		ll tmp=5;
		while(n/tmp!=0){
			ans+=n/tmp/2;
			tmp*=5;
		}
		cout<<ans;
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>

using namespace std;

int main(){
    int A,B,C,D,AAA;
    string op1,op2,op3;
    char p='+',m='-';
    cin>>AAA;
    D=AAA%10;
    AAA=AAA/10;
    C=AAA%10;
    AAA=AAA/10;
    B=AAA%10;
    AAA=AAA/10;
    A=AAA%10;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<2;k++){
                int sum=A;
                if(i%2==0){
                    sum+=B;
                    op1=p;
                }else{
                    sum-=B;
                    op1=m;
                }
                if(j%2==0){
                    sum+=C;
                    op2=p;
                }else{
                    sum-=C;
                    op2=m;
                }
                if(k%2==0){
                    sum+=D;
                    op3=p;
                }else{
                    sum-=D;
                    op3=m;
                }
                if(sum==7){
                    cout<<A<<op1<<B<<op2<<C<<op3<<D<<"=7"<<endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;

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

    int H, W, h, w;

    cin >> H >> W >> h >> w;

    if (!(H % h) && !(W % w))
    {
        cout << "No" << endl;
        return 0;
    }

    int res[510][510];

    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            res[i][j] = 1;

    if (H % h)
    {
        for (int j = 0; j < W; j++)
            for (int i = h - 1; i < H; i += h)
                res[i][j] = -h;

        int sum = 0;
        for (int i = 0; i < H; i++)
            sum += res[i][0];

        int add = max(0, 1 - sum);

        for (int i = 0; i < H; i++)
            for (int j = 0; j < W; j++)
                if (res[i][j] > 0)
                    res[i][j] += add;
                else
                    res[i][j] -= add * (h - 1);
    }
    else
    {
        for (int i = 0; i < H; i++)
            for (int j = w - 1; j < W; j += w)
                res[i][j] = -w;

        int sum = 0;
        for (int i = 0; i < W; i++)
            sum += res[0][i];

        int add = max(0, 1 - sum);

        for (int i = 0; i < H; i++)
            for (int j = 0; j < W; j++)
                if (res[i][j] > 0)
                    res[i][j] += add;
                else
                    res[i][j] -= add * (w - 1);
    }

    cout << "Yes" << endl;

    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            cout << res[i][j] << (j == W - 1 ? "\n" : " ");

    return 0;
}

Measured memory_bytes: 2304
#include<stdio.h>
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
	int a[n+1];
	int i,j;
	for(i=1;i<=n;i++)
	 {
	 	scanf("%d",&a[i]);
	 }
	 int m=0;
	 for(i=1;i<n;i++)
	  {
	  	for(j=i+1;j<=n;j++)
	  	 {
	  	 	m=m+a[i]*a[j];
	  	 }
	  }
	 printf("%d\n",m);
    }
	 return 0;
}

Measured memory_bytes: 128
n,m = map(int, input().split())
a = [[0 for j in range(m)] for i in range(n)]
b = [0 for i in range(m)]

for i in range(n):
  a[i] = input().split()

for i in range(m):
  b[i] = int(input())

for i in range(n):
  c = 0
  for j in range(m):
    c += int(a[i][j]) * int(b[j])
  print(c)



Measured memory_bytes: 6248
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}



// TODO: write
int main() { 
  int n;cin>>n;
  string s;cin>>s;
  vector<int> a(26,0);
  ll ans = 1;
  rep(i,n){
    a[s[i]-'a']++;
  }
  rep(i,26){
    ans *= a[i]+1;
    ans %= INF;
  }
  ans--;
  print(ans);
  return 0;
}



Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int q = int.Parse(Console.ReadLine());
            for(int i = 0; i < q; i++)
            {
                string[] order = Console.ReadLine().Split(' ').ToArray();
                int a = int.Parse(order[1]);
                int b = int.Parse(order[2]);
                if (order[0] == "print")
                {
                    Console.WriteLine(str.Substring(a, b - a + 1));
                }else if (order[0] == "reverse")
                {
                    string s2 = str.Substring(a, b - a + 1);
                    char[] ch = str.ToCharArray(a, b-a + 1);
                    Array.Reverse(ch);
                    string s = new string(ch);
                    str = str.Replace(s2, s);
                }else if (order[0] == "replace")
                {
                    string p = order[3];
                    string str1 = str.Substring(0, a);
                    string str2 = str.Substring(b + 1);
                    str = str1 + p + str2;
                
                }
            }
        }
    }
}

Measured memory_bytes: 9320
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int P[3];
  cin >> P[0] >> P[1] >> P[2];
  vector<int> a(3);
  a[0]=P[0]+P[1];
  a[1]=P[1]+P[2];
  a[2]=P[0]+P[2];
  sort(a.begin(), a.end());
  cout << a[0] << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
    long long int N, M, res = 0;
    scanf("%lld %lld", &N, &M);
    if(N==1 && M==1)res = 1;
    else if(N==1 || M==1)res = N*M-2;
    else res = (N-2)*(M-2);
    printf("%lld", res);
    return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val (numberA,numberB,numberC) = readLine()!!.split(" ").map { it.toInt() }
    var count = 1
    while (true){
        if (numberA*count > numberC){
            break
        }
        count++
    }
    count--
    println(count*numberB)
}

Measured memory_bytes: 36272
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 200100
#define N2 1000010
#define MOD 1000000007
#define int long long int
#define INF 1000000000000000
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
int prime[N2]={0};
vector <int> pr;
void sieve(){
    prime[0]=1;prime[1]=1;
    for(int i=2;i<=sqrt(N2);i++){
        if(prime[i]==0)
            {
                for(int j=i*i;j<N2;j+=i){
                    prime[j]=1;
                }
            }
    }
    for(int i=2;i<N2;i++){
        if(!prime[i])
            pr.pb(i);
    }
    return ;
}
double pi=3.141592653589;

signed main() {  
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //sieve();
    int n,m;
    cin>>n>>m;
    int su=0;
    for(int i=1;i<=m;i++){
        int x;cin>>x;
        su+=x;
    }

    if(su<=n){
        cout<<n-su<<endl;
    }
    else{
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 3552
//???????????????????????¨??????????????????A????????????B????????£?????¨??????A -> B??¨?????????????????????
//????????¨???????????°???????????§???????????°???????????§s??????t????????????????????¨????????¨??????
//????????????????????????s -> s1 -> s2 -> ??? -> t??¨???????????¨?????§?????????????????¨???????????????s < s1 < s2 < ??? < t??¨?????????
//s-t??????????????????L?????£?????¨??????t????????? >= s????????? + L??§???????????¨????¢??????????????????????s??????t?????????????????????ML??¨????????°???
//t????????? >= s????????? + ML?????¨???????????????????????\????????????????????????1?????\?????§?????????????????????1????????????????§?????????????
//?????????t???????????????t????????? = s????????? + ML??¨?????????????????????
//?????±????¨????????????????????????´????????????????????±????±????????????¨?????§??????????????±????±?????????°????????????????????????
//??¨?????????????????±2????????????????????????????????????????????§???1????????????1???k????????´?????????????????????????\?????????????
//??????????????????1?????????????????????{1, 2, 4}?????£?????¨???????????????3?????????????????????????????£???????????????????????????
//
//????????¨????????°?????¨???????????????????????????????????????????????°???????????°?????\??????????????????????????°??§????????????
//????????????????????¨????????¨??????????????????????????????????????°???????????????DAG????????????DAG?????§??????????????????????§£??????????°????????????§?????????????????????
//???????????????????????????????????°?????????????????????????????§????????¢???????????????????????????????????????????????¨????????????
//??¶?????????????????????, 1?????????????????¢)??§?????????????????????????????§??????????????§???BFS??§??????
//????£?????????????????????????0???n-1????????????????????????
//
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;

vector<int> et[5000], rev_et[5000];
int dp[5000];	//dp[i] = ?????????i(>=0)?????????

int n, m;
queue<P> que;

void bfs(){
	while( !que.empty() ){
		int dist = que.front().first;
		int team = que.front().second;
		que.pop();
		if( dp[team] >= dist )
			continue;
		dp[team] = dist;
		
		for( int i = 0; i < et[team].size(); i++ ){
			que.push(P(dist + 1, et[team][i]));
		}
	}
}

int main()
{
	int i, j;
	
	cin >> n >> m;
	for( i = 0; i < m; i++ ){
		int s, t;
		cin >> s >> t;
		et[s-1].push_back(t-1);
		rev_et[t-1].push_back(s-1);
	}
	
	for( i = 0; i < n; i++ ){
		if( rev_et[i].size() == 0 ){	//i?????\???????????????
			que.push(P(1, i));	//?§?????????????(dp[i]???????????????0????????§??£?????°????????????????????????)
		}
	}
	bfs();	//???????????¢?´¢??§dp??¨????????????
	
	static P perm[5000];	//perm[i] = (??????dp[i], ???????????????i)
	for( i = 0; i < n; i++ )
		perm[i] = P(dp[i], i);
	sort(perm, perm + n);	//????????§?????????
	
	bool flag = false;
	for( i = 0; i < n; i++ ){
		cout << perm[i].second + 1 << endl;
		if( i + 1 < n && perm[i].first == perm[i+1].first ){
			flag = true;
		}
	}
	if( flag ) cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 3928
# Binary Indexed Tree (Fenwick Tree)
class BIT:
  def __init__(self, n):
    self.n = n
    self.bit = [0]*(n+1)
    self.el = [0]*(n+1)
  def query(self, i):
    s = 0
    while i > 0:
      s = max(s,self.bit[i])
      i -= i & -i
    return s
  def update(self, i, x):
    # assert i > 0
    self.el[i] = max(self.el[i],x)
    while i <= self.n:
      self.bit[i] = max(self.bit[i],x)
      i += i & -i

N = int(input())
H = list(map(int, input().split()))
A = list(map(int, input().split()))
dp = BIT(N)
for i in range(N):
  dp.update(H[i],dp.query(H[i]-1)+A[i])
ans = dp.query(N)
print(ans)

Measured memory_bytes: 115560
n=gets.to_i
m=gets.split.map(&:to_i)
r=[]
for i in 0..n-2
    a=m[0..i].inject(&:+)
  
    b=m[i+1..n-1].inject(&:+)
   
   v=(a-b).abs
      
    r<<v
    
    
    
end
puts r.min


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

#define int long long
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

const int p = 31;
const int MOD = 1e9 + 7;
const int N = 5e3 + 5;
int hash1[N];

int d, x, y;
void extendedEuclid(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}

int modInverse(int A, int M)
{
    extendedEuclid(A,M);
    return (x%M+M)%M;    //x may be negative
}

int b_power(int a, int b)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD;
        a = (a * a)%MOD;
        b >>= 1;
    }
    return res;
}
int32_t main(){
	fast;
	int n;
	string s;
	cin >> n >> s;
	
	hash1[0] =  s[0] - 'a' + 1;
	int m = p;
	for(int i=1 ; i<n ; i++)
	{
		hash1[i] = (hash1[i-1] + (s[i] -'a' + 1)*m)%MOD;
		m = (m * p)%MOD;
	}
	
	int low = 0 , high = n , mid , ans = 0;
	while(low <= high)
	{
		mid = (low + high)/2;
		int j = mid;
		map<int,vector<int>> v;
		for(int i=0 ; i<=n-mid ; i++)
		{
			int val = hash1[i+j-1];
			if(i != 0) val = (val - hash1[i-1] + MOD)%MOD;
			int temp = b_power(p,i);
			temp = modInverse(temp,MOD);
			val = (val * temp)%MOD;
			v[val].pb(i);
		}
		bool chk = false;
		for(auto x : v)
		{
			if(x.S.size() >= 2)
			{
				
				if((x.S[x.S.size()-1] - x.S[0]) >= mid)
					chk = true;
			}
		}
		if(chk) ans = max(ans ,mid);
		if( ans >= mid)
		{
			low = mid + 1;
		}
		else
		{
			high =mid - 1;
		}
	}
	cout << ans;
	
}







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

namespace AGC034
{
    class A
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split(' ').Select(o => int.Parse(o)).ToArray();
            int N = a[0], A = a[1]-1, B = a[2]-1, C = a[3]-1, D = a[4]-1;
            string S = Console.ReadLine();

            string r = "No";
            if (C < D)
            {
                if (Judge(S, B, D) && Judge(S, A, C)) r = "Yes";
            }
            else
            {
                if (Judge(S, B, D) && Judge(S, A, C))
                {

                    int s = B - 1;
                    int e = D + 1;

                    for (int i = s + 2; i <= e; i++)
                    {
                        if (S[i] == '.' && S[i - 1] == '.' && S[i - 2] == '.')
                        {
                            r = "Yes";
                            break;
                        }
                    }

                }

            }
            Console.WriteLine(r);
        }

        static bool Judge(string S, int start, int end)
        {

            for(int i = start+1; i < end; i++)
            {
                if (S[i] == '#' && S[i - 1] == '#') return false;
            }
            return true;
        }

       
    }
}


Measured memory_bytes: 13792
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	static int A,B,C;
	//static String ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		A=sc.nextInt();
		B=sc.nextInt();

		C=sc.nextInt();
		int a[]=new int[101];
		for(int i=1;i<=100;i++) {
			if(A%i==0&&B%i==0)a[i]=i;
		}
		Arrays.sort(a);
		System.out.println(a[101-C]);
	}
}


Measured memory_bytes: 22868
#include <iostream>
//#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
	int N;
	string s;
	cin >> N >> s;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (s[i] != s[i + 1])ans++;
	}
	cout << ans << endl;
}


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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(Q);
  for (int i = 0; i < Q; i++) {
    cin >> A.at(i);
  }
  vector<int> S(N);
  for (int i = 0; i < Q; i++) {
    S.at(A.at(i) - 1)++;
  }
  for (int i = 0; i < N; i++) {
    if (K - Q + S.at(i) > 0) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

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

long long com(long long n,long long k){
	
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<4;i++){
		if(s[i]=='2')ans++;
	}
	cout<<ans<<endl;
}

	


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<cctype>
using namespace std;

typedef long long ll;
const int Maxn=610000;

int n,a[Maxn];
map<int,int> ma;

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);ma[a[i]]++;
	}int ans=0;
	sort(a+1,a+n+1);
	for(int i=n;i>=1;i--) {
		if(ma[a[i]]==0) continue;
		ma[a[i]]--;
		int l=1;
		while(l<=a[i]) l<<=1;
		if(ma[l-a[i]]!=0) {
			ans++;
			ma[l-a[i]]--;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 19712
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
template<class T> void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
using namespace std;

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

	int count = 0;
	for (int i = 1; i <= C; i++) {
		B -= A;
		if (B < 0) {
			break;
		}
		else {
			count++;
		}
	}

	cout << count << endl;
}

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


int MOD=1000000007;

int main(void){
    long long N,K,Q,B;
    cin >> N >> K >> Q;
    long long A[N+10];
    for(long long i=1; i<=N; i++){
        A[i]=K;
    }
    for(long long i=0; i<Q; i++){
        cin >> B;
        A[B]+=1;
    }
    for(long long i=1; i<=N; i++){
        if(A[i]-Q>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	int n;cin >> n;
	int ans = 0;
	vector<ll> v(n + 10, LLINF);

	REP(i, n){
		ll now;cin >> now;
		auto it = upper_bound(ALL(v), -now);
		if(*it == LLINF){
			ans++;
		}
		*it = -now;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long  a,b,c,x,y;
	while(cin>>a>>b>>c>>x>>y){
	if((a+b)<2*c) 	cout<<x*a+y*b<<endl;
	else 
	{
		long long ans=0;
		if(x>y) {
			ans+=(y*2)*c;
			if(a>2*c) ans+=(x-y)*2*c;
			else ans+=(x-y)*a;
			
		}
		else {
			ans+=(x*2)*c;
			if(b>2*c) ans+=(y-x)*2*c;
			else ans+=(y-x)*b;
		
		}
		cout<< ans<<endl;	
	}
	}
	
	
 } 

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s,int v,vector<int>&d,whei(edge)&G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size();i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

int main() {
	int n;
	cin >> n;
	vector<pair<string, pair<int, int>>> a(n);
	rep(i, 0, n) {
		int s;
		cin >> a[i].first >> s;
		a[i].second.first = 100 - s;
		a[i].second.second = i + 1;
	}
		sort(a.begin(), a.end());
		rep(i, 0, n) {
			cout << a[i].second.second << endl;
		}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
#define x first
#define y second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(n) n.begin(),n.end()
int main(){
	int n;
	
	while(cin >> n,n){		
		int ret = 0;
		
		vector<P> data;
		rep(i,n){
			P t;
			cin >> t.x >> t.y;
			data.push_back(t);
		}
		sort(all(data));
		
		rep(i,n){
			rep(j,n){
				if(i == j)continue;
				
				P dis;
				dis.x = data[i].x - data[j].x;
				dis.y = data[i].y - data[j].y;
				
				P tg1,tg2;
							
				tg1.x = data[i].x - dis.y;
				tg1.y = data[i].y + dis.x;
				
				tg2.x = data[j].x - dis.y;
				tg2.y = data[j].y + dis.x;
				
				if(binary_search(all(data),tg1) && binary_search(all(data),tg2)){
					ret = max(ret,dis.x * dis.x + dis.y * dis.y);
				}
			}
		}
		cout << ret << endl;
	}
	
}
	

Measured memory_bytes: 968
#include <iostream>		 // cout, endl, cin
#include <string>		 // string, to_string, stoi
#include <vector>		 // vector
#include <algorithm>	 // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>		 // pair, make_pair
#include <tuple>		 // tuple, make_tuple
#include <cstdint>		 // int64_t, int*_t
#include <cstdio>		 // printf
#include <map>			 // map
#include <queue>		 // queue, priority_queue
#include <set>			 // set
#include <stack>		 // stack
#include <deque>		 // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>		 // bitset
#include <cctype>		 // isupper, islower, isdigit, toupper, tolower
#include <cmath>	
using namespace std;

int main()
{
	int n, y;
	cin >> n >> y;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			int k = n - i - j;
			if(k < 0){
				break;
			}
			if(10000 * i + 5000 * j + 1000 * k == y){
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int>A(26,1e9);
	for (int i = 0; i < N; ++i) {
		vector<int>Asub(26);
		string S;
		cin >> S;
		for (int j = 0;j<S.size();++j) {
			Asub[S[j]-'a']++;
		}
		for (int j = 0;j<26;++j) {
			A[j] = min(A[j],Asub[j]);
		}
	}
	string ans;
	for (int i = 0;i<26;++i) {
		for (int j = 0;j<A[i];++j) {
			ans += (char)('a'+i);
		}
	}
	cout << ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

struct UnionFind {
    vector<int> par;
    vector<int> rnk;

    UnionFind(int n) {
        par.assign(n, 0);
        rnk.assign(n, 1);
        for(int i=0; i<n; i++) {
            par[i] = i;
        }
    }

    void unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return;
        if(rnk[x] < rnk[y]) swap(x, y);
        rnk[x] += rnk[y];
        par[y] = x;
    }

    int find(int x) {
        if(par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return rnk[find(x)];
    }
};

struct edge {
    int u, v, cost;
};

bool cmp(edge a, edge b) {
    return a.cost < b.cost;
}

V(edge) G;

//クラスカル法による解法
int kruscal() {
    int res = 0;
    UnionFind uf(100050);
    sort(ALL(G), cmp);
    rep(i, G.size()) {
        if(!uf.same(G[i].u, G[i].v)) {
            res += G[i].cost;
            uf.unite(G[i].u, G[i].v);
        }
    }
    return res;
}

signed main() {
    int N;
    cin >> N;
    V(P) X(N), Y(N);
    rep(i, N) {
        int x, y;
        cin >> x >> y;
        X[i] = P(x, i);
        Y[i] = P(y, i);
    }
    SORT(X); SORT(Y);

    rep(i, N-1) {
        G.pb(edge{X[i].se, X[i+1].se, abs(X[i].fi-X[i+1].fi)});
        G.pb(edge{Y[i].se, Y[i+1].se, abs(Y[i].fi-Y[i+1].fi)});
    }

    cout << kruscal() << endl;
    
    return 0;
}

Measured memory_bytes: 11504
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,0,n)

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

int n,m;
ll a[86];
ll k;
string s;

int main() {
	cin >> n;
	REP(i,4){
		a[i] = n%10;
		dump(a[i]);
		n /= 10;
	}
	reverse(a, a+4);
	REP(i, 1<<3){
		int sum = a[0];
		REP(j, 3){
			sum += a[j+1] * ((i & (1<<j)) ? 1 : -1);
		}
		dump(sum);
		if(sum==7){
			dump(a[0]);
			cout << a[0];
			REP(j, 3){
				cout << ((i & (1<<j)) ? "+" : "-");
				cout << a[j+1];
			}
			cout <<"=7"<< endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;
const double pi = 3.1415926;

double caculateDistance(const double arrayX[],const double arrayY[],int n,int p){
    double res = 0.0;
    switch (p)
    {
    case 1:
        for(int i = 0;i<n;i++){
            res = res+fabs(arrayX[i] - arrayY[i]);
        }
        break;
    case 2:
        for(int i = 0;i<n;i++){
            res = res+fabs(arrayX[i] - arrayY[i])*fabs(arrayX[i] - arrayY[i]);
        }
        res = sqrt(res);
        break;
    case 3:
        for(int i = 0;i<n;i++){
            res = res+fabs(arrayX[i] - arrayY[i])*fabs(arrayX[i] - arrayY[i])*fabs(arrayX[i] - arrayY[i]);
        }
        res = pow(res,0.3333333333);
        break;
    case 1001:
        for(int i = 0;i<n;i++){
            double temp = fabs(arrayX[i] - arrayY[i]);
            if(res < temp){
                res = temp;
            }
        }
        break;
    default:
        break;
    }
    return res;
}

int main(){
  int n;
  double x[101] = {0};
  double y[101] = {0};
  double get_number;
  cin>>n;
  for(int i = 0;i< 2;i++){
      for(int j = 0;j<n;j++){
          cin>>get_number;
          if(i == 0){
              x[j] = get_number;
          }else{
              y[j] = get_number;
          }
      }
  }
  
  cout<<setiosflags(ios::fixed)<<setprecision(6)<<caculateDistance(x,y,n,1)<<endl;
  cout<<setiosflags(ios::fixed)<<setprecision(6)<<caculateDistance(x,y,n,2)<<endl;
  cout<<setiosflags(ios::fixed)<<setprecision(6)<<caculateDistance(x,y,n,3)<<endl;
  cout<<setiosflags(ios::fixed)<<setprecision(6)<<caculateDistance(x,y,n,1001)<<endl;
  return 0;
}


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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

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

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("D.in", "r", stdin);
	freopen ("D.out", "w", stdout);
#endif
}

const int N = 1e5 + 1e3;

struct edge {
	int u, v, w;
	edge(int u_ = 0, int v_ = 0, int w_ = 0): u(u_), v(v_), w(w_) {};
} E[N << 1];

int n, m, p[N], x[N], y[N], fa[N];

int find(int x) { 
	return fa[x] == x ? x : fa[x] = find(fa[x]); 
}

int main() {

	File();

	n = read();
	For (i, 1, n)
		x[i] = read(), y[i] = read(), fa[i] = p[i] = i;

	sort(p + 1, p + n + 1, [&](int a, int b) { return x[a] < x[b]; });
	For (i, 1, n - 1) E[++ m] = edge(p[i], p[i + 1], x[p[i + 1]] - x[p[i]]);

	sort(p + 1, p + n + 1, [&](int a, int b) { return y[a] < y[b]; });
	For (i, 1, n - 1) E[++ m] = edge(p[i], p[i + 1], y[p[i + 1]] - y[p[i]]);

	long long ans = 0;
	sort(E + 1, E + m + 1, [&](edge a, edge b) { return a.w < b.w; } );
	For (i, 1, m) {
		int u = E[i].u, v = E[i].v, w = E[i].w;
		if (find(u) != find(v))
			fa[find(u)] = find(v), ans += w;
	}
	printf ("%lld\n", ans);

	return 0;

}

Measured memory_bytes: 4224
import copy as c
n,*a=open(0).read().split()
n=int(n)
b=c.deepcopy(a)
for i in range(n):
    for j in range(n-1,0,-1):
        if int(b[j][1])<int(b[j-1][1]):
            b[j],b[j-1]=b[j-1],b[j]
print(*b)
print("Stable")

for i in range(n):
    minj=i
    for j in range(i,n):
        if int(a[j][1])<int(a[minj][1]):
            minj=j
    a[i],a[minj]=a[minj],a[i]
print(*a)
if a!=b:
    print("Not stable")
else:
    print("Stable")



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

int main(){
    int n;
    cin >>n;
    vector<int> blue(n);
  for(int i=0;i<n;i++){
    cin >>blue[i];
     }
  
  int ans=0;
  for(int i=0;i<n;i++){
    int plus=blue[0];
    int count=0;
    for(int j=0;j<n;j++){
      if(blue[j]>plus){
        plus=blue[j];
        count=j;
      }
    }
   blue[count]=0;  
    if(i%2==0){ ans=ans+plus;}
    else{ans=ans-plus;}
  }
  
  cout << ans <<endl;
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<string, pair<int,int>> pii;

int main(){

  int n;
  cin >> n;

  vector<int> p(n);
  vector<pii> v;
  REP(i,n){
      string s;
      cin >> s >> p[i];
      v.pb(MP(s, MP(-p[i], i+1)));
  }

  sort(ALL(v));
  REPI(itr, v){
      cout << itr->second.second << endl;
  }


  return 0;
}



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

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

    int cnt = 0;
    for(int i = 0;  i < (int)s.length(); i++){
        if(s[i] == 'g') cnt++;
        else cnt--;
    }
    if(cnt == 0){
        cout<<0;
        return 0;
    }
    if(cnt>0){
        cout<<(cnt/2);
        return 0;
    }
    cout<<(cnt-1)/2;
}


Measured memory_bytes: 512
n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
    dp[i] = min(
        # 2つ前の足場からジャンプした時のコスト
        dp[i-2] + abs(h[i] - h[i-2]),
        # 1つ前の足場からジャンプした時のコスト
        dp[i-1] + abs(h[i]-h[i-1]))
print(dp[-1])

Measured memory_bytes: 52208
import Control.Applicative

main :: IO ()
main = do  
  x <- getInts
  let a = x !! 0 - x !! 1
      b = x !! 1 - x !! 2
  if a < 0 && b < 0 then putStrLn "Yes"
  else putStrLn "No"




getInts = do 
  x <- getLine 
  let y = (map$toInt)$words x
  return y

toInt :: (String -> Int)
toInt x = read x :: Int


Measured memory_bytes: 3600
def main():
    n = int(input())
    mod = 10 ** 9 + 7

    a = 9 ** n
    b = 9 ** n
    c = 8 ** n

    ans = 10 ** n - (a + b - c)

    print(ans % mod)


if __name__ == "__main__":
    main()


Measured memory_bytes: 86056
N=int(input())
l=[]
for x in range(0,N):
    l.append(input())
for x in range(N):
    k=list(l[x])
    k.sort()
    k=''.join(k)
    l[x]=k
l.sort()
k=1
ans=0
for i in range(N-1):
    if l[i]==l[i+1]:
        k+=1
    else:
        ans+=k*(k-1)//2
        k=1
ans+=k*(k-1)//2
print(ans)


Measured memory_bytes: 10584
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin>>n;
	
	string str;
	
	vector<string> vec;
	
	for(int i=0;i<n;i++)
	{
	    cin>>str;
	    vec.push_back(str);
	}
	
	sort(vec.begin(),vec.end());
	/*
	for(int i=0;i<vec.size();i++)
	{
	    cout<<vec[i]<<endl;
	}
	*/
	
    map<string,int> mp;
    
    for(int i=0;i<vec.size();i++)
    {
        mp[vec[i]]++;
    }
	
	int max = 0;
	
	for(auto it: mp)
	{
	    //cout<<it.first<<" "<<it.second<<endl;
	    if(it.second >= max)
	    max = it.second;
	}
	
	for(auto it: mp)
	{
	    if(it.second == max)
	    {
	        cout<<it.first<<endl;
	    }
	}

}

Measured memory_bytes: 25456
N = int(input())
a = [int(input()) for i in range(N)]
a.sort()
goukei = sum(a)

if goukei % 10 == 0:
    for i in range(N):
        if a[i] % 10:
            goukei -= a[i]
            break

print(goukei if goukei % 10 else 0)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll INF = 1e18;

int main(){
  int N, M, X;
  cin >> N >> M >> X;
  vector<pair<int,vector<int>>> v;
  rep(i,N){
    int c;
    cin >> c;
    vector<int> tmp;
    rep(j,M){
      int a;
      cin >> a;
      tmp.push_back(a);
    }
    v.emplace_back(c, tmp);
  }


  ll ret = INF;
  for(ll S=1; S<(1<<N); S++){
    vector<int> w;
    rep(i,N){
      if((S>>i)&1) w.push_back(1);
      else w.push_back(0);
    }
    ll tmp = 0;
    vector<int> A(M, 0);
    rep(i,N){
      if(w[i] == 0) continue;
      tmp += v[i].first;
      rep(j,M){
        A[j] += v[i].second[j];
      }
    }
    bool flg = true;
    rep(i,M){
      if(A[i] < X) flg = false;
    }

    if(flg){
      ret = min(ret, tmp);
    }
  }

  if(ret == INF) cout << -1 << endl;
  else cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_091
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            int[] bArray = ReadInts();
            var aMods = new int[30][];
            var bMods = new int[30][];
            for (int i = 0; i < 30; i++)
            {
                aMods[i] = new int[n];
                bMods[i] = new int[n];
                int div = 2 << i;
                for (int j = 0; j < n; j++)
                {
                    aMods[i][j] = array[j] % div;
                    bMods[i][j] = bArray[j] % div;
                }
            }

            var cnts = new long[30];
            for (int i = 0; i < 30; i++)
            {
                Array.Sort(aMods[i]);
                Array.Reverse(aMods[i]);
                Array.Sort(bMods[i]);
                int t = 1 << i;
                int[] itrs = new int[4];
                for (int j = 0; j < n; j++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        while (itrs[k] < n
                            && bMods[i][itrs[k]] < t * (k + 1) - aMods[i][j])
                            itrs[k]++;
                    }
                    cnts[i] += itrs[1] - itrs[0];
                    cnts[i] += itrs[3] - itrs[2];
                    //Console.Write(cnts[i] + " ");
                }
                //Console.WriteLine();
            }
            long res = 0;
            for (int i = 0; i < 30; i++)
            {
                //Console.WriteLine(cnts[i]);
                if (cnts[i] % 2 > 0) res += 1 << i;
            }
            Console.WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 80848
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll MOD = (ll)1e9 + 7LL;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	vector<ll> x(n, 0LL);
	rep (i, n){
		cin >> x[i];
	} // end rep
	vector<ll> y(m, 0LL);
	rep (j, m){
		cin >> y[j];
	} // end rep

	ll xsum = 0LL;
	rep (k, n){
		xsum += k * x[k] - (n - k - 1)*x[k];
		xsum %= MOD;
	} // end rep

	ll ysum = 0LL;
	rep (k, m){
		ysum += k * y[k] - (m - k - 1)*y[k];
		ysum %= MOD;
	} // end rep

	ll res = xsum;
	res *= ysum;
	res %= MOD;

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1792
x,y,z,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
AB=[]
for a in A:
    for b in B:
        AB.append(a+b)
AB=sorted(AB,reverse=True)[:k]
ABC=[]
for ab in AB:
    for c in C:
        ABC.append(ab+c)
ABC.sort(reverse=True)
for abc in ABC[:k]:
    print(abc)

Measured memory_bytes: 143096
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

@njit((i8, i8, i8, i8[:]), cache=True)
def solve(R,C,K,XYV):
  item = np.zeros((R + 1, C + 1), dtype=np.int64)
  for i in range(0, 3 * K, 3):
    x, y, v = XYV[i:i + 3]
    item[x - 1, y - 1] = v
  dp = np.zeros((C+1,4), dtype=np.int64)
  for i in range(1,R+1):
    new_dp = np.zeros((C+1,4), dtype=np.int64)
    #上から移動
    for k in range(4):
      new_dp[:,0] = np.maximum(new_dp[:,0], dp[:,k])
    dp = new_dp
    for j in range(1,C+1):
      #横から移動
      new_dp[j] = np.maximum(new_dp[j],new_dp[j-1])
      #アイテムを取る
      for k in range(2,-1,-1):
        dp[j,k+1] = np.maximum(dp[j,k+1],dp[j,k]+item[i-1,j-1])
  ans = dp[-1].max()
  return ans

R, C, K = map(int, readline().split())
XYV = np.array(read().split(), np.int64)
print(solve(R,C,K,XYV))


Measured memory_bytes: 186484
#include <bits/stdc++.h>
 
typedef long long ll;
using namespace std;
const int MOD = 1e9+7;
ll cache[123456];
ll calc(int cnt[], int n) {
	if(n==0) {
		return 0;
	}
	if(n==1) {
		return cnt[n];
	}
	
	if(cache[n]!=-1) {
		return cache[n];
	}
	// if we select nth element, then we cant get previous(n-1) result, 
	// we need to get it from prevoious of the previous(n-2) result
	// because previous(n-1) was removed according to game rules
	ll point = 1ll*n*cnt[n];
	cache[n] = max(calc(cnt, n-1), calc(cnt, n-2) + point);
	return cache[n];
}
int main() {
	int n;
	cin>>n;
	while(n) {
		int a = n%10;
		if(a==7) {
			cout <<"Yes";
			return 0;
		}
		n/=10;
	}
	cout <<"No";
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  ll ans = 0;
  int t = n - 1;
  rep(i,n) {
    int lim = 2;
    if (i == 0) lim = 1;
    rep(j,lim) {
      if (t > 0) {
        ans += a[i];
        t--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
N = int(input())
Wlist = list(map(int,input().split()))

minimum = -1
for i in range(N):
    sum1 = sum(Wlist[:i+1])
    sum2 = sum(Wlist[i+1:])
    diff = abs( sum1-sum2)
    #print( "sum1={} sum2={} diff={}".format(sum1,sum2,diff))
    if minimum == -1 or minimum > diff:
        minimum = diff
print(minimum)

Measured memory_bytes: 3060
x = int(input())
a = list(False for i in range(x + 1))
a[0] = True
for i in range(1, x + 1):
    for j in range(6):
        if (i - 100 - j) >= 0:
            if a[(i - 100 - j)]:
                a[i] = True
if a[x]:
    print(1)
else:
    print(0)

Measured memory_bytes: 3876