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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define Graph vector<vector<int>>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";



int main(){

    long long N;
    scanf("%lld",&N);

    int a, b, c;

    a = N % 10;
    b = ((N - a) / 10) % 10;
    c = (N - b * 10 - a) / 100;

    if(a==7||b==7||c==7){
        cout << "Yes" << endl;
    }

    else{
        cout << "No" << endl;
    }


    return 0;
}


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

int main() {
  int N; cin >> N;
  vector<char> s(N); for (int i = 0; i < N; i++) cin >> s[i];
  bool ans {};
  for (int i = 0; i < N; i++) if (s[i] == 'Y') ans = true;
  cout << ( (ans) ? "Four" : "Three" ) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=1e4+10,D=110,mod=1e9+7;
int n,d;
ll dp[N][D][2][2];
string s;
ll solve(int i,int mo,bool les,bool use){
    if(i==n){
        return (mo==0 && use!=0);
    }
    ll &ret = dp[i][mo][les][use];
    if(ret+1)return ret;
    ret = 0;
    if(les){
        for(int j=0;j<10;j++){
            ret += solve(i+1,(mo+j)%d,1,use|j);
            ret %= mod;
        }
    }
    else{
        for(int j=0;j<=s[i]-'0';j++){
            ret += solve(i+1,(mo+j)%d,(j<s[i]-'0'),use|j);
            ret %= mod;
        }
    }
    return ret;
}

int main ()
{
    FASTIO
    memset(dp,-1,sizeof dp);
    cin >> s >> d;
    n = s.si;
    cout << solve(0,0,0,0) << endl;
    return 0;
}
/**

*/


Measured memory_bytes: 35584
n=int(input())
f=[]
for i in range(n):
    f.append(list(map(int,input().split())))
p=[]
for i in range(n):
    p.append(list(map(int,input().split())))
a=0
ans=-(10**10)
for k in range(1,1024):
    a=0
    x=bin(k)
    y=[0]*10
    for i in range(2,len(x)):
        y[10-len(x)+i]+=int(x[i])
    for i in range(n):
        m=0
        t=0
        for j in range(10):
            if y[j]+f[i][j]==2:
                t+=1
        m+=p[i][t]
        a+=m
    ans=max(a,ans)
print(ans)

Measured memory_bytes: 91908
open Str

type card = {suit : char; value : int}

let card_of_string s = {suit = s.[0]; value = Char.code s.[1] - Char.code '0'}
let string_of_card c = String.init 2 (fun i -> if i = 0 then c.suit else Char.chr (c.value + Char.code '0'))

let is_stable rl sl =
  if List.stable_sort (fun x y -> compare x.value y.value) rl = sl then "Stable" else "Not stable"
              
let bubble_sort c n =
  let a = Array.of_list c in
  let rec iter i j =
    if i = n then Array.to_list a
    else if j = i then iter (i+1) (n-1)
    else if a.(j).value < a.(j-1).value
    then begin
        let t = a.(j) in
        a.(j) <- a.(j-1);
        a.(j-1) <- t;
        iter i (j-1)
      end
    else iter i (j-1)
  in iter 0 (n-1)
      
let selection_sort c n =
  let a = Array.of_list c in
  let rec iter i j minj =
    if i = n then Array.to_list a
    else if j = n then begin
        let t = a.(i) in
        a.(i) <- a.(minj);
        a.(minj) <- t;
        iter (i+1) (i+1) (i+1)
      end
    else if a.(j).value < a.(minj).value then iter i (j+1) j
    else iter i (j+1) minj
  in iter 0 0 0

let read_list () =
  split (regexp " +") (read_line ())

let print_cards cs = List.map string_of_card cs |> String.concat " " |> print_endline
                                                                          
let () =
  let n = read_int () in
  let cs = List.map card_of_string (read_list ()) in
  let bs = bubble_sort cs n in
  let ss = selection_sort cs n in
  print_cards bs;
  is_stable cs bs |> print_endline;
  print_cards ss;
  is_stable cs ss |> print_endline

Measured memory_bytes: 2124
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define vi vector<int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;



int main(){
    int n; cin >> n;
    
    bool s[14],h[14],c[14],d[14];
    
    //初期化
    rep(i,14){
        s[i] = h[i] = c[i] = d[i] = 0;
    }
    
    //バケット
    rep(i,n){
        char suit; int a;
        cin >> suit >> a;
        
        if(suit == 'S') s[a] = 1;
        if(suit == 'H') h[a] = 1;
        if(suit == 'C') c[a] = 1;
        if(suit == 'D') d[a] = 1;
        
    }
    //表示
    Rep(i,1,14){
        if(!s[i]) cout << "S " << i << endl;
    }
    Rep(i,1,14){
        if(!h[i]) cout << "H " << i << endl;
    }
    Rep(i,1,14){
        if(!c[i]) cout << "C " << i << endl;
    }
    Rep(i,1,14){
        if(!d[i]) cout << "D " << i << endl;
    }
}






Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << endl

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


int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N;
  cin >> N;
  vector<int> L(N*2);
  vector<int> C;
  rep(i, N*2){
    cin >> L[i];
  }

  sort(L.begin(), L.end());
  rep(i, N*2){
    if(i % 2 == 0){
      C.push_back(L[i]);
    }
  }
  cout << accumulate(C.begin(), C.end(), 0) << endl;

  return 0;
}

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

