akhauriyash/Code-Regression huggingface dataset:
package main

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

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var ans, cnt int

func main() {
	reader.Split(bufio.ScanWords)
	r, _ := strconv.Atoi(read())
	fmt.Println(3 * pow(r, 2))

}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] < h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


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

using namespace std;
typedef long long ll;
const int N=2e5+100;
int a[20100];
bool cmp(int x,int y){return x>y;}
int p[N],q[N],r[N];
int main()
{
   int x,y,a,b,c;
   cin>>x>>y>>a>>b>>c;
   for(int i=1;i<=a;i++) scanf("%d",&p[i]);
   for(int i=1;i<=b;i++) scanf("%d",&q[i]);
   for(int i=1;i<=c;i++) scanf("%d",&r[i]);
   sort(p+1,p+1+a,cmp);
   sort(q+1,q+1+b,cmp);
   sort(r+1,r+1+c,cmp);
   for(int i=x,j=1;i>=1&&j<=c;i--,j++){
     if(p[i]<r[j]) swap(p[i],r[j]);
   }
   sort(r+1,r+1+c,cmp);
   for(int i=y,j=1;i>=1&&j<=c;i--,j++)
      if(q[i]<r[j])swap(q[i],r[j]);
   ll ans=0;
   for(int i=1;i<=x;i++) ans+=p[i];
   for(int i=1;i<=y;i++) ans+=q[i];
   cout<<ans<<endl;
   return 0;
 }


Measured memory_bytes: 1408
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
p = readl()
for i in range(1, n + 1):
    p[i - 1] = p[i-1] - i
