akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    // 一番安いところでできるだけ買って一番高いところでできるだけ売る
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    int now = A[0];
    ll have = 0;
    ll money = 1000;
    int state = 0; // 0:上昇、1:下降
    for(int i=0;i<N+1;i++){
        if(state == 0){
            if(i==N) break;
            if(now>=A[i]){
                now = A[i];
            }else{
                have = money/now;
                money-= have*now;
                //cout << "B ";
                //cout << "i:" << i << " have:" << have << " money:" << money << endl;
                state = 1;
                now = A[i];
            }
            //cout << state << " " << now << endl;
        }else{
            if(i==N){
                money += have*A[N-1];
                have = 0;
                //cout << "S ";
                //cout << "i:" << i << " have:" << have << " money:" << money << endl;
                break;
            }
            if(now<=A[i]){
                now = A[i];
            }else{
                money += have*now;
                //cout << "S ";
                //cout << "i:" << i << " have:" << have << " money:" << money << endl;
                have = 0;
                state = 0;
                now = A[i];
            }
            //cout << state << " " << now << endl;
        }
    }
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
#include <stdio.h>
#include <iomanip>
#include <queue>
using namespace std;

#define rep(i,N) for(int i=0; i<N; i++)
#define revrep(i,N) for(int i=N-1; i>=0; i--)
#define coutline cout<<"------------ ("<<__LINE__<<")"<<endl;

typedef long long ll;

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

    vector<vector<pair<int, ll>>> p(N);
    vector<int> ret(N,0);

    rep(i, N-1){
        int u,v;
        ll w;
        cin >> u >> v >> w;
        u--;v--;

        p.at(u).push_back(make_pair(v,w));
        p.at(v).push_back(make_pair(u,w));
    }

    queue<int> q;

    rep(t, N) {
        if (ret.at(t) == 0) {
            q.push(t);
            ret.at(t) = 1;
        }
        while (!q.empty()) {
            int i = q.front();q.pop();
            
            rep(j, p.at(i).size()){
                if (p.at(i).at(j).second % 2 == 1) {
                    if (ret.at(p.at(i).at(j).first) == 0) {
                        ret.at(p.at(i).at(j).first) = ret.at(i) * (-1);
                        q.push(p.at(i).at(j).first);
                    } 
                } else {
                    if (ret.at(p.at(i).at(j).first) == 0) {
                        ret.at(p.at(i).at(j).first) = ret.at(i);
                        q.push(p.at(i).at(j).first);
                    } 
                }
            }
        }
    }

    rep(i, N) {
        if(ret.at(i) == 1) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
    }
   

    return 0;
}


