akhauriyash/Code-Regression huggingface dataset:
/*      西江月·证明
	即得易见平凡，仿照上例显然。
   留作习题答案略， 读者自证不难。

	反之亦然同理，推论自然成立。
	略去过程QED，由上可知证毕。*/
# pragma GCC optimize (1)
# pragma GCC optimize (2)
# pragma GCC optimize (3)
# pragma GCC optimize ("Ofast")
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdio>
#define kkk register
#define ll long long
#define inf 2147098934832ll
using namespace std;
ll read(){ll ans=0,f=1;char a=getchar();while(a>'9'||a<'0'){if(a=='-')f=-1;a=getchar();}while(a>='0'&&a<='9')ans=(ans<<3)+(ans<<1)+a-'0',a=getchar();return ans*f;}
//一条long long的黄金分割线-----------------------------------------------------------------------------------------------------------------------------------
ll a[2000005],n,m,sum,x;
int main(){
	n=read();
	for(int i=1;i<=n;i++)x=read(),a[x]++,sum+=x;m=read();
	for(int i=1;i<=m;i++){
		ll b=read(),c=read();
		sum+=a[b]*(c-b);
		a[c]+=a[b];a[b]=0;
		printf("%lld\n",sum);
	}
	return 0; 
} 

Measured memory_bytes: 4508
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
ll mod=998244353;

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  if(a[0]!=0){
    cout << 0 << endl; return 0;
  }
  ll ans=1;
  vector<ll> d(100000);
  ll m=0;
  for(int i=1;i<n;i++){
    d[a[i]]++; m=max(m,a[i]);
  }
  if(d[0]>0){
    cout << 0 << endl; return 0;
  }
  for(int i=1;i<m;i++){
    for(int j=0;j<d[i+1];j++){
      ans=ans*d[i]%mod;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
import Data.List

gather [] = []
gather list@(x:xs) = length b : gather a
  where
    (b,a) = span (==x) list


main = do
  n <- getLine
  s <- getContents >>= return . gather . sort . map head . (filter (\(x:_) -> elem x "MARCH")) . lines

  print $ f s

  where
    f [] = 0
    f (x:xs) = x * (g xs) + f xs
    g [] = 0
    g (x:xs) = x * (sum xs) + g xs


Measured memory_bytes: 12540
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <set>
#include <map>
#include <bitset>

using namespace std;

typedef long long LL;
typedef pair<LL, LL> LLLL;
typedef pair<LLLL, LLLL> LLLLLLLL;

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		LL n = -1;
		cin >> n;
		if (n < 0) return 0;
		vector<LL> a(n), b;
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		b.push_back(a[0]);
		for (int i = 1; i < n; ++i) {
			if (b.back() != a[i]) {
				if (b.size() >= 2 && b[b.size() - 2] > b.back() && b.back() > a[i]) {
					b.pop_back();
				}
				b.emplace_back(a[i]);
			}
		}
		a = b;
		n = a.size();
		a.push_back(a.back());
		a.push_back(a.back());

		vector<LLLLLLLL> q;
		q.emplace_back(LLLLLLLL(LLLL(1000, 1000), LLLL(0, 0)));
		for (int i = 0; i < n; ++i) {
			if (a[i] == a[i + 1]) continue;
			if (a[i] > a[i + 1] && a[i + 1] > a[i + 2]) continue;
			vector<LLLLLLLL> nq;
			if (a[i] < a[i + 1]) {
				for (auto kv : q) {
					LL m = kv.first.second;
					if (m < a[i]) {
						nq.emplace_back(kv);
					} else {
						LL x = m / a[i];
						LL s = kv.second.first + x;
						m -= a[i] * x;
						nq.emplace_back(LLLLLLLL(LLLL(s * a[i + 1] + m, m), LLLL(s, 0)));
						if (x > 1) {
							--s;
							m += a[i];
							nq.emplace_back(LLLLLLLL(LLLL(s * a[i + 1] + m, m), LLLL(s, 0)));
						}
					}
				}
			} else {
				for (auto kv : q) {
					LL m = kv.first.second + kv.second.first * a[i];
					nq.emplace_back(LLLLLLLL(LLLL(m, m), LLLL(0, 0)));
				}
			}
			sort(nq.begin(), nq.end());
			nq.resize(unique(nq.begin(), nq.end()) - nq.begin());
			sort(nq.rbegin(), nq.rend());
			if (nq.size() > 100000) {
				nq.resize(100000);
			}
			q = nq;
		}
		LL ans = 0;
		for (auto kv : q) {
			LL m = kv.first.second + kv.second.first * a[n - 1];
			ans = max(ans, m);
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main(){
    int a,b,c;
    const int CO=100;
    vector<int> vb;

    cin>>a>>b>>c;
    for (int i=1;i<CO+1;i++){
        if (a %i==0 && b % i==0){
        vb.push_back(i);
        }
    }
    reverse(vb.begin(),vb.end());
    cout<<vb[c-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int INF=2147483647;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
int n,k,a[1005];
ll ans;
int main(){
	n=read(),k=read();
	for(int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1);
	for(int i=1;i<=k;i++) ans+=a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3808
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := 5
	ml := make([]int, n+1)
	mln := make([]int, n+1)

	for i := 1; i < n+1; i++ {
		ml[i] = nextInt()
		if ml[i]%10 == 0 {
			mln[i] = ml[i]
		} else {
			mln[i] = ml[i] + (10 - ml[i]%10)
		}
	}

	var tl []int = []int{1, 2, 3, 4, 5}
	pall := permutations(tl)
	pallnum := make([]int, len(pall))
	for i := 0; i < len(pall); i++ {
		tmp := 0
		for j := 0; j < n; j++ {
			tmp += pall[i][j] * pow(10, n-j-1)
		}
		pallnum[i] = tmp
	}

	mint := 130 * 6
	for i := 0; i < len(pall); i++ {
		nowtime := 0
		for j := 0; j <= 3; j++ {
			nowtime += mln[pall[i][j]]
		}
		nowtime += ml[pall[i][5-1]] //最後だけ切り上げしない

		mint = min(nowtime, mint)
	}

	fmt.Println(mint)

}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func pow(a, b int) int {
	var ret int = 1
	for b > 0 {
		if (b & 1) == 1 {
			ret *= a
		}
		a *= a
		b >>= 1
	}
	return ret
}

// 順列
// 順列作成 (ランダム順)
// var tl []int = []int{1, 2, 3, 4, 5, 6, 7, 8}
// pall := permutations(tl)
//   -> [[],[],[]]
// 数値リスト化 例
//	pallnum := make([]int, len(pall))
//	for i := 0; i < len(pall); i++ {
//		tmp := 0
//		for j := 0; j < n; j++ {
//			tmp += pall[i][j] * pow(10, n-j-1)
//		}
//		pallnum[i] = tmp
//	}
func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1836
#include<cstdio>
int n,w,f[100005];
int min(int a,int b){return a<b?a:b;}
#define m 100000
int main()
{
	scanf("%d%d",&n,&w);
	for(int i=1;i<=m+1;i++)f[i]=1e9+1;//获得价值大等于i的物品的最小容量 
	for(int i=1,w,v;i<=n;i++)
	{
		scanf("%d%d",&w,&v);
		for(int j=m;j;j--)
		{
			if(j>=v)f[j]=min(f[j],f[j-v]+w);
			f[j]=min(f[j],f[j+1]);
		}
	}int l=1,r=m,ans=0;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(f[mid]<=w)ans=mid,l=mid+1;else r=mid-1;
	}printf("%d\n",ans);
}

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

int main() {
    vector<vector<int>> c(3,vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >>c[i][j];
        }
    }

    vector<int> a(3), b(3);
    a[0] = 0;
    b[0] = c[0][0];
    b[1] = c[0][1];
    b[2] = c[0][2];
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];

    string ret = "Yes";
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (a[i] + b[j] != c[i][j]) {ret = "No";}
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;



int main() {
	cout << fixed << setprecision(18);
	long long int n,m,c,now=0,sums=0,sumt=0,s[205]={},t[205]={},x;
	cin>>n>>m;
	while(n!=0){
		sums=0;sumt=0;x=INF;
		long long int ress,rest;
		for(int i=0;i<n;i++){
			cin>>s[i];
			sums+=s[i];
		}
		for(int i=0;i<m;i++){
			cin>>t[i];
			sumt+=t[i];
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(sums-s[i]+t[j]==sumt+s[i]-t[j]){
					if(s[i]+t[j]<x){x=s[i]+t[j];ress=s[i];rest=t[j];}
				}
			}
		}
		if(x==INF){cout<<-1<<endl;}
		else{cout<<ress<<" "<<rest<<endl;}
		cin>>n>>m;
	}
} 



Measured memory_bytes: 3056
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 

 int main(){
  ll n; cin>> n ;
  vector<ll> A(n) ;
  ll ma =0 ; ll ko = -1;
  bool ok= 0;
  rep(i,n){
    cin>>A[i] ;
    if(A[i]!=0)  ok=1 ;
  }
  if(!ok) cout<<0<<endl ;
  else{
    rep(i,n){
      if(abs(A[i])>ma){
        ma = abs(A[i]) ;
        ko = i ;
      }
    }
  
  cout<< 2*n-2<<endl ;
  rep(i,n){
    if(i!=ko) cout<<ko+1<<" "<<i+1<<endl ;
      }
   if(A[ko]<0){
     rep(i,n-1) cout<<n-i<<" "<<n-1-i<<endl ; 
   }
   else{
     rep(i,n-1) cout<< i+1<<" "<<i+2<<endl ;
   }

  }

   return 0 ;
 }



Measured memory_bytes: 3644
#include <iostream>
using namespace std;
long N, A[300010], B[300010];

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> N;
  for(int i = 0; i < N; ++i) {
    long a; cin >> a; --a;
    ++A[a]; // cnt
    ++B[A[a]]; // cnt of cnt
  }
  
  for(int i = 1; i < N; ++i) B[i+1] += B[i];

  for(int i = 1; i <= N; ++i) {
    long ok = 0, ng = N+1;
    while(ng - ok > 1) {
      long mid = (ok + ng) >> 1;
      if(B[mid] >= mid * i) ok = mid;
      else ng = mid;
    }
    cout << ok << '\n';
  }
  return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,x,y,t,i,x0=0,y0=0,t0=0;
	bool q=true;
	cin>>n;
	for (i=0;i<n;i++){
		cin>>t>>x>>y;
		int d=abs(x-x0)+abs(y-y0),t1=t-t0;
		if (t1<d||t1>d&&(t1-d)%2!=0){
			q=false;
		}
		x0=x;
		y0=y;
		t0=t;
	}
	if (q==false){
		cout<<"No";
	}
	else {
		cout<<"Yes";
	}
	return 0;
}

Measured memory_bytes: 256
n,m,k=map(int,input().split())
MOD=998244353
dp=[0] *(k+1)
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = MOD #出力の制限
N = 3*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans=0

for i in range(0,k+1):
    ans+=m*pow(m-1,n-i-1,MOD)*cmb(n-1,i,MOD)
    ans%=MOD
print(ans)

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

#define M 1000000007

typedef pair<int, int> P;
struct edge { int to, cap, cost, rev; };

int V = 366;
vector<edge> G[400];
int h[400];
int dist[400];
int prevv[400], preve[400];
void add_edge(int from, int to, int cap, int cost) {
    G[from].push_back((edge){ to, cap, cost, (int)G[to].size() });
    G[to].push_back((edge){ from, 0, -cost, (int)G[from].size() - 1 });
}

// テヲツオツ?」ツ?崚」ツ?ェテ」ツ??・ツ?エテ・ツ青暗」ツ?ッM
int min_cost_flow(int s, int t, int f) {
    int res = 0;
    fill(h, h + V, 0);
    while (f > 0) {
        priority_queue<P, vector<P>, greater<P> > q;
        fill(dist, dist + V, M);
        dist[s] = 0;
        q.push(P(0, s));
        while (!q.empty()) {
            P p = q.top();
            q.pop();
            int v = p.second;
            if (dist[v] < p.first) continue;
            for (int i = 0; i < (int)G[v].size(); ++i) {
                edge &e = G[v][i];
                if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
                    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                    prevv[e.to] = v;
                    preve[e.to] = i;
                    q.push(P(dist[e.to], e.to));
                }
            }
        }
        if (dist[t] == M) return M;
        for (int v = 0; v < V; ++v)
            h[v] += dist[v];

        int d = f;
        for (int v = t; v != s; v = prevv[v])
            d = min(d, G[prevv[v]][preve[v]].cap);

        f -= d;
        res += d * h[t];
        for (int v = t; v != s; v = prevv[v]) {
            edge &e = G[prevv[v]][preve[v]];
            e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}

int main()
{
    while (true) {
        int n;
        cin >> n;
        if (n == 0) return 0;
        for (int i = 0; i < 400; ++i) {
            G[i].clear();
            h[i] = 0;
            dist[i] = 0;
            prevv[i] = 0;
            preve[i] = 0;
        }
        for (int i = 0; i < V - 1; ++i) {
            add_edge(i, i + 1, 2, 0);
        }
        for (int i = 0; i < n; ++i) {
            int a, b, w;
            cin >> a >> b >> w;
            add_edge(a - 1, b, 1, -w);
        }
        cout << -min_cost_flow(0, V - 1, 2) << "\n";
    }
}

Measured memory_bytes: 3264
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
     Scanner sc = new Scanner(System.in);
     int a = sc.nextInt();
     int b = sc.nextInt();
     if ((a*b)%2==0){
     System.out.println("Even");
     }else {
         System.out.println("Odd");
        }
    }
}



