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

using namespace std;

void solve()
{
    int dp[3][3];

    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>dp[i][j];
        }
    }

    int n;
    cin>>n;

    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];

    for(int i=0;i<n;i++)
    {
        for(int x=0;x<3;x++)
        {
           for(int y=0;y<3;y++)
           {
               if(dp[x][y]==arr[i])
                dp[x][y]=0;
           }
        }
    }

    for(int i=0;i<3;i++)
    {
        if(dp[i][0]==0 && dp[i][1]==0 && dp[i][2]==0)
        {
            cout<<"Yes\n";
            return;
        }
    }

    for(int i=0;i<3;i++)
    {
        if(dp[0][i]==0 && dp[1][i]==0 && dp[2][i]==0)
        {
            cout<<"Yes\n";
            return;
        }
    }

    // diagonal matching

    if(dp[0][0]==0 && dp[1][1]==0 && dp[2][2]==0)
    {
        cout<<"Yes\n";
        return ;
    }

    if(dp[0][2]==0 && dp[1][1]==0 && dp[2][0]==0)
    {
        cout<<"Yes\n";
        return;
    }

    cout<<"No\n";
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

        solve();

    return 0;
}


Measured memory_bytes: 3652
a =gets.chomp.to_i

arr = []
a.times do 
 arr << gets.chomp
end

unless arr.length == arr.uniq.length
  puts "No"
  exit 0
end

before = ""
arr.each do |s|
  if before == ""
    before = s
    next
  end
  unless before[-1] == s[0]
    puts "No"
    exit 0
  end
  before = s
end

puts "Yes"


Measured memory_bytes: 1788
fun main(args: Array<String>) {
    val (aplusone, b, c, d) = readLine()!!.split(" ").map{ it.toLong()}
    val a = aplusone - 1
    val lcm = lcm(c, d)
    println(b - (b / c) - (b / d) + (b / lcm) - (a - (a / c) - (a / d) + (a / lcm)))
}
fun gcd(a: Long, b: Long): Long {
    if (b == 0L) return a
    return if (a < b)gcd(b, a) else gcd(b, a % b)
}
fun lcm(a: Long, b: Long): Long {
    return a * b / gcd(a, b)
}


Measured memory_bytes: 37748
#include<stdio.h>

int main(void) {
  int a, b;
  int i = 0;
  scanf("%d %d", &a, &b);
  for ( i; ; i++ ) {
    if ( i >= ((double)(b-1) / (a-1)) ) { break; }
  }
  printf("%d\n", i);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];
//平方根　= sqrt



int main() {

  vector<int> x(5);
  rep(i,5) cin >> x[i];
  rep(i,5) {
    if (x[i] == 0) cout << i+1 << endl;
  }

  return 0;
}


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

int main(){
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    s = 'Z' + s;
    ve<int> ruiseki(n+1);
    ruiseki[0] = 0;
    ruiseki[1] = 0;
    rep(i,n){
        ruiseki[i+1] = ruiseki[i];
        if(s[i] == 'A' && s[i+1] == 'C') ruiseki[i+1]++;
    }
    rep(Q,q){
        int l,r;
        cin >> l >> r;
        int ans = ruiseki[r] - ruiseki[l];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3884
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


ll n;
ll a,b,c,d;

map<ll,ll>dp;
ll resi(ll x){
    //cout << x << "\n";
    if(x == 0)return 0;
    if(x == 1)return d;
    if(dp.find(x) != dp.end())return dp[x];
    ll d2,g2,d3,g3,d5,g5;
    d2 = (x/2)*2; g2 = ((x+1)/2)*2;
    d3 = (x/3)*3; g3 = ((x+2)/3)*3;
    d5 = (x/5)*5; g5 = ((x+4)/5)*5;
    ll sol = 1e18;
    if(x <= sol/d)sol = x*d;
    sol = min(sol, llabs(d2 - x) * d + resi(d2/2) + a);
    sol = min(sol, llabs(g2 - x) * d + resi(g2/2) + a);
    sol = min(sol, llabs(d3 - x) * d + resi(d3/3) + b);
    sol = min(sol, llabs(g3 - x) * d + resi(g3/3) + b);
    sol = min(sol, llabs(d5 - x) * d + resi(d5/5) + c);
    sol = min(sol, llabs(g5 - x) * d + resi(g5/5) + c);
    dp[x] = sol;
    return dp[x];

}


void solve(){
    cin >> n >> a >> b >> c >> d;
    dp.clear();
    cout << resi(n) << "\n";

}


int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    int tt; cin >> tt; while(tt--)solve();
    return 0;
}


Measured memory_bytes: 4400
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int x, a; cin >> x >> a;
    cout << (x < a ? 0 : 10);
}


