akhauriyash/Code-Regression huggingface dataset:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
X = list(map(int, input().split()))

Y = [(i, x) for i, x in enu(X)]
sY = sorted(Y, key=lambda x: x[1])
ssY = [(i,) + y for i, y in enu(sY)]
sssY = sorted(ssY, key=lambda x: x[1])
# print(Y)
# print(sY)
# print(ssY)
# print(sssY)

for i in range(N):
    tup = sssY[i]
    sor_ind, ini_ind, val = tup
    # print(tup)
    if sor_ind < N//2:
        print(sY[N//2][1])
    else:
        print(sY[N//2-1][1])




Measured memory_bytes: 123732
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
D = []
for i in range(min(K, X)):
    for j in range(min(K, Y)):
        if (i + 1) * (j + 1) > K:
            break
        for k in range(min(K, Z)):
            if (i + 1) * (j + 1) * (k + 1) > K:
                break
            else:

                D.append(A[i] + B[j] + C[k])

D.sort(reverse=True)
for i in range(K):
    print(D[i])

Measured memory_bytes: 8728
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static String ans="Yay!";
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//Map<Long,Integer>map=new HashMap<>();
		int n=5;
		int a[]=new int[n];
		//String s=sc.next();
		//int m=sc.nextInt();
		//int a=sc.nextInt();
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		int k=sc.nextInt();
		Arrays.sort(a);
		if(a[4]-a[0]>k)ans=":(";
		System.out.println(ans);
	}
}


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

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

int main(){
	int N;
	cin >> N;
	vector<LL> A(N);
	rep(i,N) cin >> A[i];
	map<LL,LL> s, d;
	for(LL i=0; i<N; i++){
		LL sum=(i+1)+A[i], dif=(i+1)-A[i];
		s[sum]++;
		d[dif]++;
	}
	LL ans=0;
	for(auto itr:s){
		ans+=itr.second*d[itr.first];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 39064
n, m = list(map(int, input().split()))
s = input()
t = input()

def gcd(a, b):
    if a == 0:
        return b
    elif b == 0:
        return a
    else:
        return gcd(b, a%b)

l = n*m//gcd(n,m)

nd = l//n
md = l//m

common = nd*md//gcd(nd,md)
nc = common//nd
mc = common//md

sol = True
for i in range(0, l, common):
    ind = i//common
    if s[ind * nc] != t[ind * mc]:
        sol = False
        break

print(l if sol else -1)

Measured memory_bytes: 9020
import Data.List(group, sort, nub)
import Control.Monad(replicateM)

main = do
  n <- readLn :: IO Int
  bs <- replicateM n getLine
  m <- readLn :: IO Int
  rs <- replicateM m getLine
  putStrLn $ show $ solve bs rs 

solve :: [String] -> [String] -> Int
solve bs rs = maximum $ 0 : (map fu words)
  where
    fu = calc (labeled bs) (labeled rs)
    words = nub (bs ++ rs)

labeled :: [String] -> [(String, Int)]
labeled ls = zipWith (\a b -> ((head a), length b)) sorted sorted
  where
    sorted = group $ sort ls

choose :: String -> [(String, Int)] -> (String, Int)
choose w [] = (w,0)
choose w ys
  | w ==  fst h = h
  | otherwise = choose w (tail ys)
  where
    h = head ys

calc :: [(String, Int)] -> [(String, Int)] -> String -> Int
calc bs rs w = subtract (snd r) (snd b)
  where
    b = choose w bs
    r = choose w rs

Measured memory_bytes: 636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

int main() {
        int n, a, b;
        scanf("%d%d%d", &n, &a, &b);
        printf("%d\n", min(a * n, b));
        return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<ll> VecX(N), VecY(M);
  for (ll i = 0; i < N; i++) {
    cin >> VecX[i];
  }
  for (ll i = 0; i < M; i++) {
    cin >> VecY[i];
  }
  const ll x_max = *max_element(cbegin(VecX), cend(VecX));
  const ll y_min = *min_element(cbegin(VecY), cend(VecY));

  string ans = "War";
  for (ll i = x_max + 1; i <= y_min; i++) {
    if (i > X && i <= Y) {
      ans = "No War";
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n,t,x,y;
int main()
{
	scanf("%d",&n);
	bool cnt=false;
	int x0=0,y0=0,t0=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&t,&x,&y);
		int d=abs(x-x0)+abs(y-y0);
		if(d<=abs(t-t0)&&d%2==abs(t-t0)%2) {x0=x;y0=y;t0=t;}
		else {cnt=true;printf("No\n");break;}
	}
	if(cnt==false) printf("Yes\n");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>

typedef long double ld;
typedef long long ll;

using namespace std;

int n, k;
vector<int> a;

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		a.push_back(t);
	}
	ll sum = 0;
	ll mmax = 0;
	for (int i = 0; i < k; i++) {
		sum += a[i];
	}
	mmax = sum;
	for (int i = k; i < n; i++) {
		sum += a[i];
		sum -= a[i - k];
		mmax = max(mmax, sum);
	}
	ld ans = (ld) (mmax) / (2.0 * k) + 0.5;
	printf("%.9Lf\n", k * ans);
	return 0;
}


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

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

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define MP make_pair
#define sz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

const int inf = (1LL << 60), mod = 1e9+7, nn = 2e5+5;

void solve(){
    int n, m;
    cin >> n >> m;
    if(m >= n) cout << "Yes";
    else cout << "No";
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf')] * n
dp[0] = 0

for i in range(1, n):
  for j in range(1, k+1):
    if i - j < 0:
      break
    cost = dp[i-j] + abs(h[i] - h[i - j])
    if cost < dp[i]:
      dp[i] = cost

print(dp[n-1])

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n; std::cin >> n;
    map<string, int> b;
    rep(i, n) {
        string s; std::cin >> s;
        b[s]++;
    }
    int m; std::cin >> m;
    map<string, int> r;
    rep(i, m) {
        string s; std::cin >> s;
        r[s]++;
    }
    int ans = 0;
    for (auto &p : b) {
        chmax(ans, p.se - r[p.fi]);
    }
    std::cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long LL;
LL dp[2][(1<<19)];
LL dp2[2][(1<<19)][21];
int r1[22], r2[22];
int nx[21][(1<<19)];
int main(){
	int n, m, k;
	cin >> n >> m >> k;
	n--;
	for(int i = 0; i < 22; i++){
		r1[i] = 0;
		r2[i] = 0;
	}
	for(int c = 0; c < n; c++){
		for(int i = 0; i < (1<<n); i++){
			nx[c][i] = -1;
			if( (i & (1<<c)) == 0) continue;
			nx[c][i] = i ^ (1<<c);
			for(int j = c-1; j >= 0; j--){
				if( (i & (1<<j)) == 0){
					nx[c][i] = i ^ (1<<j) ^ (1<<c);
					break;
				}
			}
		}
		/*for(int i = 0; i < (1<<n); i++){
			for(int a = n-1; a >= 0; a--){
				cout << (i >> a) % 2;
			}
			cout << " " << i << " ";
			for(int a = n-1; a >= 0; a--){
				cout << (nx[c][i]>>a) % 2;
			}
			cout << endl;
		}*/
	}
	for(int i = 0; i < k; i++){
		int a, b, c;
		cin >> a >> b >> c;
		b--;
		if(c) r1[a] |= (1<<(n-1-b));
		r2[a] |= (1<<(n-1-b));
	}
	for(int i = 0; i << (1<<n); i++){
		dp[0][i] = 0;
	}
	dp[0][0] = 1;
	for(int i = 1; i <= m; i++){
		int c = 1-i%2;
		int d = i%2;
		for(int j = 0; j < (1<<n); j++){
			for(int l = 0; l <= n; l++){
				dp2[c][j][l] = 0;
			}
			dp2[c][j][0] = dp[c][j];
		}
		for(int l = 1; l <= n; l++){
			for(int j = 0; j < (1<<n); j++){
				dp2[c][j][l] += dp2[c][j][l-1];
				if(nx[l-1][j] >= 0) dp2[c][j][l] += dp2[c][nx[l-1][j]][l-1];
				dp2[c][j][l] %= MOD;
				/*cout << j << " ";
				for(int a = n-1; a >= 0; a--){
					cout << (j >> a) % 2;
				}
				cout << " " << l << " ";
				cout << dp2[c][j][l] << " ";
				if(nx[l-1][j] >= 0){
					for(int a = n-1; a >= 0; a--){
						cout << (nx[l-1][j] >> a) % 2;
					}
				}
				cout << endl;*/
 
			}
		}
		for(int j = 0; j < (1<<n); j++){
			dp[d][j] = 0;
			if((j & r2[i]) != r1[i]){
				continue;
			}
			dp[d][j] = dp2[c][j][n];
			//if(dp[d][j] > 0) cout << d << " " << j << " " << dp[d][j] << endl;
		}
	}
	LL ans = 0;
	for(int j = 0; j < (1<<n); j++){
		ans += dp[m%2][j];
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 221568
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;

  vector<long long> num(k, 0);
  for (int i = 1; i <= n; i++) {
    num[i % k]++;
  }

  long long ans = 0;
  for (int a = 0; a < k; a++) {
    int b = (k - a) % k;
    int c = (k - a) % k;
    if ((b + c) % k != 0) {
      continue;
    }
    ans += (num[a] * num[b] * num[c]);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace

#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    	
        ll r;
        cin >> r;
        cout << r * r << '\n';
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int houses[4][3][10]={},n,b,f,r,v;
    cin >>n;
    for(int i=0;i<n;i++){
        cin >> b>> f>> r>>v;
        houses[b-1][f-1][r-1] += v;
        if(houses[b-1][f-1][r-1] < 0)
            houses[b-1][f-1][r-1] = 0;
        if(houses[b-1][f-1][r-1] > 9)
            houses[b-1][f-1][r-1] = 9;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++)
            for(int k=0;k<10;k++){
                cout << " "<< houses[i][j][k];
                if(k==9)
                    cout<<endl;
            }
        if(i<3)
            for(int t=0;t<20;t++){
                cout <<"#";
               if(t==19)
                    cout<<endl; 
            }
    }
}


Measured memory_bytes: 3100
#include <stdio.h>
int main(void){
    int ans=0;
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==1){
        a=100;
    }
    if(b==1){
        b=100;
    }
    if(a>b){
        printf("Alice\n");
    }else if(a<b){
        printf("Bob\n");
    }else{
        printf("Draw\n");
    }
    
    
    return 0;
}

Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: i64,
        m: i64,
    }
    println!("{}", combination(n, 2) + combination(m, 2));
}

fn combination(mut n: i64, k: i64) -> i64 {
    let mut result = 1;
    for i in 1..k {
        result = result * n / i;
        n = n - 1;
    }
    let a = result * n / k;
    a
}

Measured memory_bytes: 4352
unittest
{
	assert( [ "5 3", "50 100 80 120 80" ].solve == 210 );
	assert( [ "1 1", "1000" ].solve == 1000 );
}



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

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

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s"( n, k );
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	
	return ps.sort().take( k ).sum;
}


Measured memory_bytes: 2944
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int>>
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;cin>>n;
  	int sum=0,m;cin>>m;
  	for(int i=0;i<m;i++){
  	    int x;cin>>x;sum+=x;
  	}
  	if(sum>n)cout<<-1<<endl;
  	else cout<<n-sum<<endl;
    return 0;
}

Measured memory_bytes: 3668
#include <stdio.h>
 
long long num[200];
 
int main(){
    int N;
    scanf("%d",&N);
    
    for(int i = 0; i < N; i++){
        scanf("%d",num+i);
    }
    
    int cnt=0;
    while(1){
    char possible = 1;
    for(int i = 0; i < N; i++){
        if(num[i] & 1){ possible = 0; break;} 
    }
    if(possible){
        for(int i = 0; i < N; i++){
            num[i] /= 2;
        }
        cnt++;
    }else break;
    }
    printf("%d\n",cnt);
}

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

using namespace std;

int main() {
	string s;
	int a, z;
	cin >> s;
	a = s.size();
	z = 0;
	for (int i = 0; i != s.size(); i++){
		if (s[i] == 'A')a = min(a, i);
		if (s[i] == 'Z')z = max(z, i);
	}
	cout << z - a + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
using namespace std;
int n,a[400010],l=200005,r=200005;
bool reverse;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        if(reverse)a[--l]=x;else a[r++]=x;
        reverse=!reverse;
    }
    if(!reverse)for(int i=l;i<r;i++)printf("%d ",a[i]);
    else for(int i=r-1;i>=l;i--)printf("%d ",a[i]);
    return 0;
}


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

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

  int count = 0;
  int start, end;
  for(int i = 0; i < N; ++i) {
    cin >> start >> end;
    count += end - start + 1;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll mo = 1000000007;
ll dp[100][3]={};
int main()
{
ll n ;
cin >> n ;
dp[0][0]=1;
ll keta=64-__builtin_clzll(n);
rep(i,keta){
  if((n>>(keta-1-i)) & 1LL){
    dp[i+1][0]+=dp[i][0];
    dp[i+1][1]+=dp[i][0];
    dp[i+1][1]+=dp[i][1];
    dp[i+1][2]+=2*dp[i][1];
  }
  else{
    dp[i+1][0]+=dp[i][0];
    dp[i+1][0]+=dp[i][1];
    dp[i+1][1]+=dp[i][1];
    dp[i+1][2]+=dp[i][1];
  }
  dp[i+1][2]+=3*dp[i][2];
  rep(j,3)dp[i+1][j]%=mo;
}

cout << (dp[keta][0]+dp[keta][1]+dp[keta][2])%mo << endl;
return 0;
}


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

int main()
{
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;

  for (int i = 1; i < n - 1; i++) {
    int kari = 0;
    for (int j = 'a'; j <= 'z'; j++) {
      bool lflag = false, rflag = false;
      for (int a = 0; a < i; a++) {
        if (s[a] == j) lflag = true;
      }
      for (int a = i; a < n; a++) {
        if (s[a] == j) rflag = true;
      }
      if (lflag && rflag) kari++;
    }
    if (ans < kari) ans = kari;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	final static long MOD = 1000000007;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		long N = Long.parseLong(W);

		W = in.readLine();
		String[] Ws = W.split(" ");

		long[] A = new long[Ws.length];
		for (int i = 0; i < Ws.length; i++) {
			A[i] = Long.parseLong(Ws[i]);
		}

		Arrays.sort(A);

		long ans =0;
		for(int i=A.length-2;i>=A.length/3;i=i-2){
			ans+=A[i];
		}

		System.out.println(ans);
	}
}


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

int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++){
		if (i % 10 == 3 || i % 3 == 0 || (i / 10) % 10 == 3 || (i / 100) % 10 == 3 || (i / 1000) % 10 == 3){
			cout << " " << i;
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3096
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner stdIn = new Scanner(System.in);
        String s = stdIn.next();
        
        switch(s){
        case "SUN":
            System.out.println(7);
            break;
        case "MON":
            System.out.println(6);
            break;
        case "TUE":
            System.out.println(5);
            break;
        case "WED":
            System.out.println(4);
            break;
        case "THU":
            System.out.println(3);
            break;
        case "FRI":
            System.out.println(2);
            break;
        case "SAT":
            System.out.println(1);
            break;
        
        }
        
    }
}


