akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
 
int main()
{
    int n;
     
    while (cin >> n, n) {
        int cnt = 0;
        unsigned long long int s[4002] = {0}, gs[4002] = {0};

        int t, cost, num;

        for (int i = 0; i < n; i++) {
            cin >> num >> t >> cost;
            s[num] += t*cost;
            gs[i] = num;
        }
         
	for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if(gs[i] == gs[j] && i < j) {
                    gs[j] = 4001;
                }
            }
        }
         
        for (int i = 0; i < n; i++) {
            if (s[gs[i]] >= 1000000) {
                cout << gs[i] << endl;
                cnt++;
            }
        }
        if (!cnt) cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yn(int o){
    if (o == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

struct point {
    vector<int> to;
};

int main() {
    int n; cin >> n;
    cout << 10 - n / 200 << endl;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  int nsize = (int)s.size();

  for(int i = 0; i < nsize; ++i){
    char ch = s[i];
    int ich = int(ch);  

    ich += n;
    if(ich>90){
      ich -= 26;
    }

    cout << char(ich);
  }

  cout << endl;

  return 0;
}

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

#define int long long

unsigned long long xor128() {
  static unsigned long long rx = 123456789, ry = 362436069, rz = 521288629, rw = 88675123;
    unsigned long long rt = (rx ^ (rx << 11));
    rx = ry;
    ry = rz;
    rz = rw;
    return (rw = (rw ^ (rw >> 19)) ^ (rt ^ (rt >> 8)));
}

typedef pair<int,int>P;
typedef pair<int,P>P2;

map<P2,int>dp;

signed main(){
  int n;
  cin>>n;
  int _9 = 1;
  for ( int i = 2; i <= 9; i++ ) _9 *= i;  
  while(n--){
    int a[9],b[9];    
    r(i,9)cin>>a[i];
    r(i,9)cin>>b[i];
    sort(a, a+9);    
    int cnt = 0;
    do{
      int sum = 0;
      for ( int i = 0; i < 9; i++ ) {
	if ( a[i] > b[i] ) sum += a[i]+b[i];
      }      
      if ( sum > 171-sum ) cnt++;			     
    }while(next_permutation(a,a+9));
    double ans = (double)cnt/_9;
    // cout << ans << " " << 1.0-ans << endl;
    printf("%.5f %.5f\n",ans,1.0-ans);    
  }
}



Measured memory_bytes: 3208
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>
 
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long int;
 
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

template<typename T>
void print(vector<T> a){
	for (auto x:a){
		cout << x << " ";
	}
	cout << endl;
}

template<typename T>
void print2d(vector<vector<T>> a){
	for (auto v:a){
		for (auto x:v){
			cout << x << " ";
		}
		cout << endl;
	}
}



int main()
{
	ll n;
	cin >> n;
	for (ll a = 1; a < 3501;a++)
	{
		for (ll b = 1; b < 3501;b++){
			if (4 * a * b - n * a - n * b <= 0)
				continue;
			ll c = (n * a * b) / (4 * a * b - n * a - n * b);
			if (4*a*b*c == n*(a*b+b*c+c*a)){
				cout << a << " " << b << " " << c << endl;
				return 0;
			}
		}
	}
	return 0;
}

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

int n, m;
ll a[101010], c[202020];
P b[101010];

int main(){
  cin >> n >> m;
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i].second >> b[i].first;
  sort(a, a + n);
  sort(b, b + m);
  reverse(b, b + m);
  
  int itr = 0;
  rep(i, m){
    rep(j, b[i].second){
      c[itr + j] = b[i].first;
    }
    itr += b[i].second;
    if(itr >= n) break;
  }
  
  ll res = 0;
  rep(i, n){
    res += max(a[i], c[i]);
  }
  
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 3712
import java.io.*;
import java.util.*;

public class Main{
	
	static long mod=(long)1e9+7;
	
	public static void main(String[] args) throws IOException {
		Writer out=new Writer(System.out);
		Reader in=new Reader(System.in);
		int ts=1;
		
		outer: while(ts-->0) {	
			int n=in.nextInt();
			int k=in.nextInt();
			int a[]=in.readArray(n);
			sort(a);
			int ans=0;
			for(int i=0; i<k; i++) ans=ans+a[i];
			out.println(ans);
		}
		out.close();		
		
	}

	static boolean tri(int a, int b, int c) {
		if(c<a+b && c>abs(a-b)) return true;
		return false;
	}
	
	
/*********************************** UTILITY CODE BELOW **************************************/	
		
	static int abs(int a) {
		return a>0 ? a : -a;
	}
	
	static int max(int a, int b) {
		return a>b ? a : b;
	}
	
	static int pow(int n, int m) {
		if(m==0) return 1;
		int temp=pow(n,m/2);
		long res=(((long)temp*temp)%mod);
		if(m%2==0) return (int)res;
		return (int)((res*n)%mod);
	}
	
	static class Pair{
		int u, v;
		
		Pair(int u, int v){this.u=u; this.v=v;}
		
		static void sort(Pair [] coll) {		
			List<Pair> al=new ArrayList<>(Arrays.asList(coll));
			Collections.sort(al,new Comparator<Pair>() {
				public int compare(Pair p1, Pair p2) {
					return p1.u-p2.u;
				}	
			});
			for(int i=0; i<al.size(); i++) {
				coll[i]=al.get(i);
			}
		}
		
	}
	
	static void sort(int[] a) {
		ArrayList<Integer> list=new ArrayList<>();
		for (int i:a) list.add(i);
		Collections.sort(list);
		for (int i=0; i<a.length; i++) a[i]=list.get(i);
	}
	
	static int [] array(int n, int value) {	
		int a[]=new int[n];
		for(int i=0; i<n; i++) a[i]=value;
		return a;
	}
	
	static class Reader{
		
		BufferedReader br;
		StringTokenizer to;
		
		Reader(InputStream stream){
			br=new BufferedReader(new InputStreamReader(stream));
			to=new StringTokenizer("");
		}
		
		String next() {
			while(!to.hasMoreTokens()) {
				try {
					to=new StringTokenizer(br.readLine());	
				}catch(IOException e) {}
				
			}
			return to.nextToken();
			
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0; i<n ;i++) a[i]=nextInt();
			return a;
		}
		long [] readLongArray(int n) {
			long a[]=new long[n];
			for(int i=0; i<n ;i++) a[i]=nextLong();
			return a;
		}
		
	}
	
	static class Writer extends PrintWriter{
		Writer(OutputStream stream){
			super(stream);
		}
		void println(int [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
		void println(long [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
	}
	
}

Measured memory_bytes: 33232
def main():
    def fib(n):
        a = 1
        b = 1
        if n == 0:
            return a
        elif n == 1:
            return b
        else:
            for i in range(n-1):
                a, b = b, a + b
            return b
    
    n = int(input())
    print(fib(n))
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 5600
import sys, collections, bisect, itertools, heapq, math, copy, string
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I() - 1

    ans = ''
    while N >= 26:
        ans += string.ascii_lowercase[N%26]
        N = N // 26 - 1
    ans += string.ascii_lowercase[N%26]

    print(ans[::-1])

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_3_D
{
    public class Program

    {
        public struct Pond
        {
            public int StartPoint { get;}
            public int Width { get;}
            public Pond(int startPoint, int width)
            {
                this.StartPoint = startPoint;
                this.Width = width;
            }
        }

        public static void Main(string[] args)
        {
            string line = ReadSt();
            Stack<Pond> ponds = new Stack<Pond>();
            Stack<int> areas = new Stack<int>();

            int startPoint = 0;
            int width = 0;

            for (int i = 0 ; i < line.Length ; i++)
            {
                if (line[i] == '\\')
                {
                    areas.Push(i);
                }
                else if (line[i] == '/' && areas.Count > 0)
                {
                    startPoint = areas.Pop();
                    width += i - startPoint;

                    while (ponds.Count > 0 && ponds.Peek().StartPoint > startPoint) //池の結合
                    {
                        width += ponds.Pop().Width;
                    }
                    ponds.Push(new Pond(startPoint, width));
                    width = 0;
                }
            }

            Console.WriteLine(ponds.Sum(x => x.Width));
            Console.WriteLine("{0}{1}", ponds.Count.ToString(), (ponds.Count > 0) ? " " + string.Join(" ", ponds.Select(x => x.Width.ToString()).Reverse().ToArray()): "");
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 18900
S = list(input())
st = [0]*len(S)
string = "ACGT"
for i in range(len(S)):
    if S[i] in string:
        st[i] += 1

st_1 = [1]*len(S)

count = []
temp = 0

for i in range(len(st)):
    if st[i] == st_1[i]:
        temp += 1
    else:
        count.append(temp)
        temp = 0
    if i+1 == len(st):
        count.append(temp)
        
#print(st)
if count:
    print(max(count))
else:
    print(0)

Measured memory_bytes: 3064
A, B, K = map(int,input().split(" "))

smaller = min(A, B)

lst = []
cnt = 1 
for i in range(1, smaller+1, 1):
  if A % i == 0 and B % i == 0:
    lst.append(i)
sorted_lst = sorted(lst,reverse=True)

print(sorted_lst[K-1])



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    long long v[n];
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v,v+n,greater<long long>());
    long long m=0;
    for(int i=0;i<a;i++)m+=v[i];
    cout<<m/a<<".";
    m%=a;
    m*=1000000000;
    cout<<m/a<<endl;
    a--,b--;
    int l=lower_bound(v,v+n,v[a],greater<long long>())-v,r=upper_bound(v,v+n,v[a],greater<long long>())-v;
    int vali=r-l;
    long long c[vali+1];//combination
    //MAX = 50 C 25 < 1.3*10^14
    long long wa[vali+1];
    c[0]=1;
    wa[0]=1;
    for(int i=1;i<=vali;i++){
        c[i]=c[i-1]*(vali-i+1)/i;
        wa[i]=wa[i-1]+c[i];
    }
    if(v[a]<v[0])cout<<c[a-l+1]<<endl;
    else{
        if(v[a]==v[b]){//vali C a～b
            cout<<wa[b-l+1]-wa[a-l]<<endl;
        }
        else{//vali C a～vali
            cout<<wa[vali]-wa[a-l]<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3640
def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    counter = {}
    for num in A:
        counter[num] = counter.get(num, 0) + 1
    for i in range(1, N+1):
        print(counter.get(i, 0))

if __name__ == "__main__":
    solve()

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll N;
VL A;

int main() {
    cin >> N;
    ll sum = 0;
    REP(i, N) {
        A.emplace_back(IN());
        sum += A[i];
    }
    if(sum % (N * (N + 1) / 2)) {
        cout << "NO"
             << "\n";
    } else {
        ll k = sum / (N * (N + 1) / 2);
        VL B(N);
        REP(i, N) {
            B[i] = A[(i + 1) % N] - A[i];
            if(B[i] - k > 0 || (B[i] - k) % N) {
                cout << "NO"
                     << "\n";
                return 0;
            }
        }
        cout << "YES"
             << "\n";
    }
}


Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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


    if(s == "SUN")cout << 7 << endl;
    else if(s == "MON")cout << 6 << endl;
    else if(s == "TUE")cout << 5 << endl;
    else if(s == "WED")cout << 4 << endl;
    else if(s == "THU")cout << 3 << endl;
    else if(s == "FRI")cout << 2 << endl;
    else if(s == "SAT")cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t x, y;
    std::cin >> x >> y;

    std::vector<int64_t> cands;

    // ++++
    if (x <= y) {
        cands.push_back(y - x);
    }

    // inv, ++++, inv
    if (x * (-1) <= y * (-1)) {
        cands.push_back(2 + (y*(-1) - x*(-1)));
    }

    // inv, ++++
    if (x * (-1) <= y) {
        cands.push_back(1 + y - x*(-1));
    }

    // ++++, inv
    if (x <= y * (-1)) {
        cands.push_back(1 + y*(-1) - x);
    }

    std::cout << *std::min_element(cands.begin(), cands.end()) << std::endl;

    return 0;
}


Measured memory_bytes: 256
while True :
    n = int(input())
    if n == 0 :
        break
    
    for i in range(n) :
        x1, y1, z1, w1, x2, y2, z2, w2 = map(int, input().split())
        print((x1*x2 - y1*y2 - z1*z2 - w1*w2), (x1*y2 + x2*y1 + z1*w2 - z2*w1), (x1*z2 - y1*w2 + x2*z1 + y2*w1), (x1*w2 + y1*z2 - y2*z1 + x2*w1))


Measured memory_bytes: 5592
#![allow(unused_imports, non_snake_case)]
use proconio::{
    input, fastout,
    marker::{Chars, Bytes, Usize1}
};

#[fastout]
fn main() {
    input!{
        N:usize,
        Q:usize,
        query:[(usize, usize); Q]
    }
    let mut h = vec![N-2; N];
    let mut w = vec![N-2; N];
    let mut hv = N;
    let mut wv = N;
    let mut ans = 0;
    for &(t, x) in &query {
        if t == 1 {
            if wv > x {
                for i in x..wv {
                    h[i] = hv - 2;
                }
                wv = x;
            }
            ans += h[x];
        } else {
            if hv > x {
                for i in x..hv {
                    w[i] = wv - 2;
                }
                hv = x;
            }
            ans += w[x];
        }
    }
    println!("{}", (N - 2).pow(2) - ans);
}


Measured memory_bytes: 9988
import bisect

n=int(input())
alist = list(map(int, input().split()))
walist=[]
salist=[]
for i in range(n):
    walist.append(alist[i]+i+1)
    if i!=0:
        salist.append(i+1-alist[i])

#print(walist,len(walist))
#print(salist,len(salist))

salist=sorted(salist)
salist2=[]
salist3=[]
mae=0.5
for sl in salist:
    if sl==mae:
        salist2[-1][1]+=1
    else:
        salist2.append([sl, 1])
        salist3.append(sl)
    mae=sl

#print(salist2)
#print(salist3)

answer=0

for i in range(n-1):
    basho=bisect.bisect_left(salist3, walist[i])
    if basho<len(salist3):
        #print(basho, walist[i], salist3[basho])
        if walist[i]==salist3[basho]:
            #print("!")
            answer+=salist2[basho][1]
    #print(salist[i+1])
    if i!=n-2:
        basho=bisect.bisect_left(salist3, salist[i])
        salist2[basho][1]-=1
    #print(salist2, answer)

print(answer)

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

bool myComparison(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}


int main(){
	int n=0;
	vector<int> re;
	while(cin>>n,n!=0){
		vector< pair<int,int > > v;
		for(int i=0;i<n;i++){
			int t1,t2;
			cin>>t1>>t2;
			v.push_back(make_pair(t1,t2));
		}
		sort(v.begin(),v.end(),myComparison);
		int flag=0;
		int load=0;
		for(int i=0;i<v.size();i++){
			load+=v[i].first;
			if(load>v[i].second){
				flag=1;
				break;
			}
		}
		if(flag==0){
			re.push_back(1);
		}else{
			re.push_back(0);
		}
	}
	for(int i=0;i<re.size();i++){
		if(re[i]==1){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
}
//ワーシャルフロイド法



Measured memory_bytes: 3068
# coding: utf-8
# 80
import itertools

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n+ 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
    

while True:
    a=int(input())
    if a==0:
        break
    #print(a)
    s=primes(a)
    
    #print(s)
    c=0
    for r in itertools.combinations(s,2):
        if r[0]+r[1]==a:
            c += 1
            #print(r)
    if a/2 in s:
        c += 1
    print(c)
            


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#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 MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long double> v(n);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  sort(ALL(v));
  long double res = v[0];
  for (int i = 1; i < n; i++) {
    res = (res + v[i]) / 2;
  }

  cout<<setprecision(15);
  cout << res << endl;

}


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

int main(void) {
    int N;
    cin >> N;
    vector<long double> x(N), y(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }

    int nfact = 1;
    long double sum = 0;
    for (int i = 2; i <= N; i++) {
        nfact *= i;
    }
    int mfact = nfact / N;
    for (int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            sum += 2 * mfact * sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
        }
    }
    printf("%.10Lf\n", sum / (long double) nfact);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  int N;
  cin >> N;
  cout << N/3 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  for(int i = 0; i < H; i++){
    cin >> a[i];
  }
  vector<bool> x(H,false);
  vector<bool> y(W,false);
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(a[i][j] == '#'){
        x[i] = true;
        y[j] = true;
      }
    }
  }
  for(int i = 0; i < H; i++){
    if(x[i]){
      for(int j = 0; j < W; j++){
        if(y[j]){
          cout << a[i][j];
        }
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    int a,b;
    cin >> a >> b;

    if(a==1 && b!=1){
        cout << "Alice" << endl;
        return 0;
    }else if(a!=1 && b==1){
        cout << "Bob" << endl;
        return 0;
    }else if(a==1 && b==1){
        cout << "Draw" << endl;
        return 0;
    }

    if(a>b){
        cout << "Alice" << endl;
    }else if(a<b){
        cout << "Bob" << endl;
    }else{
        cout << "Draw" << endl;
    }

    return 0;
}


Measured memory_bytes: 3648
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N * 3];
		sc.fill(a);

		Arrays.sort(a);
		for (int i = 0; i < a.length / 2; i++) {
			int tmp = a[i];
			a[i] = a[a.length - i - 1];
			a[a.length - i - 1] = tmp;
		}

		long sum = 0;
		for (int i = 0; i < N * 2; i += 2) {
			sum += a[i + 1];
			debug(i, a[i + 1]);
		}

		System.out.println(sum);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 28640
#include"bits/stdc++.h"
#include<atcoder/scc.hpp>
using namespace atcoder;
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pll = pair<ll, ll>;
using tp3 = tuple<ll, ll, ll>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

int main()
{
    int N, M;
    cin >> N >> M;
    scc_graph scc(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        scc.add_edge(a, b);
    }
    auto res = scc.scc();
    cout << res.size() << endl;
    for (auto group : res) {
        cout << group.size();
        for (auto num : group) {
            cout << " " << num;
        }
        cout << endl;
    }
    return 0;
}


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

using namespace std;

const int INF = 1 << 30;

struct SegNode
{
  int v;

  SegNode(int v) : v(v) {}

  SegNode operator*(const SegNode &r) const
  {
    return (v < r.v ? *this : r);
  }
} e(INF);

struct SegmentTree
{
  int sz;
  vector< SegNode > seg;

  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz - 1, e);
  }

  void update(int k, const SegNode &x)
  {
    k += sz - 1;
    seg[k] = x;
    while(k > 0) {
      k = (k - 1) >> 1;
      seg[k] = seg[2 * k + 1] * seg[2 * k + 2];
    }
  }

  SegNode query(int a, int b, int k, int l, int r)
  {
    if(a >= r || b <= l) return (e);
    if(a <= l && r <= b) return (seg[k]);
    return (query(a, b, 2 * k + 1, l, (l + r) >> 1) * query(a, b, 2 * k + 2, (l + r) >> 1, r));
  }

  SegNode query(int a, int b)
  {
    return (query(a, b, 0, 0, sz));
  }
};

int main()
{
  int N, K;
  string S, T;

  cin >> N >> K;

  cin >> S;
  cin >> T;

  vector< int > sweep(N + 1);
  for(int i = 0; i + 1 < N; i++) {
    if(T[i] != T[i + 1]) sweep[i + 1] = 1;
    sweep[i + 1] += sweep[i];
  }

  SegmentTree seg(N);
  vector< int > dp(N + 1, INF);
  dp[0] = 0;
  seg.update(0, 0);
  for(int i = 1; i <= N; i++) {
    dp[i] = dp[i - 1] + (S[i - 1] != T[i - 1]);
    int ret = seg.query(i - K, i - 1).v;
    dp[i] = min(dp[i], (ret + 3 + sweep[i - 1]) / 2);
    seg.update(i, dp[i] * 2 - sweep[i]);
  }

  cout << dp.back() << endl;
}

Measured memory_bytes: 12120
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}

int main() {
	///stuck for 90min
	Int n; cin >> n;
	Int num =n;
	if (n == 0) {
		cout << 0;
		return 0;
	}
	Int temp = 0;
	vector<int> ans;
	Int i = 0;
	while (num != 0) {
		temp = abs(num) % 2;
		ans.push_back(temp);
		if (i % 2 == 0)  num -= temp;
		else num += temp;
		num = num / 2;
		i++;
	}
	reverse(ans.begin(), ans.end());
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i];
	}


	
	//cout << (-9) % (-2);

	cout << endl;
	return 0;
}

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > Matrix;

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

	cin >> a >> b >> t;

	cout << (int)((t + 0.5) / a) * b;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define iter vector<int>::iterator
#define mod 1000000007
#define inf 1e16
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    int n,k;
    cin>>n>>k;
 
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int dp[n+1][k+1];
    dp[1][0]=1;
    dp[0][0]=0;
    for(int i=1;i<k+1;i++)
    {
        if(i<=a[0])
            dp[1][i]=dp[1][i-1]+1;
        else
            dp[1][i]=dp[1][i-1];
        dp[0][i]=0;
    }
 
    for(int i=2;i<n+1;i++)
    {
        for(int j=0;j<k+1;j++)
        {
            if(j-a[i-1]-1>=0)
                dp[i][j]=((dp[i-1][j]%mod)-(dp[i-1][j-a[i-1]-1]%mod))%mod;
            else
                dp[i][j]=dp[i-1][j]%mod;
 
            if(j>0)
                dp[i][j]=((dp[i][j]%mod)+(dp[i][j-1]%mod) + mod)%mod;
        }
    }
    
    if(k-1>=0)
        cout<<((dp[n][k]%mod)-(dp[n][k-1]%mod) + mod)%mod<<"\n";
    else
        cout<<dp[n][k]%mod<<"\n";
 
    
 
 
}

Measured memory_bytes: 79104
#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;
    using YPI = tuple<int ,int, int>;
    vector<YPI> ypi(m);
    rep(i, m){
        int p, y; cin >> p >> y;
        p--;
        ypi[i] = YPI(y, p, i);
    }

    sort(_all(ypi));

    vi idx(n);
    vector<string> res(m);
    for(auto& e : ypi){
        int p, k; tie(ignore, p, k) = e;
        int i = idx[p]++;

        stringstream ss;
        ss << setw(6) << setfill('0') << p+1;
        ss << setw(6) << setfill('0') << i+1;

        res[k] = ss.str();
    }

    for(auto& e : res){
        cout << e << endl;
    }

    return 0;
}


Measured memory_bytes: 8576
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<algorithm>

using namespace std;

int n, k;
int a[200010];
int maxb;
int main()
{
	cin >> k >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		a[i] %= k;
	}
	sort(a+1, a+n+1);
	
	cout << endl;
	for(int i = 2; i <= n; i++)
	{
		maxb = max(maxb, a[i] - a[i-1]);
	}
	maxb = max(maxb, k - a[n] + a[1]);
	cout << k - maxb << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

int bingo[3][3];
bool flag[3][3];

void check(int x){
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            if(bingo[i][j] == x){
                flag[i][j] = true;
            }
        }
    }
}