Measured memory_bytes: 256
import itertools
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
s=list(itertools.permutations(range(1,n+1)))
a=b=-1
for i in range(len(s)):
  if p==list(s[i]):
    a=i
  if q==list(s[i]):
    b=i
  if a>=0 and b>=0:
    break
print(abs(a-b))

Measured memory_bytes: 46832
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    ll nA = A, nB = B;
    nA = max(0LL, A - K);
    if(nA == 0LL) {
        K -= A;
        nB = max(0LL, B - K);
    }
    cout << nA << " " << nB << endl;
    return 0;
}

Measured memory_bytes: 256
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from itertools import product

H,W = II()
s = [list(map(str, input())) for _ in range(H)]

def neighbor(i,j):
    if H==1:
        x = []
    else:
        if i==0:
            x = [1]
        elif i==H-1:
            x = [H-2]
        else:
            x = [i-1,i+1]
    if W==1:
        y = []
    else:
        if j==0:
            y = [1]
        elif j==W-1:
            y = [W-2]
        else:
            y = [j-1,j+1]
    return  list(product(x,[j])) + list(product([i],y))  

for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            flag = True
            a = neighbor(i,j)
            for k in a:
                if s[k[0]][k[1]] == '#':
                    flag = False
                    break
            if flag:
                print('No')
                exit()

print('Yes')

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

const int maxn = 1e5+10;
int a[maxn];
int b[maxn];
int n;

int c[maxn],tmp[maxn];
long long ans;

void Merge(int l,int m,int r)
{
    int i = l;
    int j = m + 1;
    int k = l;
    while(i <= m && j <= r)
    {
        if(c[i] > c[j])
        {
            tmp[k++] = c[j++];
            ans += m - i + 1;
        }
        else
        {
            tmp[k++] = c[i++];
        }
    }
       while(i <= m) tmp[k++] = c[i++];
    while(j <= r) tmp[k++] = c[j++];
    for(int i=l;i<=r;i++)
        c[i] = tmp[i];
}
 
void Merge_sort(int l,int r)
{
    if(l < r)
    {
        int m = (l + r) >> 1;
        Merge_sort(l,m);
        Merge_sort(m+1,r);
        Merge(l,m,r);
    }
}

int lowbit(int x){
	return x&(-x);
}

void add(int x,int d){
	while(x<=n){
		b[x]+=d;
		x+=lowbit(x);
	}
}


int sum(int x){
	int res = 0;
	while(x){
		res+=b[x];
		x-=lowbit(x);
	}
	return res;
}

bool cc(int d){
	memset(b,0,sizeof(b));
for(int i=1;i<=n;i++){
	if(a[i]>=d)add(i,1);
	else add(i,-1);
}
	for(int i=1;i<=n;i++)c[i] = sum(i);
		ans = 0;
		for(int i=1;i<=n;i++){
			if(c[i]<0)ans++;
		}
		Merge_sort(1,n);
		long long num = 1LL*n*(n+1)/2 - ans;
		//printf("%lld %lld\n",num,ans);
		return num>=ans;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	int ub = 1e9;
	int lb = 0;
		while(ub-lb>1){
			int mid = lb+(ub-lb)/2;
			if(cc(mid))lb = mid;
			else ub = mid;
		}
		if(cc(lb+1))lb++;
		printf("%d\n",lb);
	return 0;
}

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

int main(void)
{
    int a = 100000, n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        a = a * 1.05;
        if (a % 1000 != 0)
            a += (1000 - a % 1000);
    }
    cout << a << endl;
    return 0;
}







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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll N, K; cin >> N >> K;
	vll A(N), F(N); cin >> A >> F;

	sort(begin(A), end(A));
	sort(rbegin(F), rend(F));
	ll ng = -1, ok = 1e15;
	while (abs(ng - ok) > 1) {
		ll x = (ng + ok) >> 1;
		ll s = 0;
		for (int i = 0; i < N; i++) {
			s += max(0ll, A[i] - x/F[i]);
		}
		if (s <= K) ok = x;
		else ng = x;
	}
	cout << ok << endl;		
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		int[] A = new int[N];
		
		String[] S = br.readLine().split(" ");
		for(int i = 0; i < N ; i++) {
			A[i] = Integer.parseInt(S[i]);
		}
		
		long[][] taro = new long[N][N];
		long[][] jiro = new long[N][N];
		
		for(int i = 0; i < N; i++) {
			taro[i][i] = A[i];
			jiro[i][i] = -A[i];
		}
		
		
		for(int i = 0; i < N; i++) {
			int diagnol = i+1;
			int start = 0;
			int end = start + diagnol;
			while(end < N) {
				
				taro[start][end] = Math.max(A[start] + jiro[start+1][end],
										   A[end] + jiro[start][end-1]);
				
				jiro[start][end] = Math.min(-A[start] + taro[start+1][end],
						   -A[end] + taro[start][end-1]);
				start++;
				end = start + diagnol;
			}
		}
		
		System.out.println(taro[0][N-1]);
	}
}


