akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
    #include<vector>
    #include<queue>

    using namespace std;
    int main()
    {

        int N;
        cin >> N;
        vector<vector<int>> Aij(N + 1, vector<int>(N + 1));
        vector<int> currentMatchIndex(N + 1, 1);
        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= N - 1; j++){
                int opponentId;
                cin >> opponentId;
                Aij.at(i).at(j) = opponentId;
            }
        }
        
        int day = 0;
        int endIndex = N;
        queue<int> todaysCheckIds;
        for(int i = 1;i <= N; i++){
            todaysCheckIds.push(i);
        }
        int matchIndex = 0;
        int opponentId = 0;
        int opponentMatchIndex = 0;
        while(todaysCheckIds.size()){
            queue<int> tomorrowCheckIds;
            vector<int> todaysOpponentId(N + 1);
            while(todaysCheckIds.size()) {
                int i = todaysCheckIds.front();
                todaysCheckIds.pop();
                if(todaysOpponentId.at(i) != 0){
                    continue;
                }
                matchIndex = currentMatchIndex.at(i);
                if(matchIndex == endIndex){
                    continue;
                }
                opponentId = Aij.at(i).at(matchIndex);
                if(todaysOpponentId.at(opponentId) != 0){
                    continue;
                }
                if(i == Aij.at(opponentId).at(currentMatchIndex.at(opponentId))){
                    todaysOpponentId.at(i) = opponentId;
                    todaysOpponentId.at(opponentId) = i;
                    currentMatchIndex.at(i)++;
                    currentMatchIndex.at(opponentId)++;
                    tomorrowCheckIds.push(i);
                    tomorrowCheckIds.push(opponentId);
                }
            }
            if(tomorrowCheckIds.size() == 0){
                break;
            }
            day++;
            swap(todaysCheckIds, tomorrowCheckIds);
        }
        for(int i = 1; i <= N; i++){
            if(currentMatchIndex.at(i) != endIndex){
                day = -1; 
            }
        }

        cout << day << endl;
        
        return 0;
    }

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


int cmpstr(const void * a, const void *b){
    //const char *x=a, *y=b;    strcmp já faz a conversão de void para char implicitamente. Olhar man de qsort
    return strcmp(a,b);
}


int main () {

    int n, l;
    char s[123][123];

    scanf("%d%d", &n, &l);

    for(int i=0; i<n ; i++) {
        scanf("%s", s[i]);
    }
    //ordenando as strings
    qsort(s,n, sizeof(s[0]), cmpstr);

    for (int i=0; i<n ; ++i )
        printf("%s", s[i]);

    printf ("\n");

return 0;
}

Measured memory_bytes: 252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
typedef long long ll;
const ll INF=1e18;
const ll MOD=1e9+7;

