akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
 using namespace std ;
 int main()
{
 int A, B, C, D, x, y, z, k;
 cin>>A;
 cin>>B;
 cin>>C;
 cin>>D;
x=(A+C);
y=(A+D);
z=(B+C);
k=(B+D);
if (x<=y&&x<=z&&x<=k)
{
  cout<<x<<endl;
}
if  (y<=k&&y<x&&y<=z)
{
  cout<<y<<endl;
}
if (z<y&&z<x&&z<=k)
{
  cout<<z<<endl;
}
if (k<y&&k<z&&k<x)
{
  cout<<k<<endl;
}
}

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int n;
ll x;
ll a[2000];
ll ans = INF*INF;

int main() {
    cin >> n >> x;
    rep(i,n) cin >> a[i];
    for (int i = 0; i < n; i++) {
        ll tmp = x*i;
        priority_queue<P, vector<P>, greater<P>> que;
        for (int j = n-1; j > n-1-i; j--) que.push(P(a[j], j));
        rep(j,n) {
            que.push(P(a[j], j));
            while (true) {
                P q = que.top();
                if (q.second > j) {
                    if (j+n-q.second > i) que.pop();
                    else break;
                } else {
                    if (j-q.second > i) que.pop();
                    else break;
                }
            }
            tmp += que.top().first;
        }
        ans = min(ans,tmp);
    }
    cout << ans << endl;
}
































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

int main() 
{
    long long q,h,s,d,n;
    
    cin>>q>>h>>s>>d;
    s=min(s,min(4*q,2*h));
    d=min(d,2*s);
    cin>>n;
    long long ans=n/2*d+n%2*s;
    cout<<ans<<endl;
    
	return 0;
}


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

using namespace std;
vector<pair<int,int> >v[100005];
bool visit[100005];
int ans[100005];
void dfs(int x,int c){
	ans[x]=c;
	visit[x]=1;
	for(int i=0;i<v[x].size();i++){
		if(v[x][i].second%2==0&&!visit[v[x][i].first])ans[v[x][i].first]=c,dfs(v[x][i].first,c);
		if(v[x][i].second%2==1&&!visit[v[x][i].first])ans[v[x][i].first]=1-c,dfs(v[x][i].first,1-c);
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b,w;
		cin>>a>>b>>w;
		a--,b--;
		v[a].push_back(make_pair(b,w));
		v[b].push_back(make_pair(a,w)); 
	}
	for(int i=0;i<n;i++)ans[i]=-1;
	dfs(0,0);
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 8448
class UnionFind:
    def __init__(self, n):
        self.par = list(range(n))
        self.rank = [0] * n
        self.size = [1] * n

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        elif self.rank[x] < self.rank[y]:
            x, y = y, x

        self.par[y] = x
        self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]


N, M, K = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]
Y = [list(map(int, input().split())) for _ in range(K)]

friend = [[] for _ in range(N + 1)]
for a, b in X:
    friend[a].append(b)
    friend[b].append(a)

block = [[] for _ in range(N + 1)]
for c, d in Y:
    block[c].append(d)
    block[d].append(c)

t = UnionFind(N + 1)
for a, b in X:
    t.unite(a, b)

ans = []
for i in range(1, N + 1):
    cnt = t.get_size(i) - len(friend[i]) - 1
    for v in block[i]:
        cnt -= int(t.is_same(i, v))
    ans.append(cnt)

print(*ans)


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

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

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

	ll a,b,c; cin >> a >> b >> c;

	if(a+b < c) cout << b + a+b + 1 << endl;
	else cout << c+b << endl;
		//	else cout << c*2 << endl;}

	return 0;

}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



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

    int T=1;
    //cin >> T;
    while(T--){
        ll n;
        cin>>n;
        ll a[n];
        rep(i,n) cin>>a[i];
        ll z[1000002]={0};
        rep(i,n) z[a[i]]++;
        ll ans=0, f;
        rep(i,n){
            f=1;
            for(int j=2;j*j<=a[i];j++){
                if(a[i]%j==0){
                    if(z[j]>0 || z[a[i]/j]>0) f=0;
                }
            }
            if(z[a[i]]>1) f=0;
            if(a[i]>1 && z[1]>0) f=0;
            ans+=f;
        }
        cout<<ans<<el;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 13128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n,m;
    cin>>n>>m;

    vector<pair<long long int,long long int>> mise(n);
    REP(i,n){
        scanf("%lld %lld", &mise[i].first,&mise[i].second);
    }

    sort(mise.begin(),mise.end());
    long long int result=0;
    for(pair<long long int,long long int> &x:mise){
        result+=x.first*min(x.second,m);
        m-=min(x.second,m);
        if(m<=0){
            break;
        }

    }
        
    cout<<result<<endl;
    

    return 0;
}


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

