akhauriyash/Code-Regression huggingface dataset:
from sys import stdin

if __name__ == '__main__':
    N, L = [int(x) for x in stdin.readline().rstrip().split()]
    apples = []
    isMinus = False
    isPlus = False
    for i in range(N):
        if L+i < 0:
            isMinus = True
        else:
            isPlus = True
        apples.append(L+i)

    if isMinus == True and isPlus == True:
        print(sum(apples))
    elif isMinus == True and isPlus == False:
        print(sum(apples[:-1]))
    else:
        print(sum(apples[1:]))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};

int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
ll inf=998244353;
ll power(ll a,ll x){
    ll res=1;
    while(x>0){
        if(x&1) res=res*x%inf;
        x=x*x%inf;
        x>>=1;
    }
    return res;
}
int main(){
    string x;cin>>x;
    int cs=0,ct=0;
    for(int i=0;i<(int)x.size();i++){
        if(x[i]=='S') cs++;
        else{
            if(cs>0) cs--;
            else ct++;
        }
    }
    cout<<cs+ct<<endl;
    return 0;
}

Measured memory_bytes: 640
n, k = map(int, input().split())
s = list(input())

cnt = []
if s[0] == '0': cnt.append(0)
i = 0
while i < n:
    j = i
    while j < n and s[j] == s[i]:
        j += 1
    cnt.append(j- i)
    i = j
if s[-1] == '0': cnt.append(0)

m = len(cnt)
cs = [0] * (m+1)
for i in range(m):
    cs[i+1] = cs[i] + cnt[i]

ans = 0
for l in range(0, m+1, 2):
    r = l + 2 * k + 1
    if r > m: r = m
    ans = max(ans, cs[r] - cs[l])

print(ans)


Measured memory_bytes: 8568
#include <string>
#include <iostream>

using namespace std;

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, sl, al;
	string s, a;
	cin >> s; sl = s.length();

	for (i; i < sl; i++) {
		if (s[i] == '0')a += '0';
		if (s[i] == '1')a += '1';
		if ((s[i] == 'B') && (a[0] != NULL)) {
			al = a.length();
			a.erase(a.begin() + al - 1);
		}
	}

	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	n := readI()
	P, Q := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		P[i] = readI()
	}
	for i := 0; i < n; i++ {
		Q[i] = readI()
	}

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = i + 1
	}

	if isLager(P, Q) {
		P, Q = Q, P
	}

	i := 0
	for ; !isSame(P, Q); i++ {
		nextPermutation(P)
	}

	fmt.Println(i)
}

func isLager(a, b []int) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			if a[i] > b[i] {
				return true
			}
			return false
		}
	}
	return false
}

