akhauriyash/Code-Regression huggingface dataset:
n,m = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
mod = 10**9+7

x_tmp = 0
for i in range(n):
    x_tmp += (2*i-n+1) * X[i]
y_tmp = 0
for i in range(m):
    y_tmp += (2*i-m+1) * Y[i]

print(x_tmp * y_tmp % mod)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
const int N = 3e5 + 5;

int n, m, tot, ans, x, y, a[N], t[N<<2];
vector <int> vec[N];

void update(int o, int l, int r, int x, int k) {
	if(l == r) {
		t[o] += k;
		return;
	}
	int mid = (l + r)>>1;
	if(x <= mid) update(o<<1, l, mid, x, k);
	else update(o<<1|1, mid + 1, r, x, k);
	t[o] = max(t[o<<1], t[o<<1|1]);
}

int main() {
	cin>>n>>m>>tot;
	rep(i, 1, tot) {
		cin>>x>>y; 
		a[x]++; vec[x].push_back(y);
		update(1, 1, m, y, 1);
	}
	rep(i, 1, n) {
		rep(j, 0, (int) (vec[i].size() - 1)) 
			update(1, 1, m, vec[i][j], -1);
		ans = max(ans, a[i] + t[1]);
		rep(j, 0, (int) (vec[i].size() - 1)) 
			update(1, 1, m, vec[i][j], 1);
	}
	cout<<ans<<endl;
}

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

bool ispalindrome(string s)
{
	for(int i=0;i<=s.size()/2;i++)
		if(s[i]!=s[s.size()-i-1])
			return false;
	return true;
}

int main()
{
	string str;
	cin>>str;
	int n=str.size();
	
	string N1=str.substr(0,(n-1)/2);
	string N2=str.substr((n+3)/2-1,n-1);
	
	if(ispalindrome(str) && ispalindrome(N1) && ispalindrome(N2))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
suit=["S","H","C","D"]
rank=[i+1 for i in range(13)]

all_cards=[]
for s in suit:
  for r in rank:
    all_cards.append(s+" "+str(r))

cards=[]

n=int(input())
for i in range(n):
  s,r=map(str,input().split())
  cards.append(s+" "+r)
  
for ac in all_cards:
  if ac in cards:
    pass
  else:
    print(ac)



Measured memory_bytes: 5600
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m; cin >> n >> m;
    vector<Pll> ab(n);
    rep(i,n){
        ll a,b; cin >> a >> b;
        ab[i] = make_pair(a,b);
    }
    sort(all(ab));
    ll temp = 0, res = 0, cnt = 0;
    while(temp < m){
        ll rest = m - temp;
        if(ab[cnt].second < rest){
            temp += ab[cnt].second;
            res += ab[cnt].first * ab[cnt].second;
        }
        else{
            temp += rest;
            res += ab[cnt].first * rest;
        }
        cnt++;
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
/*******************************
 * written by Koki Riho
 * Rih0z https://github.com/Rih0z
 *******************************/

#include<stdio.h>
#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<numeric>
#include<algorithm>
#include<cmath>
#define DEBUG false
#define FOR(i , a, b) for(size_t i = a ; i < b ; i++ )
#define REP(i,b) FOR(i , 0 , b)
#define RFOR(i,a,b) for(size_t i = a-1 ; i >= b ; i--)
#define RREP(i,a) RFOR(i,a,0)



typedef long long ll;
using namespace std;

int scanInt(void);
string scanString(void);

void scanLlArr(ll *a , int n);
void scanCharArr(char *string);

void printInt(int p);
void printLlArr(ll *a);
void printCharArr(char *string);


void perSum(ll *a , ll *sum ,int n);

/*************Global variable  **************/
int N ;
char str[26];
std::map<char,int> M ; 
string S; 
ll K;
ll num  = 0 ;
int tmpN;
/*******************************/

int main(){
  if (DEBUG){
    std::printf("******debug mode********\n");
  }
  cin >> S >> K ;
  REP(i,S.length()){
    tmpN = S[i] - '0' ;
    if(DEBUG){
      cout << num << endl;
    }
    
    
    if((tmpN != 1 && tmpN != 0) || i+1 == K){
      cout << S[i] << endl;
      return 0 ;
    }
  }
    if(S.length() >= K)
      cout << 1 <<endl;


  if (DEBUG){
    std::printf("******debug********\n");

    std::printf("******debug********\n");
  }
  return 0 ;
}

//各地点までの部分和を計算する
void perSum(ll *a , ll *sum ,int n){
  int i ;
  sum[0] = a[0];
  for(i = 1 ; i < n ; i++){
    sum[i] = a[i] + sum[i-1];
  }

}


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

int V, E;
vector<bool> visited;
vector<int> depth, lowlink, pars;

void dfs(vector<vector<int>> &G, int p, int u, int d){
    visited[u] = true;
    pars[u] = p;
    depth[u] = lowlink[u] = d;
    
    for(auto v: G[u]) if(v != p){
        if(!visited[v]){
            dfs(G, u, v, d+1);
            lowlink[u] = min(lowlink[u], lowlink[v]);
        }else{
            lowlink[u] = min(lowlink[u], depth[v]);
        }
    }
}

int main(){
    cin >> V >> E;
    
    vector<vector<int>> G(V);
    for(int i=0; i<E; i++){
        int s, t; cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    
    depth.assign(V, -1), lowlink.assign(V, -1);
    visited.assign(V, false);
    pars.assign(V, -1);
    dfs(G, -1, 0, 0);
    
    vector<pair<int, int>> ans;
    vector<vector<int>> tree(V);
    for(int i=0; i<V; i++){
        int p = pars[i];
        if(p != -1 && depth[p]<lowlink[i]){
            if(p < i)
                ans.emplace_back(p, i);
            else
                ans.emplace_back(i, p);
        }
    }
    sort(ans.begin(), ans.end());
    
    for(auto p: ans)
        cout << p.first << " " << p.second << endl;
    
    return 0;
}

Measured memory_bytes: 4884
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = 1e9+7;
string s[600];
bool sym[600][600];
vector<P> v[2];
int main()
{
	int n;
	ll ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
		s[i]=s[i]+s[i];
	}
	for(int i=n;i<2*n;i++)
		s[i]=s[i-n];
	fill(sym[0],sym[600],false);
	if(n==1)
	{
		cout<<1<<endl;
		return 0;
	}
	//2*2を探す
	for(int i=0;i<2*n-2;i++)
	{
		for(int j=0;j<2*n-2;j++)
		{
			if(s[i][j+1]==s[i+1][j])
			{
				sym[i][j]=true;
				v[0].push_back(P(i,j));
			}
		}
	}
	for(int a=3;a<n+1;a++)
	{
		v[a&1].clear();
		for(int i=0;i<v[(a+1)&1].size();i++)
		{
			P p=v[(a+1)&1][i];
			if(sym[p.first+1][p.second+1] &&(p.first+a<=2*n && p.second+a<=2*n)&&(s[p.first][p.second+a-1]==s[p.first+a-1][p.second]))
				v[a&1].push_back(p);
			else
				sym[p.first][p.second]=false;
		}
	}
	ans=v[n&1].size();
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 13184
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

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

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int n, w;
	cin >> n >> w;
	vector<ll> weight(n);
	vector<ll> value(n);
	for (int i = 0; i < n; i++)
	{
		cin >> weight[i] >> value[i];
	}

	vector<vector<ll>> dp(n, vector<ll>(w + 1));
	for (int i = 0; i <= w; i++)
	{
		if (weight[0] <= i) dp[0][i] = value[0];
	}

	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j <= w; j++)
		{
			if (j < weight[i])
			{
				dp[i][j] = dp[i - 1][j];
			}
			else
			{
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]);
			}
		}
	}
	cout << dp[n - 1][w] << endl;
}