int main(){
    string S;
    string T;
    cin>>S>>T;
    rep(i,S.size()-T.size()+1){
        bool judge=true;
        rep(j,T.size()){
            if(S[S.size()-T.size()-i+j]!='?' && S[S.size()-T.size()-i+j]!=T[j]) judge=false;
        }
        if(judge){
            string ans="";
            rep(j,S.size()){
                if(S.size()-T.size()-i<=j && j<S.size()-i){
                    ans+=T[j-(S.size()-T.size()-i)];
                }else if(S[j]=='?'){
                    ans+='a';
                }else{
                    ans+=S[j];
                }
            }
            cout<<ans<<endl;
            return 0;
        }
    }
    cout<<"UNRESTORABLE"<<endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();

    let mut ans = 0;
    for i in 1..n as u64 + 1 {
        if i % 3 == 0 || i % 5 == 0 {
            continue;
        }
        ans += i;
    }

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


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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

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


using namespace std;


typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
 
const ll MAX = 2e3+100;
const ll inf = 1e15;

string t[MAX];
ll dis[MAX][MAX],n,m;
priority_queue< pair<ll,ii >, vector<pair<ll,ii > >,greater< pair<ll,ii > > > q;

void adj(ll x,ll y,ll d){
	if(x < 0 || y < 0 || x >= n || y >= m  || t[x][y] == '#') return ;
	if(dis[x][y] > d ){
		dis[x][y] = d ;
		q.push({d,{x,y}});
	}
}

void bfs(ll x,ll y){
	q.push({0, {x,y} });
	dis[x][y] = 0;
	while(!q.empty()){
		ii u = q.top().ss;
		ll d = q.top().ff;
		q.pop();
		if(dis[u.ff][u.ss] != d) continue;
		adj(u.ff-1,u.ss,dis[u.ff][u.ss]);
		adj(u.ff,u.ss-1,dis[u.ff][u.ss]);
		adj(u.ff+1,u.ss,dis[u.ff][u.ss]);
		adj(u.ff,u.ss+1,dis[u.ff][u.ss]);
		f(i,-2,3) f(j,-2,3) adj(u.ff + i,u.ss + j,dis[u.ff][u.ss] + 1);
	}
}

int main(){
	fastio;
	ll x,y,fin1,fin2;
	cin >> n >> m;
	cin >> x >> y >> fin1 >> fin2;
	x--,y--;
	fin1--,fin2--;
	f(i,0,n) cin >> t[i];
	f(i,0,n) f(j,0,m) dis[i][j] = inf;
	bfs(x,y);
	if(dis[fin1][fin2] == inf) cout << "-1\n";
	else cout << dis[fin1][fin2] << endl;
}

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

//const long long INF = 1000000001;
const int INF = 2147483647;

const long long MOD = 1000000009;

typedef long long ll;

const int max = 100000; //配列の最大長

int n;

ll search_low(ll *ls,int k){
  ll left,right;
  left = -1,right = n;

  while(right - left > 1){
    ll mid = left + (right - left) / 2;
    if(ls[mid] >= k){
      right = mid;
    } else {
      left = mid;
    }
  }

  return left+1;
}

ll search_up(ll *ls,int k){
  ll left,right;
  left = -1,right = n;

  while(right - left > 1){
    ll mid = left + (right - left) / 2;
    if(ls[mid] <= k){
      left = mid;
    } else {
      right = mid;
    }
  }

  return right;
}

int main(void){
  std::cin >> n;

  ll a[n],b[n],c[n];
  for(int i=0; i<n; i++) std::cin >> a[i];
  for(int i=0; i<n; i++) std::cin >> b[i];
  for(int i=0; i<n; i++) std::cin >> c[i];

  std::sort(a,a+n); std::sort(b,b+n); std::sort(c,c+n);

  ll count = 0;
  for(int i=0; i<n; i++){
    ll temp1 = search_low(a,b[i]); //bの各値未満の数
    ll temp2 = n - search_up(c,b[i]); //bの各値超過の個数
    count += temp1 * temp2;
  }

  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int maxX = X;
  rep(i, N) {
    int x;
    cin >> x;
    maxX = max(maxX, x);
  }
  int minY = Y;
  rep(i, M) {
    int y;
    cin >> y;
    minY = min(minY, y);
  }
  if (maxX < minY) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	string str;
	cin >> str;
	int l = str.length();
	if(l<=n){
		cout << str;
	}
	else{
		cout << str.substr(0,n)+"..." ;
	}
	
return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    int c[n];
    memset(c,0,sizeof c);
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        c[a-1] ++;
        c[b-1] ++;
    }
    for(int i=0;i<n;i++){
        cout << c[i] << endl;
        
    }
    return 0;
}

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

class Main {

	void solve() {
		
		int a = inint();
		char c = inchar();
		int b = inint();
		
		out.println(c=='+' ? a+b : a-b);
		
	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

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

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}

	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

