akhauriyash/Code-Regression huggingface dataset:
#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)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Printer{
    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T>
    void print(vector<T> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class T>
    void print(vector<vector<T> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};
using namespace Printer;

//--global--//



//----------//

ll calc(ll n, ll m, vector<vector<ll> > vv, vector<int> out){
    vector<ll> v;
    rep(i, n){
        ll tmp = 0;
        rep(j, 3){
            vv[i][j] *= out[j];
            tmp += vv[i][j];
        }
        v.push_back(tmp);
    }
    sort(ALL(v), greater<ll>());
    ll res = 0;
    rep(i, m){
        res += v[i];
    }
    return res;
}

ll solve(ll n, ll m, vector<vector<ll> > vv, vector<int> out){
    if(out.size() == 3){
        return calc(n, m, vv, out);
    }
    ll res = 0;
    out.push_back(1);
    res = max(res, solve(n, m, vv, out));
    out.erase(out.end()-1);
    out.push_back(-1);
    res = max(res, solve(n, m, vv, out));
    return res;
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    ll n, m;
    cin >> n >> m;
    vector<vector<ll> > vv(n, vector<ll>(3));
    rep(i, n){
        rep(j, 3){
           cin >> vv[i][j];
        }
    }

    vector<int> tmp;
    cout << solve(n, m, vv, tmp) << endl;
    
    return 0;
}


Measured memory_bytes: 640
<?php
while(true){
    $input = explode(" ",trim(fgets(STDIN)));
    $x = $input[0];
    $y = $input[1];
    if($x == 0 && $y == 0) break;
    if($x > $y){
        echo $y." ".$x."\n";
    } else {
        echo $x." ".$y."\n";
    }
}

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

typedef long long ll;

vector<int> pos[3];
char let[3] = {'R', 'G', 'B'};

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

    int n;
    string s;
    cin >> n >> s;

    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            pos[0].push_back(i);
        }
        if (s[i] == 'G') {
            pos[1].push_back(i);
        }
        if (s[i] == 'B') {
            pos[2].push_back(i);
        }
    }

    ll ans = 0LL;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (s[i] == s[j]) continue;
            for (int x = 0; x < 3; x++) {
                if (s[i] != let[x] && s[j] != let[x]) {
                    ll xd = lower_bound(pos[x].begin(), pos[x].end(), j) - pos[x].begin();
                    ll cnt = pos[x].size() - xd;
                    int diff = j-i;
                    if (j+diff < n && s[j+diff] == let[x]) cnt--;
                    ans += cnt;
                }
            }
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