func isSame(a, b []int) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func nextPermutation(p []int) bool {
	swap := func(a []int, b, c int) {
		a[b], a[c] = a[c], a[b]
	}
	rev := func(s []int) {
		for i := 0; i < len(s)/2; i++ {
			swap(s, i, len(s)-1-i)
		}
	}

	l, r := len(p)-2, len(p)-1

	for p[l] >= p[l+1] {
		if l == 0 {
			rev(p)
			return false
		}
		l--
	}
	for p[l] >= p[r] {
		r--
	}

	swap(p, l, r)
	rev(p[l+1:])
	return true
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-2.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(void){

    int h,w;
    int i,j;

    while(1){

        scanf("%d%d",&h,&w);

        if (h==0&&w==0) break;

        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <cmath>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int P = 1e9+7, N = 2e6+10;
int X[6], Y[6];
int fac[N], ifac[N], kX[2][4], kY[2][4], ans;
int inv(int i) { return i == 1?i:P-1ll*(P/i)*inv(P%i)%P; }
int C(int n, int m) { return 1ll*fac[n]*ifac[m]%P*ifac[n-m]%P; }
int G(int x1, int y1, int x2, int y2) { return C(abs(x1-x2)+abs(y1-y2), abs(x1-x2));  }
int F(int x1, int y1, int x3, int y3, int o)
{
    int ret = 0;
    for(int x2 = X[2]; x2 <= X[3]; ++x2)
        ret = (ret+P-1ll*G(x1, y1, x2, Y[2]-1)*G(x2, Y[2], x3, y3)%P*(x2+Y[2])%P)%P,
        ret = (ret+1ll*G(x1, y1, x2, Y[3])*G(x2, Y[3]+1, x3, y3)%P*(x2+Y[3]+1)%P)%P;
    for(int y2 = Y[2]; y2 <= Y[3]; ++y2)
        ret = (ret+P-1ll*G(x1, y1, X[2]-1, y2)*G(X[2], y2, x3, y3)%P*(X[2]+y2)%P)%P,
        ret = (ret+1ll*G(x1, y1, X[3], y2)*G(X[3]+1, y2, x3, y3)%P*(X[3]+y2+1)%P)%P;        
    return o?P-ret:ret;
}
int main()
{
    for(int i = 0; i < 6; ++i) X[i] = read();
    for(int i = 0; i < 6; ++i) Y[i] = read();
    fac[0] = ifac[0] = 1;
    for(int i = 1; i <= X[5]+Y[5]+2; ++i) fac[i] = 1ll*i*fac[i-1]%P;
    ifac[X[5]+Y[5]+2] = inv(fac[X[5]+Y[5]+2]);
    for(int i = X[5]+Y[5]+1; i; --i) ifac[i] = 1ll*(i+1)*ifac[i+1]%P;
    kX[0][0] = X[0]-1, kY[0][0] = Y[0]-1, kX[0][1] = X[1], kY[0][1] = Y[0]-1, kX[0][2] = X[1], kY[0][2] = Y[1], kX[0][3] = X[0]-1, kY[0][3] = Y[1];
    kX[1][0] = X[4], kY[1][0] = Y[4], kX[1][1] = X[4], kY[1][1] = Y[5]+1, kX[1][2] = X[5]+1, kY[1][2] = Y[5]+1, kX[1][3] = X[5]+1, kY[1][3] = Y[4];
    for(int i = 0; i < 4; ++i)
        for(int j = 0; j < 4; ++j)
            ans = (ans+F(kX[0][i], kY[0][i], kX[1][j], kY[1][j], (i^j)&1))%P;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 15744
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const int inf = int(1e10);
//const ll inf = ll(1e19);
const int mod = int(1e9) + 7;

int x;
int main(){
    cin >> x;
    if(x == 0) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 3636
use proconio::input;
use std::collections::HashMap;

type State = (usize,bool,bool,bool);
const MOD:i64 = 1_000_000_007;

enum Resp {
    Bad,
    Fin,
    Nex(State)
}
use Resp::Bad;
use Resp::Fin;
use Resp::Nex;

fn trans(st:State,x:usize,y:usize,l:i64,r:i64) -> Resp{
    let x = x as i64;
    let y = y as i64;
    if y<x {
        return Bad;
    }
    let (p,yx,ry,xl) = st;
    if !yx && y>x {
        return Bad;
    }
    if !ry && ((r>>p)&1)<y {
        return Bad;
    }
    if !xl && ((l>>p)&1)>x {
        return Bad;
    }
    if p==0 {
        return Fin;
    }
    let nex_yx = x==1 || yx;
    let nex_ry = ((r>>p)&1)>y || ry;
    let nex_xl = ((l>>p)&1)<x || xl;
    Nex((p-1,nex_yx,nex_ry,nex_xl))
}
fn calc(st:State,mut dp:&mut HashMap<State,i64>,l:i64,r:i64) -> i64{
    if dp.contains_key(&st) {
        return dp[&st];
    }
    let mut ans = 0;
    for i in 0..2 {
        for j in 0..2 {
            let ret = trans(st,i,j,l,r);
            ans +=  match ret {
                        Bad => 0,
                        Fin => 1,
                        Nex(nexst) => calc(nexst,&mut dp,l,r)
                    };
            ans %= MOD;
        }
    }
    dp.insert(st,ans);
    // println!("{:?} {}",st,ans);
    ans
}
fn main() {
    input! {
        l:i64,r:i64
    };

    let mut dp = HashMap::new();
    let st:State = (60,false,false,false);
    
    let ans = calc(st,&mut dp,l,r);
    println!("{}",ans);
}



Measured memory_bytes: 2164
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int quickpow(int x,int y)
{
	long long res=1,base=x;
	while(y)
	{
		if(y&1) res*=base,res%=mod;
		y>>=1;
		base*=base,base%=mod;
	}
	return res;
}
int inv(int x){return quickpow(x,mod-2);}
int prod[10000001];
int invp[10000001];
int c(int n,int m){return 1ll*prod[n]*invp[m]%mod*invp[n-m]%mod;}
signed main()
{
	int n;
	scanf("%d",&n);
	int ans=0;
	prod[0]=1,invp[0]=1;
	for(int i=1;i<=n;i++)
		prod[i]=1ll*prod[i-1]*i%mod,invp[i]=inv(prod[i]);
	for(int i=n/2+((n%2==0)?1:0);i<=n;i++)
		ans+=1ll*c(n,i)*2*quickpow(2,n-i)%mod,ans%=mod;
	printf("%d",((quickpow(3,n)-ans)%mod+mod)%mod);
	return 0;
}


Measured memory_bytes: 78336
#include <stdio.h>
#include <algorithm> 

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W); 
		 if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){ 
			for(int j = 0; j < W; j++){
				printf("#");
			 }
			printf("\n");
		}
		printf("\n");
	}
}



Measured memory_bytes: 2612
#include<stdio.h>
int n,k,p[200000],i,j,q=0,m,r=0;
double t=0;
int main(){
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&p[i]);
        if(i<k)q+=p[i];
        else q+=p[i]-p[i-k];
        if(q>r){r=q;m=i;}
    }
    for(i=m;i>m-k;i--){
        for(q=j=0;j<p[i];j++)q+=(j+1);
        t+=1.0*q/p[i];
    }
    printf("%lf",t);
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int a, b;
    cin >> a >> b;
    if((a + b) % 2 == 0) {
        cout << (a + b) / 2 << endl;
    } else {
        cout << (a + b) / 2 + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

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

def main():
    mod=10**9+7
    x,y=MI()
    
    if abs(x-y)<=1:
        print("Brown")
    else:
        print("Alice")
                

main()


Measured memory_bytes: 38384
#include<stdio.h>

int main(){
int a,b,c,flag=0;
scanf("%d%d%d",&a,&b,&c);
if(a==b+c)flag=1;
if(b==c+a)flag=1;
if(c==a+b)flag=1;
if(flag==1)puts("Yes");
else puts("No");
return 0;
}

Measured memory_bytes: 128
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$n = (int)$input[0];
$m = (int)$input[1];

$ac = [];
$wa = [];
for ($i=1; $i <= $n; $i++) { 
	$ac[$i] = false;
	$wa[$i] = 0;
}

for ($i=0; $i < $m; $i++) { 
	$input = explode(' ', trim(fgets(STDIN)));
	$p = (int)$input[0];
	$s = $input[1];
	switch ($s) {
		case 'AC':
			$ac[$p] = true;
			break;
		case 'WA':
			if (!$ac[$p]) {
				$wa[$p] += 1;
			}
			break;
	}
}

$a = 0;
$w = 0;
for ($i=1; $i <= $n; $i++) { 
	if ($ac[$i]) {
		$a += 1;
		$w += $wa[$i];
	}
}

echo $a . ' ' . $w;

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

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

    int ans;
    ans = n*(n-1)/2 + m*(m-1)/2;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N = 100010;

int n, t, a[N], max[N];

int main()
{
	scanf("%d%d", &n, &t);
	for (int i = 1; i <= n; i ++)
		scanf("%d", &a[i]);
	for (int i = n; i; i --)
	{
		max[i] = max[i + 1];
		if (a[i] > max[i])
			max[i] = a[i];
	}
	for (int i = 1; i <= n; i ++)
		a[i] = max[i] - a[i];
	int ans = 0;
	for (int i = 1; i <= n; i ++)
		if (ans < a[i])
			ans = a[i];
	int cnt = 0;
	for (int i = 1; i <= n; i ++)
		if (a[i] == ans)
			cnt ++;
	return printf("%d\n", cnt), 0;
}

Measured memory_bytes: 1024
a = int(input())
b = [int(i) for i in input().split()]
c = 0
d = []

for i in b:
    if i < 0:
        c += 1
    d.append(abs(i))

if c % 2 == 0:
    print(sum(d))
else:
    print(sum(d) - (min(d) * 2))

Measured memory_bytes: 14260
n, m, v, p = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

ok = p - 1
ng = n

while abs(ok - ng) > 1:
  mid = (ok + ng) // 2
  if A[mid] + m < A[p - 1]:
    ng = mid
    continue

  used = m * p
  for i in range(p - 1, n):
    if i != mid:
      used += min(m, max(0, A[mid] + m - A[i]))

  if used >= m * v:
    ok = mid
  else:
    ng = mid

print(ok + 1)

Measured memory_bytes: 14484
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 100000000000;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

int main(void){
  int N, A, B;
  cin >> N >> A >> B;
  int ans = 0;
  rep(i, N+1){
    int I = i;
    int cnt = 0;
    cnt += I % 10;
    I /= 10;
    cnt += I % 10;
    I /= 10;
    cnt += I % 10;
    I /= 10;
    cnt += I % 10;
    I /= 10;
    cnt += I % 10;
    if(A <= cnt && cnt <= B){
      ans += i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
while True:
    n, m = map(int, input().split())
    if (n, m) == (0, 0):
        break
    dp = [list(map(int, input().split())) for i in range(n)]
    dp = sorted(dp, key=lambda kv:kv[1], reverse=True)
    r = 0
    for d,p in dp:
        if m >= d:
            m -= d
        else:
            r += p*(d-m)
            m = 0
    print(r)

Measured memory_bytes: 10060
# %% constants
# ------------


# %% body
# -------

function main(io = stdin)
    readto(target = '\n') = readuntil(io, target)
    readnum(T::Type{<:Number} = Int; dlm = isspace, kwargs...) =
        parse.(T, split(readto(), dlm; kwargs...))

    # handle IO and solve
    A, B, C = readnum()
    K, = readnum()
    println(solve(A, B, C, K) ? "Yes" : "No")
end

# A < B < C
function solve(A, B, C, K)
    for a in 0:K
        for b in 0:(K-a)
            for c in 0:(K-a-b)
                check(A, B, C, a, b, c) && return true
            end
        end
    end
    return false
end

check(A, B, C, a, b, c) = (2^a)*A < (2^b)*B < (2^c)*C

@static if @isdefined(Juno)
    main(open(replace(@__FILE__, r"(.+)\.jl" => s"\1.in")))
else
    main()
end


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

def power(N):
	if N == 1:
		return 1
	else:
		return (N*power(N-1))%mod

N = INT()
print(power(N))

Measured memory_bytes: 93260
#include<bits/stdc++.h>
#include<iomanip>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define KETA 40

using namespace std;

typedef long long  ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n;
	cin>>n;
	int t=0;

	rep(i,n+1){
		if(i>0&&i<=9)t++;
		if(i>=100&&i<=999)t++;
		if(i>=10000&&i<=99999)t++;
	}
	cout<<t<<endl;
	return 0;

}


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

int main()
{
    char b;
cin  >> b;
if(b == 'A'){
  cout << 'T' <<endl;
}else if(b == 'C'){
    cout << 'G' <<endl;
}
else if (b == 'G')
{
    cout << 'C' << endl;
}
else if (b == 'T')
{
    cout << 'A' << endl;
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int main() {
	int n, cnt = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int x;
		scanf("%d", &x);
		if (x % 2) ++cnt;
	}
	if (cnt == 0) 
		puts("second");
	else
		puts("first");
}

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

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	int n = 0;
	std::cin >> n;

	std::vector<unsigned long long> list;
	list.reserve(n);
	unsigned long long input = 0;
	for (int i = 0; i < n; ++i) {
		std::cin >> input;
		list.push_back(input);
	}
	int li = 0, ri = n-1;
	unsigned long long lt = 0, rt = 0;
	while (li <= ri) {
		if (lt <= rt) {
			lt += list[li++];
		}
		else {
			rt += list[ri--];
		}
	}
	unsigned long long sa = (rt >= lt) ? rt - lt : lt - rt;
	std::cout << sa;
	return 0;
}



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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    //good luck kittu!
    string sa, sb, sc;
    cin>>sa>>sb>>sc;
    int a = sa.size(), b = sb.size(), c = sc.size();
    int i = 0, j = 0, k = 0;
    char curr = sa[0]; i++;
    while(1){
        if((curr=='a' && i==a) || (curr=='b'&&j==b) || (curr=='c'&&k==c)) break;
        if(curr=='a'){
            curr = sa[i];
            i++;
        }
        else if(curr=='b'){
            curr = sb[j];
            j++;
        }
        else if(curr=='c'){
            curr = sc[k];
            k++;
        }
    }
    //cout<<curr<<"\n";
    if(curr=='a' && i==a) cout<<"A\n";
    else if(curr=='b' && j==b) cout<<"B\n";
    else if(curr=='c' && k==c) cout<<"C\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using P = pair<long long, long long>;

long long n;
vector<long long> s;
map<long long, long long, greater<long long>> mp;

bool solve();

int main() {
  cin >> n;
  s.resize((1LL << n));
  for(long long i = 0; i < (1LL << n); ++i) cin >> s[i];
  sort(s.begin(), s.end(), greater<long long>());
  if(solve())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

bool solve() {
  priority_queue<long long> pq, dummy;
  pq.push(s[0]);
  for(int i = 1; i < s.size(); ++i) ++mp[s[i]];
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < (1LL << i); ++j) {
      long long now = pq.top();
      pq.pop();
      dummy.push(now);
      auto it = mp.upper_bound(now);
      if(it == mp.end()) return 0;
      if(--(*it).second == 0) mp.erase(it);
      dummy.push((*it).first);
    }
    while(!dummy.empty()) {
      pq.push(dummy.top());
      dummy.pop();
    }
  }

  return 1;
}


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

using namespace std;

typedef pair<int, int> pii;

pii get_pos(int x)
{
    return pii(x / 3, x % 3);
}

bool inField(int x, int y)
{
    return (0 <= x && x < 3 && 0 <= y && y < 3);
}

int main()
{
    int N;
    while (cin >> N, N) {
        string S = "ABCDEFGHI";
        char a[3];
        for (int i = 0; i < 3; i++) {
            cin >> a[i];
        }
        int s = S.find(a[0]);
        int t = S.find(a[1]);
        int b = S.find(a[2]);

        double dp[25][9] = {{}};
        pii p = get_pos(b);

        dp[0][s] = 1;
        
        const int di[] = {-1, +0, +1, +0};
        const int dj[] = {+0, -1, +0, +1};
        
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < 9; j++) {
                if (dp[i][j] == 0) continue;
                pii n = get_pos(j);
                for (int k = 0; k < 4; k++) {
                    int ni = n.first + di[k];
                    int nj = n.second + dj[k];
                    if (!inField(nj, ni) || (pii(ni, nj) == p)) {
                        dp[i+1][j] += dp[i][j] / 4;
                    } else {
                        dp[i+1][ni*3+nj] += dp[i][j] / 4;
                    }
                }
            }
        }
        printf("%.10f\n", dp[N][t]);            
    }    
    return 0;
}

