akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 1000000007;
const int INF = 1001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    --x;
    --y;
    vector<int> ans(n);
    rep(l, n-1) {
        for(int r = l + 1; r < n; ++r) {
            int c = abs(x-l);
            int d = abs(y-r);
            int e = min(r-l, c+d+1);
            ++ans[e];
        }
    }
    repl(i, 1, n) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3616
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define sz(x) (int) x.size()
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i=0;i<(int)n;++i)
#define per(i, n) for(int i=(int)n-1;i>=0;--i)
#define rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef string str;
typedef long double db;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<str> vstr;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

//

int32_t main() {
  FAST_IO;
  str s;
  cin >> s;
  if (s == "ARC")
    cout << "ABC";
  else
    cout << "ARC";
  rtn 0;
}


Measured memory_bytes: 3636
<?php
$S=trim(fgets(STDIN));
$P=trim(fgets(STDIN));

$Sl=strlen($S);
$Pl=strlen($P);
$p=$P[0];
$S.=$S;
$F=0;
for($i=0;$i<$Sl;$i++){
  if($S[$i]!=$p) continue;
  $f=1;
  for($j=1;$j<$Pl;$j++) if($S[$i+$j]!=$P[$j]){$f=0;break;}
  if($f){$F=1;break;}
}
echo ($F)?'Yes':'No';
?>

Measured memory_bytes: 15436
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
#define intt long long
#define PI 3.14159265358979323846

using namespace std;
int main() {
    intt N; std::cin >> N;
    std::vector<intt> P(N);
    for (auto& r : P) {
        std::cin >> r;
        --r;
    }
    intt ans = 0;
    for (intt i = 0; i < N - 1; ++i) {
        if (P[i] == i) {
            std::swap(P[i], P[i + 1]);
            ++ans;
        }
    }
    if (P[N - 1] == N - 1) {
        ++ans;
    }
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 4040
S = input()

a = "0b"
for i in range(len(S)):
    if i % 2 == 0:
        a += "0"
    else:
        a += "1"
a = int(a, 2)
b = "0b"
for i in range(len(S)):
    if i % 2 == 0:
        b += "1"
    else:
        b += "0"
b = int(b, 2)
S = int("0b"+S, 2)
S_a = S ^ a
S_b = S ^ b
print(bin(S_a).count("1") if bin(S_a).count("1") < bin(S_b).count("1") else bin(S_b).count("1"))


Measured memory_bytes: 3316
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits, ascii_letters
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = INT()
B = INT()

ans = [1, 2, 3]

for i in ans:
	if i not in [A, B]:
		print(i)


Measured memory_bytes: 14552
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
    int64_t N, A, B, ans;
    cin >> N >> A >> B;

    int64_t div = N / (A+B);
    int64_t sur = N % (A+B);
    if(sur < A){
        ans = A * div + sur;
        cout << ans << endl;
    }else{
        ans = A * div + A;
        cout << ans << endl;
    }
    return 0;
}


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

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using ld = long double;

constexpr ll MOD = 1000000007LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    for (ll b = K + 1; b <= N; b++) {
        for (ll c = 0; c + K <= N; c += b) {
            ans += min(c + b - 1, N) - (c + K) + 1;
        }
    }
    if (K == 0) {
        ans -= N;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int even = sc.nextInt();  //偶数の個数
		int odd = sc.nextInt();  //奇数の個数
		int total = 0;

		if(even>=2 && odd >=2) {
			total = even*(even-1)/2 + odd*(odd-1)/2;
		}
		else if(even>=2 && odd <2) {
			total = even*(even-1)/2;
		}
		else if(even<2 && odd>=2) {
			total = odd*(odd-1)/2;
		}
		System.out.print(total);
	}
}


Measured memory_bytes: 23764
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
xorsum = 0
for i in range(60):
  c1 = sum([1 for a in A if (a >> i) & 1]) #
  xorsum += (c1*(N-c1)*(1<<i))
  xorsum = xorsum%mod
print(xorsum%mod)


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

using namespace std;

#define pb push_back

const int maxi = 1e6+10;
int a[maxi];
string s;
vector<int> v[maxi];
int m,n;

int main()
{
    cin>>s;

    int n = s.size();
    s = '+' + s;

    for (int i = 1;i<=n/2;i++)
        if (s[i]!=s[n-i+1]) return !printf("No\n");

    int x  = (n - 1)/ 2;

    for (int i = 1;i<=x;i++)
        if (s[i]!=s[x-i+1]) return !printf("No\n");

    printf("Yes\n");
    return 0;
}
//volim tvoje oci tamne kao greh


