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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll R;
	cin >> R;
	string res;
	if(R<1200) res = "ABC";
	else if(R<2800) res = "ARC";
	else res = "AGC";
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
list($A, $B, $Q) = explode(" ", trim(fgets(STDIN)));
for($i = 0; $i < $A; $i++){
    $aArray[] = intval(fgets(STDIN));
}
array_unshift($aArray, -10**18);
$aArray[] = 10**18;
for($i = 0; $i < $B; $i++){
    $bArray[] = intval(fgets(STDIN));
}
array_unshift($bArray, -10**18);
$bArray[] = 10**18;

for($i = 0; $i < $Q; $i++){
    $qArray[] = intval(fgets(STDIN));
}

foreach($qArray as $q){
    $min = 10**18;
    $a = bsl($aArray, $q);
    $b = bsl($bArray, $q);
    foreach([$aArray[$a], $aArray[$a+1]] as $a1){
        $p3 = $bArray[$b];
        $p4 = $bArray[$b+1];
        $min = min($min, abs($q - $a1) + abs($a1 - $p3));
        $min = min($min, abs($q - $a1) + abs($a1 - $p4));
    }
    foreach([$bArray[$b], $bArray[$b+1]] as $b1){
        $p3 = $aArray[$a];
        $p4 = $aArray[$a+1];
        $min = min($min, abs($q - $b1) + abs($b1 - $p3));
        $min = min($min, abs($q - $b1) + abs($b1 - $p4));
    }
    printf("%d\n", $min);
}

//二分探索　target以下で最大の値の場所を返す
function bsl($nums, $target) {
    $size = count($nums);
    $min = 0; 
    $max = $size - 1;
    while(true){
        $center = floor(($min + $max) / 2);
        $centerValue = $nums[$center];
        if($target == $centerValue){
            return $center;
        }elseif($target > $centerValue){
            $min = $center + 1;
        }else{
            $max = $center;
        }
        if($min == $max){
            $center = floor(($min + $max) / 2);
            $centerValue = $nums[$center];
            if($centerValue == $target){
                return $center;
            }elseif($centerValue < $target){
                return $center;
            }else{
                return $center-1;
            }
        }
    }
}


Measured memory_bytes: 18928
#include <iostream>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int par[100001];
int r[100001];
int p[100001];
set<int> st1[100001];
set<int> st2[100001];

int find(int x){
		if(par[x] == x)return x;
		else return par[x] = find(par[x]);
}

bool same(int x, int y){
		return find(x) == find(y);
}

void unite(int x, int y){
		int xp = find(x);
		int yp = find(y);
		if(xp == yp)return;
		if(r[xp] > r[yp]){
				par[yp] = xp;
		}else{
				par[xp] = yp;
				if(r[xp] == r[yp])r[yp]++;
		}
}