Measured memory_bytes: 22996
#include <map>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
const int MAXN = 2e3+55;
int a[MAXN];
int main()
{
    int n;
    cin>>n;
    for(int i = 0; i < n; ++i)
        cin>>a[i];
    int ans = 1000000000;
    for(int k = -100; k <= 100; ++k)
    {
        int sum = 0;
        for(int i = 0; i < n; ++i)
        {
            sum += (a[i]-k)*(a[i]-k);
        }
        ans = min(ans,sum);
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
long long n;
using namespace std;
long long tran[6];
int main()
{
	cin >> n;
	for(int i = 0; i < 5; i++)
		cin >> tran[i];
	sort(tran,tran + 5);
	long long min = tran[0];
	long long res;
	n%min == 0? res = n/min : res = n/min + 1;
	res += 4;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n, pm, pe, pj;
  int i;

  // テァツ板淌・ツセツ津」ツ?ョテ、ツコツコテヲツ閉ーテ」ツつ津・ツ?・テ・ツ環?
  scanf("%d", &n);
  while(n != 0){
    for(i = 0; i < n; i++){
      // ティツゥツウテァツエツーテ」ツδ?」ツδシテ」ツつソテ」ツ?ョテ・ツ?・テ・ツ環?
      scanf("%d %d %d", &pm, &pe, &pj);

      // テ・ツ按、テ・ツョツ?
      if(pm == 100 || pe == 100 || pj == 100){
	printf("A\n");
      }else if(((pm + pe) / 2) >= 90){
	printf("A\n");
      }else if(((pm + pe + pj) / 3) >= 80){
	printf("A\n");
      }else if(((pm + pe + pj) / 3) >= 70){
	printf("B\n");
      }else if((((pm + pe + pj) / 3) >= 50) && (pm >= 80 || pe >= 80)){
	printf("B\n");
      }else{
	printf("C\n");
      }
    }

    // テァツ板淌・ツセツ津」ツ?ョテ、ツコツコテヲツ閉ーテ」ツつ津・ツ?・テ・ツ環?
    scanf("%d", &n);
  }

  return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	map<ll,ll> hoge;
	hoge[0]++;
	ll ruiseki = 0;
	for(auto&& item : a){
		ruiseki += item;
		hoge[ruiseki]++;
	}
	ll res = 0;
	for(auto&& item : hoge){
		res += item.second * (item.second - 1) / 2;
	}
	cout << res;
}


Measured memory_bytes: 13568
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    P = [ii() for _ in range(N)]
    mx = max(P)
    P.remove(mx)
    P.append(mx // 2)
    print(sum(P))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3932
def main():
    N, M  = map(int, input().split())
    l = []
    for i in range(M):
        a, b = map(int, input().split())
        c = map(int, input().split())
        k = sum(2 ** (i-1) for i in c)
        l.append((a, k))
    m = [float('inf')] * (2 ** N)
    m[0] = 0
    for i in range(M):
        for j in range(2 ** N):
            m[j | l[i][1]] = min(m[j | l[i][1]], m[j] + l[i][0])
    if m[-1] == float('inf'):
        print('-1')
    else:
        print(m[-1])
main()


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

A, B, C, D = map(int, input().split())

def gcd(x, y):
    if x < y:
        x, y = y, x
    if x % y == 0:
        return y
    return gcd(y, x % y)
    
s = C * D // gcd(C, D)

a = (A - 1) // C + (A - 1) // D - (A - 1) // s
b = B // C + B // D - B // s

print(B - A + 1 + a - b)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int main() {
        
        int n;
        cin  >> n;
        ll ans = 0,  b = 0;
        vector<int > a(n);
        for(int i = 0; i < n; ++i)
            cin >> a[i];
            
        for(int i = 0; i < n; ++i)
        {
            ans += (a[i]*b)%mod;
            b = (b+a[i])%mod;
        }
        cout << ans%mod;
}


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

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

	int aki = a - b;
	if(aki > c) {
		cout << 0 << endl;
	} else {
		cout << c - aki << endl;
	}
}

Measured memory_bytes: 256
S = list(input())
T = list(input())

def solve(S,T):
    m = 1000000
    
    for i in range(len(S)-len(T)+1):
        cnt = difference(T,S[i:i+len(T)])

        m = min(m,cnt)

    return m


def difference(a,b):
    c = 0
    for i in range(len(a)):
        if a[i] != b[i]:
            c+=1

    return c

print(solve(S,T))

Measured memory_bytes: 9104
#include<stdio.h>

int main()
{
    int R;

    scanf("%d",&R);
    int Q;
    int maxi=0;
    int total = 0;
    for(int i=1;i<=R;i++)
    {
        scanf("%d",&Q);
        total+=Q;
        if(Q>maxi)
        {
        maxi=Q;
        }
    }
    if(total-maxi>maxi)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 1632
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}
int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}
bool array_is_unique(const int* array, int n)
{
    for (int i = 0; i < n - 1; ++i) {
        if (array[i] == array[i + 1]) {
            return false;
        }
    }

    return true;
}

int main(){
  int n,k;
  long int i;
  int a[200000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
      scanf("%d",&a[i]);
  }
  qsort(a,n, sizeof(int), asc);
  if(array_is_unique(a,n)){
    printf("YES");
  }else{
    printf("NO");
  }
  return 0;
}

Measured memory_bytes: 1788
#include<iostream>
#include<stdio.h>
using namespace std;

int main(void) {
	string S;
	cin >> S;
	int month = atoi(S.substr(5, 2).c_str());
	// cout << month << endl;
	printf(month <= 4 ? "Heisei\n" : "TBD\n");
	return 0;
}


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

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

    static class CDaydream {
        private static final String YES = "YES";
        private static final String NO = "NO";

        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            out.println(in.string().matches("^(?:dream|dreamer|erase|eraser)*$") ? YES : NO);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

    }
}



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

