akhauriyash/Code-Regression huggingface dataset:
/**
 * @author torith
 * @date 2018-10-27
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A;
    for (int i = 0; i < N; ++i) {
        int t; cin >> t;
        A.push_back(t);
    }

    sort(A.begin(),A.end());

    ll ans = 0;
    if(N % 2 == 0){
        for (int i = 0; i < N/2 - 1; ++i) {
            ans += 2 * (A[A.size()-1-i] - A[i]);
        }
        ans += A[A.size()-N/2] - A[N/2-1];
    }else{

        // 奇数の方を大きい方
        for (int i = 0; i < N/2 - 1; ++i) {
            ans += 2 * A[A.size()-1-i];
        }

        ans += A[A.size()-1-N/2] + A[A.size()-N/2];
        for (int i = 0; i < N/2; ++i) {
            ans -= 2 * A[i];
        }

        ll tmp = 0;
        for (int i = 0; i < N/2 - 1; ++i) {
            tmp -= 2 * A[i];
        }
        tmp -= A[N/2] + A[N/2-1];
        for (int i = 0; i < N/2; ++i) {
            tmp += 2 * A[A.size()-1-i];
        }
        ans = max(ans,tmp);
    }

    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 892
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Coins solver = new Coins();
		solver.readInput();
		solver.solve();
		solver.writeOutput();
	}


	static public class Coins {

		private int a;
		private int b;
		private int c;
		private int x;

		private Scanner scanner;
		private int output;
		public Coins() {
			scanner = new Scanner(System.in);
			output = 0;
		}
		public void readInput() {
			a = scanner.nextInt();
			b = scanner.nextInt();
			c = scanner.nextInt();
			x = scanner.nextInt();
		}
		public void solve() {
			for(int i=0;i<=a;i++) {
				for(int j=0;j<=b;j++) {
					for(int k=0;k<=c;k++) {
						if((x-500*i-100*j-50*k)==0) {
							output++;
						}
					}
				}
			}
		}
		public void writeOutput() {
			System.out.println(output);
		}
	}
}


Measured memory_bytes: 23892
#include <iostream>
#include <map>
#include <cmath>

using namespace std;


void prime_factor(int n, map<long long int, long long int>& res)
{
	for (int i = 2; i * i <= n; i++)
	{
		while (n % i == 0)
		{
			++res[i];
			n /= i;
		}
	}
	
	if (n != 1)
	{
		if (res[n] > 0)
			res[n]++;
		else
			res[n] = 1;
	}
}


int main()
{
	long long int N;
	long long int ans = 1;
	map<long long int, long long int> count;

	cin >> N;

	for (int i = 2; i <= N; i++)
	{
		prime_factor(i, count);
	}

	for (int i = 2; i <= N; i++)
	{
		ans *= (count[i] + 1);
		ans %= (int)(pow(10, 9) + 7);
	}

	cout << ans<< endl;

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
s = input()
s1 = s[:2]
s2 = s[2:]
if 1 <= int(s1) <= 12 and 1 <= int(s2) <= 12:
    print("AMBIGUOUS")
elif (not 1 <= int(s1) <= 12) and 1 <= int(s2) <= 12:
    print("YYMM")
elif 1 <= int(s1) <= 12 and (not 1 <= int(s2) <= 12):
    print("MMYY")
else:
    print('NA')

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;
ll const MAX_N = 1005;
ll const MAX_M = 1005;

struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}

    mint operator-() const { return mint(-x); }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(MOD - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

// int dx[2] = {1, 0};
// int dy[2] = {0, 1};
mint dp[MAX_N][MAX_M];

int main() {
    INIT;

    ll H, W;
    cin >> H >> W;
    vector<string> a(H);
    rep(i, H) { cin >> a[i]; }

    rep(i, H) rep(j, W) dp[i][j] = 0;

    dp[0][0] = 1;
    rep(i, H) {
        rep(j, W) {
            if (i + 1 < H && a[i + 1][j] != '#') {
                dp[i + 1][j] += dp[i][j];
            }

            if (j + 1 < W && a[i][j + 1] != '#') {
                dp[i][j + 1] += dp[i][j];
            }
        }
    }

    // rep(i, H) {
    //     rep(j, W) { cout << dp[i][j] << " "; }
    //     cout << endl;
    // }

    cout << dp[H - 1][W - 1] << endl;

    return 0;
}

Measured memory_bytes: 12572
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class Main {
	
	static Scanner sc = new Scanner(System.in);
	static int w, h, sx, sy;
	static int[] dx = {-1, 0, 1, 0}, dy = {0, 1, 0, -1};
	static int[][] field = new int[22][22];
	
	public static void main(String[] args) {
		while(read()) {
			System.out.println(solve());
		}
	}
	
	static boolean read() {
		w = sc.nextInt();
		h = sc.nextInt();
		if(w == 0) 
			return false;
		
		for(int i = 0; i < field.length; i++)
			fill(field[i], -1);
		
		for(int i = 1; i <= h; i++) {
			for(int j = 1; j <= w; j++) {
				field[i][j] = sc.nextInt();
				if(field[i][j] == 2) {
					sx = j; sy = i;
					field[i][j] = 0;
				}
			}
		}
		return true;
	}
	
	static int solve() {
		int ans = rec(sx, sy, 0);
		return (ans > 10) ? -1 : ans;
	}
	
	static int rec(int x, int y, int step) {
		//ツ探ツ催オツ氾債暗債づーツ陳エツつヲツづつ「ツづゥツづ個づ、ツ妥つソツ静伉づィ
		if(step >= 10)
			return step + 1;
		
		int ans = 11;
		for(int i = 0; i < 4; i++) {
			int nx = x + dx[i], ny = y + dy[i];
			if(field[ny][nx] == 1 || field[ny][nx] == -1)
				continue;
			while(field[ny][nx] == 0) {
				nx += dx[i]; ny += dy[i];
			}
			if(field[ny][nx] == 3) {
				ans = step + 1;
				break;
			}
			
			if(field[ny][nx] == 1) {
				field[ny][nx] = 0;
				ans = min(ans, rec(nx - dx[i], ny - dy[i], step + 1));
				field[ny][nx] = 1;
			}
		}
		return ans;
	}
}

Measured memory_bytes: 12000
#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>;
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 (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i,n) cin >> d[i];
	sort(d.begin(), d.end());
	int ans = d[n/2] - d[n/2-1];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
using lint = long long;
const int NMAX=200000;
int main(){
  lint N; cin>>N;
  lint a[NMAX];
  cin>>a[0];
  for(int i=1;i<N;i++){
    cin>>a[i];
    a[i]+=a[i-1];
  }
  cout<<endl;
  lint ans=abs(a[0]-(a[N-1]-a[0]));
  for(int i=0;i<N-1;i++)
    ans=min(ans,abs(a[i]-(a[N-1]-a[i])));
  cout<<ans<<endl;  
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,k;
  cin>>n>>k;
  vecll a(n);
  for(auto&&e:a)cin>>e;
  REP(i,k) {
    if (all_of(ALL(a), [&](auto&&e){return e==n;})) break;
    vecll nx(n);
    REP(j,n) {
      int st = max(0l, j-a[j]);
      int la = min(n, j+a[j]+1);
      ++nx[st];
      if(la < n) --nx[la];
    }
    REP(j,n-1) {
      nx[j+1] += nx[j];
    }
    swap(nx, a);
  }
  REP(i,n) {
    if(i)cout<<" ";
    cout<<a[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 6352
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

s = input_s
cnt = 0
max = 0
(s.length).times do |i|
  if s[i] == "S"
    next if cnt == 0
    max = cnt
    cnt = 0
  end
  cnt += 1 if s[i] == "R"
end
max = cnt if cnt > max

puts max


Measured memory_bytes: 14248
q = int(input())

def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,int(n**0.5) + 1):
        # 既にfalseになってたらスキップ
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    return is_prime
prime_ls = primes(10**5)

csum = [0] * (10**5)
for i in range(1,10**5):
    if prime_ls[i]:
        if prime_ls[(i+1) // 2]:
            csum[i] = csum[i-1] + 1
        else:
            csum[i] = csum[i-1]
    else:
        csum[i] = csum[i-1]

ans_ls = [0] * q
for i in range(q):
    l,r = map(int,input().split())
    ans_ls[i] = csum[r] - csum[l-1]
for ans in ans_ls:
    print(ans)

Measured memory_bytes: 9352
import sys
from collections import Counter
 
def main():
    input = sys.stdin.readline
    
    n, m = map(int, input().split())
    h = [int(input()) for i in range(n)]
    
    h.sort()
    
    #一番大きい値を初期値に
    min = h[len(h) - 1]
    
    #差が一番小さい区間を探す
    for i, v in enumerate(h):
        
        ku = i + (m - 1)
        if ku < len(h):
            sa = h[ku] - h[i]
            min = min if min < sa else sa
        else:
            break
    
    print(min)
    
if __name__ == '__main__':
    main()
   

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

using namespace std;
#define BUF (1000)
#define ll long long 
#define MOD 1000000007
int n;


char str[105];
char A=1;
char C=2;
char G=3;
char T=4;

ll dp[5][5][5][105];

ll dfs(int k){
	//printf("%d, %d\r\n", k, str[k]);

	if(k==n) return 1;
	ll ret = 0;

	if(k>1 && dp[str[k-2]][str[k-1]][str[k]][k]!=0){
		return dp[str[k-2]][str[k-1]][str[k]][k];
	}

	str[k+1] = A;
	ret += dfs(k+1)%MOD;

	str[k+1] = C;
	if(k>0 && str[k-1]==A && str[k]==G ){ //AGC
		ret += 0;
	}else if(k>0 && str[k-1]==G && str[k]==A ){ //GAC
		ret += 0;
	}else if(k>1 && str[k-2]==A && str[k-1]==G ){ //AGxC
		ret += 0;
	}else if(k>1 && str[k-2]==A && str[k]==G ){ //AGxC
		ret += 0;
	}else{
		ret += dfs(k+1)%MOD;
	}

	str[k+1] = G;
	if(k>0 && str[k-1]==A && str[k]==C ){ //ACG
		ret += 0;
	}else{
		ret += dfs(k+1)%MOD;
	}

	str[k+1] = T;
	ret += dfs(k+1)%MOD;

	if(k>1 && dp[str[k-2]][str[k-1]][str[k]][k]==0){
		dp[str[k-2]][str[k-1]][str[k]][k] = ret%MOD;
	}
	return ret%MOD;
}

int main(void){
	cin >> n;
	cout << dfs(0) << endl;	
	return 0;
}


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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)

int main(void){
  int a,b;
  cin>>a>>b;
  int sum=0;
  r(i,b-a+1){
    sum+=i;
  }

 cout<<sum-b<<endl;
return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;
	s = s.substr(0, s.size() - 1);

	int len;
	for (len = s.size() / 2; len >= 0; len--) {
		if (s.substr(0, len) == s.substr(len, len)) {
			break;
		}
	}

	cout << len * 2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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 (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int q;
    cin >> s >> q;
    string head = "", tail = "";
    int ord = 1;
    rep(i,q){
        int t;
        cin >> t;
        if(t == 1) ord = 1 - ord;
        else{
            int f;
            char c;
            cin >> f >> c;
            if(f == 1){
                if(ord) head += c;
                else tail += c;
            }
            else{
                if(ord) tail += c;
                else head += c;
            }
        }
    }
    if(ord){
        for(int i = head.size()-1; i >= 0; --i){
            cout << head[i];
        }
        cout << s;
        cout << tail << endl;
    }
    else{
        for(int i = tail.size()-1; i >= 0; --i){
            cout << tail[i];
        }
        for(int i = s.size()-1; i >= 0; --i){
            cout << s[i];
        }
        cout << head << endl;
    }
    return 0;
}


Measured memory_bytes: 3868
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;


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

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> a(M, vector<int>(2));
    rep(i, M){
        cin >> a[i][0] >> a[i][1];
    }
    int startIndex = 0;
    int endIndex = 1000000;
    rep(i, M){
        startIndex = max(a[i][0], startIndex);
        endIndex = min(a[i][1], endIndex);
    }
    if(startIndex > endIndex) cout << 0 << endl;
    else cout << endIndex - startIndex + 1 << endl;
}

Measured memory_bytes: 5760
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int vis[1000007];
int main()
{
	int m;
	scanf("%d",&m);
	long long int a=0,b=0;
	long long int tem;
	int i;
	for(i=0;i<m;i++)
	{
		scanf("%lld",&tem);
		if(tem/400<8)
		{
			if(!vis[tem/400])
				a++;
			vis[tem/400]=1;
		}
		else
			b++;
	}
	printf("%lld %lld\n",max(a,1LL),a+b);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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 (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

const int MAX_V = 50;
const int MAX_S = MAX_V*50+5;
using plii = pair<ll,P>;

struct Edge{
    int to,a,b;
    Edge(int to,int a,int b) : to(to),a(a),b(b) {}
};

vector<vector<Edge>> G(MAX_V);
ll dist[MAX_V][MAX_S+5];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m,s;
    cin >> n >> m >> s;
    for(int i=0; i<m; i++){
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--;v--;
        G[u].emplace_back(v,a,b);
        G[v].emplace_back(u,a,b);
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<MAX_S+5; j++){
            dist[i][j] = INF;
        }
    }
    s = min(s,MAX_S);
    priority_queue<plii,vector<plii>,greater<plii>> q;
    auto push = [&](int v,int s,ll x){
        if(s < 0) return;
        if(dist[v][s] <= x) return;
        dist[v][s] = x;
        q.emplace(x,P(v,s));
    };
    vector<int> c(n),d(n);
    for(int i=0; i<n; i++){
        cin >> c[i] >> d[i];
    }
    push(0,s,0);
    while(q.size()){
        auto suzu = q.top();
        q.pop();
        int v = suzu.second.first;
        s = suzu.second.second;
        ll x = suzu.first;
        if(dist[v][s] != x) continue;
        int ns = min(s+c[v],MAX_S);
        push(v,ns,x+d[v]);
        for(Edge e: G[v]){
            push(e.to,s-e.a,x+e.b);
        }
    }
    for(int i=1; i<n; i++){
        ll ans = INF;
        for(int j=0; j<MAX_S+5; j++){
            chmin(ans,dist[i][j]);
        }
        cout << ans << enld;
    }
    return 0;
}

Measured memory_bytes: 6224
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))


sum=0
for b in B:
    sum+=b
for i in range(N-1):
    if A[i+1]-A[i]==1:
        sum+=C[A[i]-1]
print(sum)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, stack[1000];

void push(int x)
{
	top++;
	stack[top] = x;
}

int pop()
{
	top--;
	return stack[top + 1];
}

int main(void)
{
	int a, b;
	char operand[100];

	top = 0;

	while ( scanf("%s", operand) != EOF )
	{
		if ( operand[0] == '+' )
		{
			a = pop();
			b = pop();
			push(a + b);
		}
		else if ( operand[0] == '-' )
		{
			b = pop();
			a = pop();
			push(a - b);
		}
		else if ( operand[0] == '*')
		{
			a = pop();
			b = pop();
			push(a * b);
		}
		else
		{
			push(atoi(operand));
		}
	}
	printf("%d\n", pop() );
	return 0;
}



Measured memory_bytes: 2676
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int i,j;
	int w,h;
	while(1){
		cin>>h>>w;
		if(h==0&&w==0)	break;
		for(i=0;i<w;i++){
			cout<<"#";
		}
		cout<<endl;
		for(i=0;i<h-2;i++){
			cout<<"#";
			for(j=0;j<w-2;j++){
				cout<<".";
			}
			cout<<"#";
			cout<<endl;
		}
		for(i=0;i<w;i++){
			cout<<"#";
		}
		cout<<endl;
                cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using Pos = pair<int, int>;
bool solve() {
	int H, W;
	cin >> H >> W;
	vector<string> A(H);
	for (string& S : A) cin >> S;
	Pos current(0, 0);
	vector<Pos> passed = { current };
	vector<int> dh = { 1, 0 }, dw = { 0, 1 };
	while (current != Pos(H - 1, W - 1)) {
		bool loop = false;
		for (int i = 0; i < 2; i++) {
			int h = current.first + dh[i], w = current.second + dw[i];
			if (h >= H || w >= W) continue;
			if (find(passed.begin(), passed.end(), Pos(h, w)) != passed.end()) continue;
			if (A[h][w] == '#') {
				loop = true;
				current = Pos(h, w);
				passed.push_back(current);
				break;
			}
		}
		if (!loop) break;
	}
	size_t hash_cnt = 0;
	for (string S : A) for (char c : S) if (c == '#') hash_cnt++;
	return (passed.size() == hash_cnt);
}
int main() {
	cout << (solve() ? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  int a, b;
  map<pair<int, int>, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    for (int j = 0; j <= 2; j++) {
      if (a-j <= 0 || a-j > h-2) continue;
      for (int k = 0; k <= 2; k++) {
        if (b-k <= 0 || b-k > w-2) continue;
        pair<int, int> p = make_pair(a-j, b-k);
        m[p]++;
      }
    }
  }

  long long ans[10] = {};
  ans[0] = 1LL * (h-2) * (w-2) - m.size();
  for (auto i = m.begin(); i != m.end(); i++)
    ans[i->second]++;
  for (int i = 0; i < 10; i++)
    cout << ans[i] << endl;
}

Measured memory_bytes: 56448
#include <iostream>

int main() {
    std::string s, t;
    std::cin >> s >> t;
    s = s + s + s;
    int tPos = s.find(t);
    if (tPos == std::string::npos) {
        std::cout << "No" << std::endl;
    } else {
        std::cout << "Yes" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;

int card[4][13]={};
for(int i=0;i<n;i++){
string suit;
int num;
cin>>suit>>num;

if(suit == "S") card[0][num-1] =1;
if(suit == "H") card[1][num-1] =1;
if(suit == "C") card[2][num-1] =1;
if(suit == "D") card[3][num-1] =1;
}
string str[4] = {"S","H","C","D"};
for(int i=0;i<4;i++){
for(int j=0;j<13;j++){
if(card[i][j] == 1) continue;
cout<<str[i]<<" "<<j+1<<endl;
}
}
return 0;
}


Measured memory_bytes: 3144
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def pim():
    print("Impossible")
    sys.exit()
def pp():
    print("Possible")
    sys.exit()
def solve():
    n = getN()
    nums = getList()
    cnt = Counter(nums)
    mx = max(nums)
    mn = min(nums)

    if cnt[mx] < 2:
        pim()
    if mn < (mx + 1) // 2:
        pim()

    if mx % 2 == 0:
        if cnt[mx//2] != 1:
            pim()
    else:
        if cnt[(mx+1) // 2] != 2:
            pim()

    for i in range((mx + 1) // 2 + 1, mx+1):
        if cnt[i] < 2:
            pim()

    pp()


def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()







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

int main(){
    int n,m;
    int a[100], b[100];

    while(cin>>n>>m, n&&m){
        int aSum=0, bSum=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            aSum+=a[i];
        }
        for(int i=0;i<m;i++){
            cin>>b[i];
            bSum+=b[i];
        }
        bool flag=false;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(aSum-a[i]+b[j] == bSum-b[j]+a[i]){
                    flag=true;
                    printf("%d %d\n",a[i],b[j]);
                    break;
                }
            }
            if(flag) break;
        }

        if(flag==false) cout<<"-1"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3108
n = int(input())
tl = list(map(int, input().split()))
al = list(map(int, input().split()))

if tl[-1] != al[0]:
    print(0)
    exit()

ans = 1
for i in range(1,n-1):
    if tl[i] > tl[i-1] or al[i] > al[i+1]:
        ans *= 1
    else:
        ans *= min(tl[i],al[i])

    if tl[i] > tl[i-1] and tl[i] > al[i]:
        print(0)
        exit()
    elif al[i] > al[i+1] and al[i] > tl[i]:
        print(0)
        exit()
    ans%=(10**9+7)

print(ans)

Measured memory_bytes: 97428
using System.Linq;
using static System.Console;

namespace For_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());
            int sa = ReadLine().Split(' ').Select(int.Parse).OrderByDescending(n => n).Select((w, n) => w * (1 - 2 * (n % 2))).Sum();
            
            WriteLine(sa);
        }
    }
}

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

int main(){
    ll a,b,c,d,q,w,e,r;
    cin >> a >> b >> c >> d;
    vector<ll> p(4);
    p[0] = a*d;
    p[1] = a*c;
    p[2] = b*c;
    p[3] = b*d;
    sort(p.begin(), p.end());
    cout << p[3] << endl;
 }

Measured memory_bytes: 3620
#include <iostream>
#include <math.h>

using namespace std;

int main(void)
{
    long N, a, Nd[2], i;

    cin >> N;

    a = sqrt(N);

    for(i=a; i>=1; i--){
        if(N % i == 0){
            Nd[0] = N / i;
            Nd[1] = i;
            break;
        }
    }

    cout << Nd[0]+Nd[1]-2 << endl;

    return 0;
}

Measured memory_bytes: 256
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double; 
const string FILENAME = "input";
const int MAXN = 1028;



int n, k;
int a[MAXN];
int pl[MAXN], pr[MAXN], p[MAXN];
bool bl[MAXN];


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
 	cin >> k;
 	int mx = 0;
 	for (int i = 1; i <= k; i++) {
 		cin >> a[i];
 		n += a[i];
 		pl[i] = k, pr[i] = i;
 		chkmax(mx, a[i]);
 	}
 	for (int i = 1; i <= k; i++) {
 		if (a[i] * 2 < mx) {
 			cout << -1 << endl;
 			return 0;
 		}
 	}
 	int mm = 0, mk = 0;
 	for (int i = 1; i <= n; i++) {
 		int j = 1;
 		for (; j <= k; j++) {
 			if (bl[j]) {
 				continue;
 			}
 			bool bb = 1;
 			mx = 0;
 			for (int is = 1; is <= k; is++) {
 				chkmax(mx, a[is]);
 			}
 			for (int is = 1; is <= pl[j]; is++) {
 				if (!bl[pr[is]]) {
 					a[pr[is]]--;
 				}
 			}
 			for (int is = 1; is <= k; is++) {
 				if (a[is] * 2 + 2 < mx) {
 					bb = 0;
 					break;
 				}
 			}
 			if (a[j] * 2 + 1 < mx) {
 				bb = 0;
 			}
 			for (int is = 1; is <= pl[j]; is++) {
 				if (!bl[pr[is]]) {
 					a[pr[is]]++;
 				}
 			}
 			if (bb) {
 				break;
 			}
 		}
 		bl[j] = 1;
 		p[i] = j;
 		a[j]--;
 		mm++;
 		chkmax(mk, pl[j]);
 		if (i >= k && (i == k || mm == mk)) {
 			for (int j = 1; j <= k; j++) {
 				bl[j] = 0;
 				pl[p[i - k + j]] = j;
 				pr[j] = p[i - k + j];
 			}
 			mm = 0;
 			mk = 0;
 		}
 	}
 	for (int i = 1; i <= n; i++) {
 		cout << p[i] << ' ';
 	}
 	cout << '\n';
	return 0;	 	
}


Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

map<string, int> mp;

int main() {
    bool ans=true;
    string s;
    cin >> s;
    int c[26] = {};
    int n = 26;
    rep(i, s.size()) {
        c[s[i] - 97]++;
    }
    rep(i, n) {
        if (c[i] % 2 == 1) {
            ans = false;
        }
    }
    if (ans==true) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 768
import java.awt.Point;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int N = sc.nextInt();
		char [][]c = new char[H][W];
		Queue<Point> queue = new ArrayDeque<Point>();
		for(int i = 0; i < H; i++) {
			String s = sc.next();
			for(int j = 0; j < W; j++) {
				c[i][j] = s.charAt(j);
				if(c[i][j] == 'S') {
					queue.add(new Point(j, i));
				}
			}
		}
		sc.close();
		int sum = 0;
		int []dx = {1, -1, 0, 0};
		int []dy = {0, 0, 1, -1};
		for(int i = 1; i <= N; i++) {
			int [][]color = new int[H][W];
			int [][]d = new int[H][W];
			Point p = queue.peek();
			color[p.y][p.x] = 1;
			while(true) {
				Point t = queue.poll();
				if(c[t.y][t.x] == (char)(i + '0')) {
					queue.clear();
					queue.add(t);
					sum += d[t.y][t.x];
					break;
				}
				for(int j = 0; j < 4; j++) {
					int nx = t.x + dx[j];
					int ny = t.y + dy[j];
					if(nx >= 0 && nx < W && ny >= 0 && ny < H) {
						if(color[ny][nx] == 0 && c[ny][nx] != 'X') {
							color[ny][nx] = 1;
							d[ny][nx] = d[t.y][t.x] + 1;
							queue.add(new Point(nx, ny));
						}
					}
				}
			}
		}
		System.out.println(sum);
	}
}


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

using namespace std;


int main() {
	int a,b,c;
	cin >> a >> b >> c;
	int five_count = 0;
	int seven_count = 0;
	for (int x : vector<int>{ a,b,c })
		if (x == 5)
			five_count++;
		else if (x == 7)
			seven_count++;
	cout<<(five_count == 2 && seven_count == 1 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define ll int64_t
const long MOD = 1e9 + 7;

vector<vector<int>> v;
vector<bool> d;
int ans=0;

void dfs(int p){
  d[p]=true;
  bool isallreached=true;
  for (int i = 0; i < d.size(); ++i){
    if (d[i]==false)isallreached=false;
  }
  if (isallreached){
    ans++;
    d[p]=false;
    return;
  }

  for (int i = 0; i < v[p].size(); ++i)
  {
    if (d[v[p][i]] ==false)dfs(v[p][i]);
  }


  d[p]=false;

}

int main()
{
  int n,m;
  cin  >> n >> m;
  v = vector<vector<int>>(n,vector<int>());//頂点aの接続先頂点リスト
  d = vector<bool>(n,false);

  for (int i = 0; i < m; ++i)
  {
    int a,b;
    cin >>a >> b;
    v[a-1].push_back(b-1);
    v[b-1].push_back(a-1);
  }

  dfs(0);


  cout << ans << endl;

  return 0;
}


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

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int H, W;
string S[12];

vector<vector<pair<int, int>>> cand;
vector<pair<int, int>> now;

void rec(int b){
    if(b == (1<<H)-1){
        cand.push_back(now);
        return;
    }

    vector<int> avail;
    for(int i=0; i<H; i++) if(!nth_bit(b, i)) avail.push_back(i);
    int sz = avail.size();
    int f = avail[0];
    if(sz%2){
        now.emplace_back(f, f);
        rec(b+(1<<f));
        now.pop_back();
    }
    for(int i=1; i<sz; i++){
        int g = avail[i];
        now.emplace_back(f, g);
        rec(b+(1<<f)+(1<<g));
        now.pop_back();
    }
}

int main(){
    cin >> H >> W;
    for(int i=0; i<H; i++) cin >> S[i];
    rec(0);
    for(auto& v : cand){
        int sz = v.size();
        vector<int> order;
        for(int i=0; i<sz; i++) order.push_back(v[i].first);
        for(int i=sz-1; i>=0; i--) order.push_back(v[i].second);

        multiset<string> st;
        for(int j=0; j<W; j++){
            string s;
            for(int i : order) s.push_back(S[i][j]);
            st.insert(s);
        }

        bool one_done = false, success = true;
        while(st.size() && success){
            auto it = st.begin();
            string s = *it, sr = *it;
            st.erase(it);
            reverse(sr.begin(), sr.end());
            auto it2 = st.find(sr);
            if(it2 != st.end()){
                st.erase(it2);
            }else if(!one_done && s == sr){
                one_done = true;
            }else{
                success = false;
            }
        }
        if(success){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 1152
import sys
n,*p = map(int,sys.stdin.read().split())
dist = [min(a,n-1-a,b,n-1-b) for a in range(n) for b in range(n)]

def update(v,nv):
    if dist[nv] > dist[v] + iru[v]:
        q.append(nv)
        dist[nv] = dist[v] + iru[v]

ans = 0
iru = [1]*n*n
for pi in p:
    pi -= 1
    ans += dist[pi]
    iru[pi] = 0
    q = [pi]
    while q:
        v = q.pop()
        if v%n != n-1: update(v,v+1)
        if v%n: update(v,v-1)
        if v >= n: update(v,v-n)
        if v+n < n*n: update(v,v+n)
print(ans)

Measured memory_bytes: 148520
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int count = 0;
    	for (int i = 1; i < N+1; i++) {
    		String bi = Integer.toString(sc.nextInt(), 2);
    		for (int j = bi.length()-1; 0 < j; j--) {
    			if (bi.charAt(j) == '0') {
    				count++;
    			} else {
    				break;
    			}
    		}
    	}
    	System.out.println(count);
    }
}

Measured memory_bytes: 36692
str = gets.split
L,R = str[0].to_i, str[1].to_i

if R-L >= 2018
    puts 0
    exit
elsif L > R
    puts 0
    exit
elsif L == 0
    puts 0
    exit
end

answer = 2019
for x in L...R do
    for y in x+1..R do
        if (x*y)%2019 < answer
            answer = (x*y)%2019
        end
    end
end

puts answer

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

int main(){
  int N, X, M;
  cin >> N >> M >> X;
  vector<int> A(M);
  
  for(int i = 0; i < M; i++){
    cin >> A[i];
  }
  int ans1 = 0;
  int ans2 = 0;

  for(int i = X; i <= N; i++){
    for(int j = 0; j < M; j++){
      if(A[j] == i) ans1++;
    }
  }
  for(int i = X; i >= 0; i--){
    for(int j = 0; j < M; j++){
      if(A[j] == i) ans2++;
    }
  }

  if(ans1 > ans2) cout << ans2;
  else cout << ans1;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<double>x(n);
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        double y;
        cin>>y;
        x[i]=abs(x[i]-y);
    }
    double s1=0,s2=0,s3=0,sinf=0;
    for(int i=0;i<n;i++){
        s1+=x[i];
        s2+=x[i]*x[i];
        s3+=x[i]*x[i]*x[i];
        sinf=max(sinf,x[i]);
    }
    s2=sqrt(s2);
    s3=cbrt(s3);
    cout<<fixed<<setprecision(10);
    cout<<s1<<endl<<s2<<endl<<s3<<endl<<sinf<<endl;
      
}


Measured memory_bytes: 3408
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long int N, H, a, b;
    long int atop = -1;
    cin >> N >> H;
    long int B[N];
    for (int i = 0; i < N; i++)
    {
        cin >> a >> b;
        atop = max(atop, a);
        B[i] = b;
    }
    sort(B, N+B, greater<int>() ); // なぞ処理
    long int ans = ceil((double)H / (double)atop);
    long int cnt = 0;
    double tmp, c;
    for (int i = 0; i < N; i++)
    {
        H -= B[i];
        cnt++;
        c = ceil((double)H / (double)atop);
        tmp = max(0.0, c);
        ans = min(ans, cnt + (long int)tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
	A := nextInt()
	B := nextInt()
	M := nextInt()
	a := make([]int, A)
	b := make([]int, B)
	for i := 0; i < A; i++ {
		a[i] = nextInt()
	}
	for i := 0; i < B; i++ {
		b[i] = nextInt()
	}
	ans := math.MaxInt64
	for i := 0; i < M; i++ {
		x := nextInt()
		y := nextInt()
		c := nextInt()
		ans = min(ans, a[x-1]+b[y-1]-c)
	}
	ans = min(ans, min(a...)+min(b...))
	fmt.Println(ans)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 4736
//Utkarsh-raj

#include<bits/stdc++.h>

#define ll long long int
#define vc vector
#define mod 100000000007
#define mp make_pair
#define pb push_back
#define nl cout<<endl;
#define ff first
#define ss second

using namespace std;

// void f(int i, double prob[], int head, double p, double &ans, int n){
//     if(i == n){
//         if(head > n - head){
//             ans += p;
//         }
//         return;
//     }

//     f(i+1, prob, head + 1, p*prob[i], ans, n);
//     f(i+1, prob, head, p*(1 - prob[i]), ans, n);
// }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

    int n;
    cin>>n;

    vector<vector<double> > dp(n+1, vector<double> (n+1, 0));
    dp[0][0] = 1.0;

    double prob[n+1];

    for(int i=1; i<=n; i++){
        cin>>prob[i];
    }

    for(int i=1; i<=n; i++){
        dp[i][0] = dp[i-1][0]*(1 - prob[i]);

        for(int j=1; j<=n; j++){
            dp[i][j] = dp[i-1][j-1]*prob[i] + dp[i-1][j]*(1 - prob[i]);
        }
    }

    double ans = 0;
    for(int j=n/2 + 1; j <= n; j++){
        ans += dp[n][j];
    }
    cout<<setprecision(10)<<ans<<endl;

    return 0;
}


Measured memory_bytes: 73672
from collections import Counter

n = int(input())
L = list(input().split())
L0 = []
L1 = []
ans = 0

for i in range(0, n, 2):
    L0.append(L[i])
    L1.append(L[i + 1])
    
C0 = Counter(L0).most_common()
C1 = Counter(L1).most_common()

if C0[0][0] != C1[0][0]:
    ans = n  - C0[0][1] - C1[0][1]
else:
    if len(C0) == 1 and len(C1) == 1:
        ans = n // 2
    elif len(C0) == 1 and len(C1) != 1:
        ans = n // 2 - C1[1][1]
    elif len(C0) != 1 and len(C1) == 1:
        ans = n // 2 - C0[1][1]
    else:
        a = n - C0[0][1] - C1[1][1]
        b = n  - C0[1][1] - C1[0][1]
        ans = min(a, b)

print(ans)

Measured memory_bytes: 23516
#include <bits/stdc++.h>
#define LL long long
#define INF 0x7FFFFFFF//or 0x3f3f3f3f ? -Wall
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 200000 + 5;

int n;
LL ans;
int a[N];
int g[N][20];

void pre() {
	for (int i = 1; i <= n; i++) g[i][0] = i;
	for (int j = 1; (1 << j) <= n; j++) {
		for (int i = 1; i + (1 << j) - 1 <= n; i++)
			if (a[g[i][j - 1]] < a[g[i + (1 << (j - 1))][j - 1]]) g[i][j] = g[i][j - 1];
			else g[i][j] = g[i + (1 << (j - 1))][j - 1];
	}
}

int getg(int l, int r) {
	int k = (int)log2(r - l + 1 + 0.5);
	return a[g[l][k]] < a[g[r - (1 << k) + 1][k]] ? g[l][k] : g[r - (1 << k) + 1][k];
}

void solve(int l, int r) {
	if (l > r) return;
	int pos = getg(l, r);
	ans += 1LL * a[pos] * (pos - l + 1) * (r - pos + 1);
	solve(l, pos - 1);
	solve(pos + 1, r);
}

int main() {
	read(n);
	for (int i = 1; i <= n; i++) read(a[i]);
	pre();
	solve(1, n);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 22912
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
typedef long long int ll;
ll a, b, x;

ll f() {
     ll first = a%x == 0 ? a : a + (x - a%x);
     ll last = b%x == 0 ? b: b - b%x;
     return (last - first)/x + 1;
}
int main() {

    cin >> a >> b >> x;
    cout << f() << endl;

    return 0;
}


Measured memory_bytes: 256
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let fold_left f init str =
  let acc = ref init in
  for i = 0 to String.length str - 1 do
    acc := f !acc str.[i];
  done;
  !acc

let () =
  let to_x = Array.make 128 (-1) in
  to_x.(Char.code 'A') <- 0;
  to_x.(Char.code 'C') <- 1;
  to_x.(Char.code 'G') <- 2;
  to_x.(Char.code 'T') <- 3;
  let set = Array.make 9999973 false in
  let hash s = fold_left (fun acc c -> 4*acc + to_x.(Char.code c)) 1 s in
  let n = read_int () in
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["find"; s] -> print_endline (if set.(hash s) then "yes" else "no")
    | [_; s] -> set.(hash s) <- true
    | _ -> assert false
  done

Measured memory_bytes: 83420
/*  ex4_3
    Rikuta  */

