akhauriyash/Code-Regression huggingface dataset:
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------






int main(void){
	int h, w;
	cin >> h >> w;

	vector<vector<int>> field(h, vector<int>(w));


	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			cin >> field[i][j];
		}
	}

	class Move{
	public:
		pair<int, int> from;
		pair<int, int> to;
	};

	vector<Move> ans;

	for (int y = 0; y < h; y++){
		if (y % 2 == 0){
			for (int x = 0; x < w; x++){
				if (x != w - 1){
					if (field[y][x] % 2 != 0){
						//cout << y << " " << x << " " << y << " " << x + 1 << endl;
						field[y][x]--;
						field[y][x + 1]++;
						Move tmp;
						tmp.from = make_pair(y, x);
						tmp.to = make_pair(y, x + 1);
						ans.push_back(tmp);
					}
				}
				else {
					if (y == h - 1){
						break;
					}
					if (field[y][x] % 2 != 0){
						//cout << y << " " << x << " " << y + 1 << " " << x << endl;
						field[y][x]--;
						field[y + 1][x]++;
						Move tmp;
						tmp.from = make_pair(y, x);
						tmp.to = make_pair(y + 1, x);
						ans.push_back(tmp);
					}
				}
				
			}
		}
		else {
			for (int x = w - 1; x >= 0; x--){
				if (x != 0){
					if (field[y][x] % 2 != 0){
						//cout << y << " " << x << " " << y << " " << x - 1 << endl;
						field[y][x]--;
						field[y][x - 1]++;
						Move tmp;
						tmp.from = make_pair(y, x);
						tmp.to = make_pair(y, x - 1);
						ans.push_back(tmp);
					}
				}
				else {
					if (y == h - 1){
						break;
					}
					if (field[y][x] % 2 != 0){
						//cout << y << " " << x << " " << y + 1 << " " << x << endl;
						field[y][x]--;
						field[y + 1][x]++;
						Move tmp;
						tmp.from = make_pair(y, x);
						tmp.to = make_pair(y + 1, x);
						ans.push_back(tmp);
					}
				}
			}
		}
	}

	cout << ans.size() << endl;

	for (int i = 0; i < ans.size(); i++){
		cout << ans[i].from.first + 1 << " " << ans[i].from.second + 1 << " " << ans[i].to.first + 1 << " " << ans[i].to.second + 1 << endl;
	}

}



Measured memory_bytes: 5232
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    ll N, K;
    cin >> N;
    cin >> K;

    ll combinations = K;
    repeat (i, N - 1) {
        combinations *= (K - 1);
    }
    cout << combinations << endl;
    return 0;
}


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

using namespace std;

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

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

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

#define MOD 1000000007

void solve(int test_case) {//220
	int h,w;
	cin>>h>>w;
	vector<string> arr(h);
	for(auto &i:arr)cin>>i;
	vector<vi> ans(h,vi(w,0));
	REP(i,0,h-1) {
		REP(j,0,w-1) {
			if(arr[i][j]=='#'){ans[i][j]=-1;continue;}
			if(j-1>=0&&arr[i][j-1]=='#')ans[i][j]++;
			if(j+1!=w&&arr[i][j+1]=='#')ans[i][j]++;
			if(i-1>=0&&arr[i-1][j]=='#')ans[i][j]++;
			if(i+1!=h&&arr[i+1][j]=='#')ans[i][j]++;
			if(j-1>=0&&i-1>=0&&arr[i-1][j-1]=='#')ans[i][j]++;
			if(j-1>=0&&i+1!=h&&arr[i+1][j-1]=='#')ans[i][j]++;
			if(j+1!=w&&i-1>=0&&arr[i-1][j+1]=='#')ans[i][j]++;
			if(j+1!=w&&i+1!=h&&arr[i+1][j+1]=='#')ans[i][j]++;
		}
	}
	REP(i,0,h-1){REP(j,0,w-1){if(ans[i][j]==-1)cout<<"#";else cout<<ans[i][j];}cout<<"\n";}
}

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


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