int N;
ll inf = 1e9+7;
ll G[1001] = {0};


int main(){
	cin >> N;
	for(int i=2;i<=N;i++){
		int t = i;
		for(int j=2;j<=N;j++){
			while(t%j==0){
				G[j]++;
				t /= j;
			}
		}
	}
	ll ans = 1;
	for(int i=2;i<=N;i++){
		ans = (ans*(G[i]+1))%inf;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
h,w,k = map(int, input().split())

C = []
for _ in range(h):
  C.append([1 if i == '#' else 0 for i in input()])
C = np.array(C)
ans = 0
for i in range(2**h):
  for j in range(2**w):
    row = [l for l in range(h-1, -1, -1) if (i >> l) & 1]
    col = [l for l in range(w-1, -1, -1) if (j >> l) & 1]
    if len(row) > 0 and len(col) > 0:
      #print(row, col)
      s = C[row][:,col].sum()
      if len(row) > 1 and len(col) > 1:
        s = s.sum()
    else:
      s = 0
    if s == k:
      ans += 1
    #print(row, col, j)
print(ans)


Measured memory_bytes: 27092
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <time.h>
using namespace std;
typedef long long ll;
bool x[110], y[110];
int main() {
	int h, w,cnt=0;
	cin >> h >> w;
	char a[10][10];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
			if (a[i][j] == '#')cnt++;
		}
	}
	if (cnt == h + w - 1) {
		cout << "Possible" << endl;
		return 0;
	}
	else cout << "Impossible" << endl;
	system("PAUSE");
	return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 998244353LL
#define endl "\n"

//DPの考察が普通に難しかった。
//部分集合のさらに部分集合を考える場合は、もとの集合の各要素は３通りに遷移する。
//空集合でない部分集合という条件があるが、Sが正であるため、空集合ではないという条件は無視できる。

ll modbeki(ll x, ll n){
  ll res = 1LL;
  while(n > 0){
    if(n & 1){
      res *= x % MOD;
      res %= MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return res % MOD;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, S;
  cin >> N >> S;
  vll A(N+1);
  for(ll i = 1; i <= N; i++){
    cin >> A.at(i);
  }
  vvll dp(N+1, vll(3001, 0));
  dp.at(0).at(0) = 1;
  for(ll i = 1; i <= N; i++){
    for(ll j = 0; j <= S; j++){
      dp.at(i).at(j) += dp.at(i-1).at(j) * 2;
      dp.at(i).at(j) %= MOD;
      if(j + A.at(i) <= 3000){
        dp.at(i).at(j+A.at(i)) += dp.at(i-1).at(j);
        dp.at(i).at(j+A.at(i)) %= MOD;
      }
    }
  }
  cout << dp.at(N).at(S) << endl;
}


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

vector<int> sieve(int n) {
  vector<int> prime(n);
  for(int i=2; i<n; i++) prime[i]=i;
  for(int i=2; i*i<n; i++) {
    if(prime[i]) {
      for(int j=i*i; j<n; j+=i) prime[j]=0;
    }
  }
  return prime;
}

int main() {
  vector<int> prime=sieve(50001);
  int n;
  while(cin >> n && n!=0) {
    int cnt=0;
    for(int i=2; i<=n/2; i++) {
      if(prime[n-i] && prime[i]) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}


Measured memory_bytes: 1272
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
a = int(0.1*(9+A))
b = int(0.1*(9+B))
c = int(0.1*(9+C))
d = int(0.1*(9+D))
e = int(0.1*(9+E))
t_1 = 10*(a+b+c+d) + E
t_2 = 10*(b+c+d+e) + A
t_3 = 10*(c+d+e+a) + B
t_4 = 10*(d+e+a+b) + C
t_5 = 10*(e+a+b+c) + D
print(min([t_1,t_2,t_3,t_4,t_5]))

Measured memory_bytes: 3064
#include<stdio.h>

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

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

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, K;
int A[MAX_N];

int ans() {
	set<int> S;
	int cnt = 0;
	rep(i, 0, K) {
		S.insert(A[i]);
		if(i > 0) {
			cnt += (A[i - 1] > A[i]);
		}
	}
	int same = 0;
	int res = 0;
	rep(i, 0, N - K) {
		if(cnt == 0) same = 1;
		else {
			if(*(S.begin()) == A[i] && S.lower_bound(A[i + K]) == S.end()) {
			}
			else {
				res++;
			}
		}
		// debug(cnt, res, vi(all(S)));
		cnt -= (A[i] > A[i + 1]);
		cnt += (A[i + K - 1] > A[i + K]);
		S.erase(A[i]);
		S.insert(A[i + K]);
	}
	if(cnt == 0) same = 1;
	else res++;
	return res + same;
}

void solve() {
	cin >> N >> K;
	rep(i, 0, N) cin >> A[i];
	// sort(A, A + N);
	// do {
	// 	set<vi> S;
	// 	rep(i, 0, N - K + 1) {
	// 		vi vec(A, A + N);
	// 		sort(vec.begin() + i, vec.begin() + i + K);
	// 		S.insert(vec);
	// 	}
	// 	if(ans() != sz(S)) {
	// 		debug(vi(A, A + N), sz(S), ans());
	// 	}
	// } while(next_permutation(A, A + N));
	cout << ans() << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 10496
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(A, B),
    (A mod 3 =:= 0 ; B mod 3 =:= 0 ; (A + B) mod 3 =:= 0) -> writeln("Possible") ; writeln("Impossible").


Measured memory_bytes: 8084
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#include<string.h>
#include<string>
using namespace std;

#define ll long long int
#define ld long double
#define reps(i,f,n) for(int i=f;i<n;i++)
#define rep(i,n) reps(i,0,n)
#define m1 cout<<"move1"<<endl
#define m2 cout<<"move2"<<endl
#define m3 cout<<"move3"<<endl
#define m4 cout<<"move4"<<endl

bool lr(char c){
  if(c<=103 || ( c>=113 && c<= 116) || (c >= 118 && c<=120) || c == 'z')
    return true;
  else
    return false;
}


int main(){
  string s;

  while(cin>>s,s[0] != '#'){
    //ll num = strlen(s);
    ll ans = 0;
    bool flag = true;

    flag = lr(s[0]);

    reps(i,1,s.size()){
      if(lr(s[i]) != flag){
	  ans++;
	  flag = lr(s[i]);
	}
    }
    cout<<ans<<endl;
  }
  return 0;
}
	
	  
    
    
    
    
    

Measured memory_bytes: 3152
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var p = Partition(ar, 0, num - 1);
        if (p == 0)
            WriteLine($"[{ar[0]}] {string.Join(" ", ar.Skip(1).ToArray())}");
        else if (p == num - 1)
            WriteLine($"{string.Join(" ", ar.Take(num - 1).ToArray())} [{ar[num - 1]}]");
        else
            WriteLine($"{string.Join(" ", ar.Take(p).ToArray())} [{ar[p]}] {string.Join(" ", ar.Skip(p+1).ToArray())}");
    }
    private static int Partition(int[] ar,int left,int right)
    {
        var last = ar[right];
        var i= left-1;
        for(var j = left; j < right; j++)
        {
            if (ar[j] <= last)
            {
                i++;
                var t = ar[j];
                ar[j] = ar[i];
                ar[i] = t;
            }
        }
        var tmp = ar[i + 1];
        ar[i + 1] = ar[right];
        ar[right] = tmp;
        return i + 1;
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 33008
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = s.nextInt();
    }
    Arrays.sort(a);
    int minDiff = a[0];
    if (a[n-1] % 2 == 0) {
      for (int i = 0; i < n-1; i++) {
        if (Math.abs(a[n-1] / 2 - minDiff) > Math.abs(a[n-1] / 2 - a[i])) {
          minDiff = a[i];
        }
      }
    } else {
      for (int i = 0; i < n-1; i++) {
        if (Math.abs(a[n-1] - 2*minDiff) > Math.abs(a[n-1] - 2*a[i])) {
          minDiff = a[i];
        }
      }
    }
    System.out.printf("%d %d\n", a[n-1], minDiff);
  }
}


Measured memory_bytes: 50744
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,m;
int a[100005],b[100005];
vector<int>v[100005];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		int a,b;cin>>a>>b;
		v[a].push_back(b);
	}
	priority_queue<int>q;
	int ans=0;
	for(int i=m;i>=0;i--){
		int pos=m-i;
		for(auto x:v[pos]){
			q.push(x);
		}
		if(!q.empty()){
			ans+=q.top();
			q.pop();
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

bool kaibun(int num)
{
    int keta[5];
    for (int i = 0; i < 5; i++)
    {
        keta[i] = num % 10;
        num /= 10;
        // cout << "keta:" << keta[i] << endl;
    }
    if (keta[0] == keta[4])
    {
        if (keta[1] == keta[3])
        {
            return true;
        }
    }
    return false;
}
int main()
{
    int a, b;
    cin >> a >> b;
    int ans = 0;

    for (int i = a; i <= b; i++)
    {
        if (kaibun(i))
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int w,h;
int t[52][52];
int dx[] = {-1,0,1,-1,1,-1,0,1};
int dy[] = {-1,-1,-1,0,0,1,1,1};


void solve(int x,int y){
  t[y][x] = 0;
  rep(i,8){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(w>nx && nx>=0 && h>ny && ny>=0 && t[ny][nx]){
      solve(nx,ny);
    }
  }
}

int main(){
  while(cin>>w>>h,w||h){
    rep(i,h){
      rep(j,w){
        cin>>t[i][j];
      }
    }

    int cnt = 0;
    rep(i,h){
      rep(j,w){
        if(t[i][j]){
          solve(j,i);
          cnt++;
        }
      }
    }
    cout<<cnt<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long A, long long B){
	if ((N == 1 && A != B) || (A > B)) cout << "0" << endl;
	else if (N <= 2) cout << "1" << endl;
	else cout << B*(N-1)+A - (B+(N-1)*A) + 1 << endl;
}

int main(){	
	long long A;
	long long B;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&A);
	scanf("%lld",&B);
	solve(N, A, B);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <stack>

using namespace std;

string s;
string t;

int main(void) {

	cin >> s;
	cin >> t;

	int st = 0;

	for (int i = 0; i < s.size(); ++i) {
		auto it = s.begin();
		int a = s.size() - 1;
		it = s.insert(it, s[a]);
		s.pop_back();

		if (s == t) {
			st = 1;
			break;
		}
		
	}

	if (st == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner input=new Scanner(System.in);
		int max1=0,
			max2=0,
			max3=0;
		for(int i=0;i<10;i++){
			int newNum=input.nextInt();
			if(newNum>max1){
				max3=max2;
				max2=max1;
				max1=newNum;
			}
			else if(newNum>max2 && newNum<=max1){
				max3=max2;
				max2=newNum;
			}
			else if(newNum>max3 && newNum<=max2){
				max3=newNum;
			}
			
			//System.out.println(max1+" "+max2+" "+max3);
		}
		
		System.out.println(max1);
		System.out.println(max2);
		System.out.println(max3);
	}

}

Measured memory_bytes: 26100
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	string a, b, c; cin >> a >> b >> c;
	cout << a[0] << b[1] << c[2] << endl;
}

Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}};




ll a[6];
ll k;
int main() {


	rep(i, 5)
		cin >> a[i];

	cin >> k;
	rep(i, 5) {
		for (int j = i; j < 5; j++) {
			if (abs(a[i] - a[j]) > k) {
				cout << ":(" << endl;
				return 0;
			}

		}

	}


	cout << "Yay!" << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for(int i=0; i<N; i++)
    cin >> p[i];
  int b=0;
  for(int i=0; i<N-2; i++){
    if((p[i] <= p[i+1] && p[i+1] <= p[i+2])  || 
        (p[i] >= p[i+1] && p[i+1] >= p[i+2]))
      b++;
  }
  cout << b;
}

Measured memory_bytes: 256