akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    string s;int cnt=0;
    while(cin>>s){
        if(cnt!=0)cout<<" ";cnt++;
    for(int i=0;i<s.length();i++){
        if(s[i]>='a'&&s[i]<='z'){
            s[i]=toupper(s[i]);
        }
        else if(s[i]>='A'&&s[i]<='Z'){
            s[i]=tolower(s[i]);
        }
    }
    cout<<s;
    }
    cout<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


































Measured memory_bytes: 3232
n = int(input())
a = list(map(int, input().split()))
C_sum = [0] * n
C_sum[0] = a[0]
for i in range(1, n):
    C_sum[i] = C_sum[i-1] + a[i]
ans = float('inf')
for j in range(n-1):
    x = C_sum[j]
    y = C_sum[-1] - x
    ans = min(ans, abs(x-y))
print(ans)

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

using namespace std;

int main(){
    long long int N;
    cin >> N;
    
    for(int i=1;i<=3500;i++){
        for(int j=1;j<=3500;j++){
            if((4*i*j-N*(i+j)) != 0 && (N*i*j)%(4*i*j-N*(i+j)) == 0 && 0<(N*i*j)/(4*i*j-N*(i+j))){
                cout << i << " " << j << " " << (N*i*j)/(4*i*j-N*(i+j)) << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 384
H, W = map(int, input().split())
S = [input() for i in range(H)]
a = [[0 for i in range(W)] for j in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j]== '#':
            a[i][j] = '#'
            for p in [-1, 0, 1]:
                for q in [-1, 0, 1]:
                    if i + p >= 0 and j + q >= 0 and i + p < H and j + q < W and S[i + p][j + q] != "#":
                        a[i + p][j + q] += 1
for i in range(H):
    print(''.join(map(str, a[i])))

Measured memory_bytes: 41328
#include<bits/stdc++.h>
using namespace std;
int a[1010];
int b[1010];
int main()
{
	int n, m;
	scanf("%d",&n);
	int i;
	for(i=0; i<n; i++) scanf("%d",&a[i]);
	scanf("%d",&m);
	for(i=0; i<m; i++) scanf("%d",&b[i]);
	printf("%d\n",lexicographical_compare(a,a+n,b,b+m));
	return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) xmin = x; return true;
    return false;
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;
ll mod_pow(ll x, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) return mod_pow(x * x % MOD, n / 2) % MOD;
    else return x * mod_pow(x, (n - 1)) % MOD;
}
ll mod_pow_r(ll x, ll n) {
    if (x == 0) return 0;
    if (n == 0) return 1;
    ll ret = 1;
    while (n) if (n & 1) ret = ret * x % MOD; x = x * x % MOD; n /= 2;
    return ret;
}
ll factorial(ll n) {
    ll ret = 1;
    REP(i, n) ret *= (i + 1); ret %= MOD;
    return ret;
}
ll combination(ll n, ll r) {
    if (n < 0 || n < r || r < 0) return 0;
    ll fn = factorial(n);
    ll fr = factorial(r);
    ll fn_r = factorial(n-r);
    ll d = (mod_pow(fr, MOD - 2) * mod_pow(fn_r, MOD - 2)) % MOD;
    ll u = fn % MOD;
    return u * d % MOD;
}

void solve() {
    int n, m; cin >> n >> m;
    vector<int> a(m); FOR(i, 0, m) cin >> a[i];

    int ret = -1;
    int sum = accumulate(a.begin(), a.end(), 0.0);
    if (sum <= n) ret = n - sum;
    cout << ret;
}

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

Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s=new FastReader();
        int n = s.nextInt();
        int m = s.nextInt();

        long total = 0;
        for (int i = 0; i < m; i++) {
            total += s.nextInt();
        }
        long diff = n - total;
        if(diff <0){
            System.out.println("-1");
        }else{
            System.out.println(diff);
        }
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}



Measured memory_bytes: 27424
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        boolean bl = false;
        for (int i = a; i <= b; i++) {
            if (i % k == 0) {
                bl = true;
            }
        }
        System.out.println(bl?"OK":"NG");
    }
}