Measured memory_bytes: 21716
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        System.out.println(t.length() - s.length() == 1 && t.startsWith(s) ? "Yes" : "No");
    }
}

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

int main(){
    int64_t N,A;
    cin>>N>>A;
    int64_t res=N;
    for(int k=1;k<=40;k++){//k回クッキーを食べる。
        int64_t tmp = A*k;
        int64_t X = (int64_t)(pow(1.0*N,1.0/(1.0*k+1.0)));
        bool flag=true;
        int64_t tt=1;
        for(int i=0;i<k+1;i++){
            tt*=X;
            if(tt>=N){
                flag=false;
                break;
            }
        }
        if(!flag){
            X--;
        }else{
            flag=false;
            tt=1;
            for(int i=0;i<k+1;i++){
                tt*=(X+1);
                if(tt>=N){
                    flag=true;
                    break;
                }
            }
            if(!flag){
                X++;
            }
        }
        int64_t lo=0;
        int64_t up=k+1;//X+1をかける回数
        while(up-lo>1){
            int64_t mid=(lo+up)/2;
            int64_t ttt=1;
            for(int i=0;i<mid;i++){
                ttt *= (X+1);
                if(ttt > N){
                    up = mid;
                    break;
                }
            }
            for(int i=mid;i<k+1;i++){
                ttt *= X;
                if(ttt > N){
                    up = mid;
                    break;
                }
            }
            if(ttt >= N){
                up = mid;
            }else{
                lo = mid;
            }
        }
        tmp += X*(k+1-up) + (X+1)*up;
        res = min(res,tmp);
    }
    cout<<res<<endl;
    return 0;
}