p.sort()
if n % 2 == 1:
    t = p[n // 2]
else:
    t = (p[n // 2] + p[n // 2 -1]) // 2
count = 0
for i in p:
    count += abs(i - t)
print(count)

Measured memory_bytes: 27548
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,k,i,h[200005];
  
  cin >> n >> k;
  for (i=0;i<n;i++) cin >> h[i];
  
  sort(h,h+n);
  
  ll ans=0;
  for (i=0;i+k<n;i++) ans+=h[i];
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>

using namespace std;

#define EPS 1e-5

double heron(double a,double b,double c){
      double s = (a + b + c) / 2;

      return sqrt(s * (s - a) * (s - b) * (s - c));
}

int main() {
    double x[3],y[3],xp,yp,a,b,c,d,e,f,sq,sqd,sqe,sqf;
    
    while(cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> xp >> yp){
        a = sqrt(pow((x[1] - x[0]),2) + pow((y[1] - y[0]),2));
        c = sqrt(pow((x[2] - x[0]),2) + pow((y[2] - y[0]),2));
        b = sqrt(pow((x[2] - x[1]),2) + pow((y[2] - y[1]),2));

        sq = heron (a,b,c);

        d = sqrt(pow((xp - x[0]),2) + pow((yp - y[0]),2));
        e = sqrt(pow((xp - x[1]),2) + pow((yp - y[1]),2));
        f = sqrt(pow((xp - x[2]),2) + pow((yp - y[2]),2));

        sqd = heron(d,e,a);
        sqe = heron(e,b,f);
        sqf = heron(f,c,d);
        /*
        if(sqd == 0 || sqe == 0 || sqf == 0){
             cout << "NO" << endl;
             return 0;
         }
        */
         if(abs(sq - (sqd + sqe + sqf)) < EPS){
            cout << "YES" << endl;
            
        }
        else {
            cout << "NO" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3028
#include<cstdio>
#include<algorithm>
#include<cstring>
typedef long long ll;
int m;

template<typename T>
inline void read(T &x){
    x = 0; char ch = getchar(); int f = 1;
    for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
    for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
    x *= f;
}

int main(){
    read(m);
    if(m >= 30) printf("Yes\n");
    else printf("No\n");
    return 0;
}
/*

*/

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

int n, A[25];

int solve(int i, int m)
{
    if (m == 0) return 1;
    if (i >= n) return 0;
    int res = solve(i+1, m) || solve(i+1, m-A[i]);
    return res;
}

int main()
{
    int q, M;
    cin >> n;
    for (int i=0; i<n; ++i) {
        cin >> A[i];
    }
    cin >> q;
    for (int i=0; i<q; ++i) {
        cin >> M;
        if (solve(0, M)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n;
	cin>>n;
	float a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	float s=0;
	sort(a,a+n);
	for(int i=1;i<n;i++)
	{
		s=(a[i]+a[i-1])/2;
		a[i]=s;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;

int main(){
    int n;cin>>n;
    int res[10][10];
    rep(i,10)rep(j,10)res[i][j]=0;
    rep(i,n+1){
        if(i==0)continue;
        string s= to_string(i);
        //if(s[0]-'0'>s[s.length()-1]-'0')res[s[s.length()-1]-'0'][s[0]-'0']++;
        res[s[0]-'0'][s[s.length()-1]-'0']++;
        
    }
    ll ans =0;
    rep(i,n+1){
        if(i==0)continue;
        string s =to_string(i);
        int f = s[0]-'0';
        int l =s[s.length()-1]-'0';
        ans+=res[l][f];
    }

    cout<<ans<<endl;

}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define PI 3.1415926535898

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

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    Yes(s < t);

    return 0;
}



Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$s = fgets(STDIN);
$aList = array_map('intval', explode(' ', $s));

$sum = 0;
$before = 0;
foreach ($aList as $a) {
	$l = 0;
	if ($before > $a) {
		$l = $before - $a;
	}

	$sum += $l;
	$before = $a + $l;
}

echo $sum . "\n";

Measured memory_bytes: 38272
import java.util.*;
import java.io.*;
import java.text.*;
import java.lang.*;
import java.math.*;

public class Main {

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);

			int n = in.nextInt();
			int ans = 0 ;

			if(n < 3)
				System.out.println(ans);
			else
				System.out.println(ans = n / 3);
	}
}
    

Measured memory_bytes: 21716
#include <fstream>
#include <iostream>
#include <string>
#define rep(i,n)for(int i=0;i<n;i++)

using namespace std;

int main()
{
    int n;
    string s,t;

    cin>>n>>s;
    rep(i,s.size())
    {
        char c=s[i];
        c+=n;
        if(int(c)>90)
        {
            c-=90;
            c=64+c;
        }
        t.push_back(c);
    }
    cout<<t<<endl;

    return 0;
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var sum = new long[N];
            var diff = new long[N];

            for (int i = 0; i < N; i++)
            {
                var s = i + A[i];
                var d = i - A[i];
                if (s < N) sum[s]++;
                if (0 <= d) diff[d]++;
            }

            Console.WriteLine(sum.Zip(diff, (s, d) => s * d).Sum());
        }
    }
}


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

int main() {
    int n, m, l;
    cin >> n >> m >> l;

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

    int b[100][100];
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> b[i][j];
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            long long c = 0;
            for (int k = 0; k < m; k++) {
                c += a[i][k] * b[k][j];
            }
            cout << c;
            if (j < l - 1) {
                cout << " ";
            } else {
                cout << endl;
            }
        }
    }

    return 0;
}


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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n, k; cin>>n>>k;
    vector<int> a(n);
    for(int i = 0; i<n; i++) cin>>a[i];
    sort(a.begin(), a.end());
    int sum = 0;
    for(int i = 0; i<k; i++) sum += a[i];
    cout<<sum<<"\n";
    return 0;
}

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

bool prime[1000007];
vector<int> p;

void prim(){

  for(int i = 2;i*i<=1000000;i++){
    if(!prime[i]){
        //p.push_back(i);

        for(int j = 2*i; j<=1000000; j+=i){
          prime[j] = true;
        }
    }
  }

  for(int i = 1;i<=1000000;i++){
    if(!prime[i])p.push_back(i);
  }
}
int main(){
  int n;
  cin >> n;
  
  prim();

  int l = lower_bound(p.begin(), p.end(), n )- p.begin();
  //cout << l << endl;
  cout << p[l] << endl;

  return 0;
}
    
  


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

int main()
{
	int N, M;
	scanf("%d %d", &N, &M);
	
	int A[N];
	int r;	//ループ用
	int sum = 0;		//得票数カウント用
	for(r=0; r<N; r++){
		scanf("%d", &A[r]);
		sum = sum + A[r];
	}
	
	int L;	//得票数加減チェック
	
	if(sum % 4*M == 0) L = sum /(4*M);
	else L = sum/(4*M) + 1;
	
	int cnt = 0; //選出可能な商品数チェック
	
	for(r=0; r<N; r++){
		if(A[r] >= L) cnt++;
	}
	
	if(cnt >= M) printf("Yes");
	else printf("No");
	
	return 0;
	
}



Measured memory_bytes: 128
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int A, B, M;cin>>A>>B>>M;
  vector<int> a(A), b(B);
  int ma=INF, mb=INF;
  rep(i, A){
    cin>>a[i];
    ma=min(ma, a[i]);
  }
  rep(i, B){
    cin>>b[i];
    mb=min(mb, b[i]);
  }
  int ans=ma+mb;
  rep(i, M){
    int x, y;cin>>x>>y;x--;y--;
    int c;cin>>c;
    int cost=a[x]+b[y]-c;
    ans=min(ans, cost);
  }
  cout<<ans<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define le 100005
#define la 102
#define ll long long int
using namespace std;
ll val[la], cost[la], dp[la][le], cap;
int len;
ll fnc(int i, int w){
  if(i == len) return 0;
  if(dp[i][w] != 0) return dp[i][w];
  else{
    ll pro = 0, pro1;
    if(w + cost[i] <= cap) pro = val[i] + fnc(i + 1, w + cost[i]);
    pro1 = fnc(i + 1, w);
    return dp[i][w] = max(pro, pro1);
  }
}
int main(){
  //freopen("input.txt", "r", stdin);
  scanf("%d %lld", &len, &cap);
  for(int i = 0; i < len; scanf("%lld %lld", &cost[i], &val[i]), i++);
  printf("%lld\n", fnc(0, 0));
  return 0;
}


Measured memory_bytes: 76416
#include <stdio.h>

int main(void){
  
  int a[3][3];
  int ans[3][3];
  int n;
  int b[105];
  
  for(int i=0;i<3;i++){
    scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
  }
  scanf("%d", &n);
  
  for(int i=0;i<n;i++){
    scanf("%d", &b[i]);
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      ans[i][j]=0;
      for(int k=0;k<n;k++){
        if(a[i][j]==b[k]){
          ans[i][j]=1;
        }
      }
    }
  }
  
  int hantei=0;
  
  for(int i=0;i<3;i++){
    if(ans[i][0]==1&&ans[i][1]==1&&ans[i][2]==1){
      hantei =1;
    }
    else if(ans[0][i]==1&&ans[1][i]==1&&ans[2][i]==1){
      hantei =1;
    }
  }
   if(ans[0][0]==1&&ans[1][1]==1&&ans[2][2]==1){
      hantei =1;
     //return 0;
    }
  else if(ans[0][2]==1&&ans[1][1]==1&&ans[2][0]==1){
    hantei = 1;
  }
  
  if(hantei==1){
  printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}



Measured memory_bytes: 1620
var t:array[0..100000]of longint;
    i,n,m,a,l,r:longint;
procedure add(x,y:longint);inline;
begin
  while x<=n do
  begin
    inc(t[x],y);
    inc(x,x and -x);
  end;
end;
function ask(x:longint):longint;inline;
var a:longint=0;
begin
  while x<>0 do
  begin
    inc(a,t[x]);
    dec(x,x and -x);
  end;
  exit(a);
end;
begin
  readln(n,m);
  for i:=1 to m do
  begin
    read(l,r);
    add(l,1);
    add(r+1,-1);
  end;
  for i:=1 to n do
    if ask(i)=m then
      inc(a);
  writeln(a);
end.

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 300005
#define ll long long
using namespace std;
int c[maxn];
int n,m;
struct node
{
    int l,r;
}a[maxn];
bool cmp(node a,node b)
{
    return a.r-a.l<b.r-b.l;
}
int lowbit(int x)
{
    return x&(-x);
}
void add(int i,int val)
{
    while(i<=m+1)
    {
        c[i]+=val;
        i+=lowbit(i);
    }
}
int sum(int i)
{
    int res=0;
    while(i>0)
    {
        res+=c[i];
        i-=lowbit(i);
    }
    return res;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i].l,&a[i].r);
    sort(a+1,a+n+1,cmp);
    int p=1;

    for(int i=1;i<=m;i++)
    {
        while(a[p].r-a[p].l+1<i&&p<=n)
        {  add(a[p].l+1,1);
            add(a[p].r+2,-1);

            p++;
        }

    ll ans=n-p+1;
    for(int j=0;j<=m;j+=i)
    {ans+=sum(j+1);

}
printf("%lld\n",ans);
    }
return 0;
    }