Measured memory_bytes: 170848
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s;cin>>s;bool p=true;
    for(int i=0;i<s.size();i++)
    if(i%2)
        {if(s[i]=='R')p=false;}
    else
        {if(s[i]=='L')p=false;}
        cout<<(p?"Yes":"No");
    return 0;
}


Measured memory_bytes: 256
program main
  implicit none
  integer(8) i, j, N, L, ans,x
  !read(*, *) (L(i), i = 1,N)
  read(*, *)N, L
  if (L < 0 .and. L+N-1 > 0) then
    i = L
    j = L+N-1
  elseif (L < 0) then
    i = L
    j = L+N-2
  else
    i = L+1
    j = L+N-1
  end if
      ans = 0
    do x = i,j
      ans = ans + x
    end do

  write(*, *) ans
end program main


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

stack<int>st;
string s;
int n;
int before , after ;

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

for(int i=0;i<n;i++){

    if( s[i]=='(' )st.push( '(' );
    else{
        if( st.empty() ){
                before++;
        }else{
                st.pop();
        }
        }
}

while( !st.empty() ){ st.pop(); after++; }

while( before-- )cout<<'(';
cout<<s;
while(  after-- )cout<<')';
cout<<endl;

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.exceptions(cin.failbit)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define endl '\n'  
#define show(a) for(auto i:a) cout<<i<<" ";cout<<endl
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< int , int > mypair;
typedef priority_queue <int> max_heap;
typedef priority_queue <mypair, vector<mypair>, greater<mypair> > min_heap;
const int mod=1000000007;
const int inf=1e9+100;
const int N=2e6+10;