/*
const int MAX_N=10000000;
int memo[MAX_N]={};

int64_t solv(int64_t N,int64_t A){//目標個数と待機時間
//cout<<N<<' '<<A<<endl;
    if( A >= N || N<=4){
        if(memo[N]==0){
            memo[N]=N;
        }
        return N;
    }
    if(N < MAX_N && memo[N]!=0){
        return memo[N];
    }
    int64_t res=N;
    int64_t maaa = (int64_t)sqrt(2*N);
    //int64_t zzz = 2;
    int64_t sihyo;
    for(int64_t j=2;j <= maaa + 2;j--){
        int64_t tm;
        if(N%j==0){
            tm=N/j;
        }else{
            tm=N/j+1;
        }
        int64_t tmp;
        if(tm < MAX_N){
            if(memo[tm]!=0){
                tmp=memo[tm]+j+A;
            }else{
                memo[tm]=solv(tm,A);
                tmp=memo[tm]+j+A;
            }
            res = min(res,tmp);
        }else{
            tmp = solv(tm,A)+j+A;
            res = min(res,tmp);
        }
        if(j==2){
            sihyo=res;
        }else{
            if(tmp > sihyo){
                break;
            }
        }
    }
    if(N<MAX_N){
        memo[N]=res;
    }
    return res;
    
}


int main(){
    int64_t N,A;
    cin>>N>>A;
    int64_t tes= solv(N,A);
    //tes++;
    cout<<tes<<endl;
    
    
    
    return 0;
}
*/