	public char[][] incharmap(int h, int w) {
		char[][] a = new char[h][w];
		for (int i=0; i<h; i++) {
			String temp = in.next();
			for (int j=0; j<w; j++) {
				a[i][j] = temp.charAt(j);
			}
		}
		return a;
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

int main(){
  long n;
  cin>>n;
  n++;

  int len=0;
  long m = n/2;
  while(m>0) len++, m/=2;

  vector<bool> ins(len+1, false);
  m = n;
  int level=0;
  while(m>0){
    if(m%2==1) ins[level] = true;
    m/=2;
    level++;
  }

  vector<int> ans;
  rep(i,len){
    if(ins[i]) ans.pb(100-i);
    ans.pb(i+1);
  }
  rep(i,len) ans.pb(i+1);
  for(int i=len-1; i>=0; i--) if(ins[i]) ans.pb(100-i);

  cout << ans.size() << endl;
  rep(i,ans.size()) cout << ans[i] << " \n"[i==ans.size()-1];

  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val a = readLine()?.split(" ")?.map(String::toInt)?.sorted() ?: return
    val count = hashMapOf<Int, Int>()
    fun add(c: java.util.HashMap<Int, Int>, v: Int) {
        if (c.containsKey(v)) {
            c[v] = c[v]!! + 1
        } else {
            c[v] = 1
        }
    }
    a.forEach {
        add(count, it - 1)
        add(count, it)
        add(count, it + 1)
    }
    count.maxBy { it.value }?.let {
        println(it.value.toString())
    }
}

Measured memory_bytes: 58212
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end() //使うときはsort(all())という感じで
using ll = long long;
#define PI 3.14159265359

int main(void){
  int n;
  cin>>n;
  ll ans=0;
  ll zero=0;
  ll a[n],b[n];
  rep(i,n+1) cin>>a[i];
  rep(i,n) cin>>b[i];
  rep(i,n){
    if(a[i]-b[i]>0){
      ans+=b[i];
    }
    else{
      ans+=a[i]+min(a[i+1],b[i]-a[i]);
      a[i+1]=max(zero,a[i+1]-(b[i]-a[i]));
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int price = 700;

        if(s.charAt(0) == 'o') price += 100;
        if(s.charAt(1) == 'o') price += 100;
        if(s.charAt(2) == 'o') price += 100;

        System.out.println(price);

    }
}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e5;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<62);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    srand((unsigned)time(NULL));
    ll D; cin>>D;
    const ll N=26;
    vi C(N);
    rep(i,0,N) cin>>C[i];
    vii A(D,vi(N));
    rep(i,0,D){
        rep(j,0,N) cin>>A[i][j];
    }
    vi last(N,-1);
    ll ans=0;
    rep(i,0,D){
        ll memo; cin>>memo;
        last[memo-1]=i;
        ans+=A[i][memo-1];
        rep(j,0,N) ans-=(i-last[j])*C[j];
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	int n ,t  ;
	cin >> n >> t ;
	vi a(n),b(n);
	t--;
	rep(i,0,n){
		cin >> a[i] >> b[i];
	}
	int ans = 0 ;
	vi idx(n);
	iota(all(idx),0);
	auto cmp = [&](int i , int j){return a[i] < a[j];};
	sort(all(idx),cmp);
//	trace(idx);
	vi dp(t+1,-MOD);
	dp[0]=0;
	trav(i,idx){
		ans = max(ans,b[i]+*max_element(all(dp)));
		vi newdp = dp;
	//	trace(dp,newdp);
		for(int j = a[i] ; j < t+1 ; ++j){
			newdp[j] = max(newdp[j],dp[j-a[i]]+b[i]);
		}
//		dp = newdp;
		swap(newdp,dp);
	}
	cout << ans << endl;
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3736
let nil = -1

type tree = { mutable parent : int; mutable child : int; mutable bro : int; mutable depth : int }

let make () = { parent = nil; child = nil; bro = nil; depth = nil }

let set_depth t n =
  let rec root i =
    if i = n then nil
    else if t.(i).parent = nil then i
    else root (i + 1) in
  let rec doit i d =
    t.(i).depth <- d;
    if t.(i).bro <> nil then doit t.(i).bro d;
    if t.(i).child <> nil then doit t.(i).child (d + 1) in
  doit (root 0) 0

let print_tree t =
  let rec print_children i c =
    if c <> nil then begin
      if c <> t.(i).child then print_string ", ";
      print_int c;
      print_children i t.(c).bro
    end in
  t |> Array.iteri (fun i _ ->
    print_string "node "; print_int i;
    print_string ": parent = "; print_int t.(i).parent;
    print_string ", depth = "; print_int t.(i).depth;
    print_string (if t.(i).parent = nil then ", root, [" else if t.(i).child = nil then ", leaf, [" else ", internal node, [");
    print_children i t.(i).child;
    Printf.printf "]\n")

let () =
  let n = Scanf.scanf "%d " (fun i -> i) in
  let t = Array.init n (fun _ -> make ()) in
  for _ = 0 to n - 1 do
    let (id, k) = Scanf.scanf "%d %d " (fun id k -> (id, k)) in
    let left_child = ref 0 in
    for i = 0 to k - 1 do
      let c = Scanf.scanf "%d " (fun i -> i) in
      t.(c).parent <- id;
      if i = 0 then t.(id).child <- c else t.(!left_child).bro <- c;
      left_child := c;
    done;
  done;
  set_depth t n;
  print_tree t

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

int main()
{
    char ch;
    int count[26];

    for (int i = 0; i < 26; i++)
        count[i] = 0;

    while (cin >> ch)
    {
        int small;
        small = tolower(ch);
        int i = small - 'a';
        count[i]++;
    }

    for (int i = 0; i < 26; i++)
    {
        cout << char(i + int('a')) << ' ' << ':' << ' ' << count[i] << endl;
    }
}



Measured memory_bytes: 3088
n,m = map(int,input().split())
a = [list(map(int,input().split()))for x in range(n)]
b = [list(map(int,input().split()))for x in range(m)]
for x in range(n):
    c = list()
    for y in range(m):
        c.append(abs(a[x][0]-b[y][0]) + abs(a[x][1]-b[y][1]))
    print(c.index(min(c))+1)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define psb push_back
#define ppb pop_back

const int INF = 1001001001;

int main() {
    string T;

    cin >> T;

    rep (i, T.size()) {
        if (T[i] == '?') T[i] = 'D';
    }

    cout << T << endl;
}


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

using namespace std;

const int MAXN = 1e6+10;
int f[MAXN], use[MAXN];

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

    vector<int> v(n);

    for(int i=0;i<n;i++)
        cin >>v[i];

    for(int &num:v){
        if(!use[num]){
            use[num] = 1;
            for(int j=num * 2;j<MAXN;j+=num){
                f[j] = -1;
            }
        }else{
            f[num] = -1;
        }
    }

    int ans = 0;
    for(int i:v){
        if(f[i] != -1){
            ans++;
        }
    }
    cout <<ans<<endl;
}


Measured memory_bytes: 11796
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,m ;
	cin >> n >> m ;
	vll a(n) ;
	for(int i=0;i<n;i++) cin >> a.at(i) ;
	vector<pair<ll,ll>> b(m) ;
	for(int i=0;i<m;i++) cin >> b.at(i).second >> b.at(i).first ;
	mysort(a) ;
	sort(b.begin(),b.end()) ;
	reverse(b.begin(),b.end()) ;
	int i = 0 ;
	int j = 0 ;
	while(i<n&&j<m&&a.at(i)<b.at(j).first){
		if(b.at(j).second==0){
			j++ ;
		}else{
			b.at(j).second-- ;
			a.at(i) = b.at(j).first ;
			i++ ;
		}
	}
	ll ans = 0 ;
	for(int i=0;i<n;i++) ans += a.at(i) ;
	cout << ans << endl ;
}


Measured memory_bytes: 2560
import java.util.*;

class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int n = Integer.parseInt(sc.next());
      	int d = Integer.parseInt(sc.next());
      	int choco = Integer.parseInt(sc.next());
      