int main()
{
    KAKA
    string s;
    cin>>s;
    if(s.back() == 's')
    {
        s += "es";
    }
    else s += 's';
    cout<<s<<"\n";
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std::literals;
using namespace std;

namespace xmaho
{
inline namespace input
{
template<typename T>
T get_value(std::istream& is = std::cin);
template<typename C>
C get_container(std::istream& is = std::cin, typename C::size_type length = std::numeric_limits<typename C::size_type>::max());
}
}
using namespace xmaho;

int main()
{
  unsigned long n, a, b;
  cin >> n >> a >> b;
  auto block_size {a + b};
  auto loop_count {n / block_size};
  auto rest {n % block_size};
  auto rest_a {min(rest, a)};
  cout << loop_count * a + rest_a << '\n';
  return 0;
}

class initalization
{
  class custom_numpunct: public std::numpunct<char>
  {
  public:
    using numpunct::numpunct;
  protected:
    std::string do_truename() const override { return "Yes"; }
    std::string do_falsename() const override { return "No"; }
  };

public:
  initalization()
  {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.imbue(std::locale(std::cout.getloc(), new custom_numpunct{}));
    std::cout << std::boolalpha << std::fixed << std::setprecision(15);
  }
} initalize;

template<typename T>
T xmaho::input::get_value(std::istream& is)
{ T v {}; is >> v; return v; }

template<typename C>
C xmaho::input::get_container(std::istream& is, typename C::size_type length)
{
  C v {};
  if (length != std::numeric_limits<typename C::size_type>::max())
    v.reserve(length);
  typename C::value_type e {};
  for (auto i {length}; i != 0 && is >> e; --i)
    v.push_back(std::move_if_noexcept(e));
  return v;
}


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

const int MOD=1000000007;
int n;
int A[100000],B[100000];

int main(){
    cin >> n;

    for(int i=0;i<n;i++){
        A[abs((n-1-i)-i)]++;
    }

    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        B[x]++;
    }

    int cc=1;

    for(int i=0;i<n;i++){
        if(A[i]!=B[i]){
            cout << 0 << endl;
            return 0;
        }
        if(A[i])
            cc=cc*A[i]%MOD;
    }

    cout << cc << endl;

    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 13234566667
#define int long long
vector<int> v;
int n;
void dfs(int x, int depth ) {
    if (depth >= 10) return;
    v.push_back(x);
    if (x % 10 != 0) dfs(x * 10 + (x - 1) % 10, depth + 1);
    dfs(x * 10 + (x) % 10, depth + 1);
    if (x % 10 != 9) dfs(x * 10 + (x + 1) % 10, depth + 1);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, 9) dfs(i + 1, 0);
    sort(v.begin(), v.end());
    cout << v[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
ll H, W;
string field[500];
ll sh, sw;
ll dh[4] = {1, -1, 0, 0};
ll dw[4] = {0, 0, 1, -1};
ll dist[500][500];


int main() {
    cin >> H >> W;
    for(int h = 0; h < H; h++) {
        cin >> field[h];
        for(int w = 0; w < W; w++) {
            if(field[h][w] == '%') {
                sh = h;
                sw = w;
            }
            dist[h][w] = INF;
        }
    }
    dist[sh][sw] = 0;
    queue<i_i> que;
    que.push({sh, sw});
    while(!que.empty()) {
        auto tmp = que.front();
        que.pop();
        int fromh = tmp.first;
        int fromw = tmp.second;
        for(int k = 0; k < 4; k++) {
            int toh = fromh + dh[k];
            int tow = fromw + dw[k];
            if(toh >= H or toh < 0) continue;
            if(tow >= W or tow < 0) continue;
            if(field[toh][tow] == '#') continue;
            ll c = dist[fromh][fromw] + 1;
            if(chmin(dist[toh][tow], c)) que.push({toh, tow});
        }
    }
    ll q;
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            if(field[h][w] == '@') q = dist[h][w];
        }
    }
    string ans = "Yes";
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            if(field[h][w] != '$') continue;
            if(dist[h][w] <= q) ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4068
#include<bits/stdc++.h>
using namespace std;
int h,w;
int dx[4] = {0,1,0,-1};
int dy[4] = {-1,0,1,0};
char maps[51][51];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	bool flag = true;
	cin >> h >> w;
	for(int i = 0;i < h;++i){
		for(int j = 0;j < w;++j){
			cin >> maps[i][j];
		}
	}
	for(int i = 0;i < h && flag;++i){
		for(int j = 0;j < w && flag;++j){
			if(maps[i][j] == '#'){
				int cnt = 0;
				for(int f = 0; f < 4;++f){
					int nx = dx[f] + j;
					int ny = dy[f] + i;
					if(maps[ny][nx] == '#')cnt++;
				}
				if(cnt == 0)flag = false;
			}
		}
	}
	if(flag)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	a, b, c := sc.NextInt(), sc.NextInt(), sc.NextInt()

	p := (c - a - b) * (c - a - b)
	ans := c-a-b >= 0 && 4*a*b < p
	if ans {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int d[105][105];
int main()
{
	int n,m;
	scanf("%d",&m);
	while(m){
		n=0;
		memset(d,0x3f,sizeof d);
		for(int i=1;i<=m;i++){
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);
			d[a][b]=c;
			d[b][a]=c;
			n=max(n,max(a,b));
		}
		for(int i=0;i<=n;i++)
			d[i][i]=0;
		for(int k=0;k<=n;k++)
			for(int i=0;i<=n;i++)
				for(int j=0;j<=n;j++)
					if(d[i][k]!=1061109567&&d[k][j]!=1061109567)
					d[i][j]=min(d[i][k]+d[k][j],d[i][j]);
		int ans=1<<30,ansi;
		for(int i=0;i<=n;i++){
			int sum=0;
			for(int j=0;j<=n;j++){
				if(d[i][j]==1061109567){
					sum=1<<30;
					break;
				}
				sum+=d[i][j];
			}
			if(sum<ans)
				ans=sum,ansi=i;
		}
		printf("%d %d\n",ansi,ans);
		scanf("%d",&m);
	}
}

Measured memory_bytes: 2624
#include <iostream>
using namespace std;
int main(){
    int n,p;
    cin>>n;
    int m=0;
    int total=0;
    for(int i=0;i<n;i++){
        cin>>p;
        total+=p;
        if(p>m) m=p;
    }
    total-=(m/2);
    cout<<total<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  int i;
  char s[100000];
  scanf("%s", s);
  for( i=0; i<strlen(s); i++){
    //printf("%c", s[i]);
    if(i%2==0){
      printf("%c", s[i]);
    }
  }
  //printf("%c\n", s[0]);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())

static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra() {
    int minv;
    int d[MAX], color[MAX];
    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }
    d[0] = 0;
    color[0] = GRAY;
    while (1) {
        minv = INFTY;
        int u = -1;
        for (int i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1) {
            break;
        }
        color[u] = BLACK;
        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INFTY) {
                if (d[v] > d[u] + M[u][v]) {
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = INFTY;
        }
    }
    int k, c, u, v;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            M[u][v] = c;
        }
    }
    dijkstra();
    return 0;
}


