akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
#include<vector> //動的配列
#include<string> 
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <cmath>



typedef long long ll;


using namespace std;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int a;
int b;
int c;


int main(){
    cin>>a>>b>>c;
    cout<<(min(a+b+1,c)+b)<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
long long c,e,f,g=0; 
long long d=0;
long long counter=0;
long long counter1=1;
string S; cin>>S;
char a=S.at(0);
char b=a;
for(long long i=1;i<S.size();i++){
if((a==S.at(i))){
counter1++;}
else{
if(g==0){
c=counter1;
counter1=1;
g++;}
counter+=counter1/2;
a=S.at(i);
counter1=1;}}
cin>>e;
if(counter1==S.size()){
f=(counter1*e)/2;}
else{
if(a==b){
d=(c+counter1)/2;
f=counter*e+d*(e-1)+counter1/2+c/2;
}
else{
counter+=counter1/2+c/2;
f=counter*e+d*(e-1);}}
cout<<f<<endl;}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        num = swap(num);
        System.out.println(num);
    }

    public static int swap(int num){
        if(num/100 == 9){
            num = num - 800;
        } else if(num/100 == 1){
            num = num + 800;
        } else {}
        
        if(num%100 >= 90 && num%100 <= 99){
            num = num - 80;
        } else if(num%100 >= 10 && num%100 <= 19){
            num = num + 80;
        } else {}

        if(num%10 == 9){
            num = num - 8;
        } else if(num%10 == 1){
            num = num + 8;
        } else {}

        return num;
    }
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main(){
	
	string s;
	int x,y;
	int sum=0;
	cin>>s;
x=	s.find("A");
y=	s.rfind("Z");
for(int i=x;i<=y;i++){
	sum++;
	
}
cout<<sum;
return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    int arr[]={0,14,2,3,4,5,6,7,8,9,10,11,12,13};
    int a,b;
    cin>>a>>b;
    if(arr[a]>arr[b])
        cout<<"Alice"<<endl;
    else if(arr[a]<arr[b])
        cout<<"Bob"<<endl;
    else
        cout<<"Draw"<<endl;
    return 0;
}


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

#define fio                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
#define time_passed 1.0 * clock() / CLOCKS_PER_SEC
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;

int main()
{
  fio;
  ll t, a, n, q, k, i, l, m, c, u, f, j, p, r, x, y, s, b, d;
  ll H, W;
  cin >> H >> W;
  vector<vector<int>> dp(H, vector<int>(W, 0));
 vector<vector<char>> v(H, vector<char>(W));
 for (i = 0; i < H; i++)
    for (j = 0; j < W; j++)cin>>v[i][j];
  
  dp[0][0] = 1;
  for (i = 0; i < H; i++)
    for (j = 0; j < W; j++)
    {
      if (v[i][j] == '#')
      {
        dp[i][j] = 0;
        continue;
      }
      if (i > 0)
        dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
      if (j > 0)
        dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
    }
  cout << dp[H - 1][W - 1];

  return 0;
}


Measured memory_bytes: 8200
#include <bits/stdc++.h>
using namespace std;
int MAXN = 100000;
vector<int> Connected(MAXN, -1);
vector<int> ForB(MAXN, 0);
vector<int> UfSize(MAXN, 1);

int root(int x)
{
  if (Connected.at(x) < 0)
    return x; // 根
  else
    return Connected.at(x) = root(Connected.at(x)); // 経路圧縮
}

bool same(int a, int b)
{
  return root(a) == root(b);
}

void unite(int x, int y)
{
  x = root(x);
  y = root(y);
  if (x == y)
    return;
  if (x > y)
    swap(x, y);
  Connected.at(y) = x;
  UfSize.at(x) += UfSize.at(y);
}

int main()
{
  int N, M, K, a, b;
  cin >> N >> M >> K;
  for (int i = 0; i < M; i++)
  {
    cin >> a >> b;
    unite(a - 1, b - 1);
    ForB.at(a - 1)++;
    ForB.at(b - 1)++;
  }
  for (int i = 0; i < K; i++)
  {
    cin >> a >> b;
    if (same(a - 1, b - 1))
    {
      ForB.at(a - 1)++;
      ForB.at(b - 1)++;
    }
  }
  for (int i = 0; i < N; i++)
  {
    cout << UfSize.at(root(i)) - ForB.at(i) - 1 << ' ';
  }
  cout << endl;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  vector<int> vec;
  int a;
  int b;
  int c;
  cin >> a >> b >> c;
  int k;
  cin >> k;
  vec.push_back(a * pow(2, k) + b + c);
  vec.push_back(a + b * pow(2, k) + c);
  vec.push_back(a + b + c * pow(2, k));
  
  cout << *max_element(vec.begin(), vec.end()) << endl;
  return 0;
}


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