Measured memory_bytes: 24832
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int N, M; cin >> N >> M;
 
  vector<int> lv;
  vector<int> lr;
  for (int i = 0; i < M; i++) {
    int a, b = 0;
    cin >> a >> b;
    lv.push_back(a);
    lr.push_back(b); 
  }
  int maxNum = *max_element(lv.begin(), lv.end());
  int minNum = *min_element(lr.begin(), lr.end());
  
  int ans = max((minNum - maxNum + 1), 0);
  
  cout << ans << endl;  
}

Measured memory_bytes: 1276
#define DEBUG 1
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

int main() {
    std::cin.tie(0); std::cin.sync_with_stdio(false);
    std::string s; std::cin >> s;
    int n=s.length();
    int ans=0;
    int a=s.at(0)-'0';
    int k; std::cin >> k;
    if(k==1){
        std::cout << a+9*(n-1) << std::endl;
    }
    if(k==2){
        // 1 つ目が 1 以降
        ans+=(n-1)*(n-2)/2*9*9;
        // 1 つ目が 0 番目で、数字として小さい
        ans+=(a-1)*(n-1)*9;
        int j=1;
        while(j<n&&s.at(j)=='0')j++;
        if(j<n){
            int b=s.at(j)-'0';
            // 2 つ目が j+1 以降
            ans+=(n-1-j)*9;
            // 2 つ目が j 番目
            ans+=b;
        }
        std::cout << ans << std::endl;
    }
    if (k==3){
        // 1 つ目が 1 以降
        ans+=(n-1)*(n-2)*(n-3)/6*9*9*9;
        // 1 つ目が 0 番目で、数字として小さい
        ans+=(a-1)*(n-1)*(n-2)/2*9*9;

        int j=1;
        while(j<n&&s.at(j)=='0')j++;
        int k=j+1;
        while(k<n&&s.at(k)=='0')k++;
        if(j<n){
            int b=s.at(j)-'0';
            // 2 つ目が j+1 以降
            ans+=(n-1-j)*(n-2-j)/2*9*9;
            // 2 つ目が数字として小さい
            ans+=(b-1)*(n-1-j)*9;
        }
        if(k<n){
            int c=s.at(k)-'0';
            // 3 つ目が k+1 以降
            ans+=(n-1-k)*9;
            // 3 つ目が k 番目
            ans+=c;
        }
        std::cout << ans << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int

int two(int n)
{
    int cnt = 0;
    while (1)
    {
        if (n % 2 == 1)
            return cnt;
        else
        {
            cnt++;
            n /= 2;
        }
    }
}

int main()
{
    ll n, a[10000];
    ll ans = 0;

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


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

int main(){
    int n,k,tmp,input;
    int count = 0;
    cin >> n >> k;


    vector<int> sunuke(n, 0);
    vector<int> d(k);

    for(int i=0; i<k; i++){
        cin >> d.at(i);
        tmp = d.at(i);
        for(int j=0; j < tmp; j++){
            cin >> input;
            sunuke.at(input-1)++;
        }
    }
    
    for(int i=0; i<n; i++){
        if(sunuke.at(i)==0){
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3636
n,q = (int(i) for i in input().split())
s = input()
ruiseki = [0]
for i in range(n-1):
    if s[i]+s[i+1] == 'AC': ruiseki.append(ruiseki[i]+1)
    else:   ruiseki.append(ruiseki[i])
lr = [[int(i) for i in input().split()] for i in range(q)]
#print(ruiseki)
for l,r in lr:
    print(ruiseki[r-1]-ruiseki[l-1])


Measured memory_bytes: 24452
#include <bits/stdc++.h>
using namespace std;
int n,m;
const int maxn=1e5+5;
int w[maxn];
int dis[maxn];
int father(int x)
{
    if(w[x]==x)
        return x;
    int r=father(w[x]);
    dis[x]=dis[w[x]]+dis[x];
    return w[x]=r;
}
int mix(int x,int y,int d)
{
    int fx,fy;
    fx=father(x);
    fy=father(y);
    if(fx!=fy){
        w[fy]=fx;
        dis[fy]=dis[x]-dis[y]+d;
        return 1;
    }
    return d==dis[y]-dis[x];
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        w[i]=i;
    }
    int f=1;
    for(int i=1;i<=m;i++){
        int l,r,d;
        scanf("%d %d %d",&l,&r,&d);
        if(f)
            f=mix(l,r,d);

    }
    if(f)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<double> x(10);
	vector<string> u(10);
	double ans = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> x[i] >> u[i];
		if(u[i] == "JPY") ans+=x[i];
		else ans+=380000.0*x[i];
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;
    cin>>n>>m;
    int ans = 0;
    for(int i = 1;i*i <= m;i++){
        if(m%i==0){
            int a = m/i;
            if(a>=n){chmax(ans, i);}
            if(i>=n){chmax(ans, a);}
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def bubble_sort(A, N):
    flag = True
    cnt = 0
    while flag:
        flag = False
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                A[i], A[i-1] = A[i-1], A[i]
                cnt += 1
                flag = True
    print(*A, sep=' ')
    print(cnt)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    bubble_sort(A, N)


if __name__ == "__main__":
    main()


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

using namespace std;

int main()
{
	long long n, m, d;
	cin >> n >> m >> d;
	cout << fixed << setprecision(7) << (long long)2 * (n - d) / (double)(n * n) * (m - 1) / (d == 0 ? 2 : 1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  double a, b, c, d, e, f;
  double x, y;

  while (scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f) != EOF) {

    x = (c * e - b * f) / (a * e - b * d);
    y = (c * d - a * f) / (b * d - a * e);

    if (x == 0) x = 0;
    if (y == 0) y = 0;

    printf("%.03lf %.03lf\n", x, y);
  }
      
  return(0);
}

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

int main() {
  int k, x;
  cin >> k >> x;
  for (int i = x - k + 1; i < k + x - 1; i++) {
    cout << i << " ";
  }
  cout << k + x - 1 << endl;
  return 0;
}

Measured memory_bytes: 256
def makelist(n, m):
    return [['.' for _ in range(m)] for _ in range(n)]

a, b = map(int, input().split())
N = 100
h = N // 2
d = makelist(N, N)


for y in range(h):
    for x in range(N):
        d[y][x] = "#"

a, b = a-1, b-1

for y in range(h):
    for x in range(N):
        if a == 0:
            break
        if y % 2 == 0 and x % 2 == 0:
            a -= 1
            d[y][x] = "."

for y in reversed(range(h, N)):
    for x in range(N):
        if b == 0:
            break
        if y % 2 == 1 and x % 2 == 1:
            b -= 1
            d[y][x] = "#"

print(N, N)
for y in range(N):
    print("".join(d[y]))


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <string>
#define int long long
#define REP(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define mp make_pair
#define Pii pair< int, int > 
#define Pid pair< int, double > 
#define Pdd pair< double, double > 
#define MOD 998244353
#define EPS 0.00000001

using namespace std;

signed main() {
    double l;
    cin >> l;
    printf("%.20lf\n",(l/3) * (l/3) * (l/3));
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    int r,g,b;
    cin >>r>>g>>b;
    if((g*10+b)%4== 0)
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int M=sc.nextInt();
        
        for(int i=0;i<M;i++){
            N-=sc.nextInt();
        }
        
        if(N<0){
            System.out.println(-1);
            return ;
        }
        
        System.out.println(N);
    }
}


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

using namespace std;

int main(void)
{
    int n,k,x,y;

    cin>>n;
    cin>>k;
    cin>>x;
    cin>>y;

    int sum = 0;
    for(int i = 1;i <= n;i++)
    {
	if(i <= k)
	    sum += x;
	else
	    sum += y;
    }

    cout<<sum<<endl;

    return 0;
}


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


int n,m;
const int Max = (int)1e5+1;
vector<int> adj[Max];
bool visited[Max];
int parent[Max];
int numNodes[Max], sizes[Max];
int subtreeSize[Max] = {0};
ll sum1[Max], sum2[Max];

void dfs(int node) {
    visited[node] = true;
    numNodes[node] = 1;
    sum1[node] = 0;
    for(int to : adj[node]) {
        if(!visited[to]) {
            dfs(to);
            numNodes[node] += numNodes[to];
            sum1[node] += sum1[to] + (ll)numNodes[to];
        }
    }
}

void bfs(int start, ll treeSize) {
    queue<int> q;
    q.push(start);
    visited[start] = true;
    sum2[start] = sum1[start];
    while(!q.empty()) {
        int parent = q.front();
        q.pop();
        for(int node : adj[parent]) {
            if(!visited[node]) {
                q.push(node);
                visited[node] = true;
                sum2[node] = sum1[node];
                sum2[node] += sum2[parent]-sum1[node]-(ll)numNodes[node];
                sum2[node] += treeSize-(ll)numNodes[node];
            }
        }
    }
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    fill(subtreeSize, subtreeSize+n, 1);
    vector<pair<int, int>> arr(n);
    for(int i = 0; i < n; ++i) {
        cin >> arr[i].first;
        arr[i].second = i+1;
    }
    sort(arr.begin(), arr.end());
    map<int, int> toNode;
    for(int i = 0; i < n; ++i) {
        toNode[arr[i].first] = i;
    }
    
    //subtreeSize
    vector<pair<int, int>> edges;
    for(int i = n-1; i > 0; --i) {
        int nextSize = arr[i].first + 2*subtreeSize[i] - n;
        if(!toNode.count(nextSize)) {
            cout << "-1\n";
            return 0;
        }
        int par = toNode[nextSize];
        adj[par].push_back(i);
        adj[i].push_back(par);
        edges.push_back({par, i});
        subtreeSize[par] += subtreeSize[i];
    }
    fill(visited, visited+n, false);
    dfs(0);
    fill(visited, visited+n, false);
    bfs(0, n);
    for(int i = 0; i < n; ++i) {
        if(sum2[i] != arr[i].first) {
            cout << "-1\n";
            return 0;
        }
    }
    for(auto &p : edges) {
        cout << arr[p.first].second << ' ' << arr[p.second].second << '\n';
    }
    return 0;
}
















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

using i64 = int64_t;

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

    if(s[0] != '1' || s.back() != '0'){
        cout << -1 << endl;
        return 0;
    }

    int n = s.size();
    for(int i=0;i<(int)s.size()/2;++i){
        if(s[i] != s[n-i-2]){
            cout << -1 << endl;
            return 0;
        }
    }

    vector<pair<int, int>> ans;
    int par = n;
    for(int i=n-2;i>=0;--i){
        ans.emplace_back(i+1, par);
        if(s[i] == '1')par = i+1;
    }

    for(auto e: ans){
        cout << e.first << " " << e.second << endl;
    }

    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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

int main()
{
  ll N,K;
  cin >> N >> K;
  VEC(ll,A,N);
  ll sum = 0;
  vector<ll> imos(1,0);
  REP(i,N){
    sum+=A[i];
    imos.push_back(sum);
  }
  vector<ll> bf;
  REP(i,N){
    REP(j,i){
      bf.push_back(imos[i+1]-imos[j]);
    }
  }
  sort(ALL(bf));
  reverse(ALL(bf));
  // REP(i,sz(bf)){
  //   cout << bf[i] << endl;
  // }
  ll ans=0;
  REPR(i,99,0){
    int cnt = 0;
    vector<ll> newbf;
    REP(j,sz(bf)){
      bitset<100> bs(bf[j]);
      if(bs[i]==1){
        cnt++;
        newbf.push_back(bf[j]);
      }
    }
    if(cnt>=K){
      bf=newbf;
      ans+=pow(2,i);
      // cout << i << endl;
    }
  }

  cout << ans << endl;
}

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define I1000000007 (1000000007)
#define I998244353   (998244353)
#define IINF             (1<<28)
#define LINF           (1LL<<60)
#define ALL(a)         (a).begin(), (a).end()
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"
template<class T> inline bool chmin(T& a, const T& b) {
  if (a > b) { a = b; return true; } else return false;
}
template<class T> inline bool chmax(T& a, const T& b) {
  if (a < b) { a = b; return true; } else return false;
}

namespace solver {
  using namespace std;
  using ll = long long;

  ll N, M;
  vector<int> color;
  vector<vector<int> > G;

  void init() {
    cin >> N >> M;
    color.resize(N);
    G.resize(N);
    int a, b;
    rep(i, M) {
      cin >> a >> b;
      a--;
      b--;
      G[a].push_back(b);
      G[b].push_back(a);
    }
  }

  bool dfs(int u, int c) {
    color[u] = c;
    for(const auto& v : G[u]) {
      if(color[u] == color[v]) return false;
      if(color[v] == 0 && !dfs(v, -c)) return false;
    }
    return true;
  }

  void solve() {
    fill(ALL(color), 0);
    if(dfs(0, 1)) {
      ll b = 0;
      ll w = 0;
      for(const auto& c : color) {
        if(c == 1) b++;
        else w++;
      }
      cout << b*w - M << "\n";
    } else {
      cout << N*(N-1)/2 - M << "\n";
    }
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 6528
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i] > a[j]) {
                if (i < j) {
                    ans += k * (k + 1) / 2;
                } else {
                    ans += k * (k - 1) / 2;
                }
                ans %= mod;
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  ll n,m,ans=0; cin>>n; m=3*n;
  ll a[m];
  rep(i,m){
    cin>>a[i];
  }
  sort(a,a+m);
  rep(i,n){
    ans+=a[n+2*i];
  }
  cout<<ans;
}

Measured memory_bytes: 2560
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: String,
    };
    match n.as_str().chars().last().unwrap().to_string().as_str() {
        "2" | "4" | "5" | "7" | "9" => print!("hon"),
        "0" | "1" | "6" | "8" => print!("pon"),
        "3" => print!("bon"),
        _ => (),
    }
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<63;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

int main(void){
    int N,M; cin >> N >> M;
    VI p(M);
    vector<string> S(M); REP(i,M) cin >> p[i] >> S[i];

    int ans[N][2]; REP(i,N)REP(j,2) ans[i][j] = 0;
    REP(i,M){
        p[i]--;
        if(S[i] == "AC") ans[p[i]][1] = min(1, ans[p[i]][1]+1);
        else{
            if(ans[p[i]][1] == 0) ans[p[i]][0]++;
        }
    }

    int AC=0, WA=0;
    REP(i,N){
        AC += ans[i][1];
        if(ans[i][1] == 1) WA += ans[i][0];
    }
    cout << AC << " " << WA << endl;
    return 0;
}

Measured memory_bytes: 6912
import bisect
n = int(input())
edges = sorted(list(map(int, input().split(' '))))
ans = 0
for i in range(n-1, -1, -1):
  for j in range(i-1, -1, -1):
    limit = edges[i] - edges[j]
    if limit < edges[j]:
      index = bisect.bisect_right(edges, limit)
      ans += max(0, j - index)  # maxいらんかも
print(ans)


Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[256];
	int i, j, num = 0;
	
	scanf("%s", str);
	
	i = 0;
	j = strlen(str) - 1;
	while (i <= j){
		switch (str[i]){
			case ' ':
			case 'i':
			case 'w':
			if (str[i] != str[j]){
				num++;
			}
			break;
			
			case '(':
			if (str[j] != ')'){
				num++;
			}
			break;
			
			case ')':
			if (str[j] != '('){
				num++;
			}
			break;
		}
		
		i++;
		j--;
	}
	
	printf("%d\n", num);
	
	return (0);
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int h, w;
  cin >> h >> w;
  h += 2;
  w += 2;

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (i == 0 || j == 0 || i == h - 1 || j == w - 1) {
        cout << '#';
      } else {
        char c;
        cin >> c;
        cout << c;
      }
    }
    cout << '\n';
  }

  return 0;
}


Measured memory_bytes: 3644
while True:
  h, w = [int(i) for i in input().split()]
  if h == 0 and w == 0:
    break
  for i in range(h):
    for j in range(w):
        print('#' if (i % 2 == 0 and j % 2 == 0) or (i % 2 != 0 and j % 2 != 0) else '.', end='')
    print()
  print()


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

typedef long long ll;
using namespace std;

int main()
{
    ll x;
    cin >> x;
    ll base = x / 11, rem = x % 11;
    cout << base * 2 + (rem > 6 ? 2 : (rem == 0 ? 0 : 1));
    return 0;
}

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() {
    int N;
    cin >> N;
    vector<string> s(N);

    ll res = 0;
    ll la = 0, fb = 0, lf = 0;
    rep(i, N) {
        cin >> s[i];
        for(int j=1; j<int(s[i].size()); j++) {
            if(s[i][j-1] == 'A' && s[i][j] == 'B') res++;
        }
        if(s[i][s[i].size()-1] == 'A' && s[i][0] == 'B') lf++;
        else if(s[i][s[i].size()-1] == 'A') la++;
        else if(s[i][0] == 'B') fb++;
    }
    
    if(lf == 0) res += min(la, fb);
    else {
        if(la + fb > 0) res += lf + min(la, fb);
        else res += lf - 1;
    }


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

Measured memory_bytes: 768
#include<bits/stdc++.h> 
#define lowbit(x) ((x) & (-(x)))

const int N = 300010;

int n, m, c[N], ans[N];

void add(int l, int r){
	++ r;
	while (r < N){
		-- c[r];
		r += lowbit(r);
	}
	while (l < N){
		++ c[l];
		l += lowbit(l);
	}
}

int query(int sit){
	int ret = 0;
	while (sit){
		ret += c[sit];
		sit -= lowbit(sit);
	}
	return ret;
}

std::vector <std::pair <int, std::pair <int, int>>> vec;

int main(){
	scanf("%d%d", &n, &m);
	for (int i = 0, l, r; i < n; ++ i){
		scanf("%d%d", &l, &r);
		vec.push_back({r - l + 1, {l, r}});
	}
	sort(vec.begin(), vec.end());
	for (int i = 1, sit = 0; i <= m; ++ i){
		while (vec[sit].first <= i && sit < n){
			add(vec[sit].second.first, vec[sit].second.second);
			++ sit;
		}
		for (int j = 1; i * j <= m; ++ j){
			ans[i] += query(i * j);
		}
		ans[i] += n - sit;
	}
	for (int i = 1; i <= m; ++ i){
		printf("%d\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 6512
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, M = LI()
p = LI()
xy = []
for i in range(M):
    x, y = LI()
    x -= 1
    y -= 1
    xy.append((x, y))

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

uf = UnionFind(N)
p_dic = {}
for i in range(N):
    p_dic[p[i]] = i
# print(p_dic)

for i in range(M):
    x, y = xy[i]
    uf.Unite(x, y)

ans = 0
for i in range(1, N + 1):
    if uf.isSameGroup(p_dic[i], i - 1):ans += 1
print(ans)



Measured memory_bytes: 38252
/*
  Topic5 ProblemB MergeSort
  n 個の整数を含む数列 S を上の疑似コードに従ったマージソートで昇順に整列するプログラムを作成してください。また、mergeにおける比較回数の総数を報告してください。 
 */

#include<stdio.h>

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int*, int, int, int, int);
void mergeSort(int*, int, int, int);

int main()
{
  int A[MAX], n, i;
  cnt = 0;

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

  mergeSort(A, n, 0, n);

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

void merge(int A[], int n, int left, int mid, int right)
{
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  
  for(i=0;i<n1;i++)
    {
      L[i] = A[left + i];
    }

  for(i=0;i<n2;i++)
    {
      R[i] = A[mid + i];
    }
  
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  i = 0; j = 0;

  for(k=left;k<right;k++)
    {
      cnt++;
      if(L[i] <= R[j])A[k] = L[i++];
      else A[k] = R[j++];
    }
}

void mergeSort(int A[], int n, int left, int right)
{
  int mid;
  
  if(left+1 < right)
    {
      mid = (left + right)/2;
      mergeSort(A, n, left, mid);
      mergeSort(A, n, mid, right);
      merge(A, n, left, mid, right);
    }
}



Measured memory_bytes: 5620
N=int(input())
a=list(map(int,input().split()))

a=sorted(a)
s=set(a)
count=0

base=0
judge=0

for i in a:
    if base!=i:
        #print(judge,base)
        if judge>=base:
            count+=judge-base
        else:
            count+=judge
        base=i
        judge=1
    else:
        judge+=1
if judge>=base:
    count+=judge-base
else:
    count+=judge


print(count)

Measured memory_bytes: 14712
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;

const int IT = 1000;

const double eps = 1e-9;
bool eq(double x, double y)
{
	return fabs(x - y) < eps;
}
bool ls(double x, double y)
{
	return x < y && !eq(x, y);
}
bool lseq(double x, double y)
{
	return x < y || eq(x, y);
}

struct Point
{
	double x, y;

	Point() : x(), y() {}
	Point (double _x, double _y) : x(_x), y(_y) {}

	void scan()
	{
		scanf("%lf%lf", &x, &y);
	}
	void print()
	{
		printf("(%.5lf %.5lf)\n", x, y);
	}

	Point operator + (const Point &a) const
	{
		return Point(x + a.x, y + a.y);
	}
	Point operator - (const Point &a) const
	{
		return Point(x - a.x, y - a.y);
	}
	Point operator * (const double &k) const
	{
		return Point(x * k, y * k);
	}
	Point operator / (const double &k) const
	{
		return Point(x / k, y / k);
	}
	double operator % (const Point &a) const
	{
		return x * a.x + y * a.y;
	}
	double operator * (const Point &a) const
	{
		return x * a.y - y * a.x;
	}

	double sqrLen() const
	{
		return *this % *this;
	}
	double len() const
	{
		return sqrt(sqrLen());
	}

	Point ort() const
	{
		return Point(-y, x);
	}
	Point norm() const
	{
		return *this / len();
	}
};

bool intersectLines(Point A, Point a, Point B, Point b, Point &M)
{
	if (eq(a * b, 0)) return false;
	double y = ((A - B) * a) / (b * a);
	M = B + b * y;
	return true;
}

Point A, B, C;

bool solve(double R)
{
	Point A1 = A + (B - A).ort().norm() * R, a1 = B - A;
	Point B1 = B + (C - B).ort().norm() * R, b1 = C - B;
	Point C1 = C + (A - C).ort().norm() * R, c1 = A - C;

	Point I1, I2, I3;
	if (!intersectLines(A1, a1, B1, b1, I1) || !intersectLines(B1, b1, C1, c1, I2) || !intersectLines(C1, c1, A1, a1, I3)) throw;

	/*
	printf("R = %.5lf\n", R);
	I1.print();
	I2.print();
	I3.print();
	*/

	return (I1 - I2).len() >= 2 * R || (I1 - I3).len() >= 2 * R || (I2 - I3).len() >= 2 * R;
}


int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	A.scan();
	B.scan();
	C.scan();

	double S = (A - B) * (A - C);
	if (S < 0)
	{
		S *= -1;
		swap(B, C);
	}
	double P = (A - B).len() + (A - C).len() + (B - C).len();
	double l = 0, r = S / P;

//	printf("%.13lf\n", r);

	for (int it = 0; it < IT; it++)
	{
		double x = (l + r) / 2;
		if (solve(x))
			l = x;
		else
			r = x;
	}
	printf("%.12lf\n", l);

	return 0;
}

Measured memory_bytes: 256
import string
s = input()
k = int(input())
d=set()
for sp in string.ascii_lowercase:
  for i,sd in enumerate(s,start=0):
    if sp == sd:
      e=set()
      for l in range(1, 6):
        if i+l > len(s):
          break
        e.add(s[i:i+l])
      d=d|e
  if len(d) >= k:
    break

d=list(d)
d=sorted(d)
print(d[k-1])

Measured memory_bytes: 3772
from collections import deque
x, y, a, b, c = list(map(int, input().split()))
pl = list(map(int, input().split()))
ql = list(map(int, input().split()))
rl = list(map(int, input().split()))
pl.sort(reverse=True)
ql.sort(reverse=True)
rl.sort(reverse=True)


ans = 0
if x > a:
    ans += sum(pl)
    dif_x = x-a
    ans += rl[:dif_x]
    del rl[:dif_x]
    if y > b:
        ans += sum(ql)
        dif_y = y-b
        ans += sum(rl[:dif_y])
    else:
        qd = deque(ql)
        rd = deque(rl)
        for i in range(y):
            if qd and rd:
                if qd[0] > rd[0]:
                    ans += qd.popleft()
                else:
                    ans += rd.popleft()
            else:
                if qd:
                    ans += qd.popleft()
                else:
                    ans += rd.popleft()
else:
    if y > b:
        ans += sum(ql)
        dif_y = y-b
        ans += rl[:dif_y]
        del rl[:dif_y]
        pd = deque(pl)
        rd = deque(rl)
        for i in range(x):
            if pd and rd:
                if pd[0] > rd[0]:
                    ans += pd.popleft()
                else:
                    ans += rd.popleft()
            else:
                if pd:
                    ans += pd.popleft()
                else:
                    ans += rd.popleft()
    else:
        pd = deque(pl)
        qd = deque(ql)
        rd = deque(rl)
        c_x = 0
        c_y = 0
        for i in range(x+y):
            if pd and qd and rd:
                if (pd[0] == max([pd[0], qd[0], rd[0]]) and c_x < x) or (not c_y < y and pd[0] >= rd[0]):
                    ans += pd.popleft()
                    c_x += 1
                elif (qd[0] == max([pd[0], qd[0], rd[0]]) and c_y < y) or (not c_x < x and qd[0] >= rd[0]):
                    ans += qd.popleft()
                    c_y += 1
                else:
                    ans += rd.popleft()
            else:
                target = [-1, -1, -1]
                if pd:
                    target[0] = pd[0]
                if qd:
                    target[1] = qd[0]
                if rd:
                    target[2] = rd[0]
                t_max = max(target)
                ans += t_max
                idx = target.index(t_max)
                if idx == 0:
                    pd.popleft()
                elif idx == 1:
                    qd.popleft()
                else:
                    rd.popleft()

print(ans)


Measured memory_bytes: 110444
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    x,y,z = map(int, input().split())
    print(z,x,y)
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 5864
#include <stdio.h>
#include <string.h>

int main(void)
{
	int		 i, j, ans;
	char	pattern;


	for(i=1; i<10; i++){
		for(j=1; j<10; j++){
			ans = i*j;
			printf("%dx%d=%d\r\n",i,j,ans);
		}
	}
	
	return 0;	 
}

Measured memory_bytes: 524
#include<stdio.h>

int main(){
  int i, j, n, a[100], minj, temp, cnt=0;

  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &a[i]);

  for(i = 0; i < n; i++){
    minj = i;
    for(j = i; j < n; j++){
      if(a[j] < a[minj]) {
        minj = j;
      }
    }
    if(i != minj) cnt++;
    temp = a[i];
    a[i] = a[minj];
    a[minj] = temp;
  }
  
  for(i = 0; i < n; i++){
      printf("%d", a[i]);
      if(i < n-1) printf(" ");
      else printf("\n%d\n", cnt);
  }
  return 0;
}



Measured memory_bytes: 2084
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CMaximumVolume solver = new CMaximumVolume();
        solver.solve(1, in, out);
        out.close();
    }

    static class CMaximumVolume {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            double l = in.nextInt();
            out.printf("%.12f", (l / 3) * (l / 3) * (l / 3));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
int Begin[maxn],Next[maxn<<1],to[maxn<<1],w[maxn<<1],e;
int sum[3],d[maxn],flag,E,cnt;
inline void add_edge(int x,int y,int z){
	to[++e]=y;
	Next[e]=Begin[x];
	Begin[x]=e;
	w[e]=z;
}
void dfs(int x){
	sum[d[x]]++,++cnt;
	for(int i=Begin[x];i;i=Next[i]){
		++E;
		if(d[to[i]]==-1) d[to[i]]=(d[x]+w[i])%3,dfs(to[i]);
		else if(d[to[i]]!=(d[x]+w[i])%3) flag=1;
	}
}
int main(){
	int n=read(),m=read();
	while(m--){
		int x=read(),y=read();
		add_edge(x,y,1),add_edge(y,x,2);
	}
	REP(i,1,n) d[i]=-1;
	ll ans=0;
	REP(i,1,n) if(d[i]==-1){
		d[i]=0;
		dfs(i);
		if(flag) ans+=(ll)cnt*cnt;
		else if(sum[0] && sum[1] && sum[2])
			ans+=(ll)sum[0]*sum[1]+(ll)sum[1]*sum[2]+(ll)sum[2]*sum[0];
		else ans+=E/2;
		memset(sum,0,sizeof(sum));
		cnt=flag=E=0;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 6528
#include<stdio.h>
#include<stdlib.h>
struct node{
  int key;
  struct node *l, *r, *p;
};
typedef struct node *Node;
Node NIL, root;

Node find(Node u,int k){
  if(u==NIL||u->key==k)return u;
  if(u->key>k)find(u->l,k);
  else find(u->r,k);
}
 
void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
  z=malloc(sizeof(struct node));
  z->key=k;
  z->l=NIL;
  z->r=NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key)x=x->l;
    else x=x->r;
  }
  z->p=y;
 
  if(y==NIL) root =z;
  else if(z->key < y->key) y->l=z;
  else y->r=z;
}
void inorder(Node u){
  if(u->l!=NIL)inorder(u->l);
  printf(" %d",u->key);
  if(u->r!=NIL)inorder(u->r);
}
 
void preorder(Node u){
  if(u!=NIL)
    printf(" %d",u->key);
  if(u->l!=NIL)preorder(u->l);
  if(u->r!=NIL)preorder(u->r);
}
 
int main(){
  int m,i,x;
  char str[20];
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%s",str);
    if(str[0]=='f'){
      scanf("%d",&x);
      Node t = find(root,x);
      if(t!=NIL)printf("yes\n");
      else printf("no\n");
    }
    if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
      //  printf("aaaaaaaa\n");
    }
    else if(str[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    
  }
  return 0;
}

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

int main() {
  int K, S;
  cin >> K >> S;

  int num = 0;
  for(int x=0; x<=K; x++) {
    for(int y=0; y<=K; y++) {
      int z = S-x-y;
      if(0 <= z && z <= K) num += 1;
    }
  }

  cout << num << endl;
}

Measured memory_bytes: 256