akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// DEBUG

#define debug(X) { cerr << #X << " = " << (X) << endl; }
#define debug_arr(X) { cerr << #X << " = "; for(auto e : X) cerr << e << " "; cerr << endl; }
#define debug_func(f,x) { cerr << #f << "(" << (x) << ") = " << (f((x))) << endl; }
#define debug_func2(f,x,y) { cerr << #f << "(" << (x) << "," << (y) << ") = " << (f((x),(y))) << endl; }

template<class T> ostream& print_collection(ostream& s, T const& a){
    s << '[';
    for(auto it = begin(a); it != end(a); ++it){
        s << *it;
        if(it != prev(end(a))) s << " ";
    }
    return s << ']';
}

template<class T, size_t N>
ostream& operator<<(ostream& s, array<T, N> const& a) { return print_collection(s, a); }
template<class T>
ostream& operator<<(ostream& s, vector<T> const& a) { return print_collection(s, a); }
template<class T, class U>
ostream& operator<<(ostream& s, multimap<T, U> const& a) { return print_collection(s, a); }
template<class T>
ostream& operator<<(ostream& s, multiset<T> const& a) { return print_collection(s, a); }
template<class T, class U>
ostream& operator<<(ostream& s, map<T, U> const& a) { return print_collection(s, a); }
template<class T>
ostream& operator<<(ostream& s, set<T> const& a) { return print_collection(s, a); }
template<class A, class B>
ostream& operator<<(ostream& s, pair<A, B> const& a) { return s << "(" << (a).first << ", " << (a).second << ")"; }

// MISC.

#define endl '\n'

#define FOR(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FORU(i, j, k) for(ll i = (ll)(j); i <= (ll)(k); ++i)
#define FORD(i, j, k) for(ll i = (ll)(j); i >= (ll)(k); --i)

#define SQ(x) ((x) * (x))

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second

#define X(A) get<0>(A)
#define Y(A) get<1>(A)
#define Z(A) get<2>(A)
#define W(A) get<3>(A)

using ll = long long int;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using ti = tuple<int, int, int>;
using tl = tuple<ll, ll, ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vti = vector<ti>;
using vtl = vector<tl>;
using ppi = pair<pi, int>;
using ppl = pair<pl, ll>;
template<class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> using max_queue = priority_queue<T>;

const ll MOD = 1e9 + 7;
const int INF = 1e9;
const ll INF_LL = 1e18;

// END TEMPLATE
// ----------------------------------------------------------------------------


int main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;

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


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    if(n&1){
    	ll sum = 0, m = -a[0], num = m;
    	for(int i=0;i<n;i+=2) sum += a[i];
    	for(int i=2;i<n;i+=2) m = max(m + a[i-1],0LL) - a[i], num = max(num,m);
    	cout << sum + num <<endl;
    }
    else{
    	vector<ll> b(n+1,0);
    	for(int i=n-2;i>=0;i-=2) b[i] = b[i+2] + a[i+1];
    	ll sum=0,ans=-1e18;
    	for(int i=0;i<n;i+=2) ans = max(ans,sum+b[i]), sum += a[i];
        cout << max(ans,sum) <<endl;
    }
    return 0;
}


Measured memory_bytes: 6316
#include<iostream>
#include<string>
using namespace std;
int main(){
   char c;
   cin>>c;
   if(!(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')){
   cout<<"consonant"<<endl;
}
   else{
       cout<<"vowel"<<endl;
   }
       
   }

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    ll A, B, K;
    cin >> A >> B >> K;
    if (K >= A) {
        K = K - A;
        A = 0;
        if (K >= B) {
            B = 0;
        } else {
            B = B - K;
        }
    } else {
        A = A - K;
    }
    cout << A;
    cout << " ";
    cout << B << endl;
    return 0;
}

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

public class Main {
	private final static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	
	private final static StringBuilder sortedSeq = new StringBuilder();
	private final static String lb = System.getProperty("line.separator");
	