int main(){
	int n[1000000]={0};
	int x, ans=0,l;
	
	for(int i=1; i<=999999; i++){
		if(i==1) n[i]=-1;
		else if(n[i]==0){
			for(int k=2; k*i<=999999; k++){
				n[k*i]=-1;
			}
		}
	}
	
	while(cin>>x){
		if(x==0) break;
		ans=0;
		l=0;
		for(int j=1; l<x; j++){
			if(n[j]==0){
				ans+=j;
				l++;
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 5072
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>
#include <climits>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int lcm(int a,int b){return a*b/gcd(a,b);}
typedef long long ll;
typedef std::vector<int> VI;
typedef std::pair<int, int> PII;

using namespace std;


int main()
{
  int a;
  cin >> a;
  cout << a * a * a << endl;
  return 0;
}


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

int K,N;

int main()
{
    cin>>K>>N;
    std::vector<int> a(N);
    cin>>a.at(0);
    int temp=0;
    for(int i=1; i<N; i++){
        cin>>a.at(i);
        temp=max(a.at(i)-a.at(i-1),temp);
    }
    temp=max(K-a.at(N-1)+a.at(0), temp);
    cout<<K-temp<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	String s1 = scan.next();
	String s2 = scan.next();
	String s3 = scan.next();

	StringBuilder str = new StringBuilder();
	str.append((char)('A' + s1.charAt(0) - 'a'));
	str.append((char)('A' + s2.charAt(0) - 'a'));
	str.append((char)('A' + s3.charAt(0) - 'a'));

	System.out.println(str.toString());
	scan.close();
    }
}


Measured memory_bytes: 23764
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <fstream>

#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

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

ll LCM(ll a, ll b) {
    return a/GCD(a,b)*b;
}

class CFiveTransportations {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll n;in>>n;
        ll mi=INF;
        ll tmp,cnt;
        rep(i,5) {
            in>>tmp;
            mi=min(tmp,mi);
        }
        ll x= n%mi==0 ? n/mi: n/mi+1;
        ll ans=5+x-1;
        out<<ans<<endl;



	}
};


int main() {
	CFiveTransportations solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;




// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    
    if(S=="ABC"){
        cout<<"ARC"<<endl;
    }else{
        cout<<"ABC"<<endl;
    }
    return 0;
}


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

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

ll A[100002];
int main() {
	int N; cin >> N;
	A[0] = 0;
	rep(i, 1, N + 1) cin >> A[i];
	A[N + 1] = 0;

	ll total = 0;
	rep(i, 0, N + 2) {
		total += abs(A[i + 1] - A[i]);
	}
	rep(i, 1, N + 1) {
		ll cost = total;
		cost -= (abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i]));
		cost += abs(A[i + 1] - A[i - 1]);
		cout << cost << endl;
	}
}

Measured memory_bytes: 2048
n=int(input())
for i in range(n):
    nmax=[]
    nmin=[]
    for ii in str(input()):
        nmax.append(ii)
        nmin.append(ii)
    nmax.sort(reverse=True)
    nmin.sort()
    ans=int("".join(nmax))-int("".join(nmin))
    print(ans)


Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

string S;
int K;
int main(){
	cin >> S;
	cin >> K;
	int N = S.size();
	map<string,int> m;
	for(int i=0;i<N;i++){
		for(int j=0;j<5;j++){
			m[S.substr(i,j+1)]++;
		}
	}
	vector<string> v;
	for(auto x:m){
		v.push_back(x.first);
	}
	sort(v.begin(),v.end());
	cout << v[K-1] << endl;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000001;
const long long LINF = 1e18;
const int MAX = 510000;

int main() {
	int n, m, cnt = 0, ans = 0;
	cin >> n;
	vector<string> s(n);

	for (int i = 0; i < n; i++) {
		cin >> s.at(i);
	}
	cin >> m;
	vector<string> t(m);
	for (int j = 0; j < m; j++) {
		cin >> t.at(j);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (s.at(i) == s.at(j))cnt++;
		}
		for (int j = 0; j < m; j++) {
			if (s.at(i) == t.at(j))cnt--;
		}
		if (ans < cnt)ans = cnt;
		cnt = 0;
	}
	cout << ans << endl;
		return 0;
	}


Measured memory_bytes: 3640
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int int64_t
#define double long double
#define pii pair<int, int>
#define pdd pair<double, double>
#define F first
#define S second
#define pb push_back
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orset;