Measured memory_bytes: 3168
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n,m = I()
a = []
b = []

for _ in range(n):
    a += [list(input())]
for _ in range(m):
    b += [list(input())]

for i in range(n-m+1):
    for j in range(n-m+1):
        if [k[j:m+j] for k in a[i:m+i]] == b:
            print('Yes')
            exit()
print('No')


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

int main() {
    int n, ans = 0, temp;
    cin >> n;
    vector<int> a(n), c(n - 1);
    rep(i, n) cin >> a.at(i);
    rep(i, n) {
        cin >> temp;
        ans += temp;
    }
    rep(i, n - 1) cin >> c.at(i);
    int last = a.at(0);
    rep(i, n - 1) {
        if(a.at(i + 1) == last + 1) ans += c.at(last - 1);
        last = a.at(i + 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
x = int(input())
def han(n):
    p = 1
    for i in range(2,int(n**0.5)+1):
        if n%i == 0:
            p = p*0
        else:
            continue
    return p
for j in range(x,x+10000):
    if han(j) == 1:
        print(j)
        break

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,k,c=0;
    cin>>n>>k;
    map<ll,ll>m;
    for(int i=1;i<=k;i++)
    {
        ll d;
        cin>>d;
        for(int j=1;j<=d;j++)
        {
            ll x;
            cin>>x;
            m[x]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(!m[i])
            c++;
    }
    cout<<c<<endl;
    
}
return 0;
}

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

using namespace std;
using ll = long long;

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

    ll cnt_two = 0;
    for (int i = 0; i < n; ++i) {
        ll a;
        cin >> a;

        ll cnt = 0;

        while (true) {
            if (a % 2 == 0) {
                a /= 2;
                cnt++;
            } else {
                cnt_two += cnt;
                break;
            }
        }
    }

    cout << cnt_two << endl;
    return 0;
}

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

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct P
{
	int x, y;
	P(int x,int y):x(x),y(y){}
	P() :P(-1, -1) {}
};

string A[100];
int H, W;

void dfs(P nowp)
{
	static const int dx[] = { 1,0,-1,0 };
	static const int dy[] = { 0,1,0,-1 };

	char c = A[nowp.y][nowp.x];
	A[nowp.y][nowp.x] = '0';

	rep(i, 0, 4)
	{
		P nextp(nowp.x + dx[i], nowp.y + dy[i]);

		if (0 <= nextp.x&&nextp.x < W && 0 <= nextp.y&&nextp.y < H)
		{
			if (A[nextp.y][nextp.x] == c)
			{
				dfs(nextp);
			}
		}
	}
}

int solve()
{
	int ans = 0;
	rep(i, 0, H)rep(j, 0, W)
	{
		if (A[i][j] != '0')
		{
			ans++;
			dfs(P(j, i));
		}
	}
	return ans;
}

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

	while (true)
	{
		cin >> H >> W;
		rep(i, 0, H)cin >> A[i];

		if (H == 0 && W == 0)
		{
			break;
		}
		cout << solve() << endl;
	}

	return 0;
}