void solve() {
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    cout<<max({a * c, a * d, b * c, b * d});
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int t = 1;
    //cin>>t;
    for(int test = 1; test <= t; test++) {
        //cout<<"Case #"<<test<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
using System;

class Program {
  static void Main(string[] args) {
    string str = Console.ReadLine().Trim();
    int rep = 0;
    char stone = '?';

    foreach(char c in str) {
      if(stone == '?') { stone = c; }
      if(stone != c) {
        stone = c;
        ++rep;
      }
    }
    
    Console.WriteLine(rep);
  }
}


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

int main() {
	while (1) {
		int a;
		cin >> a;
		if (a == 0)break;
		int c;
		cin >> c;
		for (int b = 0; b < c; b++) {
			int d, e;
			cin >> d >> e;
			a -= e - d;
		}
		(a > 0) ? (cout << a << endl) : (cout << "OK" << endl);
	}
}

Measured memory_bytes: 3132
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    scanf("%d",&N);
    
    if(N%10 == 3)
    {
        printf("bon\n");
    }
    else if(N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8)
    {
        printf("pon\n");
    }
    else
    {
        printf("hon\n");
    }
}


Measured memory_bytes: 3660
#include <algorithm>
#include <iostream>
#include <cstdint>
#include <vector>

using namespace std;

// next/prev_combination were referenced to iso c++ papers of n2639.
template <class BidirIt>
bool next_combination( BidirIt t1, BidirIt e1, BidirIt t2, BidirIt e2 ) {
	if ( t1 == e1 || t2 == e2 ) return false;
	BidirIt m1 = e1, m2 = e2;
	for ( --m2; --m1 != t1 && *m2 <= *m1; );
	bool remain = m1 != t1 || *t1 < *m2;
	if ( remain ) {
		for ( t1 = m1; t2 != m2 && *t2 <= *m1; ++t2 );
		iter_swap( t1++, t2++ );
	}
	if ( t1 == e1 || t2 == e2 ) return remain;
	for ( m1 = e1, m2 = t2; m1 != t1 && m2 != e2; iter_swap( --m1, m2++ ) );
	reverse( t1, m1 ); reverse( t1, e1 ); reverse( m2, e2 ); reverse( t2, e2 );
	return remain;
}

template <class BidirIt>
inline bool next_combination( BidirIt first, BidirIt middle, BidirIt last ) {
	return next_combination( first, middle, middle, last );
}

template <class BidirIt>
inline bool prev_combination( BidirIt first, BidirIt middle, BidirIt last ) {
	return next_combination( middle, last, first, middle );
}

int gcd( int a, int b ) {
	if ( !b ) return a;
	return gcd( b, a % b );
}

int main() {
	int n;
	cin >> n;
	vector<int> a( n ), b( n ), c( n ), o( n );
	for ( int i = 0; i < n; i++ ) cin >> a[i];
	sort( a.begin(), a.end() );
	b[0] = a[0];
	c[n-1] = a[n-1];
	for ( int i = 1; i < n; i++ ) {
		b[i] = gcd( a[i], b[i-1] );
		c[n-1-i] = gcd( a[n-1-i], c[n-i] );
	}
	int r = c[1];
	for ( int i = 1; i < n - 1; i++ ) {
		int t = gcd( b[i-1], c[i+1] );
		if ( r < t ) r = t;
	}
	if ( r < b[n-2] ) r = b[n-2];
	cout << r << endl;
	return 0;
}


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

int main(){
  int N;
  string S;
  cin>>N>>S;
  vector<vector<ll>> count(N,vector<ll>(3,0));
  for(int i=0;i<N;i++){
    if(S.at(i)=='R'){
      count.at(i).at(0)=1;
    }else if(S.at(i)=='G'){
      count.at(i).at(1)=1;
    }else{
      count.at(i).at(2)=1;
    }
  }
  for(int i=1;i<N;i++){
    count.at(i).at(0)+=count.at(i-1).at(0);
    count.at(i).at(1)+=count.at(i-1).at(1);
    count.at(i).at(2)+=count.at(i-1).at(2);
  }
  ll ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(S.at(i)==S.at(j)){
        continue;
      }
      set<char> s;
      s.insert(S.at(i));
      s.insert(S.at(j));
      if(s.count('R')==0){
        ans+=count.at(N-1).at(0)-count.at(j).at(0);
        int k=j+(j-i);
        if(k<N){
          if(S.at(k)=='R'){
            ans--;
          }
        }
      }else if(s.count('G')==0){
        ans+=count.at(N-1).at(1)-count.at(j).at(1);
        int k=j+(j-i);
        if(k<N){
          if(S.at(k)=='G'){
            ans--;
          }
        }
      }else{
        ans+=count.at(N-1).at(2)-count.at(j).at(2);
        int k=j+(j-i);
        if(k<N){
          if(S.at(k)=='B'){
            ans--;
          }
        }
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3864
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	w := readInt()
	h := readInt()
	n := readInt()

	f := make([][]int, w)
	for i := range f {
		f[i] = make([]int, h)
		for j := range f[i] {
			f[i][j] = 1
		}
	}

	for k := 0; k < n; k++ {
		x := readInt()
		y := readInt()
		a := readInt()

		switch a {
		case 1:
			for i := 0; i < x; i++ {
				for j := 0; j < h; j++ {
					f[i][j] = 0
				}
			}
		case 2:
			for i := x; i < w; i++ {
				for j := 0; j < h; j++ {
					f[i][j] = 0
				}
			}
		case 3:
			for j := 0; j < y; j++ {
				for i := 0; i < w; i++ {
					f[i][j] = 0
				}
			}
		case 4:
			for j := y; j < h; j++ {
				for i := 0; i < w; i++ {
					f[i][j] = 0
				}
			}
		}
	}

	var ans int
	for i := range f {
		for j := range f[i] {
			ans += f[i][j]
		}
	}
	println(ans)

}


Measured memory_bytes: 768
k, n = map(int, input().split())
a = list(map(int, input().split()))

r = a[0] + (k - a[n - 1])

for i in range(1, n):
    if a[i] - a[i -1] > r:
        r = a[i] - a[i -1]

print(k - r)

Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define all(x) x.begin(), x.end()
#define uni(x) x.erase(unique(all(x)), x.end());
#define BUG(x) cout << #x << " = " << x << endl
#define BUGP(x) cout << #x << " = " << x._1 << ", " << x._2 << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto _i:x) cout << _i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 1e-6
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

int n, par[200005], deg[200005], vst[200005], val[200005];
queue<int> q;
vector<int> child[200005], v;

bool ok(int cur, int x) {
	val[cur] = x;
	int p = par[cur];
	v.clear();
	for (auto nex: child[p])
		v.pb(val[nex]);
	int chs = 0;
	sort(all(v));
	for (auto j: v) if (j == chs) chs++;
	if (vst[p]) {
		if (val[p] == chs) return true;
		else return false;
	} else {
		return ok(p, chs);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	FOR (i, 1, n) cin >> par[i], child[par[i]].pb(i), deg[par[i]]++;
	FOR (i, 1, n) if (!deg[i]) q.push(i);
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		vst[cur] = 1;
		deg[par[cur]]--;
		if (!deg[par[cur]]) q.push(par[cur]);
		v.clear();
		for (auto nex: child[cur]) v.pb(val[nex]);
		sort(all(v));
		int chs = 0;
		for (auto i: v) if (i == chs) chs++;
		val[cur] = chs;
	}
	// PR(vst, 1, n);
	FOR (i, 1, n) if (!vst[i]) {
		vst[i] = 1;
		v.clear();
		for (auto nex: child[i]) if (vst[nex])
			v.pb(val[nex]);
		sort(all(v));
		int chs1 = 0;
		for (auto j: v) if (j == chs1)
			chs1++;
		v.pb(chs1);
		sort(all(v));
		int chs2 = 0;
		for (auto j: v) if (j == chs2)
			chs2++;
		if (ok(i, chs1)) cout << "POSSIBLE";
		else if (ok(i, chs2)) cout << "POSSIBLE";
		else cout << "IMPOSSIBLE";
		return 0;
	}
}	


Measured memory_bytes: 13440
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(30);
using namespace std;

int main()
{
    IOS;
    string s;
    cin>>s;
    for(char c='a'; c<='z'; c++){
        if(s.find(c)==-1){
            cout<<c;
            return 0;
        }
    }
    cout<<"None";
    return 0;
}


Measured memory_bytes: 3740
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		int[] l = new int[q];
		int[] r = new int[q];
		int max = Integer.MIN_VALUE;
		for(int i = 0; i < q; i++) {
			int ltmp = sc.nextInt();
			int rtmp = sc.nextInt();
			max = Math.max(rtmp, max);
			l[i] = ltmp;
			r[i] = rtmp;
		}
		int[] sum = new int[max + 1];
		boolean[] pri = new boolean[max + 1];
		pri[2] = true;
		for(int i = 0; i < max + 1; i++) {
			sum[i] = 0;
		}
		for(int i = 3; i < max + 1; i = i + 2) {
			boolean flag = true;
			for(int j = 3; j < i / 2; j = j + 2) {
				if(i % j == 0) {
					flag = false;
					break;
				}
			}
			if(flag)
				pri[i] = true;
			if(flag && pri[(i + 1) / 2]) {
				sum[i]++;
			}
			sum[i] += sum[i - 2];
		}
		for(int i = 0; i < q; i++) {
			int ans = 0;
			if(l[i] == 1) {
				ans += sum[r[i]] - sum[l[i]];
			} else {
				ans += sum[r[i]] - sum[l[i] - 2];
			}
			System.out.println(ans);
		}
	}

}