Measured memory_bytes: 79488
#include <iostream>
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a <= b && b <= c)
       cout << a << " " << b << " " << c << endl;
    else if(a <= c && c <= b)
       cout << a << " " << c << " " << b << endl;
       else if(b <= c && c <= a)
       cout << b << " " << c << " " << a << endl;
       else if(b <= a && a <= c)
       cout << b << " " << a << " " << c << endl;
       else if(c <= a && a <= b)
       cout << c << " " << a << " " << b << endl;
       else if(c <= b && b <= a)
       cout << c << " " << b << " " << a << endl;
}


Measured memory_bytes: 3084
#include<stdio.h>
#define N 100000
#define SENTINEL 2000000000
typedef struct number{
  char card;
  int num;
}S;
S L[N/2+2],R[N/2+2];
void merge(S A[],int s,int l,int m,int r){
  int n1=m-l;
  int n2=r-m;
  int i;
  for(i=0;i<n1;i++)L[i]=A[l+i];
  for(i=0;i<n2;i++)R[i]=A[m+i];
  L[n1].num=R[n2].num=SENTINEL;
  i=0;
  int j=0;
  for(int k=l;k<r;k++){
    if(L[i].num<=R[j].num){
      A[k]=L[i];
      i+=1;
    }
    else {
      A[k]=R[j];
      j+=1;
    }
  }
}
void mergeSort(S A[],int s,int l,int r){
  if(l+1<r){
    int m=(l+r)/2;
    mergeSort(A,s,l,m);
    mergeSort(A,s,m,r);
    merge(A,s,l,m,r);
  }
}
int partition(S a[],int s,int p,int r){
  int i,j;
  S b,x;
  x=a[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(a[j].num<=x.num){
      i++;
      b=a[i];
      a[i]=a[j];
      a[j]=b;
    }
  }
    b=a[i+1];
    a[i+1]=a[r];
    a[r]=b;

  return i+1;
}
void quicksort(S A[],int s,int p,int r){
  int q;
  if(p<r){
    q=partition(A,s,p,r);
    quicksort(A,s,p,q-1);
    quicksort(A,s,q+1,r);
  }
}
int main(){
  int a,i,w;
  int flag=1;
  S tra[N],np[N];
  char t[10];
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%s",t);
    np[i].card=tra[i].card=t[0];
    scanf("%d",&w);
    np[i].num=tra[i].num=w;
  }
  mergeSort(np,a,0,a);
  quicksort(tra,a,0,a-1);
  for(i=0;i<a;i++){
    if(np[i].card!=tra[i].card)flag=0;
  }
  if(flag==1)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<a;i++)printf("%c %d\n",tra[i].card,tra[i].num);
  return 0;
}