      	int[] a = new int[n];
      	for (int i = 0; i < n; i++) {
        	a[i] = Integer.parseInt(sc.next());
        }
  
      	for (int i = 0; i < n; i ++) {
          	int add = d % a[i] != 0 ? 1 : 0;
	       	choco += (d/a[i] + add);
        }
        System.out.println(choco);
    }
}

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

int main() {
	int a, b , c;
	cin >> a >> b >> c;
	if (a == b && a == c && b == c) {
		cout << 1 << endl;
	} else if ((a == b && b != c) || (a == c && c != b) || (b == c && c != a)) {
		cout << 2 << endl;
	} else {
		cout << 3 << endl;
	}
}

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

string s;
int cul(int i,vector<int> &r){
    int mv=0,dif,sm;
    char c=s[i];
    while(1){
      if(c=='R') i++;
      else i--;
      mv++;

      if(s[i]!=c) break;
    }
    
    dif=mv/2;
    sm=mv-dif;

    if(mv%2==0){
      r[i]+=sm;
      if(c=='R') r[i-1]+=dif;
      else r[i+1]+=dif;
    }
    else{
      r[i]+=dif;
      if(c=='R') r[i-1]+=sm;
      else r[i+1]+=sm;
    }
    
    
    return i;
}

int main(){
  cin>>s;
  int n=s.size(),i;
  vector<int> r(n);
  for(i=0;i<n;i++) r[i]=0;
//右向き
  for(i=0;i<n;i++){
    if(s[i]=='R'){
      i=cul(i,r);
    }
  }
//左向き
  for(i=n-1;i>=0;i--){
    if(s[i]=='L'){
      i=cul(i,r);
    }
  }

  for(i=0;i<n-1;i++) cout<<r[i]<<" ";
  cout<<r[n-1]<<endl;

  return 0;
}

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

