akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define INF (1LL << 30)
#define int long long
#define pii pair<long long, long long>
#define MOD 1000000007
#define print(x) cout << (x) << endl
using namespace std;
typedef long long ll;

vector<vector<pii>> graph(100011);
vector<int> dst(100011, -1);
bool visited[100011] = {false};
void dfs(int k, int now, int distance){ // Kからの距離をアレする
    // dst[k] : 0に初期化する
    if (visited[now]) return;
    visited[now] = true;
    for (auto z : graph[now]){
        /*
        if (dst[z.first] >= 0){
        dst[z.first] = min(dst[z.first], (distance + z.second));
        } else dst[z.first] = distance + z.second;
        */
       if (dst[z.first] < 0) dst[z.first] = distance + z.second;
        dfs(k,z.first,dst[z.first]);
    }
}

int query(int x, int y){
    return dst[x] + dst[y];
}


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

    rep(i,N-1){
        int a, b,c;
        cin>>a>>b>>c;
        --a;--b;
        graph[a].push_back(make_pair(b,c));
        graph[b].push_back(make_pair(a,c));
    }
    int Q,K;
    cin>>Q>>K;--K;// 0 index

    dfs(K, K, 0);

/*
    cout<<"dst:"<<endl;
    rep(i,N){
        cout<< "i:"<<i<<"  : "<<dst[i]<<endl;
    }
*/
    int x,y;
    int ans;
    rep(i,Q){
        cin>>x>>y;
        --x;--y;
        cout<<query(x,y)<<endl;
    }

    return 0;
}

Measured memory_bytes: 14464
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define from_to(from, to, i) for(int i=from;i<=to;i++)

using namespace std;
typedef long long ll;
const int MAX = 1000010;
const int INF = 1<<29;

int main(int argc, char const* argv[])
{
    vector<int> V;
    for (int i = 1; i*(i+1)*(i+2)/6 < MAX; i++) {
        V.push_back(i*(i+1)*(i+2)/6);
    }

    int all[MAX], odd[MAX];
    fill(all, all+MAX, INF);
    fill(odd, odd+MAX, INF);

    all[0] = odd[0] = 0;
    for (int v : V) {
        loop (v, i) {
            for (int j = 1; i+v*j < MAX; j++) {
                all[i+v*j] = min(all[i+v*j], all[i+v*(j-1)] + 1);

                if (v%2) {
                    odd[i+v*j] = min(odd[i+v*j], odd[i+v*(j-1)] + 1);
                }
            }
        }
    }

    while (1) {
        int n; cin >> n;
        if (!n) break;
        printf("%d %d\n", all[n], odd[n]);
    }

    return 0;
}

Measured memory_bytes: 9004
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
using pii=std::pair<int,int>;

using namespace std;