Measured memory_bytes: 3712
import sys
n = int(input())
INF = 10*n
dp = [INF]*(n+1)
dp[0] = 0
for i in range(1, n+1):
    tmp = dp[i-1] + 1
    for j in range(10):
        if i-6**j<0:
            break
        tmp = min(tmp, dp[i-6**j] + 1)
    for j in range(10):
        if i-9**j<0:
            break
        tmp = min(tmp, dp[i-9**j] + 1)
    dp[i] = tmp
print(dp[n])

Measured memory_bytes: 3828
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007

using namespace std;

int n, k;
string s;
void proc(int poz, int dir)
{
    if(poz == -1 || poz == n)
        return;
    if(dir == 0)
    {
        if(s[poz] == 'A')
        {
            s[poz] = 'B';
            proc(poz - 1, 1);
        }
        else
        {
            s[poz] = 'A';
            proc(poz + 1, 0);
        }
    }
    else
    {
        if(s[poz] == 'A')
        {
            s[poz] = 'B';
            proc(poz + 1, 0);
        }
        else
        {
            s[poz] = 'A';
            proc(poz - 1, 1);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    cin >> s;
    /*
    for(int i = 0; i < k; ++i)
    {
        proc(0, 0);
        cout << s << '\n';
    }
    return 0;
    */
    deque<int>d;
    for(int i = 1; i < n; i += 2)
        if(s[i] == 'A')
            s[i] = 'B';
        else
            s[i] = 'A';
    for(int i = 0; i < n; ++i)
        d.pb(i);
    for(int j = 1; j <= min(2 * n, k); ++j)
        if(s[d.front()] == 'A')
            s[d.front()] = 'B';
        else
        {
            int x = d.front();
            d.pop_front();
            if(n % 2 == 0)
                s[x] = 'B';
            else
                s[x] = 'A';
            d.pb(x);
        }
    k -= min(k, 2 * n);
    if(k % 2 == 1)
    {
        if(s[d.front()] == 'A')
            s[d.front()] = 'B';
        else
        {
            int x = d.front();
            d.pop_front();
            if(n % 2 == 0)
                s[x] = 'B';
            else
                s[x] = 'A';
            d.pb(x);
        }
    }
    for(int i = 0; i < n; ++i)
    {
        if(i & 1)
        {
            if(s[d[i]] == 'A')
                cout << "B";
            else
                cout << "A";
        }
        else
            cout << s[d[i]];
    }
    return 0;
}



Measured memory_bytes: 1560
#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
#define INF 1e18

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll n, x[100001], table[100001][20], L, q, a, b, ans;

void ub(int i){
	int pos = -1;
	int lo = i;
	int hi = n-1;
	int mid;
	while(lo<=hi){
		mid=(lo+hi)/2;
		if(x[mid]-x[i]<=L){
			pos=max(pos,mid);
			lo=mid+1;
		}
		else{
			hi=mid-1;
		}
	}
	table[i][0]=pos;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x[i];
	}
	cin >> L;
	for(int i = 0; i < n; i++){
		ub(i);
	}
	table[n][0]=n;
	for(int j = 1; j < 20; j++){
	for(int i = 0; i <= n; i++){
		
			table[i][j]=table[table[i][j-1]][j-1];
			
		}
	}
	cin >> q;
	while(q--){
		ans=0;
		cin >> a >> b;a--;b--;
		if(a>b){
			swap(a,b);
		}
		for(ll i = 19; i >= 0; i--){
			if(table[a][i]<b){
				ans+=1<<i;
				a=table[a][i];
			}
		}
		cout << ans+1 << '\n';
	}
	
	return 0;
}


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

// 1からnまでのxorを返す
ll f(ll n){
  //cout << "start:" << n << endl;
  if(n<1){
   // cout << "error:" << n << endl;
    return 0;
  }
	if(n==1) return 1;
	if(n==2) return 3;
	
  ll baf = n;
	ll d = 1;
	while(baf>0){
		baf >>= 1;
		d *= 2;
	}
	d /= 2;
	//cout << "d:" << d << endl;
 // cout << "next:" << n-d << endl;
  if(d*2-n==1) return 0;
    
  if((n-d)%2==0) return d + f(n-d);
  else return f(n-d);
}

int main(){
	
	ll a,b;
	cin >> a >> b;
	
	if(a==b){
		cout << a << endl;
		return 0;
	}
	
	if(a==0 || a==1){
		cout << f(b) << endl;
		return 0;
	}
	
	cout << (f(b) ^ f(a-1)) << endl;
 // cout << f(11) << endl;
	return 0;

}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>

using namespace std;

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

	sort(a, a + sizeof(a) / sizeof(a[0]));

	cout << a[N - 1] - a[0] << endl;
}


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