Measured memory_bytes: 4112
import itertools
import math


def gcd(a: int, b: int, c: int) -> int:
    return math.gcd(math.gcd(a, b), c)


def main() -> None:
    k = int(input())

    s = sum(gcd(a, b, c) for a, b, c in itertools.product(range(1, k + 1), repeat=3))
    print(s)


if __name__ == "__main__":
    main()


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

int main()
{
	long long N, A[200000], ans,k=0,b;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[i] -= i + 1;
	}

	sort(A, A + N);

	b = A[N / 2];

	for (int i = 0; i < N; i++) {
		k += abs(A[i] - b);
	}

	ans = k;
	if (N % 2 == 0)b = A[N / 2 - 1];
	k = 0;
	for (int i = 0; i < N; i++) {
		k += abs(A[i] - b);
	}

	if (ans > k)ans = k;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void) {
	int j,n,i,k,score,count;
	int l[256][3];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d",&l[i][0],&l[i][1],&l[i][2]);
	}
	for(i=0;i<n;i++){
		score=0;
		for(j=0;j<3;j++){
			count=0;
			for(k=0;k<n;k++){
				if(l[k][j]==l[i][j]){
					count++;
				}
			}
			if(count==1){
				score+=l[i][j];
			}
		}
		printf("%d\n",score);
	}
	return 0;
}