	public static void main(String[] args) {
		int[] seq = null;
		try {
			seq = getSeqence();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		seq = insertionSort(seq);
		System.out.print(sortedSeq.toString());
	}
	
	public static int[] insertionSort(final int[] seq) {
		for (int i = 1; i < seq.length; i++) {
			final int key = seq[i];
			int j = i-1;
			while (0 <= j && key < seq[j]) {
				seq[j+1] = seq[j];
				j--;
			}
			seq[j+1] = key;
			
			for (int k = 0; k < seq.length; k++) {
				sortedSeq.append(String.valueOf(seq[k])).append(k < seq.length-1 ? " " : lb);
			}
		}
		
		return seq;
	}
	
	public static int[] getSeqence() throws IOException {
		int n = Integer.parseInt(reader.readLine());
		String[] line = reader.readLine().split("[\\s]+");
		reader.close();
		
		int[] seq = new int[n];
		for (int i = 0; i < seq.length; i++) {
			seq[i] = Integer.parseInt(line[i]);
			sortedSeq.append(String.valueOf(seq[i])).append(i < n-1 ? " " : lb);
		}
		
		return seq;
	}
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

int N;
set<string> ans;

void dfs(int i, int big, string s) {
    if(i >= N) {
        ans.insert(s);
        return;
    }
    for(int j = 0; j <= big + 1; ++j) {
        char c = 'a' + j;
        int next_big = max(j, big);
        dfs(i + 1, next_big, s + c);
    }
}

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

    cin >> N;
    dfs(1, 0, "a");

    for(auto& s : ans){
        cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 12416
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> A(m);
	rep(i,m) {
		int a, b;
		cin >> a >> b;
		A[i] = make_pair(b - 1, a - 1);
	}
	sort(A.begin(), A.end());

	int count = 0, pos = -100;
	rep(i,A.size()) {
		if (A[i].second > pos) {
			count++;
			pos = A[i].first - 1;
		}
	}
	cout << count << endl;
	return 0;
}


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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int cnt = 0;
    while(a >= b) {
        b *= 2;
        cnt++;
    }
    while(b >= c) {
        c *= 2;
        cnt++;
    }
    if (k >= cnt) cout << "Yes" << endl;
    else cout << "No" << endl;
return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int n,m;
    cin>>n;
    cout<<"ABC"<<n<<NL;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int k,a[5];

int main(){
    rep(i,5)cin>>a[i];
    cin>>k;
    rep(i,5){
        repi(j,i,5){
            if(a[j]-a[i]>k){
                out(":(");
                return 0;
            }
        }
    }
    out("Yay!");
}


Measured memory_bytes: 256
import Control.Monad.Trans.State (get, modify, evalState)
import qualified Data.Map.Strict as M

f n
  | even n = div n 2
  | odd  n = 3 * n + 1

solv s = flip evalState (M.fromList [(s,1)]) $ go 2 s where
  go i prev = do
    let next = f prev
    m <- get
    case M.lookup next m of
      Just _ -> return i
      Nothing -> do
        modify (M.insert next i)
        go (i+1) next

main = do
  s <- read <$> getLine :: IO Int
  print $ solv s


Measured memory_bytes: 508
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC omodtimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long ,long> ii; 	
typedef complex<long double> com;
 
const ll mod = 998244353;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	vector <ll> red(a);
	vector <ll> green(b);
	vector <ll> color(c);
	for (int z=0;z<a;z++){
		cin >> red[z];
	}
	for (int z=0;z<b;z++){
		cin >> green[z];
	}
	for (int z=0;z<c;z++){
		cin >> color[z];
	}
	sort(red.begin(),red.end());
	sort(green.begin(),green.end());
	sort(color.rbegin(),color.rend());
	ll ans = 0;
		ll i = a-x;
	ll j = b-y;
	for (int z=i;z<a;z++){
		ans += red[z];
	}
	for (int z=j;z<b;z++){
		ans += green[z];
	}
	for (int z=0;z<c;z++){
		if(i == a && j == b) break;
		if (i == a){
			if(green[j] < color[z]){
			ans += color[z];
			ans -= green[j];
			j++;
			}
		}
		else if (j == b){
			if(red[i] < color[z]){
			ans += color[z];
			ans -= red[i];
			i++;
			}
		}
		else if (red[i] <= green[j] && red[i] < color[z]){
			ans += color[z];
			ans -= red[i];
			i++;
		}
		else if (red[i] >= green[j] && green[j] < color[z]){
			ans += color[z];
			ans -= green[j];
			j++;
		}
		else {
			break;
		}
	}	
	cout << ans << endl;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

const int MAX = 100000+100;
LL fact[MAX];
LL facti[MAX];
LL powm(LL x, LL y){
  if(y == 0) return 1;
  return powm(x*x%MOD, y/2) * (y%2==1?x:1) % MOD;
}

LL N, M;
LL dfs(LL d, int i, LL rest, vector<LL>& ds, LL div){
  if(d == 1){
    return fact[N] * facti[rest] % MOD * div % MOD;
  }
  if(rest == 0 || i == SZ(ds)){
    return 0;
  }

  LL res = 0;
  for(LL k=0;rest>=0;++k){
    (res += dfs(d, i+1, rest, ds, div * facti[k] % MOD)) %= MOD;
    if(d % ds[i] != 0) break;
    d /= ds[i];
    --rest;
  }
  return res;
}

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

  fact[0] = facti[0] = 1;
  for(int i=1;i<MAX;++i){
    fact[i] = fact[i-1] * i % MOD;
    facti[i] = powm(fact[i], MOD-2);
  }

  cin >> N >> M;

  vector<LL> ds;
  for(LL d=1;d*d<=M;++d){
    if(M % d == 0){
      if(d > 1) ds.PB(d);
      if(d != M/d) ds.PB(M/d);
    }
  }
  RSORT(ds);
  cout << dfs(M, 0, N, ds, 1) << endl;

  return 0;
}


Measured memory_bytes: 1920
from collections import deque

N, T = [int(n) for n in input().split()]
Q = deque([int(n) for n in input().split()])

def main():
    ans = 0
    while Q:
        curr = Q.popleft()
        next = Q[0] if Q else float('inf')
        ans += min(T, next - curr)
    print(ans)

if __name__ == '__main__':
    main()

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

int main(){
  int a,b;
  cin >> a >> b ;
  if ((a + b) %2==0){
    cout << (a+b) /2 << endl;
  }
  else{
    cout << (a+b) /2+1 << endl;
  }
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int getDigit(ll x) {
  int cnt = 0;
  while (x > 0) {
    x /= 10;
    cnt++;
  }
  return cnt;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;  cin >> n;
    int ans = Inf;
    FOR(i, 1, sqrt(n) + 1) {
      if (n % i != 0) {
        continue;
      }
      ans = min(ans, max(getDigit(i), getDigit(n / i)));
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)
	if n % 2 != 0 {
		fmt.Println("No")
		return
	}
	if s[0:n/2] == s[n/2:n] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	string s;
	cin >> s;

	cout << ((s[3] == s[2] && s[4] == s[5]) ? "Yes" : "No") << endl;
}

int main()
{
	fastio;
	solve();

	return 0;
}

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

int main() {
  long long int n,ans;
  cin>>n;
  string s=to_string(n);
  ans=(s.at(0)-'0')+(s.size()-1)*9-1;
  for(int i=1;i<s.size();i++){
    if(s.at(i)!='9'){
      cout<<ans<<endl;
      return 0;
    }
  }
  cout<<ans+1<<endl;
}

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

int main()
{
    ll n,ar[105],b=-1,s=999999;
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++)
    {
        scanf("%lld",&ar[i]);
        if(b<ar[i])
            b=ar[i];
        if(s>ar[i])
            s=ar[i];
    }
    ll mn=-1;
    for(ll i=s;i<=b;i++)
    {
        ll cnt=0;
        for(ll j=1;j<=n;j++)
        {
            cnt=cnt+((i-ar[j])*(i-ar[j]));
        }
        if(mn==-1)
            mn=cnt;
        else
            mn=min(mn,cnt);
    }
    printf("%lld\n",mn);
}


Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())