int main(){
  int n, a, b, ans=0;
  cin>>n>>a>>b;

  for(int i=1; i<=n; i++){
    int x=i, sum=0;
    while(x!=0){
      sum+=x%10;
      x/=10;
    }
    if(a<=sum && sum<=b)ans+=i;
  }

  cout<<ans<<endl;
}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define LOOP_IT(it,s) for(auto it=(s).begin();it!=(s).end();++it)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)


#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int mp[1000003]={};

int main(int argv, char* argc[])
{
    FASTIO

    ll n,cnt=0,ans=0;
    cin>>n;
    vll v(n);
    rep(i,n)
    {
        cin>>v[i];
        ++mp[v[i]];
    }

    rep(i,n)
    {
        cnt=0;
        --mp[v[i]];
        for(ll j=1;j*j<=v[i];++j)
        {
            if(v[i]%j) continue;

            ll x = j;
            ll y = v[i]/j;

                cnt+=mp[x];
            if(v[i]/j!=j)
            {
                cnt+=mp[y];
            }

        }
        ++mp[v[i]];
        ans+=(cnt==0);
    }

    cout<<ans;

    return 0;
}


Measured memory_bytes: 8620
require 'scanf'
while true
    height,width = STDIN.gets.scanf("%d %d")
    exit 0 if width==0 and height==0
    
    data=Array.new(height)
    for h in 0..height-1 do; data[h]=Array[width]; end

    for h in 0..height-1 do
        str = STDIN.gets.chomp
        for w in 0..width-1 do
            data[h][w] = str[w]
        end
    end

    x,y=0,0
    list = Array.new
    while true
        if data[y][x]=='.' then
            print x," ",y,"\n"
            break
        end
        if list.include?([x,y]) then
            print "LOOP\n" 
            break
        end

        list.push([x,y])
        x = x+1 if data[y][x]==">"
        x = x-1 if data[y][x]=="<"
        y = y+1 if data[y][x]=="v"
        y = y-1 if data[y][x]=="^"
    end
