akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,K;
    string S;
    cin>>N>>K>>S;
    if(S.at(K-1)=='A'){
        S.at(K-1)='a';
    }
    if(S.at(K-1)=='B'){
        S.at(K-1)='b';
    }
    if(S.at(K-1)=='C'){
        S.at(K-1)='c';
    }
    cout<<S<<endl;
}


Measured memory_bytes: 256
n = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
##print(P)
#print(Q)
import itertools
X = []
for p in itertools.permutations(range(1, n+1)):
    X.append(p)
#print(X)
for i in range(len(X)):
    if P == X[i]:
        a = i
        break
for i in range(len(X)):
    if Q == X[i]:
        b = i
        break
print(abs(a-b))


Measured memory_bytes: 79264
#include<iostream>
using namespace std;int x,y,z;
int main(){
    int n,a,b;
    cin >> n >> a >> b;
    while(n --){
        int k;
        cin >> k;
        if(k <=a)
            x++;
        else
            if(k>b)
            z++;
        else    y++;
    }
    cout << min(x,min(y,z));
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

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

using f32 = float;
using f64 = double;
using ll = long long;

constexpr i64 INF = 1010000000000000017LL;

constexpr i64 MOD = 1000000007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

ll mod_pow(ll x, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        return mod_pow(x * x % MOD, n / 2) % MOD;
    } else {
        return x * mod_pow(x, (n - 1)) % MOD;
    }
}

ll mod_pow_r(ll x, ll n) {
    if (x == 0) return 0;
    if (n == 0) return 1;

    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n /= 2;
    }
    return ret;
}

ll factorial(ll n) {
    ll ret = 1;
    REP(i, n) {
        ret *= (i + 1);
        ret %= MOD;
    }
    return ret;
}

ll combination(ll n, ll r) {
    if (n < 0 || n < r || r < 0) return 0;
    ll fn = factorial(n);
    ll fr = factorial(r);
    ll fn_r = factorial(n-r);

    ll d = (mod_pow(fr, MOD - 2) * mod_pow(fn_r, MOD - 2)) % MOD;
    ll u = fn % MOD;
    return u * d % MOD;
}

void solve() {
    string s, t, u; cin >> s >> t;
    int a, b; cin >> a >> b;
    cin >> u;

    if (s == u) cout << a-1 << " " << b;
    if (t == u) cout << a << " " << b-1;
}

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

Measured memory_bytes: 256
S = input()
N = len(S)
ans = 0
for i in range(1 << (N - 1)):
    tmp = 0
    for j in range(N):
        if i & 1 << j:
            tmp = tmp * 10 + int(S[j])
            ans += tmp
            tmp = 0
        else:
            tmp = tmp * 10 + int(S[j])

    ans += tmp

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

typedef int64_t ll;

template <class T1, class T2>
using dict = std::unordered_map<T1, T2>;