int main(void)
{
	int n;
	double ans = 0.0,tmp = 0;
	vector<double> v;
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> tmp;  v.push_back(tmp); }
	sort(v.begin(), v.end());
	ans += (v[0] + v[1]) / 2.0;
	for (int i = 2; i < n; i++)
	{
		ans = (ans + v[i]) / 2.0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

// UVa 11504

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		char a = in.next().toCharArray()[0];
		char b = in.next().toCharArray()[0];
		
		if (a == b) {
			System.out.println("H");
		} else {
			System.out.println("D");
		}
	}
}


Measured memory_bytes: 22868
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	char op;
	while(true){
		scanf("%d %c %d",&a,&op,&b);
		if(op == '?') break;
		switch(op){
		case '+':
			printf("%d\n",a+b);
			break;
		case '-':
			printf("%d\n",a-b);
			break;
		case '/':
			printf("%d\n",a/b);
			break;
		case '*':
			printf("%d\n",a*b);
			break;
		}
	}
}



Measured memory_bytes: 2740
from math import sqrt, floor
from collections import defaultdict
def comb(n,m):
    if m == 0:
        return 1
    return comb(n-1,m-1)*n // m
def facts(n):
    dic = defaultdict(int)
    for i in range(2,floor(sqrt(n))+1):
        while n % i == 0:
            n //= i
            dic[i] += 1
        if n == 1:
            break
    if n != 1:
        dic[n] += 1
    return dic
N, M = map(int,input().split())
mod = 10**9+7
ans = 1
dic = facts(M)
for p in dic:
    ans = (ans*(comb(dic[p]+N-1, dic[p]) % mod)) % mod
print(ans)


Measured memory_bytes: 3316
#include<iostream>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if(a >= b){
    for(int i = 0; i < a; i++){
      cout << b;
    }
  } else {
    for(int i = 0; i < b; i++){
      cout << a;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n, q; cin >> n >> q;
    vector<ll> a(n-1), b(n-1);
    vector<ll> p(q), x(q);
    vector<vector<ll>> g(n);
    REP(i, n-1) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }
    REP(i, q) {
        cin >> p[i] >> x[i];
        p[i]--;
    }

    vector<ll> dans(n, 0);
    REP(j, q) {
        dans[p[j]] += x[j];
    }

    deque<ll> que = {0};
    vector<ll> ans(n, 0);
    vector<bool> vst(n, false);
    vst[0] = true;
    ans[0] = dans[0];
    while (que.size()) {
        ll v = que.front(); que.pop_front();
        for (ll u : g[v]) {
            if (!vst[u]) {
                que.push_back(u);
                vst[u] = true;
                ans[u] += ans[v] + dans[u];
            }
        }
    }

    REP(i, n) cout << ans[i] << " \n"[i==n-1];
    
}


Measured memory_bytes: 25712
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

int main ()
{
    int N;
    cin >> N;
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    cout << (N / 2 - (N % 2 == 0 ? 1 : 0)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f), TMPend = (n); (i) < TMPend; (i)++)
#define RFOR(i, f, n) for(int (i) = (f), TMPend = (n); (i) >= TMPend; (i)--)
#define REP(i, n) for(int (i) = 0, TMPend = (n); (i) < TMPend; (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0, TMPend = (n); (i) < TMPend; (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int n;
double dp[301][301][301];
double dfs(int n1, int n2, int n3) {
  if (n1 == 1 && n2 == 0 && n3 == 0) {
    return n;
  }

  if (dp[n1][n2][n3] > -1) {
    return dp[n1][n2][n3];
  }

  double r = n;
  if (n1 > 0) r += dfs(n1 - 1, n2, n3) * n1;
  if (n2 > 0) r += dfs(n1 + 1, n2 - 1, n3) * n2;
  if (n3 > 0) r += dfs(n1, n2 + 1, n3 - 1) * n3;
  r /= n1 + n2 + n3;
  dp[n1][n2][n3] = r;
  return r;
}

int main(){
  memset(dp, 0, sizeof(dp));
  int input(N);
  n = N;
  int list_input(a, n);
  int cnt[3 + 1] = {0};
  forin(i, a) {
    cnt[i] += 1;
  }
  // printf("%.14f\n", dfs(cnt[1], cnt[2], cnt[3]));
  rep(k, n + 1) {
    rep(j, n + 1 - k) {
      rep(i, n + 1 - k - j) {
        if (i == 0 && j == 0 && k == 0) continue;
        double r = n;
        if (i > 0) r += dp[i - 1][j][k] * i;
        if (j > 0) r += dp[i + 1][j - 1][k] * j;
        if (k > 0) r += dp[i][j + 1][k - 1] * k;
        r /= i + j + k; 
        dp[i][j][k] = r;
      }
    }
  }

  printf("%.14f\n", dp[cnt[1]][cnt[2]][cnt[3]]);
}