int main(){
  int n;
  cin >> n;
  ll m = 0;
  ll a = 0;
  ll r = 0;
  ll c = 0;
  ll h = 0;
  ll D[5];
  int P [10]={0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2};
  int Q [10]={1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3};
  int R [10]={2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4};

  REP(i, n) {
    string s;
    cin >> s;
    if(s[0] == 'M') m++;
    if(s[0] == 'A') a++;
    if(s[0] == 'R') r++;
    if(s[0] == 'C') c++;
    if(s[0] == 'H') h++;
  }

  D[0] = m;
  D[1] = a;
  D[2] = r;
  D[3] = c;
  D[4] = h;
  // cout << m << endl;
  // cout << a << endl;
  // cout << r << endl;
  // cout << c << endl;
  // cout << h << endl;
  // return 0;

  ll res = 0;
  REP(i, 10) {
    res += D[P[i]] * D[Q[i]] * D[R[i]];
    // cout << D[P[i]] << " " << D[Q[i]] << " " << D[R[i]] << endl;
  }

  cout << res << endl;
}


Measured memory_bytes: 256
using System;

public class Hello
{
	public static void Main()
	{
		var n = int.Parse(Console.ReadLine().Trim());
		Console.WriteLine(getAns(n));
	}
	static int getAns(int n)
	{
		if (n >= 1 && n <= 9) return n;
		if (n >= 10 && n <= 99) return 9;
		if (n >= 100 && n <= 999) return n - 90;
		if (n >= 1000 && n <= 9999) return 909;
		if (n >= 10000 && n <= 99999) return n - 9090;
		else return 90909;
	}
}

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