end

Measured memory_bytes: 6976
#include <iostream>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t H, W, N;
  cin >> H >> W >> N;
  unordered_set<int64_t> st;
  vector<pair<int64_t, int64_t>> pos(N);
  rep(i, N) {
    int64_t a, b;
    cin >> a >> b;
    a--;
    b--;
    pos[i] = {a, b};
    st.emplace(a << 31 | b);
  }

  vector<int64_t> answer(10, 0);
  answer[0] = (H - 2) * (W - 2);
  rep(i, N) {
    int64_t y = pos[i].first;
    int64_t x = pos[i].second;
    for (int qy = -1; qy <= 1; ++qy) {
      for (int qx = -1; qx <= 1; ++qx) {
        int count = 0;
        bool add_flag = true;
        for (int py = -1; py <= 1 && add_flag; ++py) {
          for (int px = -1; px <= 1 && add_flag; ++px) {
            int64_t sx = x + px + qx;
            int64_t sy = y + py + qy;
            if (sx < 0 || W <= sx || sy < 0 || H <= sy) {
              add_flag = false;
              break;
            }
            // cout << "sx=" << sx << " sy=" << sy << endl;
            if (st.count(sy << 31 | sx)) {
              count++;
            }
          }
        }
        if (add_flag) answer[count]++;
      }
    }
  }

  for (int i = 1; i < 10; ++i) {
    answer[i] /= i;
    answer[0] -= answer[i];
  }
  cout << answer[0] << endl;
  for (int i = 1; i < 10; ++i) cout << answer[i] << endl;
  return 0;
}