Measured memory_bytes: 213376
#include <iostream>
#include <vector>
#include <string>

using namespace std;

void solve()
{
	string str;
	while(cin >> str)
	{
		char field[11][12];
		for(int i = 0; i < 11; ++i)
		{
			for(int j = 0; j < 12; ++j)
			{
				field[i][j] = '0';
			}
		}
		for(int i = 0; i < str.size(); ++i)
		{
			field[0][i + 1] = str[i];
		}
		for(int i = 0; i < 7; ++i)
		{
			cin >> str;
			for(int j = 0; j < str.size(); ++j)
			{
				field[i + 1][j + 1] = str[j];
			}
		}
		for(int i = 0; i < 8; ++i)
		{
			for(int j = 1; j < 9; ++j)
			{
				if(field[i][j] == '1')
				{
					if(field[i][j + 1] == '1' && field[i + 1][j] == '1' && field[i + 1][j + 1] == '1')
					{
						cout << "A" << endl;
					}
					if(field[i + 1][j] == '1' && field[i + 2][j] == '1' && field[i + 3][j] == '1')
					{
						cout << "B" << endl;
					}
					if(field[i][j + 1] == '1' && field[i][j + 2] == '1' && field[i][j + 3] == '1')
					{
						cout << "C" << endl;
					}
					if(field[i + 1][j - 1] == '1' && field[i + 1][j] == '1' && field[i + 2][j - 1] == '1')
					{
						cout << "D" << endl;
					}
					if(field[i][j + 1] == '1' && field[i + 1][j + 1] == '1' && field[i + 1][j + 2] == '1')
					{
						cout << "E" << endl;
					}
					if(field[i + 1][j] == '1' && field[i + 1][j + 1] == '1' && field[i + 2][j + 1] == '1')
					{
						cout << "F" << endl;
					}
					if(field[i + 1][j - 1] == '1' && field[i + 1][j] == '1' && field[i][j + 1] == '1')
					{
						cout << "G" << endl;
					}
				}
			}
		}
	}
}

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