#define MAX_Q (100000)
#define MAX_N (100000)

int main(int argc, char *argv[]) {
  // read inputs
  int Q, ls[MAX_Q], rs[MAX_Q];
  scanf("%d", &Q);
  for (int q = 0; q < Q; q++) {
    scanf("%d %d", &ls[q], &rs[q]);
  }

  // obtain the list of prime numbers
  int is_primes[MAX_N + 1];
  for (int i = 0; i <= MAX_N; i++) {
    is_primes[i] = 1;
  }
  is_primes[0] = 0;
  is_primes[1] = 0;
  for (int i = 2; i <= MAX_N; i++) {
    if (is_primes[i]) {
      for (int j = 2 * i; j <= MAX_N; j += i) {
        is_primes[j] = 0;
      }
    }
  }

  // calculate accumulated number of 2017 like numbers
  int is_2017likes[MAX_N + 1], acc_num_2017likes[MAX_N + 1];
  is_2017likes[0] = 0;
  acc_num_2017likes[0] = 0;
  for (int i = 1; i <= MAX_N; i++) {
    is_2017likes[i] = i % 2 == 1 && is_primes[i] && is_primes[(i + 1) / 2];
    acc_num_2017likes[i] = acc_num_2017likes[i - 1] + is_2017likes[i];
  }

  // respond to the queries
  for (int q = 0; q < Q; q++) {
    const int l = ls[q], r = rs[q];
    printf("%d\n", acc_num_2017likes[r] - acc_num_2017likes[l - 1]);
  }

  return 0;
}


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

int main()
{
    int n;
	cin>>n;
	long long arr[n];
	long long ans=0;
	for(int y=0;y<n;y++)
		cin>>arr[y];

	long long cnt=0,min__=INT_MAX;
	for(int y=0;y<n;y++)
	{
		if(arr[y]!=abs(arr[y]))
			cnt++;
		min__=min(abs(arr[y]),min__);
		//	cout<<arr[y]<<" ";
	}
	for(int y=0;y<n;y++)
	{
		ans+=abs(arr[y]);
	}
	if(cnt%2==0)
		cout<<ans<<endl;
	else
		cout<<ans-2*min__<<endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    string s;
    int a_count = 0;
    int b_count = 0;
    int count = 0;
    int both_count = 0;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        if (s[0] == 'B' && s[s.length() -1] == 'A') both_count++;
        else if (s[0] == 'B') b_count++;
        else if (s[s.length() -1] == 'A') a_count++;
        
        for (int j = 1; j < s.length(); ++j) {
            if (s[j] == 'B' && s[j-1] == 'A') count++;
        }
    }
    int c = min(a_count, b_count);
    if (!a_count && !b_count) both_count = max(0, both_count - 1);
    // cout << both_count << a_count << b_count;
    cout << count + both_count + c << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
