akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vvi vector<vector<int>>;
#define mi  map<int,int>
#define mii map<pii,int>
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define sz(x) (int)x.size()
#define all(v) (v).begin(), (v).end()
#define ret(x) return cout<<x,0;
#define rety return cout<<"Yes",0;
#define retn return cout<<"No",0;
#define fl fflush(stdout)   
#define hell 1000000007  
#define hell2 998244353 
#define pi 3.14159265358979323846
vii a[100001],b[100001];
int x[100001],vis[100001];
//mii mm;
set<pii> s;
void dfs(int v,int p,int w){
    ///cout<<v<<" "<<p<<endl;
    vis[v]=1;
    if(p!=v){
        if(x[v]==1e18)x[v]=x[p]+w;
        else{
            if(x[v]!=x[p]+w){
                cout<<"No";
                exit(0);
            }
        }
    }
    else x[v]=0;
    for(auto u:a[v]){
        if(!vis[u.ff])dfs(u.ff,v,u.ss);
        else{
            if(x[u.ff]!=x[v]+u.ss){
                cout<<"No";
                exit(0);
            }
        }
     /*   if(s.find({v,u.ff})==s.end()){
       // if(mm[{v,u.ff}]==0&&mm[{u.ff,v}]==0){
            //mm[{v,u.ff}]=1;mm[{u.ff,v}]=1;
            s.insert({v,u.ff});
            dfs(u.ff,v,u.ss);
        }*/
    }
    for(auto u:b[v]){
        if(!vis[u.ff])dfs(u.ff,v,-u.ss);
        else{
            if(x[u.ff]!=x[v]-u.ss){
                cout<<"No";
                exit(0);
            }
        }
       /* if(s.find({u.ff,v})==s.end()){
        //if(mm[{u.ff,v}]==0&&mm[{v,u.ff}]==0){
            //mm[{u.ff,v}]=1;mm[{v,u.ff}]=1;
            s.insert({v,u.ff});
            dfs(u.ff,v,-u.ss);
        }*/
    }
}

int solve(){
    int n,m,l=0,r=0,d;
    cin>>n>>m;
    rep(i,0,m){
        cin>>l>>r>>d;l--;r--;
        a[l].pb({r,d});
        b[r].pb({l,d});
    }
    rep(i,0,100001)x[i]=1e18;
    rep(i,0,100001)if(!vis[i])dfs(i,i,0);
    rety;
    return 0;
}

signed main(){
    auto start = high_resolution_clock::now();
    IOS;
    int t=1;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
   // cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cerr<<"Time taken:"<<duration.count()/1000000.0<<"seconds"<<"\n";
    return 0;
} 

Measured memory_bytes: 24324
#include <stdio.h>
#include <math.h>
int main(void){
    long long x,i,j;
    scanf("%lld",&x);
    int s = sqrt(x);
    for(i=s;i>0;i--){
        if(x%i==0){
            j = x/i;
            printf("%lld",i+j-2);
            return 0;
        }
    }
}

Measured memory_bytes: 128
// Aizu Vol-1 0198: Trouble in Shinagawa's Artifacts
// 2017.8.17 bal4u@uu

#include <stdio.h>
#include <string.h>

int r[24][7] = {
	{ 0,1,2,3,4,5,6 }, { 0,1,3,5,2,4,6 }, { 0,1,4,2,5,3,6 }, { 0,1,5,4,3,2,6 },
	{ 0,2,6,3,4,1,5 }, { 0,2,3,1,6,4,5 }, { 0,2,1,4,3,6,5 }, { 0,2,4,6,1,3,5 },
	{ 0,3,1,2,5,6,4 }, { 0,3,2,6,1,5,4 }, { 0,3,5,1,6,2,4 }, { 0,3,6,5,2,1,4 },
	{ 0,4,1,5,2,6,3 }, { 0,4,2,1,6,5,3 }, { 0,4,5,6,1,2,3 }, { 0,4,6,2,5,1,3 },
	{ 0,5,1,3,4,6,2 }, { 0,5,3,6,1,4,2 }, { 0,5,4,1,6,3,2 }, { 0,5,6,4,3,1,2 },
	{ 0,6,2,4,3,5,1 }, { 0,6,3,2,5,4,1 }, { 0,6,5,3,4,2,1 }, { 0,6,4,5,2,3,1 } };

char a[32][8];
char f[32];

int same(int x, int y)
{
	int i, j;
	char buf[8];
	for (i = 0; i < 24; i++) {
		for (j = 1; j <= 6; j++) buf[j] = a[y][r[i][j]];
		if (strncmp(a[x] + 1, buf + 1, 6) == 0) return 1;
	}
	return 0;
}

