akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); i++)
#define ll long long
#define MOD 1000000007
using namespace std;

main () {
  int n, m;
  scanf("%d %d", &n, &m);

  vector<pair<int, int>> store(n);
  rep(i,n) {
    scanf("%d %d", &store[i].first, &store[i].second);
  }
  sort(store.begin(), store.end());

  ll ans = 0;
  for(int i=0; i<n && m; i++) {
    const int n = min(m, store[i].second);
    m -= n;
    ans += (ll)store[i].first * n;
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 1024
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>

const int maxn=1005;
int h,w,k,sx,sy,mn=INF;
string s[maxn];
int dist[maxn][maxn];
queue<pii>q;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int get_dis(int x,int y){
	return min(min(x,h-x-1),min(y,w-y-1));
}

bool onboard(int x,int y){
	return x>=0&&x<h&&y>=0&&y<w;
}

void bfs(){
	q.push(mk(sx,sy));
	rep(i,maxn)rep(j,maxn)dist[i][j]=INF;
	dist[sx][sy]=0;
	mn=INF;
	while(!q.empty()){
		int x=q.front().fi,y=q.front().se;
		q.pop();
		mn=min(mn,get_dis(x,y));
		if(dist[x][y]==k)continue;
		rep(i,4){
			int nx=x+dx[i],ny=y+dy[i];
			if(dist[nx][ny]!=INF||s[nx][ny]=='#'||!onboard(nx,ny))continue;
			dist[nx][ny]=dist[x][y]+1;
			q.push(mk(nx,ny));
		}
	}
}

int main(){
	cin>>h>>w>>k;
	rep(i,h){
		cin>>s[i];
		rep(j,w)if(s[i][j]=='S'){
			sx=i;sy=j;
		}
	}
	bfs();
	cout<<mn/k+(mn%k==0?0:1)+1<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>
int main(void){
    
    int i;
    char X[100],O[100];
    scanf("%s",X);
    scanf("%s",O);
    
    for(i=0; i<strlen(O);i++){
        printf("%c%c",X[i],O[i]);
    }
    if(strlen(X)>strlen(O)){
        printf("%c\n",X[strlen(X)-1]);
    }else{
        printf("\n");
    }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;
long p = 1000000007;
int main()
{
    queue<char> a,b,c;
    string s,t,u;
    cin >> s >> t >> u;
    for (auto &&e : s)
    {
        a.push(e);
    }
    for (auto &&e : t)
    {
        b.push(e);
    }
    for (auto &&e : u)
    {
        c.push(e);
    }
    char next = 'a';
    while (true)
    {
        if (next=='a')
        {
            if(a.empty())
                break;
            next = a.front();
            a.pop();
        }
        if (next=='b')
        {
            if(b.empty())
                break;
            next = b.front();
            b.pop();
        }
        if (next=='c')
        {
            if(c.empty())
                break;
            next = c.front();
            c.pop();
        }
    }
    cout << (char)(next+'A'-'a') << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5;
int n,u,v,dep[maxn],point[2];
int s=0,p[2][maxn];
bool tag[maxn];
vector <int> to[maxn];
inline long long read(){
	long long x=0,f=1;
	char c;
	do{c=getchar();if(c=='-') f*=-1;}while(!isdigit(c));
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
	return x*f;
}
void get_dep(int now,int fa,int &res){
	dep[now]=dep[fa]+1;
	res=dep[now]>dep[res]?now:res;
	int siz=to[now].size();
	for(int i=0;i<siz;i++){
		int v=to[now][i];
		if(v==fa) continue;
		get_dep(v,now,res);
	}
}
int Find_longpoint(int now){
	int res=0;
	get_dep(now,0,res);
	return res;
}
bool make_tag(int now,int fa,int target){
	int siz=to[now].size();
	bool ex=(now==target)?true:false;
	for(int i=0;i<siz;i++){
		int v=to[now][i];
		if(v==fa) continue;
		ex|=make_tag(v,now,target);
	}
	tag[now]=ex;
	return ex;
}
bool check_it(){
	int cnt=0;
	for(int i=1;i<=n;i++){if(tag[i]) cnt+=(to[i].size()-1);}
	return (cnt+2==n);
}
void get_permutation(int now,int fa,int node,int cur){
	int siz=to[now].size(),nut=cur,tto=0;
	for(int i=0;i<siz;i++){
		int v=to[now][i];
		if(v==fa) continue;
		if(tag[v]) tto=v;
		else{p[node][nut]=nut+1;nut++;}
	}
	p[node][nut]=cur;
	if(tto) get_permutation(tto,now,node,nut+1);
}
int main(){
	n=read();
	for(int i=1;i<n;i++){
		u=read();v=read();
		to[u].push_back(v);
		to[v].push_back(u);
	}
	point[0]=Find_longpoint(1);
	point[1]=Find_longpoint(point[0]);
	make_tag(point[0],0,point[1]);
	if(!check_it()){printf("-1\n");}
	else{
		get_permutation(point[0],0,0,1);
		get_permutation(point[1],0,1,1);
		for(int i=1;i<=n;i++){
			if(p[0][i]==p[1][i]) continue;
			if(p[0][i]>p[1][i]){s=1;break;}
			if(p[0][i]<p[1][i]){s=0;break;}
		}
		for(int i=1;i<=n;i++){printf("%d ",p[s][i]);}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 18304
import math
from math import cos, sin, pi

class Point:
    def __init__(self, x=0.0, y=0.0):
        self.x = x
        self.y = y

def koch(n,a,b):
  if n == 0:
    return 0

  th = pi * 60.0 / 180.0

  s, t, u = Point(0.0, 0.0), Point(0.0, 0.0), Point(0.0, 0.0)

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y

  koch(n - 1, a, s)
  print(f'{s.x:,.8f} {s.y:,.8f}')

  koch(n - 1, s, u)
  print(f'{u.x:,.8f} {u.y:,.8f}')
  
  koch(n - 1, u, t)
  print(f'{t.x:,.8f} {t.y:,.8f}')

  koch(n - 1, t, b)
    

a = Point(0.0, 0.0)
b = Point(100.0, 0.0)
n = int(input())

print(f'{a.x:,.8f} {a.y:,.8f}')
koch(n,a,b)
print(f'{b.x:,.8f} {b.y:,.8f}')


Measured memory_bytes: 5784
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = 0, W = 0;

        while (true) {
            H = sc.nextInt();
            W = sc.nextInt();
            if (H == 0 && W == 0) break;

            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}
LL ans = 0;
string s;

int main()
{
    cin >> s;
    int sz = s.size();
    int a = 0;

    _for(i,0,sz-1){
        if(s[i] == 'A') a++;
        else if(s[i] == 'B' && s[i+1] == 'C'){
            ans += a;
            i++;
        }
        else a = 0;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
n=int(input())
s=list(map(int,input().split()))
q=int(input())
t=list(map(int,input().split()))
cnt=0
s.sort()
for i in range(n-1):
    if s[i]!=s[i+1]:
        for j in range(q):
            if s[i]==t[j]:
                cnt+=1
                break
if s[n-2]!=s[n-1]:
    for j in range(q):
        if s[n-1]==t[j]:
            cnt+=1
            break
print(cnt)


Measured memory_bytes: 6548
#include<stdio.h>
int main()
{
    int n;
    int r;
    int inner;
    scanf("%d",&n);
    scanf("%d",&r);
    if(n<10){
        inner=r+(100*(10-n));
    }else{
        inner=r;
    }
    printf("%d\n",inner);
    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2000000;

struct node {
	int val;
	node *l, *r;
	node() : l(nullptr), r(nullptr) {}
	node(int val) : val(val), l(nullptr), r(nullptr) {}
	void init(int v, node *left, node *right) {
		val = v;
		l = left;
		r = right;
	}
};

auto merge(int l, int r) {
	return min(l, r);
}

const int id = INT_MAX;
int it = 0, rit = 0, siz;
node pool[MAX];
node *root[100000];

int size(int n) {
	int res = 1;
	while (res < n) res <<= 1;
	return res;
}

node *new_node(int val = 0, node *l = nullptr, node *r = nullptr) {
	pool[it].init(val, l, r);
	return &pool[it++];
}

node *fix(node *x, int p, int val, int lb, int ub) {
	if (p < lb || ub <= p) return x;
	if (lb + 1 == ub) return new_node(val);
	int c = (lb + ub) / 2;
	auto nl = fix(x->l, p, val, lb, c);
	auto nr = fix(x->r, p, val, c, ub);
	return new_node(merge(nl->val, nr->val), nl, nr);
}

int sub(node *x, int l, int r, int lb, int ub) {
	if (ub <= l || r <= lb) return id;
	if (l <= lb && ub <= r) return x->val;
	int c = (lb + ub) / 2;
	return merge(sub(x->l, l, r, lb, c), sub(x->r, l, r, c, ub));
}

node *update(int p, int val, node *rt = nullptr) {
	if (rt == nullptr) rt = root[rit - 1];
	return root[rit++] = fix(rt, p, val, 0, siz);
}

int find(int l, int r, node *rt = nullptr) {
	if (rt == nullptr) rt = root[rit - 1];
	return sub(rt, l, r + 1, 0, siz);
}

node *init(int n) {
	siz = size(n);
	for (int i = 1; i < siz * 2; i++) {
		if (i < siz) {
			pool[i].init(id, &(pool[i * 2]), &(pool[i * 2 + 1]));
		}
		else {
			pool[i].init(id, nullptr, nullptr);
		}
	}
	it = siz * 2;
	return root[rit++] = &pool[1];
}

void print(node *rt = nullptr) {
	if (rt == nullptr) rt = root[rit - 1];
	if (rt->l == nullptr && rt->r == nullptr) {
		printf(" %d", rt->val);
		return;
	}
	print(rt->l);
	print(rt->r);
}

int main()
{
	cin.sync_with_stdio(false);
	int n, q, com, x, y;
	cin >> n >> q;
	init(n);
	while (q--) {
		cin >> com >> x >> y;
		if (com) {
			printf("%d\n", find(x, y));
		}
		else {
			update(x, y);
		}
	}
	return 0;
}

Measured memory_bytes: 50524
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    int ans = n % 2 == 0 ? n / 2 - 1 : n / 2;
    cout << ans << endl;

    return 0;
}

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

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

    int num = n;
    vector<int> ans;
    for (int i = 2; i < sqrt(n) + 1; i++)
    {
        while (num % i == 0)
        {
            num /= i;
            ans.push_back(i);
        }
    }

    cout << n << ":";
    for (int i = 0; i < ans.size(); i++)
    {
        cout << " " << ans[i];
    }
    if(num != 1) cout << " " << num;
    cout << endl;
}


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

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

    vector<pair<ll, ll>> pows;
    for(ll i = -1000; i <= 1000; i++) {
        pows.push_back(make_pair(i, pow(i, 5)));
    }

    for(int i = 0; i < pows.size(); i++) {
        for(int j = 0; j < pows.size(); j++) {
            if(pows.at(i).second - pows.at(j).second == X) {
                cout << pows.at(i).first << " " << pows.at(j).first << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 4096
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe
import Data.Ord
import Data.Time
import qualified Data.Vector as VC
import qualified Data.Vector.Mutable as VM

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegerLists :: Int -> IO [[Integer]]
readIntegerLists n = replicateM n (map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine)

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntLists :: Int -> IO [[Int]]
readIntLists n = replicateM n (map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine)

readStrings :: IO [String]
readStrings = map BS.unpack . BS.words <$> BS.getLine

readStringLists :: Int -> IO [[String]]
readStringLists n = replicateM n (map BS.unpack . BS.words <$> BS.getLine)

main :: IO ()
main = do
  [h] <- readInts
  print $ solve h

solve h = foldl1' (+) $ takeWhile (<= h) $ scanl' (\acc _ -> acc * 2) 1 $ repeat 1

Measured memory_bytes: 380
#include<stdio.h>
 int main(){
   int m,n,k,num;
   int sum=0;
   scanf("%d %d",&m,&n);
   for(k=0;k<n;k++){
     scanf("%d",&num);
     sum+=num;
   }
   if(sum>=m){
     printf("Yes\n");
   }else{
     printf("No\n");
   }
   return 0;
 }

Measured memory_bytes: 128
#include<iostream> 
using namespace std;
int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(x>=r){
        if(x<=W-r){
            if(y>=r){
                if(y<=H-r){
                    cout<<"Yes"<<endl;
                }
                else{
                    cout<<"No"<<endl;
                }    
            }
            else{
                cout<<"No"<<endl;
            }
        }
        else{
            cout<<"No"<<endl;
        }
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3112
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve(){
	string s, t; cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());
	if (s < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
_n = gets.to_i
d = gets.split.map(&:to_i)
h = Hash.new(0)
d.each { |e| h[e] += 1 }
ans = pred = 1
mod = 998244353

if d[0] != 0 || h[0] != 1
  puts 0
  exit
end

1.upto(h.keys.max) do |i|
  ans *= pred.pow(h[i], mod)
  ans %= mod
  pred = h[i]
end

puts ans


Measured memory_bytes: 25060
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

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

    for(int i = 1; i < 1000000; ++i){
        if(i * i > n){
            cout << (i-1) * (i-1) << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
/*

                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define repd(i,s,e)  for(int i=e;i>=s;i--)
#define vb vector<bool>
#define read2(n,m) int n,m; cin >> n >> m;
#define range(v) v.begin(),v.end()
#define sortd(v) sort(v.begin(),v.end(),greater<int>())
#define sorti(v) sort(v.begin(),v.end())

const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
signed main()
{
 
    fast;
    int n,x;
    cin >> x >> n;
    readarr(a,n);
    map<int,int> m;
    int mx = 0;
    rep(i,0,n-1){
    	m[abs(a[i]-x)]++;
    	mx = max(abs(a[i]-x),mx);
    }
    rep(i,0,mx+1){
    	if(i==0 && m[i]==0){
    		cout<<x<<endl;
    		break;
    	}
    	else if(m[i]<2 && i!=0){
    		int e1 = x+i,e2 = x-i; bool f1=0,f2=0;
    		rep(j,0,n-1){
    			if(a[j]==e1) f1=1;
    			if(a[j]==e2) f2=1;
    		}
    		
    		if(!f2) cout<<e2<<endl;
    		else if(!f1) cout<<e1<<endl;
    		break;
    	}
    }
    return 0;
}

/* Pooja Yadav */

Measured memory_bytes: 3660
#include<iostream>
    using namespace std;
     
    int main()
    {
    int n;cin>>n;int a[n],ans=0,cans=0;for (int i=0;i<n;i++)cin>>a[i];for (int i=n-2;i>=0;i--)
    {
      if (a[i]>=a[i+1])
                  {
    cans++;}
      else
      {
    ans=max(ans,cans);cans=0;}}
      cout<<max(ans,cans);return 0;}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int maxn = 111;
int t[maxn], v[maxn];
int mx[maxn * maxn * 20];
int main(){
	int n; cin >> n;
	for(int i = 1; i <= n; i++) cin >> t[i];
	for(int i = 1; i <= n; i++) cin >> v[i];
	n += 2;
	for(int i = 0; i < n; i++) t[i] *= 2, v[i] *= 2;
	int sum = 0;
	for(int i = 0; i < n; i++) sum += t[i];
	for(int i = 0; i < sum; i++) mx[i] = 1<<30;
	int now = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= t[i]; j++){
			mx[now + j] = min(mx[now + j], v[i]);
		}
		now += t[i];
	}
	mx[0] = 0;
	mx[sum] = 0;
	for(int i = 0; i < sum; i++) if(i) mx[i] = min(mx[i], mx[i - 1] + 1);
	for(int i = sum - 1; i >= 0; i--) mx[i] = min(mx[i], mx[i + 1] + 1);
	double ans = 0;
	for(int i = 0; i < sum; i++) ans += mx[i] + mx[i + 1];
	cout << fixed << setprecision(12) << ans / 8.0 << endl;
	return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  unordered_map<string, int> res;
  for (int i = 0; i < n; i++) {
    string s; cin >> s;
    (res.find(s) != res.end()) ? res[s]++ : res[s] = 1;
  }
  int m = 0;
  for (auto &p : res) m = max(m, p.second);
  vector<string> ans;
  for (auto &p : res) {
    if (p.second < m) continue;
    ans.push_back(p.first);
  }
  sort(ans.begin(), ans.end());
  for (auto &s : ans) cout << s << '\n';
  return 0;
}

Measured memory_bytes: 25284
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair { public int x, y; public Pair(int xx, int yy) { x = xx; y = yy; } }
    private static int[] dx = { 1, 0, -1, 0 };
    private static int[] dy = { 0, -1, 0, 1 };
    public static void Main()
    {
        //縦横別に考えてもよさげ
        int H = NextInt();
        int W = NextInt();
        int N = NextInt();
        int sr = NextInt();
        int sc = NextInt();
        string S = NextString();
        string T = NextString();

        int L = sc;
        for (int i = 0; i < N; i++)
        {
            if (S[i] == 'L') L--;
            if (L < 1) { Console.WriteLine("NO"); return; }
            if (T[i] == 'R') L += (L == W ? 0 : 1);
        }
        int R = sc;
        for (int i = 0; i < N; i++)
        {
            if (S[i] == 'R') R++;
            if (W < R) { Console.WriteLine("NO"); return; }
            if (T[i] == 'L') R -= (R == 1 ? 0 : 1);
        }
        int U = sr;
        for (int i = 0; i < N; i++)
        {
            if (S[i] == 'U') U--;
            if (U < 1) { Console.WriteLine("NO"); return; }
            if (T[i] == 'D') U += (U == H ? 0 : 1);
        }
        int D = sr;
        for (int i = 0; i < N; i++)
        {
            if (S[i] == 'D') D++;
            if (H < D) { Console.WriteLine("NO"); return; }
            if (T[i] == 'U') D -= (D == 1 ? 0 : 1);
        }
        Console.WriteLine("YES");
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 14176
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
const ll maxn=2e5+10;
const ll mod=1e9+7;

int main(){
	fast;
	ll n,i,j,k;
	cin>>n;
	ll a[n+1];
	for(i=2;i<=n;++i)
		cin>>a[i];
	ll f[maxn];
	memset(f,0,sizeof(f));
	for(i=2;i<=n;i++){
		++f[a[i]];
	}
	for(i=1;i<=n;++i)
		cout<<f[i]<<endl;
	
	
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  double b = 0.0;
  for (int i = 0; i < n; i++) {
    b += (double)1.0 / (double)a[i];
  }
  cout << (double)1.0 / b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int main(){
    int n, h;
    while(cin>>n){
        map<ll,ll> m;
        ll cnt = 0;
        fore(i,1,n+1){
            cin>>h;
            ll dif = i - h;
            ll ad = i + h;
            cnt+=m[dif];
            m[ad]++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

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

using namespace std;

int main() {
	int n, m;
	string s;
	cin >> n >> m >> s;
	vector<int> ans;
	reverse(s.begin(), s.end());
	vector<int> prevs(n + 1);
	int prev = 0;
	for (int i = 0; i < n; ++i) {
		if (s[i] == '0') {
			prev = i;
		}
		prevs[i] = prev;
	}
	int i = 0;
	while (i < n) {
		if (i + m >= n) {
			ans.push_back(n - i);
			break;
		}
		if (prevs[i + m] == i) {
			cout << "-1\n";
			return 0;
		}
		ans.push_back(prevs[i + m] - i);
		i = prevs[i + m];
	}
	reverse(ans.begin(), ans.end());
	for (auto a : ans) cout << a << " ";
	cout << "\n"; 
	return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N, a;
    cin >> N;
    int sa = 0, sa2 = 0;
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        sa += a;
        sa2 += a*a;
    }
    int m[3];
    m[1] = sa/N;
    m[0] = m[1]-1;
    m[2] = m[1]+1;

    ll ans = 10000000;
    for ( int i = 0; i < 3; i++ ) {
        ll s = N*m[i]*m[i] - 2*m[i]*sa + sa2;
        if ( ans > s ) ans = s;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
       int n=sc.nextInt();
       int m=sc.nextInt();
       int a[]=new int[n];
       double all=0;
       for(int i=0;i<n;i++) {
           a[i] = sc.nextInt();
           all += a[i];
       }
       Arrays.sort(a);
       all/=m*4.0;
        //System.out.println(all+" "+m+" "+a[n-m]);
        if(a[n-m]>=all)
            System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n, x;
    cin>> n >> x;

    long int input;
    vector<long int> vec;

    for(long int i = 1; i <= n; i++)
    {
        cin>> input;
        vec.push_back(input);
    }

    //long int temp = 0;

    long long int ans = 0;
    for(long int i = 1; i < vec.size(); i+= 2)
    {
        if(vec[i] + vec[i-1] >= x)
        {
            long int temp = vec[i] + vec[i-1] - x;
            ans += temp;
            if(temp >= vec[i])
            {
                vec[i] = 0;
                temp -= vec[i];

                vec[i-1] = vec[i-1] - temp;
            }
            else
                vec[i] = vec[i] - temp;

        }

        if((vec[i] + vec[i+1] >= x)&&(i+1 < n))
        {
            long int temp = vec[i+1] + vec[i] - x;

            ans += temp;

            if(temp >= vec[i+1])
            {
                vec[i+1] = 0;
                temp -= vec[i+1];
                vec[i] = vec[i] - temp;
            }
            else
                vec[i+1] = vec[i+1] - temp;
        }

    }

    cout<< ans;

    return 0;

}


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

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int x;

int main(void)
{
	cin >> x;
	
	int ans = 1;
	for(int i = 2; i <= x; i++){
		int v = i*i;
		while(v <= x){
			ans = max(ans, v);
			v *= i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	string S[3];
	rep( i, 3 ) cin >> S[i];

	cout << S[0].c_str()[0] << S[1].c_str()[1] << S[2].c_str()[2] << endl;

	return ( 0 );
}


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

int main() {
	string S;
	cin >> S;
	int count1 = 0;
	int count2 = 0;

	for (int i = 0; i < S.size(); i++) {
		if (S.at(i) == 'A' || S.at(i) == 'T' || S.at(i) == 'G' || S.at(i) == 'C')
			count1++;
		else {
			count2 = max(count1, count2);
			count1 = 0;
		}
	}
	
	cout << max(count1, count2) << endl;
}

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

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

    if(N %2 == 1){
        cout << 0 << endl;
    }

    else{
        N = N/2;
        ll a = N/5;
        ll b = a/5;
        ll c = b/5;
        ll d = c/5;
        ll e = d/5;
        ll f = e/5;
        ll g = f/5;
        ll h = g/5;
        ll i = h/5;
        ll j = i/5;
        ll k = j/5;
        ll l = k/5;
        ll m = l/5;
        ll n = m/5;
        ll o = n/5;
        ll p = o/5;
        ll q = p/5;
        ll r = q/5;
        ll s = r/5;
        ll t = s/5;
        ll u = t/5;
        ll v = u/5;
        ll w = v/5;
        ll x = w/5;
        ll y = x/5;
        ll z = y/5;

        cout << a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r + s + t + u + v + w + x + y + z << endl;
    }


}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n;cin >> n;
    vector<int> a(n);rep(i,n)cin >> a[i];
    ll sum = 0;
    rep(i,n)
    {
        sum += (ll)(a[i]-1);
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
s = input()
cur = ""
i,cnt = 0,0
ls = len(s)
while i < ls:
  if cur != s[i]:
    cur = s[i]
    i += 1
  elif i == ls-1:
    break
  else:
    cur = s[i:i+2]
    i += 2
  cnt += 1
print(cnt)

Measured memory_bytes: 3500
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
	int N,ans=0;
	scanf("%d",&N);
	int a[N];
	int c[100001]={};
	for(int i=0; i<N; i++){
		scanf("%d",&a[i]);
		c[a[i]]++;
	}
	int count;
	for(int i=1;i<100000;i++){
		count = c[i-1]+c[i]+c[i+1];
		if(count>ans) ans=count;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <list>
#include <stack>

typedef long long ll;
using namespace std;
const int mod = 1000000007;

vector<ll> f(45);

int main() {

    int n; cin >> n;

    f[0] = 1; f[1] = 1;

    for (int i = 2; i <= n; i++) {
        f[i] = f[i-1] + f[i-2];
    }

    cout << f[n] << '\n';

}



Measured memory_bytes: 3120
A = input()
#A = list(map(int,input().split()))
max = 0
tmp = 0
for i in range(3):
    if A[i] == 'R':
        tmp += 1
    else :
        if max <= tmp:
            max = tmp
        tmp = 0
if max <= tmp:
    max = tmp
print(max)

Measured memory_bytes: 61632
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			Question.Exec();
		}
	}

	public static class Question
	{
		public static bool IsOdd(long n)
		{
			bool isOdd = n % 2 == 1;
			return isOdd;
		}

		public static void Exec()
		{
			string str = Console.ReadLine();
			str = str.Replace("2017", "2018");
			Console.WriteLine($"{str}");

			Console.ReadKey();
		}

		public class Scanner
		{
			private readonly char[] delimiter_ = new char[] { ' ' };
			private readonly string filePath_;
			private readonly Func<string> reader_;
			private string[] buf_;
			private int index_;

			public Scanner(string file = "")
			{
				if (string.IsNullOrWhiteSpace(file))
				{
					reader_ = Console.ReadLine;
				}
				else
				{
					filePath_ = file;
					var fs = new StreamReader(file);
					reader_ = fs.ReadLine;
				}
				buf_ = new string[0];
				index_ = 0;
			}

			public string Next()
			{
				if (index_ < buf_.Length)
				{
					return buf_[index_++];
				}

				string st = reader_();
				while (st == "")
				{
					st = reader_();
				}

				buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
				if (buf_.Length == 0)
				{
					return Next();
				}

				index_ = 0;
				return buf_[index_++];
			}

			public int Int() => int.Parse(Next());
			public long Long() => long.Parse(Next());
			public double Double() => double.Parse(Next());

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

			public long[] ArrayLong(int N, long add = 0)
			{
				long[] Array = new long[N];
				for (int i = 0; i < N; i++)
				{
					Array[i] = Long() + add;
				}
				return Array;
			}

			public double[] ArrayDouble(int N, double add = 0)
			{
				double[] Array = new double[N];
				for (int i = 0; i < N; i++)
				{
					Array[i] = Double() + add;
				}
				return Array;
			}
		}
	}
}

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

int main(){
  int n;
   cin >> n;
   int a[n];
   for( int i = 0; i < n; ++i ){
     cin >> a[i];
   }
   int sum = accumulate(a, a+n, 0);
   int sum_sub = 0;
   int ans = sum;
   for(int i = 0; i < n-1; ++i){
     sum_sub += a[i];
     int abs_dif = abs(sum - 2*sum_sub);
     ans = min(ans, abs_dif);
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 384
N = int(input())
ls1 = []
for i in range(N):
    A = int(input())
    ls2 = []
    for i in range(A):
        x, y = map(int,input().split())
        ls2.append([x,y])
    ls1.append(ls2)
ans = 0
f = True
for i in range(2**N):
    for j in range(N):
        if (i>>j&1):
            f = True
            for k in ls1[j]:
                if (i >>(k[0] - 1) &1) == (k[1]&1):
                    continue
                else:
                    f = False
                    break
            if f == False:
                break
    if f:
        ans = max(ans,bin(i).count('1'))    
print(ans)

Measured memory_bytes: 9168
import operator
import collections

n, k = map(int, input().split())
sushies = []
for _ in range(n):
    t, d = map(int, input().split())
    sushies.append((t, d))

sushies.sort(key=operator.itemgetter(1), reverse=True)

dishes = sushies[:k]
c = collections.Counter(t for t, d in dishes)
a = sum(d for t, d in dishes)
answer = a + len(c) ** 2
x = k - 1
for t, d in sushies[k:]:
    if t in c:
        continue

    while x >= 0:
        if c[dishes[x][0]] > 1:
            break
        x -= 1

    if x == -1:
        break


    a = a + d - dishes[x][1]
    c[t] += 1
    c[dishes[x][0]] -= 1
    del dishes[x]
    dishes.append((t, d))

    answer = max(answer, a + len(c) ** 2)

print(answer)


Measured memory_bytes: 66904
N, M = map(int, input().split(" "))

P = []
S = []

clear = 0

q = {}
c = set()

for i in range(M):
    sss = input().split(" ")
    p = int(sss[0])
    s = sss[1]
    P.append(p)
    S.append(s)

    if p not in c:
        if s == "AC":
            clear += 1
            c.add(p)

        if s == "WA":
            q[p] = q.get(p, 0) + 1

warng = sum([
    q[k]
    for k in c
    if k in q
])

print("{} {}".format(clear, warng))


Measured memory_bytes: 65752
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n;
  cin>>n;
  vector<vecint> table(n);
  int INF = 1e9;
  for(auto&& i:irange(0,n)) {
    int len = i+1;
    vecint dist(1<<len, INF);
    dist[0] = 0;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
      int j = q.front();
      q.pop();
      bitset<18> bs(j);
      for(auto&& k:irange(0,len-1)) {
        if (bs[k] == bs[k+1]) {
          auto tmp = bs;
          tmp.flip(k);
          tmp.flip(k+1);
          int nx = tmp.to_ulong();
          if (dist[nx] > dist[j]+1) {
            dist[nx] = dist[j]+1;
            q.push(nx);
          }
        }
      }
    }
    table[i] = move(dist);
  }
  vecint a(n);
  vecint b(n);
  for(auto&& e:a) cin>>e;
  for(auto&& e:b) cin>>e;
  ll ans = INF;
  for(auto&& i:irange(0,1<<n)) {
    vector<tuple<int,int,int>> c(n);
    int cnt=0;
    for(auto&& j:irange(0,n)) {
      if ((i>>j)&1) {
        c[j] = make_tuple(b[j], true, 0);
        ++cnt;
      } else {
        c[j] = make_tuple(a[j], false, 0);
      }
    }
    if ((cnt%2) == 1) continue;
    ll swp = 0;
    for(auto&& j:irange(0,n)) {
      for(auto&& k:irange(0,n-1)) {
        int v1 = get<0>(c[k]);
        int v2 = get<0>(c[k+1]);
        if (v1 > v2) {
          ++swp;
          swap(c[k], c[k+1]);
          ++get<2>(c[k]);
          ++get<2>(c[k+1]);
        }
      }
    }
    int val = 0;
    int len = 0;
    int old = -1;
    for(auto&& j:irange(0,n)) {
      int v,o,s;
      tie(v,o,s) = c[j];
      int parity = o != ((s % 2) == 1);
      if (v != old) {
        if (len) swp += table[len-1][val];
        val = parity;
        len = 1;
        old = v;
      } else {
        val *= 2;
        val += parity;
        ++len;
      }
    }
    swp += table[len-1][val];
    ans = min(ans, swp);
  }
  if (ans < INF) {
    cout<<ans<<endl;
  } else {
    cout<<-1<<endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int l,r,ans;
    ans = 0;
    for(int j = 0;j<n;j++){
        cin >> l >> r;
        ans += r-l+1;
    }
    cout << ans;
    return 0;
}


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

int main() {
    // your code goes here
    ll n,i,x[100005],l[100005],a,b,c,d,ans=1;
    vector<pair<ll,ll>> v;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> x[i] >> l[i];
        v.push_back({x[i]+l[i]-1,x[i]-l[i]});
    }
    sort(v.begin(),v.end());
    b=v[0].first; a=v[0].second;
    for(i=1;i<n;i++){
        d=v[i].first; c=v[i].second;
        if(c>b){
            ans++;
            a=c; b=d;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3444
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          int long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<int long long,int long long>
#define vi          vector<int long long>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int long long)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(int long long i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  2007
ll n;
std::vector<pii> a(N);

ll dp[N][N];
ll func(ll pos,ll st,ll en)
{
    if(pos==(n))
        return 0;
    if(dp[pos][st]!=-1)
        return dp[pos][st];
    ll res=(abs(a[pos].S-st)*a[pos].F)+func(pos+1,st+1,en);
    res=max(res,(abs(a[pos].S-en)*a[pos].F)+func(pos+1,st,en-1));
    return dp[pos][st]=max(dp[pos][st],res);
}
int main()
{
    
    io
    
    cin>>n;
    memset(dp,-1,sizeof(dp));
    rep(i,0,n)
    {
        ll x;
        cin>>x;
        a[i]={x,i};
    }
    sort(all(a));
    reverse(all(a));
    cout<<func(0,0,n-1);
    
}


Measured memory_bytes: 35228
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    List<int[]> edges = new ArrayList<>();
    int L = scanner.nextInt();

    int r = findR(L);
    int N = r + 1;
    for (int i = N - 1; i >= 1; i--) {
      edges.add(new int[]{i, i + 1, 0});
      edges.add(new int[]{i, i + 1, 1 << (N - i - 1)});
    }

    int k = L - (1 << r);
    for (int i = r - 1; i >= 0; i--) {
      int d = 1 << i;
      if (k >= d) {
        edges.add(new int[]{1, N - i, L - k});
        k -= d;
      }
    }

    System.out.printf("%d %d\n", N, edges.size());
    for (int[] edge : edges) {
      System.out.printf("%d %d %d\n", edge[0], edge[1], edge[2]);
    }
  }

  private static int findR(int L) {
    int left = 0;
    int right = (int) Math.floor(Math.log(L) / Math.log(2)) + 1;
    while (right - left > 1) {
      int mid = (left + right) / 2;
      if (1L << mid > L) {
        right = mid;
      } else {
        left = mid;
      }
    }
    return left;
  }
}


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

int main (){
  int h,w;
  do{
  cin >> h >> w;
  for (int i = 0; i<h; i++){
    for (int j = 0; j<w; j++){
      if (i%2==0){
        if (j%2==0){
        cout << '#';

      }else {
        cout << '.';
      }
      }else {
      if (j%2==0){
        cout << '.';

      }else {
        cout << '#';
      }
     }
    }
    cout << endl;
  }

  if (h!=0 && w!=0){
  cout << endl;
  }
  }while (h!=0 && w!=0);

  return 0;
}


Measured memory_bytes: 3088
#include<stdio.h>
int main(void){
	long h, w;
	scanf("%ld", &h);
	scanf("%ld", &w);
	if(h == 1 || w == 1){
		printf("1\n");
	}
	else{
		printf("%ld\n", (h*w+1)/2);
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>

#define ll long long
#define endl \'n'
using namespace std;
const ll mod = (ll)10e9+7;
const int INF = 0x3f3f3f3f;
int a[101];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
    }
    int ans=INF;
    for(int i=-100; i<=100; i++)
    {
        int cur=0;
        for(int j=1; j<=n; j++)
        {
            cur += (i-a[j])*(i-a[j]);
        }
        ans = min(ans, cur);
    }
    cout << ans;
}



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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node find(Node u,int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key) u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeMinimum(Node x){

  while(x->left!=NIL){
    x=x->left;
  }
  return x;

}

Node treeMaximum(Node x){

  while(x->right!=NIL){
    x=x->right;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if(k<u->key){
    return treeSearch(u->left,k);
  }
  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)
    return treeMinimum(x->right);
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left==NIL || z->right==NIL)
    y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL) x=y->left;
  else x=y->right;

  if(x!=NIL) x->parent=y->parent;
  if(y->parent==NIL) root=x;
  else if(y==y->parent->left) y->parent->left=x;
  else y->parent->right=x;

  if(y!=z) z->key=y->key;
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }

  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key<y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }


}

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

 
  return 0;
}



Measured memory_bytes: 20484