char s[SIZE];
int d[SIZE],n;
bool valid(int mm){
    if(mm<=0)return 0;
    int now=mm*9;
    int r=0;
    REP(i,n){
        r+=d[i];
        int lt=r%10;
        if(lt<0)lt+=10;
        if(lt>now&&r>0)return 0;
        if(now%10<lt)now=(now/10-1)*10+lt;
        else now=now/10*10+lt;
        r-=now;
        r/=10;
    }
    return r<=0;
}
int main(){
    RS(s);
    n=LEN(s);
    reverse(s,s+n);
    REP(i,n)d[i]=s[i]-'0';
    int ll=1,rr=n;
    while(ll<rr){
        int mm=(ll+rr)/2;
        if(valid(mm))rr=mm;
        else ll=mm+1;
    }
    int an=ll;
    REPP(i,1,10)
        if(valid(ll-i))an=ll-i;
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 4608
k, x = map(int, input().split(' '))
for i in range(2*k - 1 - 1):
    if x+1-k+i < 1000001:
        if x+1-k+i >= -1000000:
            print(x+1-k+i, end = ' ')
        else:
            i += -1000000 - (x+1-k+i) 
    else:
        exit()

print(x + k - 1)

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()
auto &errStream = cerr;
#ifdef LOCAL
#define cerr (cerr << "-- line " << __LINE__ << " -- ")
#else
class CerrDummy {
} cerrDummy;
template <class T> CerrDummy &operator<<(CerrDummy &cd, const T &) {
  return cd;
}
using charTDummy = char;
using traitsDummy = char_traits<charTDummy>;
CerrDummy &operator<<(CerrDummy &cd,
    basic_ostream<charTDummy, traitsDummy> &(
      basic_ostream<charTDummy, traitsDummy> &)) {
  return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr << "reached" << endl
#define DMP(x) cerr << #x << ":" << x << endl
#define ZERO(x) memset(x, 0, sizeof(x))
#define ONE(x) memset(x, -1, sizeof(x))

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

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

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

template <class T> T Sq(const T &t) { return t * t; }

#define CAPITAL
void Yes(bool ex = true) {
#ifdef CAPITAL
  cout << "YES" << endl;
#else
  cout << "Yes" << endl;
#endif
  if (ex)
    exit(0);
}
void No(bool ex = true) {
#ifdef CAPITAL
  cout << "NO" << endl;
#else
  cout << "No" << endl;
#endif
  if (ex)
    exit(0);
}

const ll infLL = LLONG_MAX / 3;

#ifdef int
const int inf = infLL;
#else
const int inf = INT_MAX / 2 - 100;
#endif

signed main() {
  int N = read(), M = read();
  int K[M] = {0}, tmp;
  REP(i, N) {
    tmp = read();
    REP(j, tmp) {
      K[read() - 1]++;
    }
  }

  int ans = 0;
  REP(i, M) {
    if (K[i] == N)
      ans++;
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int v[10010],rez[110][110];

int main()
{
    //freopen("file.in","r",stdin);
    //freopen("file.out","w",stdout);
    int h,w,n;
    scanf("%d%d%d",&h,&w,&n);
    for(int i=1;i<=n;i++) scanf("%d",&v[i]);
    int a=1,b=1,l=1,d=1;
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
        {
            if(v[l]==0) l++;
            rez[a][b]=l;
            v[l]--;
            if(b==w && d==1) {a++;d=2;}
            else if(b==1 && d==2) {a++;d=1;}
            else if(d==1) b++;
            else b--;
        }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
            printf("%d ",rez[i][j]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <u32 M>
struct modint {
    u32 val;
public:
    static modint raw(int v) { modint x; x.val = v; return x; }
    modint() : val(0) {}
    template <class T>
    modint(T v) { ll x = (ll)(v%(ll)(M)); if (x < 0) x += M; val = u32(x); }
    modint(bool v) { val = ((unsigned int)(v) % M); }
    modint& operator++() { val++; if (val == M) val = 0; return *this; }
    modint& operator--() { if (val == 0) val = M; val--; return *this; }
    modint operator++(int) { modint result = *this; ++*this; return result; }
    modint operator--(int) { modint result = *this; --*this; return result; }
    modint& operator+=(const modint& b) { val += b.val; if (val >= M) val -= M; return *this; }
    modint& operator-=(const modint& b) { val -= b.val; if (val >= M) val += M; return *this; }
    modint& operator*=(const modint& b) { u64 z = val; z *= b.val; val = (u32)(z % M); return *this; }
    modint& operator/=(const modint& b) { return *this = *this * b.inv(); }
    modint operator+() const { return *this; }
    modint operator-() const { return modint() - *this; }
    modint pow(long long n) const { modint x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
    modint inv() const { return pow(M-2); }
    friend modint operator+(const modint& a, const modint& b) { return modint(a) += b; }
    friend modint operator-(const modint& a, const modint& b) { return modint(a) -= b; }
    friend modint operator*(const modint& a, const modint& b) { return modint(a) *= b; }
    friend modint operator/(const modint& a, const modint& b) { return modint(a) /= b; }
    friend bool operator==(const modint& a, const modint& b) { return a.val == b.val; }
    friend bool operator!=(const modint& a, const modint& b) { return a.val != b.val; }
};
using mint = modint<MOD>;

int main() {
    int n;
    cin >> n;
    mint ans = mint(10).pow(n)-mint(9).pow(n)-mint(9).pow(n)+mint(8).pow(n);
    cout << ans.val << "\n";
    return 0;
}

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

using namespace std;

#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair

#define debug(args...) { string _s = #args; replace(ALL(_s), ',', ' '); stringstream ss(_s); _debug(ss, args); }
#define _rg auto it = next(v.begin()); it != v.end(); it++
#define _input ostream& operator <<(ostream& out

template<typename T, typename U>
_input, const pair<T, U>& p) {
	out << "(" << p.first << ", " << p.second << ")";
	return out;
}

#define cont(c) template<typename T> _input, const c<T>& v) { \
					if (v.empty()) return out; \
					out << "[" << *v.begin(); \
					for (_rg) out << ", " << *it; \
					out << "]"; return out; \
				}
				
#define cont2(c) template<typename T, typename U> _input, const c<T, U>& v) { \
					if (v.empty()) return out; \
					out << "[" << *v.begin(); \
					for (_rg) out << ", " << *it; \
					out << "]"; return out; \
				}

cont(vector) cont(set) cont(multiset) cont(queue) cont2(map)

template<typename T, size_t n, typename= enable_if_t<!is_same<T, char>::value>>
_input, const T(&v)[n]) {
	if (n == 0) return out;
	out << "[" << v[0];
	for (int i = 1; i < (int)n; i++) out << ", " << v[i];
	out  << "]"; return out;
}

template<typename T, typename... Ts>
void _debug(stringstream& ss, const T &arg) {
	string name; ss >> name;
	cerr << name << " = " << arg << endl;
}

template<typename T, typename... Ts>
void _debug(stringstream& ss, const T& arg, const Ts&... args) {
	string name; ss >> name; 
	cerr << name << " = " << arg << ", ";
	if (is_class<T>::value || is_array<T>::value) cerr << endl;
	_debug(ss, args...);
}

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;
const double PI = 3.141592653589793238;

int32_t main() {
	FAST_IO;
	
	int n;
	cin >> n;
	
	int base = 1;
	while (base <= n) {
		base *= 2;
	}
	vi tree(2*base);
	
	int h[n], a[n];
	for (int& x: h) cin >> x;
	for (int& x: a) cin >> x;
	
	vi dp(n + 1);
	// dp[i] = max beauty so far if last taken flower has height i
	
	for (int flower = 0; flower < n; flower++) {
		// max dp[i] for i in [0, h[flower]-1]
		int x = h[flower] + base;
		int best = 0;
		while (x > 1) {
			if (x%2 == 1) {
				best = max(best, tree[x-1]);
			}
			x /= 2;
		}
		dp[h[flower]] = best + a[flower];
		
		for (int i = base + h[flower]; i >= 1; i /= 2) {
			tree[i] = max(tree[i], dp[h[flower]]);
		}
		
		
		//~ for (int i = 0; i < h[flower]; i++) {
			//~ dp[h[flower]] = max(dp[h[flower]], dp[i] + a[flower]);
		//~ }
	}
	
	int ans = 0;
	for (int x: dp) ans = max(ans, x);
	
	cout << ans  << endl;	
	
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17


Measured memory_bytes: 9088
#include<cstdio>
const int mod=1000000007;
int N,M,R[3010],sum[3010],f[3010][3010];
char S[3010];
int main(){
	scanf("%d%d%s",&N,&M,S);
	for(int i=0;i<N;i++)R[i]=i+1;
	for(int i=0;i<M;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		if(r>R[l-1])R[l-1]=r;
	}
	for(int i=0;i<N;i++)if(R[i]>R[i+1])R[i+1]=R[i];
	for(int i=0;i<N;i++)sum[i+1]=sum[i]+S[i]-'0';
	f[0][0]=1;
	for(int i=0;i<N;i++)for(int j=0;j<=sum[N];j++)if(f[i][j]){
		if(sum[R[i]]-j<R[i]-i)(f[i+1][j]+=f[i][j])%=mod;
		if(sum[R[i]]-j>0)(f[i+1][j+1]+=f[i][j])%=mod;
	}
	printf("%d\n",f[N][sum[N]]);
}

Measured memory_bytes: 33792
#include <cstdio>
#include <cctype>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repd(i,x,y) for (int i=x; i>=y; --i)
using namespace std;

typedef long long LL;
int n,m,log_[100100];
LL len[100100],f[100100][20],ans[100100],cnt[100100];

LL getLL()
{
    char ch;
    while (!isdigit(ch=getchar()));
    LL x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

void solve(int x,LL l,LL w)
{
    while (x)
    {
        for (int i=log_[x]; i>=0; i=min(i-1,log_[x]))
            if (f[x][i]>=l)
                x-=1<<i;
        if (x)
            cnt[x]+=l/len[x]*w,l%=len[x];
    }
    ans[n]+=l/n*w,ans[l%n]+=w;
}

int main()
{
    scanf("%d%d",&n,&m);
    if (!m)
    {
        repu(i,1,n)
            puts("1");
        return 0;
    }
    repu(i,1,m)
        len[i]=getLL();
    log_[0]=-1;
    repu(i,2,m)
        log_[i]=log_[i>>1]+1;
    repu(i,1,m)
    {
        f[i][0]=len[i];
        repu(j,1,log_[i])
            f[i][j]=min(f[i][j-1],f[i-(1<<(j-1))][j-1]);
    }
    solve(m-1,len[m],1);
    repd(i,m-1,1)
        solve(i-1,len[i],cnt[i]);
    repd(i,n,1)
        ans[i]+=ans[i+1];
    repu(i,1,n)
        printf("%lld\n",ans[i]);
    return 0;
}

Measured memory_bytes: 19968
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  int t[n];
  int sum = 0;
  for(int i = 0; i < n; i++) {
    cin >> t[i];
    sum += t[i];
  }
  int m;
  cin >> m;
  int p[m],x[m];
  for(int i = 0; i < m; i++) {
    cin >> p[i] >> x[i];
  }

  for(int i = 0; i < m; i++) {
    int tmp = sum - t[p[i]-1] + x[i];
    cout << tmp << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int N, K; std::cin >> N >> K;
  int cnt = 0;
  while (N>0) {
    N /= K;
    ++cnt;
  }
  std::cout << cnt << std::endl;
}


Measured memory_bytes: 256
import math
A,B,C,D = map(int,input().split())
BIkaCbaisuC = B//C
AIkaCbaisuC = (A-1)//C
ABkanCbaisuC = BIkaCbaisuC - AIkaCbaisuC

BIkaDbaisuC = B//D
AIkaDbaisuC = (A-1)//D
ABkanDbaisuC = BIkaDbaisuC - AIkaDbaisuC

cd = math.floor(C*D/math.gcd(C,D))
BIkacdbaisuC = B//cd
AIkacdbaisuC = (A-1)//cd
ABkancdbaisuC = BIkacdbaisuC - AIkacdbaisuC

print(B-A+1-ABkanCbaisuC-ABkanDbaisuC+ABkancdbaisuC)


Measured memory_bytes: 62140
#include<iostream>
#include<vector>
using namespace std;
class DisjointSet{
private:
  vector<int> rank,p;
  void link(int x,int y){
    if(rank[x] > rank[y]){
      p[y] = x;
    }else{
      p[x] = y;
      if(rank[x] == rank[y]) rank[y]++;
    }
  }
public:
  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
  }
  void makeSet(int x){
    p[x] = x;
    rank[x] = 0;
  }
  void Union(int x,int y){
    link(findSet(x),findSet(y));
  }
  int findSet(int x){
    if(x != p[x]) p[x] = findSet(p[x]);
    return p[x];
  }
  bool isSameOut(int x,int y){
    return (findSet(x)==findSet(y));
  }
};
int main(){
  int n,q,com,x,y;
  cin >> n >> q;
  DisjointSet UF(n);
  for(int i=0;i<n;i++) UF.makeSet(i);
  for(int i=0;i<q;i++){
    cin >> com >> x >> y;
    if(com == 0) UF.Union(x,y);
    else cout << (UF.isSameOut(x,y) ? 1 : 0) << endl;
  }
}

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

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        Strategy strategy = new MyStrategy();
        strategy.solve(out, sc);
        out.flush();
    }
}

class MyStrategy implements Strategy {
    @Override
    public void solve(PrintWriter out, FastScanner sc) {
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();

        int cnt = 0;
        for (int i = 0; i < K; i++) {
            if (A > 0) {
                A--;
                cnt++;
            } else if (B > 0) {
                B--;
            } else {
                cnt--;
                C--;
            }
        }
        out.println(cnt);

    }
}

interface Strategy {
    void solve(PrintWriter out, FastScanner sc);
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 25976
#include <stdio.h>

int e;
int func(int y, int z)
{
    return e - (y * y) - (z * z * z) + y + z;
}

int main(void)
{
    while(1){
        int i, j;
        int min = 1000000;

        scanf("%d", &e);

        if(e == 0)
            break;

        for(i = 0; i <= e; i++){
            for(j = 0; j <= e; j++){
                if(i * i + j * j * j <= e){
                    int temp = func(i, j);
                    if(min > temp){
                        min = temp;
                    }
                }else{
                    break;
                }
            }
            if(i * i > e)
                break;
        }

        printf("%d\n", min);
    }

    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <random>
#include <iomanip>
#include <functional>
#include <list>
using namespace std;

int a[100100];
int cnt[2][100100];

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

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		cnt[i % 2][a[i]]++;
	}

	vector<pair<int, int>> v[2];
	for (int i = 0; i < 2; i++)
		for (int j = 1; j <= 100000; j++)
			if (cnt[i][j])
				v[i].push_back({ cnt[i][j], j });

	vector<pair<int, int>> u[2];
	for (int i = 0; i < 2; i++)
	{
		sort(v[i].rbegin(), v[i].rend());

		u[i].push_back(v[i][0]);
		if (v[i].size() >= 2)
			u[i].push_back(v[i][1]);
		else
			u[i].push_back({ 0, -1 * i });
	}

	int min_changes = n;
	for (int i = 0; i < u[0].size(); i++)
		for (int j = 0; j < u[1].size(); j++)
		{
			auto pa = u[0][i];
			auto pb = u[1][j];

			if (pa.second == pb.second)
				continue;

			min_changes = min(min_changes, n - pa.first - pb.first);
		}

	cout << min_changes;
}


Measured memory_bytes: 2552
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define Forr(i,m,n) for(int i=m;i>n;i--)
#define Sort(a) sort(a.begin(),a.end())
#define pb push_back
#define vl vector<ll>
#define vll vector<vector<ll>>
#define INF 999999999999

int main(){
  int N,A[100];
  cin>>N;
  rep(i,N){
    cin>>A[i];
    if(A[i]%2==0&&(A[i]%3!=0&&A[i]%5!=0)){
      cout<<"DENIED"<<endl;
      return 0;
    }
  }
  cout<<"APPROVED"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const ll mod=1e+9;
typedef pair<ll,ll> P;
#define fi first
#define se second

int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin>>n;
vector<string> a(n);
for(int i=0;i<n;i++){
    cin>>a.at(i);
    sort(a.at(i).begin(),a.at(i).end());
}
sort(a.begin(),a.end());
ll cnt=1;
ll ans=0;
for(int i=0;i<n-1;i++){
     if(a.at(i)==a.at(i+1))cnt++;
     else{
         ans+=cnt*(cnt-1)/2;
         cnt=1;
     }
}
if(cnt>1)ans+=cnt*(cnt-1)/2;
cout<<ans<<endl;
}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<ll> cnt(N,0);
    vector<ll> A(N,0);

    for(int i=0; i<N; i++){
        ll a;
        cin >> a;
        a--;
        cnt[a]++;
        A[i]=a;
    }

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

    for(int i=0; i<N; i++){
        int a=A[i];
        //cout << ans << ' ' << cnt[a] << endl;
        cout << ans-cnt[a]+1 << endl;
    }
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = (int)1e9 + 7;
int INF = (int)2e18;

signed main() {
    int N, D;
    cin >> N >> D;
    vector<vector<double>> X(N, vector<double>(D, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            double check = 0;
            for (int k = 0; k < D; k++) {
                check += pow(abs(X[i][k] - X[j][k]), 2);
            }
            check = sqrt(check);
            if (ceil(check) == floor(check)) ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class AAddtion
    {
        public static void Main(string[] args)
        {
            new AAddtion().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var n = cin.ReadInt;
            var aList = cin.ReadLongArray(n+1);
            var bList = cin.ReadLongArray(n);
            long ans =0;

            for(int i=0; i<bList.Length; i++){
                if(aList[i] >= bList[i]){
                    ans += bList[i];
                }else{
                    ans += aList[i];
                    if(aList[i+1] >= (bList[i] - aList[i])){
                        ans += bList[i] - aList[i];
                    }else{
                        ans += aList[i+1];
                    }
                    aList[i+1] = aList[i+1] - (bList[i] - aList[i]) < 0 ? 0 : aList[i+1] - (bList[i] - aList[i]);
                }
            }
            WriteLine(ans);
        }
    }
}
public class ConsoleInput
{
    private readonly System.IO.TextReader _stream;
    private char _separator = ' ';
    private Queue<string> inputStream;
    public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
    {
        this._separator = separator;
        this._stream = stream;
        inputStream = new Queue<string>();
    }
    public string Read
    {
        get
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(_separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
    }
    public string ReadLine { get { return _stream.ReadLine(); } }
    public int ReadInt { get { return int.Parse(Read); } }
    public long ReadLong { get { return long.Parse(Read); } }
    public double ReadDouble { get { return double.Parse(Read); } }
    public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
}

Measured memory_bytes: 31456