Measured memory_bytes: 4120
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=999999999;

int main() {
   int A,B,C,D;
   cin>>A>>B>>C>>D;
   if(A+B>C+D){cout<<"Left"<<endl;}
   if(A+B==C+D){cout<<"Balanced"<<endl;}
   if(A+B<C+D){cout<<"Right"<<endl;}
return 0;}

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

string s;
int Min = INT32_MAX, chara['z'-'a'+1];

int main() {
	cin >> s;

	int c = 0;
	for (int i = 0; i <= 'z' - 'a'; i++) {
		for (int j = s.length()-1; j >= 0; j--) {
			if (s[j] == ('a' + i)) {
				chara[i] = max(chara[i], c);
				c = 0;
			}
			else {
				c++;
			}
		}
		chara[i] = max(chara[i], c);
		c = 0;
		//char a = 'a' + i;
		//cout << a << ": " << chara[i] << endl;
		Min = min(chara[i], Min);
	}

	cout << Min << endl;
}

Measured memory_bytes: 256
//#include "debug.h"
#include <string.h>
#include <math.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 200000
typedef long long i64;

int n;
int x[MAXN], y[MAXN];
int a[MAXN];

double dist(int i, int j) {
	double dx = x[i]-x[j], dy = y[i]-y[j];
	return sqrt(dx*dx + dy*dy);
}

int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int i=0; i<n; i++) scanf("%d %d", &x[i], &y[i]);
	return 1;
}

void init() {
}

double solve() {
	for (int i=0; i<n; i++) a[i] = i;
	double avg = 0;
	int cnt = 0;
	while (1) {
		double s = 0;
		for (int i=0; i<n-1; i++)
			s += dist(a[i], a[i+1]);
		avg += s;
		cnt ++;
		if (!next_permutation(a, a+n)) break;
	}
	return avg/cnt;
}

void output(double ans) {
	printf("%lf\n", ans);
}

void cleanup() {
}

int main() {
	//precalc();
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}




Measured memory_bytes: 128
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;

  while (left < right) {
    mid = (left + right) / 2;
    if (key == A[mid]) return 1;
    if (key > A[mid]) left = mid + 1;
    else if (key < A[mid]) right = mid;
  }

  return 0;
}

int main() {
  int i, q, k, sum = 0;

  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &A[i]);

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &k);
    if (binarySearch(k)) sum++;
  }

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

  return 0;
}