int main()
{
	int n;
	int i, j, c;
	char buf[10];

	while (scanf("%d", &n) == 1 && n) {
		for (i = 0; i < n; i++) {
			f[i] = 0;
			for (j = 1; j <= 6; j++) scanf("%s", buf), a[i][j] = buf[0];
		}
		for (i = 0; i < n; i++) {
			if (f[i]) continue;
			for (j = i + 1; j < n; j++) if (same(i, j)) f[j] = 1;
		}
		for (c = i = 0; i < n; i++) if (f[i]) c++;
		printf("%d\n", c);
	}
	return 0;
}

Measured memory_bytes: 624
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
using namespace std;
int read(){
	char ch=getchar();int x=0,op=1;
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
#define N 100005
int n,head[N],cnt,dia,rt,ans,f[N],col[N],vis[N];
char s[N];
struct edge{int to,nxt;}e[N<<1];
void adde(int x,int y){e[++cnt].to=y;e[cnt].nxt=head[x];head[x]=cnt;}
void ins(int x,int y){adde(x,y);adde(y,x);}
void dfs(int u,int pr){
	if (!col[u]) vis[u]=1;
	for (int i=head[u],v;i;i=e[i].nxt) if ((v=e[i].to)!=pr){
		dfs(v,u);
		vis[u]|=vis[v];
	}
}
void dfs2(int u,int pr){
	int val,mx=0,mx2=0;
	if (!col[u]) val=2;else val=0;
	for (int i=head[u],v;i;i=e[i].nxt){
		v=e[i].to;if (!vis[v]||v==pr) continue;
		ans+=2;dfs2(v,u);
		if (f[v]+val>mx) mx2=mx,mx=f[v]+val;
		else if (f[v]+val>mx2) mx2=f[v]+val;
	}
	f[u]=mx;dia=max(dia,mx+mx2-val);
}
int main(){
	n=read();
	rep (i,1,n-1){int x=read(),y=read();ins(x,y);}
	scanf("%s",s+1);rep (i,1,n) col[i]=s[i]=='B';//白0黑1
	rt=0;rep (i,1,n) if (!col[i]){rt=i;break;}
	if (!rt){cout<<0;exit(0);}
	dfs(rt,0);
	rep (u,1,n) if (vis[u]){
		for (int i=head[u];i;i=e[i].nxt) if (vis[e[i].to]) col[u]^=1;
		ans+=!col[u];
	}
	dfs2(rt,0);
	ans-=dia;
	cout<<ans<<'\n';
	return 0;
}
/*
20
2 19
5 13
6 4
15 6
12 19
13 19
3 11
8 3
3 20
16 13
7 14
3 17
7 8
10 20
11 9
8 18
8 2
10 1
6 13
WBWBWBBWWWBBWWBBBBBW

*/

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
typedef pair<ll,ll>pll;
const  ll MAX=100000;
const  ll MOD=1e9+7;
vector<ll>sot,unsot;
ll f[MAX+100];
int main()
{

   ll n;

   cin>>n;

   ll ara[n+3];

   for(ll i=0;i<n;i++)cin>>ara[i];

   sort(ara,ara+n);


   double sum=0,a;

   a=ara[0];

  for(ll i=1;i<n;i++)
  {

      a+=ara[i];

      sum=a/2;

      a=sum;


  }

  cout<<sum<<endl;


}




Measured memory_bytes: 3776
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    d = list(map(int, input().split()))
    res = 0
    for i in combinations(d, 2):
        i = list(i)
        res += i[0] * i[1]
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
k, n = map(int, input().split())
A = list(map(int, input().split()))

L =[]
for i in range(1,n):
    L.append(A[i]-A[i-1]) #A[0],A[-1]以外のの道
L.append(k-A[-1] + A[0])#A[0],A[-1]の道
print(k - max(L))#一つだけ通らなくてもいい

Measured memory_bytes: 25840
#include<bits/stdc++.h>
#define ll long long
using namespace std;
priority_queue <ll> q;
ll n,x,Ans;
int main()
{
	scanf("%lld",&n);
	ll t=0;
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		q.push(x);
	}
	while(q.top()+t>=n)
	{
		ll x=(q.top()+t)/n,y=(q.top()+t)%n;q.pop();
		Ans+=x;
		ll now=0;/*
		while(x>=n)
		{
			Ans+=(n-1)*x/n;
			now+=x/n*(n-1);
			x=x%n+x/n*(n-1);
		}*/
		//cout<<x<<endl;
		y+=now;
		t+=x;
		q.push(y-t);
		//cout<<y<<endl;
	}/*
	for (int i=1;i<=n;i++)
	{
		printf("%lld ",q.top()+t);q.pop();
	}*/
	printf("%lld\n",Ans);
}

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

