akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int x = scanner.nextInt();
        final int y = scanner.nextInt();
        final int a = scanner.nextInt();
        final int b = scanner.nextInt();
        final int c = scanner.nextInt();

        final Function<Integer, List<Long>> listGenerator = length -> IntStream.range(0, length)
                .mapToObj(i -> scanner.nextLong())
                .sorted(Comparator.reverseOrder())
                .collect(Collectors.toList());

        final List<Long> aApples = listGenerator.apply(a);
        final List<Long> bApples = listGenerator.apply(b);
        final List<Long> cApples = listGenerator.apply(c);

        final List<Long> aSub = aApples.subList(0, x);
        final List<Long> bSub = bApples.subList(0, y);

        final Function<List<Long>, Long> sumList = list -> list.stream()
                .mapToLong(Long::longValue)
                .sum();

        long sum = sumList.apply(aSub) + sumList.apply(bSub);

        int aIndex = x - 1;
        int bIndex = y - 1;
        for (final long cApple : cApples) {
            final long aApple = aIndex >= 0 ? aSub.get(aIndex) : Integer.MAX_VALUE;
            final long bApple = bIndex >= 0 ? bSub.get(bIndex) : Integer.MAX_VALUE;
            if (aApple > cApple && bApple > cApple) {
                break;
            }

            if (aApple < bApple) {
                sum = sum - aApple + cApple;
                aIndex--;
            } else {
                sum = sum - bApple + cApple;
                bIndex--;
            }
        }
        System.out.println(sum);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

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


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