int n,a[20],cnt=0;
class BOrdinaryNumber {
public:
	void solve(std::istream& in, std::ostream& out) {
    	in >> n;
		f(i,0,n)
			in >> a[i];
		f(i,1,n-1)
			if(a[i]>min(a[i+1],a[i-1])&&a[i]<max(a[i+1],a[i-1]))
				cnt++;
			out << cnt << "\n";
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	BOrdinaryNumber solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
using ll = long long;
using vi = vector<int>;
int main()
{
    int N;
    cin >> N;
    map<int,int> mp;
    int input0;
    REP(i, N) {
        cin >> input0;
        mp[input0]++;
        mp[input0+1]++;
        mp[input0-1]++;
    }

    int ans = 0;
    REP(x, 100000) {
        ans = max(ans, mp[x]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
// AtCoder Beginner Contest 152

// Task C

// Coded by kintak

#include <bits/stdc++.h>

#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O3")


using namespace std;

long long i, x = 0, n, j, pr[200001], p[200001], ans = 0;

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (i = 1; i <= n; i++) cin >> p[i];
	for (i = 1; i <= n; i++) pr[i] = 1e18;
	pr[1] = p[1];
	for (i = 2; i <= n; i++) pr[i] = min(p[i], pr[i - 1]);
	for (i = 2; i <= n; i++)
		if (p[i] <= pr[i-1]) ans++;
	cout << ans + 1;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
int a[100005],b[100005];
int main()
{
    int n,H;
    cin>>n>>H;
    for(int i=1;i<=n;i++)
    {
    	cin>>a[i]>>b[i];
    }
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    int ans=0;
    for(int i=n;i>=1;i--)
    {
        if(b[i]>=a[n]&&H>0)
        {
            H-=b[i];
            ans++;
        }
    }
    if(H>0)
    {
        ans+=H/a[n];
        if(H%a[n]!=0)
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
s = list(input())
abc = ["a", "b", "c", "d", "e", "f","g" , "h", "i", "j", "k", "l","m", "n" ,"o" ,"p" ,"q" ,"r" ,"s", "t", "u", "v", "w", "x", "y", "z"]
for i in range(len(s)):
    if s[0] in abc:
        abc.remove(s.pop(0))
    else:
        s.pop(0)
if len(abc) == 0:
    print("None")
else:
    print(abc[0])

Measured memory_bytes: 3956
# reference: https://youtu.be/TUdZT1wIbe8?t=2810

# nCk 前処理メモ
INF = 10 ** 6
MOD = 10 ** 9 + 7
N = INF * 2
@fac = [1, 1]
@inv = [1, 1]
@finv = [1, 1]

(2..N).each do |i|
  @fac[i] = @fac[i - 1] * i % MOD
  @inv[i] = MOD - @inv[MOD % i] * (MOD / i) % MOD
  @finv[i] = @finv[i - 1] * @inv[i] % MOD
end

def nCk(n, k)
  return 0 if n < k || n < 0 || k < 0
  @fac[n] * (@finv[k] * @finv[n - k] % MOD) % MOD
end

def repeated_nCk(n, k)
  # 仕切りのイメージで
  nCk(n + k - 1, n - 1) % MOD
end

k = gets.to_i
s = gets.chomp
s_size = s.size

twentyfive_memo = [1]
twentysix_memo = [1]
(0..INF * 2).each do |i|
  twentyfive_memo[i + 1] = twentyfive_memo[i] * 25 % MOD
  twentysix_memo[i + 1] = twentysix_memo[i] * 26 % MOD
end

ans = 0
# 前半を選ぶ個数
0.upto(k) do |former|
  # nCk は、区切り文字を選ぶ組み合わせ
  ans += twentyfive_memo[former] * nCk(former + s_size - 1, s_size - 1) * twentysix_memo[k - former] % MOD
  ans %= MOD
end
puts ans


Measured memory_bytes: 94388
#include<bits/stdc++.h>
using namespace std;
int keta(long n){
    int ans = 0;
    while(n>0){
        ans++;
        n/=10;
    }
    return ans;
}
int main(){
    long n;
    cin >> n;
    long tmp = sqrt(n);
    for(long i=tmp;i>=1;i--){
        if(n%i==0){
            cout << max(keta(i),keta(n/i))<<endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int N;
    cin >> N;
    vector <string> S(N);
    vector <int> P(N) , T(N);
    vector <tuple<string , int , int>> A(N);
    for(int i = 0; i < N; i++){
        cin >> S[i] >> P[i];
        T[i] = i;
        A[i] = make_tuple(S[i] , -P[i] , T[i]);
    }
    sort(A.begin() , A.end());
    for(int i = 0; i < N; i++){
        cout << get<2>(A[i]) + 1 << endl;
    }
}


Measured memory_bytes: 3664
#include<stdio.h>
int main(void){
    int S,h,m,s;
    scanf("%d",&S);
    h=S/3600;
    m=(S-3600*h)/60;
    s=S-3600*h-60*m;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<long long>A(N);
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    if (N % 2 == 0) {
        for (int i = 0; i < N / 2; i++) {
            ans += A.at(N-1-i) * 2;
        }
        cout << ans - A.at(N-1);
    }
    else {
        for (int i = 0; i < N / 2 + 1; i++) {
            ans += A.at(N-1-i) * 2;
        }
        cout << ans - A.at(N-1) - A.at(N-1-N/2);
    }
}

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



int main(){
    long long n,q;
    cin >> n;
    vector<long long> A(100001,0);
    long long sum=0;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        sum+=a;
        A[a]++;
    }

    cin >> q;

    for(int i=0;i<q;i++){
        int b,c;
        cin >> b >> c;
        int cnt = A[b];
        sum += c*cnt -b*cnt;
        cout << sum << endl;

        A[b] -= cnt;
        A[c] += cnt;
    }
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) ; cout.tie(NULL);
#define INF 0x3f3f3f3f3f

int main() {

    fastio;

    ll n;
    vector<vector<ll>> happiness(100005 , vector<ll>(3));
    vector<vector<ll>> dp(100005 , vector<ll>(3));

    cin >> n;
    for(ll i = 0; i < n; i++) cin >> happiness[i][0] >> happiness[i][1] >> happiness[i][2];

    //OPTIMAL SUBPROBLEM :

    //dp[i][j] = maximum happiness obtained by doing the jth task on ith day

    // BASE CASE :

    dp[0][0] = happiness[0][0];
    dp[0][1] = happiness[0][1];
    dp[0][2] = happiness[0][2];


    // RECURSIVE RELATION :

    for(ll i = 1; i < n; i++){
        dp[i][0] = max(dp[i-1][1] , dp[i-1][2]) + happiness[i][0];
        dp[i][1] = max(dp[i-1][0] , dp[i-1][2]) + happiness[i][1];
        dp[i][2] = max(dp[i-1][0] , dp[i-1][1]) + happiness[i][2];
    }

    //OPTIMAL SOLUTION :

    cout << max(max(dp[n-1][0] , dp[n-1][1]) , dp[n-1][2]);

    return 0;
}

Measured memory_bytes: 11264
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int N=300005;
int n,k;
int a[N];
int main()
{
	scanf("%d%d",&k,&n);	
	if (k&1)
	{
		for (int u=1;u<=n;u++) a[u]=k/2+1;
		int t=n/2;
		int now=n;
		while (t--)
		{
			if (a[now]==1) now--;
			else
			{
				a[now]--;
				while (now<n)	a[++now]=k;
			}
		}
		for (int u=1;u<=now;u++) printf("%d ",a[u]);
	}
	else
	{
		printf("%d ",k/2);for (int u=2;u<=n;u++) printf("%d ",k);
	}
	return 0;
}

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

int main(){
	int nedan; //商品の値段 1<=nedan<=10000
	cin >> nedan;
 	int oturi = nedan%1000; //おつり計算用
	if(oturi == 0) {cout << oturi << endl;}
  	else		  {cout << 1000-oturi << endl;}
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;



int main(){
    ll N, K;
    cin>>N>>K;
    vector<ll> A(N);
    vector<ll> B(N, -1);
    rep(i, N){
        cin>>A[i];
        A[i]--;
    }
    B[0]=0;
    ll Time=0;
    ll Now=0;
    ll Roop=-1;
    while(1){
        Now=A[Now];
        Time++;
      	if(Time==K){
          	cout<<Now+1<<endl;
          	return 0;
        }
        if(B[Now]>=0){
            Roop=Now;
            break;
        }
        else{
            B[Now]=Time;
        }
    }
    K-=B[Roop];
    ll F=Time-B[Roop];
    K%=F;
    Now=Roop;
    rep(i, K){
        Roop=A[Roop];
    }
    cout<<Roop+1<<endl;
    return 0;
}

Measured memory_bytes: 6428
#include <vector>
#include <cassert>
#include <iostream>
using namespace std;
int A, B, C, pw[900009], fact[900009], inv[900009], finv[900009], mod = 1000000007;
int comb(int x, int y) {
	return y < 0 || x < y ? 0 : 1LL * fact[x] * finv[y] % mod * finv[x - y] % mod;
}
int main() {
	cin >> A >> B >> C;
	pw[0] = fact[0] = inv[1] = finv[0] = 1;
	for (int i = 1; i <= A + B + C; i++) {
		if (i >= 2) inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
		pw[i] = 3LL * pw[i - 1] % mod;
		fact[i] = 1LL * fact[i - 1] * i % mod;
		finv[i] = 1LL * finv[i - 1] * inv[i] % mod;
	}
	int ret = 0, cur = 1;
	for (int i = 0; i <= B + C; i++) {
		if (i > B) cur = (cur - comb(i - 1, B) + mod) % mod;
		if (i > C) cur = (cur - comb(i - 1, C) + mod) % mod;
		ret = (ret + 1LL * pw[B + C - i] * cur % mod * comb(A + i - 1, A - 1)) % mod;
		cur = 2 * cur % mod;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 14336
S = input()
n = len(S)
shift_max = [0]*(n+1)

big_run = 0
for i in range(n):
    if S[i] == '<':
        big_run += 1
    else:
        big_run = 0
    shift_max[i+1] = big_run
small_run = 0
for i in reversed(range(n)):
    if S[i] == '>':
        small_run += 1
    else:
        small_run = 0
    shift_max[i] = max(shift_max[i],small_run)


print(sum(shift_max))



Measured memory_bytes: 81908
import sys
from collections import Counter
from functools import reduce

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


n = read_int()
c = []
for i in range(n):
    s = read_str()
    c.append(Counter(s))

r = reduce(lambda x, y: x & y, c)
l = sorted(r.elements())
res = ''.join(l)
print(res)


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b) (v)[(a)].pb(b),(v)[(b)].pb((a))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 1005;
using namespace std;
ll n,arr[N][4],memo[N][4];
ll solve(ll ind,ll lst)
{
    if(ind == n)
        return 0;
    ll &ans = memo[ind][lst];
    if(~ans)
        return ans;
    ans = 0;
    for(int i = 0;i<3;i++)
        if(i!=lst)
            ans = max(ans,solve(ind+1,i) + arr[ind][i]);
    return ans;
}
int main()
{
    abdelrahman001
    memset(memo,-1,sizeof memo);
    cin >> n;
    for(int i = 0;i<n;i++)
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
    cout << solve(0,3);
    return 0;
}


Measured memory_bytes: 12800
def main():
    # 下、右、上、左
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == "#" and\
                    "." == s[y + dy[0]][x + dx[0]]\
                    == s[y + dy[1]][x + dx[1]]\
                    == s[y + dy[2]][x + dx[2]]\
                    == s[y + dy[3]][x + dx[3]]:
                print("No")
                return
    print("Yes")
    return


main()


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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> to(n);
    for(int i=1; i < n; i++){
        int A;
        cin >> A;
        A--;
        to.at(A).push_back(i);
    }
    for(int i = 0; i < n; i++) {
        cout << to.at(i).size() << endl;
    }
}


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

void fst()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
int nxt()
{
    int x;
    cin >> x;
    return x;
}
int nex_l()
{
    long long x;
    cin >> x;
    return x;
}

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define binary(n) cout << bitset<31>(n) << "\n";
#define FOR(i, n) for (int i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define input_arr(a, n)         \
    for (int i = 0; i < n; i++) \
        cin >> a[i];
#define print_arr(a, n)         \
    for (int i = 0; i < n; i++) \
        cout << a[i] << " ";
#define deb(n) cerr << #n << "=" << n << "\n";

int main()
{

    int n;
    cin >> n;
    map<string, int> m;
    while (n--)
    {
        string s;
        cin >> s;
        m[s]++;
    }
    string pr[4] = {"AC", "WA", "TLE", "RE"};
    for (int i = 0; i < 4; i++)
    {
        cout << pr[i]<<" x " << m[pr[i]]<<"\n";
    }
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace abc159c
{
    class Program
    {
        static void Main(string[] args)
        {
         
            int input3 = int.Parse(Console.ReadLine());

            double a = input3 / 3.0;
            


            //==========================================================================================================================
            //2) output
            double output = Math.Pow(a,3);
            Console.WriteLine(output);




        }
    }
}


Measured memory_bytes: 11092
fun main(args: Array<String>) = IO().exec {
    val s = string().toCharArray()
    var k = long()
    for (i in s.indices) {
        if (s[i] != 'a' && 'z' + 1 - s[i] <= k) {
            k -= 'z' + 1 - s[i]
            s[i] = 'a'
        }
    }
    if (k > 0) s[s.size-1] =
            (((s[s.size-1].toLong() + k - 'a'.toLong()) % 26).toInt() + 'a'.toInt()).toChar()
    println(s.joinToString(""))
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}
// endregion

Measured memory_bytes: 38688
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cassert>
#include <cstring>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int main(void) {
    long long q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    h = min(q * 2, h);
    s = min(h * 2, s);
    d = min(s * 2, d);
    cout << (n / 2 * d + n % 2 * s) << endl;
}

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

typedef long long ll;
typedef pair<int,int> Pi;
const ll inf = 1e18 + 1;
const ll limit = 1e9;

int main() {
    ll a; cin >> a;
    string s; cin >> s;
    ll b = (s[0] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0');
    cout << (ll)(a * b) / 100 << "\n";
}   
 

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


int main() {
	
	int a, b, c;
	cin >> a >> b >> c;
	set<int>d;
	d.insert(a);
	d.insert(b);
	d.insert(c);
	if (d.size()==2) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

signed main() {
    int N, K;
    cin >> N >> K;
    int A[N];
    for (int i = 0; i < N; i++) cin >> A[i];

    int dp[N+1][K+1];
    fill(dp[0], dp[N+1], 0);
    dp[0][0] = 1;

    for (int i = 0; i < N; i++) {
        int acc = 0;
        for (int j = 0; j <= K; j++) {
            acc += dp[i][j];
            if (j - A[i] - 1 >= 0) acc -= dp[i][j - A[i] - 1];
            acc = (acc % MOD + MOD) % MOD;
            dp[i+1][j] = acc;
        }
    }

    cout << dp[N][K] << endl;
}

Measured memory_bytes: 79104
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	int n, x;
	long long int count = 0;
	int a[100001];

	cin >> n >> x;

	FOR(i, 1, n) {
		cin >> a[i];
	}
	FOR(i, 2, n) {
		if (a[i - 1] + a[i] <= x) {
			continue;
		}else if (a[i - 1] <= x) {
			count += a[i] - (x - a[i - 1]);
			a[i] -= a[i] - (x - a[i - 1]);
		}
		else if (a[i - 1] > x) {
			count += a[i];
			a[i] = 0;
			count += (a[i - 1] - x);
			a[i - 1] -= (a[i - 1] - x);
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int n,a,b;
    cin>>n>>a>>b;
    int res = 0;
    rep(i,n+1){
        int k = i;
        int p = 0;
        while(k!=0){
            p += k%10;
            k/=10;
        }
        if(a<=p&&p<=b)res+=i;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
int main() {
    int n,m;
    cin>>n>>m;
    vector<vector<int>> v(n,vector<int>());
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    
    for(auto s : v[n-1]){
        for(auto t : v[s]){
            if(t == 0){
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 15016
#include <iostream>

using namespace std;

int main() {
  string s;
  cin >> s;
  int N = s.length();
  int red = 0;
  int blue = 0;
  
  for (int i=0; i< N; i++) {
    if (s[i] == '0') {
      red++;
    } else {
      blue++;
    }
  }
  if (red > blue) {
    cout << (2 * blue);
  } else {
    cout << (2 * red);
  }
  
  return 0;
}

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

int main() {
    string s; cin >> s;
    if(s.size()%2!=0){
        cout << "No" << endl;
        return 0;
    }     
    for (int i = 0; i < s.size()/2; i+=2)
    {
        if(s[i*2] != 'h' || s[i*2+1] != 'i'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>
// #include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
// using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

typedef vector<int> vec;
typedef vector<vec> mat;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N; cin >> N;
    string S; cin >> S;

    int ans = 1;
    for (int i = 1; i < N; i++) {
        if (S[i] != S[i-1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
A,B,C,D,E,F = map(int,input().split(" "))
LOOP_A = int(F / (100*A)) + 1
LOOP_B = int(F / (100*B)) + 1
LOOP_C = int((F-100) / C) + 1
LOOP_D = int((F-100) / D) + 1
ans = []
temp = []
for i in range(LOOP_A):
    Ac = i
    for j in range(LOOP_B):
        Bc = j
        W = Ac * A * 100 + Bc * B * 100
        if W >= 100 and W <= F:
            for k in range(LOOP_C):
                Cc = k
                if W + (Cc * C) <= F:
                    for l in range(LOOP_D):
                        Dc = l
                        S = Cc * C + Dc * D
                        total = W + S 
                        SW = S / W
                        #print(Dc)
                        if F >= total and SW <= E/100:
                            ans.append(str(total) + " " + str(S))
                            temp.append(S / total)
print(ans[temp.index(max(temp))])

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

struct Node{
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;



// ここからプロトタイプ宣言
void insert(int k);
void inOrder(Node *u);
void preOrder(Node *u);
// ここまでプロトタイプ宣言

int main(){
	int n;	cin>>n;
	string com;

	int x;
	for(int i=0;i<n;i++){
		cin>>com;
		if(com=="insert"){
			cin>>x;
			insert(x);
		}else if(com=="print"){
			inOrder(root);
			printf("\n");
			preOrder(root);
			printf("\n");
		}
	}

	return 0;
}


//---------------------//
void insert(int k){
	Node *y = NIL;	// xの親
	Node *x = root;
	Node *z;

	z = (Node*)malloc(sizeof(Node));
	// コレないとエラー。　コレ何してる？

	z -> key = k;
	z -> left = NIL;
	z -> right = NIL;

	while(x != NIL){
		y=x;

		if(z->key < x->key){
			x = x->left;
		}else{
			x = x->right;
		}
		// このループで、z の親を探してる？
		// 見つけた親を、y に代入？
	}

	z->parent = y;
	if(y==NIL){
		root=z;

	}else{
		// ノード挿入

		if(z->key < y->key){
			y->left = z;
		}else{
			y->right = z;
		}
	}
}

void inOrder(Node *u){
	if(u==NIL)return;

	inOrder(u->left);
	printf(" %d",u->key);
	inOrder(u->right);
}

void preOrder(Node *u){
	if(u==NIL)return;

	printf(" %d",u->key);
	preOrder(u->left);
	preOrder(u->right);
}



Measured memory_bytes: 26664
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;



int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int c = 1;
    for (int e : a) {
        if (c == e) c++;
    }
    
    if (c == 1) cout << -1;
    else cout << n - c + 1;


}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
bool flag=false;
inline void DFS(int sum,int n){
	if(sum>n||flag==true){
		return;
	}
	if(sum==n){
		flag=true;
		return;
	}
	DFS(sum+4,n);
	DFS(sum+7,n);
}
int main(){
	int n;
	cin>>n;
	DFS(0,n);
	if(flag){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

    int n;
    cin >> n;

    int r = 0, m = 1000;
    for (int i = 0; i < n; i++) {
        int s;
        cin >> s;
        if (s % 10 != 0 && s < m) m = s;
        r += s;
    }
    if (r % 10 == 0 && m != 1000) r -= m;
    if (r % 10 == 0) r = 0;

    cout << r << endl;

    return 0;
}

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

void brake(int x,int y);
string ban[8];
int dx[] = {0,0,0,1,2,3,0,0,0,-1,-2,-3};
int dy[] = {-1,-2,-3,0,0,0,1,2,3,0,0,0};

int main(){
  int n;
  int cou=1;
  cin >> n;
  while(n--){
    /*
    string blank;
    cin >> blank;
    cout << blank << "A";
    */
    for(int i=0;i<8;i++){
      cin >> ban[i];
    }
    int x,y; cin >> x >> y;
    brake(x-1,y-1);
    cout << "Data " << cou << ":" << endl;
    for(int i=0;i<8;i++){
      cout << ban[i] << endl;
    }
    cou++;
  }
}

void brake(int x, int y){
  ban[y][x] = '0';
  for(int i=0;i<12;i++){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx >= 0 && nx < 8 && ny >= 0 && ny < 8){
      if(ban[ny][nx] == '1') brake(nx,ny);
    }
  }
  return;
}

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

using ll = long long;
using P = pair<ll,ll>;

void solve(std::string X){
    ll ans = X.size();
    ll sNum=0;
    for(int i=0;i<X.size();i++){
        if(X[i] == 'S'){
            sNum++;
        }else if(sNum>0){
            sNum--;
            ans -=2;
        }
    }
    cout << ans << endl;

}

int main(){
    std::string X;
    std::cin >> X;
    solve(X);
    return 0;
}


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

typedef long long int in; 

double dp[3005][3005],ans;

int main() 
{
    in n,i,j;
    cin>>n;
    
    double p[n+1];
    
    for(i=1;i<=n;++i)
    {
        cin>>p[i];
    }
    
    dp[0][0]=1;
    
    for(i=1;i<=n;++i)
    {
        dp[i][0]=dp[i-1][0]*(1-p[i]);
        
        for(j=1;j<=i;++j)
        dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]);
    }
    
    for(i=1;i<=n;++i)
    {
        if(i>n-i)
        ans+=dp[n][i];
        
        //cout<<dp[n][i]<<" ";
    }
    
    cout<<fixed<<setprecision(10)<<ans;
    
	return 0;
}


Measured memory_bytes: 68992
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	int p,d,n;
	p=d=2000;
	rep(i,5){
		scanf("%d",&n);
		if(i<3)p=min(p,n);
		else d=min(d,n);
	}
	printf("%d\n",p+d-50);
	return 0;
}

Measured memory_bytes: 1184
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

char ch[100010];
int S[100010];
int N;
vector <pii> qq;
vector <int> V[100010];

int T[1<<18]; const int ADD = 1<<17;

void add(int l, int r, int v) {
	l += ADD, r += ADD;
	while(l <= r) {
		if(l & 1) T[l] = (T[l] + v) % 26, ++l;
		if(!(r & 1)) T[r] = (T[r] + v) % 26, --r;
		l >>= 1, r >>= 1;
	}
}

int Get(int x) {
	x += ADD;
	int res = 0;
	while(x) res += T[x], x >>= 1;
	return res % 26;
}

void solve() {
	scanf("%s", ch+1);
	int L = (int)strlen(ch+1);
	for(int i=1;i<=L;i++) S[i] = ch[i] - 'a';
	scanf("%d", &N);
	for(int i=1;i<=N;i++) {
		int x, y; scanf("%d%d", &x, &y);
		if(x+y == L+1) continue;
		if(x+y > L+1) {
			int px = L+2-x;
			if(x < px) x = px;
			if(L % 2 == 1 && x == (L+1)/2) ++x;
			if(x <= y) qq.pb(pii(x, y)), V[y].pb(x);
		}
		else {
			int py = L-y;
			if(y > py) y = py;
			if(L % 2 == 1 && y == (L+1)/2) --y;
			if(x <= y) qq.pb(pii(x, y)), V[x].pb(y);
		}
	}
	for(int i=1;i<=L;i++) add(i, i, S[i]);
	int lv = L / 2;
	for(int i=1;i<=lv;i++) {
		int vl = -1;
		if(szz(V[i]) >= 1) {
			sort(all(V[i]));
			for(int j=1;j<szz(V[i]);j++) {
				int a = V[i][j], p = V[i][j-1];
				if(p < a) V[p+1].pb(a);
			}
			vl = V[i][0];
		}
		int ri = L + 1 - i;
		int vr = -1;
		if(szz(V[ri]) >= 1) {
			sort(all(V[ri]));
			for(int j=szz(V[ri])-1;j;j--) {
				int a = V[ri][j-1], p = V[ri][j];
				if(a < p) V[p-1].pb(a);
			}
			vr = V[ri][0];
		}
		if(vl != -1 && vr != -1) {
			int l_len = vl - i + 1;
			int r_len = ri - vr + 1;
			if(l_len > r_len) {
				V[i + r_len].pb(vl);
				vl = -1;
			}
			else if(l_len < r_len) {
				V[ri - l_len].pb(vr);
				vr = -1;
			}
			else vr = -1;
		}
		if(i == 3) {
			++i; --i;
		}
		if(vl == -1 && vr == -1) {
			if(Get(i) != Get(ri)) {
				puts("NO");
				return;
			}
		}
		else if(vl == -1) {
			int val = (Get(i) - Get(ri) + 26) % 26;
			add(vr, ri, val);
		}
		else if(vr == -1) {
			int val = (Get(ri) - Get(i) + 26) % 26;
			add(i, vl, val);
		}
	}
	puts("YES");
}

int main(){
	int Tc = 1; // scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 8948
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while( x->left != NIL ) x = x->left;
  return x;
}
Node treeMaximum(Node x){
  while( x->right != NIL ) x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  while( u != NIL && k != u->key ){
    if ( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if ( x->right != NIL ) return treeMinimum(x->right);
  Node y = x->parent;
  while( y != NIL && x == y->right ){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y;
  Node x;

  if ( z->left == NIL || z->right == NIL )
    y = z;
  else y = treeSuccessor(z);
  if ( y->left != NIL )
    x = y->left;
  else x = y->right;

  if ( x != NIL ) x->parent = y->parent;

  if ( y->parent == NIL ){
    root = x;
  } else {
    if (y == y->parent->left)
      y->parent->left = x;
    else y->parent->right = x;
  }

  if ( y != z ){
    z->key = y->key;
  }

  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if ( z->key < x->key ){
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if ( y == NIL ){
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node u){
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if ( u == NIL ) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];

  scanf("%d",&n);
  for ( i = 0 ; i < n ; i++ ){
    scanf("%s",com);
    if ( strcmp(com, "find") == 0 ){
      scanf("%d",&x);
      Node t = treeSearch(root,x);
      if ( strcmp(com,"findMin") == 0 ){
        Node minn = treeMinimum(t);
        printf("%d\n",minn->key);
      } else if ( strcmp(com,"findMax") == 0 ){
        Node maxn = treeMaximum(t);
        printf("%d\n",maxn->key);
      } else {
        if ( t != NIL )
          printf("yes\n");
        else printf("no\n");
      }
    } else if ( com[0] == 'i' ){
      scanf("%d",&x);
      insert(x);
    } else if ( strcmp(com,"print") == 0 ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( strcmp(com,"delete") == 0 ){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }

  return 0;
}


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

int main(){
  int A,B;
  cin >> A >> B;
  long long sum=0;
  for(int i=A;i<=B;i++){
    string s = to_string(i);
    string ss = s;
    reverse(s.begin(),s.end());
    if(ss==s)sum++;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define N 100000
using namespace std;
struct DS {
    int p[N];
    DS(int n) {
        for (int i = 0; i < n; i++) p[i] = i;
    }
    int find(int x) {
        if (x != p[x]) p[x] = find(p[x]);
        return p[x];
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    void unite(int x, int y) {
        p[find(x)] = find(y);
    }
};

int main() {
    int n, q, cmd, x, y;
    scanf("%d%d", &n, &q);
    DS ds(n);
    while (q--){
        scanf("%d%d%d", &cmd, &x, &y);
        if (cmd == 0) ds.unite(x, y); 
        else printf("%d\n", ds.same(x, y));
    }
    return 0;
}



Measured memory_bytes: 2804
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
typedef pair<int,int> P;
const int inf=1000000007;
const lint MOD=998244353;
signed main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  vector<vector<lint>> dp(c+1,vector<lint>(d+1,0));
  dp[a][b]=1;
  for(lint i=a;i<=c;++i){
      for(lint j=b;j<=d;++j){
          if(i==a&&j==b)continue;
          dp[i][j]+=dp[i-1][j]*(j)+dp[i][j-1]*(i);
          dp[i][j]%=MOD;
          dp[i][j]+=MOD*MOD-dp[i-1][j-1]*(i-1)*(j-1);
          dp[i][j]%=MOD;
      }
  }
  cout<<dp[c][d]<<"\n";
  return 0;
}

Measured memory_bytes: 73692
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=Integer.parseInt(sc.next());
    int[] a=new int[n];
    for(int i=0;i<n;i++){
      a[i]=Integer.parseInt(sc.next());
    }
    Arrays.sort(a);
    System.out.println(a[n-1]-a[0]);
  }
}


Measured memory_bytes: 21712
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>

using namespace std;

int main()
{
    long long n;
    int a[200001] = {0};
    int x[200001] = {0};
    
    cin >> n;
    for (int i = 2;i <= n;i++){
        cin >> a[i];
        x[a[i]]++;
    }
    for (int i = 1;i <= n;i++){
        cout << x[i] << endl;
    }
}


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

#define eb emplace_back
#define INF 1LL<<62
#define FLT_INF pow(10.0, 16)

using ll = long long;
using vll = vector<ll>;
using ull = unsigned long long;
using int2 = pair<int, int>;

template <typename A> string to_string(const A& v);
string to_string(const 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(const pair<A, B>& p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A> string to_string(const A& v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename T>
void sort(vector<T>& val) {
  sort(val.begin(), val.end());
}

template <typename T>
void sort_b(vector<T>& val) {
  sort(val.begin(), val.end(), greater<T>());
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...);
#endif

#define COMMON_MOD 998244353
#define PI 3.14159265

// sort(a.begin(), a.end(), less<ll>()); greater<ll>()
// cout<<fixed<<setprecision(20)<<(s/kl)*2;

int main() {

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

  ll r, g, b, n;
  cin >> r >> g >> b >> n;

  ll res = 0;
  for (int i = 0; i <= n/r; i++) {
    for (int j = 0; j <= n/g; j++) {
      if ((n - r*i - g*j) >= 0 && (n - r*i - g*j) % b == 0) {
        res++;
      }
    }
  }
  cout << res;
  cout << endl;
  return 0;
}


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

#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, j, n) for(int i=j;i<n;i++)
#define COUT(n) cout<<(n)<<"\n"

typedef long long ll;
const int INF = 1e9;

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

    int n; cin >> n;
    string s; cin >> s;

    if (n%2==1){
        COUT("No");
        return 0;
    }
    REP(i, n/2) {
        if (s[i]!=s[i+n/2]){
            COUT("No");
        return 0;
        }
    }
    COUT("Yes");

    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

template<class V> class BIT {
private:
	int n; vector<V> bit;
public:
	void add(int i,V x){ i++; while(i <= n) bit[i] += x, i += i & -i;}
	V sum(int i){i++; V s = 0; while(i>0) s += bit[i], i -= i & -i; return s;}
	BIT(int sz){ n = sz + 1, bit.resize(n,0);} //?????????????????????0?????´???
	BIT(vector<V> v){n = (int)v.size()+1; bit.resize(n); rep(i,n) add(i,v[i]);}
	void print(){ rep(i,n-1)cout<<sum(i)-sum(i-1)<< " ";cout<<endl;}
	void print_sum(){ rep(i,n)cout<<sum(i-1)<<" ";cout<<endl;}	//-1????????????
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    BIT<int> bt(n);
    rep(i,q){
        int a,b,c;
        cin >> a >> b >> c;
        if(a == 0){
            bt.add(b-1,c);
        }else{
            cout << bt.sum(c-1) - bt.sum(b-2) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3236
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

int N, M, Q;
int st[200005];

int ele(pair<int,int>p)
{
  return p.second - p.first + 1;
}

int main()
{
  memset(st, 0, sizeof(st));
  scanf("%d%d%d", &N, &M, &Q);
  deque<pair<int,int> >b;
  b.push_back(make_pair(0, N-1));

  int pos = 0, now = 0;
  for(int i=0;i<M;i++){
    int a;
    scanf("%d", &a);
    if(a%2){
      while(a > ele(b.back())){
	a -= ele(b.back());
	b.push_front(b.back());
	b.pop_back();
      }
      pair<int, int>tmp = b.back();
      b.pop_back();
      now = tmp.second - (a-1);
      if(now == tmp.first){
	tmp.first++;
	b.push_front(tmp);
      }else if(now == tmp.second){
	tmp.second--;
	b.push_back(tmp);
      }else{
	b.push_front(make_pair(tmp.second - (a-1) + 1, tmp.second));
	b.push_back(make_pair(tmp.first, tmp.second -  (a-1) - 1 ));	
      }
    }else{
      while(a >= ele(b.front())){
	a -= ele(b.front());
	b.push_back(b.front());
	b.pop_front();
      }
      pair<int,int>tmp = b.front();
      b.pop_front();
      now = tmp.first + a;
      if(now == tmp.first){
	tmp.first++;
	b.push_front(tmp);
      }else if(now == tmp.second){
	tmp.second--;
	b.push_back(tmp);
      }else{
	b.push_back(make_pair(tmp.first, tmp.first + a - 1));
	b.push_front(make_pair(tmp.first + a + 1, tmp.second));
      }
    }
    st[now] = 1;
    now = b.front().first;
    //    for(int j=0;j<b.size();j++) printf("%d:%d ", b[j].first, b[j].second); puts("");
  }
  for(int i=0;i<Q;i++){
    int q;
    scanf("%d", &q);
    printf("%d\n", !st[q]);
  }
  return 0;
}

Measured memory_bytes: 2392
import numpy as np

N = int(input())
S = input()

W=[1 if s=='W' else 0 for s in S]
E=[1 if s=='E' else 0 for s in S]

print(
min((np.cumsum(W)[:-1] + np.cumsum(E[::-1])[::-1][1:]).min(),
    np.cumsum(W)[-1],
    np.cumsum(E[::-1])[::-1][0])
)


Measured memory_bytes: 26792
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 10000
int n;
long long a[N+5],b[N+5];
long long max(long long x,long long y) {
	return x > y ? x: y;
}
long long PD(long long p,long long q) {
	return (p+q-1)/q;
}
int main() {
	scanf("%d",&n);
	scanf("%lld %lld",&a[1],&b[1]);
	for(int i=2; i<=n; i++) {
		scanf("%lld %lld",&a[i],&b[i]);
		long long tmp=max(PD(a[i-1],a[i]),PD(b[i-1],b[i]));
		a[i]=a[i]*tmp;
		b[i]=b[i]*tmp;
	}
	printf("%lld",a[n]+b[n]);
}

Measured memory_bytes: 128