akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cctype>
#include<string>
#include<map>
#include<set>
#include<bitset>
using namespace std;
int R,C;
bitset<10000>p[10];
int main()
{
    while(cin>>R>>C)
    {
        if(R==0&&C==0)  break;
        for(int i=0;i<R;i++)
        {
            for(int j=0;j<C;j++){
                int x;
                scanf("%d",&x);
                p[i][j]=x;
            }
        }
        int now=(1<<R);  //????????¬?????°???????????????????????°
        int result=0;
        for(int i=0;i<now;i++)
        {
            for(int j=0;j<R;j++){
                    //????????\?????????????????¬
                if(i&(1<<j)){
                    p[j].flip();
                }
            }
            int res=0;
            for(int j=0;j<C;j++)
            {
                int cnt=0;
                for(int k=0;k<R;k++){
                    if(p[k][j]){
                        cnt++;
                    }
                }
                res+=max(cnt,R-cnt);
            }
            result=max(result,res);
            //????¬??????¬?????\
            for(int j=0;j<R;j++){
                if(i&(1<<j))
                    p[j].flip();
            }
        }
        cout<<result<<endl;
    }
    return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;
int rec(int l, int r, VI &a, VVI &memo) {
  if (memo[l][r] != -1) return memo[l][r];
  if (r - l <= 1) return memo[l][r] = 0;
  if (r - l == 2) {
    if (abs(a[l + 1] - a[l]) <= 1) return memo[l][r] = 2;
    return memo[l][r] = 0;
  }
  int res = rec(l + 1, r, a, memo);
  for (int i = l + 1; i < r; i++) {
    if (abs(a[i] - a[l]) <= 1 and rec(l + 1, i, a, memo) == i - (l + 1)) {
      res = max(res, i + 1 - l + rec(i + 1, r, a, memo));
    }
  }
  return memo[l][r] = res;
}
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  while (true) {
    int n; cin >> n;
    if (n == 0) break;
    VI a(n); for (int i = 0; i < n; i++) cin >> a[i];
    VVI memo(n + 1, VI(n + 1, -1));
    cout << rec(0, n, a, memo) << '\n';
  }
  return 0;
}


Measured memory_bytes: 3412
#include<stdio.h>

typedef struct{
  int k;
  int pk;
  int lk;
  int rk;
} Heap;

#define MAX 251
 Heap A[MAX];
int main(){
  //Heap A[MAX];
  int i,H;

  for(i=1;i<=H;i++){
    A[i].pk=NULL;
    A[i].lk=NULL;
    A[i].rk=NULL;
  }

  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i].k);

    if(i/2>=1){
      A[i].pk=A[i/2].k;
      if(i%2==0)
	A[i/2].lk=A[i].k;
      else
	A[i/2].rk=A[i].k;
    }
  }

  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i].k);
    if(A[i].pk!=NULL)
      printf("parent key = %d, ",A[i].pk);
    if(A[i].lk!=NULL)
      printf("left key = %d, ",A[i].lk);
    if(A[i].rk!=NULL)
      printf("right key = %d, ",A[i].rk);
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 600
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
d = list(input().split())
for check in range(n, 10 ** 5):
    flag = True
    for i in str(check):
        if i in d:
            flag = False
            break
    if flag:
        print(check)
        exit()


Measured memory_bytes: 3060
def taste(L, i):
    return L + i -1

def main(): 

    N,L = map(int, input().split())

    sum_all = 0
    for i in range(1, N+1):
        sum_all += taste(L, i)

    min_diff = 201

    sum = 0
    for i in range(1, N+1):
        sum_tmp = 0
        for j in range(1, N+1):
            if i == j:
                continue
            else:
                sum_tmp += taste(L, j)
        if min_diff > abs(sum_all - sum_tmp):
            min_diff = abs(sum_all - sum_tmp)
            sum = sum_tmp

    print(sum)

if __name__ == "__main__":
    main() 

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

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> D(K);
	for (int i = 0; i < K; ++i)
		cin >> D[i];
	auto check = [&](int n)
	{
		while (n) {
			if (count(D.begin(), D.end(), n % 10) != 0)
				return false;
			n /= 10;
		}
		return true;
	};
	int n = N;
	while (true) {
		if (check(n))
			break;
		++n;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = sc.nextInt();
		boolean[] year = new boolean[7368800];
		int p = m;
		int ans = 0;
		while(n!=0){
			Arrays.fill(year, false);
			for(int i=0; i<n; i++){
				for(int k=p; k<year.length; k+=p){
					year[k] = true;
				}
				do{
					p++;
				}while(year[p]==true);
			}
			for(int i=m; i<year.length; i++){
				if(year[i]==false){
					ans = i;
					break;
				}
			}
			System.out.println(ans);
			m = sc.nextInt();
			n = sc.nextInt();
          	p = m;
		}
	}
}


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