Measured memory_bytes: 384
/**
*    created: 26.06.2020 23:03:46
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;
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;}

const int INF = 1LL << 60;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    vector<int> dp(n,INF);
    dp[0] = 0;
    rep(i,n) rep2(j,1,k+1) {
        int t = min(i+j,n-1);
        chmin(dp[t],dp[i]+abs(h[t]-h[i]));
    }
    cout << dp[n-1] << endl;
    return 0;
}

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

typedef long long ll;
const int N = 2000006;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin>>n;
	int ac=0,wa=0,tle=0,re=0;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s[0] == 'A')ac++;
		if(s[0] == 'W')wa++;
		if(s[0] == 'T')tle++;
		if(s[0] == 'R')re++;
	}
	
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<re<<endl;
	
	return 0;
}


Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			String a = scanner.next();
			if (a.equals("-")) {
				break;
			}
			int b = scanner.nextInt();
			int sum = 0;
			for (int i = 0; i < b; i++) {
				sum += scanner.nextInt();
			}
			String c = a + a;
			System.out.println(c.substring(sum % a.length(), sum
					% a.length() + a.length()));
		}
	}
}



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

int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto &e : v)
    cin >> e;
  int t;
  cin >> t;
  int cnt = 0;
  while (t--) {
    int x;
    cin >> x;
    if (find(v.begin(), v.end(), x) != v.end())
      ++cnt;
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))


signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int h,w; cin >> h >> w;
    char a[h][w];
    int cnt=0;
    rep(i,h)rep(j,w){
        cin >>  a[i][j];
        if(a[i][j]=='#') cnt++;
    }
    if(cnt!=h+w-1||a[0][0]!='#'||a[h-1][w-1]!='#'){
        cout << "Impossible" << endl;
        return 0;
    }
    int s=0,t=0;
    while((s!=h-1)&&(t!=w-1)){
        if(a[s+1][t]=='#') s++;
        else if(a[s][t+1]=='#') t++;
        else{
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N;
  cin >> N;

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

  sort(ALL(A), greater<>());

  int ans = A[0];
  int cnt = 1;
  FOR(i, 1, N){
    REP(j, 2){
      if(cnt == N-1){
        cout << ans << "\n";
        return 0;
      }
      ans += A[i];
      cnt++;
    }
  }

  return 0;
}


Measured memory_bytes: 4776
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;




void main() {
    long N;
    scan(N);

    long ans = infl;
    for (long i = 1; i*i <= N; i++) {
        if (N % i == 0) {
            chmin(ans, f(i, N / i));
        }
    }
    writeln(ans);
}

long f(long x, long y) {
    return max(x.to!string.length, y.to!string.length);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  rep(i, n) cout << s[i] << t[i];
  cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll MAXa = (ll)pow(10, 16) + 1000;

int main(){
  ll K;
  cin >> K;

  ll N = 50;
  vl a(N);
  a[0] = K / N;
  rep2(i, 1, 50) a[i] = a[i - 1] + 1;

  if(K % N > 0) a[N - (K % N)] = a[N - 1] + 1;

  cout << N << "\n";
  rep(i, N) cout << a[i] << ' ';
  cout << "\n";
  
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;


int main() {
	int N, K;
	cin >> N >> K;
	if (K == 1) {
		cout << 0 << endl;
	}
	else {
		cout << N - K << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
mod=10**9+7
A=set([int(input()) for i in range(M)])

data=[0 for i in range(N)]
if 1 not in A:
    data[0]=1
if N>=2:
    if 2 not in A:
        data[1]=1+data[0]


for i in range(2,N):
    if i+1 not in A:
        data[i]=data[i-1]+data[i-2]
        data[i]%=mod

#print(data)

print(data[-1])


Measured memory_bytes: 59476
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#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;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
const int nax=1000*1007;

int n;

int dlu[nax];

int wyn;

int main()
{
	scanf("%d", &n);
	wyn=n;
	for (int i=1; i<=n; i++)
	{
		int x;
		scanf("%d", &x);
		dlu[x]=dlu[x-1]+1;
		wyn=min(wyn, n-dlu[x]);
	}
	printf("%d\n", wyn);
	return 0;
}


Measured memory_bytes: 1024
import itertools

n = int(input())

p = list(map(int, input().split()))
q = list(map(int, input().split()))

falist = [0, 1]
for i in range(2, n):
    falist.append(falist[i-1] * i)
falist = falist[::-1]

pscore = 0
qscore = 0
for i in range(n-1):
    for j in range(i, n):
        if p[i] > p[j]:
            pscore += falist[i]
for i in range(n-1):
    for j in range(i, n):
        if q[i] > q[j]:
            qscore += falist[i]

print(abs(pscore - qscore))


Measured memory_bytes: 38384
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long X = nx[1];
        //ちゅーごくじょーよてーり
        //オーダーによってSの終端が決定する
        //まず影響するのは降順のみなことは自明に分かって、
        //で、「次」を選ぶことができる順番は
        //「確率」「期待値」
        //aを取り除いた場合、その後に適用できるのはそれ以前全て。

        List<int> s = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToList();
        ModInt[] dp = new ModInt[X + 1];
        dp[X] = 1;
        long remain = s.Count - 1;
        foreach (var mod in s)
        {
            ModInt[] newDP = new ModInt[X + 1];

            for (int i = 0; i < dp.Length; i++)
            {
                newDP[i % mod] += dp[i];
                newDP[i] += dp[i] * remain;
            }
            remain--;
            dp = newDP;
        }
        ModInt res = 0;
        for (int i = 0; i < dp.Length; i++)
        {
            res += dp[i] * i;
        }
        Console.WriteLine(res);
    }
}

struct ModInt
{
    static readonly int MOD = 1000000007;
    long Data;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator long(ModInt modInt) => modInt.Data;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator ModInt(long val) => new ModInt(val);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator +(ModInt a, ModInt b)
    {
        long res = a.Data + b.Data;
        return new ModInt() { Data = res >= MOD ? res - MOD : res };
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator +(ModInt a, long b) => new ModInt(a.Data + b);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator -(ModInt a, ModInt b)
    {
        long res = a.Data - b.Data;
        return new ModInt() { Data = res < 0 ? res + MOD : res };
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator -(ModInt a, long b) => new ModInt(a.Data - b);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator /(ModInt a, ModInt b) => a * Power(b, MOD - 2);

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static ModInt Power(ModInt n, long m)
    {
        ModInt res = 1;
        while (m > 0)
        {
            if ((m & 1) == 1) res *= n;
            n *= n;
            m >>= 1;
        }
        return res;
    }
}


Measured memory_bytes: 31496
S = list(input())
ma = 0
n = len(S)

for i in range(n):
    for j in range(n):
        if i <= j:
            reS = S[i:j+1]
            l = len(reS)
            re = reS.count("A") + reS.count("C") + reS.count("G") + reS.count("T")
            if l == re:
                ma = max(ma, re)

print(ma)

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

int main(){
	int N;
	vector<int> a;

	cin >> N;
	for(int i = 0; i < N; ++i){
		int ai; cin >> ai;
		a.push_back(ai);
	}

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

	int Alice = 0, Bob = 0;
	for(int i = 0; i < N; ++i){
		if(i % 2 == 0) Alice += a[i];
		else Bob += a[i];
	}

	cout << Alice - Bob << endl;

	return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

template <typename _Ty>
class UnionFind {
private:
    vector<_Ty> par;
    vector<_Ty> sz;

public:
    UnionFind(_Ty N) : par(N), sz(N, 1) {
        for (_Ty i = 0; i < N; ++i) par[i] = i;
    }

    _Ty root(_Ty x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

    bool same(_Ty x, _Ty y) {
        return root(x) == root(y);
    }

    void unite(_Ty x, _Ty y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (sz[x] < sz[y]) swap(x, y);
        par[y] = x;
        sz[x] += sz[y];
    }

    _Ty size(_Ty x) {
        return sz[root(x)];
    }
};

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

    ll N, M, K;
    cin >> N >> M >> K;
    UnionFind<ll> uf(N);
    Vl indeg(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        uf.unite(a, b);
        ++indeg[a], ++indeg[b];
    }
    vector<Vl> blocks(N);
    for (int i = 0; i < K; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        blocks[a].push_back(b);
        blocks[b].push_back(a);
    }
    Vl ans(N);
    for (int i = 0; i < N; i++) {
        ans[i] = uf.size(i) - 1 - indeg[i];
        for (const auto& b : blocks[i]) {
            if (uf.same(i, b)) --ans[i];
        }
    }
    for (int i = 0; i < N - 1; i++) {
        cout << ans[i] << " ";
    }
    cout << ans[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
int begin(int n){
  if(n<10) return n;
  while(n>=10){
    n/=10;
  }
  return n;
}

int end(int n){
  return n%10;
}

int main() {
  int n;
  cin>>n;
  long long ans=0;
  vector<vector<int>> memo(9,vector<int>(9,0));
  for(int i=1;i<=n;i++){
    if(end(i)==0) continue;
    memo[begin(i)-1][end(i)-1]++;
  }
  for(int i=0;i<9;i++){
    for(int j=i;j<9;j++){
      if(i==j) ans+=memo[i][i]*memo[i][i];
      else ans+=memo[i][j]*memo[j][i]*2;
    }
  }
  cout<<ans<<endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> xx,yy,zz;
#undef int
int main(){
	#define int long long
	int N,K;	cin>>N>>K;
	vector<int> sx(N),tx(N),sy(N),ty(N),sz(N),tz(N);
	for(int i=0;i<N;i++){
		cin>>sx[i]>>sy[i]>>sz[i]>>tx[i]>>ty[i]>>tz[i];
		xx.push_back(sx[i]);	xx.push_back(tx[i]);
		yy.push_back(sy[i]);	yy.push_back(ty[i]);
		zz.push_back(sz[i]);	zz.push_back(tz[i]);
	}
	sort(xx.begin(),xx.end());	xx.erase(unique(xx.begin(),xx.end()),xx.end());
	sort(yy.begin(),yy.end());	yy.erase(unique(yy.begin(),yy.end()),yy.end());
	sort(zz.begin(),zz.end());	zz.erase(unique(zz.begin(),zz.end()),zz.end());
	int ans=0;
	for(int i=1;i<(int)xx.size();i++){
		for(int j=1;j<(int)yy.size();j++){
			for(int k=1;k<(int)zz.size();k++){
				int cnt=0;
				for(int l=0;l<N;l++){
					if(sx[l]<=xx[i-1]&&xx[i]<=tx[l]&&sy[l]<=yy[j-1]&&yy[j]<=ty[l]&&sz[l]<=zz[k-1]&&zz[k]<=tz[l]){
						cnt++;
					}
				}
				if(cnt>=K){
					ans+=(xx[i]-xx[i-1])*(yy[j]-yy[j-1])*(zz[k]-zz[k-1]);
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int n, m;
string s;
vector<pair<char, int>> v;

int f(int x) {
	rep(i, 0, m) {
		if (s[x] == v[i].first)
			x += v[i].second;
	}
	return x;
}

template<class T, class U>
T lower_bound_on(T first, T last, const U& value, const function<U(T)>& fn) {
	T it, count, step;
	count = last - first;
	while (count > 0) {
		it = first;
		step = count / 2;
		it += step;
		if (fn(it) < value) {
			first = ++it;
			count -= step + 1;
		} else {
			count = step;
		}
	}
	return first;
}

template<class T, class U>
T upper_bound_on(T first, T last, const U& value, const function<U(T)>& fn) {
	T it, count, step;
	count = last - first;
	while (count > 0) {
		it = first;
		step = count / 2;
		it += step;
		if (!(value < fn(it))) {
			first = ++it;
			count -= step + 1;
		} else {
			count = step;
		}
	}
	return first;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	cin >> skipws;

	read(n, m, s);
	s = ' ' + s + ' ';
	v = vector<pair<char, int>>(m);
	rep(i, 0, m) {
		char c;
		read(v[i].first, c);
		v[i].second = c == 'L' ? -1 : 1;
	}

	int left = upper_bound_on<int, int>(0, n + 2, 1, f);
	int right = lower_bound_on<int, int>(0, n + 2, n + 1, f);

	write(right - left);
}


Measured memory_bytes: 4972
io = STDIN
n=io.gets.chomp.to_i
ar=[]
n.times do
  hash=Hash.new{|h,k|h[k]=0}
  s=io.gets.chomp
  s.split(//).sort.each do |ch|
    hash[ch]+=1
  end
  ar<<hash
end
cnt=Hash.new{|h,k|h[k]=0}
cnt=("a".."z").map do |k|
  ar.map do |hash|
    hash[k]
  end.min
end
ss= ("a".."z").zip(cnt).select{|ch,cnt|cnt>0}
puts ss.map{|ch,cnt|ch*cnt}.join


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

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

  int cnt01 = 0;
  for ( int i=0; i<S.size(); i++ ) {
	if (i % 2) {
	  if ( S[i] == '0' ) cnt01++;
	} else {
	  if ( S[i] == '1' ) cnt01++;
	}
  }

  int cnt10 = 0;
  for ( int i=0; i<S.size(); i++ ) {
	if (i % 2) {
	  if ( S[i] == '1' ) cnt10++;
	} else {
	  if ( S[i] == '0' ) cnt10++;
	}
  }

  cout << min(cnt01, cnt10) << endl;
  
  return 0;
}

Measured memory_bytes: 512
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=a[0::2]
c=a[1::2]
x=Counter(b)
y=Counter(c)
x1=list(x.most_common(1)[0])
y1=list(y.most_common(1)[0])

if x1[0]==y1[0]:
  if x1[1]==len(b):
    if y1[1]==len(c):
      print(len(c))
    else:
      y2=list(y.most_common(2)[1])
      print(len(c)-y2[1])
  elif y1[1]==len(c):
    x2=list(x.most_common(2)[1])
    print(len(b)-x2[1])
  
  else:
    x2=list(x.most_common(2)[1])
    y2=list(y.most_common(2)[1])   
    if x1[1]+y2[1]>=x2[1]+y1[1]:
      print(len(a)-x1[1]-y2[1])
    else:
      print(len(a)-y1[1]-x2[1])
  
else:
  xc=len(b)-x1[1]
  yc=len(c)-y1[1]
  print(xc+yc)


Measured memory_bytes: 19040
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	var N int
	var S string

	fmt.Scan(&N)
	fmt.Scan(&S)

	s := make([]int, len(S))
	for i := 0; i < len(S); i++ {
		if S[i] == 'o' {
			s[i] = 0
		} else {
			s[i] = 1
		}
	}

	for t0 := 0; t0 < 2; t0++ {
		for t1 := 0; t1 < 2; t1++ {
			t := make([]int, N)
			t[0] = t0
			t[1] = t1

			for i := 2; i < N; i++ {
				t[i] = (t[i-2] ^ t[i-1] ^ s[i-1])
			}
			if (s[N-1] == (t[N-2] ^ t[N-1] ^ t[0])) && (s[0] == (t[N-1] ^ t[0] ^ t[1])) {
				ans := ""
				for _, tt := range t {
					if tt == 0 {
						ans += "S"
					} else {
						ans += "W"
					}
				}
				fmt.Println(ans)
				return
			}

		}
	}

	fmt.Println(-1)

}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
#define print(a) {for(auto xxxxx : (a)) cout << xxxxx << ' '; cout << '\n';}
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
 
ll next(){ll x; cin >> x; return x;}
const int maxn = 1e5 + 3, intf = 2e9;
const ll inf = 2e18, mod = 998244353;
const ld eps = 1e-6;
 
 
void solve(){
	int a , b; cin >> a >> b;
	if (a <= b){
		cout << "unsafe\n";
	} else {
		cout << "safe\n";
	}
}
 
 
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(20);
    
    for (int t = 1; t--;) {
    	solve();
    }
 
	return 0;
}
/*
 
 
*/
 

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		//System.out.println("??\???>>");

		Scanner scan = new Scanner(System.in);

		int intNum = scan.nextInt();

		int intH = (intNum/60)/60;

		int intNum2 = intNum - intH * 60 * 60;

		//System.out.println("intNum2: " + intNum2);

		int intM = intNum2/60;

		int intS = intNum2 - intM * 60;



		System.out.println(intH + ":" + intM + ":" + intS);




	}

}