#define upto(i,s,e,d) for(int i=(s);i<(e);i+=(d))

using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  int n,d; cin>>n>>d;
  vvi x(n, vi(d));
  upto(i,0,n,1)upto(j,0,d,1)cin>>x[i][j];
  int c=0;
  upto(i,0,n-1,1){
    vi &a=x[i];
    upto(j,i+1,n,1){
      vi &b=x[j];
      int t=0;
      upto(k,0,d,1) t+=pow(a[k]-b[k], 2);
      int s=sqrt(t);
      if(s*s==t) c++;
    }
  }
  cout<<c<<endl;
}

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

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

  for (int i = 0; i < H; ++i) {
    if (i == 0) cout << string(W+2, '#') << endl;

    for (int j = 0; j < W; ++j) {
      if (j == 0) cout << '#';
      cout << a[i][j];
      if (j == W-1) cout << '#';
    }
    cout << endl;
    if (i == H-1) cout << string(W+2, '#') << endl;
  }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;
typedef pair<ll, ll> Pll; 

int n, k, s;
ll ans;

void rec(int num, int cnt, int sum)
{
	if (sum > s || cnt > k || num < 0) return;
	if (cnt == k) {
		if (sum == s) ans++;
		return;
	}
	rec(num-1, cnt+1, sum+num);
	rec(num-1, cnt, sum);
}

int main()
{
	while (1) {
		cin >> n >> k >> s;
		if (!n && !k && !s) break;

		int t = 0;
		rep(i,0,k) t += n - i;
		if (s > t || k > n) {
			//printf("t=%d k=%d n=%d\n",t,k,n);
			cout << 0 << endl;
			continue;
		}

		ans = 0;
		rec(n,0,0);
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3008
import java.util.Scanner;

public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int h = stdIn.nextInt();
        int w = stdIn.nextInt();
        int k = stdIn.nextInt();

        boolean[][] b = new boolean[h][w];
        String s;
        for(int i=0; i<h; i++){
            s = stdIn.next();
            char[] cs = s.toCharArray();
            for(int j=0; j<w; j++){
                if(cs[j] == '.'){
                    b[i][j] = false;
                }else{
                    b[i][j] = true;
                }
            }
        }

        boolean[] flag = new boolean[h+w+1];

        int ans = 0;
        while(!flag[h+w]){
            boolean[][] copy = new boolean[h][w];
            copy2DArray(b, copy);
            for(int i=0; i<flag.length-1; i++){
                if(flag[i]){
                    if(i < h){
                        for(int j=0; j<copy[0].length; j++){
                            copy[i][j] = false;
                        }
                    }else{
                        for(int j=0; j<copy.length; j++){
                            copy[j][i - h] = false;
                        }
                    }
                }
            }

            int counter = 0;
            for(int i=0; i<copy.length; i++){
                for(int j=0; j<copy[0].length; j++){
                    if(copy[i][j]){
                        counter++;
                    }
                }
            }
            if(counter == k){
                ans++;
            }
            
            changeFlag(flag, 0);
        }

        System.out.println(ans);
    }

    static void changeFlag(boolean[] flag, int idx){
        if(flag[idx]){
            flag[idx] = false;
            changeFlag(flag, idx+1);
            return;
        }else{
            flag[idx] = true;
            return;
        }
    }

    static void copy2DArray(boolean[][] from, boolean[][] to){
        for(int i=0; i<from.length; i++){
            for(int j=0; j<from[0].length; j++){
                to[i][j] = from[i][j];
            }
        }
    }
}


Measured memory_bytes: 37864
import sys
stdin = sys.stdin
import numpy as np

 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, m, x = na()
a = np.array(na())

left = sum(a < x)
right = sum(a > x)
print(left if left < right else right)

Measured memory_bytes: 12440
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>

using namespace std;

template<typename T, typename S>
istream& operator >> (istream& is, pair<T, S>& p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

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

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    vector<int64_t> a(n);
    cin >> a;

    int64_t ans = 0, cur_bar = 0;
    for (auto x : a) {
        if (x <= cur_bar + 1) {
            cur_bar = max(x, cur_bar);
        } else {
            ans += (x - 1) / (cur_bar + 1);
            cur_bar = max(cur_bar, int64_t(1));
        }
    }
    cout << ans;
}