bool judge(){
    bool f = false;
    // horizontal
    for(int i = 0; i < 3; i++){
        f |= (flag[i][0] && flag[i][1] && flag[i][2]);
    }
    // vertical
    for(int i = 0; i < 3; i++){
        f |= (flag[0][i] && flag[1][i] && flag[2][i]);
    }
    // cross
    f |= (flag[0][0] && flag[1][1] && flag[2][2]);
    f |= (flag[2][0] && flag[1][1] && flag[0][2]);
    return f;
}

int main(){
    for(int i = 0; i < 3; i++){
        std::cin >> bingo[i][0] >> bingo[i][1] >> bingo[i][2];
    }
    int n;
    std::cin >> n;
    for(int i = 0; i < n; i++){
        int b;
        std::cin >> b;
        check(b);
    }
    std::cout << (judge() ? "Yes" : "No") << std::endl;
    return 0;
}


Measured memory_bytes: 256
// AOJ 2883: Proof of Knowledge
// 2018.7.11 bal4u

#include <stdio.h>

char tr['d'+1];

char *calc(int *ans, char *S, char *P)
{
	int v1, v2;
	char op;
	
    if (*S == '[') {
        op = *(++S), S++;
        if (*S == '[') S = calc(&v1, S, P);
        else v1 = P[tr[*S++]];

        if (*S == '[') S = calc(&v2, S, P);
        else v2 = P[tr[*S++]];
		
        if      (op == '+') *ans = v1 | v2;
        else if (op == '*') *ans = v1 & v2;
        else                *ans = v1 ^ v2;
	} else *ans = P[tr[*S++]];
    while (*S == ']') S++;
    return S;
}

