akhauriyash/Code-Regression huggingface dataset:
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/

#include <bits/stdc++.h>
using namespace std;

/* see https://github.com/pllk/cphb/
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
    tree_order_statistics_node_update> indexed_set;
 **/

typedef long long ll;
#define endl "\n"
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }

//typedef __int128 lll;
typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cini(n);
    cinai(h, n);
    for(int i=1; i<n; i++) {
        if(h[i-1]>h[i])
            h[i]++;
        if(h[i-1]>h[i]) {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}



Measured memory_bytes: 640
import sys
from collections import deque
from collections import defaultdict
import math
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n,m,k = map(int,input().split())
mod = 10**9 + 7
fact = [1]*(n*m+10000+1)
rfact = [1]*(n*m+10000+1)
for i in range(n*m+10000):
    fact[i+1] = rr = ((i+1) * fact[i]) % mod
def comb(N, K,mod):
    return fact[N] * pow(fact[K], mod-2, mod) * pow(fact[N-K], mod-2, mod) % mod
ans = 0
ni = comb(n*m-2,k-2,mod)
for i in range(n):
    for j in range(m):
        ko = (1+j)*j*n//2
        ko += (m-j)*(m-1-j)*n//2
        ko += (1+i)*i*m//2
        ko += (n-i)*(n-1-i)*m//2
        ans += ni*ko
        ans %= mod
print(ans*pow(2,mod-2,mod)%mod)

Measured memory_bytes: 44012
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 10010
#define MOD 998244353
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;

LL T,n,m,i,j,k,g,x,y,z,Ans,cnt,sum,res,Sum;
LL a[N],b[N],c[N],d[N*4],s[N];
bool v[N];

vector <LL> l[N];

IL LL Abs(LL x){return (x<0)?-x:x;}
IL void Swap(LL &a,LL &b){a^=b^=a^=b;}
IL LL Min(LL a,LL b){return (a<b)?a:b;}
IL LL Max(LL a,LL b){return (a>b)?a:b;}

IL LL Mi(LL x,LL y){
	LL p=x,t=1,Res=1;
	for (;t<=y;(t&y)?Res=(Res*p)%MOD:0,p=(p*p)%MOD,t<<=1);
	return Res;
}

IL LL read(){
	LL p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

IL void Dfs(int x){
	if (v[x])	return;
	c[cnt]+=b[x];	v[x]=1;
	l[cnt].push_back(b[x]);	Dfs(a[x]);
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();	k=read();
	for (i=1;i<=n;i++)	a[i]=read();
	for (i=1;i<=n;i++)	b[i]=read();
	for (i=1;i<=n;i++){
		if (!v[i])	++cnt,Dfs(i);
	}
/*	cout<<cnt<<endl;
	for (i=1;i<=cnt;i++)	cout<<c[i]<<endl;
	cout<<"---------"<<endl;
*/
	Ans=-INF;	sum=0;
	for (i=1;i<=cnt;i++){
		sum=0;
		for (j=0;j<l[i].size();j++)
			d[j+1]=d[j+1+l[i].size()]=l[i][j];
		s[0]=0;
		for (j=1;j<=l[i].size()*2;j++)	s[j]=s[j-1]+d[j];
		
		if (c[i]>0){
			sum=k/(l[i].size())*c[i];
			res=k%l[i].size();
			Sum=-INF;
			for (j=1;j<=l[i].size();j++)
				for (g=j;g<j+l[i].size();g++){
					if (g-j+1>res)	break;
					Sum=Max(Sum,s[g]-s[j-1]);
				}
			if (Sum!=-INF)	sum+=Sum;
			Ans=Max(Ans,sum);
			//total

			if (k>=l[i].size()){
				sum=((k-l[i].size())/l[i].size())*c[i];
				Sum=-INF;
				res=l[i].size();
				for (j=1;j<=l[i].size();j++)
					for (g=j;g<j+l[i].size();g++){
						if (g-j+1>res)	break;
						Sum=Max(Sum,s[g]-s[j-1]);
					}
				if (Sum!=-INF)	sum+=Sum;
				Ans=Max(Ans,sum);
			}
		}	else {
			res=l[i].size();
			Sum=-INF;
			for (j=1;j<=l[i].size();j++)
				for (g=j;g<j+l[i].size();g++){
					if (g-j+1>res)	break;
					Sum=Max(Sum,s[g]-s[j-1]);
				}
			Ans=Max(Ans,Sum);
		}
		//cout<<Ans<<endl;
	}
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 4156
#include <iostream>
#include <string>
#include "stdio.h"
using namespace std;

int main(void)
{
  char ch;

  while(1){
    scanf("%c", &ch);
    if(islower(ch)) 
      ch=toupper(ch);
    else if(isupper(ch)) 
      ch=tolower(ch);
    printf("%c",ch);
    if ( ch == '\n' ) break;
  }
  
  return 0;
}

Measured memory_bytes: 3128
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

class Factorial {
    private:
        vector<long long> fac;
    public:
        Factorial();
        Factorial(long long n_max);
        void initialization(long long n_max);
        long long getFactorial(long long n);
};

Factorial::Factorial() {}
Factorial::Factorial(long long n_max) {
    fac.clear();
    fac.push_back(1);
    fac.push_back(1);
    for (long long i = 2; i <= n_max; i++) {
        fac.push_back(fac[i-1] * i % MOD);
    }
}
void Factorial::initialization(long long n_max) {
    fac.clear();
    fac.push_back(1);
    fac.push_back(1);
    for (long long i = 2; i <= n_max; i++) {
        fac.push_back(fac[i-1] * i % MOD);
    }
}
long long Factorial::getFactorial(long long n) {
    return fac[n];
}

/*
  MOD計算
*/
// 割り算のための逆元を求める（mod m での a の逆元）
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int main() {
    int X, Y;
    cin >> X >> Y;
    long long ans = 0;
    if ((X + Y) % 3 != 0 || (2 * X - Y) % 3 != 0 || (2 * Y - X) % 3 != 0) {
        ans = 0;
    } else if (!(2 * X - Y >= 0 && 2 * Y - X >= 0)) {
        ans = 0;
    } else {
        int s = (2 * X - Y) / 3;
        int t = (2 * Y - X) / 3;
        Factorial fact(s + t);
        ans = fact.getFactorial(s + t) * (modinv(fact.getFactorial(s) * fact.getFactorial(t), MOD) % MOD) % MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10604
//  RAKSHIT KADAM
 #include <bits/stdc++.h>
 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
 #warning !!!check the size of arrayss!!!
 
 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define newMOD  998244353
 #define MAX 300006
            
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define endl "\n"
 #define x first
 #define y second
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define INF 1000000000000000005
 #define vi vector<ll>
#define pi 3.1415926535897932384626433832795
#define Endl endl
#define lb lower_bound
#define ub upper_bound
using namespace std;
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}
 
//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}} // if a and m are relativelyprime

void solve()
{
    ll n;cin>>n;
    set<ll>s;
    while(n)
    {
        s.insert(n%10);
        n/=10;
    }
    if(s.find(7)!=s.end())
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}
signed main()
{
 
   
    Need_for_speed(activated);
//satisfy
//    {
//   solve();
//    }

  solve();
    return 0;
    
}
 


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

int main(){

  ll i,j;
  ll n;
  string s;
  cin>>n>>s;
  ll w[n+1],b[n+1];
  w[0]=0;
  b[0]=0;
  for(i=1;i<=n;i++){
    b[i]=b[i-1];
    w[i]=w[i-1];
    if(s[i-1]=='#') b[i]++;
    else w[i]++;
  }
  ll ans=10101010;
  for(i=0;i<=n;i++){
    ans=min(ans,b[i]+w[n]-w[i]);
  }
  cout<<ans<<endl;
  
  
  return 0;
}

Measured memory_bytes: 3716
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int n,W,v[200000],w[200000],dp[101][10001]={0};
    cin>>n>>W;
    rep(i,n) cin>>v[i]>>w[i];
    rep(i,n)rep(j,W+1){
        if(j>=w[i]) dp[i+1][j]=max(dp[i+1][j-w[i]]+v[i],dp[i][j]);
        else dp[i+1][j]=dp[i][j];
    }
    cout<<dp[n][W]<<endl;
}


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

using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f
#define ll long long
#define db double
#define eps 1e-8
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
#define pi acos(-1.0)
const ll maxn = 2e5 + 100;
const ll mod = 1e9;
int c[10];
int val[10];
map<int, int> mat;
signed main()
{
	int n, m;
	cin >> n >> m;
	bool okay = 1;
	_rep(i, 1, m)
	{
		int s, c;
		cin >> s >> c;
		
		if (!mat.count(s) || mat[s] == c)
		{
			mat[s] = c;
		}
		else
			okay = 0;
	}

	string s;
	_rep(i, 1, n)
	{
		if (mat.count(i))
		{
			s += mat[i] + '0';
		}
		else
			s += '0';
	}
	if (s[0] == '0'&& n>=2)
	{
		if (!mat.count(1))
			s[0] = '1';
		else
		{
			okay = 0;
		}
	}
	if (okay)
		cout << s << endl;
	else
		cout << -1 << endl;
}

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

int main() {
  int N,Ans=1;
  string S;
  cin>>N>>S;
  rep(i,N-1){if(S.at(i)!=S.at(i+1)){Ans++;}}
  cout<<Ans<<endl;
}

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

using namespace std;

int main(void){
	int n,m,k,i,j,b;
	bool flag = false;
	cin >> n >> m >> k;
	for(i=0; i<=n; i++){
		for(j=0; j<=m; j++){
			b = (m-j)*i+(n-i)*j;
			if(b == k){
				cout << "Yes" << endl;
				flag = true;
				break;
			}
		}
		if(flag){
			break;
		}
	}
	if(!flag){
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int a,b,c;char d;
	cin>>a>>d>>b>>d>>c;
	if(a>=2019&&b>=5){
		cout<<"TBD";
	}else{
		cout<<"Heisei";
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=200005;
struct edge{int x,y,next;}a[2*MAXN];int len,last[MAXN];
void ins(int x,int y){len++;a[len].x=x;a[len].y=y;a[len].next=last[x];last[x]=len;}
char ok[MAXN];int n;
int mx[2][MAXN],dep[MAXN],s[MAXN],in[MAXN],ot[MAXN],dfn;
void init(int x,int fa)
{
	in[x]=++dfn;s[dfn]=s[dfn-1]+ok[x]-'0';
	for(int k=last[x];k;k=a[k].next)
	{
		int y=a[k].y;
		if(y!=fa)
		{
			init(y,x);dep[x]=max(dep[x],dep[y]+1);
			if(dep[y]+1>=mx[0][x])swap(mx[0][x],mx[1][x]),mx[0][x]=dep[y]+1;
			else if(dep[y]+1>=mx[1][x])mx[1][x]=dep[y]+1;
		}
	}ot[x]=dfn;
}
int upcal[MAXN];
void dp1(int x,int fa,int up)
{
	upcal[x]=up;
	for(int k=last[x];k;k=a[k].next)
	{
		int y=a[k].y;
		if(y!=fa)
		{
			if(dep[y]+1==mx[0][x])dp1(y,x,max(up,mx[1][x])+1);
			else dp1(y,x,max(up,mx[0][x])+1);
		}
	}
}
int g(int l,int r){return s[r]-s[l-1];}
int du[MAXN];
int main()
{
	n=read();
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		ins(x,y);ins(y,x);
		++du[x];++du[y];
	}scanf("%s",ok+1);
	init(1,0);dp1(1,0,0);
	LL ans=0;
	for(int i=1;i<len;i+=2)
	{
		int u=a[i].x,v=a[i].y;if(dep[u]>=dep[v])swap(u,v);
		int mx0=mx[0][u],mx1=(dep[u]+1==mx[0][v]?max(upcal[v],mx[1][v]):max(upcal[v],mx[0][v]));
		if(mx0<mx1&&g(in[u],ot[u]))++ans;
		else if(mx0>mx1&&(g(1,in[u]-1)+g(ot[u]+1,n)))++ans;
	}
	for(int i=1;i<=n;i++)
	{
		if(du[i]==1){ans+=ok[i]-'0';continue;}
		int mx0=mx[0][i],mx1=mx[1][i];
		if(upcal[i]>=mx0)swap(mx0,mx1),mx0=upcal[i];
		else if(upcal[i]>=mx1)mx1=upcal[i];
		int mn=999999999;
		for(int k=last[i];k;k=a[k].next)if(dep[a[k].y]<=dep[i])
		{
			int y=a[k].y;
			if(g(in[y],ot[y]))mn=min(mn,dep[y]+1);
		}if(g(in[i],in[i]))mn=0;
		if(g(1,in[i]-1)+g(ot[i]+1,n))mn=min(mn,upcal[i]);
		if(mn<=mx1)
		{
			if(mx0!=mx1)ans+=mx1-mn+1;
			else ans+=mx1-mn;
		}
	}
	if(g(1,n))++ans;
	pr2(ans);
	return 0;
}


Measured memory_bytes: 19200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
// map<int,int> mp;

int main() {
  int N;

  cin >> N ;
int d[N];
REP(i, N) cin>>d[i];

int ans=0;
for(int i = 0; i < N; i++) {
  for(int j = i+1; j < N; j++) {
    ans += d[i]*d[j];
    // cout << ans << endl;
  }
}

cout << ans << endl;
}

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

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

int main() 
{
    int n, k;
    cin >> n >> k;
    int h[n];
    rep(i,n) cin >> h[i];

    int dp[n];
    dp[0] = 0;
    for (int i=1; i<n; i++) {
        dp[i] = INF;
        for (int j= max(0, i-k); j<i; j++) {
            dp[i] = min(dp[i], dp[j] + abs(h[j]-h[i]));
        }
    }

    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
const int N=100005,mu=1000000007;
int n,s[N],dp[N],l=0,r=0;
long long x,y,a[N];
int main(){
	scanf("%d%lld%lld",&n,&x,&y);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
	if (x>y) std::swap(x,y);
	for (int i=1;i+2<=n;i++) 
		if (a[i+2]-a[i]<x){
			puts("0");return 0;
		} 
	dp[0]=s[0]=1;
	for (int i=1;i<=n;i++){
		while (a[i]-a[r+1]>=y && r<i-1) r++;
		if (l<=r){
			if (l) dp[i]=(s[r]-s[l-1]+mu)%mu;
			else dp[i]=s[r];	
		} 
		if (a[i]-a[i-1]<x) l=i-1;
		s[i]=(s[i-1]+dp[i])%mu;
	}
	int ans=0;
	for (int i=n;i>=0;i--){
		ans=(ans+dp[i])%mu;
		if (a[i+1]-a[i]<x && i<n) break;
	}
	printf("%d",ans);
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include<assert.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int inf = 1e17;
const int mod = 1000000007;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int dp[100008];
signed main() {
	string s; cin >> s;
	dp[0] = 1;
	rep(i, s.size()) {
		if (i + 4 < s.size()) {
			string t = "";
			rep(j, 5)t.push_back(s[i + j]);
			if (t == "dream" || t == "erase")dp[i + 5] += dp[i];
		}
		if (i + 5 < s.size()) {
			string t = "";
			rep(j, 6)t.push_back(s[i + j]);
			if (t == "eraser")dp[i + 6] += dp[i];
		}
		if (i + 6 < s.size()) {
			string t = "";
			rep(j, 7)t.push_back(s[i + j]);
			if (t == "dreamer")dp[i + 7] += dp[i];
		}
		dp[i + 5] %= mod; dp[i + 6] %= mod; dp[i + 7] %= mod;
	}
	if (dp[s.size()])puts("YES");
	else puts("NO");
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};
 


static const int MAX_SIZE = 1 << 20; 

LL segMax[2 * MAX_SIZE - 1], segAdd[2 * MAX_SIZE - 1];

//区間[a, b)に値xを加算する.
void add(int a, int b, LL x, int k = 0, int l = 0, int r = MAX_SIZE)
{
    if (r <= a || b <= l) return;

    if (a <= l && r <= b){
        segAdd[k] += x;
        return;
    }

    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);

    segMax[k] = max(segMax[k * 2 + 1] + segAdd[k * 2 + 1], segMax[k * 2 + 2] + segAdd[k * 2 + 2]);
}

LL getMax(int a, int b, int k = 0, int l = 0, int r = MAX_SIZE)
{
    if (r <= a || b <= l) return 0;

    if (a <= l && r <= b) return (segMax[k] + segAdd[k]);

    LL left = getMax(a, b, k * 2 + 1, l, (l + r) / 2);
    LL right = getMax(a, b, k * 2 + 2, (l + r) / 2, r);

    return (max(left, right) + segAdd[k]);
}


int main(){
    int n;cin >> n;
    vector<P> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].fs >> v[i].sc;
    }
    sort(ALL(v));
    add(n-1,n,n);
    for (LL i = n-2; i >= 0; i--) {
        LL t = upper_bound(ALL(v), mp(v[i].fs + v[i].sc, -LINF)) - v.begin();
        add(i,i+1, max(t, getMax(i,t)));
    }
    vector<LL> p(n);
    for (int i = 0; i < n; i++) {
        p[i] = getMax(i,i+1);
    }
    vector<LL> dp(n+1,0);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        dp[p[i]] = (dp[p[i]] + dp[i])%mod;
        dp[i+1] = (dp[i+1] + dp[i])%mod;
    }
    cout << dp[n] << endl;
    return 0;
}


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

int main() {
  int n;cin>>n;
  vector<pair<int,int>> pr(n);
  rep(i,n){
    int a;cin>>a;
    pr[i]=make_pair(a,i+1);
  }
  sort(all(pr));
  rep(i,n){
    cout<<pr[i].second;
    if(i==n-1)cout<<endl;
    else cout<<" ";
  }
}

Measured memory_bytes: 4000
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数s 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}

int main() {
    ll n,m,l,k;
    // string s;
    cin>>n>>k;
    vector<ll> v;
    rep(i, n){
        ll x;
        cin>>x;
        v.push_back(x);
    }
    ll ans = 0;
    rep(i, min(n, k) + 1){
        // i is fold unmber
        rep(j, n) {
            vector<ll> r;
            ll sum=0;
            bool ts = false;
            rep(k, i){

                // pr((j+k)%n );
                // pr(v[(j+k)%n]);
                sum+=v[(j+k)%n];
                r.push_back(v[(j+k)%n]);
                if((j+k)%n == 0 || (j+k)%n ==n-1)  ts=true;
            }
            if(!ts) {
                continue;
            }
            sort(ALL(r));
            rep(jx, min((ll)r.size(), min(n, k-i))) {
                // pr(r[j]);
                // pr(sum);
                if(r[jx] < 0 ) sum -= r[jx];
            }
            // pr(sum);
            //             pr("");

            ans = max(ans,sum);
        }
    }
    pr(ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
map<ll,int>vis;
int n;
int main()
{
    scanf("%d",&n);
    ll sum=0,ans=0;
    vis[0]++;
    while(n--)
    {
        int x;scanf("%d",&x);
        sum+=x;
        ans+=vis[sum];
        vis[sum]++;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 12800
import sys

list_line = sys.stdin.readlines()

for index, element in enumerate(list_line):
    list_line[index] = element.rstrip('\n')

counter = 1
for i in list_line:
    if i != '0':
        print("Case %d: %s" % (counter, i))
        counter += 1
    else:
        counter = 1

Measured memory_bytes: 7964
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

ll A[300010], mod=1000000007;

int main() {
	ll N;
	cin >> N;
	for(ll i=0; i<N; ++i) cin >> A[i];
	ll d=1, ans=0;
	for(int i=0; i<60; ++i){
		ll cnt=0;
		for(ll j=0; j<N; ++j){
			if((A[j])&d) ++cnt;
		}
		ll t=(cnt*(N-cnt))%mod;
		ans=(ans+((d%mod)*t)%mod)%mod;
		d=(d<<1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
from copy import *
from sys import *
import math
import queue
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)

#h,w
def main():
	l,r = map(int,input().split())
	if(r-l+1>2018):
		print(0)
		exit()
	else:
		min = 2020
		for i in range(l,r+1):
			for j in range(i+1,r+1):
				if(min>i*j%2019):
					min=i*j%2019
	print(min)
	exit()


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

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

int main() {
    string A, B, C;
    cin >> A >> B >> C;
    int a = 0, b = 0, c = 0;
    char tmp = 'a';
    while(true){
        if (tmp == 'a'){
            if (a < A.size()){
                tmp = A[a];
                a++;
            }
            else {
                cout << 'A' << endl; 
                return 0;
            }
        }
        else if (tmp == 'b'){
            if (b < B.size()){
                tmp = B[b];
                b++;
            }
            else {
                cout << 'B' << endl;
                return 0;
            }
        }
        else {
            if (c < C.size()){
                tmp = C[c];
                c++;
            }
            else {
                cout << 'C' << endl;
                return 0;
            }

        }
    }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed;
// cout << setprecision(10) << val;

int n, dp[105][5][5][5];

signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n;
  rep(i, 0, 4) rep(j, 0, 4) rep(k, 0, 4) {
    if (i == 0 and j == 1 and k == 2) continue;
    if (i == 0 and j == 2 and k == 1) continue;
    if (i == 2 and j == 0 and k == 1) continue;
    dp[3][i][j][k]++;
  }
  rep(i, 4, n+1) {
    rep(j, 0, 4) rep(k, 0, 4) rep(l, 0, 4) rep(m, 0, 4) {
      if (j == 0 and l == 2 and m == 1) continue;
      if (j == 0 and k == 2 and m == 1) continue;
      if (k == 0 and l == 1 and m == 2) continue;
      if (k == 0 and l == 2 and m == 1) continue;
      if (k == 2 and l == 0 and m == 1) continue;
      (dp[i][k][l][m] += dp[i-1][j][k][l]) %= MOD;
    }
  }
  int ans = 0;
  rep(i, 0, 4) rep(j, 0, 4) rep(k, 0, 4) ans += dp[n][i][j][k];
  cout << ans % MOD << endl;
  return 0;
}



Measured memory_bytes: 384
n, k = map(int, input().split())
a_b = []
for _ in range(n):
    _a, _b = map(int, input().split())
    a_b.append((_a, _b))
a_b = sorted(a_b, key=lambda x: x[0])
i = 0
while k > a_b[i][1]:
    k -= a_b[i][1]
    i += 1
print(a_b[i][0])

Measured memory_bytes: 87704
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1), ans(n+1);
    rep(i, n) cin >> a[i+1];

    for(int i=n; i>=1; i--){
        int sum = 0;
        for(int j=i; j<=n; j+=i){
            sum += ans[j];
        }
        if(sum%2 != a[i]) ans[i]++;
    }

    int num = 0;
    rep(i, n+1) num += ans[i];
    cout << num << endl;
    rep(i, n+1){
        if(ans[i] == 1) cout << i << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  int x;
  cin >> x;
  int p = 0;
  for(int i=1; i<=10000000; i++){
    if(p+i>=x){
      cout << i << endl;
      break;
    }else p+=i;
  }
  return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> pos(N);
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i]; a[i]--;
		pos[a[i]] = i;
	}
	set<int> st;
	st.insert(-1); st.insert(N);
	int ans = 0;
	rep(k, 0, N) {
		auto res = st.insert(pos[k]);
		set<int>::iterator l, r;
		l = r = res.first;
		l--; r++;
		ans += (k + 1)*(pos[k] - *l)*(*r - pos[k]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12800
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=0

for i in range(0,N):
    ans+=B[A[i]-1]

for i in range(0,N-1):
    if A[i+1]-A[i]==1:
        ans+=C[A[i]-1]

print(ans)


Measured memory_bytes: 3064
#include<map>
#include<cmath>
#include<stack>
#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int a,b,c,d;
int main(){
	scanf("%d%d%d%d",&a,&b,&c,&d);
	printf("%d\n",max(a*b,c*d));
	return 0;
}

Measured memory_bytes: 256
//using quick sort

import java.io.*;

public class Main {

	static int n;

	static void swap(int[] array, int i, int j) {

		int temp = array[i];
		array[i] = array[j];
		array[j] = temp;
	}

	static void quick_sort(int[] array, int left, int right) {
		int pivot = array[(left + right) / 2];
		int i = left;
		int j = right;

		while (true) {
			while (pivot > array[i])
				i++;
			while (pivot < array[j])
				j--;

			if (i >= j)
				break;

			swap(array, i, j);
			i++; // 次のデータ
			j--;
		}

		if (left < i - 1) /* 基準値の左に 2 以上要素があれば */
			quick_sort(array, left, i - 1); /* 左の配列を Q ソートする */
		if (j + 1 < right) /* 基準値の右に 2 以上要素があれば */
			quick_sort(array, j + 1, right); /* 右の配列を Q ソートする */

	}

	static void display(int[] array, int m, int n) {
		for (int i = n-1; i > m-1; i--) {
			System.out.print(array[i] + "\n");
		}
		//System.out.print("\n");
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int array[] = new int[10];
		for (int i = 0; i <= 9; i++) {
			String s = br.readLine();
			array[i] = Integer.parseInt(s);
		}

		//int[] array = { 6, 3, 1, 7, 0, 4, 8, 5, 2 };
		n = array.length;

		//System.out.println("初期値");
		//display(array, 0, n);
		quick_sort(array, n - n, n - 1);
		//System.out.println("ソート後");
		//display(array, 0, n);
		
		display(array, 7, 9+1);
	}
}

Measured memory_bytes: 16932
#include <iostream>
int ans[100010];

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


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

#define REP(i, a) for(int i=0;i<(int)a;++i)
typedef long long ll;
typedef long double ld;
using namespace std;
int a, b;
char op;

void solver() {
    while (cin >> a >> op >> b) {
        if (op == '+')cout << a + b << endl;
        else if (op == '-')cout << a - b << endl;
        else if (op == '*')cout << a * b << endl;
        else if (op == '/')cout << a / b << endl;
        else break;
    }
}

int main() {
    solver();
    return 0;
}

Measured memory_bytes: 3092
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BiConsumer;

public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        if(n == 1) System.out.println("Hello World");
        else {
            int a = sc.nextInt();
            int b = sc.nextInt();

            System.out.println(a + b);
        }
    }
}


Measured memory_bytes: 21844
import math
from functools import reduce

K = int(input())
ans = 0

def gcd(*num):
    return reduce(math.gcd, num)

for i in range(1, K + 1):
    for j in range(1, i + 1):
        for k in range(1, j + 1):
            length = len(set([i, j, k]))
            if length == 3:
                ans += gcd(i, j, k) * 6
            elif length == 2:
                ans += gcd(i, j, k) * 3
            else:
                ans += gcd(i, j, k)

print(ans)

Measured memory_bytes: 9636
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"

using namespace std;
typedef long long ll;
typedef pair <ll,ll> pii;

const ll NMAX = 10001;
const ll INF = (1LL << 60);
const ll MOD = 998244353;
const ll BLOCK = 447;

int n;
int a[3][101], dp[3][101];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,i,j;
    cin >> n;
    for(i  =1;i <= n;i++){
        cin >> a[1][i];
        dp[1][i] = -2e9;
    }
    for(i  =1;i <= n;i++){
        cin >> a[2][i];
        dp[2][i] = -2e9;
    }
    dp[1][1] = 0;
    for(i = 1;i <= 2;i++){
        for(j = 1;j <= n;j++){
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + a[i][j];
        }
    }
    cout << dp[2][n];
    return 0;
}


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

int main() {
bool no=false;
    int N;
    cin>>N;
   // vector<int> A(N);
  unordered_map<int,int> map;
    for(int i=0; i<N; i++){int a; cin>>a; 
                          if(map.count(a))map[a]++;
                          else map[a]=1;}
    // vector<vector<int>> A(N,vector<int>(M));
    // for(int i=0; i<N; i++){for(int j=0; j<M; j++){cin>>A[i][j];}}
    //sort(A.begin(),A.end());
    //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i])}
    //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i])}
  for (auto i = map.begin(); i != map.end(); ++i) {
    if(i->second > 1){cout<<"NO"<<endl;no=true;break;}
    
}if(!no)cout<<"YES"<<endl;
  //  cout <<  << endl;
}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define all(x) (x).begin(), (x).end()
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const int MOD = 998244353; //1e9+7;
const int MAXN = 1e6+1;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int H,W,K;
    cin >> H >> W >> K;
    vector<string> S(H);
    fori(i,H) cin >> S[i];

    auto numbit = [](int x) {
        int r = 0;
        for(; x; x/=2) r += x%2;
        return r;
    };

    vector<vector<int>> A(H,vector<int>(W));
    fori(h,H) {
        fori(w,W) {
            A[h][w] = S[h][w]-'0';
            //if(w) A[h][w] += A[h][w-1];
        }
    }

    int ans = 1e9;
    fori(h,1<<(H-1)) {
        int cuts = numbit(h);
        int ok = 1;
        vector<vector<int>> M(1, vector<int>(W));
        fori(b,H) {
            vector<int>& lst = M.back();
            fori(w,W) {
                lst[w] += A[b][w];
                ok &= lst[w] <= K;
            }
            if(h&(1<<b)) M.pb(vector<int>(W));
        }

        if(!ok) continue;

        int l = M.size();
        vector<int> acc(l);
        fori(w,W) {
            int tocut = 0;
            fori(i,l) tocut |= acc[i]+M[i][w]>K;
            if(tocut) {
                cuts++;
                fori(i,l) acc[i] = M[i][w];
            } else {
                fori(i,l) acc[i] += M[i][w];
            }
        }
        mmin(ans,cuts);
    }

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


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

def main():
    S=input()
    if 'AB' in S or 'BA' in S:
        print('Yes')
    else:
        print('No')

main()







Measured memory_bytes: 6068
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >>s;
  for(int i=0;i<4;i++)
  cout <<s[i];
  cout << ' ';
  for(int i=4;i<12;i++)
  cout <<s[i];
  cout <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

	cout<<fixed<<setprecision(12);
	double r;
	cin>>r;
	double PI=acos(-1);
	double area=r*r*PI;
	double cir=(r+r)*PI;
	cout<<area<<" "<<cir<<endl;

	return 0;
}


Measured memory_bytes: 3272
#include<stdio.h>

#define max 100
#define white 0
#define gray 1
#define black 2;

void dfs();
void visit(int);

int num,array[max][max];
int color[max],data[max],f[max],count;

int main(){
  int u,v,k,i,j;
  scanf("%d",&num);

  for(i = 0;i < num;i++){
    for(j = 0;j < num;j++){
      array[i][j] = 0;
    }
  }

  for(i = 0;i < num;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j = 0;j < k;j++){
      scanf("%d",&v);
      v--;
      array[u][v] = 1;
    }
  }
  dfs();
  return 0;
}

void visit(int u){
  int v;
  color[u] = gray;
  data[u] = ++count;
  for(v = 0;v < num;v++){
    if(array[u][v] == 0){
      continue;
    }
    if(color[v] == white){
      visit(v);
    }
  }
  color[u] = black;
  f[u] = ++count;
}

void dfs(){
  int u;
  for(u = 0;u < num;u++){
    color[u] = white;
  }
  count = 0;

  for(u = 0;u < num;u++){
    if(color[u] == white){
      visit(u);
    }
  }
  for(u = 0;u < num;u++){
    printf("%d %d %d\n",u + 1,data[u],f[u]);
  }
}



Measured memory_bytes: 2112
#include <stdio.h>
int main()
{
   int k,a,b,i,flag=0;
   scanf("%d",&k);
   scanf("%d %d",&a,&b);
   for(i=a;i<=b;i++)
   {
       if(i%k==0)
       {
           flag=1;
           break;
       }
   }
   if(flag==1)
    printf("OK");
   else
    printf("NG");
    return 0;
}


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

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> S(H);
  for(int i=0;i<H;i++){
    cin >> S[i];
  }
  vector<vector<int>> tate(H,vector<int>(W,0));
  vector<vector<int>> yoko(H,vector<int>(W,0));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i][j]=='#'){
        continue;
      }
      if(tate[i][j]==0){
        int tcount=1;
        int tlim=0;
        for(int k=1;k<=H;k++){
          if(i+k>=H || S[i+k][j]=='#'){
            tlim=k;
            break;
          }
          tcount++;
        }
        for(int k=0;k<tlim;k++){
          tate[i+k][j]=tcount;
        }
      }
      if(yoko[i][j]==0){
        int ycount=1;
        int ylim=0;
        for(int k=1;k<=W;k++){
          if(j+k>=W || S[i][j+k]=='#'){
            ylim=k;
            break;
          }
          ycount++;
        }
        for(int k=0;k<ylim;k++){
          yoko[i][j+k]=ycount;
        }
      }
    }
  }
  int ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      tate[i][j]+=yoko[i][j];
      ans=max(ans,tate[i][j]);
    }
  }
  cout << ans-1 << endl;
}