int main(){
    int S;
    cin >> S;
    int A = S;

    int count = 0;

    for(int i = 1; i <= A; i++){
        if(i < 10){
            count++;
        }
        else if(i >= 100 && i < 1000){
            count++;
        }
        else if(i >= 10000 && i < 100000){
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3588
using System;

namespace ABC077
{
    public class Problem_A
    {
        public static void Main(string[] args)
        {
            var line1 = Console.ReadLine();
            var line2 = Console.ReadLine();
            if (line1[0] == line2[2] && line1[1] == line2[1] && line1[2] == line2[0]) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<string> A(n), B(m);
  rep(i, n) cin >> A[i];
  rep(i, m) cin >> B[i];
  bool ans = false;
  rep(i, n) rep(j, n) {
    if(i+m>n || j+m>n) continue;
    bool ok = true;
    rep(k, m) rep(l, m) {
      if(A[i+k][j+l] != B[k][l]) {
        ok = false;
        break;
      }
    }
    if(ok) {
      ans = true;
      break;
    }
  }
  cout << (ans ? "Yes" : "No") << "\n";
  return 0;
}


Measured memory_bytes: 3612
#pragma GCC optimize "O3"
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define REP_FROM(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define REP_REV(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define REP_FROMREV(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#ifndef LOCAL
#define cerr if (false) cerr
#endif
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <class T> T sq(T x) { return x * x; }
template <class T> T clamp(T a, T l, T r) { return min(max(a, l), r); } // [l, r]
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int isRightTriangle(int a, int b, int c) {
	if(a > b && a > c)
		return b*b+c*c == a*a;
	else if(b > a && b > c)
		return a*a+c*c == b*b;
	else
		return a*a+b*b == c*c;
}

int main(int argc, char *argv[]) {
	// Something to do
	int n;
	cin >> n;
	REP(i, n) {
		int a, b, c;
		cin >> a >> b >> c;
		if(isRightTriangle(a,b,c))
			cout << "YES" << endl;
		else
			cout << "NO"  << endl;
	}
	return 0;
}

Measured memory_bytes: 3004
import sys
import math

def resolve():
    N, M = list(map(int, input().split()))
    AB = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1])
    broken = None
    cnt = 0
    for ab in AB:
        a, b = ab
        if broken and a <= broken < b:
            continue
        broken = b-1
        cnt += 1
    print(cnt)

    

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 65368
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	inputList, _ := toIntArray(splitInput(scanner, " "))
	x := new(big.Int)
	y := new(big.Int)
	z := new(big.Int)
	a := new(big.Int).SetInt64(int64(inputList[0]))
	b := new(big.Int).SetInt64(int64(inputList[1]))

	gcd := z.GCD(x, y, a, b)

	fmt.Println(z.Mul(z.Div(a, gcd), b))
}

func splitInput(scanner *bufio.Scanner, sep string) []string {
	scanner.Scan()
	return strings.Split(scanner.Text(), sep)
}

func toIntArray(str []string) ([]int, error) {
	length := len(str)
	resVal := make([]int, length)
	var err error
	for i := 0; i < length; i++ {
		resVal[i], err = strconv.Atoi(str[i])
		if err != nil {
			return nil, err
		}
	}
	return resVal, nil
}


Measured memory_bytes: 640
until (n = gets.to_i).zero?
  arr = []
  
  n.times do |i|
    arr[i] = gets.split.map(&:to_i)
    arr[i][n] = 0
    
    n.times do |j|
      arr[i][n] += arr[i][j]
    end
  end
  
  arr[n] = Array.new(n + 1, 0)
  
  (n + 1).times do |i|
    str = ""
    
    (n + 1).times do |j|
      arr[n][i] += arr[j][i] unless j == n
      str += sprintf("%5d", arr[i][j])
    end
    
    puts str
  end
end

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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define endl "\n"

vector<ll> adj[100005];
ll h[100005];
ll p[100005];
vector<ll> lvl[100005];
bool visited[100005];

void dfs(ll x)
{
    visited[x] = true;

    for(ll i = 0 ; i < adj[x].size() ; i++)
    {
        ll adjver = adj[x][i];

        if(!visited[adjver])
        {
            p[adjver] = x;
            h[adjver] = h[x] + 1;
            dfs(adjver);
        }
    }
}

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

    // cout<<fixed<<setprecision(15);

    ll n,k;
    cin>>n>>k;

    for(ll i = 0 ; i < n - 1 ; i++)
    {
        ll u,v;
        cin>>u>>v;

        adj[u].pb(v);
        adj[v].pb(u);
    }

    p[1] = -1;
    h[1] = 0;
    dfs(1);

    for(ll i = 1 ; i <= n ; i++)
    {
        // cout<<h[i]<<" "<<i<<endl;
        lvl[h[i]].pb(i);
    }

    ll t1 = k - 2;

    ll ans = k;

    for(ll i = 1 ; i <= n ; i++)
    {
        if(ans == 0)
        {
            break;
        }

        for(ll j = 0 ; j < lvl[i].size() ; j++)
        {

            ll t2 = t1;

            ll ver = lvl[i][j];
            // cout<<ver<<" "<<adj[ver].size()<<endl;
            // cout<<t2<<endl;

            if((adj[ver].size() - 1) > t2)
            {
                ans = 0;
                break;
            }

            for(ll k = 0 ; k < adj[ver].size() ; k++)
            {
                ll ver1 = adj[ver][k];

                if(ver1 == p[ver])
                    continue;

                ans = (ans * t2) % mod;
                t2--;
            }
        }
    }

    if((adj[1].size()) > (k - 1))
    {
        ans = 0;
    }
    else
    {

        ll t1 = k - 1;

        for(ll i = 0 ; i < adj[1].size() ; i++)
        {
            ans = (ans * t1) % mod;
            t1--;
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    vec<ll> X(N),Y(N);
    vec<ll> x(N),y(N);
    for(int i=0;i<N;i++){
        cin >> X[i] >> Y[i];
        x[i] = X[i],y[i] = Y[i];
    }
    ll ans = 4e18;
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    for(int a=0;a<N;a++) for(int b=a+1;b<N;b++){
        for(int c=0;c<N;c++) for(int d=c+1;d<N;d++){
            int cnt = 0;
            for(int i=0;i<N;i++) cnt += x[a]<=X[i] && X[i]<=x[b] && y[c]<=Y[i] && Y[i]<=y[d];
            if(cnt>=K) ans = min(ans,(x[b]-x[a])*(y[d]-y[c]));
        }
    }
    cout << ans << "\n";
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
template<typename T> bool chmax(T &a, T b) {if(a <= b){a = b; return true;}return false;}
template<typename T> bool chmin(T &a, T b) {if(a >= b){a = b; return true;}return false;}


int main(void){
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > a(n);
    rep(i, n)cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());
    int count = 0, now = 0;
    ll sum = 0;
    while(count < m){
        if(a[now].second){
            a[now].second--;
            sum += a[now].first;
            count++;
        }else{
            now++;
        }
    }
    cout << sum << endl;
}

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

typedef tuple<int, int, int, int> P;

P rot(P p) {
	int a, b, c, d;
	tie(a, b, c, d) = p;
	return make_tuple(b, c, d, a);
}

int index_of(vector<P> &a, P b) {
	int k = lower_bound(a.begin(), a.end(), b) - a.begin();
	if (k >= a.size() || a[k] != b) return a.size();
	return k;
}

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

	vector<int> a(n * 4), b(n * 4), c(n * 4), d(n * 4);
	for (int i = 0; i < n; i++) {
		cin >> a[i * 4] >> b[i * 4] >> c[i * 4] >> d[i * 4];
		for (int j = 1; j < 4; j++) {
			a[i * 4 + j] = d[i * 4 + j - 1];
			b[i * 4 + j] = a[i * 4 + j - 1];
			c[i * 4 + j] = b[i * 4 + j - 1];
			d[i * 4 + j] = c[i * 4 + j - 1];
		}
	}
	n *= 4;

	vector<P> dict;
	for (int i = 0; i < n; i++) {
		dict.emplace_back(a[i], b[i], c[i], d[i]);
	}
	sort(dict.begin(), dict.end());
	dict.erase(unique(dict.begin(), dict.end()), dict.end());

	vector<long long> cnt(dict.size() + 1);
	vector<int> next(dict.size() + 1);
	for (int i = 0; i < n; i++) {
		P p(a[i], b[i], c[i], d[i]);
		int k = index_of(dict, p); 
		cnt[k]++;
		next[k] = index_of(dict, rot(p));
	}
	next[dict.size()] = dict.size();

	long long ans = 0;
	for (int i = 0; i < n; i += 4) {
		for (int j = 0; j < n; j++) {
			if (i / 4 == j / 4) continue;
			int x = index_of(dict, P(a[i], b[i], c[i], d[i]));
			int y = index_of(dict, P(a[j], b[j], c[j], d[j]));
			for (int k = 0; k < 4; k++) {
				cnt[x]--;
				cnt[y]--;
				x = next[x];
				y = next[y];
			}

			int p[4];
			p[0] = index_of(dict, P(d[j], c[j], b[i], a[i]));
			p[1] = index_of(dict, P(b[i], c[j], b[j], c[i]));
			p[2] = index_of(dict, P(d[j], a[i], d[i], a[j]));
			p[3] = index_of(dict, P(d[i], c[i], b[j], a[j]));

			long long prod = 1;
			for (int k = 0; k < 4; k++) {
				prod *= cnt[p[k]];
				for (int l = 0; l < 4; l++) {
					cnt[p[k]]--;
					p[k] = next[p[k]];
				}
			}
			for (int k = 0; k < 4; k++) {
				for (int l = 0; l < 4; l++) {
					cnt[p[k]]++;
					p[k] = next[p[k]];
				}
			}

			for (int k = 0; k < 4; k++) {
				cnt[x]++;
				cnt[y]++;
				x = next[x];
				y = next[y];
			}

			ans += prod;
		}
	}
	cout << ans / 6 << endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <utility>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s){int c;
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int fib (int a, int b, int c, int n) {
	switch (n) {
	case 1: return a;
	case 2: return b;
	case 3: return c;
	default: return fib(b, c, a + b + c, n - 1);
	}
}

int main() {
	for (int n; (n = in());)
		out(fib(1, 2, 4, n)/3650 + 1, '\n');
}


Measured memory_bytes: 2476
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

struct Z {
	ll num, den;
};

int main() {
	string str;
	while ( cin >> str, str != "#" ) {
		vector<int> v;
		int pos = 0;
		while ( pos < str.size() ) {
			switch (str[pos]) {
				case 'n': v.push_back(0); pos += 5; break;
//				case 's': v.push_back(180); pos += 5; break;
//				case 'e': v.push_back(270); pos += 4; break;
				case 'w': v.push_back(90); pos += 4; break;
			}
		}
		Z ans = (Z){v[v.size()-1], 1};
		for (int i = v.size()-2; i >= 0; --i) {
			int f = v[i] == 0 ? -1 : 1;
//			ans = (Z){ ans.num + ans.den * v[i], ans.den * 2 };
			ans = (Z){ ans.num * 2 + f * 90, ans.den * 2 };
		}
		while (ans.num % 2 == 0 && ans.den % 2 == 0) {
			ans.num /= 2;
			ans.den /= 2;
		}
		if (ans.den > 1) cout << ans.num << "/" << ans.den << endl;
		else cout << ans.num << endl;
	}
}

Measured memory_bytes: 1212
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] valuesCount = new int[N];
        for (int i = 0; i < N; i++) {
            int value = sc.nextInt();
            valuesCount[value] = valuesCount[value] + 1;
        }

        if (N % 2 == 1) {
            if (valuesCount[0] != 1) {
                System.out.println(0);
                return;
            }

            for (int i = 2; i < N; i += 2) {
                if (valuesCount[i] != 2) {
                    System.out.println(0);
                    return;
                }
            }
        } else {
            for (int i = 1; i < N; i += 2) {
                if (valuesCount[i] != 2) {
                    System.out.println(0);
                    return;
                }
            }
        }

        int pow = N / 2;
        long ans = 1;
        for (int i = 0; i < pow; i++) {
            ans *= 2;
            ans = ans % 1000000007l;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 52612
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int[] x = new int[N];
		int[] y = new int[M];
		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
		}
		for (int i = 0; i < M; i++) {
			y[i] = sc.nextInt();
		}
		Arrays.sort(x);
		Arrays.sort(y);
		String ans = "War";
		for (int i = x[N-1] + 1; i <= y[0]; i++) {
			if (i <= Y && i > X) {
				ans = "No War";
				break;
			}
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll fact(ll n){ll s=1; for(ll i=1;i<=n;i++)s*=i; return s;}
ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second<b.second);} 


void solve()
{
    double n;
    cin>>n;
    cout<<2.0*3.14159265358979323846*n;
    return;
}

int main()
{
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3760
#include <stdio.h>

int main(void)
{
	int H, W, i, j;

	while (1)
	{
		scanf("%d %d", &H, &W);

		if (H == 0 && W == 0)break;

		if (H % 2)
		{
			if (W % 2)
			{
				for (i = 0; i < H / 2; i++)
				{
					for (j = 0; j < W / 2; j++)
						printf("#.");
					printf("#\n");
					for (j = 0; j < W / 2; j++)
						printf(".#");
					printf(".\n");
				}
				for (j = 0; j < W / 2; j++)
					printf("#.");
				printf("#\n");
			}
			else
			{
				for (i = 0; i < H / 2; i++)
				{
					for (j = 0; j < W / 2; j++)
						printf("#.");
					putchar('\n');
					for (j = 0; j < W / 2; j++)
						printf(".#");
					putchar('\n');
				}
				for (j = 0; j < W / 2; j++)
					printf("#.");
				putchar('\n');
			}
		}
		else
		{
			if (W % 2)
			{
				for (i = 0; i < H / 2; i++)
				{
					for (j = 0; j < W / 2; j++)
						printf("#.");
					printf("#\n");
					for (j = 0; j < W / 2; j++)
						printf(".#");
					printf(".\n");
				}
			}
			else
			{
				for (i = 0; i < H / 2; i++)
				{
					for (j = 0; j < W / 2; j++)
						printf("#.");
					putchar('\n');
					for (j = 0; j < W / 2; j++)
						printf(".#");
					putchar('\n');
				}
			}
		}

		putchar('\n');

	}

	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define P pair<int,int>
#define All(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
typedef long long ll;
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const ll LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
	return 0;
}

Measured memory_bytes: 768
A,B=sorted(map(int,input().split()))
mod=10**9+7

if B-A>1:
    print(0)

elif B-A==1:
    ANS=1
    
    for i in range(1,A+1):
        ANS=ANS*i%mod

    for i in range(1,B+1):
        ANS=ANS*i%mod

    print(ANS)

else:
    ANS=1
    
    for i in range(1,A+1):
        ANS=ANS*i%mod

    for i in range(1,B+1):
        ANS=ANS*i%mod

    print(ANS*2%mod)
    

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

int N,M,P;
int X[111];
int main(){
  while( cin >> N >> M >> P && (N||M||P) ){
    int sum = 0;
    for(int i=0;i<N;i++) {
      cin >> X[i];
      sum += X[i];
    }
    sum*=100;
    sum*=(100-P);
    if( X[M-1] == 0 ) cout << 0 << endl;
    else {
      sum/=X[M-1];
      sum/=100;
      cout << sum << endl;
    }
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#include <set>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
const int maxn = 1e6+7;

int main(){
	ll a,b,k;
	cin>>a>>b>>k;
	set<ll> s;
	int cnt=0;
	for(int i=a;i<=b;i++){
		if(cnt>=k){
			break;
		}
		s.insert(i);
		cnt++;
	}
	cnt=0;
	for(int i=b-k+1;i>=a;i++){
		if(cnt>=k||i>b){
			break;
		}
		s.insert(i);
		cnt++;
	}
	set<ll>::iterator it;
	for(it=s.begin();it!=s.end();it++){
		cout<<*it<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int n,Q;
    cin >> n >> Q;
    stack<int> S[n];
    vector<int> ans;
    rep(i, Q){
        int q, t, x;
        cin >> q;
        switch (q)
        {
        case 0:
            cin >> t >> x;
            S[t].push(x);
            break;
        case 1:
            cin >> t;
            if(!S[t].empty()) ans.push_back(S[t].top());
            break;        
        case 2:
            cin >> t;
            if(!S[t].empty()) S[t].pop();
            break;
        }
    }
    int N = ans.size();
    rep(i, N) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 4308
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String arg=sc.next();
        int ANS=0;
        
        for(int i=0;i<4;i++){
            if(arg.charAt(i)=='+'){
                ANS++;
            }else{
                ANS--;
            }
        }
        
        System.out.println(ANS);
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;

/**
 * Created by pc on 2019/12/01.
 */
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int[][] Days= {{0,0},{0,0}};

		for(int i = 0; i<2; i++){
			Days[i][0] = sc.nextInt();
			Days[i][1] = sc.nextInt();
		}

		boolean isLastday = false;
		if(Days[0][0]  != Days[1][0]){
			isLastday = true;
		}
		System.out.print(isLastday ? 1 :0);

	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define pi pair<int,int>
bool comparator(pair<int,pair<int,int>> a, pair<int,pair<int,int>> b){
    return a.ss.ss < b.ss.ss;
}

string s;
int dp[3005][3005];

int init(int n){
    dp[n-1][1] = 1 ;
    for(int i = 2 ; i<= n ; i++) dp[n-1][i] = 0;
    for(int i = n-2 ; i>=0 ; i--){
        for(int j = 1 ; j <= n-i ; j++){
            if(s[i] == '<'){
                dp[i][j] = dp[i+1][j-1];
            }
            else {
                dp[i][j] = (mod + dp[i+1][n-i-1] - dp[i+1][j-1])%mod;
            }
        }
        for(int j = 2 ; j <= n-i ; j++) dp[i][j] = (dp[i][j]+dp[i][j-1])%mod;
    }
    cout << dp[0][n] << endl;
}


int32_t main(){
    int n;
    cin >> n;
    memset(dp,0,sizeof(dp));
    cin >> s;
    init(n);
}


Measured memory_bytes: 70784
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int N, a[200009], b[200009], t[20][1 << 19], ans = 0; vector<int>p[30];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i];
	for (int i = 0; i < N; i++) cin >> b[i];
	for (int i = 0; i <= 29; i++) {
		if (i < 18) {
			for (int j = 0; j < N; j++) { t[i][b[j] % (1 << i)]++; t[i][(b[j] % (1 << i)) + (1 << i)]++; }
			for (int j = 1; j < (2 << i); j++) t[i][j] += t[i][j - 1];
		}
		else {
			for (int j = 0; j < N; j++) { p[i].push_back(b[j] % (1 << i)); p[i].push_back((b[j] % (1 << i)) + (1 << i)); }
			sort(p[i].begin(), p[i].end());
		}
	}
	for (int i = 0; i < N; i++) {
		int sum = 0;
		for (int j = 0; j <= 28; j++) {
			sum = (a[i] & ((2 << j) - 1));
			int LL = (3 << j) - sum; LL %= (2 << j);
			int RR = LL + (1 << j);
			int pos1 = 0;
			int pos2 = 0;
			if (j >= 17) {
				pos1 = lower_bound(p[j + 1].begin(), p[j + 1].end(), LL) - p[j + 1].begin();
				pos2 = lower_bound(p[j + 1].begin(), p[j + 1].end(), RR) - p[j + 1].begin();
			}
			else {
				pos1 = 0; if (LL >= 1)pos1 = t[j + 1][LL - 1];
				pos2 = t[j + 1][RR - 1];
			}
			if ((pos2 - pos1) % 2 == 1) {
				ans ^= (1 << j);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 56944
# /usr/bin/python
# -*- coding: utf-8 -*-
import math



def main():
  ## input
  A,B,C,D,E,F = map(int, input().split())

  # water list
  dp = [0 for i in range(F+1)]
  dp[100*A]=1
  if 100*B<=F: dp[100*B]=1
  Wn = set([100*A,100*B])
  for i in range(A,F+1):
    if dp[i]>0:
      Wn.add(i)
      if i+100*A<=F: dp[i+100*A]=1
      if i+100*B<=F: dp[i+100*B]=1

  # sugar list
  dp = [0 for i in range(F+1)]
  dp[C],dp[D]=[1,1]
  Sn = set([C,D])
  for i in range(C,F+1):
    if dp[i]>0:
      Sn.add(i)
      if i+C<=F: dp[i+C]=1
      if i+D<=F: dp[i+D]=1

  # solve
  ret = [0.0, 100*A, 0]
  for w in Wn:
    for s in Sn:
      if w+s>F or 100*s>E*w:
        continue
      elif 100*s/(w+s) > ret[0]:
        ret = [100*s/(w+s),w+s,s]
  return [ret[1],ret[2]]



if __name__ == "__main__":
  w,s = main()
  print(w,s)

Measured memory_bytes: 40432
//#include "bits\stdc++.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
typedef long long LL;

int main()
{
    int n, c = 1;
    cin >> n;

    while (n - (c * 2) >= 0)
    {
        c *= 2;
    } 

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
	int A,B;
    cin>>A>>B;

    if(A+B>=10){
        cout<<"error"<<endl;
    }
    else{
        cout<<A+B<<endl;
    }
}

Measured memory_bytes: 3540
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner IN = new Scanner(System.in);
        int N = IN.nextInt();
        int ans = 0;
        for (int i = 1; i <= N; i += 2) {
            if (countY(i) == 8) {
                ans++;
            }
        }
        System.out.println(ans);
    }

    public static int countY(int x) {
        int result = 0;
        for(int i = 1; i <= x; i++) {
            if (x % i == 0) {
                result++;
            }
        }
        return result;
    }
}


Measured memory_bytes: 22740
n, k = map(int, input().split())
A = [*map(int, input().split())]
A.sort(reverse=True)
ng, ok = 0, 1<<30
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A:
        d = (a - 1) // m
        if d == 0: break
        c += d
    if c <= k: ok = m
    else: ng = m
print(ok)


Measured memory_bytes: 30916
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 200005;
const int MM = 1000000007;

ll A[MX], B[MX];
int N;

ll DnC(int s, int e){
	if( s > e ) return 0;
	if( s == e ) return B[s];
	int m = (s+e) / 2;
	ll l = 0, total = 0, r = 0;
	for(int i = m; i >= s; i--){
		total += B[i];
		l = max(l, total - A[m] + A[i]);
	}
	total = 0;
	for(int i = m; i <= e; i++){
		total += B[i];
		r = max(r, total - A[i] + A[m]);
	}
	return max({DnC(s, m-1), DnC(m+1, e), l+r-B[m]});
}

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%lld%lld", A+i, B+i);
	printf("%lld\n", DnC(1, N));
}


Measured memory_bytes: 3328
#include <iostream>
using namespace std;
#define MAX 100000
typedef long long llong;
 
int n,k;
llong T[MAX];
 
int check(long p){
    int i =0;
    for (int j=0;j<k;j++){
        llong s=0;
        while(s+T[i]<=p){
            s +=T[i];
            i++;
            if (i==n) return n;
        }
    }
    return i;
}
 
 
int solve(){
    llong left =0;
    llong right = 100000 * 10000;
    llong mid;
    while(right - left >1 ){
        mid =(left+right)/2;
        int v=check(mid);
        if(v>=n)right=mid;
        else left=mid;
    }
    return right;
}
 
 
main(){
    cin >> n >> k;
    for (int i =0; i<n;i++){
    cin >> T[i];
    }
    llong ans=solve();
    cout << ans << endl;
}


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

using namespace std;

int main() {
    
    size_t H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    for (size_t h = 0; h < H; ++h) {
        cin >> S[h];
    }

    size_t res = 10e10;
    for (size_t mask = 0; mask < 1ll << (H - 1ll); ++mask) {
        vector<size_t> gr(H + 1, 0);
        size_t answ_cnt = 0;
        for (size_t i = 0; i < H; ++i) {
            if ((mask >> i) & 1) {
                gr[i + 1] = gr[i] + 1;
                ++answ_cnt;
            }
            else {
                gr[i + 1] = gr[i];
            }
        }

        size_t sub_res = answ_cnt;
        bool update = true;
        vector<int> w_cnt(answ_cnt + 1);
        for (size_t w = 0; w < W; ++w) {
            vector<int> h_cnt(answ_cnt + 1);
            bool action = false;
            for (size_t h = 0; h < H; ++h) {
                w_cnt[gr[h]] += S[h][w] - '0';
                h_cnt[gr[h]] += S[h][w] - '0';
                if (w_cnt[gr[h]] > K) action = true;
                if (h_cnt[gr[h]] > K) update = false;
            }
            if (action) ++sub_res, w_cnt = h_cnt;
        }
        if (update) res = std::min(res, sub_res);
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m; cin >> n >> m;
    vector<vll> x(n, vll(3));
    rep(i, n) rep(j, 3) cin >> x[i][j];

    ll res = 0; 
    rep(k, bit(3)){
        using Elem = tuple<ll, int>;
        vector<Elem> tbl(n);
        rep(i, n){
            ll cur = 0;
            rep(j, 3){
                cur += (((k >> j) & 1) ? +1:-1) * x[i][j];
            }
            tbl[i] = Elem(cur, i);
        }
        sort(_all(tbl), greater<Elem>());

        vll sum(3);
        rep(j, m){
            int i; tie(ignore, i) = tbl[j];
            rep(k, 3){
                sum[k] += x[i][k];
            }
        }

        ll cur = 0;
        rep(i, 3) cur += abs(sum[i]);

        chmax(res, cur);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 384
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Char (digitToInt)

main :: IO ()
main = do
  xs <- getc $ solve . map digitToInt
  mapM_ print xs

solve :: [Int] -> Int
solve xs
  | null ys = y
  | otherwise = solve (y:ys)
  where (y:ys) = rdc xs
        
rdc :: [Int] -> [Int]
rdc [x] = []
rdc (x:y:ys) = add x y : rdc (y:ys)
  where
    add a b = (a + b) `mod` 10

getc :: (String -> a) -> IO [a]
getc f = map f . lines <$> getContents

Measured memory_bytes: 3672
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] s = new char[str.length()];
        s = str.toCharArray();    

        StringBuilder ans = new StringBuilder("");

        for(int i = 0 ; i < str.length() ; i ++){
            if (s[i] == '0' || s[i] == '1') {
                ans.append(s[i]);
//                System.out.println(s[i]);
//                System.out.println(ans);
            }

            else if(ans.length() != 0){
                ans.setLength(ans.length()-1);
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
s = int(input())
l = []
flag = False
cnt = 0
tmp = 0
while flag==False:
  if tmp in l:
    cnt += 1
    flag = True
  else:
    if s % 2 == 0:
      tmp = s / 2
      l.append(s)
      s = tmp
      cnt += 1
    else:
      tmp = 3*s +1
      l.append(s)
      s = tmp
      cnt += 1
      
print(cnt)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int a[n];
  int one;
  int i;
  for(i=0;i<n;i++){
    cin >> a[i];
    if(a[i]==1)one=i;
  }
  int ans=0;
  if(n==k)ans=1;
  else{
    if((n-1)%(k-1)==0)ans = (n-1)/(k-1);
    else ans= (n-1)/(k-1)+1;
  }
  cout << ans;
}


Measured memory_bytes: 640
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007
int sum(int n) {
	int sol = 0;
	while(n>0) {
		sol+=n%10;
		n/=10;
	}
	return sol;
}
void solve(int test_case) {
	int n;
	cin>>n;
	int s = sum(n);
	if(n%s==0) {
		cout<<"Yes";
	}else cout<<"No";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3568
# include <bits/stdc++.h>
typedef long long lint;
using namespace std;

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  lint n,k; cin >> n >> k;
  vector<lint> a(n); for(lint i=0;i<n;i++) { cin >> a[i]; }

  k %= 1000000007;

  lint ans=0;
  lint cnt0=0, cnt1=0;
  for(lint i=0;i<n;i++) {
    for(lint j=0;j<n;j++) {
      if(a[i] > a[j]) {
        cnt1++;
        if(i < j) { cnt0++; }
      }
    }
  }

  ans = (cnt0*k + (k*(k-1)/2)%1000000007*cnt1)%1000000007;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
typedef pair<int,int> pii;
typedef pair <long long,long long> pll;
typedef long long ll; 
typedef long double ld; 
const ll mod = 1e9+7;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); 
    string s,t,ans = "";
    cin >> s >> t;
    int n = s.size() , m = t.size();
    vector < vector <int> > dp(n+1, vector <int>(m+1,0));
  
    for(int i = n-1 ; i >= 0 ;i--)
    {	for(int j = m-1 ; j >= 0; j--)
		{	
			if(s[i] == t[j])
				dp[i][j] = 1 + dp[i+1][j+1];
			else
				dp[i][j] = max(dp[i+1][j],dp[i][j+1]);
		}
	}
	for(int i = 0, j = 0; i < n && j < m ; )
	{		if(s[i] == t[j])
			{	ans += t[j]; i++; j++;	}
			else{ 
				if(dp[i+1][j] >= dp[i][j+1])
					i++;
				else 
					j++;
			}
	}
	cout<<ans;
    return 0;
}
 


Measured memory_bytes: 35584