#include <stdio.h>

//プロトタイプ宣言
int snow_height(int west_remain_height,int east_remain_height);

int main(void){

    int west_remain_height,east_remain_height;

    //入力受け取り
    scanf("%d %d",&west_remain_height,&east_remain_height);

    //snow_height関数に入れて計算
    int ans =snow_height(west_remain_height,east_remain_height);

    //答えの出力
    printf("%d\n",ans);

    return 0;
}

//関数の定義
int snow_height(int west_remain_height,int east_remain_height){
    //snow_heightの計算
    int snow_height=(east_remain_height-west_remain_height-1)*(east_remain_height-west_remain_height)/2-west_remain_height;

    //snow_heightを返す
    return snow_height;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdint>

using namespace std;

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

	int_least32_t temp, min{ 100 }, sum{ 0 };
	for(;n > 0; --n) {
		cin >> temp;
		sum += temp;
		if(temp < min && temp % 10 != 0) {
			min = temp;
		}
	}
	
	if(sum % 10 == 0 && min != 100) {
		cout << sum - min << endl;
	}
	else if(min == 100) {
		cout << 0 << endl;
	}
	else {
		cout << sum << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

int main() {
#ifdef LOCAL
  freopen("b.in", "r", stdin);
  freopen("b.out", "w", stdout);
#endif

  int n;
  while (scanf("%d", &n) == 1) {
    vector<pair<int, int>> ans;
    int bad = n;
    if (n % 2 == 0) bad++;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (i + j != bad) {
          ans.emplace_back(i, j);
        }
      }
    }
    printf("%d\n", (int)ans.size());
    for (auto x : ans) {
      printf("%d %d\n", x.first, x.second);
    }
  }


  return 0;
}


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