Measured memory_bytes: 3944
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<list>
#include<queue>
#include<numeric>
#include<map>
#include<string>

using namespace std;

char m[2005][2005];
int vertical[2005][2005];
int horizontal[2005][2005];
int main() {
    int h, w;
    char s[2005];

    scanf("%d%d", &h, &w);
    for (int i = 0; i < w+2; i ++) {
      m[0][i] = '#';
      m[h+1][i] = '#';
    }
    for (int i = 0; i < h; i++) {
      scanf("%s", s);
      m[i+1][0] = '#';
      m[i+1][w+1] = '#';
      for (int j = 0; j < w; j++) m[i+1][j+1] = s[j];
    }
    // for (int i = 0; i < h+2; i++) printf(" %s\n", m[i]);

    for (int i = 1; i <= h; i++) {
      int c = 0;
      for (int j = 1; j <= w+1; j++) {
        if (m[i][j] == '#') {
          for (int k = c+1; k < j; k++) vertical[i][k] = j-c-1;
          c = j;
        }
      }
    }

    for (int i = 1; i <= w; i++) {
      int c = 0;
      for (int j = 1; j <= h+1; j++) {
        if (m[j][i] == '#') {
          for (int k = c+1; k < j; k++) horizontal[k][i] = j-c-1;
          c = j;
        }
      }
    }

    // for (int i = 1; i <= h; i++) {
    //   printf("  ");
    //   for (int j = 1; j <= w; j++) {
    //     printf("%d", horizontal[i][j]);
    //   }
    //   printf("\n");
    // }

    int ans = 1;
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w+1; j++) {
        if (m[i][j] == '#') continue;

        ans = max(ans, vertical[i][j]+horizontal[i][j]-1);
      }
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>

using namespace std;

typedef long long ll;

constexpr ll MOD = 1e9 + 7;

ll n, m;