Measured memory_bytes: 27040
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  map<string, int> mp;
  while (n--) {
    string s; cin >> s;
    sort(begin(s), end(s));
    ++mp[s];
  }
  lint res = 0;
  for (const auto& e : mp) {
    lint x = e.second;
    res += x * (x - 1) / 2;
  }
  cout << res << '\n';
}

Measured memory_bytes: 11264
#  A, B のGCFの約数の、素因数はいくつか
import math

A, B = map(int, input().split())
gcf = math.gcd(A, B)


def factorization(n):
    arr = [1]
    tmp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            arr.append(i)
    if tmp != 1:
        arr.append(tmp)
    if not arr:
        arr.append(n)
    return arr


factors = factorization(gcf)
print(len(factors))


Measured memory_bytes: 63664
import math
N, A, B, C, D = map(int, input().split())
dp = [[0] * (N + 1) for _ in range(N + 1)]
#dp[i][j] = i人以下のグループを使って、j人をグループ分けする場合の数
#dp[i][j] = 0 if i < A
#dp[i][0] = 0 if i > 0 , dp[0][0] = 1
#dp[i][j] = sum_{k = 0,C<= k <= D, k * i <= j} dp[i-1][j - k * i] * comb(j, (k * i)) * (k * i)! / (i! **k * k!)

mod = 10 ** 9 + 7
dp_F = [0] * (2000) 
dp_Finv = [0] * (2000)
#dp_F[i] = i!

def factorial(n):
    if dp_F[n] > 0:
        return dp_F[n]
    elif n == 0:
        dp_F[0] = 1
        return 1
    else:
        dp_F[n] = n * factorial(n - 1) % mod
        return dp_F[n]

def inverse(n):
    #modでのnの逆数
    return pow(n, mod - 2, mod)

def factorial_inv(n):
    if dp_Finv[n] > 0:
        return dp_Finv[n]
    elif n == 0:
        dp_Finv[0] = 1
        return 1
    else:
        dp_Finv[n] = inverse(n) * factorial_inv(n - 1) % mod
        return dp_Finv[n]

def combination(n, k):
    return (factorial(n) * inverse(factorial(n - k)) * inverse(factorial(k))) % mod

for i in range(N + 1):
    dp[i][0] = 1

for i in range(A, B + 1):
    for j in range(1, N + 1):
        dp_ij = 0
        dp_ij += dp[i - 1][j]
        k = C
        while k <= j // i and k <= D:
            x = (factorial(j) * factorial_inv(j - k * i) * factorial_inv(k) * pow(factorial_inv(i), k, mod)) % mod
            dp_ij += (dp[i - 1][j - k * i] * x) % mod
            k += 1
        dp[i][j] = dp_ij % mod
print(dp[B][N])