Measured memory_bytes: 5924
#include<bits/stdc++.h>
using namespace std;
int a[4][4];
int n;
int x;
int b[4][4];
int main()
{
    memset(b,-1,sizeof(b));
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
            cin>>a[i][j];
        }
    }
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        for(int j=1;j<=3;j++)
        {
            for(int k=1;k<=3;k++)
            {
                if(x==a[j][k])
                {
                    b[j][k]=x;
                }
            }
        }
    }
    for(int i=1;i<=3;i++)
    {
        if(b[i][1]>=0&&b[i][2]>=0&&b[i][3]>=0)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        if(b[1][i]>=0&&b[2][i]>=0&&b[3][i]>=0)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    if(b[1][1]>=0&&b[2][2]>=0&&b[3][3]>=0)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    if(b[1][3]>=0&&b[2][2]>=0&&b[3][1]>=0)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input=lambda: sys.stdin.readline().rstrip()
A=input()
B=input()
C=input()

a,b,c=len(A),len(B),len(C)

def f(X,Y):
  XY=[True]*(10**4)
  x,y=len(X),len(Y)
  for i in range(5000-y+1,5000+x):
    ret=True
    if i<=5000:
      for j in range(min(x,y+i-5000)):
        if X[j]=="?" or Y[j-i+5000]=="?" or X[j]==Y[j-i+5000]:
          continue
        else:
          ret=False
    else:
      for j in range(min(y,x-i+5000)):
        if Y[j]=="?" or X[j+i-5000]=="?" or Y[j]==X[j+i-5000]:
          continue
        else:
          ret=False
    XY[i]=ret
  return XY
AB=f(A,B)
BC=f(B,C)
AC=f(A,C)
ans=a+b+c
for i in range(5000-b-c,5000+a+c):
  if AB[i]:
    for j in range(5000-b-c,5000+a+b):
      if -4000<=j-i<=4000:
        if AC[j] and BC[j-i+5000]:
          l=min(5000,i,j)
          r=max(i+b,j+c,5000+a)
          ans=min(ans,r-l)
      else:
        if AC[j]:
          l=min(5000,i,j)
          r=max(i+b,j+c,5000+a)
          ans=min(ans,r-l)
print(ans)


Measured memory_bytes: 54940
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

s=input().rstrip()
n=len(s)
beki=[0 for i in range(n+1)]
beki[0]=1
for i in range(n):
    beki[i+1]=(beki[i]*10)%13

u=[[0 for i in range(13)] for j in range(n+1)]
u[0][0]=1
s=list(reversed(s))
for i in range(n):
    #z=i%3
    for j in range(13):
        if s[i]!="?":
            u[i+1][(j+beki[i]*int(s[i]))%13]+=u[i][j]%mod
        else:
            for k in range(10):
                u[i+1][(j+beki[i]*k)%13]+=u[i][j]%mod
#print(u)
print(u[n][5]%mod)

Measured memory_bytes: 71472
# -*- coding:utf-8 -*-
import sys

a,b = 1,1
l = range(1,10)
for i in l:
    for k in l:
        result = i*k
        print(i,end="")
        print('x',end="")
        print(k,end="")
        print('=',end="")
        print(i*k)

Measured memory_bytes: 7348
#include<cstdio>
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cctype>
#define MAX 2100000000
#define rep(i,a) for(i=0;i<a;i++)
#define rep2(i,a) for(i=0;i<=a;i++)
using namespace std;
int dp[1001][1001];
int main(void)
{
	int i,j,n,m;
	int tenki[1001],kyori[1001];
	cin>>n>>m;
	rep(i,n) cin>>kyori[i];
	rep(i,m) cin>>tenki[i];
	rep2(i,m)rep2(j,n)dp[i][j]=MAX;
	dp[0][0]=0;
	rep(i,m)rep2(j,n) {
		dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
		if(j<=n)dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+kyori[j]*tenki[i]);
	}
	//rep2(i,m){cout<<endl;rep2(j,n) cout<<" "<<dp[i][j];}
	int mini=MAX;
	rep2(i,m) mini=min(dp[i][n],mini);
	cout<<mini<<endl;
	return 0;
}

Measured memory_bytes: 7028
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b)*b;
}
ll prime(ll x) {
	ll i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}



int main() {
	ll A, B;
	cin >> A >> B;
	char c[A + 10][B + 10];
	for (ll i = 0; i < A; i++) {
		for (ll j = 0; j < B; j++) {
			cin >> c[i][j];
		}
	}
	string ans = "Yes";
  for (ll i = 0; i < A; i++) {
		for (ll j = 0; j < B; j++) {
          	ll cnt=0;
			for (ll k = 0; k < 4; k++) {
				ll x = i + dx[k];
				ll y = j + dy[k];
              	
				if (c[i][j] == '#'&&c[i][j] != c[x][y]) {
					cnt++;
                  	if(cnt==4)
                      ans="No";
                }
            }
        }
  }
	cout << ans << endl;
}



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

#define pb push_back
#define fr(i, n) for(int i = 0; i < n; i++)
#define frr(i, n) for(int i = 1; i <= n; i++)

#define dbg(x) cout << #x << " = " << x << endl
#define all(x) x.begin(),x.end()
#define ms(x, i) memset(x, i, sizeof(x))

#define p(x) cout << x << "\n"
#define pv(x) fr(i, x.size()) cout << x[i] << " \n"[i==x.size()-1]

#define f first
#define s second

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f;

int main() {
    fastio;

    ll n, k;
    cin >> n >> k;

    pll v[n];
    fr(i, n) cin >> v[i].f >> v[i].s;
    sort(v, v+n);

    int i = 0;
    while (1) {
        if (k <= v[i].s) {
            p(v[i].f);
            return 0;
        }
        k -= v[i].s;
        i++;
    }
}


Measured memory_bytes: 1792
import Control.Applicative ((<$>))
import Control.Monad (unless)
import Text.Printf (printf)

expectation :: Integral a => a -> [a] -> Double
expectation n ps
    | elem 1 ps = 0.0
    | otherwise = fromIntegral n / 2.0

main :: IO ()
main = do
    (n : _) <- map read . words <$> getLine
    unless (n == 0) $ do
        ps <- map read . words <$> getLine
        printf "%.10f\n" $ expectation n ps
        main

Measured memory_bytes: 4100
let find_price s =
  let price = 700 in
  let price0 = 
    if s.[0] = 'o'
    then price + 100
    else price
    in
    let price1 =
      if s.[1] = 'o'
      then price0 + 100
      else price0
    in
    if s.[2] = 'o'
    then price1 + 100
    else price1