Measured memory_bytes: 91652
n = int(input())
_input = input().split()

l_index = 0
r_index = n - 1


while (l_index < r_index):
    temp = _input[l_index]
    _input[l_index] = _input[r_index]
    _input[r_index] = temp
    l_index += 1
    r_index -= 1

for i in range(0 ,n):
    if (i == n-1):
        print(_input[i])
    else :
        print(_input[i], end = ' ') 


Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>

#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vstr vector<string>

using namespace std;

int main()
{
	ll a, b, c;
	cin >> a >> b >> c;
	ll k;
	cin >> k;
	ll ans = 0;
	while (a >= b)
	{
		b *= 2;
		ans++;
	}

	while (b >= c)
	{
		c *= 2;
		ans++;
	}

	if (ans > k)
	{
		cout << "No" << endl;
	}
	else cout << "Yes" << endl;
}

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

bool parse(string a, int& i)
{
	switch (a[i])
	{
	case 'T': i++; return true;
	case 'F': i++; return false;
	case '-': i++; return !parse(a, i);
	}

	i++;
	bool aa = parse(a, i);

	int flag = -1;
	switch (a[i])
	{
	case '*': i++; flag = 0; break;
	case '+': i++; flag = 1; break;
	case '@': i++; flag = 2; break;
	}

	bool bb = parse(a, i);
	i++;

	switch (flag)
	{
	case 0: return aa && bb;
	case 1: return aa || bb;
	}

	if (aa && !bb) return false;
	return true;
}

bool eval(string a, string b)
{
	int i = 0;
	bool aa = parse(a, i);
	i = 0;
	bool bb = parse(b, i);

	if (aa == bb) return true;
	return false;
}

string replace(string src, string from, string to)
{
	string::size_type Pos(src.find(from));
	while (Pos != string::npos)
	{
		src.replace(Pos, from.length(), to);
		Pos = src.find(from, Pos + to.length());
	}
	return src;
}