Measured memory_bytes: 17352
#include <iostream>
#include <iomanip>
#include <ios>
#include <sstream>
#include <cstdio>

#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <regex>
#include <utility>
#include <random>

#include <cstddef>
#include <cstdint>
#include <cfloat>
#include <limits>

#include <array>
#include <bitset>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <valarray>
#include <vector>
#include <deque>
#include <forward_list>

#define FOR(i, a, b) for(itr i{a}; i < (b); ++i)
#define RFOR(i, a, b) for(itr i{(b)-1};i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) std::begin(a), std::end(a)
#define CAST static_cast

template<typename T>
constexpr bool in_range(T const &l, T const &a, T const &u){ return l < a && a < u; };
constexpr double inf = std::numeric_limits<double>::infinity();

using i32 = std::int_fast32_t;  using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t;
using itr = i32;

using namespace std;


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

  string s;

  cin >> s;

  replace(ALL(s), ',', ' ');

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

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

int main(void) {
  ll n, k;
  cin>>n>>k;
  ll kk = (k==0)?1:k;
  ll ans = n*(n-kk+1) - (((n+kk)*(n-kk+1)) / 2);
  ll base = k+1;
  for(ll i=0; i+base<=n; i++) {
    ll init = 2*k+2*i+1;
    ll q = ((n-init)) / (base+i);
    if(init <= n)
      q++;
    ans+=q*(i+1);
    if(0<=(n-(init+(base+i)*q-i)+1))
      ans+=(n-(init+(base+i)*q-i)+1);
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
int main(){
  ll n;cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  deque<ll>d;
  rep(i,n){
    if((n-i)%2==0)d.push_back(a[i]);
    else d.push_front(a[i]);
  }
  rep(i,n-1)cout<<d[i]<<" ";
  cout<<d[n-1]<<endl;
}

Measured memory_bytes: 5376
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;

static void solve(){
 for(;;){
  int n=ir.nextInt();
  int k=ir.nextInt()-1;
  int m=ir.nextInt()-1;
  if(n==0&&k==-1&&m==-1) return;
  ArrayList<Integer> stone=new ArrayList<>();
  for(int i=0;i<n;i++) stone.add(i);
  stone.remove(m);
  int now=m;
  while(stone.size()>1){
   now=(now+k)%stone.size();
   stone.remove(now);
  }
  out.println(stone.get(0)+1);
 }
}

public static void main(String[] args) throws Exception{
 ir=new InputReader(System.in);
 out=new PrintWriter(System.out);
 solve();
 out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;

 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
 
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }

 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }

 public double nextDouble(){return Double.parseDouble(next());}

 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }

 public long[] nextLongArray(int n){
  long[] a=new long[n];
  for(int i=0;i<n;i++) a[i]=nextLong();
  return a;
 }

 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
}

Measured memory_bytes: 42524