Measured memory_bytes: 2700
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool is_even_str(const string &s)
{
	auto mid = s.begin() + s.length() / 2;
	return equal(s.begin(), mid, mid, s.end());
}

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

	s.pop_back();
	while (!is_even_str(s)) {
		s.pop_back();
	}
	cout << s.length() << endl;
}


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

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];


int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> v(n+10, 1);
    vector<ll> A(n);
    for (int i=0; i<n; ++i) {
        cin >> A[i];
        if (i < k) {
            v[k-1] *= A[i];
        };
    }
    for (int i=k; i<n; ++i) {
        // v[i] = (v[i-1]/A[i-k])*A[i];
        // if (v[i] > v[i-1]) {
        if (A[i] > A[i-k]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    
    return 0;
}



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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define f first
#define s second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 100500;

int n, m;
char c[100][100];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	//cout << setprecision(2) << fixed;
	
	cin >> n >> m;
	
	for(int i = 1; i <= n; ++i)
	for(int j = 1; j <= m; ++j)
		cin >> c[i][j];

	int x = 1, y = 1;
	if(c[1][1] == '.'){
		cout << "Impossible";
		return 0;
	}

	while(true){
		c[x][y] = '.';
		if(x + 1 <= n && c[x + 1][y] == '#'){
			x++;
		}else if(y + 1 <= m && c[x][y + 1] == '#'){
			y++;
		}else{
			break;
		}
	}

	if(!(x == n && y == m)){
		cout << "Impossible";
		return 0;
	}

	for(int i = 1; i <= n; ++i)
	for(int j = 1; j <= m; ++j){
		if(c[i][j] == '#'){
			cout << "Impossible";
			return 0;
		}
	}

	cout << "Possible";
	     	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  rep(i,a,b)for(int i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const int INF=1000000000LL;
const ll r197=1000000007;
typedef pair<ll,int>P;
typedef pair<int,P>Pa;
int dp[5000][5000];
vector<P> v;
int n,q;
int i;
string str;
int A[5000]={};
int main() {
	cin>>n>>str;
	int ans=0;

	for(int l=0;l<n;++l){
		A[0]=str.size();
		int i=1,j=0;
		while(i<str.size()){
		  while(i+j<str.size()&&str[j]==str[i+j])++j;
		  A[i]=j;
		  if(j==0){++i;continue;}
		  int k=1;
		  while(i+k<str.size()&&k+A[k]<j)A[i+k]=A[k],++k;
		  i+=k;j-=k;
		}
		for(int m=0;m<str.size();m++){
			if(A[m]>=m)ans=max(ans,m);
			else ans=max(ans,A[m]);
			A[m]=0;
		}
		str=str.substr(1);
	}
	cout<<ans<<endl;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else if (a + b < c + d){
    cout << "Right" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1e9+7;

signed main(){
  int K;
  cin >> K;
  string S;
  cin >> S;
  if( S.size() <= K ) cout << S << endl;
  else cout << S.substr(0, K) << "..." << endl;
}


Measured memory_bytes: 3632
S = input()
K = int(input())
 
INNER = 0
  
if len(set(list(S))) == 1:
  print(K*len(S)//2)
else: 
  i = 0
  while i < len(S)-1:
    if S[i] == S[i+1]:
      INNER += 1
      i += 1
    i += 1
  
  if (S[0] != S[-1]):#最初の文字と最後の文字が違うなら、
    print(INNER*K)
  else:
    same_from_start = 0
    same_from_end = 0
    
    count_from_start = 0
    count_from_end = 0
    
    flag_same_from_start = 0
    flag_same_from_end = 0
    
    while flag_same_from_start == 0:
      if S[count_from_start] == S[count_from_start+1]:
        count_from_start += 1
      else:
        count_from_start += 1
        flag_same_from_start = 1
    
    while flag_same_from_end == 0:
      if S[len(S)-count_from_end-1] == S[len(S)-count_from_end-2]:
        count_from_end += 1
      else:
        count_from_end += 1
        flag_same_from_end = 1
    print(INNER*K + (K -1) * ((count_from_start+count_from_end)//2 -\
                              count_from_start//2- count_from_end//2))

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
using namespace std;
#define MAX_N 100
#define MAX_M 100
int  n, m, sn[MAX_N], sm[MAX_M], i, j, ans, nsum, msum;

//無駄ソート
int sort(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}

int main(){
  while(1){
    nsum = 0;
    msum = 0;
    ans = -1;
    scanf("%d %d", &n, &m);
    if(n == 0 && m == 0) break;
    for(i = 0; i < n; i++){
      scanf("%d", &sn[i]);
      nsum += sn[i];
    }
    for(i = 0; i < m; i++){
      scanf("%d", &sm[i]);
      msum += sm[i];
    }
    qsort(sn, n, sizeof(int), sort);
    qsort(sm, m, sizeof(int), sort);
    for(i = 0; i < n; i++) {
      for(j = 0; j < m; j++){
	if((sn[i] -  sm[j]) * 2 == nsum - msum) {
	  ans++;
	  break;
	}
      }
      if(ans != -1) break;
    }
    if(ans != -1) printf("%d %d\n", sn[i], sm[j]);
    else printf("%d\n", -1);
  }
  return 0;
}

Measured memory_bytes: 1032
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
using std::vector;

int main() {
    using lli = long long;
    lli n;
    cin >> n;

    vector<char> ans;
    while (n) {
        n--;
        ans.push_back('a' + n % 26LL);
        n /= 26LL;
    }
    for (int i = ans.size() - 1; i >= 0; --i) {
        cout << ans.at(i);
    }
    cout << '\n';
    return 0;
}

Measured memory_bytes: 3536
#include <iostream>

const int MAX_N = 100;

int n_factor[MAX_N+1] = {};
int n_over[MAX_N+1] = {};

void set_n_factor(int n)
{
    for (int i = 2; i <= n; i++)
    {
        int rest = i;
        int j = 2;
        while (true)
        {
            if (rest < j)
            {
                n_factor[rest]++;
                break;
            }
            if (rest%j == 0)
            {
                n_factor[j]++;
                rest /= j;
                continue;
            }
            else
            {
                j++;
            }
        }
    }
}

int solve(int n)
{
    for (int i = 2; i <= n; i++)
    {
        if (n_factor[i] >= 2)
        {
            n_over[2]++;
        }
        if (n_factor[i] >= 4)
        {
            n_over[4]++;
        }
        if (n_factor[i] >= 14)
        {
            n_over[14]++;
        }
        if (n_factor[i] >= 24)
        {
            n_over[24]++;
        }
        if (n_factor[i] >= 74)
        {
            n_over[74]++;
        }
    }
    int num_3_5_5 = n_over[4] * (n_over[4] - 1) * (n_over[4] - 2) / 2 + (n_over[2] - n_over[4]) * n_over[4] * (n_over[4] - 1) / 2;
    int num_15_5 = n_over[14] * (n_over[4] - n_over[14]) + n_over[14] * (n_over[14] - 1);
    int num_25_3 = n_over[24] * (n_over[2] - n_over[24]) + n_over[24] * (n_over[24] - 1);
    int num_75 = n_over[74];
    int ret = num_3_5_5 + num_15_5 + num_25_3 + num_75;
    return ret;
}

int main() 
{
    int n;
    std::cin >> n;
    set_n_factor(n);
    std::cout << solve(n) << std::endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int N;
	int R;
	int K;
	
	scanf("%d %d",&N,&R);
	getchar();
	
	if(N<10){
		printf("%d",100 * (10-N) + R);
	}
	else if  (N>=10){
		printf("%d",R);
	}
	
	return 0;
}

Measured memory_bytes: 3140
def main():
    N = int(input())
    red = [[int(i) for i in input().split()] + [True] for j in range(N)]
    blue = [[int(i) for i in input().split()] for j in range(N)]

    red.sort(reverse=True)
    blue.sort()
    ans1 = 0
    for b in blue:
        for a in red:
            if a[2] and a[0] < b[0] and a[1] < b[1]:
                ans1 += 1
                a[2] = False
                break

    red.sort(key=lambda p: p[1],reverse=True)
    red = [[r0,r1,True] for r0,r1,r2 in red]
    blue.sort(key=lambda p: p[1])
    ans2 = 0
    for b in blue:
        for a in red:
            if a[2] and a[0] < b[0] and a[1] < b[1]:
                ans2 += 1
                a[2] = False
                break

    red.sort(key=lambda p: p[1],reverse=True)
    red = [[r0,r1,True] for r0,r1,r2 in red]
    blue.sort()
    ans3 = 0
    for b in blue:
        for a in red:
            if a[2] and a[0] < b[0] and a[1] < b[1]:
                ans3 += 1
                a[2] = False
                break

    red.sort(reverse=True)
    red = [[r0,r1,True] for r0,r1,r2 in red]
    blue.sort(key=lambda p: p[1])
    ans4 = 0
    for b in blue:
        for a in red:
            if a[2] and a[0] < b[0] and a[1] < b[1]:
                ans4 += 1
                a[2] = False
                break

    print(max(ans1,ans2,ans3,ans4))

if __name__ == '__main__':
    main()

Measured memory_bytes: 41320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N, Q;
  cin >> N >> Q;
  int a[N - 1], b[N - 1];
  vector<int> adj[N];
  // 各頂点の親
  int g[N];
  for (int i = 0; i < N; i++) {
    g[i] = i;
  }
  for (int i = 0; i < N - 1; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    adj[a[i]].push_back(b[i]);
    adj[b[i]].push_back(a[i]);
    g[b[i]] = a[i];
  }
  int p[Q];
  ll x[Q];
  ll v[N]{};
  ll c[N]{};
  for (int i = 0; i < Q; i++) {
    cin >> p[i] >> x[i];
    p[i]--;
    c[p[i]] += x[i];
  }
  ll t = 0;
  deque<int> q;
  q.push_back(0);
  int vis[N]{};
  vis[0] = 1;
  while(!q.empty()) {
    int u = q.front();
    q.pop_front();
    for (int i : adj[u]) {
      if (vis[i] == 1) continue;
      vis[i] = 1; 
      c[i] += c[u];
      q.push_back(i);
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == N - 1) {
      cout << c[i] << "\n";
    } else {
      cout << c[i] << " ";
    }
  }
  return 0;
}

Measured memory_bytes: 23284
#include <iostream>
#include <string>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

const int N = 500000;
struct BIT {
	int val[N + 1];
	BIT() { int i; rep(i, N + 1) val[i] = 0; }
	void add(int p, int w) {
		for (int i = p; i <= N; i += i & -i) {
			val[i] += w;
		}
	}
	int sum(int p) {
		int ret = 0;
		for (int i = p; i > 0; i -= i & -i) {
			ret += val[i];
		}
		return ret;
	}
};

int n;
string s;
int q;
BIT seg[26];

int main() {
	int i, j;
	
	cin >> n >> s;
	rep(i, n) seg[s[i] - 'a'].add(i + 1, 1);
	
	cin >> q;
	rep(i, q) {
		int type;
		cin >> type;
		if (type == 1) {
			int p; char c;
			cin >> p >> c;
			seg[s[p - 1] - 'a'].add(p, -1);
			seg[c - 'a'].add(p, 1);
			s[p - 1] = c;
		}
		else {
			int l, r;
			cin >> l >> r;
			
			int cnt = 0;
			rep(j, 26) {
				int res = seg[j].sum(r) - seg[j].sum(l - 1);
				if (res > 0) cnt++;
			}
			cout << cnt << endl;
		}
	}
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

vector<int> to[MAX_N];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n, m;
	cin >> n >> m;

	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	queue<int> que;
	vector<int> dist(n, INF);
	vector<int> pre(n, -1);

	dist[0] = 0;
	que.push(0);

	while (!que.empty()) {
		int v = que.front();
		que.pop();
		
		for (int u : to[v]) {
			if (dist[u] != INF) {
				continue;
			}
			dist[u] = dist[v] + 1;
			pre[u] = v;
			que.push(u);
		}
	}
	
	cout << "Yes" << endl;
	rep(i, n) {
		if (i == 0) {
			continue;
		}
		int ans = pre[i];
		++ans;
		cout << ans << endl;
	}

	return 0;
}

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

int res[10000];

int as[1005];
int keys[1005];

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,m;cin>>n>>m;
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    int key=0;
    for(int j=0;j<b;j++){
      int c;cin>>c;c--;
      key = key | (1<<c);
    }
    as[i] = a;
    keys[i] = key;

    if(res[key]==0){
      res[key]=a;
    }else{
      res[key] =min(res[key], a);
    }
  }
  for(int j=0;j<m;j++){
    for(int i=0;i<(1<<n)-1;i++){
      int key = keys[j];
      if(res[i]){
        if(res[i | key]){
          res[i | key] = min(res[i | key], res[i] + as[j]);
        }else{
          res[i | key] = res[i] + as[j];
        }
      }
    }
  }

  // for(int i=0;i<5;i++){
  //   cout<<res[i]<<endl;
  // }

  if(res[(1<<n)-1]){
    cout<<res[(1<<n)-1]<<endl;
  }else{
    cout<<-1<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
	vector<int> v(3);
	cin>>v[0]>>v[1]>>v[2];
	sort(v.begin(),v.end());
	if(v[0]==5 and v[1]==5 and v[2]==7) cout<<"YES\n";
	else cout<<"NO\n";
	return 0;
}


Measured memory_bytes: 3576
# https://atcoder.jp/contests/abc083/tasks/arc088_a
# C - Multiple Gift
import math

x, y = list(map(int, input().split()))

# 一番小さい数でyが限界になるまで倍々していけばよい？
target_list = [x]
number = x

while number * 2 <= y:
    target_list.append(number * 2)
    number = number * 2

# print(target_list)
ans = len(target_list)
print(ans)


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

#define int long long int
#define ull unsigned long long int
#define for0(i, n) for (int i = 0; i < (int)(n); i++) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); i++) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); i++) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; i--) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; i--) // reverse 1 based


#define pb push_back
#define fi first
#define se second


#define all(x) (x).begin(), (x).end() 
#define rall(x) (x).rbegin, (x).rend() 
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) int((a).size())


using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef double ld;

//-------------------------------------------------------------------------------END----------------------------------------------------------------------------------//



bool inc(vi vec){
    for1(i,vec.size()-1){
        if(vec[i]<vec[i-1])return 0;
    }
    return 1;
}


void solve(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    
    int ans = b*d;
    ans = max(ans,a*c);
    ans = max(ans,a*d);
    ans = max(ans,b*c);
    cout<<ans;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(10);
    //cout << fixed;
    //int tt;cin>>tt;
    //while(tt--){
        solve();
    //}
    return 0;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll mod=998244353;
int main()
{
	ios;
	int n;
	cin>>n;
	if(n%1000) cout<<1000-n%1000;
	else cout<<0;
	
	return 0;
}

Measured memory_bytes: 3620