Measured memory_bytes: 42252
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
struct node{
	int val,id;
	bool operator<(node x)const{
		return val<x.val;
	}
}a[200100],b[200100],c[200100];
int sum[200100];
int n,suma,sumb,ans;
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&a[i].val,&b[i].val);
		c[2*i-1].val=a[i].val,c[2*i].val=b[i].val;
		c[2*i-1].id=2*i-1,c[2*i].id=2*i;
		suma+=a[i].val,sumb+=b[i].val;
	}
	ans=min(suma,sumb);
	sort(c+1,c+2*n+1);
	for(int i=1;i<=2*n;i++){
		sum[i]=sum[i-1]+c[i].val;
		if(c[i].id%2==1)a[(c[i].id+1)/2].id=i;
		else b[c[i].id/2].id=i;
	}
	for(int i=1;i<=n;i++){
		int x;
		if(a[i].id<=n&&b[i].id<=n)x=sum[n];
		else if(a[i].id<=n-1&&b[i].id>n)x=sum[n-1]+c[b[i].id].val;
		else if(b[i].id<=n-1&&a[i].id>n)x=sum[n-1]+c[a[i].id].val;
		else x=sum[n-2]+c[a[i].id].val+c[b[i].id].val;
		ans=min(ans,x);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define re register
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define per(i,n,m) for(int i=m;i>=n;i--)
#define rrep(i,m,n) for(register int i=m;i<=n;i++)
#define rper(i,n,m) for(register int i=m;i>=n;i--)
const int N = 5e6 + 10;
const ll mod = 1e9 + 7;
bitset<N> bit;
signed main(){
    int n,ans=0;
    bit[0]=1;
    si(n);
    rep(i,1,n){
        int x;
        si(x);
        bit|=bit<<x;
        ans+=x;
    }
    rep(i,(ans+1)/2,N){
        if(bit[i]){
            pi(i);
            return 0;
        }
    }
   return 0;
}

Measured memory_bytes: 5608
import java.io.*
import java.util.*

const val YES = "YES"
const val NO = "NO"
fun solve(N: Long, p: LongArray){
    val sp = p.sorted()
    val a = p.filterIndexed{ index, it -> it != sp[index] }
    if(a.size==0){println(YES); return}
    else if (a.size != 2){ println(NO); return }
    val b = sp.filterIndexed{ index, it -> it != p[index] }
    if (a[0] == b[1] && a[1] == b[0]){println(YES)}
    else println(NO)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val p = LongArray(N.toInt())
    for (i in 0 until N.toInt()) {
        p[i] = sc.next().toLong()
    }
    solve(N, p)
}



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

int32_t main(){
	int n, m, c; cin>>n>>m>>c;
	vector<int> sol(m);
	for(int i =0; i < m; i++){
		cin>>sol[i];
	}
	int ans = 0;
	while(n--){
		int res = c;
		for(int i = 0; i < m; i++){
			int x; cin>>x;
			res += x * sol[i];
		}
		if(res > 0){
			ans++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256