Measured memory_bytes: 134236
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){ 
    int A,B,C,D,E;
    cin >>A>>B>>C>>D>>E;
    int ans = 0;
    int A2 = 10000,B2=10000,C2 = 10000,D2 = 10000,E2 = 10000;
    int A3,B3,C3,D3,E3;
    for(int i = 0;i < 100;i++){
        if(A <= i * 10){
            A2 = i*10 - A;
            A3 = i*10;
            break;
        }
    }
    for(int i = 0;i < 100;i++){
        if(B <= i * 10){
            B2 = i*10 - B;
            B3 = i*10;
            break;
        }
    }
    for(int i = 0;i < 100;i++){
        if(C <= i * 10){
            C2 = i*10 - C;
            C3 = i*10;
            break;
        }
    }
    for(int i = 0;i < 100;i++){
        if(D <= i * 10){
            D2 = i*10 - D;
            D3 = i*10;
            break;
        }
    }for(int i = 0;i < 100;i++){
        if(E <= i * 10){
            E2 = i*10 - E;
            E3 = i*10;
            break;
        }
    }
    cout << A3+B3+C3+D3+E3 - max({A2,B2,C2,D2,E2}) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 21
using namespace std;
int h,w;
string mp[N];

int used[N][N][N][N],mem[N][N][N][N];
int dfs(int y,int x,int Y,int X){
  int &res=mem[y][x][Y][X];
  if(y>Y||x>X) return 0;
  if(used[y][x][Y][X]++) return res;
   
  set<int> S;
  for(int i=y;i<=Y;i++)
    for(int j=x;j<=X;j++){
      if(mp[i][j]=='X')continue;
      int a=dfs(y,x,i-1,j-1);
      int b=dfs(y,j+1,i-1,X);
      int c=dfs(i+1,x,Y,j-1);
      int d=dfs(i+1,j+1,Y,X);
      int r=a^b^c^d;
      S.insert(r);
    }
  while(S.count(res))res++;
  return res;
}

int main(){
  cin>>h>>w;
  for(int i=0;i<h;i++)cin>>mp[i];
  cout <<(dfs(0,0,h-1,w-1)!=0? "First":"Second")<<endl;
  return 0;
}

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=5e5+100;
int vis[maxn];
int a[maxn];
int main(){
    int i,j;
    int n;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i]; vis[a[i]]=1;
    }
    int cnt=0;
    for(i=1;i<n;i++){
        if(a[i+1]==a[i]){
            for(j=1;j<=10000;j++){
                if(!vis[j]){
                    vis[j]=1;
                    break;
                }
            }
            cnt++; a[i+1]=j;
        }
    }
    cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	const char *comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef float f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(int a, int b, int mod) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
 
void solve() {
	int n,d;
	cin>>n>>d;
	cout<<(n+2*d)/(2*d+1)<<endl;
}
 
signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	fr(i,1,t) {
		solve();
	}
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    string s, t;
    cin >> s >> t;
    bool ok = true;
    vector<vector<ll>> sames(26), samet(26);
    rep(i, t.size()) {
        sames[t[i]-'a'].push_back(i);
        samet[s[i]-'a'].push_back(i);
    }
    rep(i, 26) {
        if(sames[i].size() <= 1) continue;
        bool tmp = true;
        char a = s[sames[i][0]];
        rep(j, sames[i].size()) {
            if(a != s[sames[i][j]]) tmp = false;
        }
        if(!tmp) ok = false;
    }
    rep(i, 26) {
        if(samet[i].size() <= 1) continue;
        bool tmp = true;
        char a = t[samet[i][0]];
        rep(j, samet[i].size()) {
            if(a != t[samet[i][j]]) tmp = false;
        }
        if(!tmp) ok = false;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


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

base = 30
mod = 10**17 + 3

N = int(input())
S = [input().rstrip()[::-1] for _ in range(N)]
S.sort(key=lambda s: -len(s))
cnt = {}
ans = 0
one = [0] * 26
for s in S:
    n = len(s)
    if n == 1:
        ans += one[ord(s[0]) - ord('a')]
        continue
    hashes = [0] * (n - 1)
    hashes[0] = ord(s[0]) - ord('a') + 1
    for i in range(1, n - 1):
        hashes[i] = (hashes[i-1] * base + ord(s[i]) - ord('a') + 1) % mod
    if hashes[-1] in cnt:
        ans += cnt[hashes[-1]][ord(s[-1]) - ord('a')]
    found = [0] * 26
    found[ord(s[-1]) - ord('a')] = 1
    for i in range(n - 2, 0, -1):
        found[ord(s[i]) - ord('a')] = 1
        if hashes[i-1] not in cnt:
            cnt[hashes[i-1]] = [0] * 26
        for c in range(26):
            cnt[hashes[i-1]][c] += found[c]
    found[ord(s[0]) - ord('a')] = 1
    for c in range(26):
        one[c] += found[c]
print(ans)


Measured memory_bytes: 436516
// https://atcoder.jp/contests/abc145/tasks/abc145_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    string s;
    cin >> s;
    string t1 = s.substr(0, s.length() / 2);
    string t2 = s.substr(s.length() / 2);
    if (s.length() % 2 == 0 && t1 == t2) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


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

using namespace std;

int S, E, N, W;
int main(void)
{
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'S') S = 1;
		else if (s[i] == 'E') E = 1;
		else if (s[i] == 'N') N = 1;
		else W = 1;
	}

	if (S == N && W == E) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 764
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define rev reverse
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define endl '\n'
#define ull unsigned long long
#define sz(x) (int)x.size()