Measured memory_bytes: 2108
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  string S, T, result;
  cin >> S >> T;
  const int64_t SL = static_cast<int64_t>(S.length());
  const int64_t TL = static_cast<int64_t>(T.length());

  auto Match = [&](const int64_t start) -> bool {
    if (start + TL > SL) {
      return false;
    }
    for (int64_t i = 0; i < TL; ++i) {
      if (S[start + i] != '?' && S[start + i] != T[i]) {
        return false;
      }
    }
    return true;
  };

  bool found = false;
  result = S;
  for (int64_t i = SL - 1; i >= 0; --i) {
    if (Match(i)) {
      for (int64_t j = 0; j < TL; ++j) {
        result[i + j] = T[j];
      }
      found = true;
      break;
    }
  }
  if (!found) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int64_t i = 0; i < SL; ++i) {
    if (result[i] == '?') {
      result[i] = 'a';
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3620
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int A[20];
int m;
bool dfs(int x,int y){
	if(x==m)return true;
	if(x >m||y==n)return false;
	bool ret =dfs(x+A[y],y+1);
	if(!ret)ret = dfs(x,y+1);
	return ret;

}

int main(){
	int q;
	cin>>n;
	rep(i,n)cin>>A[i];
	cin>>q;
	rep(i,q){
		cin>>m;
		if(dfs(0,0)){
			cout <<"yes"<<endl;
		}else
			cout <<"no"<<endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N;
string s[3];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  REP(i, 3) cin >> s[i];
  int ans = 0;
  REP(j, N) {
    set<int> st;
    REP(i, 3) st.EMP(s[i][j]);
    ans += SZ(st)-1;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
a.sort()
for i in a:
    if a.index(i) == n - 1:
        if i == x:
            cnt += 1
    elif i <= x:
        x -= i
        cnt += 1
    else:
        break
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;


//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

vector<int> T(55,0),P(55,0);

int rec(int n,int x){
  if(n==0){return (x<=0?0:1);}
  else if(x<=1+T[n-1]){return rec(n-1,x-1);}
  else { return P[n-1]+1+rec(n-1,x-2-T[n-1]);}
}

signed main(){
  int N,X;cin>>N>>X;
  T[0]=1;P[0]=1;
  REP(i,1,55){
    T[i]=2*T[i-1]+3;
    P[i]=2*P[i-1]+1;
  }
  print(rec(N,X));
}


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

int main() {
  int N,M;
  cin >> N;
  vector<string> s(N);
  for(int i=0; i<N; i++){
    cin >> s.at(i);
  }
  cin >> M;
  vector<string> t(M);
  for(int i=0; i<M; i++){
    cin >> t.at(i);
  }
  
  int ans = 0;
  int cnt = 0;
  for(int i=0; i<N; i++){
    cnt = 0;
    for(int j=0; j<N; j++){
      if(s.at(i) == s.at(j)){
        cnt++;
      }
    }
    for(int j=0; j<M; j++){
      if(s.at(i) == t.at(j)){
        cnt--;
      }
    }
    
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
s = gets.chomp!.split("").map(&:to_i)

a = [[s.shift]]
s.each do |c|
    b = []
    a.each do |e|
        x = e.pop
        b << (e + [x,c])
        b << (e << x * 10 + c)
    end
    a.clear
    a = b
    #p b
end

ans = 0
a.each do |e|
    ans += e.inject(&:+)
end

puts ans

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

int main(){
    int d, g;
    cin >> d >> g;

    int p[d], c[d];
    for(int i = 0; i < d; i++)  cin >> p[i] >> c[i];

    int ans = INT_MAX;
    for(int i = 0; i < 1<<d; i++){
        int score = 0, _max, count = 0;
        for(int j = 0; j < d; j++){
            if(i & (1<<j))  score += p[j] * (j+1) * 100 + c[j], count += p[j];
            else            _max = j;
        }

        if(score >= g)  
            ans = min(ans, count);
        else if(g-score <= p[_max] * (_max+1) * 100)
            ans = min(ans, count + (g-score+(_max+1)*100-1) / ((_max+1)*100) );
        else
            continue;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] <= x) {
            ans++;
            x -= a[i];
        } else {
            break;
        }
    }
    if (ans == n and x > 0) {
        ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))

H[0] -= 1
for n in range(1,N):
	if H[n-1]==H[n]:
		continue
	H[n] -= 1

ans = True
for n in range(1,N):
	if H[n-1]>H[n]:
		ans = False

print('Yes' if ans else 'No')
 

Measured memory_bytes: 63856
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define bit(s,i) (((s)>>(i))&1LL)
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

vector<string> ans;

void solve(int now, int n, string s, int cur) {
	if(now==n) {
		ans.pb(s);
		return;
	}
	for(char x= 'a'; x-'a'<=cur+1; x++) solve(now+1, n, s+x, (x-'a'==cur+1? cur+1: cur));
}

signed main() {
	EmiliaMyWife

	int n;
	cin >> n;
	solve(1, n, "a", 0);
	sort(all(ans));
	for(auto &x: ans) cout << x << '\n';

	return 0;
}


Measured memory_bytes: 7796
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;


ll a[100010];
ll x[100010];
ll y[100010];
ll z[100010];

int main(){
    ll n;
    cin >> n;
    rep(i, n) cin >> a[i];
    x[0] = 1;
    ll ans = 3;

    if (a[0] != 0){
        cout << 0 << endl;
        return 0;
    }

    for(int i = 1; i < n; i++){
        ll nxt = a[i];
        ll cnt = 0;
        ll nx = x[i-1], ny = y[i-1], nz = z[i-1];

        if (nx == nxt) cnt++;
        if (ny == nxt) cnt++;
        if (nz == nxt) cnt++;

        if (nx == nxt) nx++;
        else if (ny == nxt) ny++;
        else if (nz == nxt) nz++;

        x[i] = max({nx, ny, nz});
        z[i] = min({nx, ny, nz});
        y[i] = nx + ny + nz - x[i] - z[i];
        ans *= cnt;
        ans %= MOD;
    }

    // rep(i, n) cout << x[i] << " ";
    // cout << endl;
    // rep(i, n) cout << y[i] << " ";
    // cout << endl;
    // rep(i, n) cout << z[i] << " ";
    // cout << endl;

    cout << ans%MOD << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

int main(){
    
    ll N, K; cin >> N >> K;
    vector<int> p(N);
    rep(i,N) cin >> p[i];
    vector<long double> cum(N);
    rep(i,N){

        cum[i+1] = cum[i] + (p[i]+1)/2.0;
    }
    long double ans = 0;
    rep(i,N){
        if (i+K > N) break;
        ans = max(ans, (cum[i+K] - cum[i]));
    }
    cout << fixed << setprecision(15);
    cout << ans << endl;
}

Measured memory_bytes: 7196
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int i = 0;
		for (int j = 0; j < M; j++) {
			i = sc.nextInt();
			N -= i;
		}
		sc.close();
		if (N < 0) {
			System.out.println(-1);
		}else {
			System.out.println(N);
		}
	}
}

Measured memory_bytes: 46204
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		for (int i = 0; i < n; i++) {
			int a = stdIn.nextInt();
			int b = stdIn.nextInt();

			if (a < b) {
				System.out.println(a);
			} else if (a % b == 0) {
				System.out.println(b);
			} else {
				System.out.println(a % b);
			}
		}
	}
}

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

# スペース区切りの整数の入力
m, d = map(int, input().split())
ans =0

for month in range(1, m+1):
    for i in range(22, d+1):
        d_list = list(str(i))
        d1   = int(d_list[1])
        d10 = int(d_list[0])
        if d1 < 2 or d10 < 2:
            continue
        if month == (d1 * d10):
            ans +=1

print(ans)

Measured memory_bytes: 3060
import numpy as np
W, H, N = map(int, input().split())

grid = np.array([[1] * W for _ in range(H)])

for _ in range(N):
    x, y, a = map(int, input().split())

    if a == 1:
        grid[:, :x] = 0
    elif a == 2:
        grid[:, x:] = 0
    elif a == 3:
        grid[:y, :] = 0
    else:
        grid[y:, :] = 0

print(np.count_nonzero(grid.ravel()))

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

using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)

bool can(int arr[],int sz){
  rep(i,0,sz){
    if(arr[i]>i || arr[i]<0)return false;
  }return true;
}
stack<int> s;
void build(int arr[],int sz){
  rep(i,0,sz){
    int md[sz-1];
    rep(j,0,i)md[j]=arr[j];
    rep(j,i+1,sz)md[j-1]=arr[j];
    /*rep(j,0,sz-1)cout<<md[j]<<" ";
      cout<<endl;*/
    if(can(md,sz-1) && arr[i]==i){
      //cout<<arr[i]<<endl;
      s.push(arr[i]);
      
      build(md,sz-1);
      return;
    }
  }
}
int main(){
  int n;
  cin>>n;
  int arr[n];
  rep(i,0,n){
    cin>>arr[i];
    arr[i]--;
  }
  if(can(arr,n)){
    build(arr,n);
    while(!s.empty()){
      cout<<s.top()+1<<endl;
      s.pop();
    }
    return 0;
  }
  cout<<-1<<endl;
  return 0;
}


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

int main(){
	int m, f, r;
	while(1){
		cin >> m >> f >> r;
		if(m == -1 && f == -1 && r ==-1) break;
		if(m == -1 || f == -1) cout << "F" << endl;
		else if(m+f >= 80) cout << "A" << endl;
		else if(m+f >= 65) cout << "B" << endl;
		else if(m+f >= 50) cout << "C" << endl;
		else if(m+f >= 30){
			if(r >= 50) cout << "C" << endl;
			else cout << "D" << endl;
		}
		else cout << "F" << endl;
	}
	return 0;
}


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

using namespace std;

int main()
{
    int n, q;
    std::string s;
    cin >> n >> q;
    cin >> s;
    int l[q], r[q];
    for(int i=0; i<q; i++){
        cin >> l[i] >> r[i];
    }
    //cout << s << endl;
    
    int total = 0;
    int v[n];
    v[0] = 0;
    for(int i=1; i<n; i++){
        if(s[i-1]=='A' && s[i]=='C'){
            total++;
        }
        v[i] = total;
    }
    //for(int i=0; i<n; i++) cout << v[i];
    //cout << endl;
    
    for(int i=0; i<q; i++){
        int cnt = v[r[i]-1] - v[l[i]-1];
        cout << cnt << endl;
    }
}


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

int solver(int cnt, int s, int d){
    if(d == 0) return (s==0)?1:0;
    int sum = 0;
    for(int i=cnt+1; i<=9; ++i){
        sum += solver(i, s-i, d-1);
    }
    return sum;
}

int main(){
    int n, s;
    while(cin >> n >> s, n != 0 || s != 0){
        cout << solver(-1,s,n) << endl;
    }
    return 0;
}

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

int main()
{
	int N, V[25], C[25], i, Ans = 0, judg[25];
	cin >> N;
	for (i = 0; i < N; i++)
		cin >> V[i];
	for (i = 0; i < N; i++)
		cin >> C[i];

	for (i = 0; i < N; i++)
		judg[i] = V[i] - C[i];

	for (i = 0; i < N; i++) {
		if (judg[i] > 0)
			Ans += judg[i];
	}
	cout << Ans;
}

Measured memory_bytes: 256
n, m = [int(i) for i in input().split(" ")]

ng = False
s_dict = {}
for i in range(m):
    s, c = [int(i) for i in input().split(" ")]
    if n != 1 and s == 1 and c == 0:
        ng = True
    if s in s_dict:
        if s_dict[s] != c:
            ng = True
    s_dict[s] = c

if ng:
    print(-1)
    exit(0)
    
num = 0
    
if 1 < n and (1 not in s_dict):
    num += pow(10, n - 1) * 1
for k, v in s_dict.items():
    num += pow(10, n - k) * v

print(int(num))

Measured memory_bytes: 3064
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a*500 + b*100 + c*50 == X:
                ans += 1
print(ans)

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

namespace AXORCircle
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var n = int.Parse(Console.ReadLine());
            var hats = Console.ReadLine().Split().Select(int.Parse).ToArray();

            // A B C D ... と並んでて A ^ C = B ならば A ^ B = C / B ^ C = A となる
            // 続いて、 B C D を同様に考えると B ^ C = D なので A == D でなくてはいけない（たぶん）
            // よって hats には XOR が成り立つ 3 種類の数字が同数含まれる必要がある
            // もしくは 0 と任意の数 x が 1 : 2 の割合で含まれる か 0 のみ
            var numbers = hats.GroupBy(x => x)
                .Select(group => Tuple.Create(group.Key, group.Count()))
                .ToArray();

            // hats に XOR が成り立つ 3 種類の数字が同数含まれる場合
            var threeType = numbers.Length == 3
                && numbers.Select(x => x.Item2).Distinct().Count() == 1
                && (numbers[0].Item1 ^ numbers[1].Item1) == numbers[2].Item1;

            // hats に 0 と任意の数 x が 1 : 2 の割合で含まれる場合
            var twoType = numbers.Length == 2
                && numbers.Min(x => x.Item1) == 0
                && ((double)numbers[0].Item2 / numbers[1].Item2 == 2 || (double)numbers[1].Item2 / numbers[0].Item2 == 2);

            // hats に 0 のみ含まれる場合
            var zeroOnly = numbers.All(x => x.Item1 == 0);

            var answer = threeType || twoType || zeroOnly;

            // 解答の出力
            Console.WriteLine(answer ? "Yes" : "No");
        }
    }
}


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