int main(){
    int n;
    cin >> n;
    ll a[n];
    REP(i,n) cin >> a[i];
    ll s = 0;
    ll count1 = 0;
    ll count2 = 0;
    REP(i,n){
        s += a[i];
        if (i%2==1 && s<=0){
            count1 += -s + 1;
            s = 1;
        } else if (i%2==0 && s>=0){
            count1 += s + 1;
            s = -1;
        }
    }
    s = 0;
    REP(i,n){
        s += a[i];
        if (i%2==1 && s>=0){
            count2 += s + 1;
            s = -1;
        } else if (i%2==0 && s<=0){
            count2 += - s + 1;
            s = 1;
        }
    }
    cout << min(count1,count2) << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
#include <stdbool.h>
#include <limits.h>
//#include <math.h>

#define Min(a, b) ((a < b) ? a : b)

int main() {
  int h, w, k;
  scanf("%d%d%d", &h, &w, &k);
  char s[h][w+5];
  for (int i=0; i<h; i++)
    scanf("%s", s[i]);
  int cnt[h+1][w+1], ans = INT_MAX;
  for (int i=0; i<w+1; i++)
    cnt[0][i] = 0;
  for (int i=0; i<h+1; i++)
    cnt[i][0] = 0;
  for (int i=0; i<h; i++)
    for (int j=0; j<w; j++)
      cnt[i+1][j+1] = cnt[i][j+1]+cnt[i+1][j]-cnt[i][j]+(s[i][j]=='1');
  for (int i=(1<<(h-1)); i<(1<<h); i++) {
    int c, d = 0, a = 0, tmpi = i;
    bool check = true;
    while (tmpi != 1) {
      a += tmpi%2;
      tmpi /= 2;
    }
    for (int j=0; j<w; j++) {
      c = 0;
      for (int l=0; l<h; l++) {
        if (i & (1<<l)) {
          if (cnt[l+1][j+1] - cnt[c][j+1] - cnt[l+1][d]+cnt[c][d] > k) {
            if (cnt[l+1][j+1]-cnt[l+1][j]-cnt[c][j]+cnt[c][j] > k) {
              check = false;
              break;
            }
            a++;
            d = j;
          }
          c = l+1;
        }
      }
      if (!check)
        break;
    }
    if (!check)
      continue;
    ans = Min(ans, a);
  }
  if (ans == INT_MAX)
    ans = 0;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b;
	double c;
	cin >> a >> b;
	cout << a/b << " " << a%b << " ";
	c = (double)a/b;
	printf("%8lf\n",c);
	return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
//<<setprecision(30)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  ll N,K; cin>>N>>K;
  ll res = 0;
  if(N<=K)res=min(K-N,N);
  else if(K<N){
    res = min(N%K,K-N%K);
  }
  cout<<res<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;

// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec; }
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}


int main()
{
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll N;
  std::cin >> N;

  std::map<ll, bool> mm;
  for (ll i = 0; i < N; i++) {
    ll a;
    std::cin >> a;
    mm[a] = true;
  }

  if (static_cast<ll>(mm.size()) == N) {
    print("YES");
  } else {
    print("NO");
  }

  return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
    int n;
    int k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (h[i] >= k) {ans += 1;}
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
integer::N,i
integer(16),allocatable,dimension(:)::A
integer(16),allocatable,dimension(:,:)::DP
read*,N
allocate(A(N),DP(N,3))
read*,A
DP(1,1)=A(1)
DP(2,2)=A(2)
if(N>=3)DP(3,3)=A(3);DP(3,1)=A(1)+A(3)
do i=4,N
    DP(i,1)=DP(i-2,1)+A(i)
    DP(i,2)=max( DP(i-2,2)+A(i), DP(i-3,1)+A(i) )
    DP(i,3)=max( DP(i-2,3)+A(i), DP(i-3,2)+A(i), DP(i-4,1)+A(i) )
end do
print"(i0)",merge(max(DP(N,3),DP(N-1,2),DP(N-2,1)),max(DP(N,2),DP(N-1,1)),btest(N,0))
end

Measured memory_bytes: 15660
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
	string s;
	cin >> s;
	int len = s.length();
	int ans = len / 2, left = (len - 1) / 2, right = len - (len + 1) / 2, center = left;
	while (left >= 0) {
		if (s[center] != s[left] || s[center] != s[right]) {
			break;
		}
		++ans;
		--left, ++right;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
    #include <string.h>
    int main(void){
        
        char s[300]={};
        gets(s);
        int n=strlen(s);
        for(int i=2;i<n;i+=2){
            if(strncmp(s,s+(n-i)/2,(n-i)/2)==0){
                printf("%d\n",n-i);
                return 0;
            }
        }
    }

Measured memory_bytes: 1648
#include <iostream>
#include <tr1/unordered_map>
#include <algorithm>
using namespace std;
using namespace tr1;


bool lt(const string &a,const string &b){
	if(a.length() != b.length()) return a.length() < b.length();
	else return a < b;
}
string merge(string a,string b){
	if(~a.find(b)) return a;
	for(int i = 0 ; i < a.size() ; i++){
		bool f = true;
		for(int j = 0 ; i+j < a.size() ; j++){
			if( a[i+j] != b[j] ){ f = false; break; }
		}
		if(f) return a.substr(0,i) + b;
	}
	return a+b;
}

int main(){
	int n;
	while(cin >> n && n){
		string v[10];
		unordered_map<string,string> memo[1024];
		for(int i = 0 ; i < n ; i++) cin >> v[i];
		sort(v,v+n);
		for(int i = 0 ; i < n ; i++) memo[1<<i][v[i]] = v[i];
		
		for(int bit = 0 ; bit < (1<<n) ; bit++){
			for(unordered_map<string,string>::iterator it = memo[bit].begin() ; it != memo[bit].end() ; ++it){
				string s = it->second;
				for(int i = 0 ; i < n ; i++){
					if(!(bit>>i&1)){
						string r = merge(s,v[i]);
						string key = r.substr(max(0,(int)r.size()-10));
						string& ans = memo[bit|(1<<i)][key];
						
						if(ans == "" || lt(r,ans)) ans = r;
					}
				}
			}
		}
		string ans = "";
		for(unordered_map<string,string>::iterator it = memo[(1<<n)-1].begin() ; it != memo[(1<<n)-1].end() ; ++it){
			string m = it->second;
			if(ans == "" || lt(m,ans)) ans = m;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;

	int n, ans = 0;
	string s;
	cin >> n >> s;
	for(int i=0;i<n;) {
		int j = i;
		while(s[i] == s[j]) i++;
		ans++;
	}	
	cout << ans << endl;
	
}





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

using namespace std; 

int Time;
vector< vector<int> > adj;
vector< pair<int,int> > res;

void dfs(int v) {
	res[v].first = Time;
	for (int i = 0; i < adj[v].size(); ++i) {
		if (res[adj[v][i]].first < 0) {
			++Time;
			dfs(adj[v][i]);
		}
	}
	++Time;
	res[v].second = Time;
	return;
}

int main(void) {
	int nov,noe,u,v;
	cin >> nov;
	adj = vector< vector<int> >(nov);
	for (int i = 0; i < nov; ++i) {
		cin >> u;
		cin >> noe;
		adj[u-1] = vector<int>(noe);
		for (int j = 0; j < noe; ++j) {
			cin >> adj[u-1][j];
			--adj[u-1][j];
		}
	}
	Time = 1;
	res = vector< pair<int,int> >(nov,{-1,-1});
	int start = 0;
	while (start >= 0) {
		dfs(start);
		start = -1;
		++Time;
		for (int i = 0; start < 0 && i < nov; ++i) {
			if (res[i].first < 0) {
				start = i;
			}
		}
	}
	for (int i = 0; i < nov; ++i) {
		cout << i+1 << " ";
		cout << res[i].first << " ";
		cout << res[i].second << endl;
	}
	return 0;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define f first
#define se second
#define pb push_back
#define pf push_front
#define eb emplace_back
#define emp emplace
#define ins insert
#define sz(s) (int)s.size()
#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 bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define ii pair<int,int>
#define iii tuple<int, int, int>
#define si set<int>
#define vi vector<int>
#define mi map<int,int>
#define lb lower_bound
#define ub upper_bound
#define present(s,x) (s.find(x) != s.end())
#define ford(container, it) for(auto it:container)
#define fors(container, it, a, b) for(auto it = a; it != b; it++)
#define Anurag_Gupta ios_base::sync_with_stdio(0);
#define IIIT_ALLD cin.tie(0);cout.tie(0);
#define mod 987654319
#define EPSILON 1e-9
#define PI acos(-1)
#define inf 1e17
#define int long long
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
#define trace(a) cerr<<#a<<": "<<a<<"\n"
#define gcd(a,b) __gcd(a,b)
using namespace std;
int add(int a, int b, int c){int res=a+b;return(res>=c?res-c:res);}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mul(int a, int b, int c){int res=(int)a*b;return(res>=c?res%c:res);}
template<typename T>T power(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T>T mdpower(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
/*------------------------------------------------------------------------------------------------------------------*/

int32_t main()
{
    Anurag_Gupta
    IIIT_ALLD

   


        

        string s;
        cin>>s;
        int flag=0;

        rep(i,1,4)
        {
            if(s[i]==s[i-1])
                flag=1;
        }
        if(flag)
            cout<<"Bad\n";
        else
            cout<<"Good\n";










    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 102;

int n;
char a[N], b[N];

int main()
{
    scanf("%d", &n);
    scanf(" %s %s", a, b);
    for (int i = 0; i < n; ++i)
        printf("%c%c", a[i], b[i]);
    printf("\n");
    return 0;
}


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

int main()
{
    int i=1;

    while(1){
        int x;
        cin>>x;

        if(x==0)break;

        cout<<"Case "<<i<<": "<<x<<endl;

        i++;
    }

    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

inline bool check(int a, int b, int c){
    bool res = a%2 || b%2 || c%2;
    return !res;
}

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    int res = 0;
    set<pair<pair<int, int>, int> > used;
    while(check(A, B, C)){
        pair<pair<int, int>, int> key = make_pair(make_pair(A, B), C);
        if(used.count(key)){
            res = -1;
            break;
        }
        used.insert(key);
        res++;
        int a = B/2 + C/2;
        int b = A/2 + C/2;
        int c = B/2 + A/2;
        A = a;
        B = b;
        C = c;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

enum Color { red, green, colorless }
alias S = Tuple!(long, "value", Color, "color");

long calc(int x, int y, long[] a, long[] b, long[] c) {
    a.sort!"a > b";
    b.sort!"a > b";
    c.sort!"a > b";

    S[] s = chain(
        a.take(x).map!(e => S(e, Color.red)),
        b.take(y).map!(e => S(e, Color.green)),
        c.map!(e => S(e, Color.colorless))).array;
    s.sort!"a.value > b.value";

    long ans = 0;
    int red = 0, green = 0, colorless = 0;
    foreach (e; s) {
        if (red + green + colorless == x + y) break;

        ans += e.value;
        if (e.color == Color.red && red < x) red++;
        if (e.color == Color.green && green < y) green++;
        if (e.color == Color.colorless) colorless++;
    }
    return ans;
}

void main() {
    int x, y, A, B, C; scan(x, y, A, B, C);
    auto a = reads!long;
    auto b = reads!long;
    auto c = reads!long;
    writeln(calc(x, y, a, b, c));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 17364
n, k = gets.split.map(&:to_i)

max = 0
w = []
n.times{
  m = gets.to_i
  w.push(m)
  max = m if max < m
}

sum = w.inject(&:+)

if k == 1 then
  p = sum
elsif k == n then
  p = max
else
  left = max
  right = 100000 * 100000
  # Binary search
  while left <= right
    middle = (left + right)/2
    i = 0
    on_truck = 0
    truck = 1
    while i < n
      on_truck += w[i]
      if middle < on_truck then
        truck += 1
        break if k < truck
        on_truck = w[i]
      end
      i += 1
    end
    p = middle if truck <= k

    if k < truck then
      left = middle + 1
    else
      right = middle - 1
    end
  end
end
puts p

Measured memory_bytes: 9740
import numpy as np
import sys
w = input()
countn = np.zeros(26)
ew = "abcdefghijklmnopqrstuvwxyz"
i = 0
while i < 26:
    countn[i] = w.count(ew[i])
    if countn[i] %2 != 0:
        print("No")
        sys.exit()
    i +=1
  
print("Yes")
    
    

Measured memory_bytes: 13048
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    map<int, int> even;
    map<int, int> odd;
    rep(i, n) {
        if(i&1) odd[v[i]]++;
        else even[v[i]]++;
    }
    odd[1e9] = 0;
    even[1e9] = 0;
    int ans = 1e9;
    vector<pii> a, b;
    for(auto&& p : odd) a.pb({p.second, p.first});
    for(auto&& p : even) b.pb({p.second, p.first});
    sort(rall(a));
    sort(rall(b));
    if(a[0].se != b[0].se) ans = n - (a[0].fi + b[0].fi);
    else {
        ans = n - max(a[0].fi + b[1].fi, a[1].fi + b[0].fi);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 6520
import java.util.*;

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

		int n = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();

		int in = 0;
		int out = 0;

		char[] arr = scan.next().toCharArray();
		for(int i = 0; i < n; i++) {
			if(arr[i] == 'a') {
				if(in+out<a+b) {
					System.out.println("Yes");
					in++;
				}else {
					System.out.println("No");
				}
			}else if(arr[i] == 'b') {
				if(in+out<a+b && out < b) {
					System.out.println("Yes");
					out++;
				}else {
					System.out.println("No");
				}
			}else {
				System.out.println("No");
			}
		}
	}
}


Measured memory_bytes: 23276
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        int N = cin.Int();
        var S = new string[N];
        for (int i = 0; i < N; i++) {
            S[i] = Console.ReadLine();
        }

        int m = 0, a = 0, r = 0, c = 0, h = 0;
        foreach (var s in S) {
            if (s[0] == 'M') m++;
            else if (s[0] == 'A') a++;
            else if (s[0] == 'R') r++;
            else if (s[0] == 'C') c++;
            else if (s[0] == 'H') h++;
        }

        var x1 = new int[] { 1, 1, 1, 1, 1, 0, 0, 1, 0, 0 };
        var x2 = new int[] { 1, 1, 1, 0, 0, 1, 1, 0, 1, 0 };
        var x3 = new int[] { 1, 0, 0, 1, 1, 1, 1, 0, 0, 1 };
        var x4 = new int[] { 0, 1, 0, 1, 0, 1, 0, 1, 1, 1 };
        var x5 = new int[] { 0, 0, 1, 0, 1, 0, 1, 1, 1, 1 };

        long ans = 0;
        for (int i = 0; i < 10; i++) {
            long tmp = 1;
            if (x1[i] != 0) tmp *= m;
            if (x2[i] != 0) tmp *= a;
            if (x3[i] != 0) tmp *= r;
            if (x4[i] != 0) tmp *= c;
            if (x5[i] != 0) tmp *= h;
            ans += tmp;
        }
        Console.WriteLine(ans);
        Console.ReadLine();
    }
}

Measured memory_bytes: 13792
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

ll GetGCD(ll x, ll y) {
  if (x == 0) return y;
  if (x > y) swap(x, y);
  return GetGCD(y % x, x);
}

ll GetLCM(ll x, ll y) {
  return x * y / GetGCD(x, y);
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vector<int> B(N);
  for (int i = 0; i < N; ++i) {
    B[i] = A[i] / 2;
  }

  ll lcm = B[0];
  for (int i = 1; i < N; ++i) {
    lcm = GetLCM(lcm, B[i]);
    if (lcm > M) {
      cout << 0 << endl;
      return 0;
    }
  }

  for (int i = 0; i < N; ++i) {
    if ((lcm / B[i]) % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  
  int count = (M / lcm + 1) / 2;
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <vector>
#include <algorithm>


using namespace std;

short heap_index[10000];

struct Info{
	Info(){
		to=0;
		weight = 0;
	}
	Info(short arg_to,int arg_weight){
		to = arg_to;
		weight = arg_weight;
	}
	short to;
	int weight;
};

class InfoPQ{
public:
	InfoPQ(){
		array = new Info[10000];
		n = 0;
	}
	void push(Info arg_info){
		array[n] = arg_info;
		int tmp = n;
		while(tmp != 0 && array[tmp].weight < array[(tmp-1)/2].weight){
			std::swap(array[tmp], array[(tmp-1)/2]);
			tmp = (tmp-1)/2;
		}
		n++;
	}

	bool isEmpty(){
		return n == 0;
	}

	void writeHeapIndex(){
		for(int i=0;i<n;i++){
			heap_index[array[i].to] = i;
		}
	}

	void update(short update_index,int new_weight){
		array[heap_index[update_index]].weight = new_weight;
		int tmp = heap_index[update_index];
		while(tmp != 0 && array[tmp].weight < array[(tmp-1)/2].weight){
			std::swap(heap_index[array[tmp].to],heap_index[array[(tmp-1)/2].to]);
			std::swap(array[tmp], array[(tmp-1)/2]);
			tmp = (tmp-1)/2;
		}
	}

	Info pop(){
		Info ret = array[0];
		n--;
		heap_index[array[n].to] = 0;
		std::swap(array[0],array[n]);
		int tmp = 0;
		while(2*tmp+1 <= n-1){
			if(2*tmp+2 <= n-1){
				if(array[2*tmp+2].weight < array[tmp].weight && array[2*tmp+2].weight <= array[2*tmp+1].weight){
					std::swap(heap_index[array[tmp].to],heap_index[array[2*tmp+2].to]);
					std::swap(array[2*tmp+2],array[tmp]);
					tmp = 2*tmp+2;
				}else if(array[2*tmp+1].weight < array[tmp].weight && array[2*tmp+1].weight <= array[2*tmp+2].weight){
					std::swap(heap_index[array[tmp].to],heap_index[array[2*tmp+1].to]);
					std::swap(array[2*tmp+1],array[tmp]);
					tmp = 2*tmp+1;
				}else{
					break;
				}
			}else{
				if(array[tmp].weight > array[2*tmp+1].weight){
					std::swap(heap_index[array[tmp].to],heap_index[array[2*tmp+1].to]);
					std::swap(array[tmp],array[2*tmp+1]);
					tmp = 2*tmp+1;
				}else{
					break;
				}
			}
		}
		return ret;
	}

private:
	Info* array;
	int n;
};



int main(){
	int n,count=0,tmp,left_node,right_node,dist;
	short size;
	scanf("%d",&n);
	vector<Info> V[n];
	Info catcher;
	InfoPQ A;

	int P[n],zero_dist[n];

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

	for(int i=0;i<n;i++){
		scanf("%d %d",&left_node,&tmp);
		if(left_node == 0){
			for(int k=0;k<tmp;k++){
				scanf("%d %d",&right_node,&dist);
				zero_dist[right_node] = dist;
			}
		}else{
			for(int k=0;k<tmp;k++){
				scanf("%d %d",&right_node,&dist);
				V[left_node].push_back(Info(right_node,dist));
			}
		}
	}

	for(short k=1;k<n;k++){
		A.push(Info(k,zero_dist[k]));
	}

	A.writeHeapIndex();

	while(count<n-1){

		catcher = A.pop();
		P[catcher.to]=1;
		count++;
		size = V[catcher.to].size();
		for(int k=0;k<size;k++){
			if(zero_dist[V[catcher.to][k].to] > catcher.weight+V[catcher.to][k].weight){
				zero_dist[V[catcher.to][k].to] = catcher.weight+V[catcher.to][k].weight;
				A.update(V[catcher.to][k].to,catcher.weight+V[catcher.to][k].weight);
			}
		}
	}

	for(int i=0;i<n;i++){
		printf("%d %d\n",i,zero_dist[i]);
	}

    return 0;
}

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

using namespace std;

map<string,int> mp;
const int maxn = 5e3 + 10;
int a[maxn];

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

	string name;
	int tm, sum = 0;
	for(int i = 0;i < n;++i) {
		cin >> name >> tm;
		mp[name] = i;
		a[i] = tm;
	}	
	cin >> name;
	for(int i = n - 1;i >= 0;--i) a[i] += a[i + 1];
	cout << a[mp[name]+1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int x,y,z,i=0,s=0;
	scanf("%d %d %d",&x,&y,&z);
	do
	{
		i++;
		s=y*i+(i+1)*z;
	}
	while(s<=x);
	printf("%d",i-1);
	
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007ll
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define sorrev(v) sort(v.begin(),v.end(),greater<ll>())
#define uni(v) unique(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 
auto random_address = [] { char *p = new char; delete p; return sll(p); };
const sll SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);

const ll MAXN=200005;
ll parent[MAXN],siz[MAXN],ran[MAXN],x[MAXN],y[MAXN];

void make_set(ll v) {
    parent[v] = v;
    siz[v]=1;
}

ll find_set(ll v) {
    if (v == parent[v])
        return v;
    return parent[v]=find_set(parent[v]);
}

void union_sets(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b)
    {
        if(ran[a]>=ran[b])
        {
            parent[b] = a;
            siz[a]+=siz[b];
            if(ran[a]==ran[b])
                ran[a]++;
        }
        else
        {
            parent[a] = b;
            siz[b]+=siz[a];
        }
    }
}

int main()
{
    FAST;
    ll n;
    cin>>n;
    ve<pair<ll,ll>> vec;
    map<pair<ll,ll>,ll> mp;
    for(ll i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        vec.pb({a,b});
        x[i]=a;
        y[i]=b; 
        mp[{a,b}]=i;
        make_set(i);
    }
    sor(vec);
    priority_queue<pair<ll,ll>, ve<pair<ll,ll>>, greater<pair<ll,ll>>> p;
    for(auto i:vec)
    {
        ll q=i.second;
        while(!p.empty() && (p.top()).first<i.second)
        {
            union_sets(mp[i],(p.top()).second);
            q=min(q,(p.top()).first);
            p.pop();
        }
        p.push({q,mp[i]});
    }
    for(ll i=0;i<n;i++)
        cout<<siz[find_set(i)]<<'\n';
    subt;
    return 0;
}


Measured memory_bytes: 26992
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static ConsoleApp.Util;
using static System.Math;
 
namespace ConsoleApp
{
    class Program
    {
       
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());

            int[] a = ReadLine().Split().Select(int.Parse).ToArray();

            for (int i = 0; i < n;i++)
            {
                
                
                if(a[i] % 2 == 0){
                    if(a[i] % 3 != 0 && a[i] % 5 != 0 ){
                        WriteLine("DENIED");
                        return;
                    }
                }
            }
            WriteLine("APPROVED");
            


        }

    }
 
 
    static class Util{
        public static void ChMin(ref long a,long b){
            
            if(a > b){
                a = b;
            }
        }
 
        public static void ChMax(ref long a,long b){
            if(a < b){
                a = b;
            }
        }
 
 
 
		
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
 
struct edge {int to,cap,rev;};
const int MAX_V=102,inf=1e18;
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void init(int V){
	rep(i,V) G[i].clear();
}
void add_edge(int from, int to, int cap){
	edge e1={to,cap,G[to].size()},e2={from,0,G[from].size()};
	G[from].push_back(e1);
	G[to].push_back(e2);
}
void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}
int dfs(int v,int t,int f){
	if(v==t) return f;
	for(int &i=iter[v];i<G[v].size();i++){
		edge &e=G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	while(true){
		bfs(s);
		if(level[t]<0) return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while( (f=dfs(s,t,inf))>0 ) flow+=f;
	}
}
 
 
signed main(){
	int N;
	cin>>N;
	int S = N, T = N+1;
	int off = 0;
	int allsum = 0;
	rep(i,N){
		int x;
		cin>>x;
		allsum += x;
		if(x>=0){
			add_edge(S,i,x);
			add_edge(i,T,0);
		}else{
			add_edge(S,i,0);
			add_edge(i,T,-x);
			off += x;
		}
	}
	rep1(i,N){
		for(int j=i*2;j<=N;j+=i){
			add_edge(j-1,i-1,inf);
		}
	}
	int f = max_flow(S,T) + off;
	cout << allsum - f << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  string s;
  cin >> s;
  int count = 0;
  rep(i, s.size() - 1) if (s[i] != s[i + 1]) count++;
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3716
import std.stdio;

void main(){
	auto cin = new Cin();
	auto S = cin.rect!(char[],"")()[0];
	//writeln(S);
	char[] c;
	foreach( s ; S ){
		switch( s ){
			case "0":
				c ~= "0";
				break;
			case "1":
				c ~= "1";
				break;
			case "B":
				c.length = 0<c.length ? c.length-1 : 0 ;
				break;
			default:break;
		}
	}
	
	(c).writeln();
}
auto solve(){
}
unittest{
	
}


import std.stdio,std.conv,std.string;
import std.algorithm,std.array;

class Cin
{
	T[] line( T = size_t , string token = " " )( size_t m = 1 ){
		T[] arr = [];
		foreach( i ; 0..m ){
			arr ~= this.read!T();
		}
		return arr;
	}
	T[][] rect( T = size_t , string token = " " )( size_t m = 1 ){
		T[][] arr = new T[][](m);
		foreach( i ; 0..m ){
			arr[i] = this.read!T(token);
		}
		return arr;
	}
	private T[] read( T = size_t )( string token = " " ){
		T[] arr;
		foreach( elm ; readln().chomp().split(token) ){
			arr ~= elm.to!T();
		}
		return arr;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A= sc.nextInt();
		int B = sc.nextInt();
		if (Math.abs(A-B)%2==0) {
			System.out.println("Alice");
		} else {
			System.out.println("Borys");
		}
	}
}

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

int main() {
  string s; cin>>s;
  int n=s.size();

  rep(i, n-1) {
    if (s[i]==s[i+1]) {
      cout<<i+1<<" "<<i+2<<endl;
      return 0;
    }
  }
  rep(i, n-2) {
    if (s[i]==s[i+2]) {
      cout<<i+1<<" "<<i+3<<endl;
      return 0;
    }
  }
  cout<<-1<<" "<<-1<<endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector <int> ans(n+1);
    int k;
    

    rep(i,n){
        cin >> k;
        ans[k]=i+1;
    }

    rep(i,n){
        printf("%d ",ans[i+1]);
    }
    

    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
using ll = long long;


int main(){
    ll n;
    string str;
    cin >> str;
    ll ans = 0;
    for(ll bit=0;bit<(1<<str.size()-1);bit++){
        ll num = str[0]-'0';
        for(ll i=0;i<str.size()-1;i++){
            if(bit&(1<<i)){
                ans+=num;
                num=0;
            }
            num = num*10+(str[i+1]-'0');
        }
        ans += num;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a;
    cin >> a;
    cout << a / 3;
}

Measured memory_bytes: 3612
A, B = map(int, input().split())

def cal_xor(X):
    X = X+1
    xor_sum = 0
    digit = 1
    while digit < X:
        digit *= 2
        bit_count = (X // digit) * (digit // 2)
        bit_count += max(0, (X % digit) - (digit // 2))
        
        if bit_count % 2 == 1:
            xor_sum += digit // 2
    
    return xor_sum
        

ans = cal_xor(A-1) ^ cal_xor(B)
print(ans)
   





Measured memory_bytes: 3060
K=int(input())
S=input()
N=len(S)
p=10**9+7
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N+K ):
    fact.append((fact[-1] * i) % p) # [-1]は後ろから?
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return (fact[n] * factinv[r] * factinv[n-r]) % p
A=0
TF=[1]
TS=[1]
for i in range(K+1):
    TF.append(TF[i]*25 %p)
    TS.append(TS[i]*26 %p)
for i in range(K+1): # Sに含まれる文字を加えるときは、必ず後ろであると考え、S[N-1]の(Sの文字を除いた)位置をiとする
    A=(A+TF[i]*TS[K-i]*cmb(i+N-1,i,p)) %p
print(A)

Measured memory_bytes: 226844
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			int N = scan.nextInt();
			long K = scan.nextLong();
			long[]A = new long[N];
			long[]a = new long[N];
			long[]z = new long[N+1];

			long mod = (long)1e9+7;
			Map<Long,Long>map = new TreeMap<Long,Long>();
			Map<Long,Long>map2 = new TreeMap<Long,Long>();

			for(int i = 0;i<N;i++) {
				A[i] = scan.nextLong();
				if(map.containsKey(A[i]))map.put(A[i], map.get(A[i])+1l);
				else map.put(A[i], 1l);

			}



			long go = 0;
			for(Long key:map.keySet()) {
				long x = map.get(key);
				//System.out.println(x);
				map2.put(key, go);
				go = (go+x)%mod;
			}



			for(int i = 0;i<N-1;i++) {
				for(int j = i+1;j<N;j++) {
					if(A[i]>A[j]) {
						a[i]++;
					}
				}
			}


			long goukei =0;

			for(int i = 0;i<N;i++) {

				goukei=(goukei+(K*a[i])%mod)%mod;

				long si = (K*(K-1)/2)%mod;

				goukei = (goukei+(si*map2.get(A[i]))%mod)%mod;

			}

			System.out.println(goukei);




		}


	}


}


Measured memory_bytes: 40768
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 606, mo = 1e9+7;
int n,p[N],g[N],qz[N],tot,f[N][N];
bool ok[N][N];
bool ck(int l, int r){
	if((r-l+1)&1)return 0;
	rep(i,l,r)if(p[i]&&(p[i]<l||p[i]>r))return 0;
	return 1;
}
int main() {
	read(n);n*=2;int k;read(k);while(k--){
		int u,v;read(u);read(v);p[u]=v;p[v]=u;qz[u]=qz[v]=1;
	}
	rep(i,1,n)qz[i]=qz[i-1]+(!qz[i]);tot=qz[n];
	rep(i,0,n)if(!(i&1)){g[i]=1;for(int j=i-1;j>1;j-=2)g[i]=1LL*g[i]*j%mo;}
	rep(i,1,n)rep(j,i,n)ok[i][j]=ck(i,j);
	ll ans=0;
	for(int t=2;t<=n;t+=2)rep(i,1,n-t+1)if(ok[i][i+t-1]){
		int j=i+t-1;ll res=g[qz[j]-qz[i-1]];
		for(register int k=i+1;k<j;k+=2)res-=1LL*f[i][k]*g[qz[j]-qz[k]]%mo;
		res=res%mo+mo;f[i][j]=res;ans+=res*g[tot-(qz[j]-qz[i-1])]%mo;
	//	res=(res%mo+mo)*g[tot-(qz[j]-qz[i-1])]%mo;ans+=res;f[i][j]=res;
	//	if(res)printf("%d %d:%lld\n",i,j,res*g[tot-(qz[j]-qz[i-1])]%mo);
	}
	printf("%lld",(ans%mo+mo)%mo);
	return 0;
}


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

using namespace std;

const int len = 100010;
int a[len],n,s[len];

int main() {
	ios :: sync_with_stdio(0);
	cin >> n;
	for (int i=1;i<=n;i++) {
		cin >> a[i];
	}
	sort(a+1,a+n+1);
	int sum = 1;
	for (int i=1;i<=n;i++) {
		if (!s[a[i]]) {
			int l = i;
			while (a[l] >= a[i]-1 && l > 0) {
				l--;
			}
			l++;
			int r = i;
			while (a[r] <= a[i]+1 && r <= n) {
				r++;
			}
			r--;
			s[a[i]] = r-l+1;
		}
		sum = max(sum,s[a[i]]);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int a, b,k;
int main()
{
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            cout << "OK" << endl;
            k = -1; break;
        }
    }
    if (k != -1)
    {
        cout << "NG" << endl;
    }
}

Measured memory_bytes: 3040
D, G = map(int,input().split())
Q=[0]+[list(map(int,input().split())) for i in range(D)]

def ans(a,b):
  if a==0:
    return 10**9
  n = min(b//(a*100), Q[a][0])
  score = a*100*n
  if n == Q[a][0]:
    score += Q[a][1]
  if score < b:
    n += ans(a-1, b-score)
  n = min(n, ans(a-1,b))
  return(n)

print(ans(D,G))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	string s;
	cin >> s;
	string p = s;
	reverse(p.begin(),p.end());
	
	if(p != s){
		cout << "No";
		return 0;
	}
	int n = s.size();
	
	p = s.substr(0,n/2);
	string q = p;
	reverse(q.begin(),q.end());
	
	if(p != q){
		cout << "No";
		return 0;
	}
	
	
	p = s.substr(n/2+1,n/2);
	q = p;
	reverse(q.begin(),q.end());
	
	if(p != q){
		cout << "No";
		return 0;
	}
	
	cout << "Yes\n";
	
	
	

	return 0;
}



Measured memory_bytes: 256
H, W, K = gets.split.map(&:to_i)

bc = 0 # 黒の数
tmpc = []
$c = []
# col = []
# col = col.fill(0, 0..H-1)
# row = []
# row = row.fill(0, 0..W-1)

H.times do |i|
  tmpc[i] = gets.chomp.split("")
  $c[i] = tmpc[i].map{ |x| (x=='#') ? 1 :0 }
  bc +=  $c[i].inject(:+)
end

# puts "#{$c}"
# tc = $c.transpose
# W.times do |j|
#   row[j] = tc[j].inject(:+)
# end

# bit全探索
n = H+W
ans = 0
(1 << n).times do |i|
  cnt = bc
  cc = Marshal.load(Marshal.dump($c))
  n.times do |j|
    if i[j] == 1 and j < H
      W.times do |k|
        if cc[j][k] == 1
          cc[j][k] = 0
          cnt -= 1
        end
      end
    elsif i[j] == 1 and j >= H
      H.times do |k|
        if cc[k][j-H] == 1
          cc[k][j-H] = 0
          cnt -= 1
        end
      end
    end
  end

  if cnt == K
    ans += 1
  end 
  
end

puts ans

Measured memory_bytes: 14384
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a;
		a = new int[100];
		int i;
		for(i = 0; i < n; ++i){
			int r = scan.nextInt();
			a[i] = r;
		}
		for(i = n - 1; i >= 0; --i){
			if(i == 0)
				System.out.print(a[i]);
			else 
				System.out.print(a[i]+" ");
		}
		System.out.println();
	}
}

Measured memory_bytes: 25944
// @samaranand
//
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define int64 long long
#define VI vector < int >
#define VII vector < vector < int > >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define pii pair < int , int >
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define sz(v) v.size()
//const string yo = "YES", no = "NO";
const int inf = 2e9 + 7;
//const long long biGinf = 9e+18;
const char nwl = '\n';

int visit[100105];


// int fun(VI &v, int n, int k, int m = 0) {
// 	int t = inf;
// 	if (m >= n - 1)
// 		return inf;
// 	for (int i = m + 1; i <= m + k and i < n; i++) {
// 		if (visit[i] == -1)
// 			visit[i] = fun(v, n, k, i);
// 		t = min(t, visit[i] + abs(v[m] - v[i]));
// 	}
// 	return t;

// }


int fun(VI &v, int n, int k, int m = 0) {
	int t = inf;
	if (m >= n - 1)
		return 0;
	for (int i = m + 1; i <= m + k and i < n; i++) {
		if (visit[i] == -1)
			visit[i] = fun(v, n, k, i);
		int a = abs(v[m] - v[i]) + visit[i];
		t = min(t, a);
	}
	return t;

}


int main() {

	//ur code
	for (int i = 0; i < 100005; i++)
		visit[i] = -1;
	int n, k;
	cin >> n >> k;
	VI v(n);
	inpv(v);
	cout << fun(v, n, k);
	//cout << "\ntest done";
	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 1e8;
const int INF = 1e9;
const int MOD = 998244353;



int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    for (int i = 1; i < n; i++) {
        if (s[i - 1] != s[i])
            ans++;
    }
    cout << ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
int main(){
	ll N,s;
	cin>>N>>s;
	for(ll b=2;b<=1000000;b++){
		ll x=0;
		ll tmp=N;
		while(tmp){
			x+=tmp%b;
			tmp/=b;
		}
		if(x==s){
			cout<<b<<endl;
			return 0;
		}
	}
	ll ans=1e18;
	if(N==s) chmin(ans,N+1);
	for(ll q=1;q<=1000000;q++){
		ll r=s-q;
		if(r<0) break;
		if(N-r<0) continue;
		if((N-r)%q>0) continue;
		ll b=(N-r)/q;
		if(b<=r) continue;
		chmin(ans,b);
	}
	if(ans==1e18) ans=-1;
	cout<<ans<<endl;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;


int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 1;
    for (int i = 1; i <= n; ++i) {
        if (i*i <= n) {
            ans = i*i;
        }
        if (i*i > n) {
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256