string S, T;

int main(){
  cin >> S >> T;

  int ans = 1100;
  rep(i, S.size()-T.size()+1){
    int y = 0;
    rep(j, T.size()){
      if (S[i+j] != T[j]) y++;
    }
    ans = min(ans, y);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod =  998244353;
int fac[maxn]={0};
int quick_mod(int a,int b){
    int ans =  1;
    while(b){
        if(b&1) ans = (1ll*ans*a)%mod;
        a=(1ll*a*a)%mod;
        b>>=1;
    }
    return ans ;
}
int getc(int n,int m){
    return (1ll*fac[n]*quick_mod(fac[m],mod-2)%mod)*quick_mod(fac[n-m],mod-2)%mod;
}

int main()
{

    int n,m,k;
    cin >> n >> m >> k ;
    if(n==1){
        cout << m << endl;
        return 0;
    }
    if(m==1&&k==n-1){
        cout << 1 << endl;
    }
    else if(m==1)
        cout << 0 << endl;
    if(m==1)
        return 0;
    fac[0]=1;
    for(int i=1;i<n;i++)
        fac[i]=1ll*i*fac[i-1]%mod;
    
    ll ans =  0;
    ll num =  m;
    for(int i=1;i<n;i++)
        num=num*(m-1)%mod;
    for(int i=0;i<=k;i++){
        ans = ans + num*getc(n-1,i)%mod;
        //cout << ans << endl;
        ans%=mod;
        num=num*quick_mod(m-1,mod-2)%mod;
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 4348
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long ll;

int main() {
	int K;
	cin >> K;
	int num = 7;
	for (int i = 0; i < K + 10; i++) {
		if (num % K == 0) {
			cout << i + 1 << endl;
			return 0;
		}
		num *= 10, num += 7;
		num %= K;
	}
	cout << -1 << endl;
	return 0;
}

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

int main()
{
    string str;
    int front, tail;
    cin >> str;
    for (int i = 0; i < str.size(); i++)
    {
        if (str[i] == 'A')
        {
            front = i;
            break;
        }
    }
    for (int i = str.size() - 1; i >= 0; i--)
    {
        if (str[i] == 'Z')
        {
            tail = i;
            break;
        }
    }
    cout << tail - front + 1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>
#include <fstream>



int min_count(const std::string& str, int digit, bool has_extra, std::vector<std::vector<int>>& memo) {
	if (digit == str.size()) return has_extra ? 1 : 0;
	if (memo[has_extra][digit] >= 0) return memo[has_extra][digit];
	const int current = str[digit] - '0';
	if (has_extra) {
		return memo[has_extra][digit] = std::min(min_count(str, digit + 1, true, memo) + 10 - current - 1, min_count(str, digit + 1, false, memo) + 10 - current);
	}
	else {
		return memo[has_extra][digit] = std::min(min_count(str, digit + 1, true, memo) + current + 1, min_count(str, digit + 1, false, memo) + current);
	}
}
int main(){
	std::string str; std::cin >> str;
	std::vector<std::vector<int>> memo(2, std::vector<int>(str.size(), -1));
	for (auto i = 1; i <= str.size(); i += 1000) {
		min_count(str, str.size() - i, false, memo);
	}
	std::cout << std::min(min_count(str, 0, false, memo), min_count(str, 0, true, memo) + 1) << std::endl;
}


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

string s;
int flaga,flagb;

int main(){
	cin>>s;
	for(int i=0;i<s.length();i++)
		if(s[i]=='A'){
			flaga=i;
			break;
		}
	for(int i=s.length();i>=0;i--)
		if(s[i]=='Z'){
			flagb=i;
			break;	
		}		
	cout<<flagb-flaga+1<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){

  int N, K;
  cin >> N >> K;

  char ch[N];
  for(int i=0;i<N;i++) cin >> ch[i];

  for(int i=0;i<N;i++){
    if(i!=K-1){
      cout << ch[i];
    }else{
      if(ch[i]=='A') cout << 'a';
      if(ch[i]=='B') cout << 'b';
      if(ch[i]=='C') cout << 'c';
    }
  }
  cout << endl;
  return 0;
}













Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //setprecision()
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
using ll = long long;
using namespace std;

double Mcos(double k){return cos(k*atan(1.0)*4/180);}

void monmo(){
    
}

int main() {
    map<int,int> m;
    ll sum=0;
    ll n,q,a,b,c;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        sum+=a;
        m[a]++;
    }
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>b>>c;
        int s=c-b;
        sum+=m[b]*s;
        m[c]+=m[b];
        m.erase(b); //bの要素を消す
        cout<<sum<<endl;
    }
}

 


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

#define nil string::npos

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  int ans= 0;
  int tmp= 0;
  for(int i=0; i<N; i++){
    char c= S.at(i);
    string prefix= S.substr(0,i); // S[0,i)
    string suffix= S.substr(i+1); // S[i+1,N)

    if(prefix.find(c)==nil && suffix.find(c)!=nil) tmp++;
    if(prefix.find(c)!=nil && suffix.find(c)==nil) tmp--;

    ans= max(ans, tmp);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
using namespace std;

int main(){
//srandom((unsigned long)time(NULL));

int n;
cin>>n;
int h[n+1];
h[0]=0;
int sum=0;
for(int i=1;i<n+1;i++){
    cin>>h[i];
    sum+=h[i];
    }
    int cnt=0;
    int a[n+1];
    for(int i=0;i<n+1;i++){
        a[i]=0;
    }
    int x=0;
    for(int i=1;i<n+1;i++){
        if(h[i]>h[i-1]){
            cnt=cnt+h[i]-h[i-1];
    }
    }
        
        cout<<cnt<<endl;
    
    
    
return 0;
}
   

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

int main(){
  int n;
  cin >> n;
  vector<int> od(n/2);
  vector<int> ev(n/2);
  for(int i=0; i<n; i++){
    if(i%2==0) cin >> od[i/2];
    else cin >> ev[i/2];
  }
  sort(od.begin(), od.end());
  sort(ev.begin(), ev.end());
  pair<int, int> o1=make_pair(0,0);
  pair<int, int> o2=make_pair(0,0);
  int num=od[0], c=1;
  for(int i=1; i<od.size(); i++){
    if(num==od[i]){
      c++;
      continue;
    }
    if(c>o1.second){
      o2.first=o1.first;
      o2.second=o1.second;
      o1.first=num;
      o1.second=c;
    }else if(c>o2.second){
      o2.first=num;
      o2.second=c;
    }
    num=od[i];
    c=1;
  }
  if(c>o1.second){
    o2.first=o1.first;
    o2.second=o1.second;
    o1.first=num;
    o1.second=c;
  }else if(c>o2.second){
    o2.first=num;
    o2.second=c;
  }
  pair<int, int> e1=make_pair(0,0);
  pair<int, int> e2=make_pair(0,0);
  num=ev[0];
  c=1;
  for(int i=1; i<ev.size(); i++){
    if(num==ev[i]){
      c++;
      continue;
    }
    if(c>e1.second){
      e2.first=e1.first;
      e2.second=e1.second;
      e1.first=num;
      e1.second=c;
    }else if(c>e2.second){
      e2.first=num;
      e2.second=c;
    }
    num=ev[i];
    c=1;
  }
  if(c>e1.second){
    e2.first=e1.first;
    e2.second=e1.second;
    e1.first=num;
    e1.second=c;
  }else if(c>e2.second){
    e2.first=num;
    e2.second=c;
  }
  if(o1.first!=e1.first){
    cout << n-o1.second-e1.second << endl;
  }else{
    cout << min(n-o1.second-e2.second,n-o2.second-e1.second) << endl;
  }
  return 0;
}

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

int main(){
    int a,b,c,m;
    cin >> a>> b >> c;
    if(a>b){
        m=a;
        a=b;
        b=m;
    }
    if(b>c){
        m=b;
        b=c;
        c=m;
    }
    if(a>b){
        m=a;
        a=b;
        b=m;
    }
    
    cout << a << " " << b<< " " << c << endl;
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}



  








      

 
  int main() {
   
    int n,q;
    string str;
    cin >> n >> q >> str;
    int l[q+1],r[q+1];
    rep (i,q) {
      cin >> l[i] >> r[i];
      --l[i];
      --r[i];
    }

    vector <int> s(n+1,0);
    for (int i = 0;i < n;++i){
      if (i+1 < n && str[i]=='A' && str[i+1]=='C')  s[i+1]=s[i]+1;
      else s[i+1]=s[i];
    }
    rep (i,q){
      cout << s[r[i]]-s[l[i]] << endl;
    }
}




Measured memory_bytes: 4600
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int arr[101] = {0};

int main()
{
	int a, b;
	cin >> a >> b;
	for(int i=0; i<b; i++)
	{
		int c;
		cin >> c;
		a -= c;
	}
	if(a>=0)
	{
		cout << a;
	}
	else
	{
		cout << -1;
	}
}



Measured memory_bytes: 3636
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
dp = [0 for i in range(N+1)]
if A[0] <= B[0]:
    dp[0] = A[0]
    B[0] -= A[0]
else:
    dp[0] = B[0]
    B[0] = 0
    
if A[-1] <= B[-1]:
    dp[-1] = A[-1]
    B[-1] -= A[-1]
else:
    dp[-1] = B[-1]
    B[-1] = 0

if N != 1:
    for i in range(1,N):
        if A[i] - B[i-1] <= 0:
            dp[i] = A[i]
        elif A[i] - B[i-1] >= B[i]:
            dp[i] = B[i-1] + B[i]
            B[i] = 0
        else:
            dp[i] = A[i]
            B[i] -= A[i] - B[i-1]
print(sum(dp))

Measured memory_bytes: 18752
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T,class Size=typename vector<T>::size_type>inline auto vector_2d(Size h,Size w,T v){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator,class Pair=typename iterator_traits<RandomAccessIterator>::value_type>inline void sort_pairs_by_second(RandomAccessIterator first,RandomAccessIterator last){sort(first,last,[](const Pair&p1,const Pair&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

class union_find final{
private:
    std::vector<unsigned long long>par,sz,rank;
    unsigned long long cnt;
public:
    union_find(unsigned long long n):par(n),sz(n,1),rank(n,0),cnt(n)
    {
        iota(par.begin(),par.end(),0);
    }
    unsigned long long count()const
    {
        return cnt;
    }
    unsigned long long find(unsigned long long n)
    {
        return par[n]==n?par[n]:par[n]=find(par[n]);
    }
    unsigned long long size(unsigned long long n)
    {
        return sz[find(n)];
    }
    bool is_same(unsigned long long x,unsigned long long y)
    {
        return find(x)==find(y);
    }
    void unite(unsigned long long x,unsigned long long y)
    {
        x=find(x);y=find(y);
        if(x!=y){
            if(rank[x]<rank[y]){
                par[x]=y;
                sz[y]+=sz[x];
            }else{
                par[y]=x;
                sz[x]+=sz[y];
                if(rank[x]==rank[y])++rank[x];
            }
            --cnt;
        }
    }
};
int main()
{
    ll n=in(),m=in();
    union_find uf(n);
    for(ll i=0;i<m;++i){
        uf.unite(in()-1,in()-1);
    }
    unsigned long long ans=0;
    for(ll i=0;i<n;++i){
        ans=max(ans,uf.size(i));
    }
    cout<<ans<<endl;
}


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

long long int arr[405];
long long int dp[405][405];
long long int prefsum[405];

long long int sum_Q(long long int l ,long long int r)
{
    long long int ans = prefsum[r];
    if(l-1 >= 0) ans -= prefsum[l - 1];
    return ans;
}
const long long int inf = 1e18 + 5;
long long int foo(long long int l, long long int r)
{
    if(dp[l][r] != -1) return dp[l][r];

    if(l == r)
    {
        dp[l][r] = 0;
        return dp[l][r];
    }

    long long int minm = inf;

    for (long long int i = l; i <= r-1; ++i)
    {
        long long int a = foo(l, i) + foo(i+1, r) + sum_Q(l, r);
        minm = min(minm, a);
    }

    dp[l][r] = minm;

    return minm;


}


int main()
{
    long long int n;
    cin >> n;
    
    for (long long int i = 0; i < 405; ++i)
    {
        for (long long int j = 0; j < 405; ++j)
        {
            dp[i][j] = -1;
        }
    }


    for (long long int i = 0; i < n; ++i)
    {
        cin >> arr[i];
        prefsum[i] = arr[i];
        if(i-1 >= 0)
        prefsum[i] +=  prefsum[i-1];
    }
    cout << foo(0, n-1);
    return 0;
}

Measured memory_bytes: 1536
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		//		new Main().solveB();
		new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numH = 0;
		int numW = 0;
		int h = 0;
		int w = 0;

		try {
			scanner = new Scanner(System.in);
			numH = scanner.nextInt();
			numW = scanner.nextInt();
			h = scanner.nextInt();
			w = scanner.nextInt();

			int total = numH * numW;
			int col = h * numW;
			int row = w * (numH - h);
			System.out.println(total - col - row);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		int numM = 0;
		int numC = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numM = scanner.nextInt();
			numC = scanner.nextInt();
			int[] bArray = new int[numM];
			int[][] aArray = new int[numN][numM];

			for (int i = 0; i < bArray.length; i++) {
				bArray[i] = scanner.nextInt();

			}
			for (int i = 0; i < aArray.length; i++) {
				for (int j = 0; j < aArray[i].length; j++) {
					aArray[i][j] = scanner.nextInt();
				}
			}
			int cnt = 0;

			for (int i = 0; i < aArray.length; i++) {
				int res = 0;
				for (int j = 0; j < aArray[i].length; j++) {
					res += (aArray[i][j] * bArray[j]);
				}
				if (res + numC > 0) {
					cnt++;
				}
			}

			System.out.println(cnt);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	public static class LComp implements Comparator<Long[]> {

		@Override
		public int compare(Long[] o1, Long[] o2) {
			return Long.compare(o1[0], o2[0]);
		}

	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		long numM = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numM = scanner.nextLong();

			Long[][] wk = new Long[numN][2];

			for (int i = 0; i < numN; i++) {
				wk[i][0] = scanner.nextLong();
				wk[i][1] = scanner.nextLong();
			}

			Arrays.sort(wk, new LComp());

			long resNumM = numM;
			long res = 0;
			for (int i = 0; i < wk.length; i++) {
				if (resNumM <= 0) {
					break;
				}
				long key = wk[i][0];
				long value = wk[i][1];
				if (resNumM >= value) {
					res += (key * value);
					resNumM -= value;
				} else {
					res += (key * resNumM);
					resNumM = 0;
				}

			}

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 95560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> A;
  for (int i = 1; i <= N; i++) {
    string S;
    int P;
    cin >> S >> P;
    A.push_back(make_tuple(S, -P, i));
  }
  sort(A.begin(), A.end());
  rep(i, N) {
    string a;
    int b, c;
    tie(a, b, c) = A[i];
    cout << c << '\n';
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

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

	ll t1, t2, a1, a2, b1, b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

	ll x = (a1 - b1) * t1;
	ll y = (a2 - b2) * t2;

	cerr << x << "," << y << endl;

	if((x > 0 && y > 0) ||(x < 0 && y < 0) ){
		cout << 0 << endl;
		return 0;
	}

	if(x == 0){
		if(y == 0){
			cout << "infinity" << endl;
			return 0;
		}else{
			cout << 1 << endl;
			return 0;
		}
	}

	if(x == -y){
		cout << "infinity" << endl;
		return 0;
	}

	if(x < 0){
		x = -x;
		y = -y;
	}

	ll d = x + y;
	if(d > 0){
		cout << 0 << endl;
	}else{
		if(x % (-d) == 0){
			cout << x / (-d) * 2<< endl; 
		}else{
			cout << x / (-d) * 2 + 1 << endl;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FOR(a,b,c) for(int a = (b); a <= (c); a++)
#define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
#define all(x) (x).begin(), (x).end()
#define vi vector <int>
#define vvi vector <vi>
#define ll long long
#define vll vector <ll>
#define vvl vector <vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ep emplace
#define fs first
#define sd second
using namespace std;

int main() {
    FIO;
    int x; cin >> x;
    int ans = (x / 500) * 1000;
    x %= 500;
    ans += (x / 5) * 5;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        String s = inp.next();
        inp.close();
        String[] ss = s.split(",", 0);
        for (int i = 0; i < 3; i++) {
            System.out.print(ss[i] + " ");
        }
        System.out.println();
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const long double pi = acos(-1);
const double PI = acos(-1.);

#define MOD 1000000007
const int N = 1e2 + 2;
const int K = 1e5 + 5;
const int Ai = 1e6 + 6;
const int LOGN = 30;

ll dp[N][K];
ll pre[N][K];
int a[N];
int n, k;

ll sigma(int x, int l, int r) {
//    if(x == 1) {
//        cout << "HERE: " << l << " " << r << "\n";
//        cout << pre[x][l-1] << " " << pre[x][r] << "\n";
//    }
    if(!l)
        return pre[x][r]%MOD;
    return (pre[x][r] - pre[x][l - 1] + MOD)%MOD;
}

int main() {
    ios_base::sync_with_stdio(false);

    cin >> n >> k;

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

    dp[n][0] = 1;
    pre[n][0] = dp[n][0];

    for(int j = 1; j <= k; j++)
        (pre[n][j] = pre[n][j - 1] + dp[n][j]) %= MOD;

    for(int i = n - 1; i >= 0; i--) {
        for(int j = 0; j <= k; j++)
            (dp[i][j] = sigma(i + 1, max(0, j - a[i]), j)) %= MOD;

        pre[i][0] = dp[i][0];
        for(int j = 1; j <= k; j++)
            (pre[i][j] = pre[i][j - 1] + dp[i][j]) %= MOD;
    }

    cout << dp[0][k] << "\n";

    return 0;
}


Measured memory_bytes: 158080
var input= require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.split("\n");
var str="";
for(var i=0;i<Arr.length;i++){
var ab=Arr[i].split(" ").map(Number);
var a=ab[0];
var b=ab[1];
if(a===0 && b===0)break;
str+=Math.min(a,b)+" "+Math.max(a,b)+"\n";
}
console.log(str.trim());

Measured memory_bytes: 10640
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

def rln(s):
    return range(len(s))

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



n,P = list(map(int, input().split()))
a = list(map(int, input().split()))
num01 = [0,0]

for i in a:
    num01[i%2]+=1

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10**9+7
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


#print(num01)

ans = 0
for i in range(num01[1]-P, -1, -2):
    ans += cmb(num01[1],i,p)

ans *= 2**num01[0]

print(ans)






















Measured memory_bytes: 142324
#include <bits/stdc++.h>
#define int long long

using namespace std;


int32_t main() {

    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n, 0));

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

    vector<int> win(1 << n, 0);
    for (int msk = 0; msk < (1 << n); ++msk) {
        for (int i = 0; i < n; ++i) if (msk & (1 << i)) {
            for (int j = 0; j < n; ++j) if (msk & (1 << j)) {
                win[msk] += a[i][j];
            }
        }
    }

    vector<int> dp(1 << n, 0);
    for (int msk = 0; msk < (1 << n); ++msk) {
        for (int sub = msk; sub; sub = (sub - 1) & msk) {
            dp[msk] = max(dp[msk], win[sub] + dp[msk ^ sub]);
        }
    }
    cout << dp[(1 << n) - 1] / 2 << endl;

    return 0;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

int N, M, ans = 0;
vi p;
vector<vector<int>> rs;

bool checkALLRight(int s[]) {
  int nRight;
  REP(i, M) {
    nRight = 0;
    for (auto &val : rs[i]) {
      if (s[val - 1] == 1) nRight++;
    }
    if (nRight % 2 != p[i]) return false;
  }
  return true;
}

void dfs(int s[], int index) {
  if (index == N) {
    if (checkALLRight(s)) ans++;
    return;
  } else {
    REP(i, 2) {
      s[index] = i;
      dfs(s, index + 1);
    }
  }
}

signed main() {
  cin >> N >> M;
  rs.resize(M);
  int ki;
  REP(i, M) {
    ki = read();
    REP(j, ki) { rs[i].PB(read()); }
  }
  REP(i, M) { p.PB(read()); }
  int s[N];
  dfs(s, 0);
  print(ans);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*約数の個数(x含む)*/ll divi(ll x){ll i,ans=0;rep(i,2,x+1){if(x%i==0){ans++;}}return ans;}
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n;
 sc(n);
 ll a[n+1],memo[100010]={0},sum=0;
 rep(i,0,n){
  sc(a[i]);
  memo[a[i]]++;
  sum+=a[i];
 }
 ll q;sc(q);
 ll b[q+1],c[1+q],tmp;
 rep(i,0,q){
  sc(b[i]);sc(c[i]);
  tmp=c[i]-b[i];
  sum+=memo[b[i]]*tmp;
  memo[c[i]]+=memo[b[i]];
  memo[b[i]]=0;
 pr(sum);
 }
return 0;}

Measured memory_bytes: 6744
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

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

    sort(ALL(s));
    sort(ALL(t), greater<>());

    if (t > s) print("Yes");
    else print("No");

}

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

int main () {
    int N;
    int M;

    scanf("%d", &N);
    scanf("%d", &M);
    int *L = malloc((M + 1) * sizeof(int));
    int *R = malloc((M + 1) * sizeof(int));

    int start = 0;
    int end = 0;
    for (int i = 1; i <= M; i++) {
        scanf("%d", &L[i]);
        scanf("%d", &R[i]);
        if (start == 0)
            start = L[i];
        if (end == 0)
            end = R[i];
        if (start <= L[i])
            start = L[i];
        if (end >= R[i])
            end = R[i];
    }
    int ans;
    if (start > end)
        ans = 0;
    else
        ans = (end - start) + 1;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 896
N,K = map(int,input().split())

MOD = 998244353

interval = []
for i in range(K):
    intv = [int(x) for x in input().split()]
    interval.append(intv)

dp = [0]*N
diff = [0]*(N-1)
dp[0] = 1
diff[0] = -1

for i in range(N-1):
    for L,R in interval:
        if L <= N-1 - i:
            diff[i+L-1] += dp[i]
        if R+1 <= N-1 - i:
            diff[i+R] -= dp[i]
    dp[i+1] = dp[i] + diff[i]
    dp[i+1] %= MOD

print(dp[N-1])

Measured memory_bytes: 76356
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    long long int x, k, d;
    cin >> x >> k >> d;
    if (x > 0 && x / k >= d) {
        cout << x - k * d << endl;
        return 0;
    }
    if (x <= 0 && abs(x) / k >= d) {
        cout << abs(x + k * d) << endl;
        return 0;
    }

    k -= abs(x - x % d) / d;
    k = k % 2;
    x = x % d;
    if (k == 0) {
        cout << abs(x) << endl;
    } else {
        cout << min(abs(x + d), abs(x - d)) << endl;
    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
//使い方　インスタンス化(頂点数)　uniteつなぐ(双方向注意) same判定
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b&&b==c&&a%2==0){
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0; i < 100000;i++){
        if((a+b)%2==0&&(b+c)%2==0&&(c+a)%2==0&&a%2==0&&b%2==0&&c%2==0){
            int A = (b + c) / 2;
            int B = (a + c) / 2;
            int C = (b + a) / 2;
            a = A;
            b = B;c=C;
        }else{
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
N, Q = map(int,input().split())
S = input()
C = []
cnt = 0
for i in range(len(S)):
    if 0 == i:
        C.append(cnt)
        continue
    if S[i-1] == "A" and S[i] == "C":
        cnt += 1
    C.append(cnt)

for _ in range(Q):
    l, r = map(int,input().split())
    print(C[r-1]-C[l-1])

Measured memory_bytes: 6104
N = int(input())

if N%4 == 0:
    print("Yes")

if N%4 == 1:
    if N < 21:
        print("No")
    else:
        print("Yes")

if N%4 == 2:
    if N < 14:
        print("No")
    else:
        print("Yes")


if N%4 == 3:
    if N < 7:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 2940
//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>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (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 WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
ll N,M,X;
struct book{
    ll cost;
    vi A;
};
vector<book> books(12);

bool ok(vi v){
    for(auto r:v){
        //cout<<r<<" ";
        if(r>=X)continue;
        return false;
    }//cout<<"\n";
    return true;
}
ll dfs(int i,ll sm, vi v){
    ll ret=INF;
    if(i==N){//全部決め終わったら
        //if(ok(v))cout<<sm<<" ";
        if(ok(v)) return ret=sm;
        else return ret=INF;
    }
    vi vuse=v;//cout<<i<<":";
    for(int j=0;j<M;j++){
        vuse[j]+=books[j].A[i];
        //cout<<vuse[j]<<" ";
    }//cout<<"\n";
    ret=min(
    dfs(i+1,sm+books[i].cost,vuse),//使う
    dfs(i+1,sm,v)//使わない
    );
    return ret;
}
int main(void){
    cin>>N>>M>>X;
    REP(i,N){
        cin>>books[i].cost;
        REP(i,M){
            ll a;cin>>a;
            books[i].A.push_back(a);
        }
    }
    vi v(M,0);
    ll ans=dfs(0,0,v);
    cout<<(ans==INF?-1:ans)<<"\n";
}



Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
 
#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}
 
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mk(arr,n,type)  type *arr=new type[n];
 
clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
int main(){
	int n;
	cin >> n;
	vector<string>s(10);
	s[0] = "pon";
	s[1] = "pon";
	s[2] = "hon";
	s[3] = "bon";
	s[4] = "hon";
	s[5] = "hon";
	s[6] =	"pon";
	s[7] = "hon";
	s[8] = "pon";
	s[9] = "hon";
	cout << s[n % 10]<< "\n";

	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int a,b;
	while(scanf ("%lld %lld",&a,&b)==2){
		
		if (a==1){
			
			cout<<(b*6000)<<endl;
			
		}
		else if (a==2){
			
			cout<<(b*4000)<<endl;
			
		}
		else if (a==3){
			
			cout<<(b*3000)<<endl;
			
		}
		else if (a==4){
			
			cout<<(b*2000)<<endl;
			
		}
	}
	return 0;
	
}


Measured memory_bytes: 3236
import sys
input = sys.stdin.readline
INF = float("inf")


def main():
    n, k = map(int, input().split())
    X = list(map(int, input().split()))
    if n == 1 and k == 1:
        print(0)
        exit()
    ans = INF
    for i in range(n - k + 1):
        l, r = X[i], X[i + k - 1]
        tmp = r - l
        if l * r < 0:
            tmp += min(abs(l), abs(r))
        else:
            tmp += min(abs(l), abs(r))
        ans = min(tmp, ans)
    print(ans)


if __name__ == '__main__':
    main()

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

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

  for (int i = 1; i <= N; i++) {
    int num = i;
    int dig;
    int sum = 0;
    while(num) {
      dig = num % 10;
      sum += dig;
      num = num / 10;
    }
    if(sum >= A && sum <= B) {
      result += i;
    }
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split(' ')))
A.sort(reverse=True)

dif = 0
sgn = '+'
for a in A:
    if sgn == '+':
        sgn = '-'
        dif += a
    else:
        sgn = '+'
        dif -= a

print(dif)

Measured memory_bytes: 3060
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 30;

int A[MR], B[MR], C[MR];

int main()
{
	int N;
	scanf("%d", &N);

	REP(i, N)
	{
		scanf("%d", &A[i]);
		A[i]--;
	}

	REP(i, N)
		scanf("%d", &B[i]);
	REP(i, N - 1)
		scanf("%d", &C[i + 1]);

	int res = 0;
	res += B[A[0]];
	FOR(i, 1, N)
	{
		res += B[A[i]];
		if (A[i] == A[i - 1] + 1)
			res += C[A[i]];
	}

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

	return 0;
}

// FOR GNU C++ use the following pattern:
// Uncomment the code below and change your main into main2
// It does not build in MS C++
// But it does increase the stack size from 256 MB on CF and uses GNU C++

//#include <Processthreadsapi.h>
//#include <iostream>
//#include <Synchapi.h>
//#include <windows.h>
//#include <process.h>
//
//DWORD WINAPI MyThreadFunction(LPVOID lpParam) {
//    main2(nullptr);
//    return 0;
//}
//int main() {
//    auto h = CreateThread(nullptr, 1024 << 20, MyThreadFunction, nullptr, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr);
//    WaitForSingleObject(h, INFINITE);
//}

Measured memory_bytes: 256
from collections import Counter


def prime_factorization(n):
    """
    nを素因数分解して素因数のリストを返却する
    """
    if n < 2:
        return [n]

    primes = []
    while n % 2 == 0:
        primes.append(2)
        n //= 2
    i = 3
    while i ** 2 <= n:
        while n % i == 0:
            primes.append(i)
            n //= i
        i += 2
    if n != 1:
        primes.append(n)
    return primes


MOD = 10 ** 9 + 7
N = int(input())

counter = Counter()

for n in range(2, N + 1):
    for p in prime_factorization(n):
        counter[p] += 1

ans = 1
for k, v in counter.items():
    if k < 2:
        continue
    ans *= v + 1
    ans %= MOD

print(ans)


Measured memory_bytes: 9468
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
long double pi=3.14159265358979323846L;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    char a;cin>>a;
    if(a=='z')a='a';
    else a++;
    
    cout<<a<<endl;
    
}


Measured memory_bytes: 256