akhauriyash/Code-Regression huggingface dataset:
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
#define dcml(n) fixed<<setprecision(n)

 
ll GCD(ll a,ll b) { return b ? GCD(b,a%b) : a; } 
ll LCM(ll a,ll b) { return a/GCD(a,b)*b; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 



using namespace std;
//-------------------------------------------
typedef pair<ll,ll> P;
int main(void){
    ll A,B,C;cin>>A>>B>>C;
    ll cnt=0;
    while(!(A==B&&B==C)){
        if(A==B&&A>C){C+=2;cnt++;}
        else if(A==C&&A>B){B+=2;cnt++;}
        else if(C==B&&B>A){A+=2;cnt++;}

        else if(A==B&&A<C){A++;B++;cnt++;}
        else if(A==C&&A<B){A++;C++;cnt++;}
        else if(C==B&&B<A){B++;C++;cnt++;}

        else{
            if(A<B&&B<C){A++;B++;cnt++;}
            else if(B<C&&C<A){C++;B++;cnt++;}
            else if(C<A&&A<B){A++;C++;cnt++;}

            else if(B>C&&C>A){C++;A++;cnt++;}
            else if(C>A&&A>B){A++;B++;cnt++;}
            else if(A>B&&B>C){B++;C++;cnt++;}

        }
    }
    cout<<cnt<<"\n";
    
}

Measured memory_bytes: 256
import java.util.Scanner;

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

Measured memory_bytes: 58168
S = input()
T = input()
dp = [[-1 for i in range(len(S)+1)] for j in range(len(T)+1)]
sub = [["" for i in range(len(S)+1)] for j in range(len(T)+1)]
for a in range(len(S)+1):
	dp[0][a] = 0
for b in range(len(T)+1):
	dp[b][0] = 0
for p in range(1, len(T)+1):
	for q in range(1, len(S)+1):
		if T[p-1] == S[q-1]:
			dp[p][q] = 1 + dp[p-1][q-1]
			sub[p][q] = "c"
		else:
			if dp[p-1][q] > dp[p][q-1]:
				dp[p][q] = dp[p-1][q]
				sub[p][q] = "u"
			else:
				dp[p][q] = dp[p][q-1]
				sub[p][q] = "l"
t = len(T)
s = len(S)
out = ""
while sub[t][s] != "":
	if sub[t][s] == "c":
		out = S[s-1] + out
		t -= 1
		s -= 1
	elif sub[t][s] == "u":
		t -= 1
	else:
		s -= 1
print(out)

Measured memory_bytes: 191752
package main

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

func main() {
	N := nextInt64()
	m := N - 1

	for x := int64(2); x*x <= N; x++ {
		if N%x != 0 {
			continue
		}
		y := N / x
		m = min(m, x+y-2)
	}

	fmt.Println(m)
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 640
dct = {
    'AC': 0,
    'WA': 0,
    'TLE': 0,
    'RE': 0,
}
N = int(input())
for i in range(N):
    S = input()
    dct[S] = dct[S] + 1

print('AC x %s' % dct['AC'])
print('WA x %s' % dct['WA'])
print('TLE x %s' % dct['TLE'])
print('RE x %s' % dct['RE'])

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

typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back

int main() {
    string a,b;
    cin>>a>>b;
    b.erase(b.find('.'),1);
    ll ans=stoll(a)*stoi(b);
    string s=to_string(ans);
    if(s.size()<=2) cout<<0<<endl;
    else {
        s.pop_back();s.pop_back();
        cout<<s<<endl;
    }
}

Measured memory_bytes: 3628
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int x[]=new int[n];
		for(int i=0;i<n;i++) {
			x[i]=scan.nextInt();
		}
		for(int i=n-1;i>0;i--) {

			System.out.print(x[i]+" ");
		}
		System.out.println(x[0]);
		scan.close();
	}

}


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

void insertionSort(vector<int> &A) {
    for (int i = 1; i < A.size(); ++i) {
        int v = A.at(i);
        int j = i - 1;
        while (j >= 0 && A.at(j) > v) {
            A.at(j + 1) = A.at(j);
            --j;
        }
        A.at(j + 1) = v;
        rep(i, A.size()) {
            if (i) cout << ' ';
            cout << A.at(i);
        }
        cout << endl;
    }
}

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

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A.at(i);
    rep(i, A.size()) {
        if (i) cout << ' ';
        cout << A.at(i);
    }
    cout << endl;
    insertionSort(A);

    return 0;
}


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


Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <vector>
#include <set>
#include <queue>

using namespace std;

int H, W;

set<std::pair<int, int>> blacks;
vector<std::pair<int, int>> q, new_queue;

void add(int x, int y) {
  if (x >=0 && y >= 0 && x < H && y < W) {
    if (blacks.count(make_pair(x, y)) == 0) {
      blacks.emplace(x, y);
      new_queue.emplace_back(x, y);
    }
  }
}