Measured memory_bytes: 8320
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x-r>=0&&x+r<=W){
		if(y-r>=0&&y+r<=H){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 2692
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;

void main(){
	auto N = readln.split.to!(int[]), A=N[0], B=N[1], C=N[2];
	if((A<C&&C<B)||(B<C&&C<A)){
		writeln("Yes");
	}else{
		writeln("No");
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

struct Info{
	Info(){
		num_of_page = 0;
	}

	void insert(int arg_page){
		page[num_of_page++] = arg_page;
	}

	void sort(){
		if(num_of_page > 0){
			for(int i=1; i <= num_of_page-1; i++){
				for(int k=num_of_page-1; k >= i; k--){
					if(page[k] < page[k-1])swap(page[k],page[k-1]);
				}
			}
		}
	}

	void print(){
		printf("%d",page[0]);
		for(int i=1; i < num_of_page; i++)printf(" %d",page[i]);
		printf("\n");

	}

	char word[31];
	int page[100],num_of_page;
};

bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

int strCmp2(char* left,char* right){
	int i;

	if(strCmp(left,right))return 3;

	for(i=0;left[i] != '\0' && right[i] != '\0'; i++){
		if(left[i] != right[i]){
			if(left[i] < right[i])return 1;
			else{
				return 2;
			}
		}
	}

	if(left[i] == '\0')return 1;
	else{
		return 2;
	}

}


int main(){

	Info info[100];
	int num_of_info = 0,page;
	bool FLG;

	char buf[31];

	while(scanf("%s %d",buf,&page)!=EOF){
		FLG = false;
		for(int i=0; i < num_of_info; i++){
			if(strCmp(buf,info[i].word)){
				info[i].insert(page);
				FLG = true;
				break;
			}
		}
		if(!FLG){
			strcpy(info[num_of_info].word,buf);
			info[num_of_info].insert(page);
			num_of_info++;
		}
	}

	for(int i=0; i < num_of_info; i++)info[i].sort();

	for(int i=1; i <= num_of_info-1; i++){
		for(int k=num_of_info-1;k >= i; k--){
			if(strCmp2(info[k].word,info[k-1].word) == 1)swap(info[k],info[k-1]);
		}
	}

	for(int i=0; i < num_of_info; i++){
		printf("%s\n",info[i].word);
		info[i].print();
	}


    return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define MOD 10000007
using namespace std;

int main() {
  	int n,m; cin >> n >> m;
  	vector<long long> h(n);
  	for(int i = 0;i < n;i++) {
      	long long tmp; cin >> tmp;
    	h[i] = tmp;
    }
  
  	vector<vector<int>> ab(n);
  	for(int i = 0;i < m;i++) {
    	int a,b; cin >> a >> b;
      	a--;b--;
      	ab[a].push_back(b);
      	ab[b].push_back(a);
    }
  
  	int count = 0;
  	for(int i = 0;i < n;i++) {
        bool flg = true;
      	long long ab_size = ab[i].size();
      	long long hi = h[i];
      	for(int j = 0;j < ab_size;j++ ) {
        	if(hi <= h[ab[i][j]]) flg = false;
        }
      	if(flg) count++;
    }
	cout << count << "\n";
}

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

using namespace std;

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

//State
//dp[i] The minimum cost to reach the i-th step from 1st step

//Initialization
//dp[1] = 0, dp[2] = abs(h[1] - h[0])

//Transitions
//dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),	dp[i-2]+abs(h[i]-h[i-2]))

//Order of evaluation
// i = 1...N

//Answer
//return dp[N]

//Time Complexity = O(N*K) but this can also be solved in O(N) using prefix sums

int dp[100005]; //Max value of N is 10^5
int h[100005]; //Max value of h is 10^5
const int inf = 1e9 + 5;

int main(){
	int N, K;
	cin >> N >> K;
	//int h[N];
	for(int i=1; i<=N; i++){
		cin >> h[i];
		dp[i] = inf;
	}
	dp[1] = 0;
	for(int i=2; i<=N; i++){
		for(int j=i-K; j<= i-1; j++){
			if(j>=1){
				dp[i] = min(dp[i], dp[j]+abs(h[i]-h[j]));
			}
		}
	}
	cout << dp[N] << endl;
}

Measured memory_bytes: 4344
# input
N = int(input())
K = int(input())

# defnition
N_bin = str(N)
digit_len_N = len(N_bin)
DP = [[[0]*(K+2) for _ in range(2)] for _ in range(digit_len_N+1)]
# DP[i][j][k]は、上位i桁目までで、(j==0 ?Nと同じになる可能性あり:必ずNより小さくなる)の時に、0以外の数がkこ出現する、数字の数


# initialize
DP[0][0][0] = 1

# solve with けたDP
for digit in range(digit_len_N):
    max_digit = int(N_bin[digit])
    for smaller in range(2):  # smaller=0?Nと同じになる可能性あり:Nより小さいの確定
        for k in range(K+1):
            cand_digits = max_digit+1 if smaller == 0 else 10  # 小さい確定なら0~9の全部が候補
            for next in range(cand_digits):
                if next == max_digit and smaller == 0:  # Nと同じになる可能性を残しつつ
                    if next == 0:  # 0のときは,kの値が増えないので特別扱い
                        DP[digit+1][0][k] += DP[digit][0][k]
                    else:
                        DP[digit+1][0][k+1] += DP[digit][0][k]
                else:  # ここで、Nより必ず小さい道に行く
                    if next == 0:  # 0のときは,kの値が増えないので特別扱い
                        DP[digit+1][1][k] += DP[digit][smaller][k]
                    else:
                        DP[digit+1][1][k+1] += DP[digit][smaller][k]
print(DP[-1][0][K]+DP[-1][1][K])


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

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

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)

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

main :-
    get_number(N),
    get_number(A),
    get_number(B),
    X is min(N * A, B),
    writeln(X).


Measured memory_bytes: 8140
#include<stdio.h>

int main(void){

    int X,j,divisor,ans_found = 0;
    long int i;

    scanf("%d",&X);

    i = X;
    while(ans_found == 0){
        divisor = 0;
        for(j = 1;j <= i;j++){
            if(i%j == 0){
                divisor++;
            }
        }
        if(divisor == 2){
            printf("%ld\n",i);
            ans_found = 1;
        }
        i++;
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
string s, t;
int sum, ans;
int main() {
  cin >> s >> t;
  for (int i = 0; i < s.length() - t.length() + 1; i++) {
    sum = 0;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] == t[j]) sum++;
    }
    ans = max(ans, sum);
  }
  cout << t.length() - ans << endl;
  system("pause");
  return 0;
}

Measured memory_bytes: 3680
n = gets.to_i
l = Array.new(n)
r = Array.new(n)
n.times do |i|
    l[i],r[i] = gets.split.map(&:to_i)
end
ans = 0
ret = 0
l = l.sort.reverse
r.sort!
for i in 0..2*n-1
    if i%2 == 0
        ret += 2*l[i/2]
    else
        ret -= 2*r[i/2]
    end
    ans = ret if ans < ret
end
ret = 0
for i in 0..2*n-1
    if i%2 == 1
        ret += 2*l[i/2]
    else
        ret -= 2*r[i/2]
    end
    ans = ret if ans < ret
end
puts ans

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

const int N=4005;

int n,ans,l;
int d[N],cnt[N];

int main(){
	int i,j;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&d[i]),cnt[d[i]]++;
	sort(d+1,d+1+n); l=(d[n]+1)/2;
	if (d[n]>=n){
		printf("Impossible\n");
		return 0;
	}
	if (d[1]<l){
		printf("Impossible\n");
		return 0;
	}
	for (i=l+1;i<=d[n];i++)
		if (cnt[i]<2){
			printf("Impossible\n");
			return 0;
		}
	if (d[n]&1){
		if (cnt[l]!=2) printf("Impossible\n");
		else printf("Possible\n");
	}
	else{
		if (cnt[l]!=1) printf("Impossible\n");
		else printf("Possible\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
  int count_five = 0;
  int count_seven = 0;

  for(int i=0; i<3; i++){
    int num;
    cin >> num;

    if(num == 5) count_five++;
    if(num == 7) count_seven++;
  }

  if(count_five == 2 && count_seven == 1){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int x, a;
  cin >> x >> a;
  cout << (x < a ? 0 : 10);
}
#endif


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

#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

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

    int a[100010];
    Rep(i, m) cin >> a[i];

    int mx = 0;
    for ( int i = 0; i < m-1; i++ ) {
        mx = max(mx, (a[i+1]-a[i]) / 2);
    }

    cout << max(mx, max(a[0]-1, n - a[m-1])) << endl;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	int A, B;

	cin >> A >> B;

	if (A < B * 2)
		cout << 0 << endl;
	else
		cout << A - B * 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
int N, M, Q; 
cin >> N >> M >> Q; 
int A[512][512] = {0}; 
for(int i = 0; i < M; i++){
int L, R; 
cin >> L >> R; 
A[L][R] ++; 
}
int S[512][512] = {0}; 

S[1][1] = A[1][1]; 
for(int j = 2; j <= N; j++){
S[1][j] = S[1][j-1] + A[1][j]; 
}

for(int i = 2; i <= N; i++){
S[i][1] = S[i-1][1] + A[i][1]; 
for(int j = 2; j <= N; j++){
S[i][j] = S[i][j-1] + S[i-1][j] - S[i-1][j-1] + A[i][j]; 
}
}

for(int i = 0; i < Q; i++){
int X, Y; 
cin >> X >> Y; 
cout << S[Y][Y] - S[X-1][Y] - S[Y][X-1] + S[X-1][X-1] << endl; 
}
}

Measured memory_bytes: 2944
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> ab(100010);
    rep(i, n){
        int a, b;
        cin >> a >> b;
        ab[a].push_back(b);
    }

    int res = 0;
    priority_queue<int> q;
    for(int i = m-1; i >= 0; --i){
        for(auto j : ab[m-i]) q.push(j);
        if(q.size()){
            int cur = q.top();
            q.pop();
            res += cur;
        }
        //cout << res << endl;
    }
    cout << res << endl;
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,m,i,a[100005],cf[100005],cf2[100005],ans,max1;
void cr(long long x,long long y,long long z){
	if(x>y)
		return;
	cf[x]+=z;
	cf[y+1]-=z;
	cf2[x+1]++;
	cf2[y+1]--;
	cf[y+1]-=y-x;
}
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
   	n=read();m=read();
   	for(i=1;i<=n;i++)
		a[i]=read();
	for(i=1;i<n;i++){
		if(a[i]<a[i+1]){
			cr(a[i]+1,a[i+1],0);
			ans+=a[i+1]-a[i];
		}
		else{
			cr(a[i]+1,m,0);
			cr(1,a[i+1],m-a[i]);
			ans+=a[i+1]-a[i]+m;
		}
	}
	for(i=1;i<=m;i++){
		cf2[i]+=cf2[i-1];
		cf[i]+=cf2[i]+cf[i-1];
		max1=max(max1,cf[i]);
	}
	ans-=max1;
	pus(ans,2);
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>

using namespace std;

int main()
{
  vector<int> x_array;

  for (int i = 0;; i++) {
    int x;
    cin >> x;
    if (x == 0) break;
    x_array.push_back(x);
  }

  for (int i = 0; i < x_array.size(); i++) {
    cout << "Case " << i + 1 << ": " << x_array[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int s = 0;
	for (int i = 0; i < 4; i++) {
		int a;
		cin >> a;
		s += a;
	}
	cout << s / 60 << endl << s % 60 << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
#define PAI 3.14159265358979
// ver1.6
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int k,t;
  cin >> k >> t;
  Vi a(t);
  rep(i,0,t) cin >> a[i];
  a.pb(0);
  sort(ALL(a));
  reverse(ALL(a));
  int ans = 0,sum = 0;
  
  while(a[1]!=0){
    a[0] -= a[1];
    a[1] = 0;
    sort(ALL(a));
    reverse(ALL(a));
  }
  cout << max(0LL,a[0]-1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define SIZE 2000000

int main() {
  int A[SIZE];
  int H=0;
  int i, key, l, largest, p, tmp;
  char com[20];
  do {
    scanf("%s", com);
    if (com[0] == 'i') {
      scanf("%d", &key);
      A[++H] = key;
      for (i=H,p=i/2; p>0 && A[p]<A[i];i=p,p/=2) {
        tmp = A[p];
        A[p] = A[i];
        A[i] = tmp;
        if (p/2==0) break;
      }
    } else if (com[1]=='x') { // extract
      printf("%d\n", A[1]);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i*2;
        // 左の子、自分、右の子で値が最大のノードを選ぶ
        if (l < H && A[l] > A[i])        largest = l;
        else                             largest = i;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;  // i の子の方が値が大きい場合
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (com[2]!='d');
  return 0;
}


Measured memory_bytes: 5604
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main(){
	int n;
	cin >> n;
	int mx1 = 0, mx2 = 0;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] >= mx2) mx2 = a[i];
		if(mx2 >= mx1) swap(mx1, mx2);
	}
	for(int i = 0; i < n; i++){
		if(a[i] == mx1) cout << mx2 << endl;
		else cout << mx1 << endl;
	}
	return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)
#define all(a) a.begin(), a.end()
#define gr greater<LL>()

using namespace std;

void solve(long long N, std::vector<long long> a){
    vector<pair<LL, LL>> ais(N);
    rep(i, N)ais[i] = make_pair(a[i], i);
    sort(all(ais));
    set<LL> right;
    right.insert(-1);
    right.insert(N);

    LL ans = 0;
    for(auto ai : ais){
        LL i=ai.second, aa=ai.first;
        auto it = right.upper_bound(i);
        LL r = *it, l=*(--it);
        right.insert(i);
        ans += (i-l)*(r-i)*aa;
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 14336
const log = console.log;

const createScanFunctions = (input: string) => {
  const str = input.trim();
  const len = str.length;
  let index = 0;

  const scan = () => {
    const startIndex = index;

    while (index < len) {
      const char = str[index];

      if (char === " " || char === "\n")
        return str.substring(startIndex, index++);

      index++;
    }

    return str.substr(startIndex);
  };

  const scanInt = () => parseInt(scan());

  return { scan, scanInt };
};

// ----

function Main(input: string): void {
  const { scanInt } = createScanFunctions(input);

  const n = scanInt();
  const m = scanInt();

  let minCardNo = 1;
  let maxCardNo = n;

  for (let i = 0; i < m; i++) {
    const l = scanInt();
    const r = scanInt();

    if (l > minCardNo) minCardNo = l;
    if (r < maxCardNo) maxCardNo = r;
  }

  log(Math.max(0, maxCardNo - minCardNo + 1));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15404
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int progA[] = new int[n];
		for(int i = 0; i < n; i++) {
			progA[i] = sc.nextInt();
		}

		int m = sc.nextInt();
		int progB[] = new int[m];
		for(int i = 0; i < m; i++) {
			progB[i] = sc.nextInt();
		}

		boolean flag = false;  //for文をbreakで出たのかどうか判定
		for(int j = 0; j < Math.min(progA.length, progB.length); j++) {
			if(progA[j] > progB[j]) {
				System.out.println(0);
				flag = true;
			}
			else if(progA[j] < progB[j]) {
				System.out.println(1);
				flag = true;
			}
			if(flag == true) break;
		}

		if(flag == false) {  //breakで出ていない場合
			if(progA.length < progB.length) System.out.println(1);
			else System.out.println(0);
		}
	}

}



Measured memory_bytes: 32476
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 998244353

N, S = MAP()
A = LIST()

# dp0[i][j] := i番目の要素まで見て、総和がjで、使う区間が未確定の状態の通り数
dp0 = list2d(N+1, S+1, 0)
# dp1[i][j] := i番目の要素まで見て、総和がjで、使う区間がL確定済の状態の通り数
dp1 = list2d(N+1, S+1, 0)
# dp2[i][j] := i番目の要素まで見て、総和がjで、使う区間がLR確定済の状態の通り数
dp2 = list2d(N+1, S+1, 0)
dp0[0][0] = 1
for i, a in enumerate(A):
    for j in range(S+1):
        # aを総和に足さない遷移は普通
        dp0[i+1][j] += dp0[i][j]
        dp1[i+1][j] += dp1[i][j]
        dp2[i+1][j] += dp2[i][j]
        # aを総和に足す遷移は、遷移元が状態2と遷移先が状態0は無理
        if j+a <= S:
            # 左端を決める時はそこより手前が自由に使えるのでその分を掛ける
            dp1[i+1][j+a] += dp0[i][j] * (i+1)
            # 右端を決める時はそこより先が自由に使えるのでその分を掛ける
            dp2[i+1][j+a] += dp1[i][j] * (N-i)
            dp1[i+1][j+a] += dp1[i][j] 
            dp2[i+1][j+a] += dp0[i][j] * (i+1) * (N-i)
        dp0[i+1][j] %= MOD
        dp1[i+1][j] %= MOD
        dp2[i+1][j] %= MOD
ans = dp2[N][S]
print(ans)


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

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

    ll X;
    cin >> X;
    vector<P> V;
    for (int i = 0; 1LL * pow(i, 5) <= LLONG_MAX; ++i) {
        V.push_back(make_pair(i, 1LL * pow(i, 5)));
    }

    for (auto &x : V) {
        for (auto &y : V) {
            if (x.second - y.second == X) {
                cout << x.first << ' ' << y.first << endl;
                return 0;
            } else if (x.second + y.second == X) {
                cout << x.first << ' ' << -1 * y.first << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 4324
import java.sql.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		List<Integer> nums = new ArrayList<Integer>() ;
		for (int i = 0; i < len; i++) {
			nums.add(scanner.nextInt());
		}
		
		int min = nums.get(0);
		int profit = -1000000000;
		for (int i = 1; i < len; i++) {
			if (profit<(nums.get(i)-min)) {
				profit = nums.get(i)-min;
			}
			if (nums.get(i)<min) {
				min = nums.get(i);
			}
		}
		
		System.out.println(profit);
	}

}


Measured memory_bytes: 105692
#include <cstdio>
#include <cctype>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>

int apply(int lhs, char op, int rhs) {
  switch (op) {
  case '+': return lhs+rhs;
  case '-': return lhs-rhs;
  case '*': return lhs*rhs;
  case '/': return lhs/rhs;
  }
  assert(false);
}

int parse(const std::string &s, size_t &i, size_t preced=0) {
  const std::vector<std::string> ops={"+-", "*/"};
  if (preced == ops.size()) {
    if (s[i] == '(') {
      int res=parse(s, ++i, 0);
      assert(s[i] == ')');
      ++i;
      return res;
    }
    if (isdigit(s[i])) {
      int res=s[i]-'0';
      while (++i < s.length() && isdigit(s[i]))
        res = res*10+s[i]-'0';
      return res;
    }
    assert(false);
  }
  int res=parse(s, i, preced+1);
  while (i < s.length()) {
    char op=s[i];
    if (!std::count(ops[preced].begin(), ops[preced].end(), op)) break;
    int tmp=parse(s, ++i, preced+1);
    res = apply(res, op, tmp);
  }
  return res;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i=0; i<n; ++i) {
    char buf[128];
    scanf("%s", buf);
    std::string s=buf;
    size_t j=0;
    printf("%d\n", parse(s, j));
  }
}



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

int main(){
 int n, m,i;
 cin >> n >> m;
 priority_queue<pair<int,int >> q;
 vector<int> a(n), b(m), c(m);
 rep(i,n){
  cin >> a[i];
  q.push( make_pair(a[i], 1) );
 }
 rep(i,m){
  cin >> b[i] >> c[i];
  q.push( make_pair(c[i], b[i]));
 }

ll ans=0;

rep(i,n){
auto p = q.top();
q.pop();
ans += p.first;
if(p.second>1){
 p.second--;
 q.push(p);
}
}

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

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

struct Node{
    int key;
    Node *p, *l, *r;
};

Node *root, *NIL;

void insert(int n);
Node* find(int n);
void print(Node *r);
void inorder(Node *r);
void preorder(Node *r);

int main(){
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        string com; cin >> com;
        if(com == "insert"){
            int num; cin >> num;
            insert(num);
        }
        if(com == "print"){
            print(root);
        }
        if(com == "find"){
            int num; cin >> num;
            if(find(num) != NIL){
                cout << "yes" << endl;
            }else{
                cout << "no" << endl;
            }
        }
    }
}


void insert(int n){
    Node *y = NIL; //見つかった挿入箇所の親
    Node *x = root; //根から挿入箇所を調べていく
    Node *z;
    z = (Node *)malloc(sizeof(Node));
    z->key = n;
    z->l = NIL; z->r = NIL;

    while(x != NIL){ //一番下
        y = x; //調べているところのおや
        if(z->key < x->key){ //調べてる場所より小さい
            x = x->l;
        }else{
            x = x->r;
        }
    }
    z->p = y; //

    if(y == NIL){
        root = z;
    }else if(z->key  < y->key){
        y->l = z;
    }else{
        y->r = z;
    }
}

void print(Node *r){
    inorder(r);
    cout << endl;
    preorder(r);
    cout << endl;
}

void inorder(Node *r){
    if(r == NIL) return;
    inorder(r->l);
    cout << " " << r->key;
    inorder(r->r);
}

void preorder(Node *r){
    if(r == NIL) return;
    cout << " " << r->key;
    preorder(r->l);
    preorder(r->r);
}

Node* find(int n){
    Node *x = root;
    while(x != NIL && x->key != n){
        if(n < x->key){
            x = x->l;
        }else{
            x = x->r;
        }
    }
    return x;
}


Measured memory_bytes: 21760
n=gets.to_i
l=gets.split.map(&:to_i).sort

p (2...n).inject(0){|s,i|
  (1...i).inject(s){|t,j|
    min_k = l[i]-l[j]
    t + j - ((0...j).bsearch{|k| min_k < l[k]} || j)
  }
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007

using namespace std;

struct prg {
    int l, r, ch;
    prg() {}
};

const int mx = 100;
int n, c, kek[mx];
vector<prg> a;
vector<pair<int, int> > ev;

int main()
{
    cin >> n >> c;
    a.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].l >> a[i].r >> a[i].ch;
        a[i].r++;
    }
    for (int i = 0; i < n; ++i) {
        ev.push_back({a[i].l, a[i].ch});
        ev.push_back({a[i].r, -a[i].ch});
    }
    sort(ev.begin(), ev.end());
    int ans = 0, diff = 0;
    for (int i = 0; i < ev.size(); ++i) {
        if (kek[abs(ev[i].second)] > 0)
            diff--;
        if (ev[i].second > 0)
            kek[ev[i].second]++;
        if (ev[i].second < 0)
            kek[-ev[i].second]--;
        if (kek[abs(ev[i].second)] > 0)
            diff++;
        ans = max(ans, diff);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3572
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var imp = Console.ReadLine();
            int S = imp.Length;
            char firstS = imp[0];
            char lastS = imp[S-1];
            //Console.Write(lastS);
            Console.Write(firstS);
            Console.Write(S - 2);
            Console.Write(lastS);


            //System.Threading.Thread.Sleep(1000);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const ll INF = 1000000000;
//const ll MOD = 1000000007;
const ld PI = (acos(-1));
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
typedef pair<int, int> pair;
double rad(double a) {return a * 180 / PI;}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//dpTable
int dp[100050];

int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    vector<ll> cnt(5,0);
    rep (i,N) {
        cin >> S.at(i);
        if (S.at(i).at(0) == 'M') cnt.at(0)++;
        if (S.at(i).at(0) == 'A') cnt.at(1)++;
        if (S.at(i).at(0) == 'R') cnt.at(2)++;
        if (S.at(i).at(0) == 'C') cnt.at(3)++;
        if (S.at(i).at(0) == 'H') cnt.at(4)++;
    }
    ll ans = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += cnt.at(i) * cnt.at(j) * cnt.at(k);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6420
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int n;
    cin>>n;
    vector<int> vec(n);
    rep(i,n){
        cin>>vec[i];
    }
    sort(all(vec));
    cout<<vec[n/2]-vec[n/2-1]<<endl;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
#define MOD 1000000007
#define MAX 1000000
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  long long x,y;cin>>x>>y;
  if((x+y)%3){
    cout << 0 << endl;
    return 0;
  }
  if(min(x,y)*2 < max(x,y)){
    cout << 0 << endl;
    return 0;
  }
  long long z = (x+y)/3;
  x-=z;
  y-=z;

  COMinit();
  cout << COM((x+y),x) << endl;

  
}

Measured memory_bytes: 23680
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=105;
int f[N][20],p[N][20],n,ans=-2e9;
void dfs(string s)
{
	if(s.size()==10)
	{
		if(s=="0000000000")return;
		int sum=0;
		for(int i=0;i<n;i++)
		{
			int num=0;
			for(int j=0;j<10;j++)
				if(f[i][j]&&s[j]=='1')
					num++;
			sum+=p[i][num];
		}
		ans=max(ans,sum);
		return;
	}
	dfs(s+"0");
	dfs(s+"1");
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<10;j++)
				cin>>f[i][j];
	for(int i=0;i<n;i++)
		for(int j=0;j<11;j++)
			cin>>p[i][j];
	dfs("");
	cout<<ans<<endl;
	return 0;
}
/*
1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 2e5 + 7;
int n;
map <int, int> pos;
map <int, bool> vis;
int seq[maxx];
LL k;

int main() {
	scanf("%d %lld", &n , &k);
	for(int i = 1; i <= n; i++) scanf("%d", &pos[i]);
	int nxt = 1;
	int t = -1;
	seq[++t] = nxt;
	for(int i = 1; ;) {
		if(vis[i]) break;
		vis[nxt] = 1; //先打标记
		nxt = pos[i]; //更新nxt
		seq[++t] = nxt;
		i = nxt; //替换
	}
	//seq[t]是第一次重复的数字
	//定位第一次出现时的位置fir
	int x = 0;
	for(int i = 0; i < t; i++) {
		if(seq[i] == seq[t]) {
			x = i;
			break;
		}
	}
	//cout << x << endl;
	if(k <= x) printf("%d\n", seq[k]);
	else { 
		k -= (LL)x;
		LL id = k % ((LL)t - (LL)x);
		printf("%d\n", seq[x + id]);
	}
	return 0;
}

Measured memory_bytes: 23172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,s,t;
    vector<ll> g[100010];
    cin>>n>>m;
    rep(i,m){
      ll u,v;
      cin>>u>>v;
      g[u].push_back(v);
    }
    cin>>s>>t;
    ll dp[100010][3];
    ll inf=1e15;
    rep(i,100010)rep(j,3) dp[i][j]=inf;
    dp[s][0]=0;
    queue<P> que;
    que.push(P(s,0));
    while(!que.empty()){
      P v=que.front();
      que.pop();
      ll now=(v.second+1)%3;
      for(auto itr:g[v.first]){
        if(dp[itr][now]==inf){
          dp[itr][now]=v.second+1;
          que.push(P(itr,v.second+1));
        }
      }
    } 
    if(dp[t][0]==inf) cout<<-1<<endl;
    else cout<<dp[t][0]/3<<endl;
}

Measured memory_bytes: 8064
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
cin >> s;
if(s.size() < 4){
cout << "No" <<endl;
return 0;
}
if(s[0] == 'Y' and s[1] == 'A' and s[2] == 'K' and s[3] == 'I'){
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}

Measured memory_bytes: 256
r=j=x=1
i=0
M=10**9+7
`sed 1d`.split.map{x=$*[k=_1.to_i]||x+1
($*[k]=i+=1).pow M-2,M}.map{p (-j+r=r*i*_1%M)%M
i-=1
j=j*_1%M*x-=1}

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

cnt=0
for i in range(1,n):
  flag=0
  for j in range(i):
    if h[i]>=h[j]:
      continue
    else:
      flag=1
      break
  if flag==0:
    cnt+=1
print(cnt+1)


Measured memory_bytes: 2940
/* AOJ 0118 Property Distribution */

#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef pair<int, int> pii;

const int MAX_H = 100;
const int MAX_W = 100;

char garden[MAX_W][MAX_H];
int h, w;
vector<pii> dir;

int count_partitions();
void dfs(int x, int y, char fruit);
void set_dir();

int
main()
{
    set_dir();

    for (;;) {
        cin >> h >> w;
        cin.ignore();

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

        cout << count_partitions() << endl;
    }

    return 0;
}

int
count_partitions()
{
    int n_partitions = 0;
    int i, j;

    for (j = 0; j < h; j++) {
        string s;

        getline(cin, s);
        for (i = 0; i < w; i++)
            garden[i][j] = s[i];
    }

    for (i = 0; i < w; i++) {
        for (j = 0; j < h; j++) {
            switch (garden[i][j]) {
            case '@': // ????????´
            case '#': // ??????
            case '*': // ?????????
                n_partitions++;
                dfs(i, j, garden[i][j]);
            }
        }
    }

    return n_partitions;
}

// ??±???????????¢?´¢
void
dfs(int x, int y, char fruit)
{
    vector<pii>::iterator it;

    // ??¢?´¢???????????¨???????????????????????????
    garden[x][y] = '!';

    for (it = dir.begin(); it != dir.end(); ++it) {
        int x_new = x + it->first, y_new = y + it->second;

        if (0 <= x_new && x_new < w && 0 <= y_new && y_new < h &&
                garden[x_new][y_new] == fruit) {
            // ??°????????§?¨????????¨?????????§????????????????????´????????????????????????
            // ???????????¢?´¢??????
            dfs(x_new, y_new, fruit);
        }
    }
}

void
set_dir()
{
    dir.push_back(pii(1, 0)); // ???
    dir.push_back(pii(0, 1)); // ???
    dir.push_back(pii(-1, 0)); // ???
    dir.push_back(pii(0, -1)); // ???
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll n,k,d[105],a[105][105],s[105]={0},ans=0;
    cin >> n >> k;
    rep(i,1,k){
    	cin >> d[i];
    	rep(j,1,d[i]){
    		cin >> a[i][j];
    		s[a[i][j]]++;
    	}
    }
    rep(i,1,n){
    	if(s[i]==0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3708
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const S = arg.slice(1, N + 1);
    
    let array = [0, 0, 0, 0];
    
    for(let i=0; i<N; i++) {
        if(S[i] === "AC") {
            array[0]++;
        }
        if(S[i] === "WA") {
            array[1]++;
        }
        if(S[i] === "TLE") {
            array[2]++;
        }
        if(S[i] === "RE") {
            array[3]++;
        }
    }
    
    for(let i=0; i<4; i++) {
        if(i === 0) {
            console.log("AC x " + array[0]);
        }  
        if(i === 1) {
            console.log("WA x " + array[1]);
        }  
        if(i === 2) {
            console.log("TLE x " + array[2]);
        }  
        if(i === 3) {
            console.log("RE x " + array[3]);
        }  
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 38212
let lcs x y =
  let m = String.length x in
  let n = String.length y in
  let dp = Array.make_matrix (m+1) (n+1) 0 in
  let rec duduwa i j z =
    if j > n then doit (i + 1) z
    else begin
      dp.(i).(j) <- if x.[i-1] = y.[j-1] then dp.(i-1).(j-1) + 1 else max dp.(i - 1).(j) dp.(i).(j-1);
      duduwa i (j + 1) (max z dp.(i).(j))
    end
  and doit i z =
    if i > m then z
    else duduwa i 1 z
  in
  doit 1 0

let () =
  let q = read_int () in
  let rec doit i =
    if i < q then begin
      let x = read_line () in
      let y = read_line () in
      Printf.printf "%d\n" (lcs x y);
      doit (i + 1)
    end
  in
  doit 0

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n, m;
ll ans = -1;

int main() {
	cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    vector<pair<pii, int>> edges;
    for (int i = 0; i < m; ++i) {
        int l, r, c;
        cin >> l >> r >> c;
        edges.push_back({{l, r}, c});
    }

    sort(all(edges));

    // Dist, To which node
    set<pair<ll, ll>> cur;
    cur.insert({0, 1});
    
    for (int i = 0; i < m; ++i) {
        int l, r, c;
        l = edges[i].first.first, r = edges[i].first.second, c = edges[i].second;
        while (sz(cur) && cur.begin()->second < l)
            cur.erase(cur.begin());

        if (!cur.size()) break;
        if (r == n) {
            if (ans == -1) ans = cur.begin()->first + c;
            else ans = min(ans, cur.begin()->first + c);
        }

        cur.insert({cur.begin()->first + c, r});
    }

    cout << ans;
}


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

int n,m;

struct az
{
	int p;
	int y;
	int cnt;
}q[100005];

struct za
{
	int p;
	int y;
    int x;
}l[100005];

bool cmp(za a, za b)
{
	if(a.p==b.p) return a.y < b.y;
	return a.p < b.p;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i)
	   scanf("%d%d",&q[i].p,&q[i].y),l[i].x=i,l[i].p=q[i].p,l[i].y=q[i].y;
	sort(l+1,l+1+m,cmp);
	int now = 0 ;
	for(int i=1;i<=m;++i)
	{
		if(l[i].p != l[i-1].p) now=0;
		q[l[i].x].cnt=++now;
	}
	for(int i=1;i<=m;++i)
	{
		int s=q[i].p;
		int ls=0;
		while(s)
		{
			s/=10;
			++ls;
		}
		for(int j=1;j<=6-ls;++j)
		   cout<<0;
		cout<<q[i].p;
		s=q[i].cnt;
		ls=0;
		while(s)
		{
			s/=10;
			++ls;
		}
		for(int j=1;j<=6-ls;++j)
		   cout<<0;
		cout<<q[i].cnt;
		cout<<endl;
	}
	return 0;
 } 

Measured memory_bytes: 6104
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

vector<int> tree[100001];
int L[100001];
void DFS(int past, int now, int level){
	L[now] = level;
	
	for(int i = 0; i < tree[now].size(); i++){
		if(past != -1){
			if(tree[now][i] == past){
				continue;
			}
		}
		DFS(now, tree[now][i], level+1 );
	}
}

int DFS_2(int past, int now, int level, int BannedL){
	if(L[now] <= BannedL){
		return -1;
	}
	int M = 0;
	for(int i = 0; i < tree[now].size(); i++){
		if(past != -1){
			if(tree[now][i] == past){
				continue;
			}
		}
		M = max(M, DFS_2(now, tree[now][i], level+1, BannedL));
	}
	
	return max(M, L[now]);
}

int main()
{
 int N,u,v;
	cin >> N >> u >> v;
	for(int i = 0; i < N-1; i++){
		int A, B;
		cin >> A >> B;
		tree[A].push_back(B);
		tree[B].push_back(A);
	}
	
	DFS(-1, v, 0);
	
	int ban = L[u]/2;
	int result = DFS_2(-1, u, 0, ban);
	if(result == 0 && L[u] == 2){
		result = 1;
	}
	cout << result-1 << endl;
	
	return 0;
}

Measured memory_bytes: 11264
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
// template<class T> T gabs(const T& x) { return max(x, -x); }
// #define abs gabs

int main() {
    int n;
    cin >> n;
    vector<i64> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }

    if (a == b) {
        cout << 0 << endl;
        return 0;
    }

    i64 sum = 0, min_b = 1ll << 50;
    for (int i = 0; i < n; ++i) {
        sum += a[i];
        if (a[i] > b[i]) {
            min_b = min(min_b, b[i]);
        }
    }

    cout << sum - min_b << endl;
    return 0;
}

Measured memory_bytes: 640
n, m = map(int, input().split())
l1 = []
ln = []
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        l1.append(b)
    elif b == 1:
        l1.append(a)
    elif a == n:
        ln.append(b)
    elif b == n:
        ln.append(a)
l1.sort()
ln.sort()
ans = False
for i in l1:
    low = 0
    high = len(ln) - 1
    while low <= high:
        mid = (low + high)//2
        if ln[mid] == i:
            ans = True
            break
        elif ln[mid] > i:
            high = mid - 1
        else:
            low = mid + 1
    if ans:
        break
if ans:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

using namespace std;
int main()
{
  string S, T, U;
  cin >> S >> T;

  int A, B;
  cin >> A >> B;
  
  cin >> U;

  if (S == U) {
    A = A - 1;
  } else {
    B = B - 1;
  }
  
  cout << A << " " << B << endl;
  
  return 0;
}


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

void Main() {
  int N, M, Q;
  cin >> N >> M >> Q;

  int num[N][N];
  memset(num, 0, sizeof(num));

  for (int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    l--; r--;
    num[l][r] += 1;
  }

  int cum[N][N];
  memset(cum, 0, sizeof(cum));
  for (int i = 0; i < N; i++) {
    cum[i][0] = num[i][0];
    for (int j = 1; j < N; j++) {
      cum[i][j] = cum[i][j - 1] + num[i][j];
    }
  }

  for (int i = 0; i < Q; i++) {
    int p, q;
    cin >> p >> q;
    p--; q--;
    int ans = 0;
    for (int j = p; j <= q; j++) {
      if (p > 0) ans += cum[j][q] - cum[j][p - 1];
      else ans += cum[j][q];
    }
    cout << ans << endl;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 2944