char S[100];
char p[10000][4];

int main()
{
	int i, k, val, cnt;
	char P[10];

	for (i = 0; i < 4; i++) tr['a'+i] = i;
	for (i = 0; i < 10000; i++) {
		p[i][0] = i/1000;
		p[i][1] = (i/100)%10;
		p[i][2] = (i/10)%10;
		p[i][3] = i%10;
	}

	while (fgets(S, 100, stdin) && *S != '.') {
		fgets(P, 10, stdin);
		for (i = 0; i < 4; i++) P[i] &= 0xf;
		calc(&val, S, P), cnt = 0;
		for (i = 0; i < 10000; i++) {
			calc(&k, S, p[i]);
			if (k == val) cnt++;
		}
		printf("%d %d\n", val, cnt);
	}
	return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(0, i, N)
    {
        cin >> A.at(i);
        int c = 0;
        while (A.at(i) > 0 && (A.at(i) % 2 == 0))
        {
            c++;
            A.at(i) /= 2;
        }
        A.at(i) = c;
    }
    sort(all(A));
    cout << A.at(0) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
int main()
{
	double t,x;
	scanf("%lf%lf",&t,&x);
	printf("%.10f",t/x);
    return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

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

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

  int N;
  cin >> N;
  cout << "ABC" << N << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;



char A[1010][1010];
int cum[1010][11];
void solve() {
	int H, W, K; cin >> H >> W >> K;
	REP(i, H)REP(j, W)cin >> A[i][j];
	REP(j, W) {
		REP(i, H) {
			cum[j][i + 1] += cum[j][i];
			if (A[i][j] == '1')cum[j][i + 1] += 1;
		}
	}
	ll ans = 1e18;
	REP(bit, 1 << (H - 1)) {
		vector<int>divi;
		divi.push_back(0);
		REP(j, H-1) {
			if (bit&(1 << j))divi.push_back(j + 1);
		}
		divi.push_back(H);
		int siz = divi.size();
		siz--;
		int res = siz - 1;

		vector<int>sum(siz,0);
		REP(j, W) {
			bool over = false;
			REP(i, siz) {
				//pe(divi[i]); print(divi[i + 1]);
				sum[i] += cum[j][divi[i + 1]] - cum[j][divi[i]];
				if (sum[i] > K)over = true;
			}
			if (over) {
				res++;
				REP(i, siz) {
					sum[i] = cum[j][divi[i + 1]] - cum[j][divi[i]];
					if (sum[i] > K) { res = 1e9; goto END; }
				}
			}
			
		}
	END:;
		//pe(bit);

	 //print(res);
		ans = min(ans, res);
	}
	print(ans);
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 384
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a[] = sc.next().split("");
    String b[] = sc.next().split("");
    String c[] = sc.next().split("");
    System.out.println(a[a.length-1].equals(b[0]) && b[b.length-1].equals(c[0]) ? "YES" : "NO");
  }
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)

#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(void)
{
    int r,c;
    cin>>r>>c;
    vector<vector<int>> x(r+1,vector<int>(c+1));
    REP(i,r) {
        REP(j,c) {
            cin>>x.at(i).at(j);
            x.at(i).at(c)+=x.at(i).at(j);
            x.at(r).at(j)+=x.at(i).at(j);
        }
        x.at(r).at(c)+=x.at(i).at(c);
    }
    //REP(i,c) x.at(r).at(c)+=x.at(r).at(i);
    REP(i,r+1) {
        REP(j,c+1) {
            cout<<x.at(i).at(j);
            if(c!=j) cout<<' ';
            else cout<<endl;
        }
    }
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=3e5+5;
int tr[MN<<2],tag[MN<<2];
#define mid (l+r>>1)
#define ls (t<<1)
#define rs (t<<1|1)
void build(int t,int l,int r){
	tr[t]=tag[t]=0;if(l==r)return;
	build(ls,l,mid);build(rs,mid+1,r);
}
inline void pushdown(int t){
	if(!tag[t])return;
	tag[ls]+=tag[t];tr[ls]+=tag[t];
	tag[rs]+=tag[t];tr[rs]+=tag[t];
	tag[t]=0;
}
void update(int t,int l,int r,int a,int b,int v){
	if(a<=l&&r<=b){tag[t]+=v,tr[t]+=v;return;}
	pushdown(t);
	if(a<=mid)update(ls,l,mid,a,b,v);
	if(b>mid)update(rs,mid+1,r,a,b,v);
	tr[t]=max(tr[ls],tr[rs]);
}
void update(int t,int l,int r,int pos,int v){
	if(l==r){tr[t]+=v;return;}
	pushdown(t);
	if(pos<=mid)update(ls,l,mid,pos,v);
	else update(rs,mid+1,r,pos,v);
	tr[t]=max(tr[ls],tr[rs]);
}
int n,m,k,X[MN],Y[MN],id[MN],Ans;
typedef pair<int,int>pii;
#define fi first
#define se second
pii s1[MN],s2[MN];
void solve(){
	for(reg int i=1;i<=k;i++)id[i]=i;
	build(1,1,k);
	sort(id+1,id+1+k,[](int a,int b){
		return X[a]==X[b]?Y[a]<Y[b]:X[a]<X[b];
	});
	reg int t1=0,t2=0;
	for(reg int i=1;i<k;i++){
		if(Y[id[i]]<=m/2){
			reg int cur=i-1;
			while(t1&&s1[t1].fi<Y[id[i]]){
				update(1,1,k,s1[t1].se,cur,s1[t1].fi-Y[id[i]]);
				cur=s1[t1].se-1;t1--;
			}
			if(cur!=i-1)s1[++t1]=make_pair(Y[id[i]],cur+1);
		}
		else{
			reg int cur=i-1;
			while(t2&&s2[t2].fi>Y[id[i]]){
				update(1,1,k,s2[t2].se,cur,Y[id[i]]-s2[t2].fi);
				cur=s2[t2].se-1;t2--;
			}
			if(cur!=i-1)s2[++t2]=make_pair(Y[id[i]],cur+1);
		}
		s1[++t1]=make_pair(0,i);
		s2[++t2]=make_pair(m,i);
		update(1,1,k,i,m-X[id[i]]);
		Ans=max(Ans,tr[1]+X[id[i+1]]);
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(reg int i=1;i<=k;i++)scanf("%d%d",X+i,Y+i);
	k++;X[++k]=n;Y[k]=m;solve();
	for(reg int i=1;i<=k;i++)swap(X[i],Y[i]);
	swap(n,m);solve();
	printf("%d\n",Ans*2);
	return 0;
}

Measured memory_bytes: 16128
N,M = map(int,input().split())
X = list(map(int,input().split()))

ans = 0

if N >= M:
  pass
else:
  X.sort()
  dist = []

  for i in range(1,M):
    dist.append(abs(X[i]-X[i-1]))
  dist = sorted(dist, reverse= True)

  ans = sum(dist[N-1:])

print(ans)

Measured memory_bytes: 13960
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

int n,m;

int yes=0;

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		if(x%2==1)
		{
			printf("first");
			exit(0);
		}
	}
	printf("second");
}

Measured memory_bytes: 256