char str[10];
int ans,n;
signed main(){
	scanf("%lld",&n);
	ans=n/500*1000;
	n%=500;
	ans+=n/5*5;
	printf("%lld\n",ans);
return 0;
}

Measured memory_bytes: 256
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int a,b; cin>>a>>b;
	if((a+b)%3 && a%3 && b%3) ote("Impossible");
	else ote("Possible");
}


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

int main() {
  string a;
  cin>>a;
  if(a.at(0)==a.at(1)&&a.at(2)==a.at(3)&&!(a.at(0)==a.at(2))){
    cout <<"Yes"<<endl;
  }
  else if(a.at(0)==a.at(2)&&a.at(1)==a.at(3)&&!(a.at(0)==a.at(3))){
    cout<<"Yes"<<endl;
  }
  else if(a.at(0)==a.at(3)&&a.at(1)==a.at(2)&&!(a.at(0)==a.at(1))){
    cout<<"Yes"<<endl;
  }
  else if(a.at(1)==a.at(2)&&a.at(0)==a.at(3)&&!(a.at(0)==a.at(1))){
    cout<<"Yes"<<endl;
  }
   else if(a.at(1)==a.at(3)&&a.at(0)==a.at(2)&&!(a.at(0)==a.at(1))){
    cout<<"Yes"<<endl;
  }
   else if(a.at(3)==a.at(2)&&a.at(0)==a.at(1)&&!(a.at(0)==a.at(2))){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P );
P dequeue(void);
int calc(int,int);

int main(){
  int e=0,c;
  int i,q;
  P u;
  scanf("%d %d\n", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d",&Q[i].t);

  }

  head = 1;
  tail = n+1;
  
  while(head != tail){
    u = dequeue();
    c = calc(q,u.t);
    u.t -= c;;
    e += c;
   

    if(u.t > 0){
      enqueue(u);
    }
    
    else{
      printf("%s %d\n", u.name ,e);
    }
 
  }
  return 0;
}
P dequeue(){
	P x;
	x = Q[head];
	head = (head+1)%LEN;
	return x;
      }
void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1)%LEN;
}
int calc(int x, int y){
  return x < y ? x:y;
}