ll get_edge_len(ll n, vector<ll> X) {
    ll xall = 0;
    ll k = 0;
    vector<ll> D(n - 1);
    for (ll i = 0; i < n - 1; i++) {
        D[i] = X[i + 1] - X[i];
    }

    ll len = D.size();
    for (ll i = 0; i < len / 2; i++) {
        k += len - 2 * i;
        xall = (xall + ((k * D[i]) % MOD) + MOD) % MOD;
        xall = (xall + ((k * D[len - 1 - i]) % MOD) + MOD) % MOD;
    }

    if (len % 2) {
        ll i = len / 2;
        k += len - 2 * i;
        xall = (xall + ((k * D[i]) % MOD) + MOD) % MOD;
    }

    return xall;
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    vector<ll> X(n), Y(m);
    for (auto&& x : X) {
        cin >> x;
    }
    for (auto&& y : Y) {
        cin >> y;
    }

    ll xall = 0, yall = 0;

    /*
    for (ll i = 0; i < n; i++) {
        for (ll j = i + 1; j < n; j++) {
            xall = (xall + X[i] - X[j]) % MOD;
        }
    }

    for (ll i = 0; i < m; i++) {
        for (ll j = i + 1; j < m; j++) {
            yall = (yall + Y[i] - Y[j]) % MOD;
        }
    }

    cout << xall << "," << yall << endl;

    cout << "reset" << endl;
    xall = yall = 0;
    */

    // xall = get_edge_len(n, X);
    // yall = get_edge_len(m, Y);

    // cout << xall << "," << yall << endl;

    // from editorial
    for (ll i = 0; i < n; i++) {
        xall = (xall + (i * X[i] - (n - 1 - i) * X[i])) % MOD;
    }

    for (ll i = 0; i < m; i++) {
        yall = (yall + (i * Y[i] - (m - 1 - i) * Y[i])) % MOD;
    }

    cout << (xall * yall) % MOD << endl;

    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define maxn 100005
#define int long long
using namespace std;
int cnt[maxn][2];
int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	
	int ans = 0;
	for(int i=1;i<=2*n;i++) {
		int x,y;
		cin >> x >> y;

		int nx = x;
		if(x<1)
			ans += 1-x , nx = 1;
		else if(x>n)
			ans += x-n , nx = n;
		
		int ny = y-1;
		if(y<1)
			ans += 1-y , ny = 0;
		else if(y>2)
			ans += y-2 , ny = 1;
			
		cnt[nx][ny] ++;
	}
	
	for(int i=1;i<=n;i++) {
		int y[] = {0,1};
		if(cnt[i][0] < cnt[i][1])	swap(y[0],y[1]);
		int need = 1 - cnt[i][y[0]];
		ans += abs(need);
		if(-need > 0 && cnt[i][y[1]] < 1) {
			int tem = min(-need,1-cnt[i][y[1]]);
			need += tem;
			cnt[i][y[1]] += tem;
		}
		cnt[i+1][y[0]] -= need;
		
		need = 1 - cnt[i][y[1]];
		ans += abs(need);
		cnt[i+1][y[1]] -= need;
	}
	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 4764
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> P;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const int inf = 1e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[ry]>rank[rx]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

vector<ll> fac,inv,finv;

void initcom(){
    fac=inv=finv=vector<ll>(1e6);
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(ll i=2;i<1e6;++i){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll com(int n,int k){
    if(n<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
ll mopow(ll a,ll x,ll mod){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}
int main(){
    int n;cin>>n;
    vector<string> s(n);
    int ans=0;
    int ca=0,cb=0,bh=0;
    for(int i=0;i<n;++i){
        cin>>s[i];
        for(int j=0;j<(int)s[i].size()-1;++j){
            if(s[i][j]=='A'&&s[i][j+1]=='B') ans++;
        }
        if(s[i][0]=='B'&&s[i][(int)s[i].size()-1]=='A') bh++;
        else if(s[i][0]=='B') cb++;
        else if(s[i][(int)s[i].size()-1]=='A') ca++;
    }
    if(bh>0){
        ans+=bh-1;
        if(ca>0){
            ans+=1;
            ca--;
        }
        if(cb>0){
            ans+=1;
            cb--;
        }
    }
    ans+=min(ca,cb);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> minus(0);
  vector<int64_t> zero(0);
  vector<int64_t> plus(0);
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    if(x > 0){
      plus.push_back(x);
    }
    else if(x == 0){
      zero.push_back(x);
    }
    else{
      minus.push_back(x);
    }
  }
  int64_t M = minus.size();
  int64_t Z = zero.size();
  int64_t P = plus.size();
  sort(minus.begin(),minus.end());
  sort(plus.begin(),plus.end());
  int64_t ans = 0;
  
  vector<int64_t>::iterator pos;
  int64_t idx;
  
  if(K <= M*P){
    int64_t up = 0;
    int64_t down = -1000000000000000000;
    while(up - down > 1){
      int64_t mid = (up+down)/2;
      int64_t cnt = 0;
      int64_t a = abs(mid);
      for(int i=0; i<minus.size(); i++){      
        int64_t b = abs(minus.at(i));
        pos = lower_bound(plus.begin(),plus.end(),(a+b-1)/b);
        idx = distance(plus.begin(),pos);
        cnt += plus.size() - idx;
      }
      if(cnt < K){
        down = mid;
      }
      else{
        up = mid;
      }
      //cout << mid << " " << cnt << endl;
    }
    ans = up;
  }
  else if(K <= M*P+Z*(P+M)+Z*(Z-1)/2){
    ans = 0;
  }
  
  else{
    K -=  M*P+Z*(P+M)+Z*(Z-1)/2;
    K = P*(P-1)/2 + M*(M-1)/2 - K;
    for(int i=0; i<minus.size(); i++){
      minus.at(i) *= -1;
    }
    sort(minus.begin(),minus.end());
    int64_t up = 1000000000000000000;
    int64_t down = 0;
    while(up - down > 1){
      int64_t mid = (up+down)/2;
      int64_t cnt = 0;
      for(int64_t i=0; i<minus.size(); i++){
        int64_t b = minus.at(i);
        pos = lower_bound(minus.begin(),minus.end(),(mid+b-1)/b);
        idx = distance(minus.begin(),pos);
        if(idx <= i && idx != minus.size()){
          idx = min(i+1,(int64_t)minus.size());
        }
        cnt += minus.size() - idx;
      }
      for(int64_t i=0; i<plus.size(); i++){
        int64_t b = plus.at(i);
        pos = lower_bound(plus.begin(),plus.end(),(mid+b-1)/b);
        idx = distance(plus.begin(),pos);
        if(idx <= i && idx != plus.size()){
          idx = min(i+1,(int64_t)plus.size());
        }
        cnt += plus.size() - idx;
      }
      if(cnt > K){
        down = mid;
      }
      else{
        up = mid;
      }
      //cout << mid << " " << cnt << endl;
    }
    ans = down;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2548
#define _CRT_SECURE_NO_WARNINGS
#define NOMINMAX
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INF = (int) 1e9;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.00001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

ll C[51][51];
void make(int n) {
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			if (i == 0 || j == i) C[i][j] = 1;
			else C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
		}
	}
}
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	int n, a, b;
	cin >> n >> a >> b;
	vector<ll> v(n);
	for (int i = 0; i < n; i++) cin >> v[i];
	make(n);
	sort(full(v), greater<ll>());
	double mavg = 0;
	for (int i = 0; i < a; i++) mavg += v[i];
	mavg /= a;
	int an = 0, ap = 0;
	for (int i = 0; i < n; i++) {
		if (v[i] == v[a - 1]) {
			an++;
			if (i < a) ap++;
		}
	}
	ll cnt;
	if (ap == a) {
		cnt = 0;
		for (ap = a; ap <= b; ap++) {
			cnt += C[an][ap];
		}
	}
	else {
		cnt = C[an][ap];
	}
	cout << setprecision(12) << fixed << mavg << endl;
	cout << cnt << endl;
	return 0;
}


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

int main(){
    int N,M;
    vector<long long> A,B,C;
    

    scanf("%d%d",&N,&M);
    for(int i=0; i<N; i++){
        long long a;
        cin>>a;
        A.push_back(a);
    }
    for(int j=0; j<M; j++){
        long long b,c;
        cin>>b>>c;
        B.push_back(b);
        C.push_back(c);
    }
    vector<size_t> ind(C.size());
    iota(ind.begin(),ind.end(),0);
    sort(ind.begin(),ind.end(),[&C](size_t i1, size_t i2){
        return C[i1]>C[i2];
    });
    sort(A.begin(),A.end());
    long long ans = 0;
    for(int i=0; i<A.size(); i++) ans+=A[i];
    int indc = 0;

    for(int i=0; i<N; i++)
    {
        
    if(indc>=M) break;
        if(B[ind[indc]]==0)indc++;
        if(indc>=M) break;
        long long c = C[ind[indc]];
        B[ind[indc]]--;
        if(A[i]<c){
            ans+=c-A[i];
        }
        else break;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3484
use proconio::input;
use proconio::marker::*;
use std::collections::HashMap;

pub const ALL_DIRS: [(isize, isize); 8] = [
    // 時計回り
    (-1, 0),  // 上
    (-1, 1),  // 右上
    (0, 1),   // 右
    (1, 1),   // 右下
    (1, 0),   // 下
    (1, -1),  // 左下
    (0, -1),  // 左
    (-1, -1), // 左上
];

fn main() {
    input! {
        h: usize, w: usize, n: usize,
        abv: [(Usize1, Usize1); n]
    };

    let is_ok = |i: usize, j: usize| -> bool { i > 0 && i < h - 1 && j > 0 && j < w - 1 };
    let mut table = HashMap::new();
    for (a, b) in abv {
        let i = a;
        let j = b;
        if is_ok(i, j) {
            *table.entry((i, j)).or_insert(0) += 1;
        }
        for &(di, dj) in &ALL_DIRS {
            let new_i = i as isize + di;
            let new_j = j as isize + dj;
            if new_i < 0 || new_i >= h as isize || new_j < 0 || new_j >= w as isize {
                continue;
            }
            let new_i = new_i as usize;
            let new_j = new_j as usize;
            if is_ok(new_i, new_j) {
                *table.entry((new_i, new_j)).or_insert(0) += 1;
            }
        }
    }
    let all_count = (w - 3 + 1) * (h - 3 + 1);
    let mut counts = vec![0; 10];
    for (_, c) in table {
        counts[c] += 1;
    }
    let zero_count = all_count - counts.iter().skip(1).sum::<usize>();
    counts[0] = zero_count;
    for c in counts {
        println!("{}", c);
    }
}


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

int w,h,sx,sy,gx,gy;
int mas[101][101],used[101][101];
int dx[] = {0,1,0,-1},dy[] = {1,0,-1,0};

void make_map(int x,int y,int chk,int color){
  if(chk == 0){
    for(int i=y;i<y+2;i++){
      for(int j=x;j<x+4;j++) mas[i][j] = color;
    }
  }
  else {
    for(int i=y;i<y+4;i++){
      for(int j=x;j<x+2;j++) mas[i][j] = color;
    }
  }
}

bool dfs(int x,int y){
  used[y][x] = true;
  if(x == gx && y == gy) return true;
  for(int i=0;i<4;i++){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx >= 0 && nx < w && ny >= 0 && ny < h && mas[ny][nx] == mas[sy][sx] && !used[ny][nx]) dfs(nx,ny);
  }
  return used[gy][gx];
}

int main(){
  int n;
  while(cin >> w >> h,w||h){
    fill_n(mas[0],101*101,0);
    memset(used,false,sizeof(used));
    cin >> sx >> sy >> gx >> gy >> n;
    --sx; --sy; --gx; --gy;
    while(n--){
      int c,d,x,y; cin >> c >> d >> x >> y; --x; --y;
      make_map(x,y,d,c);
    }
    cout << (dfs(sx,sy)? "OK" : "NG") << endl;
  }
}

Measured memory_bytes: 1244
from itertools import combinations
import numpy as np
n = int(input())

testimonies = []

for i in range(n):
    A_i = int(input())
    testimonies.append([])
    for j in range(A_i):
        x_ij, y_ij = map(int, input().split())
        testimonies[i].append([x_ij-1, y_ij])

ans = 0
for i in range(n):
    i = n - i
    contradiction = True
    for honests in combinations(range(n), i):
        contradiction = False
        for testimony in [testimonies[i] for i in honests]:
            for x, y in testimony:
                if (y == 1 and x not in honests) or (y == 0 and x in honests):
                    contradiction = True
                    break
        if not contradiction:
            print(i)
            exit()

print(0)


Measured memory_bytes: 12436
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] -= i + 1;
  }
  sort(a.begin(), a.end());
  ll b;
  if(n % 2 == 0) {
    b = (a[n / 2 - 1] + a[n / 2]) / 2;
  } else {
    b = a[n / 2];
  }
  ll sum = 0;
  for(int i = 0; i < n; i++) {
    sum += abs(a[i] - b);
  }
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1792
n, x, m = map(int, input().split())
a = x
S = [0] * (m + 1)
F = [None] * m
F[x] = 0
i0, j0 = None, None
for i in range(1, m + 1):
    S[i] = S[i - 1] + a
    a = pow(a, 2, m)
    if F[a] is not None:
        i0, j0 = F[a], i
    F[a] = i
q, r = (n - i0) // (j0 - i0), (n - i0) % (j0 - i0)
print((S[j0] - S[i0]) * q + S[i0 + r])


Measured memory_bytes: 16448
/*
Dont BLUNDER
*/
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
 
 */
//#define d long double
#define int long long
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define pi acos(-1)
#define inf (int)1e18
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod1=998244353;
int const mod=1000000007;
#define l first
#define r second
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 #define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// *** Using PBDS ***
 /*typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
                os; */


 
int modexp(int x, int n){
	if(n==0){
		return 1;
	}
	else if(n&1){
		return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
	}
	else{
		return (modexp((x*x)%mod, n/2)%mod);
	}
}
 
int modinv(int n)
{
	return modexp(n,mod-2);
}


signed main()
{
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	set<int> s;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	s.insert(d);
	s.insert(e);
	if(s.find(1)==s.end())
	cout<<1;
	if(s.find(2)==s.end())
	cout<<2;
	if(s.find(3)==s.end())
	cout<<3;
	if(s.find(4)==s.end())
	cout<<4;
	if(s.find(5)==s.end())
	cout<<5;


}

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

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}
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;
    string S;
    cin >> S;
    vi l(Q), r(Q);
    rep(i, 0, Q) {
        cin >> l[i] >> r[i];
    }

    vi a(N);
    rep(i, 0, N){
        if (S[i] == 'A' && S[i+1] == 'C') a[i] = 1;
    }
    vi sum(N+1);
    rep(i, 0, N) {
        sum[i+1] = sum[i] + a[i];
    }

    rep(i, 0, Q) {
        cout << sum[r[i] - 1] - sum[l[i]- 1] << endl;
    }
    return 0;
}

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

