akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define INF 0x3fffffff
using namespace std;
string str[100];

int main() {
	int n, l;
	cin >> n >> l;
	REP(i, 0, n) {
		cin >> str[i];
	}
	sort(str, str + n);
	REP(i, 0, n) {
		cout << str[i];
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 100000000000007
using namespace std;
using pii=pair<int,int>;
using LL=int64_t;



vector<pair<int64_t, int64_t>> fs;//素因数分解の素数，指数のペア
 
vector<pair<LL,LL>> prime_factorize(LL N){
   vector<pair<LL, LL>> res;
   for (LL a = 2; a * a <= N;a++) {
	   if(N % a != 0) continue;
	   LL ex = 0; //指数
 
	   //割れる限り割り続ける
	   while (N % a == 0) {
		   ++ex;
		   N /= a;
	   }
 
	   res.push_back(make_pair(a, ex));
   }
 
   //最後に残った数について
   if ( N != 1) res.push_back(make_pair(N, 1));
   return res;
}
	
void factorization(int64_t base){//baseを素因数分解
    //base未満のiが約数か
    for(int i=2;i*i<=base;i++){
        //iで割り切れるなら限界まで割る
        
        if(base%i==0){
            int cnt=0;
            while(base%i==0){
                base/=i;
                cnt++;
            }
            fs.push_back(make_pair(i,cnt));
        }
    }
    //baseが素数
    if(base>1){
        fs.push_back(make_pair(base,1));
    }
}
int main(){
    int64_t n;
    cin>>n;
    
    
    //factorization(n);
    auto res=prime_factorize(n);
    int64_t ans=0;
    for(auto p : res){
        int64_t e;
        e=p.second;
        int k=1;
        while(e-k>=0){
            e-=k;
            k++;
            ans++;
        }
    }

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

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

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



int main(){
	int a,b,c,d,e,k;
	cin>>a>>b>>c>>d>>e>>k;
	if(e-a<=k){
		cout<<"Yay!"<<endl;
	}
	else{
		cout<<":("<<endl;
	}
	
	
	
	return 0;
}


Measured memory_bytes: 256
void main() {
    int n = readln.chomp.to!int;
    int[] x = new int[n], y = new int[n];
    double s = 0.0;
    foreach (i; 0 .. n) {
        int[] tmp = readln.split.to!(int[]);
        x[i] = tmp[0], y[i] = tmp[1];
    }
    foreach (i; 0 .. n) {
        foreach (j; 0 .. n) {
            if (i == j) continue;
            int xdiff = x[i] - x[j];
            int ydiff = y[i] - y[j];
            s += sqrt(xdiff.to!double^^2+ydiff.to!double^^2);
        }
    }
    writefln("%.10f", s / n);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;
int main(){
	ll n, ans = 0;
	cin >> n;
	string s;
	map<string, ll> mp;
	for(int i = 0 ; i < n ; i++){
		cin >> s;
		sort(s.begin(), s.end());
		++mp[s];
	}
	map<string, ll>::iterator it;  
	for(it=mp.begin(); it!=mp.end(); it++){
		ans += (it->second) * (it->second - 1) / 2;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
using ul = unsigned long;
using ull = unsigned long long;
#define vec vector
#define rep(_i,_n) for(ull _i = 0; _i < _n; _i++)
#define rep2(_i,_s,_n) for(ull _i = _s; _i < _n; _i++)
#define elif else if
#define push(_a) push_back(_a)
#define fullSort(_a) sort(_a.begin(), _a.end())
#define inputVecI(_name, _n) vec<int> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecUL(_name, _n) vec<ul> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecULL(_name, _n) vec<ull> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecS(_name, _n) vec<string> _name(_n);rep(_i, _n)cin >> _name[_i];
#define printVec(_vec) cout << "{";rep(i, _vec.size()-1)cout << _vec[i] << ",";cout << _vec[_vec.size()-1];cout << "}\n";
#define append(_x) push_back(_x)
#define mapLoop(_i, _name) for(auto i = _name.begin(); i != _name.end(); i++)


int main()
{
    int A, B;
    cin >> A >> B;
    if(A >= 13){
      cout << B << endl;
    }
    elif(A > 5){
      cout << B/2 << endl;
    }
    else{
      cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    ios::sync_with_stdio(false);

    #define int long long

    int N;
    cin >> N;
    int A[100000];
    int sumA = 0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        sumA += A[i];
    }
    int B[100000], C[100000];
    int sumB = 0;
    for(int i=0; i<N; i++){
        cin >> B[i];
        sumB += B[i];
        C[i] = A[i] - B[i];
    }

    if(sumA < sumB){
        cout << -1 << endl;
        return 0;
    }

    bool already = false;
    int tmp = N-1;
    sort(C, C+N);
    for(int i=0; i<N; i++){
        if(C[i] >= 0){
            if(already) cout << i + N-1-tmp +1 << endl;
            else cout << i + N-1-tmp << endl;
            break;
        }
        while(C[i] < 0){
            if(C[i]+C[tmp] > 0){
                C[tmp] += C[i];
                C[i] = 0;
                already = true;
            }
            else{
                C[i] += C[tmp];
                C[tmp] = 0;
                tmp--;
                already = false;
            }
        }
    }


    return 0;
}

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

int main() {
  long long int S;
  cin >> S;
  long long int ans = 10000;
  while (S >= 100) {
    ans = min(ans, abs((S % 1000) - 753));
    S /= 10;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from functools import reduce
from operator import mul


def main():
    N, K = map(int, input().split())
    ans = []
    lst = []
    for i in range(1, N + 1):
        lst.clear()
        for j in range(K):
            if K <= i << j:
                break
            lst.append(0.5)
        ans.append(reduce(mul, lst, 1 / N))
    print(sum(ans))
    return


main()


Measured memory_bytes: 6788
use proconio::input;
use proconio::marker::*;
use proconio::fastout;

fn main() {
  input! {
    h : usize, w : usize, k : usize,
  };
  input! {
    c : [Chars; h],
  };

  let mut res = 0usize;
  for rows in 0..(1 << h) {
    for cols in 0..(1 << w) {
      let mut cnt = 0;
      for i in 0..h {
        if rows & (1 << i) != 0 {
          for j in 0..w {
            if cols & (1 << j) != 0 {
              if c[i][j] == '#' {
                cnt += 1;
              }
            }
          }
        }
      }
      if cnt == k {
        res += 1;
      }
    }
  }
  
  println!("{}", res);
}


Measured memory_bytes: 2140
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long;
using P = pair<int, int>;


ull E = 1000000007;

int main() {
    int H, W;
    cin >> H >> W;
    for (int i = 0; i < H; ++i) {
        string s;
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
  char A[3];
  int i,j,count=0;
  for(i=0;i<3;i++)
    cin>>A[i];
  for(i=0;i<3;i++)
  {
    if(A[i]=='R'&&count==0)
    {
      count++;
      for(j=i+1;j<3;j++)
      {
        if(A[j]=='R')
          count++;
        else
          break;
      }
    }
  }
  cout<<count;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

template<typename T>
struct BIT {
    int n, p;
    vector<T> d;
    BIT(int n=0) : n(n), d(n+1) {
        p = 1;
        while (p < n) p *= 2;
    }
    void add(int i, T x=1) {
        for (i++; i <= n; i += i&-i) d[i] += x;
    }
    //[0, i)
    T sum(int i) {
        T res = 0;
        for (; i; i -= i&-i) res += d[i];
        return res;
    }
    //[a, b)
    T sum(int l, int r) { return sum(r) - sum(l);} 
    // v0 + v1 + v2 + ... + vx　>= w となる最小のxを求める
    int lower_bound(T w) {
        if (w <= 0) return 0;
        int x = 0;
        for (int i = p; i; i /= 2) {
            if (i+x <= n && d[i+x] < w) {
                w -= d[i+x];
                x += i;
            }
        }
        return x;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, q; string s;
    cin >> n >> s >> q;
    vector<BIT<int>> bit(26, BIT<int>(n));
    rep(i, n) bit[s[i] - 'a'].add(i);
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            if (s[i] != c) {
                bit[s[i] - 'a'].add(i, -1);
                s[i] = c;
                bit[s[i] - 'a'].add(i);
            }
        } else {
            int l, r;
            cin >> l >> r;
            l--; r--;
            int res = 0;
            rep(i, 26) if (bit[i].sum(l, r+1)) res++;
            cout << res << endl;
        }
    }
}

Measured memory_bytes: 53660
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
ll n,m;
std::vector<ll> g[111111];
bool visit[111111] = {false};
void dfs(int v,vector<ll>& tmp){
  visit[v] = true;
  for(int nv : g[v]){
    if(!visit[nv]){
      dfs(nv,tmp);
      break;
    }
  }
  tmp.pb(v+1);
  return ;
}
void solve(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m;
  std::vector<ll> a,b;
  ll x,y;
  rep(i,m){
    cin>>x>>y;
    x--;
    y--;
    g[x].pb(y);
    g[y].pb(x);
  }
  std::vector<ll> resa,resb,res;
  dfs(0,resa);
  dfs(0,resb);
  reverse(all(resb));
  rep(i,resa.size()) res.pb(resa[i]);
  repl(i,1,resb.size()) res.pb(resb[i]);
  cout<<res.size()<<endl;
  rep(i,res.size()-1) cout<<res[i]<<" ";
  cout<<res[res.size()-1]<<endl;


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


Measured memory_bytes: 13556
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main(){
    int k, a, b;
    cin >> k >> a >> b;
    REP(i,a,b+1)if(i % k == 0){
        cout << "OK" << endl;
        return 0;
    }
    cout << "NG" << endl;
    return 0;
}  

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;



public class Test
{
	public static void Main()
	{
//		while(true){
		  string[] str1 = Console.ReadLine().Split(' ');
		  int n = int.Parse(str1[0]); 
		  ulong m = ulong.Parse(str1[1]); 

//		  if(n == 0) break;
		
		  ulong[] a = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,ulong>(s => ulong.Parse(s)));
//		  string ss = Console.ReadLine();
//		  int[] b = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
//		  int[] c = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
		  //Console.WriteLine("改行あり N = {0} P = {1} Ai = {2}", n, p, a);

		    ulong k = 0;
		    ulong f = 0;
		    int keta = (int)Math.Log((double)m,2.0)+1;
		    if(keta < 0) keta = 0;
		    for(int i=keta; 0<=i; i--){
				int ka = 0;
				int kb = 0;
			    for(int j=0; j<n; j++){
					byte bit = (byte)((a[j]>>i)&1);
					ka += (bit^0);
					kb += (bit^1);
			    }
			    ulong tk = k;
				if(ka<kb) tk += ((ulong)1<<i);
				if(m < tk) continue;
				k = tk;
			}
			
		    for(int i=0; i<n; i++) f += (k^a[i]);
			
			
			Console.WriteLine(f);
			
//	    }


	}

  public static int calc(int n,int m,int[] a,int[] b,int[] c) {



	  return 0;
  }
  
  


}


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

int main() {
	int N, K;

	cin >> N >> K;

	int ma = N - (K - 1);
	int ans = ma - 1;
	if( K == 1) {
		ans = 0;
	}

	cout << ans << endl;

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	ll a, b, k,c;
	ll ans = 0;
	cin >> k >> a >> b;
	if (b - a <= 2) {
		cout << 1 + k << endl; return 0;}
	else {
		c = max(0LL, ll(floor((k - (a - 1LL)) / 2LL)));
		ans = (b - a) * c;
		if ((k - (a - 1)) % 2 == 1)ans++;
	}
	cout << a + ans << endl;
	return 0;
}



Measured memory_bytes: 3636
#include <stdio.h>

int ans ;
char s[4] ;

int main(void){
    
    scanf ("%s",s) ;
    
    if (s[0]=='1'){
        ans++ ;
    }
    if (s[1]=='1'){
        ans++ ;
    }
    if (s[2]=='1'){
        ans++ ;
    }
    
    printf ("%d",ans) ;
    
    return 0 ;
    
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int cnt[8];
int num[256];
int n;
string str;
Int ans = 1;
int ord[] = {7, 6, 5, 3, 4, 2, 1, 0};
int main(){
    cin >> n;
    cin >> str;
    num['R'] = 1;
    num['G'] = 2;
    num['B'] = 4;
    int rcnt = 0;
    int bcnt = 0;
    int gcnt = 0;
    cnt[0] = n;
    for(int i = 0;i < 3 * n;i++){
        int v = num[str[i]];
        for(int j = 0;j < 8;j++){
            if(ord[j] & v)continue;
            if(cnt[ord[j]] == 0)continue;
            ans *= cnt[ord[j]];ans %= MOD;
            cnt[ord[j]]--;
            cnt[ord[j] + v]++;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 900
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        int num = 1;
        while (num * 2 <= N)
        {
            num *= 2;
        }
        WriteLine(num);
    }
}


Measured memory_bytes: 27524
n = gets.chomp.to_i
tasks = []

n.times do
  tasks << gets.chomp.split(" ").map(&:to_i)
end

tasks.sort! do |a, b|
  a[1] <=> b[1] 
end

now = 0
result = "Yes"
tasks.each do |task|
  now += task[0]
  if now > task[1]
    result = "No"
    break
  end
end

puts result

Measured memory_bytes: 18424
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N;
int a[50], b[50];
int M;
int u[20], v[20];

const int N_MAX = 50;
const int N_LOG_MAX = 9;
vector<int> G[N_MAX];
int root;

int parent[N_LOG_MAX][N_MAX];
int depth[N_MAX];

void dfs(int v, int p, int d){
    parent[0][v] = p;
    depth[v] = d;
    for(int i = 0; i < G[v].size(); i++){
        if(G[v][i] != p) dfs(G[v][i], v, d+1); 
    }
}

void init(int V){
    dfs(root, -1, 0);
    for(int i = 0; i < N_LOG_MAX-1; i++){
        for(int v = 0; v < V; v++){
            if(parent[i][v] < 0) parent[i+1][v] = -1;
            else parent[i+1][v] = parent[i][parent[i][v]];
        }
    }
}

int lca(int u, int v){
    if(depth[u] > depth[v]) swap(u, v);
    for(int i = 0; i < N_LOG_MAX; i++){
        if((depth[v] - depth[u]) >> i & 1){
            v = parent[i][v];
        }
    }
    if(u == v) return u;
    for(int i = N_LOG_MAX-1; i >= 0; i--){
        if(parent[i][u] != parent[i][v]) {
            u = parent[i][u];
            v = parent[i][v];
        }
    }
    return parent[0][u];
}

int col[50];
bool used[50];
int cnt_e;
void clear(){
    for(int i = 0; i < N; i++) col[i] = 0;
    for(int i = 0; i < N; i++) used[i] = 0;
    cnt_e = 0;
}


void paint(int v){
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]) {
            paint(G[v][i]);
            col[v] += col[G[v][i]];
            if(col[G[v][i]] > 0){
                cnt_e++;
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N-1; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    cin >> M;
    for(int i = 0; i < M; i++){
        cin >> u[i] >> v[i];
        u[i]--;
        v[i]--;
    }
    init(N);
    ll ans = 0;
    for(int i = 0; i < ((ll)1<<M); i++){
        clear();
        int c = 0;
        for(int j = 0; j < M; j++){
            if(i&(1<<j)){
                c++;
                col[v[j]]++;
                col[u[j]]++;
                int l = lca(v[j], u[j]);
                col[l] -= 2;
            }
        }
        int cnt = 0;
        paint(0);
        
        if(c%2 == 0){
            ans += ((ll)1<< (N-cnt_e-1));
        }else{
            ans -= ((ll)1<< (N-cnt_e-1));
        }
        // cout << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
cnt=0
for x in b:
     a_=bisect.bisect_left(a,x)
     c_=n-bisect.bisect_right(c,x)
     cnt+=a_*c_
print(cnt)

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n;cin>>n && n;){
		vd xs(n),ys(n);
		{
			rep(i,n) cin>>xs[i]>>ys[i];
			
			vd uys=ys;
			sort(all(uys));
			uys.erase(unique(all(uys)),end(uys));
			
			vd xs2(1,xs[0]),ys2(1,ys[0]);
			repi(i,1,n){
				double x1=xs[i-1],x2=xs[i];
				double y1=ys[i-1],y2=ys[i];
				int j=upper_bound(all(uys),min(y1,y2))-begin(uys);
				int k=lower_bound(all(uys),max(y1,y2))-begin(uys);
				if(j<k){
					repi(l,j,k){
						double y=uys[l];
						// y-y1=(y2-y1)/(x2-x1)*(x-x1)
						double x=(y-y1)*(x2-x1)/(y2-y1)+x1;
						xs2.push_back(x);
						ys2.push_back(y);
					}
					if(y1>y2){
						reverse(end(xs2)-(k-j),end(xs2));
						reverse(end(ys2)-(k-j),end(ys2));
					}
				}
				xs2.push_back(xs[i]);
				ys2.push_back(ys[i]);
			}
			xs=xs2,ys=ys2,n=xs.size();
		}
		
		//using tiid=tuple<int,int,double>;
		typedef tuple<int,int,double> tiid;
		struct comp{
			bool operator()(tiid a,tiid b){
				return get<2>(a)>get<2>(b);
			}
		};
		priority_queue<tiid,vector<tiid>,comp> q;
		q.emplace(0,n-1,0);
		vector<vector<bool>> vis(n,vector<bool>(n));
		vd dist(n,INF);
		while(q.size()){
			int i,j; double d;
			tie(i,j,d)=q.top(); q.pop();
			if(vis[i][j]) continue;
			vis[i][j]=1;
			if(i==j) dist[i]=d;
			for(int k=i-1;k<=i+1;k++)
				for(int l=j-1;l<=j+1;l++){
					if(k<0 || n<=k || l<0 || n<=l || ys[k]!=ys[l]) continue;
					double d1=hypot(xs[k]-xs[i],ys[k]-ys[i]);
					double d2=hypot(xs[l]-xs[j],ys[l]-ys[j]);
					q.emplace(k,l,d+d1+d2);
				}
		}
		double res=INF;
		rep(i,n) res=min(res,dist[i]);
		printf("%.3f\n",res);
	}
}

Measured memory_bytes: 4376
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
    }
    let mut ans = vec![0; n];
    for i in 1..n {
        for j in 1..i + 1 {
            'inner: for k in 1..j + 1 {
                let tmp = (i + j + k) * (i + j + k) - (i * j + j * k + k * i);
                if tmp > n {
                    break 'inner;
                } else {
                    if i == j && i == k {
                        ans[tmp - 1] += 1;
                    } else if i != j && j != k && k != i {
                        ans[tmp - 1] += 6;
                    } else {
                        ans[tmp - 1] += 3;
                    }
                }
            }
        }
    }
    for i in 0..n {
        println!("{:?}", ans[i]);
    }
}


Measured memory_bytes: 2172
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author gainullin.ildar
 */

#include <bits/stdc++.h>

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>

using namespace std;

typedef long long ll;

const int N = 2e5 + 7;

int t[N];

void inc(int x)
{
    for (; x < N; x = (x | (x + 1)))
    {
        t[x]++;
    }
}

int get(int x)
{
    int ans = 0;
    for (; x >= 0; x = (x & (x + 1)) - 1)
    {
        ans += t[x];
    }
    return ans;
}

class TaskE
{
public:
    void solve(std::istream &in, std::ostream &out)
    {
        for (int i = 0; i < N; i++)
        {
            t[i] = 0;
        }
        int n, k;
        in >> n >> k;
        vector<int> a(n);
        for (int i = 0; i < n; i++)
        {
            in >> a[i];
            a[i] -= k;
        }
        auto f = a;
        ll s = 0;
        vector<ll> pref;
        pref.push_back(0);
        for (auto c : a)
        {
            s += c;
            pref.push_back(s);
        }
        sort(pref.begin(), pref.end());
        pref.resize(unique(pref.begin(), pref.end()) - pref.begin());
        ll ans = 0;
        s = 0;
        inc(lower_bound(pref.begin(), pref.end(), 0) - pref.begin());
        for (auto c : a)
        {
            s += c;
            int ind = lower_bound(pref.begin(), pref.end(), s) - pref.begin();
            ans += get(ind);
            inc(ind);
        }
        out << ans << '\n';
    }
};


int main()
{
    ios::sync_with_stdio(0);
    TaskE solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i=0; i < N; i++){
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  
  int ans = N;
  for (int i=1; i < N; i++){
    if(S.at(i) == S.at(i-1)){
      ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 9600
#include<stdio.h>
int main()
{
    int a,b,s=0,c;
    scanf("%d",&a);
    b=a;
    while(a)
    {
        c=a%10;
        s=s+c;
        a=a/10;
    }
    if(b%s==0)
    {
        printf("Yes\n");
        return 0;
    }
    else
    {
        printf("No\n");
        return 0;
    }
}


Measured memory_bytes: 128
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0 for i in range(0,n)]
count = 0
for i in range(0,n):
    b[a[i]-1] += 1
for i in range(0,n):
    count += b[i]
b.sort()
b.reverse()
for i in range(0,k):
    count -= b[i]
print(count)


Measured memory_bytes: 24748
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  int n,w,z;
  cin>>n>>w>>z;

  vector<string> p(n);
  rep(i,n) cin>>p[i];

  vector<vector<int>> q(n,vector<int>(w));
  rep(i,n) rep(j,w) q[i][j]=p[i][j]-'0';

  //——————————————bit全探索——————————————
  ll ans=INF;
  rep(i, (1<<n-1)){
    ll cnt=0;
    auto copy=q;
    vector<vector<int>> r;
    rep(j,n-1){
      if(i & (1<<j)){
        rep(k,w){
          copy[j+1][k]+=copy[j][k];
        }
      }
      else {
        cnt++;
        r.pb(copy[j]);
      }
    }
    r.pb(copy[n-1]);

    bool ok=true;
    rep(j,w-1){
      bool oke=true;
      rep(k,r.size()){
        if(r[k][j]>z) ok=false;
        if(r[k][j]+r[k][j+1]>z) oke=false;
      }
      if(oke) {
        rep(k,r.size()){
          r[k][j+1]+=r[k][j];
        }
      }
      else cnt++;
    }

    if(ok) chmin(ans,cnt);
  }

  cout << ans << endl;

  //——————————————————————————————————————

}


Measured memory_bytes: 3772
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

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


int main(void) {
	int n;

	cin >> n;
	cout << n / 3 << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(void) {
  int n;
  cin >> n;
  int a[3][101] = { { 0 } };
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
    }
  }

  int memo[3][101] = { { 0 } };
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= n; j++) {
      memo[i][j] = a[i][j] + max(memo[i - 1][j], memo[i][j - 1]);
    }
  }
  cout << memo[2][n] << endl;
  return EXIT_SUCCESS;
}


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

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

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

  int ans = 0;
  for(int i = 0; i < 1000; ++i){
    char find_c[4];
    sprintf(find_c, "%03d", i);
    int count = 0;
    for(int j = 0; j < n; ++j){
      if(s[j] == find_c[count]){
        count++;
        if(count == 3){
          ans++;
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int main()
{
  fastio;
  int n, m; cin >> n >> m;
  cout << (n == m ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


def LI(): return list(map(int, input().split()))


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(list, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]


def sosu(x):
    for i in range(2, int(sqrt(x)+1)):
        if x % i == 0:
            return False
    return True


mod = 1000000007
inf = float('INF')


def A():
    N = II()

    if N % 2 == 0:
        print((N//2)-1)
    else:
        print(N//2)
    return

# B


def B():
    N = II()
    if N <= 81 and N > 9:
        for i in range(2, 10):
            if N % i == 0 and N/i <= 9:
                print('Yes')
                return

    elif N > 81:
        print('No')
        return
    else:
        print('Yes')
        return
    print('No')

    return

# C


def C():
    N = II()

    L = []
    count = 0
    for i in range(2, int(sqrt(N)+2)):
        if N % i == 0:
            L.append(N/i)
            count = 1
    if count == 0:
        print(N-1)
    else:
        print(int(L[-1]-2+(N/L[-1])))

    return

# D


def D():

    a, b, x = LI()
    BIG = a*a*b/2
    if x > BIG:
        y = 2*b-(2*x/a/a)
        print(math.degrees(math.atan(y/a)))
    else:
        y = 2*x/a/b
        print(math.degrees(math.atan(b/y)))
    return

# E


def E():
    N, K = LI()
    A = LI()
    F = LI()
    A.sort(reverse=True)
    F.sort()
    cost = []
    for i in range(len(N)):
        cost.append(A[i]*F[i])

    a = F[cost.index(max(cost))]

    return

# F


def F():
    N, M = LI()

    value = [0] * M
    power = [0] * M
    for i in range(M):
        a, b = LI()
        value[i] = a
        c = LI()
        L = ['0'] * N
        for k in c:
            L[k - 1] = '1'
        bint = ''.join(L)
        power[i] = int(bint, 2)
    bint = ''.join(list(['1'] * N))
    dp = [inf] * (int(bint, 2)+1)
    t = 0
    cost = 0

    dp[0] = 0
    for s in range(int(bint, 2) + 1):
        for i in range(M):
            t = s | power[i]
            cost = dp[s] + value[i]
            dp[t] = min(dp[t], cost)
    print(-1) if(dp[-1] == inf) else print(dp[-1])

    return

    # you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")


def solution(S):
    # write your code in Python 3.6
    N = len(S)

    pass


# Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 40048
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;
struct Node{
 int key;
 Node *right,*left,*parent;
};
Node *root,*NIL;
Node* find(Node *u,int k){
 while(u!=NIL&&k!=u->key){
  if(k<u->key)u=u->left;
  else u=u->right;
 }
 return u;
}
void insert(int k){
 Node *y=NIL;
 Node *x=root;
 Node *z;
 z=(Node *)malloc(sizeof(Node));
 z->key=k;
 z->left=NIL;
 z->right=NIL;
 while(x!=NIL){
  y=x;
  if(z->key<x->key) x=x->left;
  else x=x->right;
 }
 z->parent=y;
 if(y==NIL)root=z;
 else {
  if(z->key<y->key)y->left=z;
  else y->right=z;
 }
}
void inorder(Node *u){
 if(u==NIL)return;
 inorder(u->left);
 printf(" %d",u->key);
 inorder(u->right);
}
void preorder(Node *u){
 if(u==NIL)return;
 printf(" %d",u->key);
 preorder(u->left);
 preorder(u->right);
}
int main(){
 int n,i,x;
 string com;
 scanf("%d",&n);
 for(i=0;i<n;i++){
  cin>>com;
  if(com[0]=='f'){
   scanf("%d",&x);
   Node *t=find(root,x);
   if(t!=NIL)printf("yes\n");
   else printf("no\n");
  }else if(com=="insert"){
   scanf("%d",&x);
   insert(x);
  }else if(com=="print"){
   inorder(root);
   printf("\n");
   preorder(root);
   printf("\n");
  }
 }
 return 0;
}


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

using namespace std;

int N;
vector<long long> x, y;

int solve() {
    if (N == 1) return 1;

    int res = N;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            if (i == j) continue;
            long long dx = x[j] - x[i], dy = y[j] - y[i];

            int sub = 0;
            for (int i2 = 0; i2 < N; ++i2) {
                for (int j2 = 0; j2 < N; ++j2) {
                    if (j2 == i2) continue;
                    if (dx == x[j2] - x[i2] && dy == y[j2] - y[i2]) ++sub;
                }
            }
            res = min(res, N - sub);
        }
    }
    return res;
}

int main() {
    cin >> N;
    x.resize(N); y.resize(N);
    for (int i = 0; i < N; ++i) cin >> x[i] >> y[i];
    cout << solve() << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
    int n, k;
	cin>>n>>k;
	ll ans=0;
	for(ll i=k; i<=n+1; i++){
		ll s=(ll)n*(n+1)/2-(n-i)*(n-i+1)/2-i*(i-1)/2+1;
		(ans+=s)%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

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

using namespace std;

int main()
{
	long long value[4001];

	int n,num;
	long long k,m;
	while(cin >> n && n)
	{
		memset(value,0,sizeof(value));

		vector<int> ans;
		rep(i,n)
		{
			cin >> num >> k >> m;
			vector<int>::iterator ite = find(ans.begin(),ans.end(),num);
			if(ite == ans.end())
			{
				value[num] += k*m;
				
				if(value[num] >= 1000000)
				{
					ans.push_back(num);
				}
			}			
		}

		if(ans.size() == 0)
		{
			cout << "NA" << endl;
		}
		else
		{
			rep(i,ans.size())
			{
				cout << ans[i] << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1268
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    int n;
    cin>>n;
    vi s(n);
    for (auto & it : s)
        cin>>it;
    int mn = min_element(all(s)) - s.begin();
    int mx = max_element(all(s)) - s.begin();
    vi p(n);
    for (int i = 0;i < n;++i)
        p[i] = i + 1;
    int w = mx + 1;
    if (abs(s[mx]) < abs(s[mn]))
        w = mn + 1,reverse(all(p));
    vector < pii > ans;
    for (int i = 0;i < n;++i)
        ans.pb(mp(w,i + 1));
    for (int i = 0;i + 1 < n;++i)
        ans.pb(mp(p[i],p[i + 1]));
    cout << (ans.size()) << '\n';
    for (auto it : ans)
        cout << it.fi << ' ' << it.se << '\n';
    return 0;
}


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

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

struct UnionFind {
  vi par; //par[i] : iの親番号（例）par[3] = 2 : 3の親は2

  UnionFind(int N) : par(N) { //最初は全てが根として初期化
    rep(i,N) par[i] = i;
  }

  int root(int x){ //データxが属する木の根を再帰で得る : root(x) = {xの木の根}
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){ //xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if(rx == ry)return; //xとyの根が同じ
    par[rx] = ry; //xとyの根が同じでない時、xの根rxをyの根にryにつける。
  }

  bool same(int x, int y){//2つのデータx，yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};


int main(){

  int n, k; cin >> n >> k;
  int pos = 0;

  rep(i,n){
    int a; cin >> a;
    if(a == 1)pos = i;
  }

  int left,right;
  left = pos;
  right = n - pos - 1;
  int ans = 0;

  if(right + left <= k - 1)cout << 1 << endl;
  else{
    while(1){
      ans ++;
      n -= k;
      if(n <=0)break;
      n++;
    }
    cout << ans << endl;
  }
  return 0;

}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(), s.end()
void vout(vi v)
{
    for (int i = 0; i < v.size(); i++)
        cout << v.at(i) << endl;
}
int main()
{
    string s;
    lli ans = 0;
    cin >> s;
    rep(i, 6)
    {
        if (s[i] == '1')
        {
            ans++;
        }
    }
    out(ans);
}

Measured memory_bytes: 3596
N,A,B,C=map(int,input().split())
l=[int(input()) for i in range(N)]
inf=10**9
def dfs(d,a,b,c):
    if d==N:#合成完了
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf #無からは作れない#0に合成するのにmpは使わないので-30
    ret0=dfs(d+1,a,b,c)#l[d]を使わない
    ret1=dfs(d+1,a+l[d],b,c)+10#l[d]をAに
    ret2=dfs(d+1,a,b+l[d],c)+10#l[d]をBに
    ret3=dfs(d+1,a,b,c+l[d])+10#l[d]をCに
    ans=min(ret0,ret1,ret2,ret3)
    return ans
print(dfs(0,0,0,0))

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
a1 = []
for i in range(n):
    a1.append(a[i]-i-1)
a1.sort()
b = a1[n//2]
y = 0
for i in a1:
    y += abs(i-b)
print(y)

Measured memory_bytes: 25196
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var a = IntStream.range(0, n + 1).map(i -> sc.nextInt()).toArray();
		sc.close();

		var sum = 0L;
		for (var i = 0; i <= n; i++) {
			sum += a[i];
		}
		var result = 0L;
		var node1 = 1L;
		var node2 = 0L;
		for (var i = 0; i <= n; i++) {
			sum -= a[i];
			var max = i == 0 ? 1 : node1 * 2;
			var node1c = Math.min(max - a[i], sum);
			var node2c = a[i];
			//System.out.printf("%d:%d %d\r\n", i, node1c, node2c);
			if ((node1c + node2c) < node1 || node1c < 0 || i < n && node1c == 0) {
				System.out.println(-1);
				return;
			}
			node1 = node1c;
			node2 = node2c;
			result += (node1 + node2);
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 59708
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char s[10005],t[10005],lens,lent,len;
bool ans,f;
bool cmp1(int a,int b){
	return a<b;
}

bool cmp2(int a,int b){
	return a>b;
}

void pd(char a[],char b[]){
	len=min(lens,lent);
	for(int i=0;i<len;i++){
		if(s[i]>t[i])
			return;
		if(s[i]<t[i]){
			ans=1;
			return;
		}
	}
	if(lens<lent){
		ans=1;
		return;
	}
	return;
}

int main(){
	scanf("%s %s",s,t);
	lens=strlen(s),lent=strlen(t);
	sort(s,s+lens,cmp1);
	sort(t,t+lent,cmp2);
	pd(s,t);
	if(ans==1)
		printf("Yes");
	else
		printf("No");
	return 0;
}

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

// MY TOOLS
#define let long long int
#define async ios_base::sync_with_stdio(false);cin.tie(NULL);
#define i_upto( n ) for( int i = 0 ; i < n ; i++ )
#define ij_upto( n, m ) for( int i = 0 ; i < n ; i++ ) for( int j = 0 ; j < m ; j++ )
template<class T>
T ** array2D( let R , let C ){
	T ** t = new T * [R] ;
	for( int i = 0 ; i < R ; i++ ){
		t[i] = new T[C] ;
	}
	return t ;
}
template<class T>
T ** array2D( let R , let C, T value ){
	T ** t = new T * [R] ;
	for( int i = 0 ; i < R ; i++ ){
		t[i] = new T[C] ;
	}
    ij_upto( R, C ) t[i][j] = value ;
	return t ;
}
template<class T>
T * array1D( let N, T value ){
    T * t = new T[N] ;
    i_upto(N) t[i] = value ;
    return t ;
}
template<class T>
T * array1D( let N ){
    T * t = new T[N] ;
    return t ;
}
template<class T>
vector<vector<T>> vector2D( let N, let M ){
	return vector<vector<T>>(N,vector<T>(M)) ;
}
template<class T>
vector<vector<T>> vector2D( let N, let M, T Value ){
	return vector<vector<T>>(N,vector<T>(M,Value)) ;
}
#define then ;
#define vector2D( t ) vector<vector<t>>
template<class T>
class matrix{
	public :
    T ** v ;
	let rows, cols ;
		matrix( let n, let m ){
			v = array2D<T>( n, m ) ;
			rows = n ;
			cols = m ;
		}
		void input(){
			ij_upto( rows, cols ) cin >> v[i][j] ;
		}
		T& at( let i, let j ){
			return v[i][j] ;
		}
		void set( let i, let j, T value ){
			v[i][j] = value ;
		}
		void output(){
			for( let i = 0 ; i < rows ; i++ ){
				for( let j = 0 ; j < cols ; j++ ){
					cout << v[i][j] << " " ;
				}
				cout << endl ;
			}
		}
		void fill( T value ){
			ij_upto( rows, cols ) v[i][j] = value ;
		}
		T ** begin(){
			return v ;
		}
		T ** end(){
			return v + rows ;
		}
};
//

bool compare( let * a, let *b ){
	return a[0] + a[1] < b[0] + b[1] ;   // w should be in increasing order and s should also in increasing order
}
let Min( let a, let b ){
	return a < b ? a : b ;
}
let Max( let a, let b ){
	return a > b ? a : b ;
}

// 0 -> w, 1 -> s, 2 -> v 
// main
// write your code here
int main(){
	async ;
    let N then cin >> N ;
    matrix<let> arr( N, 3 ) then arr.input() ;
	sort( arr.begin() , arr.end() , compare ) ;
	let dp[20001] = {0} ;
	for( let part = 0 ; part < N ; part++ ){
		for( let j = arr.at(part,1) ; j >= 0 ; j-- ){
			dp[j+arr.at(part,0)] = Max(dp[j+arr.at(part,0)], dp[j]+arr.at(part,2) ) ;
		}
	}
	let ans = 0 ;
	i_upto( 20001 ) ans = Max( ans, dp[i] ) ;
	cout << ans then return 0 ;
} 

Measured memory_bytes: 3840
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>

using namespace std;
#define i64  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807



void solve(void)
{

  vector<vector<vector<int> > > data(4,vector<vector<int> >(3,vector<int>(10,0)));

  

  int N;
  cin>>N;

  for (int i = 0; i < N; i++)
  {
    int A,B,C,D;
    cin>>A>>B>>C>>D;

    data[(A-1)][(B-1)][C-1] += D;
  }

  for (int i_1 = 0; i_1 < 4; i_1++)
  {
    for (int i_2 = 0; i_2 < 3; i_2++)
    {
      for (int i_3 = 0; i_3 < 10; i_3++)
      {
        cout<<" "<<data[i_1][i_2][i_3];
        
      }
      cout<<endl;
    }
    if(i_1 <3) cout<<"####################"<<endl;
  }
  
  
    
  return;
}

int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define display(v) for (auto x : v) cout << x << ", "
#define print(x) cout << (#x) << " = [ ";display(x); cout << "]\n"
#define endl '\n'
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
 
// DEBUG TEMPLATE by livw
void __print(int x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifdef INCLUDEWHENOFFLINE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif



int main()
{
    fastio;
    
    int a, b;
    cin >> a >> b;
    int ans = a / b;
    if (a % b != 0) ans++;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  vector<long> foo(5);
  rep (i, 5) cin >> foo[i];
  long max = 0;
  rep (i, 5) {
    if (foo[i] % 10 != 0) {
      long tmp = 10 - foo[i] % 10;
      if (tmp > max) max = tmp;
      foo[i] += tmp;
    }
  }
  long result = 0;
  rep (i, 5) result += foo[i];
  result -= max;
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256