template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll inf = 1e9+7;
const ll N = 1e5+1;
const ll mod = 1e9+7;
const ll P = 31;

int main() {
    IOS
    map<string, int> m;
    ll n, ans = 0;
    cin >> n;
    while(n--) {
        string s;
        cin >> s;
        if(m[s] == 0) {
            ans++;
            m[s]++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

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

int gcd(int x, int y){
  if(y==0)return x;
  return gcd(y,x%y);
}


int main(){
  string s; cin >> s;
  cout << (set<char>(s.begin(),s.end()).size() == s.size() ? "yes" : "no") << endl;
}

 


Measured memory_bytes: 3592
from collections import deque
n=int(input())
l=[[] for _ in [0]*n]
for _ in [0]*(n-1):
  a,b,c=map(int,input().split())
  l[a-1].extend([(b-1,c)])
  l[b-1].extend([(a-1,c)])

q,k=map(int,input().split())
dst=[0 for _ in [0]*n]
que=deque([])
v,p,d=k-1,-1,0
que.append((v,p,d))
while que:
  v,p,d=que.pop()
  dst[v]=d
  for i,j in l[v]:
    if i==p:continue
    que.append((i,v,d+j))

for _ in [0]*q:
  x,y=map(int,input().split())
  print(dst[x-1]+dst[y-1])

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

//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back


const int N = 2e5 + 51 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

//gp_hash_table<int, int> table;

int dp[N], a[N];
bool used[N];

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= k; i++) {
        for (int j = 0; j < n; j++) {
            if (i >= a[j]) {
                int x = i - a[j];
                used[dp[x]] = 1;
            }
        }
        for (int j = 0; j <= N; j++) {
            if (!used[j]) {
                dp[i] = j;
                break;
            }
        }
        for (int j = 0; j < n; j++) {
            if (i >= a[j]) {
                int x = i - a[j];
                used[dp[x]] = 0;
            }
        }
    }
    if (dp[k]) cout << "First";
    else cout << "Second";
}


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

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

int main(){
	int D, T, S;
	cin >> D >> T >> S;
	if(S*T>=D) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

class UnionFind{
private:
  vector<ll> Parent; 
 public:
  UnionFind(ll N){
    Parent = vector<ll>(N, -1);
  }
  
  ll root(ll A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  ll size(ll A){
    return -Parent[root(A)]; 
  }
  
  bool connect(ll A, ll B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(ll A, ll B){
    return root(A) == root(B);
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  UnionFind uf(n);
  vll a(n);
  rep(i,n) cin>>a[i], a[i]--;
  rep(i,m){
    ll x,y; cin>>x>>y; x--,y--;
    uf.connect(x,y);
  }
  ll ans=0;
  rep(i,n){
    if(uf.isSame(a[i],a[a[i]])) ans++;
  }
  cout<<ans<<endl;
}

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

string origine;

int modExp(long long a, long long b, int p) {
	int ret = 1;
	for (a = (a%p+p)%p; b; b >>= 1, a = a*a%p) if (b&1) ret = ret*a%p;
	return ret;
}

bool isDig(char c) {
	return '0' <= c && c <= '9';
}

long long calcExp(string exp) {
	if (!exp.size()) return 0;
	int cur = 0;
	if (exp[0] == '-' || exp[0] == '+') cur++;
	long long ret = 0;
	while (cur < exp.size()) {
		int sig = 1;
		if (cur && exp[cur - 1] == '-') sig = -1;
		long long val = 1, now = 0;
		while (cur < exp.size()) {
			if (exp[cur] == '*') {
				val = val * now % MOD;
				now = 0;
			}
			if (isDig(exp[cur])) now = (now * 10 + exp[cur] - '0') % MOD;
			if (exp[cur] == '+' || exp[cur] == '-') {
				++cur;
				break;
			}
			++cur;
		}
		val = val * now % MOD;
		ret = (ret + val * sig) % MOD;
	}
	ret = (ret % MOD + MOD) % MOD;
	return ret;
}

string toStr(long long val) {
	string ret;
	if (!val) {
		ret.push_back('0');
		return ret;
	}
	int flg = 0;
	if (val < 0) flg = 1, val *= -1;
	while (val) {
		ret.push_back('0' + val % 10);
		val /= 10;
	}
	if (flg) ret.push_back('-');
	reverse(ret.begin(), ret.end());
	return ret;
}

long long getVal(string str) {
	long long ret = 0, pw = 1;
	while (str.size()) {
		ret = (ret + pw * (str.back() - '0')) % MOD;
		str.pop_back();
		pw = pw * 10 % MOD;
	}
	return ret;
}

string convert(string exp, int times) {
	if (times == 1) return exp;
	int sz = exp.size();
	int pos = -1;
	string head, tail;
	for (int i = 0; i < sz; i++) {
		if (exp[i] == '+' || exp[i] == '-') {
			pos = i;
			break;
		}
		head.push_back(exp[i]);
	}
	if (pos >= 0) {
		for (int i = pos; i < sz; i++) tail.push_back(exp[i]);
		long long val = calcExp(tail + head);
		val = (val * (times - 1)) % MOD;
		return head + "+" + toStr(val) + tail;
	}
	pos = -1;
	head.clear();
	for (int i = 0; i < sz; i++) {
		if (exp[i] == '*') {
			pos = i;
			break;
		}
		head.push_back(exp[i]);
	}
	if (pos >= 0) {
		for (int i = pos + 1; i < sz; i++) tail.push_back(exp[i]);
		long long val = calcExp(tail + head);
		val = modExp(val, (times - 1), MOD);
		return head + "*" + toStr(val) + "*" + tail;
	}
	string empty;
	return empty;
}

void append(string str, int times) {
	string res = convert(str, times);
	if (res.size()) {
		origine += res;
		return;
	}
	string tail;
	while (origine.size() && isDig(origine.back())) tail.push_back(origine.back()), origine.pop_back();
	reverse(tail.begin(), tail.end());
	long long head = getVal(tail);
	long long val = getVal(str);
	int l = str.size();
	long long inst = head * modExp(10, 1LL * l * times, MOD) % MOD + val * (modExp(10, 1LL * l * times, MOD) - 1) % MOD * modExp((modExp(10, 1LL * l, MOD) - 1) % MOD, MOD - 2, MOD) % MOD;
	inst = ((inst % MOD) + MOD) % MOD;
	origine += toStr(inst);
}

int main() {
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	while (n--) {
		int times; string tmp; 
		cin >> times >> tmp;
		append(tmp, times);
	}
	cout << calcExp(origine) << endl;
	return 0;
}



Measured memory_bytes: 3492
{-# LANGUAGE DataKinds          #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE KindSignatures     #-}
{-# LANGUAGE TypeOperators      #-}
-- module ExaWizards2019.D (main) where

import           Control.Exception   (assert)
import           Data.List           (sort)
import           Data.Ratio          (denominator, numerator)
import           Data.Vector.Unboxed (Vector, (!))
import qualified Data.Vector.Unboxed as V (generate)
import           GHC.TypeLits        (type (+), KnownNat, Nat, type (^), natVal)

main :: IO ()
main = do
  [n, x] <- map read . words <$> getLine
  ss <- map read . words <$> getLine
  assert (length ss == n) $
    print $ solve n x ss

type M = Modular Int (10 ^ 9 + 7)

-- Unbox じゃないと TLE
-- https://atcoder.jp/contests/exawizards2019/submissions/4777744 を参考にした
solve :: Int -> Int -> [Int] -> M
solve n x ss = fact n * fromIntegral (foldl step table0 set ! x)
  where
    set :: [(Int, Int)]
    set = zip [1..n] $ sort ss

    table0 :: Vector Int
    table0 = V.generate (x + 1) id

    step :: Vector Int -> (Int, Int) -> Vector Int
    step table (i, y) =
      let
        p1, p2 :: M
        p1 = recip $ fromIntegral i
        p2 = 1 - p1
      in
        V.generate (x + 1) $ \x' ->
            let
              n1 = fromIntegral $ table ! (x' `mod` y)
              n2 = fromIntegral $ table ! x'
            in
              unModular $ p1 * n1 + p2 * n2

fact :: Int -> M
fact n = product $ map fromIntegral [1 .. n]

-- modular

newtype Modular a (modulus :: Nat) =
  Modular { unModular :: a }
  deriving (Eq)

instance Show a => Show (Modular a modulus) where
  show (Modular n) = show n

instance (Integral a, KnownNat modulus) => Num (Modular a modulus) where
  fromInteger           = toModular . fromInteger
  Modular n + Modular m = toModular $ n + m
  Modular n * Modular m = toModular $ n * m
  negate (Modular n)    = toModular $ negate n
  abs (Modular n)       = toModular $ abs n
  signum (Modular n)    = toModular $ signum n

instance (Integral a, KnownNat modulus) => Fractional (Modular a modulus) where
  recip m@(Modular n) = toModular $ modularReciprocal (fromInteger (natVal m)) n
  fromRational r = fromInteger (numerator r) / fromInteger (denominator r)

toModular :: (Integral a, KnownNat modulus) => a -> Modular a modulus
toModular n = let m = Modular $ n `mod` fromInteger (natVal m) in m

modularReciprocal :: Integral a => a -> a -> a
modularReciprocal modulus n = snd $ modularReciprocal' modulus n
  where
    -- modularReciprocal' n m = (x, y)
    -- n * x + m * y = 1
    modularReciprocal' :: Integral a => a -> a -> (a, a)
    modularReciprocal' _ 0 = notCoprimeError
    modularReciprocal' _ 1 = (0, 1)
    modularReciprocal' m l = (y, x - q * y)
      where
        (q, r) = m `divMod` l
        (x, y) = modularReciprocal' l r
    notCoprimeError :: a
    notCoprimeError =
      error $ unwords
        [ "divider"
        , parentheses $ showIntegral n
        , "must be coprime to modulus"
        , parentheses $ showIntegral modulus
        ]
    parentheses s = "(" ++ s ++ ")"
    showIntegral = show . toInteger


Measured memory_bytes: 163632
use proconio::{input, fastout};

#[fastout]
fn main() {
   input! {
       N: i64,
       M: i64,
       A: [i64; M],
   } 
   let ans = N - A.iter().sum::<i64>();
   if ans < 0 {
       println!("{}", -1);
   } else {
       println!("{}", ans);
   }
}


Measured memory_bytes: 2208
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int n,m,a[100010],r[100010];
bool isOK(int x){
	int sum=0;
	rep(i,n)sum+=n-(lower_bound(a,a+n,x-a[i])-a);
	return sum>=m;
}
signed main(){
	cin>>n>>m;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	int ok=0,ng=10000000010;
	while(ng-ok>1){
		int mid=(ok+ng)/2;
		if(isOK(mid))ok=mid;
		else ng=mid;
	}
	int ans=0,cnt=0;
	rep(i,n)r[i]=a[i]+(i?r[i-1]:0);
	rep(i,n){
		int l=(lower_bound(a,a+n,ok-a[i])-a);
		ans+=r[n-1]-(l?r[l-1]:0);
		ans+=a[i]*(n-l);
		cnt+=(n-l);
	}
	if(cnt>=m)ans-=(cnt-m)*ok;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(void)
{
    int n,d;
    int tgt;
    int mod;
    int ans;
    int ret;
    scanf("%d %d\n", &n, &d);
    tgt = 1 + (d * 2);
    
    ans = n / tgt;
    mod = n % tgt;

    if(ans == 0)
    {
        ret = 1;
    }
    else
    {
        ret = ans;
    }

    if((mod != 0) && (ans != 0))
    {
        ret +=1;
    }
    
    printf ( "%d\n", ret);
    return 0;
}


Measured memory_bytes: 128
def readinput():
    n,w=list(map(int,input().split()))
    wlist=[]
    vlist=[]
    for _ in range(n):
        ww,vv=list(map(int,input().split()))
        wlist.append(ww)
        vlist.append(vv)
    return n,w,wlist,vlist

def main(n,W,w,v):
    dp=[]
    for _ in range(n+1):
        dp.append([0]*(W+1))
    for i in range(1,n+1):
        for j in range(W+1):
            if j-w[i-1]>=0:
                dp[i][j]=max(dp[i-1][j-w[i-1]]+v[i-1], dp[i][j])
            dp[i][j]=max(dp[i-1][j], dp[i][j])
    return dp[n][W]

if __name__=='__main__':
    n,w,wlist,vlist=readinput()
    ans=main(n,w,wlist,vlist)
    print(ans)


Measured memory_bytes: 147380
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);CIN(K);
    if(K%2 == 0){
        LL s = N/K;
        LL hoge = N/K;
        if(N%K >= K/2){
            hoge++;
        }
        cout<<s*s*s+hoge*hoge*hoge<<endl;
    }else{
        LL s = N/K;
        cout<<s*s*s<<endl;
    }
    return 0;
}




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

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

  s.erase(s.begin()+4);
  s.erase(s.begin()+6);
 
  int s_int = atoi(s.c_str());

  if(s_int <= 20190430) std::cout << "Heisei" << std::endl;
  else std::cout << "TBD" << std::endl;

  return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n,m; cin>>n>>m;
	string A[50],B[50];
	rep(i,n) cin>>A[i];
	rep(i,m) cin>>B[i];

	rep(i,n-m+1) rep(j,n-m+1) {
		bool ok=true;
		rep(y,m) rep(x,m) if(A[i+y][j+x]!=B[y][x]) ok=false;
		if(ok) return cout<<"Yes\n",0;
	}
	cout<<"No\n";

	return 0;
}


Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (_, K) = read!(usize, usize);
    let S = rl().chars().collect::<Vec<_>>();

    let mut X = vec![];
    let mut l = 0;
    for r in 1..S.len() + 1 {
        if r == S.len() || S[r] != S[l] {
            X.push((r - l, S[l]));
            l = r;
        }
    }
    debug!(X);

    let mut max_sum = 0;
    let mut r = 0;
    let mut zero_count = 0;
    let mut sum = 0;
    for l in 0..X.len() {
        while r < X.len() && (X[r].1 == '1' || zero_count < K) {
            let (n, c) = X[r];
            sum += n;
            if c == '0' {
                zero_count += 1;
            }
            r += 1;
        }

        max_sum = max(max_sum, sum);

        let (n, c) = X[l];
        sum -= n;
        if c == '0' {
            zero_count -= 1;
        }
    }

    println!("{}", max_sum)
}


Measured memory_bytes: 6396
#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 ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<P> b(n);
  REP(i, n) {
    cin >> a[i];
    b[i].first = a[i];
    b[i].second = i;
  }

  sort(ALL(b));

  set<ll> st;
  st.insert(-1);
  st.insert(n);
  ll ans = 0;
  REP(i, n) {
    ll mn = b[i].first;
    ll index = b[i].second;
    st.insert(index);

    auto it = st.find(index);

    ll l = *(prev(it));
    ll r = *(next(it));

    ans += mn * (*it - l) * (r - *it);
  }

  cout << ans << endl;

  return 0;
}

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

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;
typedef vector< vector<int> > vvi;

string inv(string s) {
	if(s=="2") return "0";
	if(s=="1") return "1";
	if(s=="0") return "2";
}

string mult(string a, string b) {
	if(a[0] < b[0]) {
		return a;
	} else {
		return b;
	}
}

string add(string a, string b) {
	if(a[0] < b[0]) {
		return b;
	} else {
		return a;
	}
}

string form(string s) {
	if(s.length()==1) {
		return s;
	}
	if(s[0]=='-') {
		return inv( form(s.substr(1)) );
	}
	if(s[0]=='(') {
		int enc = 0;
		for(int i=1; i<s.length(); i++) {
			if(s[i] == '(') {
				enc++;
			}
			else if(s[i] == ')') {
				enc--;
			}
			else if(enc==0 && s[i] == '*') {
				string a = form( s.substr(1,i-1) );
				string b = form( s.substr(i+1, s.length()-1-i-1) );
				return mult(a, b);
			}
			else if(enc==0 && s[i] == '+') {
				string a = form( s.substr(1,i-1) );
				string b = form( s.substr(i+1, s.length()-1-i-1) );
				return add(a, b);
			}
		}
	}
}

int main() {
	string in;
	while(cin >> in, in!=".") {
		int cnt = 0;
		rep(p,3) rep(q,3) rep(r,3) {
			string s = in;
			rep(i,s.length()) {
				if(s[i] == 'P') {
					s[i] = p+'0';
				}
				if(s[i] == 'Q') {
					s[i] = q+'0';
				}
				if(s[i] == 'R') {
					s[i] = r+'0';
				}
			}
			string ss = form(s);
			if( ss == "2" ) {
				cnt++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<tuple>
#include<algorithm>

using lld = long long int;

int main(){
    
    int n, m;
    lld ans = 0;

    std::cin >> n >> m;

    std::vector<std::tuple<lld, lld>> ab;

    for(int i = 0; i < n; i++){
        int a, b;
        std::cin >> a >> b;
        ab.emplace_back(std::make_tuple(a, b));
    }

    std::sort(ab.begin(), ab.end());

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

        if(m <= std::get<1>(ab[i])){
            ans += std::get<0>(ab[i]) * m;
            m -= m;
        }else{
            ans += std::get<0>(ab[i]) * std::get<1>(ab[i]);
            m -= std::get<1>(ab[i]);
        }
    }

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


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

struct node{
    int key;
    int priority;
    struct node *right, *left, *parent;
};

struct node *root, *NIL;

struct node * _delete(struct node*, int);

struct node * rightRotate(struct node *t){
    struct node *s =t->left;
    t->left = s->right;
    s->right = t;
    return s;

}

struct node * leftRotate(struct node *t){
    struct node *s =t->right;
    t->right = s->left;
    s->left = t;
    return s;
}



struct node * find(struct node *u, int k){
    while(u != NIL && k != u->key){
        if(k < u->key){
            u=u->left;
        }
        else{
            u=u->right;
        }
    }

    return u;
}



struct node *  delete(struct node *t, int key){
    if(t==NIL){
       return NIL;
    }
    if(key < t->key){
        t->left=delete(t->left, key);
    }else if(key > t->key){
        t->right=delete(t->right, key);
    } else{
        return _delete(t, key);
    }   

    return t;

}

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

    return delete(t, key);
}

struct node * insert(struct node *t, int key, int priority){
    if(t==NIL){
        struct node *z;
        z = (struct node *)malloc(sizeof(struct node));
        z->key=key;
        z->priority=priority;
        z->left=NIL;
        z->right=NIL;
        return z;
    }

    if(key==t->key){
        return t;
    }

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

    return t;
    
}

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

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

int main(void){
    int n, i, x, y;
    char com[10];
    scanf("%d", &n);

    for(int i=0; i<n; i++){
        scanf("%s", com);
        if(com[0]=='i'){
            scanf("%d %d", &x, &y);
            root=insert(root, x, y);
            x++;
        }else if(com[0]=='f'){
            scanf("%d", &y);
            struct node *t = find(root, y);
            if(t!=NIL){
                
                printf("yes\n");
            }
            else{
                printf("no\n");
            }
        }
         else if(com[0]=='d'){
            scanf("%d", &y);
            root=delete(root, y);
        }else if(com[0]=='p'){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
       
    }
    return 0;
}


Measured memory_bytes: 11084
#include <bits/stdc++.h>
using namespace std;
int main (){
	string txt1;
	string txt2;
	cin >> txt1; cin >> txt2;
	txt2.erase(txt2.size()-1);
	if (txt1 == txt2) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 3620