let () =
  let s = Scanf.scanf "%s" (fun x -> x) in
  let ans = find_price s in
  Printf.printf "%d\n" ans


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>

int H,W,map[100][100],dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

void solve(int x,int y) {
	int ch=map[x][y];
	map[x][y]=0;
	for(int i=0;i<4;i++) {
		int nx=x+dx[i],ny=y+dy[i];
		if(0<=nx&&nx<W&&0<=ny&&ny<H&&map[nx][ny]==ch) solve(nx,ny);
	}
}

int main() {
	while(scanf("%d %d",&H,&W),H!=0&&W!=0) {
		getchar();
		memset(map,0,sizeof(map));
		for(int j=0;j<H;j++) {
			for(int i=0;i<W;i++) {
				map[i][j]=getchar();
			}
			getchar();
		}
		int ans=0;
		for(int j=0;j<H;j++) {
			for(int i=0;i<W;i++) {
				if(map[i][j]) {
					solve(i,j);
					ans++;
				}
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1544
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	static int[] fy = { -2, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 2 };
	static int[] fx = { -1, 0, 1, -2, 2, -2, 2, -2, 2, -1, 0, 1 };

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int kx = scanner.nextInt();
			int ky = scanner.nextInt();
			if (ky == 0 && kx == 0)
				break;
			int n = scanner.nextInt();
			int[][] num = new int[n][2];
			for (int i = 0; i < n; i++) {
				num[i][0] = scanner.nextInt();
				num[i][1] = scanner.nextInt();
			}
			Deque<int[]> deque = new ArrayDeque<int[]>();
			deque.offer(new int[] { ky, kx });
			boolean flag = true;
			loop: for (int i = 0; i < n; i++) {
				int size = deque.size();
				Deque<int[]> dequetmp = new ArrayDeque<int[]>();
				while (size-- > 0) {
					int[] m = deque.pop();
					slove(m, num[i], dequetmp);
				}
				if (dequetmp.isEmpty()) {
					flag = false;
					break loop;
				}
				deque = dequetmp;
			}
			System.out.println(flag ? "OK" : "NA");
		}

	}

	private static void slove(int[] m, int[] num, Deque<int[]> dequetmp) {
		boolean[][] map = new boolean[14][14];
		for (int i = 1; i < 4; i++) {
			for (int j = 1; j < 4; j++) {
				int y = num[1] + i;
				int x = num[0] + j;
				if (2 <= y && y <= 12 && 2 <= x && x <= 12)
					map[y][x] = true;
			}
		}
		for (int i = 0; i < fy.length; i++) {
			int py = m[0] + fy[i] + 2;
			int px = m[1] + fx[i] + 2;
			if (map[py][px]) {
				py -= 2;
				px -= 2;
				boolean flag = true;
				for (int[] t : dequetmp) {
					if (t[0] == py && t[1] == px) {
						flag = false;
						break;
					}
				}
				if (flag) {
					dequetmp.push(new int[] { py, px });
				}
			}
		}
	}
}

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

int M, N;
vector<int> objects;
int memo[1<<11][1<<11];

int to_int(string s){
    int res = 0;
    for(int i=0; i<s.size(); i++){
        res = res*2 + (s[i] == '1');
    }
    return res;
}

int dfs(int s, int ys){
    if(memo[s][ys] >= 0) return memo[s][ys];
    
    int& res = memo[s][ys];
    int cnt = 0;
    for(auto v: objects) if((v&s) == ys) cnt++;
    if(cnt < 2)
        return res = 0;
    
    res = M;
    for(int i=0; i<M; i++) if((s>>i&1) == 0){
        res = min(res, max(dfs(s|(1<<i), ys)+1, dfs(s|(1<<i), ys|(1<<i))+1));
    }
    return res;
}

void solve(){
    memset(memo, -1, sizeof(memo));
    cout << dfs(0, 0) << endl;
}

int main(){
    while(cin >> M >> N, M|N){
        objects.resize(N);
        string s;
        for(int i=0; i<N; i++){
            cin >> s; objects[i] = to_int(s);
        }
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 19464
S = input()
T = input()

cnt = 0
best = 0
for i in range(len(S)-len(T)+1):
    cnt = 0
    for j in range(len(T)):
        if S[i+j] == T[j]:
            cnt += 1
    if cnt > best:
        best = cnt

print(len(T) - best)

Measured memory_bytes: 67636
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		int ans = a + b;
		ans = Math.max(ans, a-b);
		ans = Math.max(ans, a*b);
		System.out.println(ans);
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21204
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>

int main(void){
    std::string a,b,c;
    std::cin >> a >> b >> c;

    if(a[a.size()-1] == b[0]){
        if(b[b.size()-1] == c[0]){
            std::cout << "YES";
            return 0;
        }
        else{
            std::cout << "NO";
            return 0;
        }
    }
    else{
        std::cout << "NO";
        return 0;
    }
}




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

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)

using namespace std;

using ll = long long;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}

int main() {

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

    constexpr int L_MAX = 100000;

    int N;
    cin >> N;
    vector<int> V(N), W(N);
    FOR(i, 1, N + 1) cin >> V[i] >> W[i];

    int N_upper = min((1 << 9) - 1, N);
    vector<vector<ll>> dp(N_upper + 1, vector<ll>(L_MAX + 1));
    FOR(i, 1, N_upper + 1) {
        FOR(j, 1, L_MAX + 1) {
            dp[i][j] = dp[i / 2][j];
            if (j >= W[i]) {
                amax(dp[i][j], dp[i / 2][j - W[i]] + V[i]);
            }
        }
    }

    int Q;
    cin >> Q;
    vector<int> lowers(9);
    REP(_, Q) {
        int v, L;
        cin >> v >> L;

        int H = 0;
        while (v > N_upper) {
            lowers[H++] = v;
            v /= 2;
        }
        ll result = 0;
        REP(bit, 1 << H) {
            ll sum_V = 0;
            ll sum_W = 0;
            REP(i, H) {
                if (bit & (1 << i)) {
                    sum_V += V[lowers[i]];
                    sum_W += W[lowers[i]];
                }
            }
            if (sum_W <= L) {
                amax(result, sum_V + dp[v][L - sum_W]);
            }
        }
        cout << result << '\n';
    }
    cout << flush;

    return 0;
}


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

bool flags[10];

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int N, K;
    cin >> N >> K;
    REP(i, K) {
    	int b;
    	cin >> b;
    	flags[b] = 1;
    }
    int ans;
    FOR(i, N, 20000000) {
    	string s = to_string(i);
    	trav(c, s) {
    		if (flags[c - '0']) {
    			goto fail;
    		}
    	}
    	succ:
    	ans = i;
    	break;
    	fail:;
    }
    cout << ans << endl;
}

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