Measured memory_bytes: 1176
#include<iostream>
using namespace std;
int n,ans=1,a[100],b[100];
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=0;i<n;i++){
        int cnt=0;
        for(int k=0;k<=i;k++)cnt+=a[k];
        for(int j=i;j<n;j++)cnt+=b[j];
        if(ans<cnt)ans=cnt;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
ll cnt = 0;
ll gcd(ll x,ll y){
   return y ? gcd( y , x%y ) : x;
}



int main(){
   string s;    cin >> s;
   int n=s.size();
   vector<char>t(n),u(n);

   
   for(int i=0;i<n;i++){
       if(i%2 == 0){
           t.at(i) = '0';
           u.at(i) = '1';
       }else{
           t.at(i) = '1';
           u.at(i) = '0';
       }
   }


   int a=0,b=0;

   for(int i=0;i<n;i++){
       if(s.at(i) != t.at(i))a++;
       if(s.at(i) != u.at(i))b++;
   }

   cout << min (a,b) << endl;
   
}

Measured memory_bytes: 512
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;

    vector<int> h(N);
    REP(i, N) cin >> h[i];

    int ans = 0;
    while(true) {
        bool f = true, s = false;

        REP(i, N) {
            if (h[i] != 0) {
                h[i]--;
                f = false;
                s = true;
            } else if(s) {
                ++ans;
                s = false;
            }
        }

        if (s) ++ans;

        if (f) break;
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    vector<int>a(n);
    for (int &x : a) scanf("%d", &x);
    // dp[i] la TRUE neu First win va su dung i stone
    vector<int>dp(k + 1, false);
    for (int i = 0; i <= k; i++){
        for (int j = 0; j < n; j++){
            if (i - a[j] >= 0 && !dp[i-a[j]])
                dp[i] = true;
        }
    }
    //for (int i = 0; i <= k; i++) cout << dp[i] << " ";
    if (dp[k]) puts("First");
    else puts("Second");
}


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

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

using namespace std;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

void DFS(int N, vector<vector<int>> & bits, vector<int> vec) {
	if (vec.size() == N)bits.push_back(vec);
	else {
		vector<int> tmp = vec;
		tmp.push_back(1);
		DFS(N, bits, tmp);
		tmp = vec;
		tmp.push_back(0);
		DFS(N, bits, tmp);
	}
}

int main() {
	int H, W, K; cin >> H >> W >> K;
	vector<vector<char>> c(H, vector<char>(W));
	rep(i, H) {
		rep(j, W)cin >> c[i][j];
	}
	int ans = 0;
	vector<vector<int>> bits;
	DFS(H + W, bits, vector<int>());
	//cout << bits.size() << endl;

	int count = 0;
	rep(i, bits.size()) {
		rep(j, H) {
			if (bits[i][j] == 0) {
				rep(k, W) {
					if (bits[i][H + k] == 0) {
						if (c[j][k] == '#')++count;
					}
				}
			}
		}
		if (count == K)++ans;
		count = 0;
	}
	cout << ans;
}



Measured memory_bytes: 3964
N = int(input())
G = [input() for k in range(N)]
ans = 0
for B in range(N):
    temp = [[""]*N for k in range(N)]
    f = 1
    for i in range(N):
        for j in range(N):
            temp[i][j] = G[i][(j+B)%N]
            if temp[j][i] != "":
                if temp[i][j] != temp[j][i]:
                    f = 0
                    break
    ans += f*N

print(ans)


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mod = 1e9+7;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,k;
    cin>>n>>k;
    vector<int> x,y;
    vector<pair<int,int>> b(n);
    for(auto & a : b) cin>>a.first >> a.second,x.push_back(a.first),y.push_back(a.second);
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    ull ret = (1ull<<62);
    for(int l=0;l<n;++l){
        for(int r=l+1;r<n;++r){
            for(int d=0;d<n;++d){
                for(int u=d+1;u<n;++u){
                    int count = 0;
                    for(int i=0;i<n;++i){
                        if(x[l] <= b[i].first and b[i].first <= x[r] and y[u] >= b[i].second and b[i].second >= y[d])count++;
                    }
                    if(count >= k)ret = min(ret,1ull*abs(x[r] - x[l])*abs(y[u] - y[d]));
                }
            }
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3644
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	ll res = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (i % 3 != 0 && i % 5 != 0)res += i;
	}
	cout << res << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main() {
    int x=0,y=0,z=0,w=0,n=0,m=0;
cin>>x>>y;
if(x+y>=24)cout <<x+y-24;
else cout <<x+y;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int n;
int res = 1;

int main(){
  cin >> n;
  int a;
  cin >> a;
  int min = a;
  for(int i=1;i<n;i++){
    cin >> a;
    if(min>a){
      res++;
      min = a;
    }
  }
  cout << res << endl;
  return 0;
}

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

const int N = (int) 2e5+20;

int n;
int a[N];
int cnt[N];

void get(int st, int ban, int &res, int &val)
{
    res = 0;
    memset(cnt, 0, sizeof(cnt));
    for(int i = st; i < n; i += 2) cnt[a[i]]++;
    for(int i = 1; i < N; i++) if(i != ban)
    {
        if(cnt[i] > res)
        {
            val = i;
            res = cnt[i];
        }
    }
}

void work()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", a + i);

    int a, b, c, d;
    get(0, -1, a, b);
    get(1, -1, c, d);
    if(b != d)
    {
        cout <<n - a - c <<endl;
    }
    else
    {
        int u, v, x, y;
        get(0, b, u, v);
        get(1, d, x, y);
        int ans = min(n - u - c, n - x - a);
        cout <<ans <<endl;
    }
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 1408
package main

import (
	. "fmt"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, m, low int
	Scan(&n, &m, &low)
	c := make([]int, n)
	a := make([][]int, n)
	for i := range a {
		Scan(&c[i])
		a[i] = make([]int, m)
		for j := range a[i] {
			Scan(&a[i][j])
		}
	}
	ans := int(1e9)
	for sub := 0; sub < 1<<n; sub++ {
		s := 0
		level := make([]int, m)
		for i := 0; i < n; i++ {
			if sub>>i&1 == 1 {
				s += c[i]
				for j, v := range a[i] {
					level[j] += v
				}
			}
		}
		ok := true
		for _, v := range level {
			if v < low {
				ok = false
				break
			}
		}
		if ok && s < ans {
			ans = s
		}
	}
	if ans == 1e9 {
		ans = -1
	}
	Print(ans)
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	cout << s.substr(0, 3) << endl;
}


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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

int main()
{
    // Fast_IO();
    vector < pair<ll,ll> > v;
    f(i,-1000,1000) {
        ll num = i * i * i * i * i;
        v.pb(mp(num,i));
    }
    ll n = sz(v);
    ll x; cin >> x;
    f(i,0,n-1) f(j,0,n-1) {
        if(v[i].ff - v[j].ff == x) {
            cout << v[i].ss << spc << v[j].ss << endl;
            return 0;
        }
    }
    return 0;
}

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

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

    int B;
    cin >> B ;
    
    C =( A - B)*2;
    
    
	if (B * 2 <= C) {
      D += B*2 ;

      
    }
    else if (B * 2 > C){
      D += C ;

    }

  }

  cout << D << endl;

}


Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main (String[] args ) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();        
        String str = "#";
        
        while(true){
            String data = reader.readLine();
            String[] number = data.split(" ");
            int y = Integer.parseInt(number[0]);
            int x = Integer.parseInt(number[1]);
            if (x == 0 && y == 0 ) {
                break;
            }
            for ( int c = 0; c < y ; c++) {
                builder
                   .append(StringUtilsRepeat(str,x))
                   .append("\n");
            }
            builder.append("\n");
                   
        }
        System.out.print(builder);
        
    }
    public static StringBuilder StringUtilsRepeat(String str,int x) {
        StringBuilder line = new StringBuilder();
        
        for ( int i = 0; i < x ; i++) {
            line.append(str);
        }
        return line;
    }
}