Measured memory_bytes: 3104
#!/usr/bin/env ruby

require 'set'

debug = false

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

def bit_search(bit_num)
  for x in [*0...2**bit_num]
    # true, falseの配列がyieldされる
    yield x.to_s(2).rjust(bit_num, '0').split('').map { |s| s == '1' }
  end
end

H, W, K = get_ints
S = Array.new(H) { [] }

H.times do |i|
  S[i] = gets.chomp.split('')
end

ans = H - 1 + W - 1
# 横線はbit全探索
bit_search(H-1) do |arr|
  tate = []
  youso = [0]
  arr.each.with_index do |b, i|
    if b
      tate.push(youso)
      youso = [i+1]
    else
      youso.push(i+1)
    end
  end
  tate.push(youso)

  # 縦に線を引いていく
  stock = Array.new(tate.length, 0)
  ws = Set.new
  ws.add(-1)
  impossible = false
  for w in [*0...W]
    sub = Array.new(tate.length, 0)
    tate.each.with_index do |t_arr, i|
      t_arr.each { |t| sub[i] += 1 if S[t][w] == '1' }
    end
    if stock.zip(sub).any? { |a, b| a + b > K }
      # 越したので線を引く
      if ws.include?(w-1)
        impossible = true
        break
      end
      ws.add(w-1)
      stock = sub
    else
      stock = stock.zip(sub).map { |a, b| a + b }
    end
  end

  next if impossible

  res = arr.count { |x| x } + (ws.length - 1)
  ans = res if res < ans