const int N = 202000;
const int F = 10000000000;

set<int> ans;

void rec(int v, int c, int last){
   if(v)ans.insert(v);
   if(c >= F)
      return;
   if(last - 1 >= 0)
      rec(v + (last - 1) * c, c * 10, last - 1);
   if(last + 1 <= 9)
      rec(v + (last + 1) * c, c * 10, last + 1);
   rec(v + last * c, c * 10, last);
}

int32_t main(){
   ios_base :: sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   for(int i = 0; i <= 9; i ++)
      rec(i, 10, i);
   int k; cin >> k;
   int c = 0;
   for(auto it = ans.begin(); c != k; it ++){
      c ++;
      if(c == k)
         cout << *it;
   }
}


Measured memory_bytes: 9600
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
    }

    let mut ok = vec![false; n];

    for _ in 0..k {
        input! {
            d: usize,
            ax: [usize; d]
        }
        for a in ax {
            ok[a-1] = true;
        }
    }

    let count: usize = ok.iter().filter(|&x| !*x).map(|_| 1).sum();

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

Measured memory_bytes: 2208
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)

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

     ll N;ll sum=0;
  cin>> N;
   int A[N];int C[N-1];
   for(int i=0;i<N;i++)
     cin>>A[i];
  int B[N];
  for(int i=0;i<N;i++)
     cin>>B[i];
  
  for(int i=0;i<N;i++)
     cin>>C[i];
  
  int k,s=0;
  for(int i=0;i<N;i++)
  {
    
    k = A[i];
    
    if(A[i]-A[i-1]==1)
    {
      s=s+C[A[i-1]-1]+B[k-1];
    }
    else
    {
       s+= B[k-1];
    }
  }
  cout<<s<<endl;
    
    
    
  




return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn = 105;
int n, m;
int head[maxn], nxt[maxn << 1], tail[maxn << 1], ecnt = 1;
int a[maxn], x[maxn], y[maxn];
bool col[maxn << 1];
ll ans;

void addedge(int u, int v) {
	nxt[++ecnt] = head[u];
	head[u] = ecnt;
	tail[ecnt] = v;
}

bool dfs1(int u, int p, int t) {
	if (u == t) return true;
	for (int e = head[u]; e; e = nxt[e]) {
		int v = tail[e];
		if (v != p)
			if (dfs1(v, u, t)) {
				col[e] = col[e ^ 1] = true;
				return true;
			}
	}
	return false;
}

void dfs(int pos, int cnt) {
	if (pos == m + 1) {
		if (!cnt) return ;
		memset(col, false, sizeof(col));
		for (int i = 1; i <= cnt; i++) dfs1(x[a[i]], 0, y[a[i]]);
		ll tmp = ecnt - 1; // * 2
		for (int i = 2; i <= ecnt; i++) tmp -= col[i];
		tmp >>= 1;
		tmp = (1LL << tmp);
		if (cnt & 1) ans -= tmp;
		else ans += tmp;
		return ;
	}
	dfs(pos + 1, cnt);
	a[cnt + 1] = pos;
	dfs(pos + 1, cnt + 1);
	a[cnt + 1] = 0;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n - 1; i++) {
		int u, v; scanf("%d%d", &u, &v);
		addedge(u, v); addedge(v, u);
	}
	scanf("%d", &m);
	for (int i = 1; i <= m; i++) scanf("%d%d", &x[i], &y[i]);
	ans = (1LL << (n - 1));
	dfs(1, 0);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = 200000;
int n;
struct NOOD {
	int x, pos;
}a[maxn + 5];
int cnt, Max;
bool cmp(NOOD x, NOOD y) {
	return x.x < y.x;
}
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i].x);
		a[i].pos = i;
	}
	sort(a + 1, a + n + 1, cmp);
	a[0].pos = 0;
	for(int i = 1; i <= n; i++) {
		if(a[i].pos > a[i - 1].pos)cnt++;
		else {
			//printf("%d\n", cnt);
			Max = max(Max, cnt);
			cnt = 1;
		}
	}
	Max = max(Max, cnt);
	printf("%d\n", n - Max);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll  long long
#define PR  pair<int, int>

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long x, k, d;
    cin >> x >> k >> d;
    long long ned = abs(x) / d;
    long long rem = abs(x) % d;
    long long now = abs(x) - (min(ned, k) * d);
    k -= min(k, ned);
    if (k % 2) {
        cout << min(now + d, abs(now - d)) << '\n';
    } else {
        cout << now << '\n';
    }
    return 0;
}


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

using namespace std;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

int n;
VV<int> g;