int main()
{
	boost;
	int n;
	cin>>n;
	ll a[n];
	for(auto &i:a)  cin>>i;
	ll b[n];
	for(int i=0;i<n;i++) b[i]=a[i];
	ll ans=1e18;
	for(int i=n-2;i>=0;i--) b[i]+=b[i+1];
	for(int i=1;i<n;i++) a[i]+=a[i-1];	
	for(int i=0;i<(n-1);i++)
	{
		ans=min(abs(a[i]-b[i+1]),ans);
		//check(abs(a[i]-b[i+1]));
	}
	//check(ans);
	ans=min({ans,b[0],a[n-1]});
	cout<<ans;

	return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;
import java.util.Arrays;
 
public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        String s = stdIn.next();
        char c[] = s.toCharArray();
        Arrays.sort(c);
        
        if(c[0] == c[1] && c[2] == c[3] && c[0] != c[2]){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

signed main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  int two = 0; //2の倍数
  int yon = 0; //4の倍数
  for( int i = 0; i < N; i++ ){
    cin >> A.at(i);
    if( A.at(i) % 4 == 0 ) yon++;
    else if( A.at(i) % 2 == 0 ) two++;
  }
  
  int ans = two / 2 + yon;
  if( ans >= N/2 ) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int x, n, p;
bool bl[110];
int ans;

signed main() {
	cin >> x >> n;
	for (int i = 0; i < n; i++) {
		cin >> p;
		bl[p] = true;
	}
	for (int i = 1; i <= 100; i++) {
		if (!bl[i] && abs(x - i) < abs(x - ans))ans = i;
	}
	if (abs(101 - x) < abs(ans - x))ans = 101;
	cout << ans << endl;
}

Measured memory_bytes: 3620
package main

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

var A int
var B int
var C int

func main() {
	A = nextInt()
	B = nextInt()
	C = nextInt()
	num := B / A
	if num > C {
		fmt.Printf("%v", C)
		return
	}
	fmt.Printf("%v", num)
	return
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func MaxIn2Values(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
using pii = pair<int, int>;
static const int INF = 1000000000;

int solve(string a, string b){
	const int n = a.size();
	vector<int> l(n), r(n);
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			if(b[(i + j) % n] == '1'){
				l[i] = j;
				break;
			}
		}
		for(int j = 0; j < n; ++j){
			if(b[(i - j + n) % n] == '1'){
				r[i] = j;
				break;
			}
		}
	}
	int answer = INF;
	for(int i = 0; i < n; ++i){
		int moves = i;
		vector<pii> rl;
		for(int j = 0; j < n; ++j){
			if(a[j] != b[(j + i) % n]){
				++moves;
				rl.emplace_back(-r[j], l[j]);
			}
		}
		sort(rl.begin(), rl.end());
		int lmost = i;
		for(const auto& p : rl){
			answer = min(answer, moves + (p.first * -2) + (lmost - i) * 2);
			lmost = max(lmost, p.second);
		}
		answer = min(answer, moves + (lmost - i) * 2);
	}
	return answer;
}

int main(){
	ios_base::sync_with_stdio(false);
	string a, b;
	cin >> a >> b;
	if(count(b.begin(), b.end(), '1') == 0 && a != b){
		cout << -1 << endl;
		return 0;
	}
	int answer = solve(a, b);
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	answer = min(answer, solve(a, b));
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 384
require 'pp'
require 'set'

w, h, x, y = gets.chomp!.split(" ").map(&:to_i)

=begin
if w == h 
    xx = w.to_f / 2
    yy = h.to_f
    d = 1
elsif w < h
    xx = [w - x, x].min.to_f
    yy = h.to_f
    d = 0
else # h < w
    xx = w.to_f
    yy = [h - y, y].min.to_f
    d = 0
end
=end

d = (x * 2 == w && y * 2 == h) ? 1 : 0
puts "#{sprintf("%.10f", w * h / 2.0)} #{d}"


Measured memory_bytes: 2428
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;



int main() {
	int H,W;cin>>H>>W;
	long long int ans;
	if (H % 3 == 0 || W % 3 == 0) {
		ans=0;
	}
	else {
		ans=min(H,W);
		for (int l = W / 3; l <= W / 3 + 1; ++l) {
			long long int a=l*H;
			long long int b=(W-l)*(H/2);
			long long int c=(W-l)*((H+1)/2);
			vector<long long int>v{ a,b,c };
			sort(v.begin(),v.end());
			ans=min(ans,v[2]-v[0]);
		}
		swap(H,W);
		for (int l = W / 3; l <= W / 3 + 1; ++l) {
			long long int a = l*H;
			long long int b = (W - l)*(H / 2);
			long long int c = (W - l)*((H + 1) / 2);
			vector<long long int>v{ a,b,c };
			sort(v.begin(), v.end());
			ans = min(ans, v[2]-v[0]);
		}
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll l,r,ans;
  cin>>l>>r;
  if(r-l>2019)
  {
    ans=0;
  }
  else
  {
    ll i,j;
    ans=2020;
    int f=0;
    for(i=l;i<r;i++)
    {
      for(j=i+1;j<=r;j++)
      {
     	if((i*j)%2019 <ans) ans=(i*j)%2019;
        if(ans==0) {f=1;break;}
      }
      if(f==1) break;
    }
  }
  cout<<ans;
  return  0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll unsigned long long
#define ld long double
#define pi 3.14159
#define mx 9999999
using namespace std;
ll mark[mx];
map<ll,ll> m;
int main()
{
    ll x;
    cin>>x;
    ll a[x];
    for(int i=0;i<x;i++){
        cin>>a[i];
    }
    ll c=0,ma=0;
    for(int i=x-1;i>=0;i--){
        if(a[i]<=a[i-1]&&i-1>=0){
            c++;
        }
        else{
                //if(i==0&&a[i]>=a[i+1]) c++;
            if(c>ma) ma=c;
            c=0;
        }
    }
    cout<<ma;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,s=0;
    cin>>n;
    long long a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
            s+=(a[i]*a[j]);
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
string s[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main()
{
	string a;
	cin>>a;
	int b;
	for(int i=0;i<7;i++){
		if(s[i]==a) b=i;
	}
	if(!b) b=7;
	int ans=7-b;
	if(ans) cout<<ans;
	else cout<<7;
	cout<<"\n"; 
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(M)]
red = [0] * (N+1) #赤になりうる場所を１とする
red[1] = 1
red[0] = ""
ball = [1] * (N+1) #個数
ball[0] = ""
for x, y in xy:
  ball[y] += 1
  ball[x] -= 1
  if red[x] == 1:
    red[y] = 1
    if ball[x] == 0: red[x] = 0
print(red.count(1))

Measured memory_bytes: 28964
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    A, B, C = MI()

    if A + B + C >= 22:
        print('bust')
    else:
        print('win')


if __name__ == '__main__':
    main()


Measured memory_bytes: 5708
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        StringTokenizer st;
        String[] weekday = {"Sunday",
                "Monday",
                "Tuesday",
                "Wednesday",
                "Thursday",
                "Friday",
                "Saturday"};
        try {

            while (true) {
                Calendar cal = Calendar.getInstance();
                String line = br.readLine();
                st = new StringTokenizer(line);
                int month = Integer.parseInt(st.nextToken());
                int date = Integer.parseInt(st.nextToken());
                if(month==0&&date==0){
                    break;
                }
                cal.set(2004,month-1,date);
                System.out.println(weekday[cal.get(Calendar.DAY_OF_WEEK)-1]);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

Measured memory_bytes: 25484
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N, A, B;
    cin >> N >> A >> B;
    cout << max(B * (N - 1) + A - (A * (N - 1) + B) + 1, 0LL) << endl;
    return 0;
}


Measured memory_bytes: 256
[A11,A12,A13] = list(map(int,input().split()))
[A21,A22,A23] = list(map(int,input().split()))
[A31,A32,A33] = list(map(int,input().split()))
N = int(input())

b=[]
for i in  range(N):
    b.append(int(input()))

A=[A11,A12,A13,A21,A22,A23,A31,A32,A33]

#フラグ
sheet=[0]*9

for i in range(N):
    for j in range(9):
        if b[i]==A[j]:
            sheet[j]=1

if sheet[0]==1 and sheet[1]==1 and sheet[2]==1:
    print("Yes")
elif sheet[3]==1 and sheet[4]==1 and sheet[5]==1:
    print("Yes")
elif sheet[6]==1 and sheet[7]==1 and sheet[8]==1:
    print("Yes")
elif sheet[0]==1 and sheet[3]==1 and sheet[6]==1:
    print("Yes")
elif sheet[1]==1 and sheet[4]==1 and sheet[7]==1:
    print("Yes")
elif sheet[2]==1 and sheet[5]==1 and sheet[8]==1:
    print("Yes")
elif sheet[0]==1 and sheet[4]==1 and sheet[8]==1:
    print("Yes")
elif sheet[2]==1 and sheet[4]==1 and sheet[6]==1:
    print("Yes")
else:
    print("No")


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

typedef long long int ll;

int main() {
    int N, M;
    cin >> N >> M;

    vector<vector<int>> v(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;

        v[a].push_back(b);
        v[b].push_back(a);
    }

    vector<set<int>> s[2];
    vector<bool> used(N);
    for (int i = 0; i < N; i++) {
        if (used[i]) continue;
        int len = s[0].size();
        s[0].push_back(set<int>());
        s[1].push_back(set<int>());
        int side = 0;
        queue<int> que[2];
        que[0].push(i);
        while (que[0].size()) {
            while (que[0].size()) {
                int num = que[0].front(); que[0].pop();
                s[side][len].insert(num);
                used[num] = true;
                for (auto j : v[num]) {
                    if (s[side][len].find(j) == s[side][len].end()) {
                        if (!used[j]) que[1].push(j);
                    } else {
                        cout << - 1 << endl;
                        return 0;
                    }
                }
            }
            que[0] = que[1];
            que[1] = queue<int>();
            side = !side;
        }
    }

    map<ll,ll> m;
    ll sub = 0;
    for (int i = 0; i < s[0].size(); i++) {
        m[(ll)max(s[0][i].size(), s[1][i].size()) - (ll)min(s[0][i].size(), s[1][i].size())]++;
        sub += (ll)min(s[0][i].size(), s[1][i].size());
    }

    vector<ll> dp(N+1, -1);
    dp[0] = 0;
    for (auto p : m) {
        ll x = p.first;
        ll count = p.second;
        for (ll i = 0; i < dp.size(); i++) {
            if (dp[i] >= 0) dp[i] = count;
            else if (i < x || dp[i - x] < 0) dp[i] = -1LL;
            else dp[i] = dp[i - x] - 1LL;
        }
    }

    ll ans = 0;
    for (ll i = 0; i <= N; i++) {
        if (dp[i] >= 0)
            ans = max(ans, (sub + i) * (N - sub - i) - M);
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	
	if((x+r) <= W && (y+r) <= H && (x-r) >= 0 && (y-r) >= 0){
		cout << "Yes" << endl;}
	else{
		cout << "No" << endl;}	
	return 0;
}


Measured memory_bytes: 3100
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<assert.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define INF 0x3f3f3f3f
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod=1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0;//角度转弧度 
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N = 2e5+10, M = 1e6+10;
int n;
int a[N];
int main() {
	cin>>n;
	for(int i = 1;i <= n;i++) cin>>a[i];
	int mx = 0;
	ll ans = 0;
	for(int i = 1;i <= n;i++) {
		if(a[i] >= mx) {
			mx = max(mx, a[i]);
			continue;
		}
		ans += mx - a[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4316
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int go[] = new int[N];
		int arrive[] = new int[N];
		for (int i=0;i<M;i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if (a==1) {
				go[b-1]=1;
			} else if (b==N) {
				arrive[a-1]=1;
			}
		}
		for (int i=0;i<N;i++) {
			if (go[i]==1&&arrive[i]==1) {
				System.out.println("POSSIBLE");
				return;
			}
		}
		System.out.println("IMPOSSIBLE");
	}
}

Measured memory_bytes: 94860
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        char[] sa = s.toCharArray();
        int ans = 0;
        for(int i = 0;i<=n-3;i++){
            if(sa[i]=='A'&&sa[i+1]=='B'&&sa[i+2]=='C'){
                ans ++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
  fast;
  int n,w;
  cin>>n>>w;
  vector<int> weight(n),value(n);
  for(int i=0;i<n;i++) cin>>weight[i]>>value[i];
  vector<vector<long long>> dp(n+1,vector<long long>(w+1));
  for(int i=n-1;i>=0;i--){
    for(int j=1;j<=w;j++){
      if((j-weight[i])>=0)
        dp[i][j]=max(value[i]+dp[i+1][j-weight[i]],dp[i+1][j]);
      else
        dp[i][j]=dp[i+1][j];
    }
  }
  cout<<dp[0][w]<<"\n";
  return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;
constexpr int inv(LL x, int m) { return x > m ? inv(x % m, m) : x > 1 ? inv(m % x, m) * (m - m / x) % m : x; }
constexpr int mpow(LL a, LL k, int m) { int r(1); for (a %= m; k; k >>= 1, a = a * a % m) if (k & 1)r = r * a % m; return r; }

const int N = 1e5 + 5;
int n, A[N], B[N], C[N], F[N][3];

int main() {
    cin >> n;
    FI(i, 1, n) scanf("%d%d%d", &A[i], &B[i], &C[i]);
    F[1][0] = A[1], F[1][1] = B[1], F[1][2] = C[1];
    FI(i, 2, n) {
        F[i][0] = max(F[i - 1][1], F[i - 1][2]) + A[i];
        F[i][1] = max(F[i - 1][0], F[i - 1][2]) + B[i];
        F[i][2] = max(F[i - 1][0], F[i - 1][1]) + C[i];
    }
    cout << max({F[n][0], F[n][1], F[n][2]}) << endl;
}


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(void){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    int x0=r, x1=w-r, y0=r, y1=h-r;
    if((x>=x0)&&(x<=x1)&&(y>=y0)&&(y<=y1)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
import std.stdio,std.regex;

void main(){
	auto str = readln().chomp();

	str = str.replaceAll(regex(r"1"),"a");
	str = str.replaceAll(regex(r"9"),"1");
	str = str.replaceAll(regex(r"a"),"9");

	writeln(str);
	return;
}

import std.string,std.conv;

T[] readMany( T = size_t )(){
	T[] ret;
	foreach( val; readln().chomp().split() ){
		ret ~= val.to!T();
	}
	return ret;
}




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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

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

int main(void)
{
    ll N, P;
    cin >> N >> P;
    if (N == 1) {
        cout << P << endl;
        return 0;
    }
    ll result = 1;
    for (ll d = 2; d * d <= P; ++d) {
        int cnt = 0;
        while (P % d == 0) {
            P /= d;
            ++cnt;
        }
        while (cnt >= N) {
            result *= d;
            cnt -= N;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
S = int(input())
mod = 10**9 + 7

dp = [0] * (S+1)
dp[0] = 1
for i in range(1,S+1):
  for j in range(0,(i-3)+1):
    dp[i] += dp[j]
    dp[i] %= mod
    
print(dp[S])

Measured memory_bytes: 8936
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// 入力受付
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String tomorrow = null;
		switch (s) {
		case "Sunny":
			tomorrow = "Cloudy";
			break;
		case "Cloudy":
			tomorrow = "Rainy";
			break;
		case "Rainy":
			tomorrow = "Sunny";
			break;
		}

		System.out.println(tomorrow);
	}
}


Measured memory_bytes: 20820
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, w, h, i, j, x, y, p;
    int[] fw, fh;

    n = sc.nextInt(); w = sc.nextInt(); h = sc.nextInt();
    fw = new int[w]; fh = new int[h]; j = 0;
    for(;n-- > 0;){
      x = sc.nextInt(); y = sc.nextInt(); p = sc.nextInt();
      if(x - p < 0)fw[0]++;
      else fw[x - p]++;
      if(y - p < 0)fh[0]++;
      else fh[y - p]++;
      if(x + p < w)fw[x + p]--;
      if(y + p < h)fh[y + p]--;
    }
    for(i = 1;i < w;i++)fw[i] += fw[i - 1];
    for(i = 1;i < h;i++)fh[i] += fh[i - 1];

    for(i = 0;i < w;i++)if(fw[i] <= 0)break;
    for(j = 0;j < h;j++)if(fh[j] <= 0)break;
    if(i == w || j == h)out.println("Yes");
    else out.println("No");

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 103188
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Map<String, Set<Integer>> map = new TreeMap<String, Set<Integer>>();
		while(sc.hasNext()) {
			String s = sc.next();
			int n = sc.nextInt();
			if(map.containsKey(s)) {
				map.get(s).add(n);
			}else {
				Set<Integer> set = new TreeSet<Integer>();
				set.add(n);
				map.put(s, set);
			}
		}
		sc.close();
		for(String key : map.keySet()) {
			int cnt = 1;
			int l = map.get(key).size();
			System.out.println(key);
			for(int i : map.get(key)) {
				if(l == cnt) {
					System.out.println(i);
				}else {
					System.out.printf("%d ", i);
				}
				cnt++;
			}
		}
	}
}


Measured memory_bytes: 26252
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

int main(){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n; cin >>n;
    string s; cin >>s;
    int w = 0;
    for(int i = 0; s[i]; i++){
        w += (s[i] == 'W');
    }

    int ans = 0;
    int p = s.length()-1;
    for(int i = 0; i<w; i++, p--){
        if(s[p] == 'R') ans++;
    }

    cout <<ans <<endl;

    return 0;
}


Measured memory_bytes: 3748
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main()
{
    large x, k, d;
    cin >> x >> k >> d;
    
    x = abs(x);

    auto n = x / d;
    x %= d;

    if (n >= k) {
        x += (n - k) * d;
    } else {
        k -= n;
        if (k % 2 == 1) x -= d;
    }


    cout << abs(x) << endl;
    return 0;
}


Measured memory_bytes: 3636
N, M = map(int, input().split())
P = []
for _ in range(N):
    P.append(list(map(int, input().split())))
Q = []
for _ in range(M):
    Q.append(list(map(int, input().split())))
for i in P:
    lst = []
    for j in Q:
        dis = abs(i[0] - j[0]) + abs(i[1] - j[1])
        lst.append(dis)
    print(lst.index(min(lst)) + 1)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
using namespace std;
#define ll long long
ll fac[100005];
const ll mod = 1e9 + 7;
int main()
{
    fac[1] = 1;
    for (int i = 2; i <= 100000; i++)
    {
        fac[i] = (fac[i - 1] * i)%mod;
    }
    int n;
    scanf("%d",&n);
    printf("%lld\n",fac[n]);
}


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

typedef struct Node{
  int value, priority;
  Node *left, *right;
} Node;

Node* Delete(Node *, int);
Node* _delete(Node *, int);

Node *NIL,*root;

Node* rightRotate(Node *t){
  Node *s = t->left;
  t->left = s->right;
  s->right = t;
  return s;
}
Node* makenode(int key, int priority){
  Node *node = (Node *)malloc(sizeof(Node));
  node->value = key;
  node->priority = priority;
  node->left = node->right = NIL;
  return node;
}
Node* leftRotate(Node *t){
  Node *s = t->right;
  t->right = s->left;
  s->left = t;
  return s; 
}

Node* insert(Node *t, int key, int priority){    
  Node *x;

  if(t == NIL) return x = makenode(key, priority); 

  if(key == t->value) return t;                

  if(key < t->value){                          
    t->left = insert(t->left, key, priority); 
    if(t->priority < t->left->priority) t = rightRotate(t); 
  }else{                                      
    t->right = insert(t->right, key, priority); 
    if(t->priority < t->right->priority) {
        t = leftRotate(t); 
    }
  }

  return t;
}
Node* find(Node *x, int k){
  if(x == NIL || x->value == k) return x;

  if(k < x->value) return find(x->left, k);
  else return find(x->right, k);
}
Node* Delete(Node *t, int key){
  if(t == NIL) return NIL;
  if(key < t->value) t->left = Delete(t->left, key); 
  else if(key > t->value) t->right = Delete(t->right, key);
  else return _delete(t, key);
  return t;
}

Node* _delete(Node *t, int key){ 
  if(t->left == NIL && t->right == NIL) return NIL; 
  else if(t->left == NIL) t = leftRotate(t);   
  else if(t->right == NIL) t = rightRotate(t); 
  else{                                     
    if(t->left->priority > t->right->priority) 
    t = rightRotate(t); 
    else
    t = leftRotate(t);
  }
  return Delete(t, key);
}

void preParse(Node *node){
  if(node == NIL) return ;

  cout<<" "<< node->value;
  if(node->left != NIL) preParse(node->left);
  if(node->right != NIL) preParse(node->right);
}

void inParse(Node *node){
  if(node == NIL) return ;

  if(node->left != NIL) {
      inParse(node->left);
  }
  cout<<" "<<node->value;
  if(node->right != NIL) {
      inParse(node->right);
  }
}

int main(){
  int n,key,priority;
  string command;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>command;
    if(command=="insert"){
      cin>>key>>priority;
      root=insert(root,key,priority);
    }else if(command=="print"){
      inParse(root);
      cout<<endl;
      preParse(root);
      cout<<endl;
    }else if(command=="find"){
      cin>>key;
      if(find(root,key)) cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }else if(command=="delete"){
      cin>>key;
      root=Delete(root,key);
    }
  }
  return 0;
}


Measured memory_bytes: 9476
# -*- coding: utf-8 -*-

n = input()
a = map(int,raw_input().split())

mod = 10**9+7
flg = [False]*n
      
for i in range(n):
    if(flg[a[i]]==False):
        flg[a[i]] = True
    elif(flg[a[i]-1]==False and a[i]-1>=0):
        flg[a[i]-1] = True
    
           
if(n%2==0):
    if(all(flg)):
        print(2**(n/2) % mod)
    else:
        print('0')
else:
    if(all(flg)):
        print(2**((n-1)/2) % mod)
    else:
        print('0')
        

Measured memory_bytes: 11328
#include <iostream>
#include <sstream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  ll N;
  cin>>N;
  vector<ll> H(N);
  FORi(N){
    cin>>H[i];
  }
  ll num=1;
  ll max=H[0];
  FORi(N-1){
    if(H[i+1]>=max){
      max=H[i+1];
      ++num;
    }
  }
  cout<<num<<endl;
  return 0;
}


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

int main(void) {
    long long int N, A, B, ans = 0;
    cin >> N >> A >> B;
    vector<long long int> X(N+1);
    cin >> X[0];
    for(int i = 1; i < N; i++) { 
        cin >> X[i];
        ans += min(A*(X[i]-X[i-1]), B);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  int a[n];
  rep(i,n) R a[i];
  sort(a,a+n,greater<int>());
  int ans=0;
  rep(i,m) ans+=a[i];
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int n;
vector<int> vec;

int main(int argc, char *argv[])
{
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int num;
        cin >> num;
        vec.emplace_back(num);
    }
    sort(vec.begin(), vec.end());
    ++n;
    cout << vec[n / 2] - vec[n / 2 - 1] << endl;
}

Measured memory_bytes: 892
def main():
  n, k = map(int, input().split())

  mod = 10 ** 9 + 7

  if n == k:
    ans = 1
    for num in input().split():
      ans = (ans * int(num)) % mod

    print(ans % mod)
    return

  plus = []
  minus = []
  for num in input().split():
    num = int(num)
    if num >= 0:
      plus.append(num)
    else:
      minus.append(num)

  pn = len(plus)
  mn = len(minus)

  if pn == 0 and k % 2 == 1:
    minus.sort(reverse = True)
    ans = 1
    for i in range(k):
      ans = (-ans * minus[i]) % mod

    print((-ans) % mod)
    return


  plus.sort(reverse = True)
  minus.sort()

  pi = 0
  mi = 0

  while k > 0:
    if pi + 1 == pn:
      if k % 2 == 0:
        mi += k
      else:
        pi += 1
        mi += k - 1

      break

    if pi == pn:
      mi += k
      break

    if mi + 1 >= mn:
      pi += k
      break

    if k == 1 or plus[pi] * plus[pi + 1] >= minus[mi] * minus[mi + 1]:
      pi += 1
      k -= 1
    else:
      mi += 2
      k -= 2

  ans = 1
  for i in range(pi):
    ans = (ans * plus[i]) % mod

  for i in range(mi):
    ans = (-ans * minus[i]) % mod

  print(ans % mod)


main()


Measured memory_bytes: 32420
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

template <typename T>
struct BIT {
private:
    vector<T> v;
public:
    BIT(int n) : v(n, 0) {}
    T sum(int i) const {
        T s = 0;
        while (i > 0) {
            s += v[i];
            i = (i & (i + 1)) - 1;
        }
        return s;
    }
    void add(int i, T x) {
        while (i < (int)v.size()) {
            v[i] += x;
            i |= i + 1;
        }
    }
    int size() const { return v.size(); }
};

int main() {
    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);
    for (auto &e: a) cin >> e;

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

    BIT<ll> a_bit(n+1);
    for (int i = 1; i <= n; ++i) {
        a_bit.add(i, a[i-1]);
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ll tn = a[i];
        ll s = upper_bound(a.begin(), a.end(), tn) - a.begin();
        ll t = upper_bound(a.begin(), a.end(), tn+m) - a.begin() - s;
        ll q = n-(s+t);
        if (q >= p) continue;

        if (t+q <= p-1) {
            ++ans;
            continue;
        }

        t -= (p-1)-q;
        q = p-1;

        int ts = upper_bound(a.begin(), a.end(), tn) - a.begin();
        int tt = n-(p-1);
        ll tsum = a_bit.sum(tt) - a_bit.sum(ts);

        ll lim = (q+s)*m + (t*(tn+m) - tsum);
        if (m*v <= lim) ++ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
     
    using namespace std;
    typedef long long ll;
    const int N = 2e5 + 5, MOD = 1e9+7;
    
	int n, p[22], ans;
	
    int main(){
      	scanf("%d",&n);
      	for(int i=0;i<n;++i){
        	scanf("%d",p+i);
        }
      	for(int i=1;i<n-1;++i){
        	if(p[i]<p[i+1]&&p[i-1]>p[i])continue;
          	if(p[i]>p[i+1]&&p[i-1]<p[i])continue;
          	if(p[i]==p[i+1]&&p[i-1]==p[i])continue;
          	ans++;
        }
      	printf("%d",ans);
        return 0;
    }

Measured memory_bytes: 256