using namespace std;
using ll = long long;

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

int main() {
  string s, t;
  cin >> s >> t;
  t.pop_back();
  cout << (s == t ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3596
n,m=map(int,input().split())
ab=[map(int,input().split()) for _ in range(m)]
t1=set()
t2=set()
for a,b in ab:
    if a==1:
        t1.add(b)
    if b==n:
        t2.add(a)
for t in t1:
    if t in t2:
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 94640
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){

  int sum=0;
  int n=0;
  int cnt=0;

  int a,b;
  while(scanf("%d,%d",&a,&b) != EOF){
    sum += (a*b);
    n += b;
    cnt++;
  }

  double ave = (double)n/cnt;

  printf("%d\n%d\n",sum,(int)(ave+0.5));

  return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    string s;
    int count0 = 0;
    int count1 = 0;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s.at(i) == '0') count0++;
        else count1++;
    }
    cout << 2 * (min(count0, count1)) << endl;
}

Measured memory_bytes: 512
#include<cstdio>

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

	if ( n>=0 )
	printf("%d\n",n);
	else
	printf("-1\n");
	return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;

    vector<int> c(m);
    for(int i=0;i<m;i++){
        cin >> c[i];
    }

    //1が必ず含まれるので1が最初になる、そしてコインの必要初期値はn
    sort(c.begin(),c.end());

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

    for(int i=0;i<m;i++){
        for(int j=0;j<=n;j++){
            if(j-c[i]>=0){
                dp[j] = min(dp[j],dp[j-c[i]]+1);
            }
        }
    }


    cout << dp[n] << endl;
}


Measured memory_bytes: 3336
#include <stdio.h>
#define MAX 100
#define INF 1000000
#define NIL -1
 
void MST();
 
int n;
int haruka[MAX][MAX];
int heap_size;
int key[MAX];
int xxhairetsuxx[MAX];
 
main()
{
  int i, j, total=0;
  scanf("%d",&n);
  
  for(i=0; i<n; i++)
    {
      for(j=0; j<n; j++)
	{
	  scanf("%d",&haruka[i][j]);
	}
    }
  
  MST();
  for(i=0; i<n; i++)
    {
      total+=key[i];
    }
  printf("%d\n",total);
  
  return 0;
}


void MST()
{
  int u, v, v1, flag[MAX], minv, i;
  
  for(u=0; u<n; u++)
    {
      key[u]=INF;
      xxhairetsuxx[u]=NIL;
      flag[u]=0;
    }
  
  key[0]=0;
  
  for(v1=0; v1<n; v1++)
    {
      minv = INF;
      for (i=0; i<n; i++)
	{
	  if(flag[i]==1)
	    {
	      continue;
	    }
	  if(key[i]<=minv)
	    {
	      u=i;
	      minv=key[i];
	    }
	}
      
      for(v=0; v<n; v++)
	{
	  if(haruka[u][v]==-1)
	    {
	      continue;
	    }
	  if(flag[v]==1)
	    {
	      continue;
	    }
	  if(haruka[u][v]<key[v])
	    {
	      xxhairetsuxx[v]=u;
	      key[v]=haruka[u][v];
	    }
	}
      flag[u]=1;
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll int 
double dp[3000][3000],p[3000];
ll n;

void boost()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

double solve(ll i,ll ch)
{
	//cout<<ch<<endl;
	if(i==n+1)
	{
		if(ch<=(n/2))
			return 0;
		else
			return 1;
	}
	if((ch+(n-i)+1)<=(n/2))
		return 0;
	if(dp[i][ch]!=-1.0)
		return dp[i][ch];
	double res1=0.0,res2=0.0,temp=0.0;
	temp = solve(i+1,ch)*(1-p[i]);
	if(temp>res1)
		res1=temp;
	temp = solve(i+1,ch+1)*p[i];
	if(temp>res2)
		res2=temp;
	return dp[i][ch]=(res2+res1);
}

int main()
{
	ll i,j;
	boost();
	cin>>n;
	cout.precision(10);
	for(i=1;i<=n;i++)
	{
		for(j=0;j<=n;j++)
			dp[i][j]=-1.0;
	}
		
	for(i=1;i<=n;i++)
	{
		cin>>p[i];
		//cout<<p[i]<<endl;
	}
	cout<<solve(1,0)<<endl;
	return 0;
}

Measured memory_bytes: 70784
import sys

H, W, M = map(int, sys.stdin.readline().strip().split())

h = [0] * H
w = [0] * W

# g = [[False] * W for _ in range(H)]
S = set()
for _ in range(M):
    Th, Tw = map(int, sys.stdin.readline().strip().split())

    h[Th - 1] += 1
    w[Tw - 1] += 1

    # g[Th - 1][Tw - 1] = True
    S.add((Th - 1, Tw - 1))

max_h = max(h)
max_w = max(w)
ans = max_h + max_w

index_h = [n for n, v in enumerate(h) if v == max_h]
index_w = [n for n, v in enumerate(w) if v == max_w]

sub = 1
# for ih in index_h:
#     for iv in index_w:
#         if g[ih][iv] is False:
#             sub = 0
#             break
#     else:
#         continue
#     break
# ans -= sub
# print(ans)


for ih in index_h:
    for iv in index_w:
        if not (ih, iv) in S:
            print(ans)
            exit()
print(ans - 1)



Measured memory_bytes: 167900
import math
a,b,C = map(float,input().split())
rad = math.radians(C)
h = b*math.sin(rad)
S = a*h/2
L = a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(rad))

print("%.5f\n%.5f\n%.5f" % (S,L,h))

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

public class Main{
    public static void main(String[] args){
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    
    try{
        String str = br.readLine();
        StringTokenizer st = new StringTokenizer(str, " ");
        
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        
        if (a<b){
            System.out.println("a < b");
        }
        
        if (a>b){
            System.out.println("a > b");
        }
        
        if (a==b){
            System.out.println("a == b");
        }
        
        
        
    }catch(IOException e){}
    

    }
}

Measured memory_bytes: 24260
import java.util.*;

public class Main{
    Scanner in = new Scanner(System.in);

    void solve(){
        String s = in.nextLine();
        for(char ch : s.toCharArray()){
            System.out.print(Character.toUpperCase(ch));
        }
        System.out.println();
    }
    
    public static void main(String[] args){
        new Main().solve();    
    }
}

Measured memory_bytes: 25940
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    int n;
    cin>>n;
    vector<int>v,u;
    rep(i,1,n){
        int a,b;
        cin>>a>>b;
        v.pb(a);
        u.pb(b);
    }
    sort(all(v));
    sort(all(u));
    if(n%2) return cout<<u[n/2]-v[n/2]+1,0;
    return cout<<u[n/2]+u[n/2-1]-v[n/2]-v[n/2-1]+1,0;
    return 0;
}