int dfs(int v) {
    V<int> st;
    for (int u: g[v]) {
        st.push_back(dfs(u));
    }
    sort(st.begin(), st.end());
    int g = 0;
    for (int d: st) {
        g = max(g, d) + 1;
    }
    return g;
}

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

    cin >> n;
    g = VV<int>(n);
    for (int i = 1; i < n; i++) {
        int p;
        cin >> p; p--;
        g[p].push_back(i);
    }
    cout << dfs(0) << "\n";
    return 0;
}


Measured memory_bytes: 13568
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

bool cmp(pll p1, pll p2){
    return p2.first * (1+p1.second) < p1.first * (1+p2.second);
}

class DMangaMarket {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        lint T;
        in>>N>>T;
        vc<pll> A;
        vc<lint> B;
        REP(i, N){
            lint a, b;
            in>>a>>b;
            if(a) A.pb(mp(a, b));
            else B.pb(b);
        }
        sort(ALL(A), cmp);
        sort(ALL(B));
        int M = LEN(A), K = LEN(B);
        vvc<lint> dp(M+1, vc<lint>(31, 2*ten(9)));
        REP(i, M+1) dp[i][0] = 0;
        RREP(i, M) RREP(j, 30){
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-1]+1+A[i-1].first*(dp[i-1][j-1]+1)+A[i-1].second);
        }
        int ans = 0;
        REP(i, 31){
            int tmp = i;
            if(dp[M][i]>T) continue;
            lint cur = dp[M][i];
            REP(j, K){
                if(cur+1+B[j]>T) break;
                cur += B[j] + 1;
                ++tmp;
            }
            chmax(ans, tmp);
        }
        out<<ans<<'\n';
    }
};