int main(int argc, char const* argv[])
{
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++)par[i] = i;
	for(int i = 0; i < n; i++)cin >> p[i];
	for(int i = 0; i < m; i++){
			int x, y;
			cin >> x >> y;
			unite(x - 1, y - 1);
	}
	for(int i = 0; i < n; i++){
			p[i]--;
			int tmp = find(i);
			st1[tmp].insert(i);
			st2[tmp].insert(p[i]);
	}
	int res = 0;
	for(int i = 0; i < n; i++){
			if(st1[i].size() == 0)continue;
			for(auto itr = st1[i].begin(); itr != st1[i].end(); ++itr){
					if(st2[i].find(*itr) != st2[i].end())res++;
			}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 20224
#include <cstdio>
#include <cmath>
using namespace std;


int main (void)
{
	int h, w;
	int i, j;

	while (scanf("%d %d", &h, &w) != EOF && h != 0 || w != 0){
		for (i=1; i<=h; i++){
			for (j=1; j<=w; j++){
				if (i%2 == 0){
					if (j%2 != 0)
						printf(".");
					else
						printf("#");
				}
				else{
					if (j%2 != 0)
						printf("#");
					else
						printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 1000
#include "bits/stdc++.h"

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long

int main()
{
  IOS;
  string s;
  cin >> s;
  for (int i=0; i<s.length(); i++)
    {
      cout << "x";
    }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 3592
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Map<String, Integer> m = new HashMap<>();
        m.put("AC", 0);
        m.put("WA", 0);
        m.put("TLE", 0);
        m.put("RE", 0);
        for (int i = 0; i < n; i++) {
            String res = in.next();
            m.put(res, m.get(res) + 1);
        }

        System.out.println("AC x " + m.get("AC"));
        System.out.println("WA x " + m.get("WA"));
        System.out.println("TLE x " + m.get("TLE"));
        System.out.println("RE x " + m.get("RE"));
    }
}

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

int main(){
	int n;
	int x[210][2];
	for(;cin>>n,n;){
		x[0][0]=x[0][1]=0;
		int nn,d;
		for(int i=1;i<n;i++){
			cin>>nn>>d;
			x[i][0]=x[nn][0]+(d%2?d-2:0);
			x[i][1]=x[nn][1]+(d%2?0:d==2?1:-1);
		}
		int max,min;
		max=min=0;
		for(int i=0;i<n;i++){
			if(max<x[i][1])max=x[i][1];
			if(min>x[i][1])min=x[i][1];
		}
		cout<<max-min+1<<" ";
		max=min=0;
		for(int i=0;i<n;i++){
			if(max<x[i][0])max=x[i][0];
			if(min>x[i][0])min=x[i][0];
		}
		cout<<max-min+1<<"\n";
	}
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] l = new int[n];
        int ans = 0;

        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }

        Arrays.sort(l);

        for (int i = 0; i < k; i++) {
            ans += l[n-1-i];
        }

        System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 22868
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    string s;
    int zero = 0, one = 0;
    
    cin >> s;
    
    for(int i = 0; i < s.length() ; i++){
        if(s[i] == '0'){
            zero++;
        }else if(s[i] == '1'){
            one++;
        }
    }
    //cout << (zero < one ? zero : one) * 2 << endl; 
    cout << min(zero, one) * 2 << endl;
}


Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


public class Test
{	
    public static void Main()
	{
	    string s = Console.ReadLine();
	    if(s[0] == s[s.Length-1]) Console.WriteLine("Yes");
	    else Console.WriteLine("No");
	} 
}

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

int main() {
  int k,a,b;
  cin >>k>>a>>b;
  for(int i=a; i<=b; i++){
    if(i%k==0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" <<endl;
  return 0;
  
}

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

#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())

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

bool compare(pair<int, string> a, pair<int, string> b)
{
    if (a.first != b.first)
    {
        return a.first > b.first; //昇順
        //return a.second > b.second; // 降順
    }
    else
    {
        return a.second < b.second;
    }
    
    
}

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n)
    {
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    int counter = 1;
    vector<pair<int, string>> ans;
    for (int i = 0; i < n; i++)
    {
        if (i == n - 1)
        {
            pair<int, string> temp_pair;
            temp_pair.first = counter;
            temp_pair.second = s[i];
            ans.push_back(temp_pair);
            continue;
        }
        if (s[i].compare(s[i+1])==0)
        {
            counter++;
            continue;
        }
        pair<int, string> temp_pair;
        temp_pair.first = counter;
        temp_pair.second = s[i];
        ans.push_back(temp_pair);
        counter = 1;
    }
    sort(ans.begin(),ans.end(), compare);
    //for(auto&u: ans) cout << u.first << u.second << endl; 
    bool ok = true;
    int index = 0;
    while(ok)
    {
        if (ans[index].first != ans[index+1].first)
        {
            ok = false;
        }
        cout << ans[index].second << endl;
        index++;
    }
}
    

Measured memory_bytes: 18420
#include<stdio.h>

int main(){
    int i,n,c[50],v[50],x=0,y=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&v[i]);
    }
    for(i=0;i<n;i++){
        scanf("%d",&c[i]);
    }
    for(i=0;i<n;i++){
        if(c[i]<v[i]){
            x+=v[i];
            y+=c[i];
        }
    }
    printf("%d\n",x-y);

    return 0;
}

Measured memory_bytes: 128
import heapq
N, M = map(int, input().split())
if N >= M:
    print(0)
    exit()
X = list(map(int, input().split()))
X.sort(reverse=True)
dist = []
for i in range(1, M):
    dist.append(X[i] - X[i - 1])
dist = list(map(lambda x: (-1) * abs(x), dist))
heapq.heapify(dist)
#print(dist)
for _ in range(N - 1):
    heapq.heappop(dist)
ans = -1 * sum(dist)
print(ans)



Measured memory_bytes: 87108
n=int(input())
a=list(map(int,input().split()))[::-1]
b=list(map(int,input().split()))[::-1]

cnt=0

for i in range(n):
    for j in range(2):
        x=a[i+j]
        y=b[i]
        m=min(x,y)
        b[i]-=m
        a[i+j]-=m
        cnt+=m

print(cnt)

Measured memory_bytes: 18624
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
#define N 200005
#define F(i,j,k) for(int i=(j);i<=(k);++i)
#define D(i,j,k) for(int i=(j);i>=(k);--i)
using namespace std;
inline void read(int &x){
	char ch=getchar();int f=1;x=0;
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	x*=f;
}
int n,a[N],b[N],bin[35],ans;
int find1(int x){
	return lower_bound(b+1,b+n+1,x)-b;
}
int find2(int x){
	return upper_bound(b+1,b+n+1,x)-b;
}
int main(){
	//freopen("txt.in","r",stdin);freopen("txt.out","w",stdout);
	read(n);
	F(i,1,n)read(a[i]); 
	F(i,1,n)read(b[i]);
	bin[0]=1;F(i,1,31)bin[i]=bin[i-1]<<1;
	D(i,29,0){
		//F(j,1,n)printf("%d ",a[j]);printf("\n");
		//F(j,1,n)printf("%d ",b[j]);printf("\n");
		int res=0;
		stable_sort(a+1,a+n+1);
		stable_sort(b+1,b+n+1);
		F(j,1,n){
			int x=max(bin[i]-a[j],0),y=max(bin[i+1]-1-a[j],0);
			int p=max(bin[i]+bin[i+1]-a[j],0),q=max(bin[i+2]-1-a[j],0);
			//printf("%d %d %d %d %d %d %d %d %d\n",a[j],x,y,p,q,find(x),find(y),find(p),find(q));
			res+=find2(y)-find1(x)+find2(q)-find1(p);
		}
		/*
		F(j,1,n){
			int x=max(bin[i]-a[j],0),y=bin[i+1]-a[j]-1;
			res+=find(y)-find(x)+1;
		}
		F(j,1,n)a[j]-=bin[i],b[j]-=bin[i];*/
		F(j,1,n)a[j]&=bin[i]-1,b[j]&=bin[i]-1;
		ans+=(res&1)*bin[i];
		//printf("%d %d\n",i,ans);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int N,M,ANS=0;
	vector<int> T;
	cin >> N >> M;
	for(int i=0;i<N;i++)
	{
		int A;
		cin >> A;
		for(int j=0;j<A;j++)
		{
			int B;
			cin >> B;
			T.push_back(B);
		}
	}
	
	for(int i=0;i<M+1;i++)
	{
		size_t n_count = count(T.begin(), T.end(), i);
		if(n_count==N)
		{
			ANS++;
		}
	}

	cout << ANS << endl;

}

Measured memory_bytes: 256
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
// namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif
using namespace std;

bool ok = true;
const size_t SIZE = 5000;
V<int> edges[SIZE];
int X[SIZE];

PLL dfs(int cur) {
    bitset<SIZE + 10> bs;
    bs.set(0, 1);
    int sum = 0;
    for(int nxt : edges[cur]) {
        int a, b;
        tie(a, b) = dfs(nxt);
        if(!ok) return PLL();
        sum += a + b;
        bs = (bs << a) | (bs << b);
    }
    for(int i = SIZE; 0 <= i; i--) {
        if(!bs.test(i)) continue;
        if(X[cur] < i) continue;
        return PLL(X[cur], sum - i);
    }
    ok = false;
    return PLL();
}

int main() {
    int N;
    scanf("%d", &N);
    for(int i = 1; i < N; i++) {
        int c = i;
        int p;
        scanf("%d", &p);
        edges[p - 1].push_back(c);
    }
    for(int i = 0; i < N; i++) scanf("%d", X + i);
    dfs(0);
    if(!ok) printf("IM");
    printf("POSSIBLE\n");
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;
bool sr(int a, int b)
{
	return a > b;
}
bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(ll n)
{
	int count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}
template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}
bool ssign(int a,int b){
	if(a>0&&b>0){
		return true;
	}else if(a<0&&b<0){
		return true;
	}else{
		return false;
	}
}
bool larger(int a,int b){
	if(a<b){
		return true;
	}else{
		return false;
	}
}
int main()
{
	int n;
	cin>>n;
	int no=0;
	int here=0;
	FOR(i,1,n+1){
		ll sum=(ll)(i+1)*i/2;
		if(sum>=n){
			//cout<<i<<endl;
			here=i;
			no=sum-n;
			break;
		}
	}
	//cout<<here<<endl;
	FOR(i,1,here+1){
		if(i!=no){
			cout<<i<<endl;
		}
	}

}

Measured memory_bytes: 256
a,b = map(int,input().split())
count = 0
for i in range(a,b+1):
    moji = str(i)
    flag = True
    for j in range(1,len(moji)//2+1):
        if moji[j-1]!=moji[-j]:
            flag = False
            break
    if flag:
        count += 1
print(count)

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    string a,b;
    cin >> a >> b;
    if(a.size()>b.size()){
        cout << "GREATER" << endl;
    }else if(a.size()<b.size()){
        cout << "LESS" << endl;
    }else{
        rep(i,a.size()){
            if(a[i]>b[i]){
                cout << "GREATER" << endl;
                return 0;
            }else if(a[i]<b[i]){
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n,a,ma=0,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a>=ma){
			ans++;
			ma=a;
		}		
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

if any([a < b for a,b in zip(A,B)]):
    print(-1)
    exit()
if A == B:
    print(0)
    exit()


def reachable(a,b,gr):
    if a == b: return True
    assert a > b
    visited = [0] * (a+1)
    stack = [a]
    while stack:
        v = stack.pop()
        if v == b: return True
        visited[v] = 1
        for to in gr[v]:
            if visited[to]: continue
            stack.append(to)
    return False

permanent_use = []

def need(n):
    gr = [set() for i in range(51)]
    for i in range(51):
        for p in permanent_use:
            gr[i].add(i%p)
        for j in range(1,n):
            gr[i].add(i%j)
    for a,b in zip(A,B):
        if not reachable(a,b,gr):
            return True
    return False

if need(51):
    print(-1)
    exit()

for i in range(50,0,-1):
    if need(i):
        permanent_use.append(i)

ans = 0
for p in permanent_use:
    ans += 2**p
print(ans)

Measured memory_bytes: 3188
while True:
    h, w = list(map(int, input().split()))
    a, b = divmod(w, 2)
    c, d = divmod(h, 2)
    if h == w == 0:
        break
    print(('#.' * a + '#' * b + '\n' + '.#' * a + '.' * b + '\n') * c
          + ('#.' * a + '#' * b + '\n') * d)

Measured memory_bytes: 7612
#include<bits/stdc++.h>
#define LL long long 
const int N=1e5+9;
using namespace std;
LL a[N],b[N],n,k,ans;
int pos[50],app[N],tot;
bool pd(int who,int difang)
{
	int flag=1;
	for(int i=30;i>=pos[difang];--i)
	   if(app[i]==0&&(a[who]&(1LL<<i)))
	      flag=0; 
	
	if(difang==tot)
	{
	 for(int i=pos[difang]-1;i>=0;--i)
	 if((a[who]&(1LL<<i)))
	  flag=0;
	 return flag;
    }
//if(difang==1&&who==3)
//{
//   system("pause");	
//}	
	for(int i=pos[difang]-1;i>=pos[difang+1];--i)
	 if((a[who]&(1LL<<i)))
	  flag=0;
	
	return flag;
	
}
int main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;++i) scanf("%lld%lld",&a[i],&b[i]);
	
	for(int i=30;i>=0;--i)
	 if((1LL<<i)&k) pos[++tot]=i;

//for(int i=1;i<=tot;++i)
// printf("pos[%d]:%d\n",i,pos[i]);	
  
	for(int i=0;i<=tot;++i)
	{
	   if(i) app[pos[i]]=1;
	   LL now=0;
	   for(int j=1;j<=n;++j)
	   {
	   	 if(i)
		  {
		   if(pd(j,i)) 
            now=now+b[j];
	      }
		 else 
		  {
		     int flag=1;
				 for(int p=30;p>=pos[1];--p)
		       if((a[j]&(1ll<<p)))
		        flag=0;
			   if(flag) now=now+b[j];	
		  } 
	   }
	   ans=max(ans,now);
	}
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
char s[100005];
const int base=40005;
int A[20005],B[20005];
int main()
{
	int n,a,cur=20000;
	scanf("%d",&n);
	for(int i=0;i<n;i++) A[i]=(i+1)*base;
	for(int i=0;i<n;i++) B[i]=(n-i)*base;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a);
		B[a-1]-=cur;
		cur--;
	}
	for(int i=0;i<n;i++) printf("%d ",A[i]);
	printf("\n");
	for(int i=0;i<n;i++) printf("%d ",B[i]);
	printf("\n");
	return 0;
}
/*
10 7 6
1 3
5 7
3 5
2 6
2 4
8 4
10 9
1 9 2 3 10 3
*/

Measured memory_bytes: 768
unittest
{
	assert( [ "3", "acornistnt", "peanutbomb", "constraint" ].parse.expand.solve == 1 );
	assert( [ "2", "oneplustwo", "ninemodsix" ].parse.expand.solve == 0 );
	assert( [ "5", "abaaaaaaaa", "oneplustwo", "aaaaaaaaba", "twoplusone", "aaaabaaaaa" ].parse.expand.solve == 4 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto ss = new dchar[][ n ];
	foreach( ref s; ss )
	{
		input.popFront;
		s = input.front.to!( dchar[] );
	}
	return tuple( ss );
}

auto solve( dchar[][] ss )
{
	foreach( ref s; ss )
	{
		s.sort();
	}
	auto ans = 0L;
	foreach( g; ss.sort().group )
	{
		auto c = cast( long ) g[ 1 ];
		ans += c * ( c - 1 ) / 2;
	}
	return ans;
}


Measured memory_bytes: 13308
#include<stdio.h>
int main(void)
{
  int price,time,dyna,stat;
  char str[16];
  
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d%d%d",&time,&dyna,&stat);
  
  price = time * dyna;
  
  if(price > stat)
  {
    printf("%d",stat);
  }else
  {
    printf("%d",price);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
ll inf=1e18;
ll p=1e9+7;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll i,j,w,h,a,x,y,r,k,d,b,c,n;
	cin>>n;
	string t;
	set<string>s;
	for(i=0;i<n;i++)
	{
	    cin>>t;
	    s.insert(t);
	}
	cout<<s.size();
	
	
	return 0;
	
	
}

Measured memory_bytes: 19288
// VSCF.cpp : Defines the entry point for the console application.
//
#include <list>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define FOR(v,p,k) for(int v=p;v<=k;++v)
#define FORD(v,p,k) for(int v=p;v>=k;--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define VAR(v,i) __typeof(i) v=(i)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define SIZE(x) (int)x.size()
#define ALL(c) c.begin(),c.end()
#define int long long
#define MAXN 1000010
typedef long double LD;

#undef int
int main() {
#define int long long
	ios_base::sync_with_stdio(0);
	vector<int> count;
	set<int> poss;
	poss.insert(0);
	int n, m;
	cin >> n >> m;
	count.resize(n, 1);
	REP(i, m) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		if (poss.count(x)) {
			if (count[x] == 1) {
				poss.erase(x);
			}
			poss.insert(y);
		}
		count[x]--;
		count[y]++;
	}
	cout << poss.size();
	return 0;
}



Measured memory_bytes: 5760
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    ll A,B,C,D;cin>>A>>B>>C>>D;
    ll A_C = (A - 1) / C;
    ll A_D = (A - 1) / D;
    ll B_C = B / C;
    ll B_D = B / D;
    ll A_CD = (A - 1) / (C * D / __gcd(C,D));
    ll B_CD = B / (C * D / __gcd(C,D));
    cout << B + 1 - A - ((B_C - A_C) + (B_D - A_D) - (B_CD - A_CD)) << endl;
    return 0;
}

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

using namespace std;


typedef long long ll;
//const int maxn=1e5;
//ll a[maxn];
vector<ll> ve;
int main(){
	ll n;
	cin>>n;
	ll k;
	for(int i=0;i<n;i++){
		cin>>k;
		ve.push_back(k);
	}
	ll ans=0;
	ll idex;
	for(int i=0;i<n-1;i+=(idex+1)){
		int j=i;
		idex=0;
		if(ve[j]<ve[j+1]) continue;
		while(ve[j]>=ve[j+1]){
			idex++;
			j++;
			if(j==n-1) break;
//			cout<<idex<<endl;
		}
		ans=max(ans,idex);
//		cout<<ans<<endl;	
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int digit_sum(int n) { 
    int res = 0;
    while (n > 0) {
        res += n % 10;
        n /= 10;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int mn = 1001001001;
    for (int i = 1; i <= n-1; ++i) {
        chmin(mn, digit_sum(i) + digit_sum(n-i));
    }
    cout << mn << endl;
}

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

int main(){
	int n, z, w;

	cin >> n >> z >> w;

	vector<int> a(n);

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

	int x1, x2;

	if(n>=2){
		x1 = abs(a[n - 2] - a[n-1]);
		x2 = abs(a[n - 1]- w);

		if(x2>x1){
			cout << x2 << endl;
		}else{
			cout << x1 << endl;
		}
	}else{
		cout << abs(a[0]- w) << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
int b[222222];
int vis[6222];
int a[6666];
 
vector<ll> S;
 
void dfs(int u, ll s)
{
	if(vis[u]) return ;
	vis[u]=1;
	s+=b[u];
	S.pb(s);
	dfs(a[u],s);
}
 
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; cin>>n>>k;
	for(int i=0;i<n;i++) 
	{
		cin>>a[i]; a[i]--;
	}
	for(int i=0;i<n;i++) 
	{
		cin>>b[i]; 
	}
	ll ans = -ll(1e18);
	for(int i=0;i<n;i++)
	{
		memset(vis,0,sizeof(vis));
		dfs(i,0);
		if(S.back()>0&&k>=int(S.size()))
		{
			ll q = k/int(S.size());
			if(q>=1)
			{
				ll mx = -ll(1e18);
				// if(q-1>0) mx=0;
				for(int i=0;i<int(S.size());i++)
				{
					mx=max(mx,S[i]);
				}
				ans=max(ans,(q-1)*S.back()+mx);
			}
			
			{
				int r = k%int(S.size());
				ll mx = 0;
				for(int i=0;i<r;i++)
				{
					mx=max(mx,S[i]);
				}
				ans=max(ans,mx+q*S.back());
			}
		}
		else
		{
			for(int j=1;j<=k;j++)
			{
				if(j-1<S.size()) ans=max(ans,S[j-1]);
				else break;
			}
		}
		S.clear();
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> d(N);
  rep(i,N)
  {
    cin >> d[i];
  }
  sort(ALL(d));
  cout << d[N/2] - d[N/2-1] << endl;
  return 0;
}


Measured memory_bytes: 3796
// finish date: 2018/05/26

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define pii pair<int,int>
const int bigmod = 1000000007;
#define INF 1050000000


int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0;
    vi bcount(20, 0);
    int l = 0;
    int r = 0;
    rep(i, 20) bcount[i] += (A[r] >> i) % 2;
    while (r < N) {
        rep(i, 20) {
            if (bcount[i] > 1) {
                rep(j, 20) bcount[j] -= (A[l] >> j) % 2;
                l++;
                goto outer;
            }
        }
        ans += r - l;
        r++;
        rep(i, 20) bcount[i] += (A[r] >> i) % 2;
        outer:;
    }
    cout << ans + N << endl;


    return 0;
}




Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<chrono>
#include<algorithm>
#include<functional>
#include<cstdlib>
#include<numeric>
#include<omp.h>
#include<queue>
#include<stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
constexpr double PI = 3.14159265358979323846;
int main()
{
	int N = 0;
	cin >> N;
	std::vector<int>ans(N, 0);
	int a = 0;
	for (int i = 0; i < N-1; i++)
	{
		cin >> a;
		ans[a - 1] += 1;

		
	}
	for (auto item : ans) {
		std::cout << item << std::endl;
	}
}

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

using namespace std;

int n,a[100010],a1[100010],b[100010],b1[100010];
int ans=-1,fa[100010],h[19260827],p[19260827],cnt;

inline int hah(int x)
{
	int y=x%19260817;
	while(h[y]>=0&&h[y]!=x)y=(y+1)%19260817;
	return y;
}

inline int f(int x)
{
	if(fa[x]!=x)fa[x]=f(fa[x]);
	return fa[x];
}

int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
	{
		scanf("%d",&a[i]);
		a1[i]=a[i];
		a[n+1]^=a[i];
	}
	a1[n+1]=a[n+1];
	for(int i=1; i<=n; i++)
	{
		scanf("%d",&b[i]);
		b1[i]=b[i];
		b[n+1]^=b[i];
	}
	b1[n+1]=b[n+1];
	sort(a1+1,a1+n+2);
	sort(b1+1,b1+n+2);
	for(int i=1; i<=n+1; i++)
	{
		if(a1[i]^b1[i])
		{
			printf("-1");
			return 0;
		}
	}
	memset(h,-1,sizeof(h));
	for(int i=1; i<=n+1; i++)
	{
		if(i==n+1||a[i]^b[i])
		{
			if(i<=n)ans++;
			int k=hah(a[i]);
			if(h[k]==-1)h[k]=a[i],p[k]=++cnt;
			k=hah(b[i]);
			if(h[k]==-1)h[k]=b[i],p[k]=++cnt;
		}
	}
	for(int i=1; i<=cnt; i++)fa[i]=i;
	for(int i=1; i<=n+1; i++)
	{
		if(a[i]^b[i])
		{
			fa[f(p[hah(a[i])])]=f(p[hah(b[i])]);
		}
	}
	for(int i=1; i<=cnt; i++)if(fa[i]==i)ans++;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 152704
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
using Graph = vector<vector<pair<int, int> > >;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

int N;
ll W;
ll dp[110][100101];

vector<ll > w;
vector<ll > v;


int main() {
	cin >> N >> W;
	w.assign(N+1, 0);
	v.assign(N+1, 0);
	for (int i = 0; i <= N; i++) {
		if(i!=0)cin >> w[i] >> v[i];
		for (int val = 0; val <= 100100; val++) {
			dp[i][val] = INF10;
		}
	}

	dp[0][0] = 0;
	for (int val = 0; val < 100101;val++) {
		for (int i = 1; i <= N; i++) {
			if (val - v[i] >= 0) {
				dp[i][val] = min(dp[i - 1][val - v[i]] + w[i], dp[i][val]);
			}
			dp[i][val] = min(dp[i - 1][val],dp[i][val]);
		}
	}

	ll ans = 0;
	for (ll val = 0; val < 100100; val++) {
		if (dp[N][val] <= W)ans = val;
	}
	
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 80128
#include<bits/stdc++.h>
using namespace std;
#define INF (1LL<<30)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long


signed main(){
	string s;
	cin>>s;
	string ans="Good";
	lp(i,3){
		if(s[i]==s[i+1]) ans="Bad";
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0262>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int M;
string solve(){
    int n; cin >> n;
    vector<int> d(n+2);
    for(int i = 1; i <= n;i++) cin >> d[i];
//    vector<vector<int>> canvisit(n+2,vector<int>(n+2,0));
//    for(int i = 0; i < n+2;i++) canvisit[i][i] = 1;
//    for(int i = 0; i < n+2;i++){
//        queue<int> q; q.push(i);
//        while(q.size()){
//            int now = q.front(); q.pop();
//            if(canvisit[i][now]) continue;
//            canvisit[i][now] = true;
//            for(int dice = 1; dice <= M && dice+now<=n+1;i++){
//
//            }
//        }
//    }
    vector<int> canvisit(n+2),checked(n+2); canvisit[0] = true;

    while(true){
        int target = -1;
        for(int i = 0; i <= n;i++){
            if(canvisit[i]){
                if(checked[i]) continue;
                target = i;
                break;
            }
        }
        if(target == -1) break;
        checked[target] = true;

        vector<int> visited(n+2);
        queue<int> q; q.push(target);
        while(q.size()){
            int now = q.front(); q.pop();
            if(visited[now]) continue;
            visited[now] = true;
            for(int dice = 1; dice <= M;dice++){
                if(now + dice >= n+2)break;
                int next = max(0,min(n+1,dice+now));
                q.push(max(0,min(n+1,next+d[next])));
            }
        }
        if(visited[n+1] == false) return "NG";
        if(target == 0){
            for(int i = 0; i <= n;i++){
                canvisit[i] |= visited[i];
            }
        }
    }
    return "OK";
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> M,M){
        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 3220
function main(input: string) {
  const [M1, M2] = input.split("\n").map(v => parseInt(v.split(" ")[0]));
  console.log(M1 === M2 ? 0 : 1)
}

main(
  require("fs")
    .readFileSync("/dev/stdin", "utf8")
    .trim()
);

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
// using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
#define int ll
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define vi vector<int>
#define pii pair<int,int>
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define initialize(arr,elem) memset(arr,elem,sizeof(arr))
#define sz size
const int MOD = 1e9+7;
const int MAX_SZ = 2e5+9;
const int INF = 1e18+9;

int n;
int seg_tree[2*MAX_SZ];
int tree[4*MAX_SZ],A[MAX_SZ];

// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
void build(){
	for (int i= n-1;i>0;--i) seg_tree[i] = max(seg_tree[i<<1], seg_tree[(i<<1)|1]);
}

void point_update(int p, int value){
	for (seg_tree[p+=n] = value;p>1; p>>=1) seg_tree[p>>1] = max(seg_tree[p],seg_tree[p^1]);
}

int query(int l, int r){
	int res = 0;
	for (l+=n, r+=n; l<r; l>>=1, r>>=1) {
		if (l&1) res = max(seg_tree[l++], res);
		if (r&1	) res = max(seg_tree[--r],res);
	}
	return res;
}

void rand_shuff(vi &arr){
	random_device rd;
	mt19937 g(rd());
	shuffle(all(arr),g);
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
		
	cin>>n;
	int height[n],val[n];
	For(i,0,n) cin>>height[i];
	For(i,0,n) cin>>val[i];
	For(i,0,n) height[i]--;
	//int arr[n+1];
	initialize(seg_tree,0);
	seg_tree[height[0]+n] = val[0];
	build();
	int res = val[0];
	For(i,1,n){
		int cur = query(0,height[i]);
		if (height[i] == 0) point_update(0,val[i]);
		else point_update(height[i],cur+val[i]);
		res = max(res,cur+val[i]);
	}

	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 8192
l,r=map(int,input().split());d=y=2019;a=l%y;b=r%y;c=(r-l)//y
if c>0 or b<=a:print(0)
else:
	for i in range(a,b):
		for j in range(i+1,b+1):
			e=(i*j)%y;d=e if e<d else d
	print(d)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define ALL(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 999999999
const double PI = 3.1415926535897932384626433832795;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
	ios::sync_with_stdio(false);

	string s1,s2,s3;
	cin >> s1 >> s2 >> s3;
	std::transform(s1.begin(),s1.end(),s1.begin(), ::toupper);
	std::transform(s2.begin(),s2.end(),s2.begin(), ::toupper);
	std::transform(s3.begin(),s3.end(),s3.begin(), ::toupper);
	cout << s1[0] << s2[0] << s3[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<map>
int main()
{
	int n,x,i,f;
	while(scanf("%d",&n),n)
	{
		typedef std::map<int,int>M;
		M m;
		for(f=i=0;i<n;++i)scanf("%d",&x),m[x]++;
		for(M::iterator t=m.begin();t!=m.end();++t)
			if(t->second>n/2)f=printf("%d\n",t->first);
		if(!f)puts("NO COLOR");
	}
	return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> G(H);
    rep(i, H) cin >> G[i];

    vector<vector<int>> GG(H * W, vector<int>(0));
    for (int x = 0; x < H; x++) {
        for (int y = 0; y < W; y++) {
            int cid = x * W + y;
            char cc = G[x][y];
            for (int i = 0; i < 4; i++) {
                int nx = x + dx[i], ny = y + dy[i];
                if (nx < 0 or H <= nx or ny < 0 or W <= ny) continue;
                int nid = nx * W + ny;
                int nc  = G[nx][ny];
                if (nc != cc) {
                    GG[cid].push_back(nid);
                    // GG[nid].push_back(cid);
                };
            }
        }
    }

    lint ans = 0;
    vector<bool> check(W * H, false);
    for (int id = 0; id < H * W; id++) {
        if (check[id]) continue;
        check[id] = true;
        lint cntW = 0, cntB = 0;

        queue<int> que;
        que.push(id);
        while (not que.empty()) {
            int cid = que.front();
            que.pop();
            int cx = cid / W, cy = cid % W;
            if (G[cx][cy] == '#')
                cntB++;
            else
                cntW++;

            for (auto nid : GG[cid]) {
                if (not check[nid]) {
                    que.push(nid);
                    check[nid] = true;
                }
            }
        }
        ans += cntB * cntW;
    }

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

Measured memory_bytes: 9216
use std::cmp::min;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        x: i64,
        y: i64,
        xs: [i64; n],
        ys: [i64; m],
    }
    let mut xm = xs; xm.push(x);
    let mut ym = ys; ym.push(y);
    let maxx = xm.iter().max();
    let miny = ym.iter().min();
    if maxx < miny{
        println!("No War");
    } else {
        println!("War");
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll K;
  ll X;
  IN(K,X);

  if(K*500>=X){
    OUT("Yes");
  }else{
    OUT("No");
  }

  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);

  sort(H.begin(), H.end());

  int ans = 1e9;

  for (int i = K - 1; i < N; i++) {
    ans = min(ans, H.at(i) - H.at(i - (K - 1)));
  }

  cout << ans << endl;
}

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

int main(){
    int N;
    cin>>N;
    vector<string> S(N);
    for(auto &s:S) cin>>s;
    int BA=0,XA=0,BX=0;
    int ans=0;
    for(auto s:S){
        if(s[0]=='B'&&s.back()=='A'){
            BA++;
        }else if(s.back()=='A'){
            XA++;
        }else if(s[0]=='B'){
            BX++;
        }
        for(int i=0;i<s.size()-1;i++){
            if(s[i]=='A'&&s[i+1]=='B') ans++;
        }
    }
    ans+=max(0,BA-1);
    BA=min(1,BA);
    if(BA){
        if(XA&&BX){
            ans+=2;
            XA--;BX--;
        }else if(XA){
            ans++;
            XA--;
        }else if(BX){
            ans++;
            BX--;
        }
    }
    ans+=min(XA,BX);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 768
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int main() {
	int N;
	lint K;
	cin >> N >> K;
	
	vector< lint > A(N), F(N);
	for (int i=0; i<N; ++i) cin >> A[i];
	for (int i=0; i<N; ++i) cin >> F[i];
	sort(allof(A));
	sort(allof(F), greater< lint >());
	
	auto valid = [&](lint x) {
		lint sum = 0LL;
		for (int i=0; i<N; ++i) {
			lint y = x / F[i];
			sum += max(0LL, A[i] - y);
		}
		return sum <= K;
	};
	
	lint lb = -1, ub = (lint)1e15;
	while (ub - lb > 1) {
		lint med = (lb + ub) / 2;
		if (valid(med)) ub = med;
		else lb = med;
	}
	cout << ub << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 3328
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var a = +o.getValue(0);

    return a + a**2 + a**3;
}

Measured memory_bytes: 29584