long long nCr(const long long n, long long r) {
    if (n == 0) { return 0; }
    if (r == 0) { return 1; }
    if (r == 1) { return n; }
    if (n == r) { return 1; }

    if (r > n / 2) { r = n / 2; }

    long long result = 1;
    for (long long i = 1; i <= r; i++) { result *= (n - i + 1) / i; }

    return (result);
}

int main() {
    //
    long long num;
    string str;
    long long kekka = 0;

    map<string, long long> m;

    cin >> num;

    for (long long i = 0; i < num; i++) {
        cin >> str;
        sort(str.begin(), str.end());
        m[str]++;
    }

    for (auto itr : m) {
        if (itr.second < 2) continue;
        long long tmp = itr.second-1;
        kekka += tmp * (tmp + 1) / 2;
    }

    cout << kekka;
}

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

int main() {
    int h, w; cin >> h >> w;
    vector<string> a(h);
    vector<bool> hb(h);
    vector<bool> wb(w);
    rep(i, h) {
            cin >> a.at(i);
    }

    rep(i, h) {
        rep(j, a.at(i).size()) {
            if (a.at(i).at(j) == '#') {
                wb.at(j) = true;
                hb.at(i) = true;
            }
        }
    }

    rep(i, h) {
        bool flg = false;
        rep(j, a.at(i).size()) {
            if (hb.at(i) == true && wb.at(j) == true) {
                cout << a.at(i).at(j);
                flg = true;
            }
        }
        if (flg)
            cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var s = o.a(1);
  var a = +(s[0]+s[1]);
  var b = +(s[2]+s[3]);
  var n = "NA";
  if((a > 12 || a === 0) && (b > 12 || b === 0))return n;
  if(a <= 12 && b <= 12 & a > 0 && b > 0)return "AMBIGUOUS";
  if(a <= 12 && a > 0)return "MMYY";
  return "YYMM"
}

Measured memory_bytes: 21064
s = input()
q = int(input())
zengo = True
mae = []
usiro = []
for i in range(q):
  qi = input()
  if qi[0] == "1":
    if zengo:
      zengo = False
    else:
      zengo = True
  else:
    t, f, c = qi.split() 
    if zengo:
      if f == "1":
        mae.append(c)
      else:
        usiro.append(c)
    else:
      if f == "1":
        usiro.append(c)
      else:
        mae.append(c)
mae = mae[::-1]
s = ''.join(mae) + s + ''.join(usiro)
if zengo:
  print(s)
else:
  print(s[::-1])

Measured memory_bytes: 6128