using namespace std;
string character[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

void solve()
{
	int N;
	cin >> N;
	for(int i = 0; i < N; ++i)
	{
		string s;
		cin >> s;
		for(int j = 0; j < s.size(); ++j)
		{
			int pos = j;
			int c = 0;
			if(s[pos] == '0')
			{
				continue;
			}
			else
			{
				c = s[pos] - '0';
			}
			bool zero_flag = true;
			while(s[pos] != '0')
			{
				++pos;
				if(pos >= s.size())
				{
					zero_flag = false;
					break;
				}
			}
			if(!zero_flag)
			{
				break;
			}
			if(pos > j)
			{
				--pos;
			}
			cout << character[c][(pos - j) % character[c].size()];
			j = pos;
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1212
N, X, Y = map(int, input().split())

X -= 1
Y -= 1
dist = [0]*(N-1)
for i in range(N):
    for j in range(i+1, N):
        dist[min(j-i, abs(X-i) + 1 + abs(Y-j))-1] += 1

print(*dist, sep="\n")

Measured memory_bytes: 74208
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

int ans;
char c[40][40];
int a,b;


void bfs(int sx, int sy) {
	queue< pair<int,int> > q;
	queue< PII > qp;
	q.push(MP(sx,sy));
	c[sx][sy] = 'x';
	for (int i = 1; i < 1000; i++) {
		while (!q.empty()) {
			PII v = q.front(); //get value
			q.pop();
			int x = v.first, y = v.second;
			if (c[x+1][y] == '.'){ qp.push(MP(x+1,y)); c[x+1][y] = 'x'; ans++; }
			if (c[x-1][y] == '.'){ qp.push(MP(x-1,y)); c[x-1][y] = 'x'; ans++; }
			if (c[x][y+1] == '.'){ qp.push(MP(x,y+1)); c[x][y+1] = 'x'; ans++; }
			if (c[x][y-1] == '.'){ qp.push(MP(x,y-1)); c[x][y-1] = 'x'; ans++; }

		}
		while (!qp.empty()) {
			q.push(qp.front());
			qp.pop();
		}
		//		for (int h = 0; h < b+2; h++) {
		//			for (int w = 0; w < a+2; w++) {
		//				cout << c[w][h];
		//			}
		//			cout << endl;
		//		}
		//		cout << endl;

	}
}

int main(int argc, char const* argv[])
{
	while (true) {
		int sx,sy;
		cin >> a >> b;
		if (a == 0 && b == 0) {
			break;
		}
		for (int h = 0; h < b+2; h++) {
			for (int w = 0; w < a+2; w++) {
				if (h == 0 || w == 0 || h == b+1 || w == a+1) {
					c[w][h] = '#';
				}
				else {
					cin >> c[w][h];
					if (c[w][h] == '@') {
						sx = w;
						sy = h;
					}
				}
			}
		}

		ans = 1;
		bfs(sx,sy);
		cout << ans << endl;
	}
	return 0;

}



Measured memory_bytes: 3124
#include <stdio.h>

int i, j, k, l, m, N, Q, X, r;
char S[200010], t[200010], d[200010];

int main(void) {
    scanf("%d%d\n", &N, &Q);
    scanf("%s\n", &S);
    for (j=0;j<Q;j++) scanf("%c%*c%c%*c", &t[j], &d[j]);
    l = 0; r = N-1;
    for (j=Q-1;j>=0;j--) {
        if (d[j] == 'R') {
            if (S[r] == t[j]) r--;
            if (S[l-1] == t[j]) l--;
        }
        if (d[j] == 'L') {
            if (S[l] == t[j]) l++;
            if (S[r+1] == t[j]) r++;
        }
//        printf("%d: %d %d\n", j, l, r);
    }

//    for (i=0;i<N;i++) printf("%d ", G[i]);
    if (r<l) X = 0; else X = r-l+1;
    printf("%d\n", X);
    return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
#include<string>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
int  main() {
	int a, b, n, t=0, y=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if (a == b)t++;
		else {
			if (y <= t) y = t;

			t = 0;
		}
	}
	if (y <= t)y = t;
	if (y >= 3)cout << "Yes";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 3632
n = int(input())
#a = list(map(int, input().split()))
#b = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(int(input()))

b = sorted(a)
m = max(b)

for i in range(n):
    if a[i]==m:
        print(b[-2])
    else:
        print(m)

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

int main()
{
	int a, b;
	long int c;
	cin >> a >> b;
	std::vector<int> vec(a);
	for (int i = 0; i < a; i++) {
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end());
	c = 0;
	for (int i = 0; i < a - b; i++) {
		c = c + vec[i];
	}
	cout << c;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
const int inf = 1e9+7;

class TreeDistanceConstruction { public: vector<int> construct(vector<int> d); };
vector<int> TreeDistanceConstruction::construct(vector<int> d) {
    int n = d.size();
    vector<int> result;
    int min_d = *whole(min_element, d);
    int cnt_min_d = whole(count, d, min_d);
    if (cnt_min_d == 1 or cnt_min_d == 2) { // construct
        int l = whole(find, d, min_d) - d.begin();
        int r;
        if (cnt_min_d == 1) {
            r = l;
        } else {
            r = find(d.begin() + l + 1, d.end(), min_d) - d.begin();
            result.push_back(l);
            result.push_back(r);
        }
        int m = l;
        int tick = 0;
        vector<int> que(n);
        whole(iota, que, 0);
        whole(sort, que, [&](int i, int j) { return d[i] < d[j]; });
        repeat_from (top, cnt_min_d, n) {
            int i = que[top];
            if (d[m] + 1 < d[i]) {
                tick = 0;
                m = l;
            }
            if (tick == 0) {
                result.push_back(l);
                result.push_back(i);
                l = i;
            } else if (tick == 1) {
                result.push_back(r);
                result.push_back(i);
                r = i;
            } else {
                result.push_back(m);
                result.push_back(i);
            }
            ++ tick;
        }
    } else {
        // impossible
    }
    if (not result.empty()) { // validate
        vector<vector<int> > dist = vectors(n, n, inf);
        repeat (i,n) dist[i][i] = 0;
        repeat (i,n-1) {
            int u = result[2*i  ];
            int v = result[2*i+1];
            dist[u][v] = 1;
            dist[v][u] = 1;
        }
        repeat (k,n) { // W/F
            repeat (i,n) {
                repeat (j,n) {
                    setmin(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
        vector<int> eccentricity(n);
        repeat (i,n) {
            repeat (j,n) {
                setmax(eccentricity[i], dist[i][j]);
            }
        }
        repeat (i,n) {
            if (d[i] != eccentricity[i]) {
                result.clear();
            }
        }
    }
    return result;
}


int main() {
    int n; cin >> n;
    vector<int> a(n); repeat (i,n) cin >> a[i];
    cout << (TreeDistanceConstruction().construct(a).empty() ? "Impossible" : "Possible")  << endl;
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    if(s.at(2)==s.at(3)&&s.at(4)==s.at(5)){
        cout << "Yes" << endl;
    }else{
        cout <<"No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <queue>
#include <vector>
using namespace std;

int W[1000000];
int n, k;

int check(long long p) {
	long long w;
	int i = 0;

	for (int j = 0; j < k; j++) {
		w = 0;
		while (W[i] + w <= p) {
			w += W[i];
			i++;

			if (i == n) return n;
		}
	}

	return i;
}

int search() {
	long long left = 0;
	long long right = 100000 * 10000;
	long long mid, v;

	while (right - left > 1) {
		mid = (left + right) / 2;
		v = check(mid);

		if (v >= n) {
			right = mid;
		}
		else {
			left = mid;
		}
	}

	return right;
}

int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> W[i];
	cout << search() << endl;
}


Measured memory_bytes: 3444
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
typedef long long ll;
const long long llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int n,i,ans;
pair<ll,int>a[nmax];
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n;
    for(i=1;i<=n;i++)cin>>a[i].fr,a[i].sc=i;
    sort(a+1,a+n+1);
    for(i=1;i<=n;i++)if((i&1) && !(a[i].sc&1))ans++;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e7+1;
const int MOD = 1000000007;
int K,S;
ll fac[MAXN],ifac[MAXN],inv[MAXN];
ll wfac[MAXN];
ll bio(int n,int m){
    return ((fac[n]*ifac[m])%MOD*ifac[n-m])%MOD;
}
char str[MAXN];
int main(){
    cin >> K;
    scanf("%s",str+1);
    S = strlen(str+1);
    ll ans = 1;
    for(int i=1;i<=K+S;i++){ans = (ans * 26)%MOD;}
    wfac[0]=fac[0]=ifac[1]=ifac[0]=inv[0]=inv[1]=1;
    for(int i=1;i<=K+S;i++){
        wfac[i] = (wfac[i-1]*25)%MOD;
        fac[i] = (fac[i-1] * i)%MOD;

    }
    for(int i=2;i<=K+S;i++){
        inv[i] = ((MOD-MOD/i)*inv[MOD%i])%MOD;
        ifac[i] = (ifac[i-1]*inv[i])%MOD;
    }
    for(int i=0;i<S;i++){
        ans -= (bio(K+S,i)*wfac[K+S-i])%MOD;
        ans %= MOD;
        ans = (ans + MOD)%MOD;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 67152
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
ll A, B;
ll x[100100];
int main()
{
	ll ans = 0;
	scanf("%d%lld%lld", &n, &A, &B);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &x[i]);
		if (i > 1)
			ans += min(B, A * (x[i] - x[i - 1]));
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1024
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

bool solve(int N) {
    int cnt[26] = {};
    
    V<int> sets[26];
    for(int i = 0; i < 26; i++) sets[i].push_back(i);
    bool exist[26] = {};
    int id[26];
    iota(id, id + 26, 0);

    auto merge = [&](int a, int b) {
        if(id[a] == id[b]) return;
        ll id_a = id[a];
        ll id_b = id[b];
        for(int e : sets[id_b]) {
            sets[id_a].push_back(e);
            id[e] = id_a;
        }
        sets[id_b].clear();
    };
    
    while(N--) {
        string a;
        cin >> a;
        int fst = a[0] - 'a';
        int snd = a.back() - 'a';
        cnt[fst]++;
        cnt[snd]--;
        merge(fst, snd);
        exist[fst] = exist[snd] = true;
    }

    set<int> components;
    for(int i = 0; i < 26; i++) {
        if(cnt[i]) return false;
        if(exist[i]) components.insert(id[i]);
    }
    
    return components.size() <= 1;
}

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;
        cout << (solve(N) ? "OK" : "NG") << endl;
    }
    return 0;
}



Measured memory_bytes: 3088
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
using namespace std;
typedef long long ll;

int main(){
  string s;
  cin >> s;
  ll ans = 700;
  if(s[0]=='o') ans+=100;
  if(s[1]=='o') ans+=100;
  if(s[2]=='o') ans+=100;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector <int> ar(n);
	for(int i=0; i<n; i++){
		cin >> ar[i];
	}
	vector <int> car = ar;
	sort(ALL(car)); reverse(ALL(car));
	
	for(int i=0; i<n; i++){
		if(ar[i] == car[0]) cout << car[1] << endl;
		else cout << car[0] << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
//    freopen("int.txt","r",stdin);

    int a,c,v;
    while(cin>>a>>c>>v)
    {

        if(a>c)
            swap(a,c);
        if(c>v)
            swap(c,v);
        if(a>c)
            swap(a,c);
        cout<<a<<" "<<c<<" "<<v<<endl;
    }
}



Measured memory_bytes: 3108
# -*- coding:utf-8 -*-
import copy

def solve():
    N, K = list(map(int, input().split()))
    V = list(map(int, input().split()))
    
    ans = 0
    M = min(N,K)
    for l in range(M+1):
        having = []
        for r in range(M+1):
            if l+r > M: break
            if l+r == 0: continue
            # 左からl, 右からr個の宝石を取り出す
            having = V[:l] + V[::-1][:r]
            having.sort(reverse=True)

            restK = K - (l+r)

            for _ in range(restK):
                if len(having)!=0 and having[-1] < 0:
                    having.pop()
                    continue
                break

            ans = max(ans, sum(having))
    
    print(ans)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3444
#include <iostream>
#include <string>
using namespace std;
int main(){

  int a,b,i;
  string c;

  for(i=0;i<9;i++){

    cin>>c>>a>>b;

    cout<<c<<" "<<a+b<<" "<<a*200+b*300<<endl;

  }

  return 0;

}
  

Measured memory_bytes: 3164
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const double PI = acos(-1);
const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,a,b;
    cin >> n >> a >> b;
    if((b - a) % 2 == 0) print((b - a) / 2);
    else print(min(a, n - b + 1) + (b - a - 1) / 2);
    


}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int A, B;
    cin >> A >> B;
    
    // calculation
    cout << (A+B+1)/2 << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1e18) + 1;

struct edge
{
    ll to;
    ll cost;
};

int V;
vector<edge> G[1000010];
vector<ll> d(1000010);

void dijkstra(int s)
{
    int i;
    priority_queue<P, vector<P>, greater<P>> q;
    fill(d.begin(), d.end(), INF);
    d[s] = 0;
    q.push(P(0, s));

    while (q.size())
    {
        P p = q.top();
        q.pop();
        int v = p.second;

        if (d[v] < p.first)
        {
            continue;
        }

        for (auto &x : G[v])
        {
            edge e = x;

            if (d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                q.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(void)
{
    int V, E, r;
    cin >> V >> E >> r;
    int i;
    ll x, y, z;

    rep(i, 0, E)
    {
        edge e;
        cin >> x >> y >> z;
        e.to = y;
        e.cost = z;
        G[x].push_back(e);
    }

    dijkstra(r);

    rep(i, 0, V)
    {
        if (d[i] == INF)
        {
            cout << "INF" << endl;
        }
        else
        {
            cout << d[i] << endl;
        }
    }
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, std::vector<long long> A){
    vector<int> cnt(N+1);
    rep(i,2,N+1) cnt[A[i-2]]++;
    rep(i,1,N+1) cout << cnt[i] << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-2+1);
    for(int i = 0 ; i < N-2+1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  ll a[n],ans=1,inv;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]==0){cout << 0 << endl;return 0;}
  }
  for(int i=0;i<n;i++){
    inv=(ll)1e18/ans;
    if(a[i]>inv){cout << -1 << endl;return 0;}
    ans*=a[i];
  }
  cout << (ans>(ll)1e18 ? -1 : ans) << endl;
}


Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
int n;
cin >> n;
vector<int> dp1(n + 1);
vector<int> dp2(n + 1);
rep(i, n)
{
    cin >> dp1[i + 1];
    dp1[i + 1] += dp1[i];
}
rep(i, n)
{
    cin >> dp2[i + 1];
    dp2[i + 1] += dp2[i];
    }
    int ans = 0;
    rep(i,n){
        ans = max(ans,dp1[i+1]-dp1[0]+dp2[n]-dp2[i]);
    }
    cout << ans << endl;
    return 0;
}

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

#define INF (1LL<<60)
int W, H;
int N;
long long xs[100010], ys[100010];
pair<int, int> P[100010];

int main() {
  cin >> W >> H >> N;
  for (int i=0; i<N; i++) {
    cin >> xs[i] >> ys[i];
    P[i] = make_pair(xs[i], ys[i]);
  }
  sort(xs, xs+N);
  sort(ys, ys+N);

  vector<int> med_x, med_y;
  if (N % 2 == 1) {
    med_x.push_back(xs[N/2]);
    med_y.push_back(ys[N/2]);
  }
  else {
    med_x.push_back(xs[N/2-1]), med_x.push_back(xs[N/2]);
    med_y.push_back(ys[N/2-1]), med_y.push_back(ys[N/2]);
  }

  long long ans = INF;
  int tx = -1, ty = -1;
  for (int x : med_x) {
    for (int y : med_y) {
      long long sum = 0LL, mx = 0LL;
      for (int i=0; i<N; i++) {
        long long d = abs(P[i].first-x) + abs(P[i].second-y);
        sum += 2*d;
        mx = max(mx, d);
      }
      long long v = sum - mx;
      if (ans > v) {
        ans = v;
        tx = x, ty = y;
      }
    }
  }
  cout << ans << "\n";
  cout << tx << " " << ty << "\n";
  return 0;
}

Measured memory_bytes: 5468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(void){
	string a, b, c; cin >> a >> b >> c;
	if(a.back() == b.front() && b.back() == c.front()){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}

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

using namespace std;
 
int main()
{
    int N;
    cin >> N;
    int result = 0;
    int max = 0;
    for (int i=0; i<N; i++) {
        int temp;
        cin >> temp;
        result += temp;
        if (max < temp) {max=temp;};
    }
    cout << result - (max/2) << endl;

    return 0;
}


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

int main(){
    string root;
    int sx, sy, tx, ty;
    int dx, dy;
    int i, j;

    cin >> sx >> sy >> tx >> ty;

    dx = tx - sx;
    dy = ty - sy;

    //root = NULL;
    //root = '\0';

    root = 'R';

    for (i=1; i<dx; i++){
        root = root + 'R';
    }
    for (i=0; i<dy; i++) {
        root = root + 'U';
    }
    for (i=0; i<dx; i++){
        root = root + 'L';
    }
    for (i=0; i<dy; i++) {
        root = root + 'D';
    }

    root = root +'L';
    for (i=0; i<dy+1; i++) {
        root = root + 'U';
    }
    for (i=0; i<dx+1; i++){
        root = root + 'R';
    }
    root = root +'D';

    root = root +'R';
    for (i=0; i<dy+1; i++) {
        root = root + 'D';
    }
    for (i=0; i<dx+1; i++){
        root = root + 'L';
    }
    root = root +'U';


    
    cout << root << endl;

}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int, Int> pii;
typedef pair<Int, double> pid;
typedef pair<double, double> pdd;
typedef pair<Int, pii> pip;
typedef pair<pii, Int> ppi;
typedef pair<double, Int> pdp;
typedef vector<Int> veci;
typedef vector<double> vecd;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<pii> vecpii;
typedef vector<ppi> vecppi;
typedef vector<veci> mati;
typedef vector<vecll> matll;
typedef vector<vecd> matd;
#define PB(x) push_back(x)
#define EB(x) emplace_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define REP(i, a, b) for(int i = (a);i <= (b);i++)
#define FORO(i, n) REP(i,0,(int)n-1)
#define FORI(i, n) REP(i,1,(int)n)
#define FORIT(i, t) for(auto i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a, _b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
#define DEBUG 1
#if DEBUG
#define DUMP(a) do { std::cout << #a " = " << (a) << ", "; } while(false)
#define DUMPLN(a) do { std::cout << #a " = " << (a) << std::endl; } while(false)
#else
#define DUMP(a)
#define DUMPLN(a)
#endif
template<typename T, typename U>
inline void getMin(T &a, U b) { if (a > b) a = b; }
template<typename T, typename U>
inline void getMax(T &a, U b) { if (a < b) a = b; }
template<typename T>
vector<T> getVector(const int n) { return vector<T>(n); }
template<typename T>
vector<T> getVector(const int n, const T a) { return vector<T>(n, a); }
template<typename T>
vector<T> getEmptyVector() { return vector<T>(); }
template<typename T>
void appendAll(vector<T> &a, vector<T> b) { a.insert(a.end(), b.begin(), b.end()); }
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
// #define X first
// #define Y second
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const ll MOD = 1000000007;
const int MAXN = 1 << 17;
const int inf = 1 << 27;
const ll llinf = 1LL << 50;
const int NIL = -inf;
int popcount(int x) { return __builtin_popcount(x); }


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

    int N;
    cin >> N;
    vector<pair<ll, ll>> ps(N);
    for(int i = 0;i < N;i++) cin >> ps[i].first >> ps[i].second;
    sort(ALL(ps));
    set<ll> S1, S2;
    ll ans = 0;
    for(int i = 0;i < N;i++) {
        if(i > 0) {
            ans = max(ans, max(ps[i].first - ps[i].second + *(S1.rbegin()), ps[i].first + ps[i].second + *(S2.rbegin())));
        }
        S1.insert((ll)- ps[i].first + ps[i].second);
        S2.insert((ll)- ps[i].first - ps[i].second);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 25100
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int A = 1e6 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

inline int read() {
	char c = getchar();
	int x = 0, f = 1;
	for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	return x * f;
}

int n, a[A], ans = 0;
char s[A];

int main() {
	int n = read();
	int left = 1, right = n;
	scanf("%s", s + 1);
	for (int i = 1; i <= n; i++) if(s[i] == 'W') a[i] = 1;
	int temp;
	while(left < right) { 
		while (left < right && a[left] == 0) left++;
		while (left < right && a[right] == 1) right--;
		if (left < right) {
			temp = a[left];
			a[left] = a[right];
			a[right] = temp;
			ans++;
		}
	}
  cout << ans << '\n';
}


Measured memory_bytes: 4732
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;

int main(){
  double r, s, l;
  cin >> r;
  s = r * r * M_PI;
  l = 2 * r * M_PI;
  cout << fixed << setprecision(6) << s << " " << l;
  return 0;
}



Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000000;
long long a[maxn];
long long n,g,i,ans;
int main(){
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i];a[i]-=i;
	}
	sort(a+1,a+n+1);
	g=a[(n-1)/2+1];
	for(i=1;i<=n;i++)ans+=abs(g-a[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5200
#include<iostream>
using namespace std;
int main(){
  char s;
  cin >> s;
  char v[] = { 'a', 'i', 'u', 'e', 'o', '\0' };
  int i=0;
  while(i<5){
    if(s==v[i]){
      cout << "vowel" << endl;
      break;
    }
    if(i==4){
      cout << "consonant" << endl;
    }
    i+=1;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <cstring>
#include <algorithm>
#define meow(args...) fprintf(stderr, args)
#define inc(x, y) (x=(x+y)%p)
typedef unsigned long long QWORD;
template<class Type> inline bool cmin(Type &a, const Type &b) {return b<a?(a=b, 1):0;}
template<class Type> inline bool cmax(Type &a, const Type &b) {return a<b?(a=b, 1):0;}
const unsigned p=1e9+7;
int n, fac[501], ifac[501], f[501][501], g[501][1001];
QWORD power(QWORD a, int b)
{
	QWORD ans=1;
	for(; b; a=a*a%p, b>>=1) if(b&1) ans=ans*a%p;
	return ans;
}
int main()
{
	int i, j, k;
	scanf("%d", &n);
	fac[0]=1;
	for(i=1; i<=n; ++i) fac[i]=(QWORD)fac[i-1]*i%p;
	ifac[n]=power(fac[n], p-2);
	for(i=n; i>=1; --i) ifac[i-1]=(QWORD)ifac[i]*i%p;
	f[1][0]=f[1][1]=fac[n];
	for(i=1; i<=n; ++i) {
		for(k=0; i+k<=n; ++k) for(j=k; j>=-n; j-=2) if(g[i][j+n]) inc(f[i+k][std::abs(j+k)/2], (QWORD)g[i][j+n]*ifac[k]);
		for(k=1; i+k<=n; ++k) for(j=0; j<=n&&j+3*k<=2*n; ++j) if(f[i][j]) inc(g[i+k][j-k+n], (QWORD)f[i][j]*ifac[k]);
		for(k=1; i+k<=n; ++k) for(j=k&1; j<=k&&j+3*k<=2*n; j+=2) if(f[i][j]) inc(f[i+k][(j+k)/2], (QWORD)f[i][j]*ifac[k]);
	}
	printf("%d\n", f[n][0]);
	return 0;
}


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

int main() {
  int N, x;
  cin >> N >> x;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) cin >> a[i];
  sort(begin(a), end(a));
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    x -= a[i];
    if (x < 0) break;
    ++ans;
  }
  if (x > 0) ans = max(ans - 1, 0);
  cout << ans << endl;
  return 0;
}


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

public class Main {
	
	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve() {
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		int t=sc.nextInt();
		System.out.println(Math.max(0,x-t));
	}
}


Measured memory_bytes: 23252
import java.math.BigDecimal;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		BigDecimal sum = BigDecimal.ZERO;
		List<Entry<Integer, Integer>> list = new ArrayList<>();
		for(int i =0; i < n; i++)
			list.add(new SimpleEntry<Integer,Integer>(sc.nextInt(), sc.nextInt()));
		
		list = list.stream()
				.sorted(Comparator.comparingInt(entry -> entry.getKey()))
				.collect(Collectors.toList());
		
		for(Entry<Integer, Integer> entry : list) {
			if(m == 0)
				break;
			
			BigDecimal a = BigDecimal.valueOf(entry.getKey());
			BigDecimal b = BigDecimal.valueOf(entry.getValue());

			if(m > entry.getValue()) {
				m-= entry.getValue();
				sum = sum.add(a.multiply(b));
			}else if(m <= entry.getValue()) {
				b = BigDecimal.valueOf(m);
				sum = sum.add(a.multiply(b));
				
				m = 0;
			}
		}
		
		System.out.println(sum.toString());
	}
}

Measured memory_bytes: 96712
import java.util.*;

public class Main{
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			while(true){
				int N = sc.nextInt(), M = sc.nextInt();
				if(N == 0 && M == 0){
					break;
				}
				int[] Vmin = new int[N], Vmax = new int[N];
				
				for(int i = 0; i < M; i++){
					int v = sc.nextInt();
					int num = sc.nextInt();
					for(int j = 0; j < num; j++){
						int p = sc.nextInt() - 1;
						Vmax[p] += v;
						if(num == 1){
							Vmin[p] += v;
						}
					}
				}

				int ansmin = 0, ansmax = 0;
				for(int i = 0; i < N; i++){
					if(Vmax[i] > Vmax[ansmax]){
						ansmax = i;
					} else if(Vmin[i] < Vmin[ansmin]){
						ansmin = i;
					}
				}

				System.out.println(Vmax[ansmax] - Vmin[ansmin] + 1);
			}
		}
	}
}

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


int main(void){
    int s, ans, cnt=1;
    std::cin >> s;
    std::vector<std::vector<int>> d(1000001, std::vector<int>(2, 0));
    ++d.at(s).at(1);

    while (true){
        ++cnt;
        if (s % 2 == 0) s /= 2;
        else s = 3 * s + 1;
        if (d.at(s).at(1) == 1) break;
        ++d.at(s).at(1);
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 57888
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int main() {
	int n, m;
	cin >> n >> m;
	pair<int, int>a[100010];
	for (int i = 0; i < m; i++) {
		int f, g;
		cin >> f >> g;
		a[i].first = g;
		a[i].second = f;
	}
	sort(a, a + m);
	int l = 0, ans = 0;
	for (int i = 0; i < m; i++) {
		if (a[i].first != a[i + 1].first && !(a[i].first > l&&a[i].second <= l)) {
			ans++;
			l = a[i].first - 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<stack>
using namespace std;
int main(){
  stack<int> s;
  int num;
  while(scanf("%d",&num)>0){
    if(num){
      s.push(num);
    }else{
      printf("%d\n",s.top());
      s.pop();
    }
  }
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int N,K,X,Y,x,i;
	x=0;
	scanf("%d%d%d%d",&N,&K,&X,&Y);
	if(N<K){
		for(i=0;i<N;i++){
			x+=X;
		}
	}
	else{
		for(i=0;i<K;i++){
			x+=X;
		}
		for(i=K;i<N;i++){
			x+=Y;
		}
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#define int long long

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

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = (int)1e9 + 7;

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

    int n, k;
    cin >> n >> k;

    vector<LL> x(n), y(n);
    REP(i, n) cin >> x[i] >> y[i];

    vector<LL> sortx = x, sorty = y;
    sort(all(sortx));
    sort(all(sorty));
    LL ans = INFL;
    for(int bot = 0; bot < n; bot++){
        for(int top = bot+1; top < n; top++){
            for(int left = 0; left < n; left ++){
                for (int right = left+1; right < n; right++) {
                    LL curx1 = sortx[right], curx2 = sortx[left];
                    LL cury1 = sorty[top], cury2 = sorty[bot];

                    int cnt = 0;
                    for(int i = 0; i < n; i++){
                        if(y[i] <= cury1 && y[i] >= cury2 && x[i] <= curx1 && x[i] >= curx2) cnt++;
                    }
                    if(cnt >= k){
                        ans = min(ans, (curx1 - curx2) * (cury1 - cury2));
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

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

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int N = 2e5 + 5;
int pre[N], suf[N];
char s[N];

int main()
{
	int n = read();
	scanf("%s", s + 1);
	for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + (s[i] == 'R');
	for (int i = n; i >= 1; --i) suf[i] = suf[i + 1] + (s[i] == 'R');
	
	int ans = n;
	for (int i = 0; i <= n; ++i)
	{
		int x = i - pre[i];
		int y = suf[i + 1];
		ans = min(ans, max(x, y));
	}
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 5452
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

int n;

main()
{
    cin>>n;

    map<string,int> m;
    set<string> s;
    rep(i,n)
    {
        string t;
        cin>>t;
        m[t]++;
        s.insert(t);
    }

    int max=0;
    vector<string> a;
    each(it,s)
    {
        //cout<<it<<" "<<m[it]<<endl;

        if(max<m[it])
        {
            a.clear();
            a.push_back(it);
            max=m[it];
        }else if(max==m[it])
        {
            a.push_back(it);
        }
    }

    sort(all(a));

    each(it,a)cout<<it<<endl;

}

Measured memory_bytes: 36212
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }

  vector<ll> visited(n, -1), path;
  ll res = 0, cnt = 0, cycle = 0;
  while (visited[res] == -1) {
    visited[res] = cnt;
    cnt++;
    res = a[res];
    if (visited[res] != -1) {
      cycle = cnt - visited[res];
      break;
    }
  }
  if (k < cnt) {
    rep(i, n) {
      if (visited[i] == k) {
        cout << i + 1 << '\n';
        return 0;
      }
    }
  }
  k = (k - visited[res]) % cycle + visited[res];
  rep(i, n) {
    if (visited[i] == k) {
      cout << i + 1 << '\n';
      return 0;
    }
  }
  





  
  return 0;
}

Measured memory_bytes: 6368
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector< ll > 	vi;
typedef pair< ll,ll > 	ii;

#define endl 		"\n"
#define pb		push_back
#define all(c) 		(c).begin(),(c).end()
#define rep(i,n)	for(ll i=0LL; i<(n); i++)
#define MOD 		1000000007
#define INF 		(int)1e9
#define MEM(a, b) 	memset(a, (b), sizeof(a))

double tick(){static clock_t oldt,newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt=newt;return diff;}

int main()
{	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);

	string s,t;
	cin>>s;
	cin>>t;
	int cnt=0;
	for(int i=0; i<s.size(); i++){
		if(s[i]!=t[i])
			cnt++;
	}
	cout<<cnt;

	
	// cout<<"\nExecution time : "<<tick()<<"\n";
	return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    ll a[n],k[n];
    rep(i,0,n)cin>>a[i]>>k[i];
    ll ans=0;
    rep(i,0,n){
        if(a[i]<k[i])continue;
        ll now=a[i];
        for(;;){
            if(now%k[i]==0){
                ans=ans^(now/k[i]);
                break;
            }
            ll u=now%k[i];
            ll y=now/k[i]+1;
            u/=y;
            if(u==0){
                now-=y;
            }
            else{
                now-=u*y;
            }
        }
    }
    if(ans==0)cout<<"Aoki"<<endl;
    else cout<<"Takahashi"<<endl;
    
}


Measured memory_bytes: 384
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,R = map(int, readline().split())

    if N >= 10:
        print(R)
    
    else:
        print(R + 100 * (10 - N))


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair < int,int > PII;
typedef pair < ll,ll > PLL;
#define pb push_back
//#all(x) (x).begin(),(x).end()

//int const N = 1;
int const MOD = 1e9 + 7;

ll bigmod(ll a, ll b)
{
    if(b==0)
        return 1 % MOD;
    ll x = bigmod(a,b/2);
    x = (x * x) % MOD;
    if(b%2)
        x = (x * a) % MOD;
    return x;
}

int const N = 3e5 + 10;

vector < int > g[N] ;
int dp[N] ;
int n,m;

int dfs(int node)
{
    int &r = dp[node];
    if(r != -1) return r;

    r = 1;
    int mx = 0;
    for(auto v : g[node])
    {
        mx = max(mx,dfs(v));
    }
    r += mx;
    return r;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    memset(dp,-1,sizeof dp);
    cin >> n >> m;

    for(int i = 1; i <= m; i++)
    {
        int a,b;
        cin >> a >> b;
        g[a].pb(b);
    }
    memset(dp,-1,sizeof dp);

    int ans = 0;
    for(int i = 1; i <= n;i++)
        ans = max(ans, dfs(i) - 1);
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 13696