Measured memory_bytes: 10756
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

ll const MOD = 1e9 + 7;

int main(){

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

    ll n; cin >> n;
    ll a[n];
    rep(i, n){
        cin >> a[i];
    }

    ll ans = 0;

    rep(i_dig, 61){
        ll cnt_1 = 0;
        ll cnt_0 = 0;

        rep(i, n){
            if(((a[i] >> i_dig) % 2) == 1){
                cnt_1++;
            }
            else{
                cnt_0++;
            }
        }

        ll n_comb = cnt_1 * cnt_0;
        n_comb %= MOD;
        // cout << i_dig << " " << cnt_0 << " " << cnt_1 << endl;

        ll sum_temp = (((1LL << i_dig)) % MOD) * n_comb;
        sum_temp %= MOD;
        // cout << i_dig << " " << (1LL << i_dig) << " " << n_comb << endl;
        ans = (ans + sum_temp) % MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
import math
n=int(input())
if(n%1.08==0):
    print(int(n/1.08))
else:
    x=n/1.08
    n_low=int(math.floor(1.08*math.floor(x)))
    n_high=int(math.floor(1.08*math.ceil(x)))
    if(n==n_low):
        print(int(math.floor(x)))
    elif(n==n_high):
        print(int(math.ceil(x)))
    else:
        print(":(")

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

int main(){
	int length = 4;
	char taroNomber[length+1];
	char hanakoNomber[length+1];
	int hitCount = 0;
	int blowCount = 0;
	while(true){
		cin >> taroNomber;
		cin >> hanakoNomber;
		hitCount = 0;
		blowCount = 0;
		if(strlen(taroNomber)==1){
			break;
		}
		for(int i=0;i<length;i++){
			for(int j=0;j<length;j++){
				if(taroNomber[i]==hanakoNomber[j]){
					if(i==j){
						hitCount++;
						break;
					}else{
						blowCount++;
						break;
					}
				}
			}
		}
		cout << hitCount << ' ' << blowCount << '\n';
	}
	return 0;
}

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

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

  while(K > 0){
    if (B > A && C > B){
      break;
    }

    if (B <= A){
      B *= 2;
      K--;
    }else if (C <= B){
      C *= 2;
      K--;
    }
  }

  if (B > A && C > B){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    int N; cin>>N;
    string S; cin>>S;
    if(S[0]=='W' || S[2*N-1]=='W'){
        cout<<0<<endl;
        return 0;
    }
    vec v(2*N), zero(2*N), one(2*N); v[0] = one[0] = 0; zero[0] = 1;
    rep(i,2*N-1){
        if(S[i+1]!=S[i]) v[i+1]=v[i];
        else             v[i+1]=1-v[i];
        zero[i+1] = zero[i];
        one[i+1] = one[i];
        if(v[i+1] == 0) zero[i+1]++;
        else            one[i+1]++;
        if(one[i+1]>zero[i+1]){
            cout<<0<<endl;
            return 0;
        }
    }
    if(zero[2*N-1] != N){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1;
    rep(i,2*N){
        if(v[i]==1){
            ans=(ans*(zero[i]-one[i]+1LL))%mod;
        }
    }
    FOR(i,1,N+1) ans=(ans*(ll)i)%mod;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 5252
fun main(args: Array<String>) {
  val list = readLine()?.split(" ") ?: listOf()
  val a = Integer.parseInt(list[0] ?: "0")
  val b = Integer.parseInt(list[1] ?: "0")
  val c = Integer.parseInt(list[2] ?: "0")
  if((a < c && c < b) || (b < c && c < a)) {
    println("Yes")
  } else {
    println("No")
  }
}


Measured memory_bytes: 36012
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
const int inf = 1001001001;

int main()
{
  int h, w, k; cin >> h >> w >> k;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<int>> d(h, vector<int>(w, 0));
  rep(i, h) rep(j, w) {
    int t = 0;
    if (s[i][j] == '1') t = 1;
    if (j == 0) d[i][j] = t;
    else d[i][j] = d[i][j-1] + t;
  }
  rep(i, h-1) rep(j, w) {
    d[i+1][j] += d[i][j];
  }
  ll ans = 1001001001;
  for (int bit=0; bit<1<<(h-1); bit++) {
    ll tmp = __builtin_popcount(bit);
    int r = 0;
    int l = 0;
    while (r < w) {
      int t = 0;
      int b = 0;
      bool flg = false;
      while (t < h) {
        while (((bit>>b)&1)==0&&b<h-1) b++;
        int x = 0;
        if (t==0) {
          if (l == 0) {
            x = d[b][r];
          } else {
            x = d[b][r] - d[b][l-1];
          }
        } else {
          if (l == 0) {
            x = d[b][r] - d[t-1][r];
          } else {
            x = d[b][r] - d[t-1][r] - d[b][l-1] + d[t-1][l-1];
          }
        }
        if (x>k) {
          flg = true;
          break;
        }
        t = b+1;
        b = t;
      }
      if (flg) {
        tmp++;
        if (r==l) {
          tmp = 1001001001;
          break;
        }
        l = r;
      } else {
        r++;
      }
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  	int n,f=-1,m=-1,s=-1;
  	cin>>n;
  	vector<int> nums(n);
  	for(int i=0;i<n;i++)
    {
      cin>>nums[i];
      if(i>0)
        if(nums[i]<nums[i-1])
        {
          if(f==-1)
          {
            f=i-1;
            m=i;
          }
          else if(s==-1)
          {
            s=i;
          }
        }
    }
	if(f==-1)
    {
      	cout<<"YES\n";
      	return 0;
    }
    if(s==-1)
    {
     	swap(nums[f],nums[m]);
    }
     else
       swap(nums[f],nums[s]);
  	for(int i=0;i<n-1;i++)
    {
     	if(nums[i]>nums[i+1])
        {
          cout<<"NO\n";
          return 0;
        }
    }
      cout<<"YES\n";
	return 0;  
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

// 1<=A,B<=500(自然数)
// hxw 1<=h,w<=100
// 白: A個の連結成分(.)
// 黒: B            (#)
// 

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

    int A, B;
    cin >> A >> B;
    const int N = 99;
    vector<string> S(N, string(N, '#'));

    B--;
    [&] {
        for (int i = 0; i < 99; i += 3)for (int j = 0; j < 99; j += 3) {
            if (!B--)return;
            rep(ii, 3)rep(jj, 3) S[i+ii][j+jj] = '.';
            S[i + 1][j + 1] = '#';
        }
    }();
    if (S[0][0] == '.')A--;

    [&] {
        for (int i = 96; i >= 0; i -= 3)for (int j = 96; j >= 0; j -= 3) {
            if (!A--)return;
            S[i + 1][j + 1] = '.';
        }
    }();

    cout << N << ' ' << N << endl;
    each(line, S)cout << line << endl;
}

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

using namespace std;

int main()
{
    long long n;
    cin>>n;
    vector<long long> p(3*n);
    for(long long i=0;i<3*n;i++){
        long long a;
        cin>>a;
        p[i]=a;
    }
    sort(p.rbegin(), p.rend());
    long long sum=0;
    for(long long j=1;j<(3*n)-n;j+=2){
        sum+=p[j];
    }
    cout<<sum;
}

Measured memory_bytes: 2560
import heapq
n,m = map(int,input().split())
ls = list(map(int,input().split()))
ls = list(map(lambda x :-x,ls))
heapq.heapify(ls)
for i in range(m):
    a = heapq.heappop(ls)
    heapq.heappush(ls,a/2)
ls = list(map(int,ls))
ls = list(map(lambda x :-x,ls))
print(sum(ls))
    

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int H[101010];
int num[101010];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>H[i];
	
	int ma=0;
	for(i=N-2;i>=0;i--) {
		if(H[i]>=H[i+1]) num[i]=num[i+1]+1;
		ma=max(ma,num[i]);
	}
	cout<<ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

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

  string s;
  ll k;
  cin>>s>>k;
  ll n = s.size();

  bool all_eq=true;
  rep(i,n-1){
    if(s[i]!=s[i+1])all_eq=false;
  }
  if(all_eq){
    cout<<n*k/2<<endl;
  }
  else{
    if(s[0]==s.back()){
      string t=s;
      ll a=1,b=1,c=0,ai,bi;
      rep(i,n-1){
        if(s[i]==s[i+1]){
          a++;
          //s[i+1]='#';
        }
        else {
          ai=i;
          break;
        }
      }
      for(ll i=n-1;i>0;--i){
        if(s[i]==s[i-1]){
          b++;
          //s[i]='#';
        }
        else {
          bi=i;
          break;
        }
      }
      rep(i,ai)if(s[i]==s[i+1])s[i+1]='#';
      for(ll i=n-1;i>=bi;--i)if(s[i]==s[i-1])s[i+1]='#';
      for(ll i=ai;i<bi;++i){
        if(s[i]==s[i+1]){
          c++;
          s[i+1]='#';
        }
      }
      ll ans = 0;
      ans += c*k;
      ans += a/2;
      ans += b/2;
      ans += ((a+b)/2)*(k-1);
      cout<<(ans)<<endl;
    }
    else{
      ll ans=0;
      rep(i,n-1){
        if(s[i]==s[i+1]){
          ans++;
          s[i+1]='#';
        }
      }
      ans*=k;
      cout<<(ans)<<endl;
    }
  }


}


Measured memory_bytes: 256