int main() {
	DMangaMarket solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	int m = 2;
	while(1){
		int t = m * (m - 1) / 2;
		if(t < n){
			m++;
		}else if(t == n){
			break;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}
	vector<vector<int>> a(m, vector<int>());
	int cnt = 1;
	for(int i = 0; i < m - 1; i++){
		for(int j = i + 1; j < m; j++){
			a[i].emplace_back(cnt);
			a[j].emplace_back(cnt);
			cnt++;
		}
	}
	cout << "Yes" << endl;
	cout << m << endl;
	for(int i = 0; i < m; i++){
		cout << m - 1 << " ";
		for(int j = 0; j < m - 1; j++){
			cout << a[i][j];
			if(j < m - 1){
				cout << " ";
			}
		}
		cout << endl;
	}
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> color(8, 0);
    int variable = 0;
    rep(i, N) {
        int tmp;
        cin >> tmp;
        if (tmp < 3200) color[tmp/400] = 1;
        else variable += 1;
    }
    int cnt = 0;
    rep(i, 8) if (color[i] == 1) cnt += 1;
    int ans1 = cnt, ans2 = cnt;
    ans1 = max(1, cnt);
    ans2 = cnt + variable;
    printf("%d %d", ans1, ans2);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (a).size()
#define pb(a) push_back(a)
#define eb(...) emplace_back(__VA_ARGS__)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr double EPS = 1e-10;

int N;
int a[110];
int flag[110];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  rep(i, 0, N) cin >> a[i];
  int ans = 0;
  rep(i, 1, N) {
    if (flag[i-1]) continue;
    if (a[i-1] == a[i]) {
      ans++;
      flag[i] = 1;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
	int N;
	cin >> N;
	int dp[N],h[N];
	for(int i=0;i<N;i++){
		cin >> h[i];
		dp[i] = INF;
	}
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	for(int i=2;i<N;i++){
		dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
use proconio::input;

fn main() {
	input! {
		n: u32,
	}
	let ans = match n % 10 {
		2 | 4 | 5 | 7 | 9 => "hon",
		0 | 1 | 6 | 8 => "pon",
        3 => "bon",
		_ => "hoge",
	};
	println!("{}", ans);
}


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

//TO_STRING
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(char ch){
  string s;
  s += ch;
  return s;
}

string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + 
    to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + 
    to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

//DEBUG 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL //compile with -DLOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vvi> vvvi;

#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
#define fi first
#define se second  
#define sz(x) ((int)x.size())


void solve() {
	int n;
	cin >> n;
	vi cnt(n + 1);
	for (int i = 2; i <= n; i++) {
		int x;
		cin >> x;
		cnt[x]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << cnt[i] << "\n";
	}
}	

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0); 
  
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

int main() {
    ll n;
    cin >> n;
    vector<ll> a;
    rep(i, n) {
        ll num;
        cin >> num;
        a.push_back(num);
    }

    sort(a.begin(), a.end(), greater<ll>());

    vector<pair<ll, ll>> v;
    pair<ll, ll> PAIR1;
    PAIR1.first = a[0];
    PAIR1.second = a[0];
    v.push_back(PAIR1);

    ll score = 0;
    for (ll ii = 1; ii < n; ii++) {
        score += v[ii-1].first;

        ll fnum = v[ii-1].first;
        ll snum = v[ii-1].second;
        pair<ll, ll> pair1;
        pair1.first = a[ii];
        pair1.second = snum;
        v.push_back(pair1);
        pair<ll, ll> pair2;
        pair2.first = a[ii];
        pair2.second = fnum;
        v.push_back(pair2);
    }

    cout << score << endl;
}

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

int main()
{
  int N;
  cin >> N;
  vector<long long> A(N+1);
  vector<long long> B(N);
  for (auto i = 0; i < N+1; i++) cin >> A[i];
  for (auto i = 0; i < N; i++) cin >> B[i];
  
  long long m = 0;

  for (auto i = 0; i < N; i++) {
    if (A[i] <= B[i]) {
      m += A[i];
      B[i] -= A[i];
      A[i] = 0;
      if (A[i+1] < B[i]) {
        m += A[i+1];
        B[i] -= A[i+1];
        A[i+1] = 0;
      } else {
        m += B[i];
      	A[i+1] -= B[i];
        B[i] = 0;
      }
    } else {
      m += B[i];
      A[i] -= B[i];
      B[i] = 0;
    }
  }
  
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n;
  cin >> n;
  cout << n/2 + n%2;
}

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

ans = 1
cnt = [0] * (n)

for i in d:
  cnt[i] += 1

if d[0] != 0 or cnt[0] > 1:
  ans = 0
else:
  for i in range(2,n):
    ans *= cnt[i-1] ** cnt[i]
    ans %= 998244353

print(ans)

Measured memory_bytes: 53300
#include "bits/stdc++.h"
using namespace std;

double PI = 3.141592653589793238462643383279502884197;

int main() {
	long long N;
	vector<pair<pair<long long, long long>, long long> > V;
	cin >> N;
	V.resize(N);
	for (int i = 0; i < N; i++) cin >> V[i].first.first >> V[i].first.second, V[i].second = i;
	sort(V.begin(), V.end());
	vector<long long> L;
	long long A = 0;
	do {
		L.push_back(A);
		long long B = 0;
		for (int i = 1; i < N; i++) {
			if (B == A) B = i;
			else {
				pair<long long, long long> AB, AC;
				AB.first = V[B].first.first - V[A].first.first;
				AB.second = V[B].first.second - V[A].first.second;
				AC.first = V[i].first.first - V[A].first.first;
				AC.second = V[i].first.second - V[A].first.second;
				long long X = AB.first * AC.second - AB.second * AC.first;
				if (X > 0 || (X == 0 && AC.first * AC.first + AC.second * AC.second > AB.first * AB.first + AB.second * AB.second)) B = i;
			}
		}
		A = B;
	} while (A != 0);
	vector<double> ANS(N, 0);
	for (int i = 0; i < L.size(); i++) {
		long long Now = i;
		long long Left = (i + L.size() - 1) % L.size();
		long long Right = (i + 1) % L.size();
		pair<double, double> LP, RP;
		LP.first = V[L[Now]].first.second - V[L[Left]].first.second;
		LP.second = V[L[Left]].first.first - V[L[Now]].first.first;
		RP.first = V[L[Right]].first.second - V[L[Now]].first.second;
		RP.second = V[L[Now]].first.first - V[L[Right]].first.first;
		double LA, RA;
		LA = atan2(LP.first, LP.second);
		RA = atan2(RP.first, RP.second);
		double Angle;
		if (LA < RA) Angle = RA - LA;
		else Angle = 2 * PI - (LA - RA);
		ANS[V[L[Now]].second] = Angle / (PI * 2);
	}
	for (int i = 0; i < N; i++) printf("%.12lf\n", ANS[i]);
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}



int main(){
    int n;cin >> n;
    ll a[n+1]; //敵の数
    ll b[n]; //勇者の数
    ll ans=0;
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    

    rep(i,n){
        ans+=min(a[i],b[i]);
        ans+=min(a[i+1],b[i]-min(a[i],b[i])); //b[i]-min(a[i],b[i])が勇者の残りHP
        a[i+1]=a[i+1]-min(a[i+1],b[i]-min(a[i],b[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;


int main(){

	int N;

	int tmp;
	cin >> N;


	tmp = int(N / 1.08 + 0.5) * 0.08;
	int ans = N - tmp;

	if (int(ans * 1.08) == ans + tmp){
		cout << ans;
	}
	else{
		cout << ":(";
	}


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define f(i,o,n) for(i=o;i<n;i++)
#define pb push_back
#define vll vector<ll>
#define s(x) sort(x.begin(),x.end())
using namespace std;

int main() {
    ll n,x,t;
    cin>>n>>x>>t;
    ll j,k;
    j=n/x;
    if(n%x!=0)  j++;
    cout<<j*t<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  //最小本数をマックスまで取る。
  //同じ本数の場合は数字が大きいものだけ。
  //priority_queueで1つずつ出して出力っぽい。桁数的に。配列でもいいけど
  //ぴったりとれるか判定が難しい･･･。
  //1つの数字をマッチに戻して、最小本数以外で満たす組み合わせがあるか都度確認か
  //より少ない本数のものを最大とって、それ以降の探索
  //だめなら放流して次の数、とか
  //あまり数、
  //3,7とか。あまり1,4,7で7で判定
  //4,6,7とか。余り1,5,9,13で67判定、あまり2,6はんてい,あまり3、7判定
  //ぴったりとれる組み合わせがわからぬ
  //ひらめかないな
  //457で、57でとりうる組み合わせ。5,7,10,12,14,15くらい用意するとか
  //数字がわかったところでそれがどんな組み合わせかわからねえ
  //0,0 1,0 0,1 1,1 2,0 0,2
  //あまりを出す？1とか2とか。3とか。
  //2,5,7だったときに0,1,1になるか。5をとるべきが判定不能
  //4,5,7 0,1,3になるもし余りが1だったら5、3なら7をとる。
  //4,6,7で0,2,3。４ふえたときにずれるからだめ。
  //ひらめかないなあ
  //ぴったりとる、が鬼門。
  //はじめにひくか。
  //使用本数出して、最小以外のものの組み合わせをある程度出す。
  //1個選ぶ場合、2個選ぶ場合。最大2個までかな。
  //3,5,6,7とか。14がきたら、5ひいて3の倍数。16がきたら、7ひいて３のばいすう
  //11がきて、65をとるか74をとるか迫られたとき、つむな。かならず最小をとればいいわけでもなさそうだ
  //最小使用本数の倍数にあるときは、それを並べるのが正解
  //そうじゃないとき。
  //13で4,6,7は、67をとる。しかし444+1で3桁まで視野にはいってしまう
  //444+1で出来ない４けた
  //44+5でできない3けた
  //4+9でできない2けた
  //13で67ができたみたいな？
  //14のときは？
  //4442
  //446で完
  //11のとき
  //443でできない
  //47でできた。しかし56が答えだったら終了
  //使える本数で最大組み合わせをだしておくべきか
  //4=4,5=0,6=6,7=7,8=44,9/4=2で2桁、みたいなことか
  //13/4=3,445,
  //15/4=3,447,456とか。この判定どうする
  //何桁なのか定まる必要がある。
  //4,6,7において、9=0 10=2 11=2 12=3 13=2 14=3
  //13の特殊性･･･。
  //4=1,8=2,12=3,16=4･･･としておけば、4+7no11=2,DP的に桁数だせそう
  //9通り*10^4ならすべて検査できそう
  //4,6,7なら、まず4の倍数。次に6+4の倍数。次に7+4の倍数、次に6+6+4の倍数、、、
  //法則違うな。全部やるか。4,6,7, 4+[4,6,7], 6+[4,6,7], 7+[4,6,7];
  //D[4]=1,D[6]=1,D[7]=1が初期として。。。どう展開させるのか。
  //D[10]=D[6]+1;
  //D[4n]=D[4(n-1)]+1;
  //D[i]=D[i-n]+1; nは入りうるマッチ数。0<=i<=10000でうめられるかも
  //桁数とったら。数字が何かを探す。
  //D[N-A]=D[N]-1になっているようなもののうち、Aの最も数字の大きい値をとる、でいける。
  
  ll N,M,A;
  cin>>N>>M;
  vector<int> D(N+100,-1000000),Z(0,0);
  D[0]=0;
  int set[10]={0,2,5,5,4,5,6,3,7,6};
  unordered_map<int,int> MtoP;
  for(int i=0; i<M; i++){
    int A;
    cin>>A;
    MtoP[set[A]]=max(MtoP[set[A]],A);
    Z.push_back(set[A]);
  }
  sort(Z.begin(), Z.end());
  Z.erase(unique(Z.begin(), Z.end()), Z.end());
  int x=Z.size();
  for(int i=0; i<x; i++)
    D[Z[i]]=1;
  for(int i=0; i<=N; i++){
    for(int j=0; j<x; j++){
      if(i-Z[j]<0)
        continue;
      D[i]=max(D[i],D[i-Z[j]]+1);
    }
  }
  //Zの順番を、数字が大きい順に並べ替えたい
  vector<vector<int>> Y(x,vector<int>(2,0));
  for(int i=0; i<x; i++){
    Y[i][0]=Z[i];
    Y[i][1]=MtoP[Z[i]];
  }
  sort(Y.begin(), Y.end(), [](auto& h, auto&k){return h[1] > k[1];});
  while(N>0){
    for(int j=0; j<x; j++){
      if(N-Y[j][0]<0)
        continue;
      if(D[N]==D[N-Y[j][0]]+1){
        N-=Y[j][0];
        cout<<Y[j][1];
        break;
      }
    }
  }
  cout<<endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = 2019LL;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

template<typename T>
T power(T x, long long n, const T &m){
    if(n == 0) return 1;
    if(n == 1) return x;
    T tmp = power(x, n/2, m);
    if(n%2 == 0) return tmp * tmp % m;
    else return tmp * tmp % m * x % m;
}

string S;
int sum[200000];
unordered_map<int, int> m;

signed main(){
	cin >> S;
    ll ans = 0;
    m[0] = 1;
    rep(i, S.size()){
        sum[i] = (i!=0 ? sum[i-1] : 0) * 10 + (S[i]-'0');
        sum[i] %= MOD;
        ll tmp = sum[i] * power(10LL, S.size()-i, MOD) % MOD;
        if(m.count(tmp) == 0) m[tmp] = 0;
        ans += m[tmp];
        m[tmp]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4492
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n = in();
  vi a(n);
  rep(i,n) cin >> a[i];
  int mi = INF;
  int ma = -INF;
  ll tot = 0;
  rep(i,n) {
    if (a[i] < mi) mi = a[i];
    if (a[i] > ma) ma = a[i];
    tot += a[i];
  }
  printf("%d %d %lld\n", mi, ma, tot);
  return 0;
}


Measured memory_bytes: 3228
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359

int main(){
  ll n;
  cin>>n;
  n = n/2;

  
  vector<ll> a(100000,0);
  vector<ll> b(100000,0);

ll tmp,tmp1;
  for(ll i=0;i<n;i++){
cin>>tmp>>tmp1;
a[tmp]++;
b[tmp1]++;
  }


  ll am = distance(a.begin(),max_element(a.begin(),a.end()));
    ll bm = distance(b.begin(),max_element(b.begin(),b.end()));

if(am!=bm){
  cout<<2*n-a[am]-b[bm]<<endl;
}
else{
    ll ram = a[am];
    ll rbm = b[bm];

  
  

a[am]=-100;
    b[bm]=-100;

       am = distance(a.begin(),max_element(a.begin(),a.end()));
     bm = distance(b.begin(),max_element(b.begin(),b.end()));

    ll r2am = a[am];
    ll r2bm = b[bm];
     

    ll ans = min(2*n-ram-r2bm,2*n-r2am-rbm);
    cout<<ans<<endl;


  
}



  


}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int n, m, l[100000], r[100000], a[100002], c[100002];
int main() {
    cin >> n >> m;
    for(int i = 0; i < m; ++i)
        cin >> l[i] >> r[i];
    for(int i = 0; i < m; ++i)
        a[l[i]] += 1, a[r[i] + 1] += -1;
    c[1] = a[1];
    for(int i = 2; i <= n; ++i)
        c[i] = c[i - 1] + a[i];
    int rj = 0;
    
    for(int i = 1; i <= n; ++i)
        if(c[i] == m)
            ++rj;
    cout << rj << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
	int a,b,c,d,p,x,y;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&p);
	x=a*p;
	if(c>=p){
		y=b;
	}
	else{
		y=b+d*(p-c);
	}
	if(x<y){
		printf("%d\n",x);
	}
	else{
		printf("%d\n",y);
	}
return 0;;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
//#define debug1 cout<<"?"<<endl;
//#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=3e5+9;
const double pi=acos(-1);
const int mod=998244353;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	int n,p,i;
	char s[maxn];
	scanf("%d%d",&n,&p);
	scanf("%s",s+1);
	ll ans=0;
	if(p==2||p==5)
	{
		for(i=1;i<=n;i++)
		{
			if((s[i]-'0')%p==0)ans+=i;
		}
		printf("%lld\n",ans);return 0;
	}
	int cur[maxn]={1},base=1,now=0;
	for(i=n;i>=1;i--)
	{
		int num=(s[i]-'0')%p;
		now=(now+num*base)%p;
		ans+=cur[now];
		cur[now]++;
		base=(base*10)%p;
	}
	printf("%lld\n",ans);
}

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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,k,dp[2001][2001];

signed main() {
    cin >> n >> k;
    dp[0][0] = 1;
    rep1(i,2000) rep(j,i+1) {
        if (j) dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
        else dp[i][j] = dp[i-1][j];
        dp[i][j] %= MOD;
    }
    rep1(i,k) cout << (dp[n-k+1][i] * dp[k-1][i-1])%MOD << endl;
}



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

using namespace std;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  int ans = 0;
  for (int i = 0; i < N-2; i++) {
    if (S.substr(i, 3) == "ABC") {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 2e9
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	char c;
	cin >> c;
	if (c - 'A' < 26)cout << "A" << endl;
	else cout << "a" << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <iterator>
#include <cmath>
#include <map>
using namespace std;


void func160a() {
  string s;
  cin >> s;
  if ((s.at(2) == s.at(3))&&(s.at(4) == s.at(5))) {
    cout << "Yes" << "\n";
  }else{
    cout << "No" << "\n";
  }
}



int main(void) {
  func160a();
  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n";
using namespace std;
using ll=long long;
using ld=long double;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class CBBuBBBlesort {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int n;
	    in >> n;
	    vector<ll> a(n);
	    for(int i=0; i<n; i++){
	        in >> a[i];
	    }

	    set<int> eve, odd;
	    for(int i=0; i<n; i++){
	        if(i%2 == 0) eve.insert(a[i]);
	        else odd.insert(a[i]);
	    }

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

	    int res = 0;
	    for(int i=0; i<n; i++){
            if(i%2 == 0){
                if(eve.find(a[i]) == eve.end()) res++;
            }
	    }

	    out << res << endl;
	}
};


int main() {
	CBBuBBBlesort solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e9;
int dp[1000005][2];
int main(){
	string s;
	cin >> s;
	s='0'+s+'0';
	for(int i=0; i<s.size(); i++)
		s[i]-='0';
	dp[0][1]=Inf;
	for(int i=1; i<=s.size()-1; i++){
		dp[i][0]=min(dp[i-1][0]+s[i],dp[i-1][1]+s[i]+1);
		dp[i][1]=min(dp[i-1][0]+10-s[i],dp[i-1][1]+9-s[i]);
	}
	cout<<dp[s.size()-1][0]<<endl;
	return 0;
}


Measured memory_bytes: 9136
import sys


class UnionFind:
    def __init__(self, n=0):
        self.d = [-1]*n
        self.u = n

    def root(self, x):
        if self.d[x] < 0:
            return x
        self.d[x] = self.root(self.d[x])
        return self.d[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return False
        if x > y:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        self.u -= 1
        return True

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.d[self.root(x)]

    def num_union(self):
        return self.u


def c2(n):
    return n*(n-1)//2


N, M = map(int, sys.stdin.readline().split())
E = []
for line in sys.stdin:
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    E.append((a, b))

u = UnionFind(N)
r = c2(N)
result = [r]
for a, b in E[::-1]:
    na = u.size(a)
    nb = u.size(b)
    if u.unite(a, b):
        r -= na*nb
    result.append(r)

for r in result[-2::-1]:
    print(r)


Measured memory_bytes: 28052
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp1
{
    public class Program
    {
        static void Main(string[] args)
        {
            var a = Hoge(ReadLine());

            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);
            WriteLine(a);
            Out.Flush();
        }

        public static int Hoge(string s)
        {
            var n = short.Parse(s);
            return n / 3;
        }
    }




}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	int C = sc.nextInt();
	int D = 0;

	D = A;
	A = C;
	C = B;
	B = D;
	System.out.println(A + " " + B  + " " + C);
    }
}


Measured memory_bytes: 23380
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int N, K;
  string S;
  cin >> N >> K >> S;
  int same = 0;
  rep(i, N-1) {
    if(S[i] == S[i+1])
      same++;
  }
  cout << min(same+K*2, N-1) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  double t = 0;
  for (int i = 0; i < n; i++){
    cin >> a[i];
    t += (double)a[i];
  }
  t /= (4.0 * double(m));
  int cnt = 0;
  for (int i = 0; i < n; i++){
    if (a[i] >= t){
      cnt++;
    }
  }
  cout << (cnt >= m ? "Yes\n" : "No\n");

  return 0;
}


Measured memory_bytes: 256