Measured memory_bytes: 26488
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int X = sc.nextInt();

		boolean[] p = new boolean[100003 + 1];
		Arrays.fill(p, true);

		sc.close();

		p[0] = false;
		p[1] = false;
		for (int i = 2; i <= Math.sqrt(100004); i++) {
			if (p[i] == true) {
				for (int j = i * 2; j < p.length; j += i) {
					p[j] = false;
				}
			}
		}

		int ans = 0;
		for (int i = X; i < p.length; i++) {
			if (p[i]) {
				ans = i;
				break;
			}
		}

		out.println(ans);

	}

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


Measured memory_bytes: 22356
#include <stdio.h>

int main(void){
	int H,W;
	int i,j;
	for(;;){
	    scanf("%d %d",&H,&W);
	    if(H==0 && W==0) break;
	    for(i=0;i<H;i++){
	    	for(j=0;j<W;j++){
	        if((i+j)%2==0) printf("#");
	        else printf(".");
	    	}
	        puts("");
	    }
	    puts("");
	}
	return 0;
}

Measured memory_bytes: 588
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)

ll gcd(ll, ll);
ll lcm(ll, ll);

int main() {

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

	ll ccnt = 0, dcnt = 0;
	a--;
	ll cd = lcm(c, d);

	ccnt = a / c + a / d - a / cd;
	dcnt = b / c + b / d - b / cd;

	cout << b - dcnt - a + ccnt << endl;

	return 0;
}

ll gcd(ll m, ll n) {
	ll temp;
	while (m % n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

ll lcm(ll m, ll n) {
	return m * n / gcd(m, n);
}

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

int main(){
  long long a,b;
  long long min;
  int kouho;
 
  cin>>a>>b;
  if(a>b)
    min=b;
  else
    min=a;
  
  for(int i=1;i<=min;i++)
    if(a%i==0&&b%i==0){
      kouho=i;
    }
    cout<<a*b/kouho<<endl;
  
  return 0;
}

Measured memory_bytes: 256
def array_integer(a)
	0.upto(a.count) {|x|
		a[x] = a[x].to_i
	}
	return a
end

eof = false

until eof do
	a,op,b = STDIN.gets.split(" ")
	a,b = array_integer([a,b])

	if op == "?" then
		eof = true
		break
	end

	num =	case
				when op == "+" then a + b
				when op == "-" then a - b
				when op == "*" then a * b
				when op == "/" then a / b
			end
	puts num
end


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

bool check_prime(long n) {
  long limit = long(sqrt(n));
  for (long i = 2; i <= limit; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  int N {0};
  long total {0};
  cin >> N;
  for (int i = 0; i < N; i++) {
    long tmp;
    cin >> tmp;
    if (check_prime(tmp)) {
      total++;
    }
  }

  cout << total << endl;
}



Measured memory_bytes: 3052