int main(){
    string s;
    cin >> s;
    int n=(int)(s.length());
    string res;
    for(int i=0;i<n;i++){
        if(2*i >= n)break;
        res+=s[2*i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
x, y, a, b, c = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)[:x]
Q = sorted(list(map(int, input().split())), reverse=True)[:y]
R = sorted(list(map(int, input().split())), reverse=True)
PQL = sorted(P+Q+R, reverse=True)
ans = sum(PQL[:x+y])
print(ans)


Measured memory_bytes: 22504
#include<bits/stdc++.h>
using namespace std;
int T[105];
int sum={0};
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>T[i];
        sum+=T[i];
    }
    int m;
    cin>>m;
    for(int i=1;i<=m;i++)
    {
        int p,x;
        cin>>p>>x;
        cout<<sum-T[p]+x<<endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll H,W;
    cin >> H >> W;
    if (H % 3 == 0 || W % 3 == 0){
        cout << 0 << endl;
    }
    else{
        ll ans = min(H,W);
        for(ll i = 1; i <= H - 1; i++){
            ll p1 = i * W;
            if (W % 2 == 0){
                ll p2 = (H - i) * W / 2;
                ans = min(ans, max(p1 - p2, p2 - p1));
            }
            else{
                ll p2 = (H - i) * (W / 2);
                ll p3 = (H - i) * W - p2;
                ll s_max = max(p1,max(p2,p3));
                ll s_min = min(p1,min(p2,p3));
                ans = min(ans, s_max - s_min);
                
            }
        }
        for(ll i = 1; i <= W - 1; i++){
            ll p4 = i * H;
            if (H % 2 == 0){
                ll p5 = (W - i) * H / 2;
                ans = min(ans, max(p4 - p5, p5 - p4));
            }
            else{
                ll p5 = (W - i) * (H / 2);
                ll p6 = (W - i) * H - p5;
                ll s_max = max(p4,max(p5,p6));
                ll s_min = min(p4,min(p5,p6));
                ans = min(ans, s_max - s_min);
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;
typedef vector<long long int> vi;
typedef vector<long long int>::iterator vit;

int main(){
	int n, k;
	vector<int> vi, vi2;
	while (cin >> n)
	{
		if (n == 0){
			vi.pop_back();
			vi2.push_back(k);
		}
		else {
			vi.push_back(n);
		}
		k = vi[vi.size() - 1];
	}
	REP(i, vi2.size()){
		cout << vi2[i] << endl;
	}
}

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	long long a, b = 0;
	cin >> a;
	b = (a / 500) * 1000;
	a %= 500;
	b += (a / 5) * 5;
	cout << b;

	return 0;
}



Measured memory_bytes: 256
n = int(input())

out = [input()]
f = 0
for i in range(n-1):
  in_str = input()
  if in_str[0] != out[-1][-1]:
    f = 1
    break
  if in_str in out :
    f = 1
    break
  out.append(in_str)

if f == 1:
  print('No')
else :
  print('Yes')
    
  

Measured memory_bytes: 3060