int main()
{
	while (1)
	{
		string s; cin >> s;
		if (s[0] == '#') return 0;

		s = replace(s, "->", "@");

		int equ = s.find("=");
		string left = s.substr(0, equ);
		string right = s.substr(equ+1);

		bool ans = true;
		rep(i, 0, 1 << 11)
		{
			string a = left;
			string b = right;
			string c = "a";
			rep(j, 0, 11)
			{
				c[0] = 'a' + j;
				if (i & (1 << j))
				{
					a = replace(a, c, "T");
					b = replace(b, c, "T");
				}
				else
				{
					a = replace(a, c, "F");
					b = replace(b, c, "F");
				}
			}

			if (!eval(a, b)) ans = false;
		}

		if (ans)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

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

int main(){
    string a,b,c;cin >> a >> b >> c;
    if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
r=0
for i,aa in enumerate(A):
    for j,a in enumerate(aa[i+1:]):
        f=1
        j+=i+1
        for k in range(N):
            if k==i or k==j:
                continue
            if a>A[i][k]+A[k][j]:
                f=r=-1
                break
            if a==A[i][k]+A[k][j]:
                f=0
                break
        if f==1:
            r+=a
        elif f==-1:
            break
    if r<0:
        break
print(r)

Measured memory_bytes: 44252
while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0:
        break

    count = 0
    for a in range(1, n + 1 - 2):
        for b in range(a + 1, n + 1 - 1):
            for c in range(b + 1, n + 1):
                if (a + b + c) == x:
                    count += 1
    print(count)

Measured memory_bytes: 6724
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
//typedef pair<int, int> P;

/** Problem0506 : String **/
int main()
{
	int N; string s;
	while (cin>>N, N) {
		cin>>s;
		s+='*';
		
		string ans;

		rep(j, N) {
			char base = s[0];
			int num=1;
			ans = "";
			REP(i, 1, s.size()) {
				if (s[i] == base)
					num++;
				else {
					stringstream ss;
					string t;
					ss<<num;
					ss>>t;
					ans += t;
					ans += base;
					base = s[i];
					num = 1;
				}
			}
			s = ans;
			s += '*';
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1336
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=405,mod=998244353;
int n,a[N],f[N<<1][N][N][2],pw2[N],C[N][N],id[N][N],size[N<<1],tot;
//f[i][j][k][0/1] i:state j:height k:unfilled number 0/1 is under finished?
inline void inc(int& x,CI y)
{
	if ((x+=y)>=mod) x-=mod;
}
inline int DP(CI l=1,CI r=n,CI h=0)
{
	if (l>r) return f[0][h][0][0]=f[0][h][0][1]=1,0;
	int &now=id[l][r],pos=l; RI i,j; if (!now) now=++tot;
	for (i=l+1;i<=r;++i) if (a[i]<a[pos]) pos=i;
	if (a[pos]==h) //remove the lowest column
	{
		int x=DP(l,pos-1,h),y=DP(pos+1,r,h);
		size[now]=size[x]+size[y]+1; //size calculated the number of column
		for (i=0;i<=size[x];++i) for (j=0;j<=size[y];++j)
		inc(f[now][h][i+j][0],1LL*f[x][h][i][0]*f[y][h][j][0]%mod), // if draw
		inc(f[now][h][i+j+1][1],1LL*f[x][h][i][1]*f[y][h][j][1]%mod); //or so
	} else //remove the lowest row
	{
		for (DP(l,r,h+1),i=0;i<=size[now];++i)
		inc(f[now][h][i][0],f[now][h+1][i][1]),inc(f[now][h][i][1],f[now][h+1][i][1]),//filled draw or not
		inc(f[now][h][i][0],1LL*f[now][h+1][i][0]*(pw2[size[now]-i]-1)%mod),
		//draw i columns and fill other size[now]-i columns (can't all empty)
		inc(f[now][h][i][1],1LL*f[now][h+1][i][1]*(pw2[size[now]-i]-1)%mod);
		for (i=1;i<=size[now];++i) for (j=1;j<=i;++j)
		inc(f[now][h][i-j][0],1LL*f[now][h+1][i][0]*pw2[size[now]-i]%mod*C[i][j]%mod),
		//choose j columns from i filled columns, other columns are filled optionally
		inc(f[now][h][i-j][1],1LL*f[now][h+1][i][1]*pw2[size[now]-i]%mod*C[i][j]%mod);//same as above
	}
	return now;
}
int main()
{
	RI i,j; for (scanf("%d",&n),i=1;i<=n;++i) scanf("%d",&a[i]);
	for (pw2[0]=i=1;i<=n;++i) pw2[i]=2LL*pw2[i-1]%mod;
	for (C[0][0]=i=1;i<=n;++i) for (C[i][0]=j=1;j<=n;++j)
	C[i][j]=C[i-1][j-1],inc(C[i][j],C[i-1][j]);
	int now=DP(); return printf("%d",f[now][0][0][0]),0;
}

Measured memory_bytes: 494848
N = gets.to_i
a = []
b = []
N.times do |i|
  a[i],b[i] = gets.split(' ').map(&:to_i)
end

a.sort!
b.sort!
if N.odd?
  # 中央値の範囲を求める
  m = (N+1)/2
  min = a[m-1]
  max = b[m-1]
  puts max-min+1
else
  m = N/2
  min = (a[m-1] + a[m])
  max = (b[m-1] + b[m])
  puts max-min+1
end


Measured memory_bytes: 20024
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<queue>
#include<vector>
//#include<Windows.h>
using namespace std;
#define ll long long int
#define LL ll
#define INF 0x3f3f3f3f
const int maxn = 1e2 + 10;
struct node {
	string str;
	int sco;
	int id;
	int cs;
}a[maxn];
bool cmp(node a, node b) {
	if (a.str == b.str) {
		return a.sco > b.sco;
	}
	return a.str < b.str;
}
bool cmp2(node a, node b) {
	return a.id < b.id;
}
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		cin >> a[i].str;
		cin >> a[i].sco;
		a[i].id = i;
	}
	sort(a + 1, a + 1 + n, cmp);
	/*for (int i = 1; i <= n; i++) {
		a[i].cs = i;
	}
	sort(a + 1, a + 1 + n, cmp2);
	for (int i = 1; i <= n; i++) {
		cout << a[i].cs << endl;
	}*/
	for (int i = 1; i <= n; i++) {
		cout << a[i].id << endl;
	}
	return 0;
}

Measured memory_bytes: 256
s=list(input())
count=0
kaisu=1
while kaisu>0:
  kaisu=0
  n=len(s)
  for i in range(0,n):
    i=n-i-1
    try:
      if s[i]!=s[i-1]:
        count+=1
        kaisu+=1
        s.pop(i)
        s.pop(i-1)
    except IndexError:
      pass

print(count*2)

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

const int mod = 2019;

int main() {
	ll l, r;
	cin >> l >> r;

	ll ans = 2019 * 2019;
	if (r - l >= mod) {
		cout << 0 << endl;
		return 0;
	}
	else {
		for (ll i = l; i < r; i++) {
			for (ll j = i + 1; j <= r; j++) {
				ll c = (i * j) % mod;
				ans = min(c, ans);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <unordered_map>
#include <math.h>
using namespace std;
#define _USE_MATH_DEFINES

int main() {
	double a;
	cin >> a;
	double PI = 3.141592653589793238463;
	cout << setiosflags(ios::fixed) << setprecision(10) << a*a*PI << " " << a * 2 * PI << endl;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second

int main(){
    FAST
    int k, x; cin >> k >> x;
    int left = max(x - k + 1, -1000000);
    int right = min(x + k - 1, 1000000);
    for(int i = left; i <= right; i++){
        cout << i << " ";
    }
    return 0;
}


Measured memory_bytes: 3576
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  int a,b,tmp,x=1,A=0;
  cin>>a>>b;
  if(a>b)
  {
    tmp=a;
    a=b;
    b=tmp;
  }
  for(int i=1; i<b; i++)
  {
    x=x*10;
    A=A+x*a;
  }
  A=A+a;
  cout<<A<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k % 2 == 0){
        cout << a - b << endl;
    } else {
        cout << (b + c) - (a + c) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
    int X,T;
    cin>>X>>T;

    cout<<max(0,X-T)<<endl;

    return 0;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{
  gearup;
  ll n,a,b; cin >> n >> a >> b;
  vl x(n);
  rep(i,n)cin>>x[i];
  ll res = 0;
  rep(i,n-1){
    ll dist = x[i+1] - x[i];
    res += min(dist*a,b);
  }
  out(res);
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
int main(){
    int N;
    int s[108];
    int sum=0;
    bool suc=0;
    cin >> N;
    REP(i,N){cin >> s[i];sum+=s[i];}
    sort(s,s+N);
    if(sum%10!=0){
        cout << sum << endl;
    }else{
        REP(i,N){
            if(s[i]%10!=0){
                cout << sum-s[i] << endl;
                suc=1;
                break;
            }
        }
        if(suc==0){
            cout << "0" << endl;
        }
    }
 return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef long long tnum;

#define loop(i, num) for(int i = 0; i < num; i++)

tnum* tnumAlloc(int num);
tnum getNumStdin();
tnum* getNumsStdin(int);
char* getCharsStdin(int maxlength);
string getStringStdin();
void printlnNums(int count, tnum* nums);
void printlnNum(tnum num);
void printString(string str);

#define min(a,b) (a <= b ? a : b)
#define max(a,b) (a >= n ? a : b)

/*void sort(T* start, T* end) (in <algorithm>)
example:
	int a[5] = {2, 1, 3, 5, 4};
	sort(a, a + 5);
	-> a: {1, 2, 3, 4, 5}
*/

int main() {
    char *s, *t;

    tnum n = getNumStdin();
    tnum *a = getNumsStdin(n);

    tnum sum1 = 0;
    tnum sum2 = 0;

    loop(i, n){
        sum2 += sum1 * a[i];
        sum2 %= 1000000007;
        sum1 += a[i];
        sum1 %= 1000000007;
    }

    printlnNum(sum2);

    return 0;
}



//have to be free()
tnum* tnumAlloc(int num) {
	return (tnum*)calloc(num,sizeof(tnum));
}

tnum getNumStdin() {
	tnum ret;
	scanf("%lld", &ret);

	return ret;
}

//have to be free()
tnum* getNumsStdin(int num) {
	tnum* buf;
	tnum* tmp;
	buf = tnumAlloc(num);
	for (int i = 0; i < num; i++) {
		scanf("%lld", &buf[i]);
	}

	return buf;
}

//have to be free()
char* getCharsStdin(int maxlength) {
	char* ret = (char*)malloc(maxlength+1);
	scanf("%s", ret);

	return ret;
}

//have to be free()
string getStringStdin() {
	string ret;
	cin >> ret;
	return ret;
}

void printlnNum(tnum num) {
	printf("%lld\n", num);
}

// can be used for debugging
void printlnNums(int count, tnum *nums) {
	loop(i, count) {
		printf("%lld", nums[i]);
		if (i != count - 1) printf(" ");
	}
	printf("\n");
}

void printString(string str) {
	cout << str;
}


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

int main() {

  int N;
  cin >> N;

  string tmp;
  map<string, int> m;
  int max = 0;
  for(int i = 0; i < N; i++){
    cin >> tmp;
    m[tmp]++;
  }

  for(auto iter = m.begin(); iter != m.end(); iter++){
    if(iter->second > max){
      max = iter->second;
    }
  }

  for(auto iter = m.begin(); iter != m.end(); iter++){
    if(iter->second == max){
      cout << iter->first << endl;
    }
  }
}

Measured memory_bytes: 25216
#include<stdio.h>
#define MAX 2000000

int n, A[MAX+1];

void maxHeapify(int i){
  int l, r, largest, t;
  l = 2*i;
  r = 2*i+1;
  if ( l <= n && A[l] > A[i] ) {
largest = l;
}
  else largest = i;

  if ( r <= n && A[r] > A[largest] ) {
largest = r;
}
  if ( largest != i ){
    t = A[i]; A[i] = A[largest]; 
    A[largest] = t;
    maxHeapify(largest);
  }
}

main(){
  scanf("%d", &n);
  int i;
  for ( i = 1; i <= n; i++ ) {
scanf("%d", &A[i]);
  }

  for ( i = n/2; i >= 1; i-- ) {
maxHeapify(i);
}

  for ( i = 1; i <= n; i++ ) {
    printf(" %d", A[i]);
  }
  printf("\n");
  

  
  return 0;
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int count(int n, int a)
{
  if(n %a != 0){
    return 0;
  }else{
    return 1 + count(n/a, a);
  }
}
int main()
{
  int a;
  cin >> a;
  int ans = 0;
  REP(i, a + 1){
    if(i%2 == 1){
      int tmp = (count(i, 3) + 1)*(count(i, 5) + 1)*(count(i, 7) + 1)*(count(i, 11) + 1)*(count(i, 13) + 1)*(count(i, 17) + 1);
      if(tmp == 8){
	// cout << i << " "<< count(i, 3) << " " << count(i, 5) << " " << count(i, 7)<<endl;
	ans ++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
class CMB_C():
    def __init__(self, mod=10**9+7,mx=10**5):#mx:入力制限
        N = mx
        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)
        self.g1 = g1
        self.g2 = g2
        self.mod = mod

    def cmb(self, n, r):  # 素数で割って出力　の場合
        if (r < 0 or r > n):
            return 0
        r = min(r, n-r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod

CMB=CMB_C(mx=2001)
def main():
    import sys
    A=int(sys.stdin.readline())
    res=0
    for i in range(1,A):
        B=A-i*3
        if B<0:
            break
        res+=CMB.cmb(B+i-1,i-1)
        res%=10**9+7
    print(res)
main()

Measured memory_bytes: 9420
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int n; cin >> n;
    vector<int> a(n+1,0);
    rep(i,n) cin >> a[i];
    ll m = 1000;
    ll cabu = 0;
    rep(i,n) {
        if (a[i] < a[i+1]) {
            cabu += m / a[i];
            m -= (m / a[i]) * a[i];
        } else if (a[i] > a[i+1]){
            m += cabu * a[i];
            cabu = 0;
        } else {
            continue;
        }
    }
    cout << m << endl;

    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
//#include <stdlib.h>
using namespace std;
int main(void)
{
    int N, A, B;
    cin >> N >> A >> B;
    int Min, Max;
    //最大は小さいほうが大きいほうの部分集合
    if (A < B)
        cout << A << " ";
    else
        cout << B << " ";
    //最小は共通部分のない集合、合計が全体を超えた分は共通部分
    if (A + B - N > 0)
        cout << A + B - N << endl;
    else
        cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	COMinit();
	int H,W,A,B;
	cin >> H >> W >> A >> B;
	ll ans = 0;
	//1行目からH-A行目までについてi行目の移動回数は
	//右への移動回数は(B-1)回なので 場合の数は(B-1)+(i-1)_C_B-1;
	for(int i=1;i<=H-A;i++){
		ll t = COM(B-1+(i-1),B-1);
		//またi行目について右下までいく場合の数は
		//下にH-i-1回移動して、右にW-B-1回移動するので
		ans += t*COM( (H-i) + W-B-1,H-i);
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 12288
#include<iostream>
#include<cmath>
main(){int e,x,y,z,m;for(;std::cin>>e,m=e;printf("%d\n",m))for(z=-1;++z*z*z<=e;x=e-y*y-z*z*z,m=m>x+y+z?x+y+z:m)y=pow(e-z*z*z,0.5);}

Measured memory_bytes: 0
// AOJ 2883: Proof of Knowledge
// 2018.7.11 bal4u

#include <stdio.h>

char *calc(int *ans, char *S, char *P)
{
	int v1, v2;
	char op;
	
    if (*S == '[') {
        op = *(++S), S++;
        if (*S == '[') S = calc(&v1, S, P);
        else {
            if (*S == 'a') v1 = P[0];
            else if (*S == 'b') v1 = P[1];
            else if (*S == 'c') v1 = P[2];
            else v1 = P[3];
            S++;
		}

        if (*S == '[') S = calc(&v2, S, P);
        else {
            if (*S == 'a') v2 = P[0];
            else if (*S == 'b') v2 = P[1];
            else if (*S == 'c') v2 = P[2];
            else v2 = P[3];
            S++;
		}
		
        if (op == '+') *ans = v1 | v2;
        else if (op == '*') *ans = v1 & v2;
        else *ans = v1 ^ v2;
	} else {
        if (*S == 'a') *ans = P[0];
        else if (*S == 'b') *ans = P[1];
        else if (*S == 'c') *ans = P[2];
        else *ans = P[3];
        S++;
	}
    while (*S == ']') S++;
    return S;
}

char S[100];
int main()
{
	int i, k, val, cnt;
	char P[10];
	
	while (fgets(S, 100, stdin) && *S != '.') {
		fgets(P, 10, stdin);
		for (i = 0; i < 4; i++) P[i] &= 0xf;
		calc(&val, S, P), cnt = 0;
		for (P[0] = 0; P[0] <= 9; P[0]++)
			for (P[1] = 0; P[1] <= 9; P[1]++)
				for (P[2] = 0; P[2] <= 9; P[2]++)
					for (P[3] = 0; P[3] <= 9; P[3]++) {
						calc(&k, S, P);
						if (k == val) cnt++;
					}
		printf("%d %d\n", val, cnt);
	}
	return 0;
}



Measured memory_bytes: 2024
#include <vector>
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<string> s(N);
    for(int i=0; i<N; ++i) cin >> s[i];

    set<string> st;

    for(int i=0; i<N; ++i){
            st.insert(s[i]);
    }

    cout << st.size() << endl;
}

Measured memory_bytes: 25008
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define pii pair<int,int>
#define x first
#define y second

const int N=20;
int ans=1e9,n,a[N],b[N],pos[N];
pii p[N],q[N];
bool v[N];

int count(int s){
	int cnt=0;
	while(s) s^=s&(-s),cnt++;
	return cnt;
}

signed main(){
	read(n);
	for(int i=1;i<=n;i++) read(a[i]);
	for(int i=1;i<=n;i++) read(b[i]);
	for(int s=0;s<(1<<n);s++){
		int cnt=0;
		for(int i=1;i<=n;i++) cnt+=s>>i-1&1,q[i]=p[i]=s>>i-1&1?pii(b[i],1):pii(a[i],0);
		if(cnt&1) continue;
		sort(q+1,q+1+n);
		for(int i=1;i<=n;i++) v[i]=0;
		cnt=0;
		for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(!v[j]&&q[j].x==p[i].x&&(abs(i-j)&1)==p[i].y) {v[j]=1;pos[i]=j;cnt++;break;}
		if(cnt<n) continue;
		cnt=0;
		for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) cnt+=pos[i]>pos[j];
		ans=min(ans,cnt);
	}
	if(ans==1000000000) ans=-1;
	write(ans);
}

Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string.h>
#include <algorithm>
#include <math.h>
//#include <bits/stdc++.h>
#define ll long long
#define wtcl return
using namespace std;

inline int read()
{
	ll s = 0, f = 1;
	char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = - 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) s = ((s << 3ll) + (s << 1ll) + (ch ^ 48ll));
	return s * f ;
}
int main()
{
	int n,m;

	while(cin>>n>>m)
	{
		int k = m%n;
		int l = m/n;
		if(n==1)
		{
			cout<<m<<endl;
		}
		else if(n == 2)
		{
			if(m&1)
				cout<<1<<endl;
			else cout<<m/2<<endl;
		}
		else
		{
			if(k!=0)
			{
				int ans = 1;
				for(int i=0; i<l ; i++)
				{
					if( (k+(n-1)*i+l) % (l-i) == 0 )
					{
						ans = l-i;
						break;
					}
//					int x = i*(n-1);
//					int y = m-x;
//					int z = __gcd(y,i);
//					ans = max(ans,z);
				}
				cout<<ans<<endl;
			}
			else cout<<m/n<<endl;
		}

	}
	wtcl 0;
}

Measured memory_bytes: 256
H,W,D = map(int, input().split())
fields = []
amaris = [[0] * (H*W//D+1) for i in range(D)] # あまり
for i in range(H):
    row = list(map(int, input().split()))
    # あまりがいくつかで分類
    for j,e in enumerate(row):
        n = (e-1) // D
        m = (e-1) % D
        amaris[m][n] = (i,j)

# あまりごとに累積和を取っておく
acc = [[0] * (H*W//D+1) for i in range(D)]
for i in range(D):
    cnt = 0
    x_pre, y_pre = amaris[i][0]
    for j in range(1,(H*W)//D+1):
        coords = amaris[i][j]
        if isinstance(coords,int): break
        x = coords[0]
        y = coords[1]
        cnt += abs(x-x_pre)+abs(y-y_pre)
        acc[i][j] = cnt
        x_pre = x
        y_pre = y
# print(acc)

Q = int(input())
for i in range(Q):
    l,r  = map(int, input().split())
    m = (l-1) % D
    s = (l-1) // D
    g = (r-1) // D
    ans = acc[m][g] - acc[m][s]
    print(ans)


Measured memory_bytes: 77436
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define PI aocs(-1.0)

const int maxn=610;
char s[maxn][maxn];
int dp[maxn][maxn];

int main()
{
    int n;
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> s[i];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            s[i+n][j]=s[i][j];
            s[i][j+n]=s[i][j];
            s[i+n][j+n]=s[i][j];
        }
    }
    int m=n*2;
//    for(int i=0;i<m;i++)
//        cout << s[i] << endl;
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<m;j++)
        {
            dp[i][j]=1;
            for(int k=1;k<=n&&k+i<m&&k+j<m;k++)
            {
                if(s[i+k][j]==s[i][j+k])
                    dp[i][j]++;
                else
                    break;
            }
  //          cout << dp[i][j] << " " << i << " " << j << endl;
        }
    }
    int sum=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            bool flag=true;
            for(int k=0;k<n;k++)
            {
                int x=i+k,y=j+k;
                if(dp[x][y]<n-k)
                {
                    flag=false;
                    break;
                }
            }
            if(flag)
                sum++;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<pair<ll, ll> > h(N, pair<ll, ll>());
  vector<pair<ll, ll> > ht(N, pair<ll, ll>());
  vector<pair<ll, ll> > ha(N, pair<ll, ll>());
  vector<ll> T(N+1, 0);
  vector<ll> A(N+1, 0);
  REP(i, N){
    cin >> T[i+1];
  }
  REP(i, N){
    cin >> A[i];
  }
  REP(i, N){
    if(T[i] < T[i+1]){
      ht[i] = {T[i+1], T[i+1]};
    }else{
      ht[i] = {T[i+1], 1};
    }
  }
  for(int i = N; i > 0; i--){
    if(A[i] < A[i-1]){
      ha[i-1] = {A[i-1], A[i-1]};
    }else{
      ha[i-1] = {A[i-1], 1};
    }
  }
  REP(i, N){
    h[i] = {min(ht[i].first, ha[i].first), max(ht[i].second, ha[i].second)};
  }
  ll ans = 1, mod = 1e9+7;
  REP(i, N){
    ans = ans * max(0LL, (h[i].first - h[i].second + 1)) % mod;
  };
  cout << ans << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

ll lcm(ll x, ll y) {
    ll gcd = __gcd(x, y);
    x /= gcd;
    return x*y;
}

set<int> st;

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

    int n;
    ll m;
    cin >> n >> m;
    vector<ll> a(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ll tmp = a[i];
        int cur = 0;
        while (tmp%2 == 0) {
            cur++;
            tmp /= 2;
        }
        st.insert(cur);
        a[i] /= 2;
    }

    if (st.size() > 1) {
        cout << 0;
        return 0;
    }

    ll l = a[0];
    for (int i = 1; i < n; i++) {
        l = lcm(l, a[i]);
        if (l > m) {
            cout << 0;
            return 0;
        }
    }

    ll tmp = m / l;
    ll ans = (tmp+1) / 2;

    cout << ans;



    return 0;
}


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

#define ll long long

int main(){
	int n,x,y;
	cin>>n;
	ll s=0;
	int a[n+1];
	for(int i=0;i<=n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>x;
		y=min(x,a[i]);
		s+=y;
		x-=y;
		y=min(x,a[i+1]);
		s+=y;
		a[i+1]-=y;
	}
	cout<<s<<"\n";
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
#include <queue>
#include <algorithm>

int main()
{
	int s;
	cin>>s;
	long long a[s+1];
	for(int i=0;i<s;i++)
	{
		cin>>a[i];
	}
	sort(a,a+s);
	long long k=0,max1=-11111,max2=-11111;
	while(k<s)
	{
		if(a[k]==a[k+1]) {
			max2=max1;
			max1=a[k];
			k+=2;
		}
		else
			k++;
	}
	if(max1!=-11111&&max2!=-11111) cout<<max1*max2;
	else cout<<0;
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	vector<int> arr(n + 1);
	
	for (int i = 0; i < n - 1; ++i) {
		int x;
		cin >> x;
		
		++arr[x];
	}
	
	for (int i = 1; i <= n; ++i) {
		cout << arr[i] << endl;
	}
	
	return 0;
}


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

struct Card
{
    char suit;
    int value;
};

void bubbleSort(Card C[], int N){
    for (int i=0; i<N; i++){
        for (int j=N-1; j>i; j--){
            if (C[j-1].value > C[j].value){
                Card tmp = C[j-1];
                C[j-1] = C[j];
                C[j] = tmp;
            }
        }
    }
}

void selectionSort(Card C[], int N){
    for (int i=0; i<N; i++){
        int minj = i;
        for (int j=i; j<N; j++){
            if (C[j].value < C[minj].value){
                minj = j;
            }
        }
        // swap
        Card tmp = C[i];
        C[i] = C[minj];
        C[minj] = tmp;
    }
}

// C1: bubble sortでソートされた配列(stable). C2: bubble_sort以外でソートされた配列(is_stable?). この2つの配列を比べればstableかどうかわかる
bool isStable(Card C1[], Card C2[], int N){
    for (int i=0; i<N; i++)
        if (C1[i].suit != C2[i].suit)
            return false;

    return true;
}

void printArray(Card C[], int N){
    for (int i=0; i<N; i++){
        cout << C[i].suit << C[i].value;
        if (i != N-1) cout << " ";  // 最後の要素以外は後ろに空白スペースを追加
    }
    cout << endl;
}

int main(int argc, char const *argv[])
{
    const int MAX = 100;
    Card C_in[MAX], C1[MAX], C2[MAX];
    int N;

    // 入力データ
    cin >> N;
    for (int i=0; i<N; i++) cin >> C_in[i].suit >> C_in[i].value;
    // 配列の中身ををコピー
    for (int i=0; i<N; i++) C1[i] = C_in[i];
    for (int i=0; i<N; i++) C2[i] = C_in[i];

    bubbleSort(C1, N);
    selectionSort(C2, N);

    // バブルソートは必ず安定(stable)
    printArray(C1, N);
    cout << "Stable" << endl;
    
    // 選択ソートは不安定
    printArray(C2, N);
    cout << (isStable(C1, C2, N) ? "Stable" : "Not stable") << endl;

    return 0;
}



Measured memory_bytes: 3100