akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

string a, b;
int main() {
	getline(cin, a);
	getline(cin, b);
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	reverse(b.begin(), b.end());
	if (a < b) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;


int flag[MAXN];
int num[MAXN];
int main() {

    int n, m;

    for(int i=1; i<MAXN; i*=2) {
        for(int j=i; j<MAXN; j*=3) {
            for(int k=j; k<MAXN; k*=5) {
                flag[k] = 1;
            }
        }
    }

    for(int i=1; i<MAXN; ++i) {
        num[i]=num[i-1]+flag[i];
    }

    while(cin >> m >> n, m) { // if (m>0)
        cout << num[n]-num[m-1] << endl;
    }
}




Measured memory_bytes: 8028
from math import isinf


class WarshallFloyd(object):

    def __init__(self, adj):
        """
        ワーシャル・フロイド法によって全頂点間の最短距離を O(|V|^3) で計算する。

        :param adj: 隣接行列 adj[i][j] でi番目の頂点からj番目の頂点へのコストを示す パスがなければINF
        """
        self._dist = adj  # 各頂点間の最短距離 初期値として隣接行列をそのまま用い、[i, i]要素を0に初期化する
        for i in range(len(adj)):
            self._dist[i][i] = 0

        self._solve()

    def _solve(self):
        v_len = len(self._dist)
        for i in range(v_len):  # 経由する頂点
            for j in range(v_len):  # 開始頂点
                for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

    def distance(self, start, goal):
        return self._dist[start][goal]

    def path(self, start, goal):
        pass


N, M, L = map(int, input().split())
adj = [[float('inf') for _ in range(N)] for _ in range(N)]
for A, B, C in [tuple(map(int, input().split())) for _ in range(M)]:
    adj[A - 1][B - 1] = C
    adj[B - 1][A - 1] = C

wf = WarshallFloyd(adj)

adj2 = [[float('inf') for _ in range(N)] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if wf.distance(i, j) <= L:
            adj2[i][j] = 1
wf2 = WarshallFloyd(adj2)

Q = int(input())
for s, t in [tuple(map(int, input().split())) for _ in range(Q)]:
    ans = wf2.distance(s - 1, t - 1) - 1
    if isinf(ans):
        print(-1)
    else:
        print(ans)


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll E[300005];
ll W[300005];

int main() {
    ll N;
    string S;
    cin >> N >> S;
    memset(E, 0, sizeof(E));
    memset(W, 0, sizeof(W));
    REP(i, N) {
        E[i + 1] += E[i];
        W[i + 1] += W[i];
        if (S[i] == 'E')
            E[i + 1]++;
        else
            W[i + 1]++;
    }

    ll min = INF;
    REP(i, N) {
        min = std::min(min, W[i] + (E[N] - E[i + 1]));
    }
    cout << min << endl;

    return 0;
}

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

    int x;
    while(cin>>x,x!=-1){
        if(x==0)cout<<"0"<<endl;
        else{
            string s="";
            for(int i=0;x>=1;i++){
                s+=x%4+'0';
                x/=4;
            }
            for(int i=s.size()-1;i>=0;i--){
                cout<<s[i];
            }
            cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
#include<stdlib.h>

#define MAX 500000

int n, s[MAX+1];
int count = 0;

void mergeSort(int, int);
void merge(int, int, int);

int main()
{
  int i;
  
  scanf("%d", &n);
    for( i = 0; i < n; i++)
      {
	scanf("%d", &s[i]);
      }

    mergeSort(0,n);
   
   for( i = 0; i < n-1; i++)
      {
	printf("%d ", s[i]);
      }
   printf("%d\n", s[i]);
   printf("%d\n", count);
   
  return 0;
}

void merge(int left,int mid, int right)
{
  int *l, *r;
  int n1, n2, i, j, k;
  int inf=1000000000;
  n1 = mid-left;
  n2 = right-mid;

  l = malloc(sizeof(int)*(n1+1));
  r = malloc(sizeof(int)*(n2+1));

  for(i = 0; i < n1; i++)
    {
      l[i] = s[left+i];
    }
  l[n1] = inf;
  for( i = 0; i < n2; i++)
    {
      r[i] = s[mid+i];
    }
  r[n2] = inf;


  /*
  printf("l:");
 for(i = 0; i <= n1; i++)
    {
      printf("%d ", l[i]);
    }
 printf("r:");
for( i = 0; i <= n2; i++)
    {
     printf("%d ", r[i]);
    }

 printf("\n");
  */

 
  i = 0;
  j = 0;
  
  for(k = left; k < right;k++)
    {
      if(l[i] <= r[j])
	{
	  s[k] = l[i];
	  i++;
	}
      else
	{
	  s[k] = r[j];
	  j++;
	}
      count++;
    }
  return;
}

void mergeSort(int left, int right)
{
  int mid;

   if(left+1 < right)
    {
      mid = (right+left) / 2;
      mergeSort(left, mid);
      mergeSort(mid, right);
      merge(left,mid,right);
    }
   return;
}



Measured memory_bytes: 64452
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  int p = 0;
  int w = 0;
  int g = 0;
  int y = 0;
  
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    
    if (s == "P" && p == 0) {
      p++;
    }
    if (s == "W" && w == 0) {
      w++;
    }
    if (s == "G" && g == 0) {
      g++;
    }
    if (s == "Y" && y == 0) {
      y++;
    }
    
    int total = p + w + g + y;
    if (total >= 4) {
      cout << "Four" << endl;
      return 0;
    } else if (total >= 3 && n == (i + 1)) {
      cout << "Three" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
using i64 = int64_t;
using namespace std;
int main() {
    int N;
    cin >> N;
    i64 last = 0;
    bool flag = true;
    vector<i64> H(N);
    for(int i = 0; i < N; i++) cin >> H[i];
    for(int i = 1; i < N - 1; i++) {
        if (H[i - 1] <= H[i] - 1 && H[i] - 1 <= H[i + 1]) {
            H[i]--;
            continue;
        } else if (H[i - 1] <= H[i] && H[i] <= H[i + 1]) {
            continue;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    if(N == 2) {
        if(H[0] - 1 > H[1]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
    int a[3];
    int low=101,total_cost=0,s1=0,s2=0;
    for (int i=0;i<3;i++)
    {
        scanf("%d",&a[i]);
        if (a[i]<low){
            low=a[i];
            s1=i;
        }
    }
    a[s1]=101;
    int low2=101;
    for (int i=0;i<3;i++)
    {
        if (a[i]<low2){
            low2=a[i];
            s2=i;
        }
    }
    total_cost=low2-low;
    for (int i=0;i<3;i++)
    {
        if (i!=s1 && i!=s2)
            total_cost=total_cost+(a[i]-low2);
    }
    printf("%d",total_cost);

    return 0;
}


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

int main()
{
  int h,m,s, Sec;

  cin >> Sec;   // 秒数

  s= Sec % 60;  // 秒
  Sec /= 60;    // 分単位に・・・
  m= Sec % 60;  // 分
  h = Sec / 60; // 時

  cout << h << ":"<< m << ":" << s << endl;

  return 0;
}


Measured memory_bytes: 3092
/*
 © 2020-09-13 21:16:02 Franco1010 All Rights Reserved
*/

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;
const lli MOD = 1e9 + 7;
const lli N = 2e3 + 5;
lli fac[N];
lli fpow(lli x, lli y){
  lli res = 1;
  while(y > 0){
    if(y & 1) res = res * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return (res + MOD) % MOD;
}
lli dp[N];
lli solve(lli res){
  if(res == 0) return 1;
  lli &ans = dp[res];
  if(ans == -1){
    ans = 0;
    fore(i, 3, res+1){
      ans = (ans + solve(res - i) + MOD) % MOD;
    }
    ans = (ans + MOD) % MOD;
  }
  return ans;
}
int main(){ _
  fore(i, 0, N) dp[i] = -1;
  lli n; cin >> n;
  if(n < 3){
    cout << 0 << ENDL;
    return 0;
  }
  lli res = solve(n);
  res = (res + MOD) % MOD;
  cout << res << ENDL;
  return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;

	int weigh, all = 0, sugar = 0;
	double dens;
	double mx = 0.0;
	REP(i, 0, 31) {
		REP(j, 0, 31) {
			REP(k, 0, 301) {
				REP(l, 0, 301) {
					int a = 100 * (A*i + B*j);
					int b = C*k + D*l;

					if (a == 0) continue;
					weigh = a + b;
					dens = 100.0 * 100.0 * b / (a + b);
					
					if (weigh > F || E*(A*i + B*j) < b) continue;
					if (dens >= mx) {
						all = weigh;
						sugar = b;
						mx = dens;
					}
				}
			}
		}
	}

	cout << all << " " << sugar << endl;
	return 0;
}

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

public class Main{
static public void main(String args[]){
Scanner scan=new Scanner(System.in);
Calculate calc = new Calculate(scan.nextInt(),
								scan.nextInt());
	calc.show();
}
}

class Calculate{
	int a;
	int b;
  Calculate(int x, int y) {
  	a=x;
	b=y;
  }
	public void show(){
	System.out.printf("%d %d %.6f", a/b, a%b, (double)a/b);
}

}

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

int main() {
  int N;
  int dan = 0;

  cin >> N;
  int a[N];

  for(int i = 0; i < N; i++){
    cin >> a[i];

    for(int j = 0; j < i; j++){
      if(a[i] > a[j]){
        int temp = a[j];
        a[j] = a[i];
        a[i] = temp;
      }
      else if (a[i] == a[j]){
        a[i] = 0;
      }
    }
  }

  for(int i = 0; i < N; i++){
    if(a[i] != 0){
      dan++;
    }
  }

  cout << dan << endl;

  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			solveA();
			//			 solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int a = nextInt();
		int b = nextInt();

		if (a <= 5) {
			out.println(0);
		} else if (a <= 12) {
			out.println(b / 2);
		} else {
			out.println(b);
		}
	}

	private void solveB() {
		int n = nextInt();

		out.println("");
	}

	private void solveC() {
		int n = nextInt();

		out.println("");
	}

	private void solveD() {
		int n = nextInt();

		out.println("");
	}

	private void solveE() {
		int n = nextInt();

		out.println("");
	}

	private void solveF() {
		int n = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 21204
#include <stdio.h>
#include <stdlib.h>
void selectionSortAndShow(int*,int);
int main(){
    int i,N,*array;
scanf("%d",&N);
array=(int *)malloc(N*sizeof(int));
for(i=0;i<N;i++){
scanf("%d",&array[i]);
}
selectionSortAndShow(array,N);
return 0;
}

void selectionSortAndShow(int *array,int N){
    int i,j,min,s,temp,count=0;

    for(i=0;i<N-1;i++){
        s=i;
        for(j=i+1;j<N;j++){
	  if(array[j]<array[s]){
               s=j;    
            }
        }
	if(array[i]!=array[s]){ 
          temp=array[i];
          array[i]=array[s];
          array[s]=temp;
          count++;
	}
      
    }
    for(i=0;i<N-1;i++){
        printf("%d ",array[i]);
    }
    printf("%d",array[N-1]);
    printf("\n");
     printf("%d\n",count);

}



Measured memory_bytes: 2140
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)
b = gets.strip.split.map(&:to_i)

result = 0
remain = 0
n.times do |index|
  current_a = a[index]
  current_b = b[index]

  assist = [remain, current_a].min
  result += assist

  current_a = current_a - assist

  if current_b > current_a
    result += current_a
    remain = current_b - current_a
  else
    result += current_b
    remain = 0
  end
end
last_assist = [remain, a.last].min
result += last_assist

p result



Measured memory_bytes: 21772
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

int main(){
  int N;
  std::cin >> N;
  std::vector<int> primeList{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  std::vector<int> numPrime(primeList.size(), 0);
  std::map<int, int> nokori;
  bool isFinish;
  for(int i = 2; i < N + 1; i++){
    int temp = i;
    for(int j = 0; j < primeList.size(); j++){
      isFinish = false;
      while(true){
        if(temp % primeList.at(j) == 0){
          temp = temp / primeList.at(j);
          numPrime.at(j)++;
        }else if(temp == 1){
          isFinish = true;
          break;
        }else break;
      }
      if(isFinish) break;
      if(j == primeList.size() - 1 && temp != 1){
        auto itr = nokori.find(temp);
        if(itr != nokori.end()) nokori[temp]++;
        else nokori[temp] = 1;
      }
    }//j
  }//i
  long ans = 1;
  for(int i = 0; i < primeList.size(); i++){
    ans = (ans * (numPrime.at(i) + 1)) % 1000000007;
  }
  for(int i = 0; i < nokori.size(); i++){
    ans = (ans * (nokori[i] + 1)) % 1000000007;
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define rep(i,n) for(int64_t i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr int64_t INF=(1ll<<60);
constexpr int64_t mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll h,n;cin>>h>>n;
    ll sum=0;
    rep(i,n){
        ll a;cin>>a;
        sum+=a;
    }

    if(sum>=h){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    sort(btoe(p));
    vector<int> an(p[n-1]+5);
    rep(i,n){
        if(an[p[i]]<=1){
            for(int j=p[i]; j<=p[n-1]; j+=p[i]){
                an[j]++;
            }
        }
    }
    int ans=0;
    rep(i,n) if(an[p[i]]==1) ans++;
    cout<<ans<<endl;    
    return 0;
}

Measured memory_bytes: 7992
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long  double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	string s;
	cin >> s;
	vector<int>sum(N*2);
	for (int i = 0; i < N * 2; i++) {
		if (s[i] == 'a')sum[i]++;
		else sum[i]--;
		if (i)sum[i] += sum[i - 1];
	}
	vector<string>st;
	int bef = 0;
	for (int i = 0; i < N*2; i++) {
		string nx;
		if (sum[i] == 0) {
			if (s[bef] == 'a') {
				int anum = 0;
				int bnum = 0;
				int abef = -1;
				for (int j = bef; j <= i; j++) {
					if (s[j] == 'a') {
						anum++;
						if (bnum >= abef) {
							nx.push_back(s[j]);
							abef = anum;
						}
					}
					else {
						bnum++;
						if (bnum == abef) {
							nx.push_back(s[j]);
						}
					}
				}
			}
			else {
				int num = i - bef + 1;
				num >>= 1;
				for (int j = 0; j < num; j++) {
					int a = j, b = j;
					string box;
					for (int k = bef; k <= i; k++) {
						if (s[k] == 'a') {
							if (a)a--;
							else box.push_back('a');
						}
						else {
							if (b)b--;
							else box.push_back('b');
						}
					}
					nx = max(nx, box);
				}
			}
			st.push_back(nx);
			bef = i + 1;
		}
	}
	string ans;
	reverse(st.begin(), st.end());
	for (auto i : st) {
		ans = max(ans, i + ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h> 

int main() 

{ 

int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

 int n; 

scanf("%d",&n);

printf("%d\n",a[n-1]); 

return 0; 

}



Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 
   
int main(){
   ll n;
   cin >> n;
   vector<ll> a(n);
   rep(i,n){
      cin >> a.at(i);
   }
   ll sum=0;
   rep(i,n){
      sum+=a.at(i);
   }
   sum%=MM;
   ll ans=sum*sum;
   rep(i,n){
      ll x=a.at(i)*a.at(i);
      x%=MM;
      ans-=x;
      if(ans<0)ans+=MM;
   }
   ll b=(MM+1)/2;
   ans%=MM;
   ans*=b;
   ans%=MM;
   cout << ans << endl;
} 

Measured memory_bytes: 4828
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define vint vector<signed>
#define pint pair<signed,signed>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define isEven(t) t%2==0
#define debg(a) cout<<#a<<":"<<a<<endl;
signed main(){
  int n,k;
  cin>>n>>k;
  int a[n+1];
  rep(i,n)cin>>a[i];
  //if(n==k){cout<<abs(a[0]-a[n-1])<<endl;return 0;}
  a[n]=0;
  sort(a,a+n+1);
  int cent,left,right;
  rep(i,n+1)if(a[i]==0)cent=i;
  vint ans;
  rep(i,k+1){
    if(k-i>=cent){
      left=0;
    }
    else left=cent-(k-i);
    right=cent+k-(cent-left);
    if(right>n)break;
    int Lres=abs(a[left]-a[cent]);
    int Rres=abs(a[right]-a[cent]);
    int res=min((Lres*2+Rres),(Lres+Rres*2));
    ans.pb(res);
  }
  sort(all(ans));
  cout<<ans[0]<<endl;
  
  return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <map>
#include <string>
using namespace std;
int main(){
    long long N;
    cin >> N;
    vector<long long> cnt(5);
    for(int i = 0; i < N; i++){
        string S;
        cin >> S;
        if(S[0] == 'M') cnt[0]++;
        else if(S[0] == 'A') cnt[1]++;
        else if(S[0] == 'R') cnt[2]++;
        else if(S[0] == 'C') cnt[3]++;
        else if(S[0] == 'H') cnt[4]++;
    }
    long long ans = 0;
    for(int bit = 0; bit < (1 << 5); bit++){
        long long sum = 1;
        int cn = 0;
        for(int j = 0; j < 5; j++){
            if(bit & (1 << j)) {
                sum *= cnt[j];
                cn++;
            }
        }
        if(cn == 3) ans += sum;
    }
    cout << ans << endl;
}

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

struct UnionFindTree {
  std::vector<long> par;

  UnionFindTree(long N) : par(N) {
    for (long i=0; i<N; i++) {
      par[i] = i;
    }
  }

  long root(long x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }

  bool same(long x, long y) {
    return root(x) == root(y);
  }

  void unite(long x, long y) {
    long root_x = root(x);
    long root_y = root(y);
    if (root_x == root_y) return;
    par[root_x] = root_y;
  }
};

int main() {
  long N, M;

  std::cin >> N;
  std::cin >> M;

  std::vector<long> P(N);

  for (size_t i=0; i<N; i++) {
    long p;
    std::cin >> p;
    P[i] = p-1;
  }

  UnionFindTree tree(N);

  for (size_t i=0; i<M; i++) {
    long x, y;
    std::cin >> x;
    std::cin >> y;
    tree.unite(x-1, y-1);
  }

  long ans=0;

  for (size_t i=0; i<N; i++) {
    if (tree.same(P[i], i)) {
      ans++;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>

using namespace std;

#define INF 999999999

vector <string> a(52);
queue<pair <int, int> > q[2];
bool c[2][52][52];
int f[2];

void search(int x, int y, int z){
	pair<int, int> r;
	if(a[x][y] == '.')f[z]++;
	if(a[x+1][y]=='.'&&c[z][x+1][y]==0){
		c[z][x+1][y] = 1;
		r.first = x+1;
		r.second = y;
		q[z].push(r);
	}
	if(a[x-1][y]=='.'&&c[z][x-1][y]==0){
		c[z][x-1][y] = 1;
		r.first = x-1;
		r.second = y;
		q[z].push(r);
	}
	if(a[x][y-1]=='.'&&c[z][x][y-1]==0){
		c[z][x][y-1] = 1;
		r.first = x;
		r.second = y-1;
		q[z].push(r);
	}
	if(a[x][y+1]=='.'&&c[z][x][y+1]==0){
		c[z][x][y+1] = 1;
		r.first = x;
		r.second = y+1;
		q[z].push(r);
	}
	q[z].pop();
	if(!q[z].empty()) search(q[z].front().first, q[z].front().second, z);
}

int main(){
	int i, j, w, h;
	string s;
	pair<int, int> d;
	while(1){
		cin >> w >> h;
		if(!w)break;
		for(i=0;i<=h+1;i++){
			for(j=0;j<=w;j++){
				c[0][i][j] = 0;
				c[1][i][j] = 0;
				if(i==0||i==h+1) a[i] = "####################################################";
			}
		}
		for(i=1;i<=h;i++){
			cin >> s;
			a[i] = "#" + s + "#";
		}
		
		int common = 0;
		f[0]=0;
		f[1]=0;
		for(i=1;i<=h;i++){
			for(j=1;j<=w;j++){
				d.first = i;
				d.second = j;
				if(a[i][j]=='B'){
					c[0][i][j] = 1;
					q[0].push(d);
				}
				else if(a[i][j]=='W'){
					c[1][i][j] = 1;
					q[1].push(d);
				}
				else common++;
			}
		}
		if(q[0].empty() && q[1].empty()){
			cout << "0 0" << endl;
		}
		else{
			if(!q[0].empty()) search(q[0].front().first, q[0].front().second, 0);
			if(!q[1].empty()) search(q[1].front().first, q[1].front().second, 1);
			//cout << common << " " << f[0] << " " << f[1] << endl;
			cout << common-f[1] << " " << common-f[0] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1276
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

if sum(As)==0:
    print('Yes')
elif N%3!=0:
    print('No')
else:
    from collections import Counter
    d = N//3
    c = Counter(As)
    if len(set(As))>3:
        print('No')
    elif len(set(As))==3:
        items = list(set(As))
        a = 0
        for item in items:
            a ^= item
            if not c[item]==d:
                print('No')
                break
        else:
            if a!=0:
                print('No')
            else:
                print('Yes')
    else:
        if c[0]==d:
            print('Yes')
        else:
            print('No')

Measured memory_bytes: 104476
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int L, R, d;
    cin >> L >> R >> d;

    int ans = 0;
    for (int i = d; i <= R; i += d) {
        if (i >= L && i <= R) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3588
x1, y1, x2, y2 = map(int, input().split())

def rot90(vec):
    return [-vec[1], vec[0]]

vec12 = [x2-x1, y2-y1]
vec23 = rot90(vec12)
vec34 = rot90(vec23)
x3 = x2 + vec23[0]
y3 = y2 + vec23[1]
x4 = x3 + vec34[0]
y4 = y3 + vec34[1]

print(x3, y3, x4, y4)

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,cnt=0,ans=0; cin>>n;
    rep(i,n){
        int a; cin>>a;
        if(a==i+1) cnt++;
        else{
            ans+=(cnt+1)/2;
            cnt=0;
        }
    }
    cout<<ans+(cnt+1)/2<<endl;
}

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

int main() {
	int a[3], n = 0;
	cin>>a[0]>>a[1]>>a[2];

	while(a[0] != a[1] || a[1] != a[2]) {
		sort(a, a+3);
		while(a[1] < a[2]) {
			a[0]++;
			a[1]++;
			n++;
		}
		while(a[0] < a[1]) {
			a[0] += 2;
			n++;
		}
	}

	cout<<n<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main()
{
  int N, M, input, sum = 0;
  cin >> N >> M;
  for(int i=0;i<M;i++){
    cin >> input;
    sum += input;
  }
  if(N - sum < 0){
    cout << -1 << endl;
  }else{
    cout << N - sum << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
use std::cmp;

fn main() {
    let stdin = std::io::stdin();
    let mut sc = scanner::Scanner::new(stdin.lock());
    let n: usize = sc.read();
    let c: i64 = sc.read();
    let mut x: Vec<i64> = vec![0; n];
    let mut v: Vec<i64> = vec![0; n];
    for i in 0..n {
        x[i] = sc.read();
        v[i] = sc.read();
    }

    let mut right_sum = vec![0; n + 1];
    for i in 0..n {
        right_sum[i + 1] = right_sum[i] + v[i];
    }

    let mut left_sum = vec![0; n + 1];
    for i in 0..n {
        left_sum[i + 1] = left_sum[i] + v[n - 1 - i];
    }

    let mut right_max = vec![0; n + 1];
    for i in 0..n {
        right_max[i + 1] = cmp::max(right_max[i], right_sum[i + 1] - x[i]);
    }

    let mut left_max = vec![0; n + 1];
    for i in 0..n {
        left_max[i + 1] = cmp::max(left_max[i], left_sum[i + 1] - (c - x[n - 1 - i]));
    }

    let mut ans = 0;
    for i in 0..n {
        let dist = c - x[n - 1 - i];
        let left = left_sum[i + 1] - dist * 2;
        ans = cmp::max(ans, left + right_max[n - 1 - i]);
    }
    for i in 0..n {
        let dist = x[i];
        let right = right_sum[i + 1] - dist * 2;
        ans = cmp::max(ans, right + left_max[n - 1 - i]);
    }
    ans = cmp::max(ans, left_max[n]);
    ans = cmp::max(ans, right_max[n]);
    println!("{}", ans);
}

pub mod scanner {
    use std::fmt::Debug;
    use std::io::Read;
    use std::str::{self, FromStr};

    pub struct Scanner<R: Read> {
        reader: R,
    }

    impl<R: Read> Scanner<R> {
        pub fn new(reader: R) -> Self {
            Scanner { reader: reader }
        }

        pub fn read<T>(&mut self) -> T
        where
            T: FromStr,
            T::Err: Debug,
        {
            let buf = self
                .reader
                .by_ref()
                .bytes()
                .map(|b| b.unwrap())
                .skip_while(|&b| b == b' ' || b == b'\n')
                .take_while(|&b| b != b' ' && b != b'\n')
                .collect::<Vec<_>>();

            unsafe { str::from_utf8_unchecked(&buf) }
                .parse()
                .expect("Parse error.")
        }
    }
}


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

int main() {
  int a;
  cin>>a;
  vector<int> b(a),c(a);
  for(int i=0;i<a;i++){
    cin>>b.at(i);
  }
  for(int i=0;i<a;i++){
    cin>>c.at(i);
  }
  int d=0;
  int e=0;
  for(int i=0;i<a;i++){
    if(b.at(i)>c.at(i)){
      d+=b.at(i);
      e+=c.at(i);
    }
  }
  d-=e;
  cout<<d<<endl;
}

Measured memory_bytes: 256
def GCD(a,b):
    if(b==0):
        return a 
    return GCD(b,a%b)

def LCM(a,b):
    return a / GCD(a,b) * b


while True:
    try:
        x = list(map(int,input().split()))
        ans_1 = GCD(x[0],x[1])
        ans_2 = LCM(x[0],x[1])
        print("%d %d"%(ans_1,ans_2))
    
    except:
        break


Measured memory_bytes: 5600
#include<iostream>

using namespace std;


int main()
{
  int h, w;

  cin >> h >> w;

  while(true)
    {
      if ( h == 0 && w == 0 ) break;

      for ( int i = 0; i < h; i++ )
        {
          for ( int j = 0; j < w; j++ )
            {
              cout << "#";
            }
          cout << endl;
        }
      cout << endl;
      
      cin >> h >> w;
    }

  return 0;
}

          

Measured memory_bytes: 1152
#include<iostream>
#include <sstream>
using namespace std;

int main()
{
	int n, y;
	bool ok = false;
	stringstream ss;
	string s;

	cin >> n >> y;

	for (int i = y/10000; i >= 0; --i)
	{
		for (int j = 0; j <= n-i; ++j)
		{
			if (10000*i + 5000*j + 1000*(n-i-j) == y)
			{
				ok = true;
				ss << i << " " << j << " " << n-i-j;
				s = ss.str();
				break;
			}
		}
		if (ok)
		{
			break;
		}
	}

	if (ok)
	{
		cout << s << endl;
	} else {
		cout << -1 << " " << -1 << " " << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();
        int cnt = 0;
        for (int i = N.length(); i > 0; i--) {
            if (i % 2 == 0) continue;
            if (i == N.length()) {
                cnt += Integer.parseInt(N) - Math.pow(10, i - 1) + 1;
            } else {
                cnt += 9 * Math.pow(10, i - 1);
            }
        }
        System.out.println(cnt);
        sc.close();
    }
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll X;
  cin >> X;
  if(X>=30){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}


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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0LL)
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

template<typename A, size_t N, typename T> // n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int n;cin>>n;
  int a[n]; rep(i, n) {cin>>a[i];}

  int p[100001]={};
  int q[100001]={};
  rep(i, n){
    if (i%2==0) { p[a[i]]++; }
    else{ q[a[i]]++; }
  }

  int res = 0;
  vector<pii> x,y;
  rep(i, 100001){
    x.pb(mp((n/2)-p[i], i));
  }
  rep(i, 100001){
    y.pb(mp((n/2)-q[i], i));
  }
  sort(all(x));
  sort(all(y));
  // dump(x);
  // dump(y);
  dump_1d(x, 10);
  dump_1d(y, 10);

  if (x[0].second != y[0].second){
    cout << x[0].first + y[0].first << endl;
  }
  else{
    int res = min(x[1].first + y[0].first, x[0].first + y[1].first);
    cout << res << endl;
  }

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


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

int main() {
    int N; cin >> N;
    vector<int> W(N);
    int sum = 0;
    for (int i = 0; i < W.size(); i++) {
        cin >> W.at(i);
        sum += W.at(i);
    }
    
    int secsum = 0,minus,  m = 101;
    for (int i = 0; i < W.size() - 1; i++) {
        secsum += W.at(i);
        minus = abs(sum - 2 * secsum);
        m = min(m, minus);
        //cout << secsum << " " << minus << " " << m << endl;
    }
    cout << m << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def main():
    # 整数の入力
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())

    # 雑な探索
    cnt = 0
    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                v = 500 * i + 100 * j + 50 * k
                if v == x:
                    cnt += 1

    print(cnt)


main()


Measured memory_bytes: 3060
#include <vector>
#include<iostream>
using namespace std;
int main(){
	vector<int> num;
	int n;
	for(int i=0;i<5;i++){
		cin>>n;
		num.push_back(n);
	}
	for(int i=0;i<5;i++){
		if(num[i]==0)cout<<i+1;
	}
}

Measured memory_bytes: 3628
#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>;

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

int main(){
	int X,Y;
	cin >> X >> Y;
    vector<string> board(X);
	rep(i,X) cin >> board[i];
	for(int i = 0;i < X;i++){
		for(int j = 0;j < Y;j++){
			if(board[i][j] == '.'){
				int cnt = 0;
				for(int k = 0;k < 8;k++){
					int x = i + dx[k];
					int y = j + dy[k];
					if(x >= 0 && x < X && y >= 0 && y < Y && board[x][y] == '#') cnt++;
				}
				board[i][j] = '0' + cnt;
			}
		}
	}
	for(int i = 0;i < X;i++) cout << board[i] << endl;
}

Measured memory_bytes: 256
n = int( input() )
a = list( map( int, input().split() ) )


for i in range(n-1): a[i+1] += a[i]

ansPos = 0
change = 0
# a[0] を正にする場合
for i in range(n):
    if i%2 == 0 and a[i]+change <= 0:
        ansPos += -a[i]-change+1
        change += -a[i]-change+1
    if i%2 == 1 and a[i]+change >= 0: 
        ansPos +=  a[i]+change+1
        change -=  a[i]+change+1

ansMin = 0
change = 0
# a[0] を負にする場合
for i in range(n):
    if i%2 == 0 and a[i]+change >= 0:
        ansMin +=  a[i]+change+1
        change -=  a[i]+change+1
    if i%2 == 1 and a[i]+change <= 0:
        ansMin += -a[i]-change+1
        change += -a[i]-change+1

print( min(ansPos, ansMin) )

Measured memory_bytes: 14332
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int Maxn = 100010;
int a[Maxn], n;
int sum1[Maxn], sum2[Maxn];
int _max(int x, int y) { return x > y ? x : y; }
int main() {
	int i, j, k;
	scanf("%d", &n);
	for(i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(i = 1; i <= n; i += 2) sum1[a[i]]++;
	for(i = 2; i <= n; i += 2) sum2[a[i]]++;
	int max11 = 0, max12 = 0, num11, num12;
	for(i = 1; i <= 100000; i++){
		if(sum1[i] > max11){
			max12 = max11; num12 = num11;
			max11 = sum1[i]; num11 = i;
		} else if(sum1[i] > max12){
			max12 = sum1[i]; num12 = i;
		}
	}
	int max21 = 0, max22 = 0, num21, num22;
	for(i = 1; i <= 100000; i++){
		if(sum2[i] > max21){
			max22 = max21; num22 = num21;
			max21 = sum2[i]; num21 = i;
		} else if(sum2[i] > max22){
			max22 = sum2[i]; num22 = i;
		}
	}
	int ans = 0;
	if(num11 != num21) ans = n-max11-max21;
	else ans = n-_max(max11+max22, max21+max12);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1280
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] A = new int[N];
		int[] B = new int[N];
		
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			B[i] = A[i];
		}
		
		Arrays.sort(A);
		
		int Y = yaku(A[0], A[1]);
		int check = 1;
				
		for(int i = 2; i < N; i++) {
			if(yaku(Y, A[i]) < Y) {
				Y = yaku(Y, A[i]);
				check = i;
			} else {
				Y = yaku(Y, A[i]);
			}
		}
		
		A[check] = A[0];
		int Y1 = yaku(A[0], A[1]);
		
		for(int i = 2; i < N; i++) {
			Y1 = yaku(Y1, A[i]);
		}
		
		Arrays.sort(B);
		
		B[0] = B[1];
		int Z = yaku(B[0], B[1]);
		
		for(int i = 2; i < N; i++) {
			Z = yaku(Z, B[i]);
		}
	
		System.out.println(Math.max(Y1, Z));
	}
	
	public static int yaku(int a, int b) {
		if(b == 0) {
			return a;
		}
		return yaku(b, a % b);
	}
}

Measured memory_bytes: 60216
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0L;i--)
#define prep(i,n) for(int64_t i=1;i <= (int64_t)(n);i++)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  fspcnt = 0;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  string s,t;
  cin >> s;
  t = "2019/04/30";
  if(s == t){
    cout << "Heisei" << endl;
  }else{
    rep(i,s.size()){
      if(s.at(i) > t.at(i)){
        cout << "TBD" << endl;
        break;
      }
      if(s.at(i) < t.at(i)){
        cout << "Heisei" << endl;
        break;
      }
    }
  }
  
}

Measured memory_bytes: 256
<?php

class In {

	private $buf = [];
	private $count = 0;
	private $pointer = 0;

	public function nextLine() {
		$ret = '';
		if($this->hasNext()){
			while($this->hasNext()){
				$ret .= $this->next();
			}
		}else{
			$ret = trim(fgets(STDIN));
		}

		return $ret;
	}

	public function next() {
		if(!$this->hasNext()) {
			$str = trim(fgets(STDIN));
			$this->buf = explode(' ',$str);
			$this->count = count($this->buf);
			$this->pointer = 0;
		}

		return $this->buf[$this->pointer++];
	}

	public function hasNext() {
		return $this->pointer < $this->count;
	}

	public function nextInt() {
		return (int)$this->next();
	}

	public function nextDouble() {
		return (double)$this->next();
	}
}

class Out {
	public function println($str = '') {
		echo $str . PHP_EOL;
	}
}

$in = new In();
$out = new Out();

$N = $in->nextInt();

while($N > 0) {
	if ($N % 10 === 9) {
		$out->println('Yes');
		return;
	}
	$N = floor($N/10);
}

$out->println('No');

?>


Measured memory_bytes: 4604
#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;
#define inRange(x,a,b) (a <= x && x <= b)

int fun(string s, string t){
    int n = s.length();
    stack<int> x;
    for(int i = 0; i < n; i++){
        if(s[i] == '[' || s[i] == ']')  continue;
        if(inRange(s[i], 'a', 'd')){
            x.push(t[s[i]-'a']-'0');
            continue;
        }
        int j = x.top(); x.pop();
        int k = x.top(); x.pop();
        if(s[i] == '+'){
            x.push(j|k);
        }else if(s[i] == '*'){
            x.push(j&k);
        }else if(s[i] == '^'){
            x.push(j^k);
        }
    }
    return x.top();
}

int main(){
    string s, p;
    while(cin >> s, s != "."){
        reverse(s.begin(), s.end());
        cin >> p;
        int h = fun(s, p);
        int cnt = 0;
        for(int i = 0; i <= 9999; i++){
            string t = to_string(i);
            while(t.size() < 4) t = "0" + t;
            if(fun(s, t) == h)    cnt++;
        }
        cout << h << " " << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#include <iostream>
#include <string>

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define REP(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  i32 a, b, c, d;
  cin >> a >> b >> c >> d;

  while (a > 0 && c > 0) {
    c = c - b;
    if (c <= 0) {
      cout << "Yes";
      return 0;
    }

    a = a - d;
    if (a <= 0) {
      cout << "No";
      return 0;
    }
  }
}


Measured memory_bytes: 3612
s = input()
l = set(s)
ans = 10 ** 10
for x in l:
    cnt, cnt_max = 0, 0
    for i in s:
        if i != x:
            cnt += 1
        else:
            cnt_max = max(cnt_max, cnt)
            cnt = 0
    cnt_max = max(cnt_max, cnt)
    ans = min(cnt_max, ans)
print(ans)

Measured memory_bytes: 8992
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
#define INF 1e9;
#define LINF 1e18;
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(long long n, long long m){
  ANS((n-1) * (m-1));
}

// clang-format off
int main() {
  long long n;
  scanf("%lld",&n);
  long long m;
  scanf("%lld",&m);
  solve(n, m);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int a,b;

int main(){
	cin>>a>>b;
	cout<<6-a-b<<endl;
}

Measured memory_bytes: 256