int main() {
  cin >> H >> W;

  string s;
  for (int i = 0; i < H; i++) {
    cin >> s;
    for (int x = 0; x < W; x++) {
      if (s[x] == '#') {
        blacks.emplace(i, x);
        q.emplace_back(i, x);
      }
    }
  }

  size_t end = (size_t)(H * W);
  int ans = 0;
  while (blacks.size() != end) {
    for (const auto &p : q) {
      add(p.first-1, p.second);
      add(p.first+1, p.second);
      add(p.first, p.second+1);
      add(p.first, p.second-1);
    }

    swap(q, new_queue);
    new_queue.clear();
    ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 54888
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
	vector<string> rec;

	int m, f, r;
	while (cin >> m >> f >> r) {
		if (m == -1 && f == -1 && r == -1) {
			break;
		}

		if (m == -1 || f == -1) {
			rec.push_back(string("F"));
		}
		else if (m + f >= 80) {
			rec.push_back(string("A"));
		}
		else if (m + f >= 65 && m + f < 80) {
			rec.push_back(string("B"));
		}
		else if (m + f >= 50 && m + f < 65) {
			rec.push_back(string("C"));
		}
		else if(m + f >= 30 && m + f < 50){
			if (r >= 50) {
				rec.push_back(string("C"));
			}
			else {
				rec.push_back(string("D"));
			}
		}
		else if(m + f < 30) {
			rec.push_back(string("F"));
		}
	}

	for (int i = 0; i < rec.size(); i++) {
		cout << rec[i] << endl;
	}

	return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

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

  vector<int> wsum(n, 0), esum(n, 0);
  rep(i, n) {
    if (i) {
      wsum[i] = wsum[i - 1];
      esum[i] = esum[i - 1];
    }
    if (s[i] == 'W') wsum[i]++;
    if (s[i] == 'E') esum[i]++;
  }

  int ans = n;
  rep(i, n) {
    int tmp = 0;
    tmp += esum[n - 1] - (i ? esum[i - 1] : 0);
    if (s[i] == 'E') tmp--;
    tmp += (i ? wsum[i - 1] : 0);
    ans = min(ans, tmp);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3076
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    ll N;
    io.read(N);
    vector<int> A(N);
    vector<int> B(N);
    for(int i = 0; i < N; i++){
        io.read(A[i], B[i]);
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int ans;
    if(N % 2){
        ans = B[N / 2] - A[N / 2] + 1;
    }
    else{
        ans = B[N / 2 - 1] + B[N / 2] - A[N / 2 - 1] - A[N / 2] + 1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4756
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <time.h>
#include <string.h>
#include <queue>
#include <complex>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef complex<double> base;
ll mod=1e9+7;
double eps=1e-9;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ll pexp(ll x, ll y){if(y<0) return 0; ll ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
int n, k, q; ll ans=1e9;
ll a[2111], lef, rig, mid, best;
int chk[2111], ps[2111];

ll pos(ll x, ll dt) // erase is from [x~x+dt]
{
	int i, lst=0, tp=0, ret=0;
	for(i=1 ; i<=n ; i++)
	{
		if(x<=a[i] && a[i]<=x+dt) chk[i]=1;
		if(a[i]<x) chk[i]=-5000;
		if(a[i]>x+dt) chk[i]=0;
		ps[i]=ps[i-1]+chk[i];
	}	
	for(i=1 ; i<=n ; i++)
	{
		if(ps[i]<ps[lst]) // lst+1~i -> negative exist
		{
			lst=i; tp=0; 
		}
		if(lst+k<=i) // array leng>=k
		{
			if(ps[i]>ps[lst]+tp)
			{
				ret++; tp++;
			}
			else if(ps[i]<ps[lst])
			{
				lst=i; tp=0;
			}
		}
	}
	return ret;
}

ll gv(ll x)
{
	lef=0; rig=1e9; best=1e9;
	while(lef<=rig)
	{
		mid=(lef+rig)/2;
		if(pos(x,mid)>=q)
		{
			best=mid;
			rig=mid-1;
		}
		else
		{
			lef=mid+1;
		}
	}	
	return best;
}

int main(void)
{
	cin>>n>>k>>q; int i;
	for(i=1 ; i<=n ; i++) scanf("%lld",&a[i]);
	for(i=1 ; i<=n ; i++) ans=min(ans,gv(a[i]));
	cout<<ans; return 0;
}

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

using namespace std;
int main() {
    long long int n;
    cin >> n;
    vector<long long int> a;
    int temp;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        a.push_back(temp);
    }
    vector<long long int> kakeru;
    for (int i = 0; i < n; i++) {
        kakeru.push_back(a[i] * 2);
    }

    long long int mass = 0;
    for (int i = 0; i < n; i++) {
        mass += kakeru[i] * pow(-1, i);
    }
    vector<int> ans;
    ans.push_back(mass / 2);
    for (int i = 0; i < n-1; i++) {
        ans.push_back(kakeru[i] - ans[i]);
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
    }


    return 0;
    
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
void solve() {
        int m1, d1, m2, d2;
        cin >> m1 >> d1 >> m2 >> d2;
        if(m2 == m1+1) {
                if(d2 == 1)
                        cout << "1\n";
        }
        else
                cout << "0\n";
        return;
}
int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        solve();
        return 0;
}



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

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

using namespace std;

void solve(int n, int num)
{
	for(int i=num;i>=1;i--)
	{
		if(n>=i)
		{
			printf("%d\n",i);
			n-=i;
		}
	}
}

int main()
{
	int n=0;
	int sum=0;
	
	cin>>n;
	
	reps(i,1,n+1)
	{
		sum += i;
		if(sum >=n){solve(n,i);break;}
	}
}

Measured memory_bytes: 256
#include<stdio.h>


#define N 100

int data[N],num1,num2;

int flag=0;

int solve(int i,int m){

  if(i>num1) return 0;
  else if(m<0) return 0;
  else if(m== 0 || m-data[i] == 0){
    flag=1;
    return 1;
  }
    else{
      solve(i+1,m);
      solve(i+1,m-data[i]);
  }    
}

int main(){

  int i,m;

  scanf("%d",&num1);

  for(i=0;i<num1;i++){
    scanf("%d",&data[i]);
  }

  scanf("%d",&num2); 

  for(i=0;i<num2;i++){
    scanf("%d",&m);
    flag=0;

    solve(-1,m);
    if(flag==1){
      printf("yes\n");
    }  
    else printf("no\n");
  }

  return 0;
}

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

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

    string ans = "";
    do
    {
        if(n % 2 == 0)
        {
            ans = "0" + ans;
            n = n / -2;
        }
        else
        {
            ans = "1" + ans;
            n = (1 - n) / 2;
        }
    }
    while(n != 0);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define db double
#define il inline
#define re register
#define mkpr make_pair

using namespace std;
const int N=1e6+10,mod=1e9+7;
il LL rd()
{
    LL x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
int n,m,f[N],ans;

int main()
{
    //???
	n=rd();
	m=(1ll*(n-1)*(n-1))%mod;
	ans=m+1+(n>2);
	int sm=f[0]=1;
	for(int i=1;i<n;++i)
	{
		f[i]=sm;
		if(i-2>=0) f[i]=(f[i]-f[i-2]+mod)%mod;
		sm=(sm+f[i])%mod;
		if(i!=n-1) ans=(ans+1ll*f[i]*(m+min(i+2,n-1))%mod)%mod;
		else ans=(ans+1ll*f[i]*n%mod)%mod;
	}
	printf("%d\n",ans);
    return 0;
}



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

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    vector<int> v = {a,b,c};
    sort(v.begin(), v.end());
    int ans = v[2] * 10 + v[1] + v[0];
    
    cout << ans << endl;
    return 0;
}

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

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

int main()
{
    int N;
    cin >> N;
    set<int> s;
    vector<int> num(1e+6+1, 0);
    REP(i, N){
        int A;
        cin >> A;
        s.insert(A);
        ++num[A];
    }

    int ans = 0;
    vector<bool> divide(1e+6+1, false);
    for(auto v: s){
        if(!divide[v] and num[v] == 1) ++ans;
        int tmp = v;
        for(int j = 1; tmp <= 1e+6; ++j){
            tmp = v*j;
            // if(divide[tmp]) break;
            divide[tmp] = true;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 16604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define endl "\n"
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e16;
const double PI = acos(-1);
const int N = 1e6 + 7;
int mod = 1e9 + 7;

int32_t main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> dis(n);
    for(int i = 1; i <= n; i++)
    {
    	for(int j = i + 1; j <= n; j++)
    	{
    		int tmp = abs(x - i) + 1 + abs(y - j);
    		int d = min(j-i, tmp);
    		dis[d]++;
    	}
    }
    for(int i = 1; i < n; i++)
    	cout << dis[i] << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int 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; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> v;
    rep(i,n){
        ll a, b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }
    sort(v.begin(), v.end());
    ll ans = 0;
    rep(i,n){
        if(v[i].second >= m){
            ans += v[i].first * m;
            m = 0;
            break;
        }
        ans += v[i].first * v[i].second;
        m -= v[i].second;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n;
  int a[SIZE];

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

  int cn = 0;

  vector<int> ans;
  
  for(int i=n/2*2;i>0;i-=2){
    ans.push_back(a[i-1]);
  }
  for(int i=1;i<=n;i+=2){
    ans.push_back(a[i-1]);
  }

  if(n%2) reverse(ans.begin(),ans.end());

  for(int i=0;i<n;i++){
    printf("%d%c",ans[i], " \n"[i==n-1]);
  }
  
  return 0;
}


Measured memory_bytes: 3828
class BIT:
  def __init__(s, n):
    s._n = n
    s.data = [0] * n
  def add(s, p, x):
    p += 1
    while p <= s._n:
      s.data[p - 1] += x
      p += p & -p
  def sum(s, l, r):
    return s.zum(r) - s.zum(l)
  def zum(s, r):
    ans = 0
    while r > 0:
      ans += s.data[r - 1]
      r -= r & -r
    return ans

N, Q = list(map(int, input().split()))
a = list(map(int, input().split()))
Query = [list(map(int, input().split())) for _ in range(Q)]
  
bit = BIT(N)
for i in range(N):
  bit.add(i, a[i])
 
for q in Query:
  if q[0] == 0:
    _, p, x = q
    bit.add(p, x)
  else:
    _, l, r = q
    print(bit.zum(r) - bit.zum(l))


Measured memory_bytes: 174912
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto abc = readln.split.to!(int[]);
    auto A = abc[0];
    auto B = abc[1];
    auto C = abc[2];
    auto K = readln.chomp.to!int;

    int k;
    while (B <= A) {
        ++k;
        B *= 2;
    }
    while (C <= B) {
        ++k;
        C *= 2;
    }
    writeln(k <= K ? "Yes" : "No");
}

Measured memory_bytes: 2684
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    int x, a, b;

    cin >> x >> a >> b;
    if (abs(a-x) > abs(b-x)) {
        cout << 'B' << endl;
    }
    else {
        cout << 'A' << endl;
    }
}


Measured memory_bytes: 256
//Bismillah hirrahmanir Rahim
            #include<bits/stdc++.h>
            #define ll long long
            #define pb push_back
            #define dbug printf("I am here\n");
            #define Fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
           using namespace std;
           int main() {
          map<string ,int>mp;
            ll int a,b,c,d,tst,n;
          string x;
          cin>>tst;ll cnt=0;
          while(tst--){
          cin>>x;
          if(mp[x]<1)cnt++;
          mp[x]++;
          }
          cout<<cnt<<endl;
            return 0;
          }


Measured memory_bytes: 19252
import sys
h, w = map(int, input().split())
if h%3==0 or w%3==0:
    print(0)
    sys.exit()
ans=h*w #inf
for i in range(1, h):
    s1=i*w
    s2=(h-i)*(w//2)
    s3=h*w-s1-s2
    now=max(s1, s2, s3)-min(s1, s2, s3)
    #print(i, now)
    ans=min(ans, now)
for j in range(1, w):
    s1=h*j
    s2=(w-j)*(h//2)
    s3=h*w-s1-s2
    now=max(s1, s2, s3)-min(s1, s2, s3)
    ans=min(ans, now)
if w>3:
    ans=min(ans, h)
if h>3:
    ans=min(ans, w)
print(ans)


Measured memory_bytes: 9076
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		double dbD1 = 0.0;
		double dbD2 = 0.0;
		double dbD3 = 0.0;
		double dbMax = 0.0;
		double xy;


		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

//			String str = br.readLine();
//			str = br.readLine();

			int n = Integer.parseInt(br.readLine() );
			int[] x = new int[n];
			int[] y = new int[n];


			String[] arrX = br.readLine().split(" ");
			String[] arrY = br.readLine().split(" ");

			for(int i=0; i<n; i++)
			{
				x[i] = Integer.parseInt(arrX[i]);
				y[i] = Integer.parseInt(arrY[i]);
			}


			//	int[][] intArrX = new int[2][arrX.length];


			//			str = br.readLine();
			//			String[] arrY = str.split(" ");

			//			for(int i=0; i<arrY.length; i++){
			//				intArrX[0][i] = Integer.parseInt(arrX[i]);
			//				//intArrX[1][i] = Integer.parseInt(arrY[i]);
			//				System.out.println(intArrX[0][i]  +" " + intArrX[1][i]);
			//			}

			for (int i = 0; i < n; i++) {
				xy = Math.abs(x[i] - y[i]);

				dbD1 += Math.pow(xy, 1);
				dbD2 += Math.pow(xy, 2);
				dbD3 += Math.pow(xy, 3);

				dbMax = Math.max(xy, dbMax);


//				dbD1 += Math.abs(intArrX[0][i] - intArrX[1][i]);
//
//				dbD2 += Math.abs(intArrX[0][i] - intArrX[1][i])
//						* Math.abs(intArrX[0][i] - intArrX[1][i]);
//
//				dbD3 += Math.abs(intArrX[0][i] - intArrX[1][i])
//						* Math.abs(intArrX[0][i] - intArrX[1][i])
//						* Math.abs(intArrX[0][i] - intArrX[1][i]);

				//if (i == 0) {

					//	dbMax = Math.abs(intArrX[0][i] - intArrX[1][i]);
				//} else {


//				if (dbMax < Math.abs(intArrX[0][i] - intArrX[1][i])) {
//					dbMax = intArrX[0][i] - intArrX[1][i];
//				}
//				//}

			}

			dbD2 = Math.sqrt(dbD2);
			dbD3 = Math.cbrt(dbD3);

			System.out.printf("%.6f",dbD1);
			System.out.println();
			System.out.printf("%.6f",dbD2);
			System.out.println();
			System.out.printf("%.6f",dbD3);
			System.out.println();
			System.out.printf("%.6f",dbMax);



		} catch (IOException e) {
			System.out.println(e);
		} catch (NumberFormatException e) {
			System.out.println("??°?????§??\??????????????????");
		}
	}
}

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

int main(){
    int w,h,x,y,r;

    cin >> w >> h >> x >> y >> r;
    cout << (x-r<0 || y-r<0 || x+r>w || y+r>h ? "No":"Yes") << endl;

    return 0;
}

Measured memory_bytes: 3076
def main():
  N, M = (int(_) for _ in input().split())
  MOD = 10 ** 9 + 7
  
  def fact(n):
    res = 1
    for i in range(n):
      res *= (i+1)
      res %= MOD
    return res
  
  ret = 0
  if abs(N - M) == 1:
    ret = (fact(N) * fact(M)) % MOD
  elif N == M:
    ret = (2 * fact(N) * fact(M)) % MOD
  else:
    pass
  print(ret)
  return

if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
struct Segment{
    int l,r;
    Segment(){}
    Segment(int l,int r):l(l),r(r){}
};
Segment b[200005];
int sum0[200005], sum1[200005];
//option0: 0 point
//f[0][i]: dp[i]-sum0[i], f[1][i]: dp[i]-sum1[i]
//once you sort by l, every thing is clear...
int f[200005][2];

struct SegmentT{
    int l,r;
    int d[2];
    SegmentT(){
        d[0] = d[1] = 10000007;
    }
};
SegmentT t[800005];

int min(int a,int b){ return a>b?b:a; }

SegmentT merge(SegmentT& u,SegmentT &v){
    SegmentT res;
    res.l = u.l, res.r = v.r;
    for(int i = 0; i < 2; i++) res.d[i] = min(u.d[i],v.d[i]);
    return res;
}

void build(int p,int l,int r){
    t[p].l = l, t[p].r = r;
    if(l!=r){
        int m = (l+r)/2;
        build(2*p,l,m);
        build(2*p+1,m+1,r);
        t[p] = merge(t[2*p],t[2*p+1]);
    }
}

void setV(int p,int x,int v,int tag){
    if(t[p].l==t[p].r){
        if(t[p].d[tag]>v) t[p].d[tag] = v;
    }
    else{
        int m = (t[p].l+t[p].r)/2;
        if(x<=m) setV(2*p,x,v,tag);
        else setV(2*p+1,x,v,tag);
        t[p] = merge(t[2*p],t[2*p+1]);
    }
}

SegmentT ask(int p,int l,int r){
    if(l<=t[p].l && r>=t[p].r) return t[p];
    else{
        int m = (t[p].l+t[p].r)/2;
        SegmentT u,v;
        if(l<=m) u = ask(2*p,l,r);
        if(r>=m+1) v = ask(2*p+1,l,r);
        return merge(u,v);
    }
}

int getMin(int l,int r,int tag){
    int res = 10000007;
    if(l>r) return res;
    else{
        //for(int i = l; i <= r; i++) if(f[i][tag]<res) res = f[i][tag];
        res = ask(1,l,r).d[tag];
        return res;
    }
}

void upDate(int p,int tag,int v){
    //if(f[p][tag]>v) f[p][tag] = v;
    setV(1,p,v,tag);
}

int main(){
    int n;
    scanf("%d",&n);
    sum0[0] = sum1[0] = 0;
    for(int i = 1; i <= n; i++){
        int u;
        scanf("%d",&u);
        sum0[i] = sum0[i-1], sum1[i] = sum1[i-1];
        if(u==0) sum0[i]++;
        else sum1[i]++;
    }
    int q;
    scanf("%d",&q);
    for(int i = 1; i <= q; i++) scanf("%d%d",&b[i].l,&b[i].r);
    for(int i = 1; i <= n; i++) f[i][0] = f[i][1] = 10000007;
    std::sort(b+1,b+1+q,[&](Segment& u,Segment& v){ return u.l<v.l; });
    int ans = sum1[n];
    build(1,1,n);
    for(int i = 1; i <= q; i++){
        int l = b[i].l, r = b[i].r;
        int res = sum0[r]-sum0[l-1]+sum1[l-1];
        int opt = getMin(1,l-1,1)+sum1[l-1]+sum0[r]-sum0[l-1];
        if(opt<res) res = opt;
        opt = getMin(l,r-1,0)+sum0[r];
        if(opt<res) res = opt;
        int offer = res+sum1[n]-sum1[r];
        if(offer<ans) ans = offer;
        upDate(r,0,res-sum0[r]);
        upDate(r,1,res-sum1[r]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 18876
import heapq
def hq(x,y,z):
    return (-A[x-1]-B[y-1]-C[z-1],x,y,z)
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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

visited=[hq(1,1,1)]
q=[]
heapq.heappush(q,hq(1,1,1))
for _ in range(K):
    e,x,y,z=heapq.heappop(q)
    if x+1<=X and hq(x+1,y,z) not in visited:
        heapq.heappush(q,hq(x+1,y,z))
        visited.append(hq(x+1,y,z))
    if y+1<=Y and hq(x,y+1,z) not in visited:
        heapq.heappush(q,hq(x,y+1,z))
        visited.append(hq(x, y+1, z))
    if z+1<=Z and hq(x,y,z+1) not in visited:
        heapq.heappush(q,hq(x,y,z+1))
        visited.append(hq(x, y, z+1))
visited.sort()
for i in visited[0:K]:
    print(-i[0])



Measured memory_bytes: 4972
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
//aoj 2170
using namespace std;
int n,q;
long long ans;
int f[100003];
int find(int x)
{
	if(f[x]==x)
	{
		return x;
	}else{
		return find(f[x]);
	}
}
int main()
{
	while(1)
	{
		scanf("%d%d",&n,&q);
		if(n==0&&q==0)
		{
			break;
		}
		ans=0;
		memset(f,0,sizeof(f));
		f[1]=1;
        for(int i=2;i<=n;i++)
		{
            scanf("%d",&f[i]);
        }
        for(int i=1;i<=q;i++)
		{
			int a;
			char pd;
			while(getchar()!='\n');
            scanf("%c%d",&pd,&a);
            if(pd=='Q')
			{
                ans+=(long long)find(a);
            }else{
                f[a]=a;
			}
        }
        printf("%lld\n",ans);
	}
	return 0;
}
	
	
	
	
	
	
	
	
	


Measured memory_bytes: 3000
#include "bits/stdc++.h"
using namespace std;
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
#define int long long
const int N = 1e6 + 10;
int cnt[N];
int32_t main()
{
   int n; cin >> n;
   int gc = 0;
   fr(_,n) {
   	int x; cin >> x;
   	gc = __gcd(gc, x);
   	cnt[x] ++;
   }
   bool ok = 1;
   for(int i= 2; i < N; i++){
   	int cc = 0;
   	for(int j= i; j < N; j+=i){
   		cc += cnt[j];
   	}
   	if(cc > 1) {ok = 0; break;}
   }
   if(ok) cout << "pairwise coprime\n";
   else if(gc == 1) cout << "setwise coprime\n";
   else cout << "not coprime\n";



}

Measured memory_bytes: 11392
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

struct Info{
	Info(){
		empty_bottle = fill_bottle = 0;
	}
	int empty_bottle,fill_bottle;
};

int main(){

	int N,R,T,total,location;
	scanf("%d %d %d",&N,&R,&T);
	int student[N];
	Info info[R];

	for(int i = 0; i < N; i++)scanf("%d",&student[i]);

	total = 0;
	for(int i = 1; i <= T; i++){

		for(int k = 0; k < R; k++){
			info[k].fill_bottle += info[k].empty_bottle;
			info[k].empty_bottle = 0;
		}

		for(int k = 0; k < N; k++){
			location = (student[k]*i)%R;

			if(i > 1){
				info[location].empty_bottle++;
			}
			if(info[location].fill_bottle == 0){
				total++;
			}else{
				info[location].fill_bottle--;
			}
		}
	}

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

    return 0;
}

Measured memory_bytes: 2772
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	register short f=1;x=0;char c=getchar();
	while(!isdigit(c)){ if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
	x*=f;
}
template<typename T>inline void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
template<typename T>inline void writeln(T x){
	write(x),putchar('\n');
}
int main(){
	long long a,b,x;
	read(a),read(b),read(x);
	write(!(a%x)?b/x-a/x+1:b/x-a/x);
	return 0;
}


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

char s[15];

int main()
{
    cin >> s;
    int flag = 1;
    for (int i = 0; s[i]; i += 2)
    {
        if (s[i] != 'h' || s[i+1] != 'i')
        {
            flag = 0;
            break;
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext()) {
			int[] a = new int[4];
			int[] b = new int[4];
			for(int i = 0; i < 4; i++) {
				a[i] = stdIn.nextInt();
			}
			for(int i = 0; i < 4; i++) {
				b[i] = stdIn.nextInt();
			}
			int hit = 0;
			int blow = 0;
			for(int i = 0; i < 4; i++) {
				for(int j = 0; j < 4; j++) {
					if(a[i] == b[j]) {
						if(i == j) {
							hit++;
						}
						else {
							blow++;
						}
					}
				}
			}
			System.out.println(hit + " " + blow);
		}
		
	}
}

Measured memory_bytes: 18100
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll l,r,d;
    cin >> l >> r >> d;
    ll ans=r/d-(l-1)/d;
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
 
#define rep(i, n)      for (int i = 0; i < (n); i++)
#define repr(i, n)     for (int i = (n) - 1; i >= 0; i--)
#define repe(i, l, r)  for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define repi(i, l, r)  for (int i = (l); i <= (r); i++)
#define repir(i, l, r) for (int i = (r); i >= (l); i--)
#define range(a) a.begin(), a.end()
void initio() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() { initio();
  int x, y; cin >> x >> y; x--; y--;
  int a[] = {300000, 200000, 100000, 0};
  cout << (a[min(3, x)] + a[min(3, y)] + (x == 0 && y == 0 ? 400000 : 0)) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  string s,t;
  cin >> s >> t;
  ll n=s.size();
  map<ll,ll> cs,ct;
  for(ll i=0;i<n;i++) {
    if(cs[s[i]]) {
      if(cs[s[i]]!=t[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
    cs[s[i]]=t[i];
    if(ct[t[i]]) {
      if(ct[t[i]]!=s[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
    ct[t[i]]=s[i];
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 776
n=int(input())
l=list(map(int,input().split()))
sl=sorted(l)
def bin_srch(x):
	
	low=0
	high=n-1
	mid=n//2
	while sl[mid]!=x:
		if sl[mid]>x:
			high=mid-1
		else:
			low=mid+1
		mid=(low+high)//2
	return mid
m1,m2=sl[n//2-1],sl[n//2]
for i in l:
	pos=bin_srch(i)
	print(m1 if pos>=n//2 else m2)
		

Measured memory_bytes: 26176
import java.util.Scanner;

public class Main{

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


		for(int i = 0; i < a; i++) {
			for(int j = 0; j < a; j ++) {
				graph[i][j] = sc.nextInt();
			}
		}
		
		boolean[] visit = new boolean[a];
		
		int number = 1;
		int current;
		int val;
		int sum = 0;
		visit[0] = true;
		while(true) {
			val = 10000000;
			current = -1;
			
			for(int i = 0; i < a; i++) {
				if(visit[i] == true) {
					for(int j = 0; j < a; j++) {

						if(val > graph[i][j] && graph[i][j] >= 0 && visit[j] == false) {
			
							val = graph[i][j];
							//System.out.println("val updated:" + i + ":" + j + " = " + val);
							current = j;
						}
					}
				}	
			}
			//System.out.println(current);
			visit[current] = true;
			sum += val;
			number ++;
			if(number == a) break;
			
		}
		
		System.out.println(sum);

	}
}


Measured memory_bytes: 41616
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int a[5];
	int mi1 = 10000, mic = 1000;
	for (int i = 0; i < 5; ++i)
	{
		cin >> a[i];
		if (a[i] % 10 != 0 && mi1 > a[i]%10)
		{
			mi1 = a[i] % 10;
			mic = i;
		}
	}
	int ans = 0;
	for (int i = 0; i < 5; ++i)
	{
		if (i == mic)
		{
			ans += a[i];
		}
		else
		{
			ans += ((a[i] + 9) / 10) * 10;
		}
	}
	cout << ans << endl;
 
 
	return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, a[101][10], b[101][11];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			cin >> a[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= 10; j++){
			cin >> b[i][j];
		}
	}
	
	int ans = -INF;
	for(int i = 1; i < (1<<10); i++){
		bool ok[10] = {};
		for(int j = 0; j < 10; j++){
			ok[j] = (i>>j&1);
		}
		int cnt = 0;
		for(int j = 0; j < n; j++){
			int c = 0;
			for(int k = 0; k < 10; k++){
				if(a[j][k] && ok[k]) c++;
			}
			cnt += b[j][c];
		}
		chmax(ans,cnt);
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      p: usize,
    }
    let mut p = p;
    let mut x = 2;
    let mut ans = 1usize;
    while x*x <= p {
        let mut cnt = 0;
        while p%x == 0 {
            p /= x;
            cnt += 1;
        }
        ans *= x.pow((cnt/n) as u32);
        x += 1;
    }
    if n == 1 {
        ans *= p;
    }
    println!("{}", ans);
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===


const int INF = int(1e9 + 7);


int main() {

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

	int N, M;
	cin >> N >> M;
	vector<Vi> to(N);
	for (int i = 0; i < M; ++i) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		to[u].push_back(v);
	}
	int S, T;
	cin >> S >> T;
	--S; --T;

	auto pdist = new array<array<int, 3>, 100005>;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 3; ++j) {
			(*pdist)[i][j] = INF;
		}
	}

	queue<Pii> q;
	q.emplace(S, 0);
	(*pdist)[S][0] = 0;
	while (!q.empty()) {
		int v = q.front().first;
		int l = q.front().second;
		q.pop();
		for (const auto& u : to[v]) {
			int nl = (l + 1) % 3;
			if ((*pdist)[u][nl] != INF) continue;
			(*pdist)[u][nl] = (*pdist)[v][l] + 1;
			q.emplace(u, nl);
		}
	}

	int ans = (*pdist)[T][0];
	delete pdist;
	if (ans == INF) ans = -1;
	else ans /= 3;
	cout << ans << endl;
}


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

int main(){
    long long int N, a, b;
    cin >> N >> a >> b;
    int v, w, x, y, z;
    long long int sum=0;
    for(long long int i=1; i<N+1; i++){
        v=i/10000;
        w=(i%10000)/1000;
        x=(i%1000)/100;
        y=(i%100)/10;
        z=i%10;
        if(v+w+x+y+z>=a && v+w+x+y+z<=b){
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX  1e18
#define ss 1e15
#define pb push_back

int main() {
    int a,p;
    cin>>a>>p;
    a = a*3;
    a+=p;
    cout<<a/2<<"\n";
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

cnt = 0
for a in A:
    if a == cnt + 1:
        cnt += 1
if cnt == 0:
    print(-1)
else:
    print(N - cnt)


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

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif

template<class T>using vv = vector<vector<T>>;

int main() {
  int N, M, X;
  ins(N, M, X);

  vi C(N);
  vv<int> A(N, vi(M));
  rep(i, N) {
    cin >> C[i];
    rep(j, M)
      cin >> A[i][j];
  }

  int ans = 1e7;
  rep(bit, 1<<N) {
    vi rikai(M, 0);
    int cost = 0;
    rep(i, N) {
      if (bit & (1 << i)) {
        cost += C[i];
        rep(j, M)
          rikai[j] += A[i][j];
      }
    }
    bool ok = true;
    rep(i, M) {
      if (rikai[i] < X)
        ok = false;
    }
    if (ok)
      ans = min(ans, cost);
  }
  if (ans == 1e7) {
    cout << "-1\n";
  } else
    cout << ans << endl;

  return 0;
}


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

int main(){
    int ans = 0;
    int n;
    string stone;
    cin >> n >> stone;
    
    int wazawai = 0, white = 0, red = 0;
    
    for (int i = 0; i < n; i++) {
        if (stone[i] == 'W') {
            white++;
        } else {
            red++;
        }
        if (i == 0) continue;
        if (stone[i - 1] == 'W' && stone[i] == 'R') {
            wazawai++;
        }
    }
    
    if (wazawai == 0) {
        ans = 0;
        cout << ans << endl;
        return 0;
    }
    
    for (int i = 0; i < red; i++) {
        if (stone[i] == 'W') {
            ans++;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3720
#include <stdio.h>
#include <math.h>

double average(int n, double *score){
    double sum = 0;
    int x = 0;
    while(x != n){
        sum += *(score + x);
        x++;
    }
    //printf("合計%lf\n", sum);
    return sum / n;
}

double dispersion(int n, double m, double *score){
    int j;
    double sum = 0;
    double sm = 0;
    for(j = 0; j < n; j++){
        sm = *(score + j) - m;
        sum += sm * sm;
    }
    return sum / n;
}

int main(void){
    char text[1010];
    int n;
    int j;
    double x[1100];
    double m,a,deviation;
    
    while(1){
        //fgets(text, 1010, stdin);
        //sscanf(text, "%d", &n);
        scanf("%d", &n);
        if(n == 0)
            break;
        //printf("%d\n", n);
        for(j = 0; j < n; j++){
            scanf("%lf", &x[j]);
        }
        /*for(j = 0; j < n; j++){
            printf("%lf ", x[j]);
        }*/
        //printf("\n");
        m = average(n, x);
        //printf("平均%lf\n", m);
        a = dispersion(n, m, x);
        //printf("分散%lf", a);
        deviation = sqrt(a);
        printf("%lf\n", deviation);
    }
    return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define int long long
#define pii pair<int, int>
using namespace std;
bool comparator(pii a, pii b)
{
    return a.second > b.second;
}
main()
{
    int n, m, k, a, b, c, l, r;
    cin >> k >> n;
    int ara[n], sum = 0;
    for(int i = 0; i < n; i++)
        cin >> ara[i];

    pii d[n];
    for(int i = 1; i < n; i++)
    {
        d[i].first = ara[i];
        d[i].second = ara[i] - ara[i-1];
        sum += ara[i] - ara[i-1];
    }
    sort(d, d+n, comparator);
    int check = k - ara[n-1] + ara[0];
    if(sum - d[0].second + check < sum)
        cout << sum - d[0].second + check << endl;
    else
        cout << sum << endl;
    //main();
}



Measured memory_bytes: 4992