akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp std::make_pair
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pll;
typedef std::vector<int> vi;
typedef std::set<ll> sll;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
ll N;
ll A[200010];
int main(){
  cin>>N;
  rep(i,N) cin>>A[i];
  pll p[200010];
  rep(i,N) p[i]=mp(A[i],i);
  std::sort(p,p+N);
  ll res=0;
  sll st;
  st.insert(-1);
  st.insert(N);  
  rep(i,N){
    ll f=p[i].first,s=p[i].second;
    auto itr_up=st.upper_bound(s);
    ll x=*itr_up;
    itr_up--;
    ll y=*itr_up;
    res+=f*(x-s)*(s-y);
    st.insert(s);
  }
  prin(res);
  return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  int i;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  long const mod = 1000000007;
  vector<int>numbers(100001,0);
  long ans = 1;
  for(i=0;i<n;i++){
    if(a[i] == 0){
      ans *= 3-numbers[0];
      ans %= mod;
      numbers[0]++;
    }else{
      ans *= numbers[a[i]-1]-numbers[a[i]];
      ans %= mod;
      numbers[a[i]]++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1152
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


int main() {
	
	ll n;
	cin >> n;
	map<int, int> mp;
	for (int i = 2; i <= n; i++) {
		int x = i;
		for (int j = 2; j <= x; j++) {
			while (x%j == 0) {
				x /= j;
				mp[j]++;
			}
		}
	}
	ll ans = 1;
	for (auto x : mp) {
		ans = ((ans%MOD) * (x.second + 1) % MOD) % MOD;
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{   int N;
    scanf(" %d",&N);
    char S[N],T[N];
    int i;
    scanf("%s %s",S,T);
    for(i=0;i<N;i++)
        printf("%c%c",S[i],T[i]);
    return 0;
}

Measured memory_bytes: 128
''' 
    [Bit]
'''
class Bit:
    """ used for only int(>=0) 
        1-indexed (ignore 0-index)
    """
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length()
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def lower_bound(self, x):
        """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1, sum_

    def get_less_than_x_cnt(self, x):
        """ 累積和がx未満 の個数 """
        lb_pos, lb_sum = self.lower_bound(x)
        return lb_pos-1

    def get_less_than_and_x_cnt(self, x):
        """ 累積和がx以下 の個数 """
        lb_pos, lb_sum = self.lower_bound(x+1)
        return lb_pos-1
    
    def get_more_than_x_cnt(self, x):
        """ 累積和がxより大きい 個数 """
        return self.size - self.get_less_than_and_x_cnt(x)


n = int(input())
pl = list(map(int, input().split()))
pll = []
for i,p in enumerate(pl):
    pll.append((p,i+2))

pll.sort(reverse=True)
bit = Bit(n+1)
bit.add(1,1)
ans = 0
for p,i in pll:
    ix = bit.sum(i)
    lmax, _ = bit.lower_bound(ix)
    lmin, _ = bit.lower_bound(ix-1)
    lcnt = lmax - lmin
    
    rmin, _ = bit.lower_bound(ix+1)
    rmax, _ = bit.lower_bound(ix+2)
    rcnt = rmax - rmin

    comb = lcnt*(rmin-i) + (i-lmax)*rcnt
    ans += comb*p

    bit.add(i,1)

print(ans)

Measured memory_bytes: 93092
using System;
using System.Linq;
class c
{
    static void Main()
    {
        var hw = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var map = new string[hw[0]];
        for (int i = 0; i < hw[0]; i++)
        {
            map[i] = Console.ReadLine();
        }
        var ans = new int[hw[0]][];
        for (int i = 0; i < hw[0]; i++)
        {
            ans[i] = new int[hw[1]];
        }
        for (int i = 0; i < hw[0]; i++)
        {
            for (int j = 0; j < hw[1]; j++)
            {
                if (map[i][j] == '.') ans[i][j] = 1;
                else ans[i][j] = int.MinValue;
            }
        }
        for (int i = 0; i < hw[0]; i++)
        {
            int temp = 0;
            for (int j = 0; j < hw[1]; j++)
            {
                ans[i][j] += temp;
                if (map[i][j] == '.') temp++;
                else temp = 0;
            }
        }
        for (int i = hw[0] - 1; i >= 0; i--)
        {
            int temp = 0;
            for (int j = hw[1] - 1; j >= 0; j--)
            {
                ans[i][j] += temp;
                if (map[i][j] == '.') temp++;
                else temp = 0;
            }
        }
        for (int i = 0; i < hw[1]; i++)
        {
            int temp = 0;
            for (int j = 0; j < hw[0]; j++)
            {
                ans[j][i] += temp;
                if (map[j][i] == '.') temp++;
                else temp = 0;
            }
        }
        for (int i = hw[1] - 1; i >= 0; i--)
        {
            int temp = 0;
            for (int j = hw[0] - 1; j >= 0; j--)
            {
                ans[j][i] += temp;
                if (map[j][i] == '.') temp++;
                else temp = 0;
            }
        }
        int max = 0;
        for (int i = 0; i < hw[0]; i++)
        {
            max = Math.Max(max, ans[i].Max());
        }
        Console.WriteLine(max);
    }
}

Measured memory_bytes: 43976
#include<bits/stdc++.h>  
template <class T>  
inline bool rd(T &ret) {  
    char c; int sgn;  
    if(c=getchar(),c==EOF) return 0;  
    while(c!='-'&&(c<'0'||c>'9')) c=getchar();  
    sgn=(c=='-')?-1:1;  
    ret=(c=='-')?0:(c-'0');  
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');  
    ret*=sgn;  
    return 1;  
}  
template <class T>  
inline void pt(T x) {  
    if (x <0) {  
        putchar('-');  
        x = -x;  
    }  
    if(x>9) pt(x/10);  
    putchar(x%10+'0');  
}  
using namespace std;  
typedef long long ll;  
const int MAXN = 55;  
double C[MAXN+1][MAXN+1];  
void Initial()  
{  
    memset(C, 0, sizeof C);  
    for(int i=0; i<=MAXN; ++i)  
    {  
        C[0][i] = 0.0;  
        C[i][0] = 1.0;  
    }  
    for(int i=1; i<=MAXN; ++i)  
    {  
        for(int j=1; j<=MAXN; ++j)  
        C[i][j] = C[i-1][j] + C[i-1][j-1];  
    }  
}  
const int N = 110;  
int n, m;  
int l, t[N], v[N];  
double p[N];  
double Pow(double x, int y){  
    double ans = 1.0;  
    while(y){  
        if(y&1)ans *= x;  
        x = x*x;  
        y >>= 1;  
    }  
    return ans;  
}  
double work(int x){  
    double ans = 0.0;  
    for(int i = 0; i <= m; i++)  
    {  
        double pp = C[m][i] * Pow(p[x], i) * Pow(1.0-p[x], m-i);  
        for(int j = 1; j <= n; j++)  
        {  
            if(j == x)continue;  
            double siz = 0;  
            for(int k = m; k >= 0; k--)  
            {  
                if(l*v[j] + i*t[x]*v[j]*v[x] < l*v[x] + k*t[j]*v[x]*v[j])  
                    siz += C[m][k] * Pow(p[j], k) * Pow(1.0-p[j], m-k);  
                else break;  
            }  
            pp *= siz;  
        }  
        ans += pp;  
    }  
    return ans;  
}  
void input(){  
    for(int i = 1; i <= n; i++)  
        {  
            rd(p[i]);rd(t[i]);rd(v[i]);  
            p[i] /= 100.0;  
        }  
}  
int main(){  
    Initial();  
    while(cin>>n>>m>>l){  
        input();  
        for(int i = 1; i <= n; i++)  
            printf("%.10f\n", work(i));  
    }  
    return 0;  
}  

Measured memory_bytes: 1220
use v6;
my $n = get().chomp;
my $k = get().chomp;
my $x = get().chomp;
my $y = get().chomp;

if ($k <= $n) {
       	say $k * $x + ($n - $k) * $y;
} else {
       	say $n * $x;
}

exit;

Measured memory_bytes: 66172
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string>
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(void) {
	ll n, m, sum = 0, a;
	cin >> n >> m;
	map<ll, ll>r;
	for (ll i = 0;i < n;i++) {
		cin >> a;
		sum += a;
		r[sum%m]++;
	}
	ll ans = 0;
	for (auto itr = r.begin();itr != r.end();++itr) {
		if (itr->first == 0) {
			if (itr->second == 1)ans += 1;
			else ans += ((itr->second)*(itr->second - 1)) / 2 + itr->second;
		}
		else {
			if (itr->second > 1)ans += ((itr->second)*(itr->second - 1)) / 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;
const int PN = 1 << 17;
int Puu[PN * 2];
void Muuta(int k, int x) {
	Puu[k += PN] |= x;
	while (k /= 2) Puu[k] = Puu[k * 2] | Puu[k * 2 + 1];
}
int Hae(int a, int b) {
	int r = 0;
	for (a += PN, b += PN; a <= b; a /= 2, b /= 2) {
		if (a % 2 == 1) r |= Puu[a++];
		if (b % 2 == 0) r |= Puu[b--];
	}
	return r;
}
int Lst[11], Fst[11], R, N;
char T[100100];
int main() {
	scanf("%d", &N);
	scanf("%s", T + 1);
	for (int i = 0; i < 10; ++i) Fst[i] = N + 1;
	for (int i = 1; i <= N; ++i) Lst[T[i] - '0'] = i;
	for (int i = N; i >= 1; --i) Fst[T[i] - '0'] = i;
	for (int i = 1; i <= N; ++i) Muuta(i, 1 << (T[i] - '0'));
	for (int a = 0; a < 10; ++a) {
		for (int b = 0; b < 10; ++b) {
			for (int c = 0; c < 10; ++c) {
				if (Hae(Fst[a] + 1, Lst[b] - 1) & (1 << c)) {
					++R;
				}
			}
		}
	}
	printf("%d\n", R);
}


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

void chmin (int& a, int b) {
  if (a > b) a = b;
}

int main() {
  int L, R;
  cin >> L >> R;
  bool num[2019] = {false};
  
  
  int count = 0;
  for (int i = L; i <= R; i++) {
    count++;
    num[i % 2019] = true;
    
    if (count == 2019) break;
  }

  
  int ans = 2018;
  for (int i = 0; i < 2019; i++) {
    if (!num[i]) continue;
    for (int j = i+1; j < 2019; j++) {
      if(!num[j]) continue;
      chmin(ans, (i * j) % 2019);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

// 隣接リスト
const ll MAX_V = 1010;
vvll g(MAX_V, vll());
vi visited(MAX_V, 0);

// グラフに対する幅優先探索
ll bfs(ll start){
    queue<pll> q;
    visited[start] = 1;
    ll depth = 0;
    ll now = start;
    q.emplace(now, depth);
    while(!q.empty()){
        now = q.front().first;
        depth = q.front().second;
        q.pop();
        for(auto to: g[now]){
            if(!visited[to]){
                visited[to] = 1;
                q.emplace(to, depth+1);
            }else if(to == start){
                return depth+1;
            }
        }
    }
    return INF;
}

vvll g2(MAX_V, vll());
ll mi;
vll ans;
ll stnode;
// グラフに対する深さ優先探索
void dfs(ll node, ll depth){
    ans.emplace_back(node);
    for(auto to: g2[node]){
        if(to == stnode){
            cout << SZ(ans) << endl;
            rep(i, SZ(ans)){
                cout << ans[i]+1 << "\n";
            }
            exit(0);
        }
        dfs(to, depth+1);
    }
    ans.pop_back();
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, m;
    cin >> n >> m;
    vll a(m), b(m);
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        g[a[i]].emplace_back(b[i]);
    }
    // 閉路
    vll clos(n);
    rep(i, n){
        fill(ALL(visited), 0);
        clos[i] = bfs(i);
    }
    mi = *min_element(ALL(clos));
    if(mi >= INF){
        cout << -1 << endl;
        return 0;
    }
    rep(i, m){
        if(clos[a[i]] == mi && clos[b[i]] == mi){
            g2[a[i]].emplace_back(b[i]);
        }
    }
    rep(i, n){
        stnode = i;
        dfs(i, 0);
    }
    return 0;
}

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

int n, pos;
vector<int> pre, in, post;

void reconstruction(int l, int r) {
  if ( l >= r ) return;
  int root = pre[pos++];
  int m = distance(in.begin(), find(in.begin(), in.end(), root));
  reconstruction(l, m);
  reconstruction(m + 1, r);
  post.push_back(root);
}

void solve() {
  pos = 0;
  reconstruction(pos, pre.size());
  for ( int i = 0; i < n; i++ ) {
    if ( i ) cout << " ";
    cout << post[i];
  }
  cout << endl;
}


int main() {
  int v;
  cin >> n;

  for ( int i = 0; i < n; i++ ) {
    cin >> v;
    pre.push_back(v);
  }

  for ( int i = 0; i < n; i++ ) {
    cin >> v;
    in.push_back(v);
  }

  solve();

  return 0;
}

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


void fn(int arr[], int n , int k)
{
    int dp[k+1] ; 

    dp[0]=0 ; 
    for(int i=1; i<= k ; i++)
    {
        int f=0 ; 
        for(int j=0 ; j<n ; j++)
        {
            if( (i-arr[j])>=0  and dp[i-arr[j]]==0)
            {
                f=1; 
                dp[i]= 1;
                break ;  
            }

        }

        if(f==0){
        dp[i]=0 ;}; 
    }

    if(dp[k]==0)
    {
        cout<<"Second";
    }  
    else
    {
        cout<<"First" ; 
    }

}

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

    int arr[n+1] ; 

    for (int i = 0; i < n; ++i)
    {
        int x; 
        cin>>x; 
        arr[i]=x; 
    }
    fn(arr, n, k) ; 


}

Measured memory_bytes: 3996
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A=list(map(int,input().split()))
    d=defaultdict(int)
    s=set()
    for x in A:
        d[x]+=1
        s.add(x)
    W=0
    for x in s:
        W+=d[x]*(d[x]-1)//2
    for x in A:
        a=d[x]
        print(W-a*(a-1)//2+(a-1)*(a-2)//2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 87776
#include<stdio.h>
long ans=-1000000000,min=1000000000,n;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int r;
        scanf("%ld",&r);
        if(i!=0&&ans<r-min) ans=r-min;
        if(min>r) min=r;
    }
    printf("%ld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    int M, N; cin >> M >> N;
    vector<int> A(N); for (auto &a : A) cin >> a;
    int ans = 0;
    if (M != 2) {
        for (int i = 0; i < N; i++) {
            int n = 1;
            while (i + 1 < N && A[i] == A[i + 1]) {
                i++, n++;
            }
            ans += n / 2;
        }
    } else {
        int a = 0;
        for (int i = 0; i < N; i++) a += A[i] == ((i % 2 == 0) + 1);
        int b = 0;
        for (int i = 0; i < N; i++) b += A[i] == ((i % 2 == 1) + 1);
        ans = min(a, b);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int f[100005],p[100005],ans[100005],fp[100005];string s;
inline int dfs(int i){
	if(fp[i])return p[i];
	fp[i]=1;
	if(f[i])return p[i]=i;
	if(s[i]=='L'){
		return p[i]=dfs(i-1);
	}else return p[i]=dfs(i+1);
}
int main(){
	cin>>s;
	for(int i=0;i<s.size()-1;i++){
		if(s[i]=='R'&&s[i+1]=='L'){
			f[i]=1;
		}
	}
	for(int i=0;i<s.size();i++){
		dfs(i);
		if(abs(p[i]-i)%2==0)ans[p[i]]++;else ans[p[i]+1]++;
	}
	for(int i=0;i<s.size();i++)cout<<ans[i]<<' ';
	return 0;
}

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

using namespace std;

int main() {
#ifdef  DEBUG
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif  // for local.
  string str;
  cin >> str;

  string s, r;
  int ans;
  s = str.substr(0, str.size()/2);
  reverse(str.begin(), str.end());
  r = str.substr(0, str.size()/2);
  for (int i = 0; i < str.size()/2; i++) {
    if (s[i] != r[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

char buf[20];
char res[20];

int main(void) {
  scanf("%s", buf);
  int n = 0;
  for(int i = 0; buf[i]; ++i) {
    if(buf[i] == 'B') {
      if (n > 0) {
        --n;
      }
      res[n] = 0;
    } else {
      res[n++] = buf[i]++;
    }
  }
  puts(res);
   
  return 0;
}


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int n;
  cin >> n;
  vector<long> a(n);
  for (long &x : a) {
    cin >> x;
  }
  vector<long> b(n, 0);
  for (int i = n - 2; i >= 0; i--) {
    b.at(i) = (b.at(i + 1) + a.at(i + 1)) % (1000000000 + 7);
  }
  long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a.at(i) % (1000000000 + 7) * b.at(i) % (1000000000 + 7);
    sum = sum % (1000000000 + 7);
  }
  cout << sum << endl;
}


Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a >= d || c >= b){
        cout << 0 << endl;
        return 0;
    }
    if (a > c) {
        if (d > b) {
            cout << b - a << endl;
        }else{
            cout << d - a << endl;
        }
    }else{
        if (d > b) {
            cout << b - c << endl;
        }else{
            cout << d - c << endl;
        }
    }
    return 0;
}


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

int main() {

    string a, b;
    cin >> a >> b;

    if(!(a.size() == b.size() - 1)) {
        cout << "No\n";
        return 0;
    }

    for(int i = 0; i < (int)a.size(); i++) {
        if(a[i] != b[i]) {
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 3592
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N, K;
	cin >> N >> K;
	int H[302] = {};
	rep1(i, N) cin >> H[i];
	ll hutuu = 0;
	rep(i, N + 1) {
		if (H[i + 1] > H[i]) hutuu += H[i + 1] - H[i];
	}

	ll dp[302][301] = {};
	rep(i, N + 1) {
		ll tmp1 = max(0, H[i + 1] - H[i]);
		ll tmp2 = max(0, H[i] - H[i + 1]);
		int mae = H[i + 1];
		for (int j = i + 2; j <= N + 1; j++) {
			if (mae < H[j]) tmp1 += H[j] - mae;
			if (mae > H[j]) tmp2 += mae - H[j];

			int k = j - i - 1;
			rep(p, K - k + 1) chmax(dp[j][p + k], dp[i][p] + min(tmp1, tmp2));
			mae = H[j];
		}
		rep(p, K + 1) chmax(dp[i + 1][p], dp[i][p]);

		//rep(p, K + 1) cesp(dp[i + 1][p]);
		//ce("");
	}
	co(hutuu - dp[N + 1][K]);


	Would you please return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}




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

    vector<int>A(N),B(N);
    rep(i,N) cin >> A[i];

    B = A;
    sort(B.begin(),B.end(),greater<int>());

    rep(i,N){
        if(A[i] == B[0])cout << B[1] << endl;
        else cout << B[0] << endl;
    }
}

Measured memory_bytes: 4840
import collections
n = int(input())
s = input()
ans = []
if n != 2:
    for i in range(1,n-1):
        counter = 0
        seg = s[0:i]
        another = s[i:n]
        d = collections.Counter(seg)
        for k in d:
            if k in another:
                counter += 1
        ans.append(counter)
    print(max(ans))
else:
    if s[0] == s[1]:
        print('1')
    else:
        print('0')

Measured memory_bytes: 3444
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iterator>
#include <fstream>
#include <math.h>

#include <random>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <list>
#include <bitset>
#include <unordered_set>
#include <unordered_map>

#include <random>
#include <ctime>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define FOR(i, from, to) for (int i = from; i < to; i++)
#define ROF(i, from, to) for (int i = from; i > to; i--)

const long double PI = 3.141592653589793238463;
const int INF = 0x3f3f3f3f;
const int INFS = 1000000000;
const ll M = 1000000007;
const ll LLINF = 1000000000000000000;
const double EPS = 1e-8;

#define int long long

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, x, ans = 0, tmp, n2;
    cin >> n >> x;
    n2 = 2 * n;
    vector<int> a(n2);
    FOR(i, 0, n) {
        cin >> a[i];
        ans += a[i];
    }
    FOR(i, n, n2)
        a[i] = a[i % n];
    vector<vector<int> > prec(n2, vector<int>(n2, LLINF));
    FOR(i, 0, n2) {
        prec[i][i] = a[i];
        FOR(j, i + 1, n2)
            prec[i][j] = min(a[j], prec[i][j - 1]);
    }
    FOR(i, 1, n + 1) {
        tmp = i * x;
        FOR(j, n, n2)
            tmp += prec[j - i][j];
        ans = min(ans, tmp);
    }
    cout << ans << "\n";

    return 0;
}


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

int main() {
  string S; cin >> S;
  ll ans = 0;
  int cnt = 0;
  rep(i, 0, S.size()) {
    if(S[i] == 'A') cnt++;
    else {
      if(i != S.size()-1 && S[i] == 'B' && S[i+1] == 'C') {
        ans += cnt;
        i++;
      }
      else cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
N = int(input())
W = [0]*N
W = list(map(int, input().split()))
SumW = int(0)

for i in range(N):
    SumW += W[i]

S = int(SumW//2+1)
M = int(0)
i = int(0)
while(S>M):
    M += W[i]
    i +=1

M2 = M - W[i-1]



ans = min(2*M-SumW,SumW-2*M2)


print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define for_int(i,a,b) for(int i=(a);i<=(b);++i)
#define rep_int(i,a,b) for(int i=(a);i>=(b);--i)
#define for_ll(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep_ll(i,a,b) for(ll i=(a);i>=(b);--i)
#define ull unsigned long long
#define ll long long
#define db double
#define HPMAX 1005
#define KMP_MAX 1005
#define prime_MAX 1e6+5
#define quick_pow_mod 1e9+7
#define PII pair<int,int>
const int factor_N = 1e7 + 5;
const int tree_arr_N = 1e6 + 5;
using namespace std;
//快读
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
	return x * f;
}
int x;
int main() {
	x = read();
	if (x >= 400 && x < 600) cout << 8 << endl;
	else if (x >= 600 && x < 800)cout << 7 << endl;
	else if (x >= 800 && x < 1000)cout << 6 << endl;
	else if (x >= 1000 && x < 1200)cout << 5 << endl;
	else if (x >= 1200 && x < 1400)cout << 4 << endl;
	else if (x >= 1400 && x < 1600) cout << 3 << endl;
	else if (x >= 1600 && x < 1800) cout << 2 << endl;
	else cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int A,B;
    cin >> A >> B;
    string str[100];
    for(int i = 0;i < 100;i++){
        if(i / 50)  str[i].resize(100,'.');
        else        str[i].resize(100,'#');
    }
    for(int i = 0;i < A-1;i++){
        int x = i%50*2, y = i/50*2;
        str[y][x] = '.';
    }
    for(int i = 0;i < B-1;i++){
        int x = i%50*2, y = i/50*2 + 51;
        str[y][x] = '#';
    }
    cout << "100 100" << endl;
    for(int i = 0;i < 100;i++)cout << str[i] << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
    int n; cin>>n;
    int a[100002];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    int p=0, ans=1;
    for(int i=0; i<n-1; i++){
        int pi=0;
        if(a[i]<a[i+1]){
            pi=1;
        }else if(a[i]>a[i+1]){
            pi=-1;
        }
        if(pi!=0){
            if(p==0) p=pi;
            else if(p!=pi){
                ans++;
                p=0;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 768
void main() {
	auto ip = readAs!(real[]), x1 = ip[0], y1 = ip[1], x2 = ip[2], y2 = ip[3];
	writefln("%.5f", (pow(x2-x1, 2) + pow(y2-y1, 2)).sqrt);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}



Measured memory_bytes: 2576
#include<stdio.h>
#include<math.h>
#define STANDARD 22;

struct BodyData
{
	int number;
	double bmi;
	double ideal_body;
};

int main(void) {
	int n,h,w,flag;
	int i,j;
	double a;
	struct BodyData data[1000],*p,temp;

	p = data;
	while (1) {
		scanf("%d",&n);
		if (n == 0)break;
		for (i = 0; i < n; i++) {
			scanf("%d %d %d",&data[i].number,&h,&w);
			data[i].bmi = w / pow((double)h / 100, 2);
			a = data[i].bmi - STANDARD;
			data[i].ideal_body = fabs(a);
		}
	
		for (i = 0; i < n; i++) {
			for (j = i+1; j < n; j++) {
				flag = 0;
				if ((p + i)->ideal_body == (p + j)->ideal_body) {
					if ((p + i)->number > (p + j)->number)flag = 1;
				}
				else if ((p + i)->ideal_body > (p + j)->ideal_body)
					flag = 1;
				if (flag) {
					temp = *(p + i);
					*(p + i) = *(p + j);
					*(p + j) = temp;
				}
			}
		}
		printf("%d\n",p->number);
	}
	return 0;
}

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

using namespace std;

int main()
{
    int a, b;
    int ans = 0;

    cin >> a >> b;

    for(int i = a; i <= b; ++i)
    {
        string num = to_string(i);
        bool isPalindromic = true;

        for(int j = 0; j < num.size() / 2; ++j)
        {
            if(num[j] != num[num.size() - 1 - j])
            {
                isPalindromic = false;
            }
        }

        ans += isPalindromic ? 1 : 0;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <numeric> 
#include <bits/stdc++.h>
typedef long long ll;
typedef std::pair<std::pair<int,int>,int>pi;
using namespace std;

int main() {
    ll n, m; cin >> n >> m;
    
    if(n%m == 0) cout << 0 << endl;
    else{
        cout << min(abs(n%m-m), abs(abs(n%m-m) - m)) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>

#define rep(i,n) for(int i = 0;i < (n);i++)
#define repp(i,j, n) for(int i = (j);i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define INF 1e9

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M, R;
  cin >> N >> M >> R;
  vi r(R);
  rep(i, R){
    cin >> r[i];
    r[i]--;
  }
  vvi cost(N, vi(N));
  rep(i, N) rep(j, N) cost[i][j] = INF;
  rep(i, M){
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    cost[a][b] = min(cost[a][b], c);
    cost[b][a] = min(cost[b][a], c);
  }

  rep(i, N) rep(j, N) rep(k, N) cost[j][k] = min(cost[j][i]+cost[i][k], cost[j][k]);
  sort(all(r));
  ll ans = INF;
  do {
    ll tmp = 0;
    rep(i, R-1) {
      tmp += cost[r[i]][r[i+1]];
    }
    ans = min(tmp, ans);
  }while(next_permutation(all(r)));

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


Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,ans=0; cin>>n;
    rep(i,n){
        int a; cin>>a;
        if((i+1)%2 && a%2) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(10) << ans << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;
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;
    }
};


signed main(){
    string s;
    cin >> s;
    twovec(a,13,s.size());
    if(s[0] == '?'){
        REP(i,10){
            a[i][0]++;
        }
    }
    else{
        int t = s[0] - '0';
        a[t][0]++;
    }
    REP(i,s.size()-1){
        if(s[i+1] == '?'){
            REP(j,13){
                int tmp = j*10;
                REP(k,10){
                    a[tmp%13][i+1] += a[j][i];
                    tmp++;
                    a[tmp%13][i+1] %= max_int;
                }
            }
        }
        else{
            int tmp = s[i+1] - '0';
            REP(j,13){
                int x = (j * 10 + tmp)%13;
                a[x][i+1] += a[j][i];
                a[x][i+1] %= max_int;
            }
        }
    }
    print(a[5][s.size()-1]%1000000007)
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std; 
int main(){
//  freopen("test.in","r",stdin);
//  freopen("test.out","w",stdout);
	int flag=1,i=0;
	char input[101];
	memset(input,'\0',sizeof(input));
	do{
	cin>>input[i];
	i++;	
	}while(input[i-1]!='\0');//这里要注意while判断的位置
	for(int i=0;input[i]!='\0';i++){
		if((i%2==1&&input[i]!='R')||(i%2==0&&input[i]!='L'))
			flag=1;
		else{
			flag=0;
			break;
	}
}
	if(flag==1)		cout<<"Yes";
	else 	cout<<"No";
    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//
using namespace std;
#define ll long long
#define F first
#define S second
int a[200005];
bool vis[200005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    int maxa=0,mina=n+1;
    for(int i=0;i<n;i++)
        cin>>a[i];
    set<int> s;
    set<int> s1;
    for(int i=0;i<k;i++)
    {
        mina=min(mina,a[i]);
        maxa=max(maxa,a[i]);
        s.insert(a[i]);
        s1.insert(-a[i]);
    }
    bool x=0;
    int t=0;
    int ans=n-k+1;
    for(int i=1;i<n;i++)
    {
        if(a[i]<a[i-1])
            t=0;
        else t++;
        if(t>=k-1) {
                if(x) ans--;
                x=1;
                vis[i-k+1]=true;
                //cout<<i-k+1<<'\n';

        }
    }
    //for(int i=0;i<n-k;i++)
    //cout<<vis[i]<<'\n';
    //cout<<ans<<'\n';
    for(int i=0;i<n-k;i++)
    {
        //cout<<maxa<<' '<<mina<<'\n';
        if(vis[i]) {
            s.erase(a[i]);
            s.insert(a[i+k]);
            s1.erase(-a[i]);
            s1.insert(-a[i+k]);
            mina=*s.begin();
            maxa=*s1.begin();
            maxa=-maxa;

            continue;
        }

        if(a[i+k]>maxa&&a[i]==mina)
        {
            //maxa=a[i+k];


            ans--;
            //cout<<i<<'\n';
        }
            s.erase(a[i]);
            s.insert(a[i+k]);
            s1.erase(-a[i]);
            s1.insert(-a[i+k]);
            mina=*s.begin();
            maxa=*s1.begin();
            maxa=-maxa;
    }
    cout<<ans<<'\n';
}


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

using namespace std;

//ifstream cin("/home/mihai/Documents/C++/ATCoder/Beginer_097/D/D.in");
//ofstream cout("/home/mihai/Documents/C++/ATCoder/Beginer_097/D/D.out");

const int NMAX = 1e5 + 5;

vector <int> v[NMAX];
int a[NMAX];
bool viz[NMAX];
int gr[NMAX];
int nr;

void DFS(int nod)
{
	gr[nod] = nr;
	viz[nod] = true;
	for(int i = 0; i < v[nod].size(); i++)
		if(!viz[v[nod][i]])
			DFS(v[nod][i]);
}
int main()
{
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = 1; i <= k; i++)
	{
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(int i = 1; i <= n; i++)
		if(!viz[i])
			{
				nr++;
				DFS(i);
			}
	int sol = 0;
	for(int i = 1; i <= n; i++)
		if(gr[i] == gr[a[i]])
			sol++;
	cout << sol;
}

Measured memory_bytes: 8576
import Control.Applicative ((<$>))
import qualified Control.Monad as Monad (forM_)
import qualified Control.Monad.Trans as Trans (lift)
import qualified Control.Monad.State as State (execStateT, modify)
import qualified Data.List.Split as Split (chunksOf)

type Room = (Int, Int, Int, Int)

main = do
    n <- getLine
    rs <- putRooms (read n)
    let rs' = Split.chunksOf limitRoom $ zipWith (++) (repeat " ") (show . getValue <$> rs)
    Monad.forM_ [1..(limitBuilding*limitFloor)] $ \bf -> do
        putStrLn $ concat $ rs' !! (bf-1)
        if ((bf `mod` limitFloor == 0) && bf /= (limitBuilding*limitFloor))
            then putStrLn "####################"
            else return ()

putRooms :: Int -> IO [Room]
putRooms n = (`State.execStateT` officialHouse) $ do
    Monad.forM_ [1..n] $ \_ -> do
        room <- Trans.lift $ toRoom . map (read :: String -> Int) . words <$> getLine
        State.modify (`updateRoom` room)

limitBuilding = 4
limitFloor    = 3
limitRoom     = 10

officialHouse :: [Room]
officialHouse = [ (b,f,r,0) | b <- [1..limitBuilding],
                              f <- [1..limitFloor],
                              r <- [1..limitRoom] ]

toRoom :: [Int] -> Room
toRoom [b,f,r,v] = (b,f,r,v)

getValue :: Room -> Int
getValue (_, _, _, v) = v

updateRoom :: [Room] -> Room -> [Room]
updateRoom [] _ = []
updateRoom (room1@(b1,f1,r1,v1):rs) room2@(b2,f2,r2,v2)
    | (b1,f1,r1) == (b2,f2,r2) = (b1,f1,r1,(v1 + v2)) : rs
    | otherwise                = room1 : updateRoom rs room2


Measured memory_bytes: 4720
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(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; }
const ll INF = 1LL << 60;
ll dist[305][305];
ll dist2[305][305];
int main(){
    int n, m;
    ll l;
    cin >> n >> m >> l;
    rep(i,n)rep(j,n){
        if(i==j) dist[i][j]=0;
        dist[i][j] = INF;
    }
    rep(i,n)rep(j,n){
        if(i==j) dist2[i][j]=0;
        dist2[i][j] = INF;
    }
    rep(i,m){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    rep(k,n)rep(i,n)rep(j,n) chmin(dist[i][j], dist[i][k]+dist[k][j]);
    rep(i,n)rep(j,n){
        if(i==j) continue;
        if(dist[i][j]<=l) dist2[i][j]=1;
    }
    rep(k,n)rep(i,n)rep(j,n) chmin(dist2[i][j], dist2[i][k]+dist2[k][j]);
    int q;
    cin >> q;
    rep(qi,q){
        int s,t;
        cin >> s >> t;
        s--; t--;
        if(dist2[s][t]==INF) cout << -1 << endl;
        else cout << dist2[s][t]-1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
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; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main() {
  int dp[50];
  dp[0] = 1; dp[1] = 1;
  FOR(i,2,44){
    dp[i] = dp[i-2] + dp[i-1];
  }
  int n; cin >> n;
  cout << dp[n] << endl;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int n,m,head[N],nxt[N*2],to[N*2],num=0,c[N],E=0,a[4],dis[N*2];
bool flag=0,vis[N*2];
vector<int>S;
inline void link(int x,int y,int z){
	nxt[++num]=head[x];to[num]=y;head[x]=num;dis[num]=z;}
inline void dfs(int x){
	S.push_back(x);
	for(int i=head[x];i;i=nxt[i]){
		int u=to[i],t=c[x]+dis[i];
		if(!vis[i])vis[i]=1,E++;
		if(!t)t=3;if(t==4)t=1;
		if(c[u]){
			if(c[u]!=t)flag=1;
		}
		else c[u]=t,dfs(u);
	}
}
int main(){
	int x,y;ll ans=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		link(x,y,1);link(y,x,-1);
	}
	for(int i=1;i<=n;i++){
		if(!c[i]){
			vector<int>().swap(S);c[i]=1;flag=0;E=0;
			dfs(i);
			memset(a,0,sizeof(a));
			for(int j=S.size()-1;j>=0;j--)a[c[S[j]]]++;
			if(flag)ans+=(ll)S.size()*S.size();
			else if(!a[1] || !a[2] || !a[3])ans+=E/2;
			else ans+=1ll*a[1]*a[2]+1ll*a[2]*a[3]+1ll*a[1]*a[3];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5624
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  
  public static long gcd(int a,int b) {
    return b == 0?a:gcd(b,a%b);
  }
  
  public static long lcm(int a,int b) {
    return a/gcd(a,b)*b;
  }
  
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    System.out.println(lcm(a,b));
  }
}

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

string s;
vector<long long> cnt;

long long solve();

int main() {
  cin >> s;

  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 1, ssize = s.size();
  cnt.assign(26, 0);
  for(int i = 0; i < ssize; ++i) ++cnt[s[i] - 'a'];
  for(int i = 0; i < 26; ++i)
    for(int j = i + 1; j < 26; ++j) ans += cnt[i] * cnt[j];
  return ans;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	acs := make(map[int]bool)
	was := make(map[int]int)
	for i:=0; i<m; i++ {
		var p int
		fmt.Scan(&p)
		var s string
		fmt.Scan(&s)

		if s == "AC" {
			acs[p] = true
		} else {
			_, ok := acs[p]
			if !ok {
				was[p]++
			}
		}
	}

	cnt1 := len(acs)
	
	cnt2 := 0
	for i, w := range was {
		_, ok := acs[i]
		if ok {
			cnt2 += w
		}
	}

	fmt.Printf("%d %d", cnt1, cnt2)
}


Measured memory_bytes: 7952
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    int cnt;
    cin >> n;
    cnt = 0;
    for (int i=0;i<n;i++){
        int a,b;
        cin >> a>>b;
        int c = b-a+1;
        cnt += c;

    }
    cout << cnt;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;



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

    int ans = 0;

    while(n){
        n /= k;
        ans++;
    }
    
    cout << ans << endl;
    

    
    return 0;
}

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

int main() {
    int A[3][3];
    bool map[3][3];
    int N;
    int b[100];

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> A[i][j];
            map[i][j] = false;
        }
    }
    cin >> N;
    for (int k = 0; k < N; k++) {
        cin >> b[k];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (A[i][j] == b[k]) map[i][j] = true;
            }
        }
    }
    for (int i = 0; i < 3; i++) {
        if (map[i][0] && map[i][1] && map[i][2]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    for (int i = 0; i < 3; i++) {
        if (map[0][i] && map[1][i] && map[2][i]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if ((map[0][0] && map[1][1] && map[2][2]) || (map[2][0] && map[1][1] && map[0][2])) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


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

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

  int N, K, num;
  int counter=0;

  cin >> N;
  cin >> K;

  for (int i=0; i<N; ++i)
  {
    cin >> num;
    if (num>=K) ++counter;
  }

  cout << counter << "\n ";

  return 0;

}

Measured memory_bytes: 256