end

puts ans


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

typedef long long ll;
using namespace std;

int main(){
  ll h;
  cin>>h;
  ll ans = 2, cnt = 0;
  while (h > 1)
  {
    h /= 2;
    cnt++;
  }

  while(cnt>0){
    cnt--;
    ans *= 2;
  }
  cout << ans-1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;

int main (){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    int tmp;
    pair<int, int> a[100005];
    cin >> N;
    rep(i, N){
        cin >> tmp;
        a[i].first = tmp;
        a[i].second = i;
    }

    sort(a, a + N);
    rep(i, N){
        if (i < N-1){
            cout << a[i].second + 1 << " ";
        } else {
            cout << a[i].second +1 << endl;
        }
    }


}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#define pi acos(-1.0)


using namespace std;
int main()
{
    long long int n,m,o,p,q,i,j,k;
    char a[10];

    while(scanf("%lld",&n)==1)
    {
       for(i=1,k=0;i<=n;i++)
       {
           if(i<10 || (i>99 && i<1000) || (i>9999 && i<100000))
           {
               k++;
           }
       }
       printf("%lld\n",k);
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl
 
#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define ff first
#define ss second
#define mod 1000000007

#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	ios_base::sync_with_stdio(false);
     	cin.tie(NULL);
    	cout.tie(NULL);    
    string str;cin>>str;
    if(str[2]==str[3] && str[4]==str[5]){
        yes;
    }else no;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_vector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_vector(int n, Ts ... ts){
        return vector<decltype(make_vector(ts...))>(n, make_vector(ts...));
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    void run(){
        string s;
        is >> s;
        if(!is) return;
        int goo, par;
        goo = par = 0;
        int point = 0;
        for (auto &&st : s) {
            if(st == 'p') point--;
        } // end st
        point += s.size()/2;
        os << point << endl;

    }
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_062D.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    int a = 0;
    while (true)
    {
        if (a>=n) break;
        a+=1000;
    }
    cout<<a-n<<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int N, Q;
Graph G;
vector<int> sum;
vector<int> ans;

void dfs(int _pre, int _now, int _sum){
    _sum += sum[_now];
    ans[_now] += _sum;
    for(auto v : G[_now]){
        if(v == _pre)continue;
        dfs(_now, v, _sum);
    }
    return;
}

int main(){
    cin >> N >> Q;
    G.assign(N, vector<int>());
    sum.assign(N, 0);
    ans.assign(N, 0);
    for(int i = 1; i < N; i++){
        int from, to;
        cin >> from >> to;
        --from;
        --to;
        G[from].push_back(to);
        G[to].push_back(from);
    }
    for(int i = 0; i < Q; i++){
        int ple, plu;
        cin >> ple >> plu;
        --ple;
        sum[ple] += plu;
    }
    
    dfs(0, 0, 0);
    
    for(auto v : ans){
        cout << v << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

char a[501][501];
int n; 
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	bool allempty = 1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
			if(a[i][j]=='#') allempty=0;
		}
	}
	if(allempty)
	{
		cout<<-1<<'\n';
		return 0;
	}
	int fullcol = 0;
	for(int j = 0; j < n; j++)
	{
		bool full=1;
		for(int i=0;i<n;i++)
		{
			if(a[i][j]=='.')
			{
				full=0;
				break;
			}
		}
		if(full) fullcol++;
	}
	if(fullcol==n)
	{
		cout<<0<<'\n'; return 0;
	}
	int minans = 1000000;
	for(int i = 0; i < n; i++)
	{
		//find min steps to make row i full
		int cntemp = 0;
		for(int j = 0; j < n; j++)
		{
			if(a[i][j]=='.') cntemp++;
		}
		if(cntemp==0)
		{
			minans=0; break;
		}
		bool pos=0;
		for(int j = 0; j < n; j++)
		{
			if(a[j][i]=='#')
			{
				pos=1;
			}
		}	
		if(!pos)
		{
			cntemp++;
			pos=1;
		}
		if(pos)
		{
			minans=min(minans,cntemp);
		}
	}
	minans+=n-fullcol;
	cout<<minans<<'\n';
}


Measured memory_bytes: 512
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var a = readLine()!!.split(' ').map { it.toInt() }
    var cnt = 0
    while(a.all { it%2 == 0 }) {
        cnt++
        a = a.map { it/2 }
    }
    println(cnt)
}


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

int countOk(int r, int c, vector<vector<int> > v){
    int sum = 0;
    for(int j=0; j<c; j++){
        int count = 0;
        for(int i=0; i<r; i++){
            if(v[i][j] == 1) count++;
        }
        sum += max(count, r-count);
    }
    return sum;
}

int solve(int r, int c, int idx, vector<vector<int> > v){
    if(idx >= r) return countOk(r, c, v);
    vector<vector<int> > vv = v;
    for(int i=0; i<c; i++){
        vv[idx][i] *= -1;
    }
    return max(solve(r, c, idx+1, v), solve(r, c, idx+1, vv));
}

int main(void){
    while(1){
        int r, c; cin >> r >> c;
        if(!r && !c) break;
        vector<vector<int> > a;
        a.resize(r);
        for(int i=0; i<r; i++){
            a[i].resize(c);
            for(int j=0; j<c; j++){
                cin >> a[i][j];
                if(a[i][j] == 0) a[i][j] = -1;
            }
        }
        
        cout << solve(r, c, 0, a) << endl;
    }    
}



Measured memory_bytes: 15752
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const double g=10.0,eps=1e-7;
const int N=200000+10,maxn=500+100,inf=0x3f3f3f;

vector<int>v[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=0;i<v[1].size();i++)
    {
        int u=v[1][i];
        for(int j=0;j<v[u].size();j++)
        {
            if(v[u][j]==n)
            {
                cout<<"POSSIBLE"<<endl;
                return 0;
            }
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}
/********************

********************/


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


int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long r = 0;
  long long g = 0;
  long long b = 0;
  for(int i = 0; i < n; i++){
      if(s[i] == 'R'){r++;}
      else if(s[i] == 'G'){g++;}
      else if(s[i] == 'B'){b++;} 
  }
    long long cnt = 0;
    if(r == 0 || g == 0 || b == 0){
        cout << 0 << endl;
    }
    else{
        cnt = r * g * b;
        for(int i = 1; i <= (n - 1) / 2; i++){
            for(int j = 0; j < n - 2 * i; j++){
                if(s[j] != s[j + i] && s[j] != s[j + 2*i] && s[j + i] != s[j + 2*i]){
                    cnt--;
                }
            }
        }
        if(cnt < 0){cnt = 0;}
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int n,k,a[100005];
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int s=(n-k)/(k-1)+1;
	if((n-k)%(k-1)!=0)s++;
	cout<<s<<endl;
	return 0;
}

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


int main(){
  long long N; cin>>N;
  std::set<long long> s;

  long long no1=0,no2=0;

  for(long long i=0;i<N;i++){
    long long k; cin>>k;
    auto result = s.insert(k);
    if(!result.second){
      if(no1<k){
        no2 = no1;
        no1 = k;
      }else if(no2<k){
        no2 = k;
      }
      s.erase(result.first);
    }

    cout<<endl;
  }

  cout<<no1*no2<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

int main() {
    int N, P;
    string S;
    cin>>N>>P>>S;
    if(P==2||P==5){
        ll ans=0ll;
        for (int i = 0; i < N; ++i) {
            if((S[i]-'0')%P==0) ans+=(ll)(i+1);
        }
        cout<<ans<<endl;
        return 0;
    }

    vector<int> mods(N+1,0);
    int mod10=1;
    vector<int> cnt(P,0);
    cnt[0]++;
    for (int i = N-1; i >= 0; --i) {
        (mod10*=10)%=P;
        mods[i]=(mods[i+1]+(S[i]-'0')*mod10)%P;
        cnt[mods[i]]++;
    }

    ll ans=0ll;
    for (int i = 0; i < P; ++i) {
        ans+=(ll)(1ll*cnt[i]*(cnt[i]-1ll))/2ll;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1412
n, l = (int(i) for i in input().split())
ans = 0
flg = 0
temp = 1000
for i in range(n) :
  sum =  l + (i + 1) - 1
  if sum == 0 :
    flg = 1
  elif temp > abs(sum) :
    temp = abs(sum)
    min = sum
  ans += sum
if flg == 1 :
  print(ans)
else :
  print(ans - min)


Measured memory_bytes: 3060
#include <stdio.h>
// route[i][0]はs>eの際に参照する(0へ向かう)
// route[1][1]はs<eの際に参照する
int route[10][2] = {
    {1,1}, //0
    {0,2}, //1
    {1,3}, //2
    {2,4}, //3
    {3,5}, //4
    {4,6}, //5
    {7,7},//6
    {8,8},//7
    {9,9},//8
    {5,5},//9
};

int
main(void) {
    char line[10];
    int n;
    int i, l, t;
    int s, e;
   
    fgets(line, 10, stdin);
    sscanf(line, "%d", &n);

    for (l = 0; l < n; l++) {
        if (fgets(line, 10, stdin) == NULL)
            break;
        sscanf(line, "%d %d", &s, &e);
       
        t = s < e;
        i = s;
        while (i != e) {
            printf("%d ", i);
            i = route[i][t ? 1 : 0];
            if (i == 0)
                t = !t;
        }
        printf("%d\n", i);
    }

    return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;

typedef pair<int,int> pii;
typedef pair<pii,int> pxyi;

vector<pii> N;
set <pii> s;
const int dx[] = {1, 1, 0, -1, -1, 0}, dy[] = {0, 1, 1, 0, -1, -1};
  
void bfs(int sx, int sy, int st)
{
  vector<pxyi> v;
  queue<pxyi> q;
  q.push(pxyi(pii(sx,sy),st));
  while(!q.empty()){
    int x, y, t;
    x = q.front().first.first;
    y = q.front().first.second;
    t = q.front().second;
    q.pop();
    bool flag = false;
    for(int i = 0; i < (int)v.size(); i++){
      if(v[i].first.first == x && v[i].first.second == y && v[i].second)
        flag = true;
    }
    if(flag){
      if(q.empty()) break;
      else continue;
    }else{
      s.insert(pii(x,y));
      v.push_back(pxyi(pii(x,y),t));
    }
    if(t == 0){
      if(q.empty()) break;
      else continue;
    }
    for(int i = 0; i < 6; i++){
      flag = false;
      int next_x = x + dx[i], next_y = y + dy[i];
      for(int j = 0; j < (int)N.size(); j++){
        if(N[j].first == next_x && N[j].second == next_y)
          flag = true;
      }
      if(flag) continue;
      q.push(pxyi(pii(next_x,next_y),t-1));
    }
  }
}


int main()
{
  while(1){
    s.clear();
    N.clear();
    int t, n;
    cin >> t >> n;
    if(t == 0 && n == 0) break;
    for(int i = 0; i < n; i++){
      int x, y;
      cin >> x >> y;
      N.push_back(pii(x,y));
    }
    int start_x, start_y;
    cin >> start_x >> start_y;
    bfs(start_x,start_y,t);
    cout << s.size() << endl;
  }
}

Measured memory_bytes: 1432
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD 1000000007
#define MAXN 100010

int n[3], q, as[3][MAXN], bs[3][MAXN];
char s[3][MAXN];

int mod(int x){
	return ((x%3)+9)%3;
}

int main(){
	while(scanf("%s", s[0])!=EOF){
		scanf("%s", s[1]);
		n[0]=strlen(s[0]); n[1]=strlen(s[1]);
		for(int ss=0; ss<2; ss++){		
			for(int i=0; i<n[ss]; i++){
				as[ss][i]=0;
				if(s[ss][i]=='A'){
					as[ss][i] = 1;
				}
				if(i>0){
					as[ss][i] += as[ss][i-1];
				}
				bs[ss][i] = (i+1)-as[ss][i];
			}
		}
		scanf("%d", &q);
		int a, b, c, d;
		for(int i=0; i<q; i++){
			scanf("%d %d %d %d", &a, &b, &c, &d);
			a--; b--; c--; d--;
			int qa0 = as[0][b] - ((a-1>=0)?as[0][a-1]:0);
			int qb0 = (b-a+1)-qa0;
			int qa1 = as[1][d] - ((c-1>=0)?as[1][c-1]:0);
			int qb1 = (d-c+1)-qa1;
			if(mod(qa0-qb0)==mod(qa1-qb1)){
				printf("%s\n", "YES");
			}
			else{
				printf("%s\n", "NO");
			}
		}
	}
	return 0;
}

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


void solve(unsigned long long N){
    if(N % 2 == 1){
        cout << 0 << endl;
    }else{
        ull d2 = N / 2;
        ull n2  = d2 * (d2 + 1) / 2;
        ull n5 = 0;
        ull M = N / 2;
        while(M >= 5){
            n5 += M / 5;
            M /= 5;
        }
        cout << min(n2, n5) << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    unsigned long long N;
    scanf("%llu",&N);
    solve(N);
    return 0;
}


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

int main(){
  int n,r;
  cin>>n>>r;
  if(n<10){
    cout<<r+100*(10-n)<<endl;
  }
  else{
    cout<<r<<endl;
  }
}

Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let a=asc(nrin(3))
  out(a[0]==5&&a[1]==5&&a[2]==7?'YES':'NO')
}
main()

Measured memory_bytes: 7372
import math

n = int(input())
if n == 0:
    print(0)
    exit()
out = ""
i = 0
while n != 0:
    if n % -2 != 0:
        out = str(- (n % -2)) + out
        # print("n:{} div:{}=(-2)^{}".format(n, (-2) ** i, i))
    else:
        out = str(- (n % -2)) + out

    # 123->100, -123->-100
    if n > 0:
        n = int(n / (-2))
    else:
        n = math.ceil(n / (-2))
    i += 1
print(out)
"""
tmp = 1
digit = 0
while tmp < n:
    tmp *= 4
    digit += 1
number = [0 for i in range(digit)]
print(number)
tmp = n
for i in range(digit):
    if 0 < tmp % 4 < 4:
        number[i] = tmp % 4
        tmp = int(tmp / 4)
"""


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;


int main() {
    int a,b;
    cin >> a>>b ;
    if (a == b)cout << "Draw" << endl;
    else if (b == 1)cout << "Bob" << endl;
    else if (a == 1)cout << "Alice" << endl;
    else if (a < b)cout << "Bob" << endl;
    else cout << "Alice" << endl;
   
    
    return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let s: String = read();
    let mut t: String = read();

    t.pop();

    if s == t {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    if (S.back() == '3') puts("bon");
    else if (S.back() == '0' || S.back() == '1' || S.back() == '6' || S.back() == '8') puts("pon");
    else puts("hon");
}

Measured memory_bytes: 3620
package main

import (
	"fmt"
)

func main() {
	var s string
	_, _ = fmt.Scan(&s)
	var answer = true
	
	for index, i := range s {
		if (index+1)%2 == 0 && i == 'R' {
			answer = false
			break
		} else if (index+1)%2 != 0 && i == 'L' {
			answer = false
			break
		}
	}
	
	if answer {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def reverse_insort(a, x, lo=0, hi=None):
    """Insert item x in list a, and keep it reverse-sorted assuming a
    is reverse-sorted.

    If x is already in a, insert it to the right of the rightmost x.

    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.
    """
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if x > a[mid]: hi = mid
        else: lo = mid+1
    a.insert(lo, x)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    index = bisect.bisect_left(A, 0)
    minus = A[:index]
    minus.reverse()
    plus = A[index:]
    # print(minus)
    # print(plus)
    progres = []
    ans = 0
    while True:
        if len(plus) == 1 and len(minus) == 1:
            p = plus.pop()
            m = minus.pop()
            progres.append((p, m))
            ans = p - m
            # print('{} {}'.format(p, m))
            break

        if len(plus) == 1 and len(minus) == 0:
            ans = plus.pop()
            break
        if len(plus) == 0 and len(minus) == 1:
            ans = minus.pop()
            break

        # まだ2つ以上入ってる
        if len(plus) == 0:
            val1 = minus.pop()  # 一番小さい
            val2 = minus.pop(0)
            new_val = val2 - val1
            plus.append(new_val)
            progres.append((val2, val1))
            # print('{} {}'.format(val1, val2))
            continue
        if len(minus) == 0:
            val1 = plus.pop(0)
            val2 = plus.pop()
            new_val = val1 - val2
            minus.append(new_val)
            progres.append((val1, val2))
            # print('{} {}'.format(val2, val1))
            continue

        if len(plus) > len(minus):
            val1 = plus.pop()
            val2 = minus.pop()
            new_val = val2 - val1
            reverse_insort(minus, new_val)
            progres.append((val2, val1))
            # print('{} {}'.format(val2, val1))
        else:
            val1 = plus.pop()
            val2 = minus.pop()
            new_val = val1 - val2
            index = bisect.bisect_left(plus, new_val)
            plus.insert(index, new_val)
            progres.append((val1, val2))
            # print('{} {}'.format(val1, val2))

    print(ans)
    for p, q in progres:
        print('{} {}'.format(p, q))


if __name__ == '__main__':
    main()


Measured memory_bytes: 63636
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
using namespace std;
const int INF = 1e9;

int N,C;
int d[33][33],c;
int dp[5][33],e[5][33],ans=INF;
int main(){
  cin>>N>>C;
  REP(i,C)REP(j,C)cin>>d[i][j];
  REP(i,N)REP(j,N){
    cin>>c;
    dp[(i+j)%3][c-1]++;
  }
  REP(i,3)REP(j,C)REP(k,C){
    e[i][k]+=dp[i][j]*d[j][k];
  }
  REP(i,C)REP(j,C){
    if(i!=j){
      REP(k,C){
	if(i!=k && j!=k){
	  ans=min(e[0][i]+e[1][j]+e[2][k],ans);
	}
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
using namespace std;

static const int MAX = 100;
static const long long INFTY = (1LL << 32);

int n;
long long D[MAX][MAX];

void floyd()
{
  for (int k = 0; k < n; k++)
  {
    for (int i = 0; i < n; i++)
    {
      if (D[i][k] == INFTY)
      {
        continue;
      }
      for (int j = 0; j < n; j++)
      {
        if (D[k][j] == INFTY)
        {
          continue;
        }
        D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
      }
    }
  }
}

int main()
{
  int e, s, t, d;
  cin >> n >> e;

  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      D[i][j] = ((i == j) ? 0 : INFTY);
    }
  }
  for (int i = 0; i < e; i++)
  {
    cin >> s >> t >> d;
    D[s][t] = d;
  }

  floyd();

  bool negative = false;
  for (int i = 0; i < n; i++)
  {
    if (D[i][i] < 0)
    {
      negative = true;
    }
  }

  if (negative)
  {
    cout << "NEGATIVE CYCLE" << endl;
  }
  else
  {
    for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < n; j++)
      {
        if (j)
        {
          cout << " ";
        }
        if (D[i][j] == INFTY)
        {
          cout << "INF";
        }
        else
        {
          cout << D[i][j];
        }
      }
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3180
Public Class Program
  Shared Sub Main()
    Dim n As Integer = Integer.Parse(Console.ReadLine())
    Dim arrayV As Double() = Array.ConvertAll(Of String, Double)(Console.ReadLine().Split(" "), AddressOf Double.Parse)
    For i As Integer = 0 To n - 2
      Array.Sort(arrayV)
      Dim s As Double = (arrayV(i) + arrayV(i + 1)) / 2
      arrayV(i) = 0
      arrayV(i + 1) = s
    Next
    Console.WriteLine(arrayV(n - 1).ToString())
  End Sub
End Class

Measured memory_bytes: 13268
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, 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 S(): return input().rstrip()
def LS(): return S().split()
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)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    a = LI()
    a.sort()
    ans = 0
    a = a[::-1]
    for i in range(1, n):
        ans += a[i // 2]
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 111228