int main(void){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int cnt = 0;
    int memo[100010];
    for(int i=0;i<n;++i){
        if(s[i]=='A'){
            if(s[i+1]=='C'){
                memo[i] = cnt;
                ++cnt;
                ++i;
            }
        }
        memo[i] = cnt;
    }
    int l, r;
    for(int i=0;i<q;++i){
        cin >> l >> r;
        cout << (memo[r-1]-memo[l-1]) << endl;
    }
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

ll calc_gcd(ll x, ll y) {
    if (y == 0) return x;
    return calc_gcd(y, x % y);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    cout << A * B / calc_gcd(A, B) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
			using namespace std;
			#define pll pair<ll,ll>
			typedef long long ll;
			#define mod 1000000007
			#define fi first
			#define se second
			#define mp make_pair
			#define pb push_back
			#define INF 1e15
			
			
			int main()
			{
				ll a[3];
				cin>>a[0]>>a[1]>>a[2];
				sort(a,a+3);
				if(a[0]==a[1]&&a[2]!=a[1])
					cout<<"Yes";
				else if(a[1]==a[2]&&a[0]!=a[1])
				{
					cout<<"Yes";
				}
				else
					cout<<"No";
			}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[200000+5],b[200000+5];
int main()
{
	int n;
	cin>>n;
	
	for(int i=2;i<=n;i++){
		cin>>a[i];
		b[a[i]]++;
		
   }
   for(int i=1;i<=n;i++)
   cout<<b[i]<<endl;
   return 0;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで降順
#define pb push_back
#define eb emplace_back
#define fst first
#define snd second
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>T add(const T &a, const T &b){return (a+b)%mod;}

signed main(){
  int n, k; cin >> n >> k;
  int maxv = (n-1)*(n-2)/2;
  if(k > maxv){
    cout << -1 << endl;
    return 0;
  }
  cout << n-1 + (maxv - k) << endl;
  FOR(i,2,n+1) cout << 1 << " " << i << endl;
  int cnt = 0;
  FOR(i,2,n) FOR(j,i+1,n+1){
    if(cnt == maxv - k) return 0;
    cout << i << " " << j << endl;
    cnt++;
  }
}


Measured memory_bytes: 256
import collections


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


N = int(input())
c = collections.Counter(prime_factorize(N))
c = list(c.items())
ans = 0
for i in range(len(c)):
    d= c[i][1]
    t=1
    while d>0:
        d -= t
        t += 1
        if d>=0:
            ans +=1

print(ans)

Measured memory_bytes: 65860
#include <iostream>
#include <algorithm>

using namespace std;
 
const int INF = 1e9; // 「無理」という状態に対応します
 
int main() {
    int n, m;
    int c[22];
 
    cin >> n >> m;
 
    for (int i = 0; i < m; i++) {
        cin >> c[i];
    }
 
    int dp[50005]; //x円支払うために必要なコインの最小枚数をdp[x]に記録します
    
    // dpテーブルを初期化します
    for (int i = 0; i < 50005; i++) {
        if (i == 0) dp[i] = 0; // 0円を支払うためにコインは必要ありません（0枚必要です)
        else dp[i] = INF;
    }
 
    for (int i = 0; i <= 50000; i++) {
        for (int j = 0; j < m; j++) {
            if ( i + c[j] > 50000 ) continue; // 制約の上限より大きい値は見る必要がありません
            dp[i+c[j]] = min(dp[i] + 1, dp[i+c[j]]); //表で一番下「最小で何枚？？」の項目を作るときの操作を思い出してください
        }
    }
    cout << dp[n] << endl; // n円支払うときのコインの最小枚数はdp[n]に格納されています
 
    return 0;
}


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

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

int n;

bool solve(int x, int y, int idx, int sum, int all, vector<vector<int> >& visited, const vector<vector<int> >&p, const vector<pair<int, int> >& s)
{

  //printf("%d %d %d %d %d\n", x, y, idx, sum, all);

  if (all == n*n && idx >= s.size())
    return true;

  if (idx >= s.size())
    return false;

  if (-p[s[idx].second][s[idx].first] == sum)
    return solve(s[idx+1].first, s[idx+1].second, idx+1, 0, all, visited, p, s);

  for (int d = 0; d < 4; ++d) {
    int xx = x + dx[d];
    int yy = y + dy[d];
    if (xx < 0 || n <= xx || yy < 0 || n <= yy || visited[yy][xx] ||
	sum+p[yy][xx] > -p[s[idx].second][s[idx].first])
      continue;
    visited[yy][xx] = 1;
    if (solve(xx, yy, idx, sum+p[yy][xx], all+1, visited, p, s))
      return true;
    visited[yy][xx] = 0;
  }

  return false;
}

int main()
{
  while (cin >> n) {
    if (n == 0)
      break;

    vector<vector<int> > p(n, vector<int>(n)), visited(n, vector<int>(n, 0));
    vector<pair<int, int> > s;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
	cin >> p[i][j];
	if (p[i][j] < 0) {
	  s.push_back(make_pair(j, i));
	  visited[i][j] = 1;
	}
      }
    }

    if (solve(s[0].first, s[0].second, 0, 0, (int)s.size(), visited, p, s))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

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

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = 0;
  if(a+b<=2*c)  ans = a*x+b*y; 
  else{
    if(x>=y) ans = y*2*c + (x-y)*a;
    else     ans = x*2*c + (y-x)*b;
  }
  if(ans > max(x,y)*2*c) ans = max(x,y)*2*c;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
}

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int i,j;
  int x;
  cin>>x;
  ll ans=0;
  ans+=1000*(x/500);
  x%=500;
  ans+=5*(x/5);
  cout<<ans<<endl;
  


}

Measured memory_bytes: 256
using CompLib.Util;
using System;
using System.Linq;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int k = sc.NextInt();

        int ans = 0;
        while(n > 0)
        {
            ans++;
            n /= k;
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;
    class Scanner
    {
        private int _index;
        private string[] _line;
        const char separator = ' ';

        public Scanner()
        {
            _index = 0;
            _line = new string[0];
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(separator);
                _index = 0;
            }
            return _line[_index++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(separator);
            _index = _line.Length;
            return _line;
        }
        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int h,w;
	int K;
	char s[10][1000];
	cin>>h>>w>>K;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>s[i][j];
		}
	}
	int ans=1e9+7;
	for(int i=0;i<(1<<(h-1));i++){
		int cnt=0;
		vector<int> hoge;
		hoge.push_back(0);
		for(int j=0;j<h;j++){
			if(i&(1<<j)){
				hoge.push_back(j+1);
				cnt++;
			}
		}
		hoge.push_back(h);
		int sum[10][1000]={};
		for(int j=1;j<hoge.size();j++){
			for(int k=hoge[j-1];k<hoge[j];k++){
				for(int l=0;l<w;l++){
					sum[j-1][l]+=(s[k][l]=='1'?1:0);
				}
			}
		}
		bool ok=true;
		for(int j=0;j<hoge.size()-1;j++){
			for(int k=0;k<w;k++){
				if(sum[j][k]>K){
					ok=false;
				}
			}
		}
		if(!ok){
			continue;
		}
		for(int j=1;j<w;j++){
			bool f=true;
			for(int k=0;k<hoge.size()-1;k++){
				if(sum[k][j]+sum[k][j-1]>K){
					f=false;
				}
			}
			if(f){
				for(int k=0;k<hoge.size()-1;k++){
					sum[k][j]+=sum[k][j-1];
				}
			}else{
				cnt++;
			}
		}
		ans=min(ans,cnt);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <cmath>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};
vector<int> G[200010];
vector<int> c(10010, 0);
int num[200010];
bool used[200010];
int now_c = 0;

int dfs(int s) {
    if (used[s]) {
        return 0;
    } else {
        used[s] = true;
    }

    num[s] = c[now_c];
    now_c++;

    for (int i = 0; i < G[s].size(); i++) {
        dfs(G[s][i]);
    }
    return 0;
}

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

    int start=1;
    int ans=0;

    while(start<B){
        start+=(A-1);
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5624
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>

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

using namespace std;

int main(){
  int a,b;
  cin>>a>>b;
  int bigger=b;
  int smaller=a;
  if(a>b){
    bigger=a;
    smaller=b;
  }
  fori(bigger){
    cout<<smaller;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N,a,mi = 1e9,ma = 0;
int main(){
	cin >> N;
  	for(int i=0;i<N;i++){
		cin >> a;
      	mi = min(a,mi);
      	ma = max(a,ma);
    }
  	cout << ma-mi << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
void Iswap(int *a,int *b){
  int t=*a;
  *a=*b;
  *b=t;
}
void Fswap(double *a,double *b){
  double t=*a;
  *a=*b;
  *b=t;
}
void Lswap(ll *a,ll *b){
  ll t=*a;
  *a=*b;
  *b=t;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}
ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

int main(void){
  int n;
  INI(n);
  PRF(6.28318530717958623200*n);
  return 0;
}

Measured memory_bytes: 1704
fun main(args: Array<String>) {
    val (n,l) = readLine()!!.split(" ").map { it.toInt() }
    val list = mutableListOf<Int>()
    var min = 300
    for (i in 0 until n) {
        val num = l + i
        list.add(num)
        if (Math.abs(min) > Math.abs(num)) min = num
    }
    println(list.reduce { acc, i -> acc + i } - min)
}


Measured memory_bytes: 37868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

const long double pi=3.14159265358979323846264;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
    if(x1>x2){
        swap(x1,x2);
        swap(y1,y2);
    }
    
    int N;cin>>N;
    
    vector<pair<int,int>> S;
    
    while(N--){
        int a,b;cin>>a>>b;
        if(x1<=a&&a<=x2&&min(y1,y2)<=b&&b<=max(y1,y2)) S.push_back({a,b});
    }
    
    sort(all(S));
    
    if(y1>y2){
        y1=100000000-y1;
        y2=100000000-y2;
        
        for(int i=0;i<S.size();i++){
            S[i].second=100000000-S[i].second;
        }
    }
    
    if(x1==x2){
        long double ans=0.0;
        ans+=(y2-y1)*100.0;
        ans+=double(S.size())*(10.0*pi-20.0);
        cout<<setprecision(25)<<ans<<endl;
        return 0;
    }
    
    if(y1==y2){
        long double ans=0.0;
        ans+=(x2-x1)*100.0;
        ans+=double(S.size())*(10.0*pi-20.0);
        cout<<setprecision(25)<<ans<<endl;
        return 0;
    }
    
    vector<int> dp(MAX,INF);
    dp[0]=-1;
    
    for(int i=1;i<MAX;i++) dp[i]=INF;
    
    for(int i=0;i<S.size();i++){
        auto it=lower_bound(all(dp),S[i].second);
        (*it)=S[i].second;
    }
    
    for(int i=1;;i++){
        if(dp[i]==INF){
            long double ans=0.0;
            ans+=(y2-y1+x2-x1);
            ans+=(0.05*pi-0.2)*(i-1);
            if(min(x2-x1,y2-y1)+1==i-1){
                ans-=(0.05*pi-0.2);
                ans+=(0.10*pi-0.2);
            }
            ans*=100.0;
            cout<<setprecision(25)<<ans<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 2672