Measured memory_bytes: 5140
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { Array(n) { '.' } }
    val rowexistblack = Array(n) { false }
    val colexistblack = Array(n) { false }
    val colallblack = Array(n) { true }
    for (i in 0 until n) {
        val _s = sc.nextLine()
        for (j in 0 until n) {
            a[i][j] = _s[j]
            if (a[i][j] == '#') {
                rowexistblack[i] = true
                colexistblack[j] = true
            } else {
                colallblack[j] = false
            }
        }
    }
    var min = Int.MAX_VALUE
    for (i in 0 until n) {
        var count = 0
        for (j in 0 until n) {
            if (a[i][j] == '.') count++
        }
        if (!colexistblack[i]) {
            if (rowexistblack[i]) {
                count++
            } else {
                continue
            }
        }
        min = minOf(min, count)
    }
    if (min == Int.MAX_VALUE) {
        println(-1)
        return
    }
    println(min + n - colallblack.count { it })
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 39180
#include<stdio.h>
#include<stdlib.h>
int compare(const void *a, const void *b){
  return *(int*)a-*(int*)b;
}

int main(){
  int unused __attribute__((unused));
  int N, K, i, ans = 0;
  int p[1000] = {0};
  unused = scanf("%d %d", &N, &K);
  for(i=0; i<N; i++) unused = scanf("%d", &p[i]);

  qsort(p, N, sizeof(p[0]), compare);
  for(i=0; i<K; i++) ans += p[i];
  printf("%d", ans);

  return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <utility>
#include<algorithm>
#include<stack>
#include<queue>
#include<list>
#include<array>
using namespace std;

int main() {
	int k = 100000;
	int n;
	cin >> n;
	vector<int>u(n);
	vector<int>v(n + 1);
	for (int i = 0;i < n+1; i++) {
		v.at(i) = -1;
	}
	for (int i = 0; i < n; i++) {
		cin >> u.at(i);
	}
	for (int i = 0; i < n; i++) {
		int j = 0;
		int min = 0;
		int max = n;
		int mid = n / 2;
		while ((max-min)>1) {
			mid = (max + min) / 2;
			if (v.at(mid) >= u.at(i)) {
				min = mid;
			}
			else {
				max = mid;
			}
		}
		if (u.at(i) > v.at(min)) {
			v.at(min) = u.at(i);
		}
		else
			v.at(max) = u.at(i);
	}
	int c = 0;
	while (v.at(c) > -1) {
		c++;
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int x,y,c,t;

int main(){
	scanf("%d%d", &x,&y);
	for(t=0; t<=x; t++){
		c=x-t;
		if(4*t+2*c==y){
		printf("Yes\n");
		return 0;
	}
	}
	printf("No\n");
	return 0;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);


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


int main() {

 ll h;
 int n;
 cin>>h>>n;
 int a[n];
 ll sum = 0;
 for(int i=0;i<n;i++){
   cin>>a[i];
   sum +=a[i];
 }

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


  
  return 0;
}


Measured memory_bytes: 3976
import java.util.*;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    char[] c = str.toCharArray();

    for (int i = 0 ; i < str.length() ; i++) {
      c[i] = 'x';
    }

    for (int i  = 0 ; i < str.length() ; i++ ) {
      System.out.print(c[i]);
    }
  }
}


Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100005
#define D first
#define T second
using namespace std;

typedef long long ll;
ll n, k, s, mx, cnt, c[N];
pair<ll, ll> a[N];

ll f(ll p) {return p * p;}

int main()
{
	ll i, j;
	cin >> n >> k;
	for (i = 0; i < n; i++) scanf("%lld %lld", &a[i].T, &a[i].D);
	sort(a, a + n, greater<pair<ll, ll> >());
	for (i = 0; i < k; i++) {
		s += a[i].D;
		if (c[a[i].T] == 0) cnt++;
		c[a[i].T]++;
	}
	mx = s + f(cnt);
	for (j = k - 1; i < n; i++) {
		if (c[a[i].T]) continue;
		for (; j >= 0 && c[a[j].T] == 1; j--);
		if (j < 0) break;
		c[a[j].T]--;
		s -= a[j].D;
		j--;
		if (c[a[i].T] == 0) cnt++;
		c[a[i].T]++;
		s += a[i].D;
		mx = max(mx, s + f(cnt));
	}
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 2560
S = input()
if S[0] == 'A' \
    and S[2:len(S) - 1].count('C') == 1 \
    and ''.join([S[i] for i in range(len(S)) if i != 0 and not (2 <= i and i < len(S) - 1 and S[i] == 'C')]).islower():
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int, int> P;
using ll = long long;
using VI = vector<int>;

void solve(){
    Int n;
    Int ans = 0;
    cin >> n;
    vector<Int> v1(100001,0),v2(100001,0);
    Int tmp;
    rep(i,n){
        cin >> tmp;
        if(i&1) v2[tmp]++;
        else v1[tmp]++;
    }
    priority_queue<P> max1,max2;
    max1.push(make_pair(0,0));
    max2.push(make_pair(0,0));
    rep(i,100001){
        if(v1[i]!=0){
            max1.push(make_pair(v1[i],i));
        }
        if(v2[i]!=0){
            max2.push(make_pair(v2[i],i));
        }
    }
    Int ans1,ans2;
    Int m11,m12,m21,m22;
    if(max1.top().second!=max2.top().second){
        ans = (n/2-max1.top().first)+(n/2-max2.top().first);
    }else{
        m11 = max1.top().first;
        max1.pop();
        m12 = max1.top().first;
        m21 = max2.top().first;
        max2.pop();
        m22 = max2.top().first;
        ans1 = (n/2-m11)+(n/2-m22);
        ans2 = (n/2-m12)+(n/2-m21);
        ans = min(ans1,ans2);
    }
    cout << ans << endl;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3064
a, b, c, x, y = map(int, input().split())
total = 0
if x >= y:
    total = min(a*x+b*y, c*x*2, c*y*2+a*(x-y))
else:
    total = min(a*x+b*y, c*y*2, c*x*2+b*(y-x))
print(total)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_output(v) for(auto it=v.begin();it!=v.end();it++){if(it!=v.begin())cout<<" ";cout<<*it;}cout<<endl;
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);
long long int combination(long long int,long long int);
long long int series_sum(long long int);

int main(){
    ll n;
    cin>>n;
    vector<ll> vec(n);
    vec_input(vec);
    list<ll> list;
    rep(i,n){
        if(i%2==0){
            list.push_back(vec[i]);
        }else{
            list.push_front(vec[i]);
        }
    }
    if(n%2==1)reverse(all(list));
    vec_output(list);
}

Measured memory_bytes: 9984
N = gets.to_i
h = gets.split(" ")
h.map!(&:to_i)

LeastCostArray = Array.new(h.size,0)
LeastCostArray[0] = 0
LeastCostArray[1] = (h[1]-h[0]).abs

for n in 2..N-1
	if LeastCostArray[n-2]+(h[n]-h[n-2]).abs<LeastCostArray[n-1]+(h[n]-h[n-1]).abs then
		LeastCostArray[n]=LeastCostArray[n-2]+(h[n]-h[n-2]).abs
	else
		LeastCostArray[n]=LeastCostArray[n-1]+(h[n]-h[n-1]).abs
	end
end

puts LeastCostArray[N-1]

Measured memory_bytes: 7948
N = int(input())
activity = [[0, 0, 0] for _ in range(10**5+10)]

for i in range(N):
    activity[i] = [int(i) for i in input().split()]

dp = [[0, 0, 0] for _ in range(10**5+10)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j==k: continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + activity[i][k])

print(max(dp[N]))

Measured memory_bytes: 80416
import java.util.Scanner;
 
public class Main{
  public static void main(String args[]){ 
    Scanner scan = new Scanner(System.in);
    String str = scan.next();
    String hiCount = str.replaceAll("hi", "");
    if (hiCount.length()%2 == 1) {
      System.out.println("No");
    }else if(hiCount.length() == 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
   }
}

Measured memory_bytes: 23892
#include<iostream>
#include<cstdio>
#include<algorithm>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=200200;
int n,m,x,y,mx,b[N],c[2];
long long su;
struct ele{
	int w,i,c;
	ele(int _w=0,int _i=0,int _c=0){w=_w,i=_i,c=_c;}
	bool operator < (const ele&a)const{return w<a.w;}
}q[N];
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d",&n);m=n<<1;
	FOR(i,1,n) scanf("%d%d",&x,&y),q[i]=ele(x,i,0),q[i+n]=ele(y,i,1);
	sort(q+1,q+m+1);
	FOR(i,1,n) mx=max(mx,++b[q[i].i]),su+=q[i].w,c[q[i].c]++;
	if(mx==2 || !c[0] || !c[1]) cout<<su<<'\n';
	else if(q[n].i!=q[n+1].i || c[q[n].c]==1) cout<<su-q[n].w+q[n+1].w<<'\n';
	else cout<<min(su-q[n].w+q[n+2].w,su-q[n-1].w+q[n+1].w)<<'\n';
}

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>
#include <numeric>

int main(){
	long int n, m, t = 0;
	std::pair<long int,long int> input;
	std::vector<std::pair<long int,long int>> store;
	std::cin >> n >> m;
	for(int i = 0; i < n; i++){
		std::cin >> input.first >> input.second;
		store.push_back(input);
	}
	std::sort(store.begin(), store.end());
	for(int i = 0; i < n; i++){
		if(m <= store[i].second){
			t += m * store[i].first;
			break;
		}
		t += store[i].first * store[i].second;
		m -= store[i].second;
	}
	std::cout << t << std::endl;
	return 0;
}



Measured memory_bytes: 2420
#include <iostream>
using namespace std;
int n, v[101], nr, i, j, k;

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

   for(i=1; i<n-1; i++)
    for(j=i+1; j<n; j++)
        for(k=j+1; k<=n; k++)
            if(v[i]!=v[j] && v[j]!=v[k] && v[i]!=v[k] && (v[i]+v[j])>v[k] && (v[i]+v[k])>v[j] && (v[j]+v[k])>v[i])    nr++;


    cout<<nr;
    return 0;
}


Measured memory_bytes: 3620
use proconio::marker::Chars;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {_: usize, in_s: Chars};
    let mut rc = 0;
    let mut gc = 0;
    let mut bc = 0;
    let mut rcsum = Vec::new();
    let mut gcsum = Vec::new();
    let mut bcsum = Vec::new();
    let mut count = 0i64;

    for i in 0..in_s.len() {
        if in_s[i] == 'R' {
            rc += 1;
        } else if in_s[i] == 'G' {
            gc += 1;
        } else {
            bc += 1;
        }

        rcsum.push(rc);
        gcsum.push(gc);
        bcsum.push(bc);
    }

    for i in 0..in_s.len() {
        for j in i + 1..in_s.len() {
            if in_s[i] == in_s[j] {
                continue;
            }

            let c: char;

            if in_s[i] == 'R' {
                c = if in_s[j] == 'G' { 'B' } else { 'G' }
            } else if in_s[i] == 'G' {
                c = if in_s[j] == 'R' { 'B' } else { 'R' }
            } else {
                c = if in_s[j] == 'R' { 'G' } else { 'R' }
            }

            let mut v: i64;

            if c == 'R' {
                v = rcsum[rcsum.len() - 1] - rcsum[j];
            } else if c == 'G' {
                v = gcsum[rcsum.len() - 1] - gcsum[j];
            } else {
                v = bcsum[rcsum.len() - 1] - bcsum[j];
            }

            let k = j + (j - i);

            if k < in_s.len() && in_s[k] == c {
                v -= 1;
            }

            count += v;
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 2316
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

using Graph = vector<vector<int>>;


signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    int A[N], B[M];
    rep(i,N) cin >> A[i];
    rep(i,M) cin >> B[i];
    int dp[N+1][M+1]{};
    int sum[N+1][M+1]{};
    rep(i,N){
        rep(j,M){
            if(A[i] == B[j]){
                dp[i+1][j+1] += sum[i][j] + 1;
                dp[i+1][j+1] %= MOD;
            }
            sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] -sum[i][j] + dp[i+1][j+1] + MOD;
            sum[i+1][j+1] %= MOD;
        }
    }
    int ans = 1;
    rep(i,N){
        ans += dp[i+1][M];
        ans %= MOD;
    }
    rep(i,M-1){
        ans += dp[N][i+1];
        ans %= MOD;
    }
    cout << sum[N][M]+1 << endl;
}

Measured memory_bytes: 62848
export class Main {
  static main(input): string {
    const [a, b]: number[] = input.split("\n")[0].split(" ").map(Number);
    const [l, s]: number[] = [Math.max(a, b), Math.min(a, b)];
    return `${l === s ? l * 2 : l + (l - 1)}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

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


int main() {
    int N, M;
    cin >> N >> M;
    vector<int> x(N);
    vector<int> m(M);
    int ans = 0;
    for(int i=0; i<N; ++i) {
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    for(int i=0; i<N; ++i) {
        m[x[i] % M]++;
    }
    for(int i=1; i<N;) {
        if(x[i] % M != 0 && x[i] == x[i-1] && m[x[i] % M] > m[M - (x[i] % M)] ) {
            ans++;
            m[x[i] % M] -= 2;
            i += 2;
        } else {
            i++;
        }
    }
    ans += m[0]/2;
    for(int i=1; i<M/2 + (M%2 == 0 ? 0 : 1); ++i) {
        ans += min(m[i], m[M-i]);
    }
    if(M % 2 == 0) {
        ans += m[M/2]/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  
  int cnt = 0;

  while(1) {
    if(N / K != 0) {
      N /= K;
      cnt++;
    }
    else {
      cnt++;
      break;
    }
  }
    
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
ll euclidean_gcd(ll a, ll b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}
int main() {
  ll k,sum=0;
  cin >> k;
  rep(i,k){
    rep(j,k){
      rep(t,k){
        sum += euclidean_gcd(euclidean_gcd(i+1,j+1),t+1);
      }
    }
  }
  cout << sum << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount

bool check(string s){
    if(s.empty())return true;
    char t = s[0];
    for(char a : s)if(a!=t)return false;
    return true;
}

int main() {
    string s; cin>>s;
    if(check(s)){
        cout<<0<<endl;
        return 0;
    }
    set<char> alla;
    for(char a : s)alla.insert(a);

    int res = INF;
    for(auto a: alla){
        int cnt=0;
        string ts=s;
        while(!check(ts)){
            string t="";
            for(int j = 0; j < sz(ts)-1; j++)
            {
                if(ts[j]==a||ts[j+1]==a){
                    t+=a;
                }else t+=ts[j];
            }
            cnt++;
            ts=t;
        }
        res=min(res, cnt);
    }
    cout<<res<<endl;

    return 0;
}

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

int main() {
   int x;
   cin >> x;

   int happy = 0;

   happy += (x / 500) * 1000;
   x %= 500;
   happy += (x / 5) * 5;

   cout << happy << endl;
}

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

using namespace std;

int main()
{
    int sum = 0;
    int n;
    cin >> n;

    int* array = new int[n];
    for(int i = 0; i < n; ++i) cin >> array[i];
    
    for(int i = 0; i < n; ++i)
        for(int j = i + 1; j < n; ++j)
            sum += array[i] * array[j];

    cout << sum;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int a = sc.nextInt();
        List<Integer> list = new ArrayList<>();

        for(int i=0; i < n; i++){
            list.add(sc.nextInt());
        }

        int answer = 0;
        double ondosa = 10000;
        int index = 0;
        for(int hi: list){
            index++;
            double temp = t - hi * 0.006;
            if (Math.abs(temp - a) < ondosa){
                ondosa = Math.abs(temp - a);
                answer = index;
            }
        }

        System.out.println(answer);

    }
}


Measured memory_bytes: 24148
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	string S;
	cin>>S;
	vector<bool> XOR;
	for(int i=0;i<S.length()-1;i++){
		if(S[i]!=S[i+1])
			XOR.pb(1);
		else
			XOR.pb(0);
	}
	/*
	for(int i=0;i<XOR.size();i++)
		cout<<XOR[i];
	cout<<endl;
	*/
	int ans=INF;
	for(int i=0;i<XOR.size();i++){
		if(XOR[i])
			ans=min(ans,max(i+1,(int)XOR.size()-i));
	}
	if(ans==INF){
		cout<<S.length()<<endl;
		return 0;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>

int main () {
    
    ll n, k;
	cin >> n >> k;
 
	ll modulo = n % k;
 
	ll ans = min(modulo, k-modulo);
 
	cout << ans << "\n";

   
    return 0 ;
}

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

using namespace std;

const int MAX_N = 100005;
const int DAYS = 3;

struct Day {
  long long a, b, c;
};

int n;

long long dp[DAYS][MAX_N];

Day arr[MAX_N];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld %lld %lld", &arr[i].a, &arr[i].b, &arr[i].c);
  }
  dp[0][1] = arr[1].a;
  dp[1][1] = arr[1].b;
  dp[2][1] = arr[1].c;
  for (int i = 2; i <= n; ++i) {
    for (int op = 0; op < 3; ++op) {
      if (op == 0) {
        dp[op][i] = arr[i].a + max(dp[1][i - 1], dp[2][i - 1]);
      } else if (op == 1) {
        dp[op][i] = arr[i].b + max(dp[0][i - 1], dp[2][i - 1]);
      } else {
        dp[op][i] = arr[i].c + max(dp[0][i - 1], dp[1][i - 1]);
      }
    }
  }
  printf("%lld", max(dp[0][n], max(dp[1][n], dp[2][n])));
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  int t1 = H1 * 60 + M1;
  int t2 = H2 * 60 + M2;
  cout << t2 - t1 - K << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#define REP(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,a) REP(i,0,a)
using namespace std;

int N,kou,bon,hara,mine,kubo;
int a[100010];

int main(void){
    cin >> N;
    rep(i,N) cin >> a[i];
    int flat = 0, bef = a[0];
    REP(i,1,N) {
        if (a[i-1] == a[i])
            ++flat;
        else if (a[i-1] < a[i]) {
            if (flat > 0) {
                if (bef < a[i-1]) ++hara;
                if (bef > a[i-1]) ++bon;
                flat = 0;
            } else {
                if (bef > a[i-1]) ++kubo;
            }
            bef = a[i-1];
        } else {
            if (flat > 0) {
                if (bef < a[i-1]) ++kou;
                if (bef > a[i-1]) ++hara;
                flat = 0;
            } else {
                if (bef < a[i-1]) ++mine;
            }
            bef = a[i-1];
        }
    }
    printf("%d %d %d %d %d\n", kou, bon, hara, mine, kubo);
    return 0;
}


Measured memory_bytes: 1536
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll N; string S;
	cin >> N>>S;
	
	// 解法
	ll b[N+1] = {0};
	REP(i,N+1){
		if (i==0) b[i] = 0;
		else if (S[i-1]=='#') b[i] = b[i-1]+1;
		else b[i] = b[i-1];
	}
	ll w[N+1] = {0};
	REP(i,N+1){
		if (i==0) w[N-i] = 0;
		else if (S[N-i]=='.') w[N-i] = w[N-i+1]+1;
		else w[N-i] = w[N-i+1];
	}
	// REP(i,N+1) printf("%lld ", b[i]);
	// printf("\n");
	// REP(i,N+1) printf("%lld ", w[i]);
	// printf("\n");
	
	ll ans = N;
	REP(i,N+1){
		if (w[i]+b[i]<ans) ans = w[i]+b[i];
	}
	
	cout<<ans<<endl;
	
}


Measured memory_bytes: 3716
h,w = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]

res = []
for i in range(h):
    if i % 2 == 0:
        # left -> right
        for j in range(w):
            if i == h - 1 and j == w - 1:
                break
            if a[i][j] % 2 == 1:
                if j != w - 1:
                    res.append([i + 1, j + 1, i + 1, j + 1 + 1])
                    a[i][j + 1] += 1
                else:
                    res.append([i + 1, j + 1, i + 1 + 1, j + 1])
                    a[i + 1][j] += 1
                a[i][j] -= 1
            pass
    else:
        # right -> left
        for j in range(w - 1, -1, -1):
            if i == h - 1 and j == 0:
                break
            if a[i][j] % 2 == 1:
                if j != 0:
                    res.append([i + 1, j + 1, i + 1, j - 1 + 1])
                    a[i][j - 1] += 1
                else:
                    res.append([i + 1, j + 1, i + 1 + 1, j + 1])
                    a[i + 1][j] += 1
                a[i][j] -= 1
            pass

print(len(res))
for i in res:
    print(*i)

Measured memory_bytes: 30316
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;

int main(){
    int n;
    scanf("%d", &n);
    int a[n], sum = 0;
    rep(i, n){
        scanf("%d", &a[i]);
        sum += a[i];
    }

    bitset<2010*2010> bs;
    bs[0] = 1;
    rep(i, n) bs |= (bs << a[i]);

    rep(i, 2010*2010)if(bs[i] && i >= (sum+1)/2){
        printf("%d\n", i);
        return 0;
    }
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  rep(i,N) cin >> d[i];
  int sum = 0;
  for (int i = 0; i < N - 1; ++i) {
    for (int j = i + 1; j < N;  ++j) {
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3152
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n-1));
    rep(i,n) {
            rep(j,n-1) {
            cin >> a[i][j];
            a[i][j]--;
        }
        reverse(a[i].begin(), a[i].end());
    }
    typedef pair<int, int> P;
    vector<P> que;

    auto add = [&](int i) -> void {
        if (a[i].size() == 0) return;
        int j = a[i].back();
        if (a[j].back() == i) {
            P p(i,j);
            if (p.first > p.second) swap(p.first, p.second);
            que.push_back(p);
        }
    };

    rep(i,n) {
        add(i);
    }

    int ans = 0;
    while (que.size()) {
        ans++;
        sort(que.begin(), que.end());
        que.erase(unique(que.begin(), que.end()), que.end());
        vector<P> pre;
        swap(que, pre);
        for (P p : pre) {
            int i = p.first, j = p.second;
            a[i].pop_back();
            a[j].pop_back();
            add(i);
            add(j);
        }
    }

    rep(i,n) {
        if (a[i].size()) {
            cout << -1 << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 4224
from itertools import accumulate
N, Q = map(int, input().split())
S = input()
rs = [0] * N

for i in range(N - 1):
    if S[i] + S[i + 1] == "AC":
        rs[i + 1] = 1

rm = [0] + list(accumulate(rs))

for i in range(Q):
    ans = 0
    l, r = map(int, input().split())
    if S[l] == "C":
        ans -= 1
    ans = rm[r] - rm[l]
    print(ans)

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll dp[1005][1005];

void Main() {
    int H, W;
    cin >> H >> W;
    vector<string> grid(H);
    rep(i, H) cin >> grid[i];

    dp[0][0] = 1;

    rep(i, H) {
        rep(j, W) {
            if (i + 1 < H && grid[i + 1][j] != '#') {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= MOD;
            }
            if (j + 1 < W && grid[i][j + 1] != '#') {
                dp[i][j + 1] += dp[i][j];
                dp[i][j + 1] %= MOD;
            }
        }
    }
    cout << dp[H - 1][W - 1] % MOD << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n, k;
vector<int> v;

bool isok(double x) {
    int sum = 0;
    for (int i : v) {
        sum += ceil((double)i / x) - 1;
    }
    return sum <= k;
}
double binarySearch(double m, double M) {
    double ok = M - 0.1, ng = 0;
    rep(i, 100){
        double mid = (ng + ok) / 2;
        if (isok(mid))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

int main() {
    cin >> n >> k;
    v.resize(n);
    rep(i, n) { cin >> v[i]; }
    sort(all(v));
    int ans = ceil(binarySearch(v.front(), v.back()));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3984
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(int i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")


ll N,M;
vector<ll> A;
vector<ll> S;

pair<ll,ll> f(ll x) {
	ll ans = 0, tot = 0;
	for (ll a : A) {
		auto itr = lower_bound(A.begin(), A.end(), x - a);
		ll d = distance(A.begin(), itr);
		ll c = A.size() - d;
		tot += S[A.size()] - S[d];
		tot += a * c;
		ans += c;
	}
	return pair<ll, ll>(tot, ans);
}

ll bins(ll m) {
	ll l = 0;
	ll r = 10000000;
	while (r - l > 1) {
		ll mid = (r + l) / 2;
		ll tmp = f(mid).second;
		if (tmp >= m) l = mid;
		else r = mid;
	}
	return l;
}

ll solve(ll L) {
	auto p = f(L);
	ll ans = p.first;
	ans -= (p.second - M) * L;
	return ans;
}

int main() {
	cin >> N >> M;
	A.resize(N);
	REP(i, 0, N)cin >> A[i];
	sort(A.begin(), A.end());
	S.resize(N + 1);
	S[0] = 0;
	REP(i, 0, N) S[i + 1] = S[i] + A[i];

	int l = bins(M);
	auto p = f(l);
	ll ans = p.first;
	ans -= (p.second - M) * l;
	PRI(ans);
	return 0;
}




Measured memory_bytes: 4816