akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
ll dp[1<<16] = {};

int main(){
  int N;
  while(cin>>N && N){
    ll ans = 0;
    memset(dp, 0, sizeof(dp));
    REP(i, N){
      int M; ll L;
      cin>>M>>L;
      int mask = 0;
      REP(t, M){
        int S, E;
        cin>>S>>E;
        S -= 6; E -= 6;
        for(int j = S; j < E; j++) mask |= (1 << j);
      }
      for(int S = 0; S < 1<<16; S++)if((mask & S) == 0){
        int next = S | mask;
        dp[next] = max(dp[next], dp[S] + L);
        ans = max(ans, dp[next]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int N;
double dp[310][310][310];
double rec(int i, int j, int k)
{
    if (dp[i][j][k] >= 0)
        return dp[i][j][k];

    if (i == 0 && j == 0 && k == 0)
        return 0.0;

    double res = 0.0;
    if (i > 0)
        res += rec(i - 1, j, k) * i;
    if (j > 0)
        res += rec(i + 1, j - 1, k) * j;
    if (k > 0)
        res += rec(i, j + 1, k - 1) * k;

    res += N;
    res *= 1.0 / (i + j + k);

    return dp[i][j][k] = res;
}

int main()
{
    cin >> N;
    int one = 0, two = 0, three = 0;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        if (a == 1)
            ++one;
        else if (a == 2)
            ++two;
        else
            ++three;
    }

    memset(dp, -1, sizeof(dp));

    cout << fixed << setprecision(10) << rec(one, two, three) << endl;

    return 0;
}

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

int N;
using P = pair<int, int>;
using P3 = pair<P, int>;
vector<P> ul, lr;
vector<int> ans;
int cnt = 0;

void dfs(int bit) { 
  if ( bit == 0 ) return;
  // cout << bit << endl;  
  vector<P3> L;
  for ( int i = 0; i < N; i++ ) {
    if ( (1<<i)&bit ) L.push_back(P3(P(ul[i].first, ul[i].second), i));    
  }
  sort(L.begin(), L.end());
  // ans.push_back(L[0].second);
  ans[L[0].second] = cnt++;  
  int k = L[0].second;
  // cout << "first " << k << " " << ul[k].first << endl;
  for ( P3 &i : L ) i.first.second = i.first.second*(-1);
  sort(L.begin(), L.end());  
  int nxt = 0;  
  for ( int i = 1; i < (int)L.size(); i++ ) {
    int j = L[i].second;
    if ( k == j ) continue;
    // cout << bit << " " << j << " " << L[i].first.second << endl;    
    if ( ul[j].second < lr[k].second &&
	 lr[j].second > lr[k].second ) break;
    if ( lr[k].second >= lr[j].second ) nxt |= (1<<j);    
  }
  dfs(nxt);
  dfs(bit-nxt-(1<<k));   
}

int tests = 0;

int main() {
  while ( cin >> N, N ) {
    cnt = 0;
    ans = vector<int>(N);    
    if ( tests++ ) cout << endl;    
    ul = lr = vector<P>(N);
    ans.clear();    
    for ( int i = 0; i < N; i++ ) {
      cin >> ul[i].first >> ul[i].second;      
      cin >> lr[i].first >> lr[i].second;
    }

    dfs((1<<N)-1);
    for ( int i = 0; i < N; i++ ) cout << ans[i]+1 << endl;
  }
  return 0;  
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int a, b, c;
    cin>>a>>b>>c;
    rep(i, b){
        if(((i+1)*a)%b == c) {
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

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

#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;

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

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

int op(int a, int b) { return max(a, b); }

int e() { return 0; }

int main() {
    int N, K, ans = 0;
    cin >> N >> K;
    segtree<int, op, e> seg(300001);

    REP(i, N) {
        int A, res;
        cin >> A;
        res = seg.prod(max(A - K, 0), min(A + K + 1, 300001)) + 1;
        chmax(ans, res);
        seg.set(A, res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 8552
//#include <bits/stdc++.h>
//using namespace std;
//#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#define ll long long int
//
//int main() {
//
//    fastio;
//
//    ll n,k;
//    vector<ll> v(705);
//    vector<ll> b(705);
//    vector<vector<ll>> dp(705 , vector<ll>(705,0));
//
//    cin >> n >> k;
//    for(ll i = 1; i <= n; i++) cin >> v[i];
//    for(ll i = 1; i <= n; i++) cin >> b[i];
//
//    // OPTIMAL SUB-PROBLEM :
//
//    // dp[i][j] = maximum value we can obtain if we pair up brackets from i to j
//
//    // BASE CASE :
//    // RECURSIVE RELATION :
//
//    for(ll i = 1; i <= n; i++){
//        for(ll j = 1; j + i - 1 <= n; j++){
//
//            ll ii = j;
//            ll jj = i+j-1;
//            if(b[ii] + k == b[jj]){
//                dp[ii][jj] = max(dp[ii][jj] , v[ii] + v[jj] + dp[ii+1][jj-1]);
//            }
//            for(ll m = ii+1; m <= jj; m++){
//                dp[ii][jj] = max(dp[ii][jj] , dp[ii][m-1]+ dp[m][jj]);
//            }
//        }
//    }
//
//    // OPTIMAL SOLUTION :
//
//    cout << dp[1][n];
//
//    return 0;
//}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int

int main() {

    fastio;

    ll k,x;
    cin >> k >> x;
    if(500*k >= x) cout << "Yes";
    else cout << "No";

    return 0;
}

Measured memory_bytes: 256
S = list(">" + input() + "<")


N = len(S) - 1
inf = 1001001
table = [inf] * N

minnum = 0
l = 0
r = 1


for i in range(N):
    if S[i+1] == "<" and S[i] == ">":
        table[i] = 0
    elif S[i] == "<":
        table[i] = table[i-1] + 1

for i in range(N, 0, -1):
    if S[i-1] == ">" and S[i] == ">":
        if table[i-1] > table[i] + 1:
            table[i-1] = table[i] + 1
    elif S[i-1] == "<" and S[i] == ">":
        if table[i-1] < table[i] + 1:
            table[i-1] = table[i] + 1

print(sum(table))


Measured memory_bytes: 93716
s = input()
t = input()
d = {i:[] for i in "abcdefghijklmnopqrstuvwxyz"}
for i in range(len(s)):
    d[s[i]].append(i)
for i in t:
    if len(d[i]) == 0:
        print(-1)
        exit()

def binary_search(arr, k):
    l, r = 0, len(arr)-1
    while l <= r:
        m = l+r >> 1
        if arr[m] < k:
            l = m+1
        else:
            r = m-1
    return l

a, b = 0, 0
for i in t:
    j = binary_search(d[i], a)
    if len(d[i]) <= j:
        a = 0
        b += 1
        j = binary_search(d[i], 0)
    a = d[i][j] + 1
print(b * len(s) + a)

Measured memory_bytes: 45680
S = input()
T = input()
ns = len(S)
nt = len(T)
idx_start = 0
n_eq_max = 0
for i in range(ns-nt+1):
    n_eq = 0
    for j in range(nt):
        if T[j] == S[i+j]:
            n_eq += 1
    if n_eq_max < n_eq:
        n_eq_max = n_eq
        idx_start = i
print(nt-n_eq_max)

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct BIT{
    int N;
    vector<int>bit;
    BIT(int x) {
        N = x;
        bit.resize(x+1);
    }
    void add(int x,int y) {
        while(x <= N) {
            bit[x] += y;
            x += x&-x;
        }
    }
    int sum(int x) {
        int res = 0;
        while(x) {
            res += bit[x];x-=x&-x;
        }
        return res;
    }
    int sum(int l, int r) {
        return sum(r+1)-sum(l);
    }
};
signed main(){
    int N,Q;
    cin >> N >> Q;
    vector<int>c(N);
    for(int i = 0; i < N; i++) {
        cin >> c[i];
        c[i]--;
    }
    vector<int>ans(Q);
    vector<vector<P>>cnt(N);
    for(int i = 0; i < Q; i++) {
        int l,r;
        cin >> l >> r;
        l--;r--;
        cnt[r].push_back({l,i});
    }
    BIT bt(N);
    vector<int>res(N,-1);
    for(int i = 0; i < N; i++) {
        if(res[c[i]] != -1) {
            bt.add(res[c[i]],-1);
        }
        bt.add(i+1,1);
        res[c[i]] = i+1;
        for(int j = 0; j < cnt[i].size(); j++) {
            ans[cnt[i][j].second] = bt.sum(cnt[i][j].first,i);
        }
    }
    for(int i = 0; i < Q; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 44168
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
    int debt=100000;
    int i;
    scanf("%d",&i);
    for(;i>0;i--){
        debt+=debt*0.05;
        debt+=999;
        debt/=1000;
        debt*=1000;
    }
    printf("%d\n",debt);
    return 0;
}

Measured memory_bytes: 592
#include <iostream>
using namespace std;
int main(void){
    int N,K;
    cin>>N>>K;
    int P[100]={0};
    for(int i=0;i<K;i++){
        int d;
        cin>>d;
        for(int j=0;j<d;j++){
            int a;
            cin>>a;
            P[a-1]++;
        }
    }
    int count=0;
    for(int i=0;i<N;i++){
        if(P[i]==0){
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+3;
char a[N];
int n;
int calc(int tp) 
{
int res=0;
  for (int i=1;i<=n;++i)
	if(a[i]-'0'!=(i+tp)%2)
	  res++;
return res;
}

int main() 
{
scanf("%s",a+1);
n=int(strlen(a+1));
printf("%d\n",min(calc(0),calc(1)));
return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#define N 100
#define INF 1000000
#define WHITE 0
#define BLACK 1
 
int main(){

  int i,j,n,count=0,u,k,v,c,mincost,a,G[N][N],color[N],d[N],pi[N];
 
  for( i = 0 ; i < N ; i++ ){
    for( j = 0 ; j < N ; j++ ){
      G[i][j] = -1;
    }
  }

  scanf("%d",&n);
 
  for( i = 0 ; i < n ; i++ ){
    scanf("%d%d",&u,&k);
    for( j = 0 ; j < k ; j++ ){
      scanf("%d%d",&v,&c);
      G[u][v] = c;
    }
  }
 
  for( i = 0 ; i < n ; i++ ){
    color[i] = WHITE;
    pi[i] = -1;
    d[i]=INF;
  }
 
  d[0]=0;
 
  while(1){
    mincost = INF;
    for( i = 0 ; i < n ; i++ ){
      if( color[i] != 2 && d[i] < mincost ){
	mincost = d[i];
	a = i;
      }
    }
    if( mincost == INF ){
      break;
    }
      
    color[a] = 2;
 
    for( i = 0 ; i < n ; i++ ){
      if( G[a][i] != -1 && color[i] != 2 && (G[a][i]+d[a]) < d[i] ){
	pi[i]= a;
	d[i] = G[a][i]+ d[a];
	color[i] = BLACK;
      }
    }
  }
 
  for( i = 0 ; i < n ; i++ )
    printf("%d %d\n",i,d[i]);

  return 0;

}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define PI 3.14159265359
#define rep(i,n) for(int i=0; i<n; ++i)
#define INF 1001001001
#define MAX_X 2002
#define MAX_Y 2002
typedef long long ll;
typedef pair<int, int> P;

int main() {
    P s, t;
    cin >> s.first >> s.second;
    cin >> t.first >> t.second;

    P p = s;
    while (p.first != t.first) {
        cout << 'R';
        p.first++;
    }

    while (p.second != t.second) {
        cout << 'U';
        p.second++;
    }

    while (p.first != s.first) {
        cout << 'L';
        p.first--;
    }

    while (p.second != s.second) {
        cout << 'D';
        p.second--;
    }

    cout << 'D';
    p.second--;
    while (p.first != (t.first + 1)) {
        cout << 'R';
        p.first++;
    }

    while (p.second != t.second) {
        cout << "U";
        p.second++;
    }
    cout << 'L';
    p.first--;

    cout << 'U';
    p.second++;
    while (p.first != (s.first - 1)) {
        cout << 'L';
        p.first--;
    }

    while (p.second != s.second) {
        cout << 'D';
        p.second--;
    }
    cout << 'R';
    p.first++;

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int lim = 20000;
int main() {
	int N;
	cin >> N;
	vector<int> W(N), S(N), V(N);
	for (int i = 0; i < N; ++i) {
		cin >> W[i] >> S[i] >> V[i];
	}
	vector<int> p(N);
	for (int i = 0; i < N; ++i) {
		p[i] = i;
	}
	sort(p.begin(), p.end(), [&](int i, int j) { return W[i] + S[i] < W[j] + S[j]; });
	vector<long long> dp(lim + 1);
	for (int i = 0; i < N; ++i) {
		for (int j = S[p[i]]; j >= 0; --j) {
			dp[j + W[p[i]]] = max(dp[j + W[p[i]]], dp[j] + V[p[i]]);
		}
	}
	cout << *max_element(dp.begin(), dp.end()) << '\n';
	return 0;
}

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

using namespace std;
const long mod = 1000000007;
typedef long long lint;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(N) for(int i = 0; i < (int)(N); i++)
#define all(x) (x).begin(),(x).end()
#define length(x) ((int)(x).size())
#define prln(s) cout<<s<<endl;

#define str(s) string s;cin>>s;
#define int1(x) int x;cin>>x;
#define int2(x,y) int x,y;cin>>x>>y;

using pr = pair<lint,lint>;
int comp(pr x, pr y){
  return x.first<y.first;
}
int main() {
  int2(N,M);
  vector< pr > drinks;
  repi(N){
    int2(ai,bi);
    drinks.push_back(make_pair(ai,bi));
  }
  sort(all(drinks));
  lint sum=0;
  lint bought=0;
  for(const auto &e:drinks){
    repi(e.second){
      sum+=e.first;
      bought++;
      if(bought>=M){
        break;
      }
    }
    if(bought>=M){
      break;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 2420
from collections import defaultdict
N, M = list(map(int, input().split()))
K = []
A = []
for _ in range(N):
    line = list(map(int, input().split()))
    K += [line[0]]
    A += [line[1:]]

count = defaultdict(int)
for a_ in A:
    for a in a_:
        count[a] += 1

result = 0
for k, v in count.items():
    if v == N:
        result += 1
print(result)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
  int countA=0;
  int countB=0;
  int countC=0;
int keisan(int x,string s,string a,string b,string c){
  if(s[x]=='a')return countA++;
  if(s[x]=='b')return countB++;
  if(s[x]=='c')return countC++;
}
string moji(int x,string s,string a,string b,string c){
  if(s[x]=='a')return a;
  if(s[x]=='b')return b;
  if(s[x]=='c')return c;
}

int main() {
  string a,b,c;
  cin>>a>>b>>c;
  int kazuA=a.size()+1;
  int kazuB=b.size()+1;
  int kazuC=c.size()+1;
  bool vA=false;
  bool vB=false;
  bool vC=false;
  int x=0;
  string s=a;
  while(countA+countB+countC<kazuA+kazuB+kazuC){
    if(countA==kazuA){
      vA=true;
      break;
    }else if(countB==kazuB){
      vB=true;
      break;
    }else if(countC==kazuC){
      vC=true;
      break;
    }
    int tmp=x;
    x=keisan(x,s,a,b,c);
    s=moji(tmp,s,a,b,c);
  }
  if(vA==true){
    cout<<"A"<<endl;
  }else if(vB==true){
    cout<<"B"<<endl;
  }else if(vC==true){
    cout<<"C"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

struct BipartiteMatching {
	int n;
	vector<vector<int>> g;
	vector<int> match;
	vector<int> used;
	BipartiteMatching(int n) : n(n), g(n), match(n), used(n) {}
	void addEdge(int u, int v) {
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	int maximumMatching() {
		int cnt = 0;
		fill(match.begin(), match.end(), -1);
		for (int v = 0; v < n; v++) {
			if (match[v] == -1) {
				fill(used.begin(), used.end(), false);
				if (augment(v)) cnt++;
			}
		}
		return cnt;
	}
	bool augment(int v) {
		used[v] = true;
		for (int u : g[v]) {
			int w = match[u];
			if (w == -1 || (!used[w] && augment(w))) {
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int N, M, L; cin >> N >> M >> L&&N;) {
		vector<vector<int>> g(N, vector<int>(N, INF));
		rep(i, 0, M) {
			int u, v, d; cin >> u >> v >> d;
			g[u][v] = g[v][u] = d;
		}
		rep(i, 0, N)
			g[i][i] = 0;
		rep(k, 0, N)rep(i, 0, N)rep(j, 0, N) {
			if (g[i][k] != INF&&g[k][j] != INF)
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
		}

		vector<int> p(L), t(L); rep(i, 0, L) {
			cin >> p[i] >> t[i];
		}
		BipartiteMatching bm(L + L);
		int source = L + L, sink = source + 1;
		rep(i, 0, L) {
			rep(j, 0, L) {
				if (i == j)continue;
				if (g[p[i]][p[j]] <= t[j] - t[i]) {
					bm.addEdge(i, L + j);
				}
			}
		}
		auto ans = L - bm.maximumMatching();
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 8432
/*input
1
*/

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <iomanip>
#include <utility>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

ll MOD = 1000000007;
const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define inv(a)      powr((a), (MOD - 2))
#define all(c)      (c).begin(),(c).end()
#define rep(i,a,b)  for(ll i = (a); i < (b); i ++)
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template<typename T> void toInt(string s, T &a) { istringstream(s) >> a; }
ll gcd(ll a, ll b) { ll t; while(a) { t = a; a = b%a; b = t; } return b; }
ll sub(ll a, ll b) { a -= b; a = (a + MOD) % MOD; return a; }
ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll add(ll a, ll b) { a += b; a %= MOD; return a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

ll powr(ll a, ll b) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a);
    a = mul(a, a), b >>= 1;
  }
  return x;
}

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/*********************************START**********************************/
const int N = 100005;

int main()
{
  ifalse;
  ll n;
  cin >> n;
  // n --;
  ll ans = (n * (n - 1)) / 2;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var c = Console.ReadLine();
        switch (c)
        {
            case "a":
            case "i":
            case "u":
            case "e":
            case "o":
                Console.WriteLine("vowel");
                break;
            default:
                Console.WriteLine("consonant");
                break;
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
using Graph = vector<vector<ll>>;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);


int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> l(m), r(m);
    rep(i, m) cin >> l[i] >> r[i];
    sort(all(l));
    sort(all(r));
    cout << max(0LL, r[0] - l[m-1] + 1) << endl;
}


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

int main(){
  char a,b,c,d; cin>>a>>b>>c>>d;
  if((a==b && c==d && a!=c)||(a==c && b==d && a!=b)||(a==d && b==c && a!=b))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 764
import sys
fin = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush


class Vertex(object):
    def __init__(self, name, distance):
        self.name = name
        self.distance = distance


    def __lt__(self, other_vertex):
        return self.distance < other_vertex.distance
    

    def __le__(self, other_vertex):
        return self.distance <= other_vertex.distance
    

    def __gt__(self, other_vertex):
        return self.distance > other_vertex.distance
    

    def __ge__(self, other_vertex):
        return self.distance >= other_vertex.distance


def initialize(adj, s):
    MAX_NUM = float('inf')
    parent = {s: None}
    d = {vertex: MAX_NUM for vertex in adj.keys()}
    d[s] = 0
    return d, parent


# Dijkstra can work using a minheap which does not have decrease_key.
# in this case, the time it takes is O(ElgE).
# E is at most O(V^2), thus O(ElgE) = O(ElgV).
def dijkstra_simple(adj, w, s):
    d, _ = initialize(adj, s)
    priority_queue = []
    heappush(priority_queue, Vertex(s, d[s]))
    while priority_queue:
        vertex = heappop(priority_queue)
        source, distance = vertex.name, vertex.distance
        for neighbor in adj[source]:
            new_distance = distance + w[(source, neighbor)]
            if new_distance < d[neighbor]:
                d[neighbor] = new_distance
#                parent[neighbor] = source
                heappush(priority_queue, Vertex(neighbor, new_distance))
    return d


n, m, s, t = [int(elem) for elem in fin().split(' ')]
adj = defaultdict(list)
yen_weights = dict()
snuuk_weights = dict()
for _ in range(m):
    u, v, a, b = [int(elem) for elem in fin().split(' ')]
    for v1, v2 in [(u, v), (v, u)]:
        adj[v1].append(v2)
        yen_weights[(v1, v2)] = a
        snuuk_weights[(v1, v2)] = b

d_yen = dijkstra_simple(adj, yen_weights, s)
d_snuuk = dijkstra_simple(adj, snuuk_weights, t)
min_cost = float('inf')
min_cost_after_each_year_reversed = []
for vertex in range(n, 0, -1):
    min_cost = min(min_cost, d_yen[vertex] + d_snuuk[vertex])
    min_cost_after_each_year_reversed.append(min_cost)

initial_money = 10**15
for i in reversed(range(n)):
    print(initial_money - min_cost_after_each_year_reversed[i])


Measured memory_bytes: 132968
S = input()
n = len(S)
 
ans = 0
 
for i in range(2**(n-1)):
    t = S[0]
    for j in range(n-1):
        if (i>>j)&1:
            t += "+"
        t += S[j+1]
    ans += eval(t)
 
print(ans)

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rev(a) reverse(all(a)
#define ld long double
const ll mod=1e9+7;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
bool ispal(string s){
    int n=s.length();
    for(int i=0; i<n/2; i++){
        if(s[i]!=s[n-1-i]) return false;
    }
    return true;
}
int main() {
    ll n;
    cin >> n;
    ll a[n];
    map<ll,ll> m;
    ll ans=0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        m[a[i]]++;
    }
    
    for(auto i: m){
        ans+=i.ss*(i.ss-1)/2; 
    }
    for(int i=0; i<n; i++){
        ll temp=ans-(m[a[i]]*(m[a[i]]-1)/2);
        temp+=((m[a[i]]-1)*(m[a[i]]-2)/2);
        cout << temp << endl;
    }
	return 0;
}

Measured memory_bytes: 11008
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
int dp[101][10001];//dp[i+1][j]は,i番目までの品物を選んで重さをj以下にする場合.
int main(){
  int v[1000];
  int w[1000];
  int N,W;
  cin >> N >> W;
  for(int i = 0;i < N;i++){
    cin >> v[i] >> w[i];
  }

  for(int i = 0;i < N;i++){
    for(int j = 0;j <= W;j++){
      if(j < w[i])dp[i+1][j] = dp[i][j];
      else{
        dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i]);
      }
    }
  }

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



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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 1e4 + 20;
const int maxm = (int) 1e6 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}

int n, m;
vector<int> G[55];
int fa[55], dep[55];
LL s[55];

void dfs(int u, int f) {for(auto v : G[u]) if(v != f) fa[v] = u, dep[v] = dep[u] + 1, dfs(v, u);};

void work()
{
    cin >>n;
    for(int i = 1; i < n; i++)
    {
        int x, y; cin >>x >>y;
        G[x].pb(y);
        G[y].pb(x);
    }

    dfs(1, 1);

    cin >>m;
    for(int i = 0; i < m; i++)
    {
        int x, y; cin >>x >>y;
        if(dep[x] < dep[y]) swap(x, y);
        LL ss = 0;
        while(dep[x] != dep[y]) ss |= 1LL << (x - 1), x = fa[x];
        while(x != y) ss |= (1LL << (x - 1)) | (1LL << (y - 1)), x = fa[x], y = fa[y];

        s[i] = ss;
    }

    LL ans = 0;
    for(int i = 0; i < (1 << m); i++)
    {
        int cnt = 0, cnt2 = 0;
        LL ss = 0;
        for(int j = 0; j < m; j++) if((i >> j) & 1) ss |= s[j], cnt++;
        for(int j = 0; j < n; j++) if((ss >> j) & 1) cnt2++;

        ans += (cnt & 1 ? -1 : 1) * (1LL << (n - 1 - cnt2));
    }
    cout <<ans <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

bool check(string tmp) {
    // cout << tmp << endl;
    if(tmp.length() % 2 == 1) {
        cout << "nope" << endl;
        return false;
    } else {
        int len = tmp.length();
        string before = tmp.substr(0, len / 2);
        string after = tmp.substr(len / 2);
        // cout << before << ":" << after << endl;
        return before == after;
    }
}
int main() {
   int r,g,b;
  cin>>r>>g>>b;
  if((100*r+10*g+b)%4==0){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
    return 0;
}

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

namespace CSharp_AtCoder
{

    
    class Program
    {

        const int MAX = 1000000009;

        static int Solve(int n, int k, int[] h)
        {
            int[] dp = new int[n];
            for (int i = 0; i < n; i++) dp[i] = MAX;
            dp[0] = 0;
            dp[1] = Math.Abs(h[1] - h[0]);

            for(int i = 2; i < n; i++)
            {
                for(int j = 1; j <= k && i - j >= 0; j++)
                {
                    dp[i] = Math.Min(dp[i], dp[i - j] + Math.Abs(h[i] - h[i - j]));
                }
            }

            return dp[n - 1];
        }

        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int n = input[0];
            int k = input[1];

            int[] h = new int[n];
            h = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            Console.WriteLine(Solve(n, k, h));

        }
    }
}


Measured memory_bytes: 18912
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N, M, X;

int main() {
    while (cin >> N >> M >> X) {
        int num = 0;
        for (int i = 0; i < M; ++i) {
            int a; cin >> a;
            if (a < X) ++num;
        }
        cout << min(num, M-num) << endl;
    }
}

Measured memory_bytes: 384
#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

constexpr int MAX_N = 100000;

int N;
int p[MAX_N];
bool fl[MAX_N];

int main()
{
  scanf( "%d", &N );
  rep( i, N )
    scanf( "%d", p+i ), fl[i] = i+1 == p[i];

  int p = 0, ans = 0;
  while( p < N )
  {
    if( fl[p] )
    {
      p += 2;
      ++ans;
    }
    else
      ++p;
  }

  printf( "%d\n", ans );

  return 0;
}

Measured memory_bytes: 640
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <list>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;

int main(void){
    int n;
    cin>>n;
    int a[100001];
    int num[100001]={};
    bool ok=true;
    for(int i=0;i<n;i++){
        cin>>a[i];
        num[a[i]]++;
        if(num[a[i]]>=3)ok=false;
    }
    ll ans=1;
    if(n%2==0){
        if(num[0]!=0)ok=false;
        for(int i=1;i<n;i++){
            if(num[i]!=2&&num[i]!=0)ok=false;
    }
    }else{
        if(num[0]!=1)ok=false;
            }
    for(int i=0;i<n/2;i++){
        ans*=2;
        ans%=MOD;
    }
    if(ok)cout<<ans<<endl;
    else cout<<"0"<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const int mx = 12800;
bool dp[80][80][mx + 1];


int main(){
    int h, w;
    cin >> h >> w;
    int a[h][w];
    int b[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> b[i][j];
        }
    }

    int dx[2] = {1, 0};
    int dy[2] = {0, 1};

    dp[0][0][abs(a[0][0] - b[0][0])] = true;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int k = 0; k < 2; k++){
                int nx = i + dx[k];
                int ny = j + dy[k];
                if(nx < h && ny < w){
                    int d = abs(a[nx][ny] - b[nx][ny]);
                    for(int l = 0; l <= mx; l++){
                        if(dp[i][j][l]){
                            int p = abs(l - d);
                            int q = min(mx, l + d);
                            dp[nx][ny][p] = true;
                            dp[nx][ny][q] = true;
                        }
                    }
                }
            }
        }
    }

    int ans = mx;
    for(int i = 0; i <= mx; i++){
        if(dp[h - 1][w - 1][i]) ans = min(ans, i);
    }

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


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

int Euclidean(int A, int B){
	int temp;
	int ma = max(A, B), mb = min(A, B);
	while(mb != 0){
		temp = mb;
		mb = ma % mb;
		ma = temp;
	}
	return ma;
}

int main(){
	int N;
	cin >> N;
	int A[N];
	int D[1000001];
	int IN[1000001];
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	for(int i=0;i<1000001;i++){
		IN[i] = 0;
		D[i] = i;
	}
	for(int i=2;i*i<=1000000;i++){
		for(int j=1;j*i<=1000000;j++){
			D[j*i] = min(D[j*i], i);
		}
	}
	int gcd = A[0];
	for(int i=1;i<N;i++){
		gcd = Euclidean(gcd, A[i]);
	}
	bool pc = true;
	for(int i=0;i<N;i++){
		int tmp = A[i];
		while(tmp > 1){
			if(IN[D[tmp]] > 0){
				pc = false;
				break;
			}
			else{
				IN[D[tmp]]++;
				int div = D[tmp];
				while(tmp % div == 0)tmp /= div;
			}
		}
	}
	// for(int i=0;i<6;i++){
	// 	cout << IN[i] << endl;
	// }
	if(pc) cout << "pairwise coprime" << endl;
	else if(gcd == 1) cout << "setwise coprime" << endl;
	else cout << "not coprime" << endl;
}

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

int main(void){
    int n,l;
    cin >> n >> l;
    string dict[n];
    for (size_t i = 0; i < n; i++)cin >> dict[i];
    sort(dict,dict+n);
    for(auto var:dict)cout << var;
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	int A, B, T;
	cin >> A >> B >> T;
	cout << B * (T / A) << "\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int X,Y;
  cin >> X >> Y;
  
  if(X * 2 <= Y && Y <= X * 4 && Y % 2 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


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

struct edge{
  int from, to, cost;
};

bool operator<(const edge &a, const edge &b){
  return a.cost < b.cost;
}

vector<edge> g;
int par[10000];

int find(int x){
  if(par[x] == x) return x;
  return par[x] = find(par[x]);
}

bool uni(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return false;
  par[x] = y;
  return true;
}

int main(){

  int v, e, s, t, w;
  cin >> v >> e;
  for(int i = 0; i < v; i++) par[i] = i;
  for(int i = 0; i < e; i++){
    cin >> s >> t >> w;
    g.push_back((edge){s, t, w});
  }
  sort(g.begin(), g.end());
  int sum = 0;
  for(int i = 0; i < g.size(); i++){
    edge e = g[i];
    if(uni(e.from, e.to)) sum += e.cost;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4528
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e9
using namespace std;

inline void up(int &x,const int &y){if(x<y)x=y;}
const int maxn = 20;
const int maxm = 81000;

int n,m;
int a[maxn][maxn];
int ct[maxm],f[maxm][maxn];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y,c; scanf("%d%d%d",&x,&y,&c);
		a[x][y]=a[y][x]=c;
	}
	int al=1<<n;
	for(int i=1;i<al;i++)
	{
		int j=1;for(;j<=n;j++) if(i>>j-1&1)break;
		ct[i]=ct[i^1<<j-1];
		for(int k=1;k<=n;k++) if(i>>k-1&1) ct[i]+=a[k][j];
	}
	for(int i=0;i<al;i++) for(int j=1;j<=n;j++) f[i][j]=-inf;
	
	f[1][1]=0; int re=0;
	for(int i=1;i<al;i+=2)
	{
		for(int j=1;j<=n;j++) if((i>>j-1&1)&&f[i][j]>=0)
		{
			if(j==n) up(re,f[i][j]);
			for(int k=1;k<=n;k++) if(!(i>>k-1&1)&&a[j][k])
				up(f[i|1<<k-1][k],f[i][j]+a[j][k]);
			
			int now=al-1-i;
			for(int k=now;k;k=k-1&now)
				up(f[i|k][j],f[i][j]+ct[k^1<<j-1]);
		}
	}
	printf("%d\n",ct[al-1]-re);
	
	return 0;
}


Measured memory_bytes: 4480
N, K = map(int, input().split())
S = input()

l = [0]
curr = '1'
for c in S:
    if c != curr:
        l.append(1)
        curr = c
    else:
        l[-1] += 1
if curr == '0':
    l.append(0)

n_group = len(l) // 2
sum_ = 0
k = min(K, n_group)
sum_ = sum(l[0:2*k+1])
max_ = sum_
for i in range(k, n_group):
    sum_ -= l[2*i-2*K] + l[2*i+1-2*K]
    sum_ += l[2*i+1] + l[2*i+2]
    max_ = max(max_, sum_)
print(max_)

Measured memory_bytes: 4596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		comparison();

	}
	
	public static void comparison() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}
}



Measured memory_bytes: 26164
#!/usr/bin/env python3
from collections import deque

n, q = map(int, input().split())

graph = [deque([]) for _ in range(n + 1)]
for _ in range(n-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

a = [0] * -~n
b = [True] * -~n
for i in range(q):
    p, x = map(int, input().split())
    a[p] += x

d = deque([1])
b[1] = False

while len(d):
    p = d.popleft()
    for i in graph[p]:
        if b[i]:
            a[i] += a[p]
            b[i] = False
            d.append(i)
print(*a[1:])


Measured memory_bytes: 234996
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
ll n, length[107];
 
int main() {
    cin >> n;
    for(ll i = 0; i < n; ++i) cin >> length[i];
 
    sort(length, length + n);
 
    ll ans = 0;
    for(ll i = 0; i < n; ++i) {
        for(ll j = i + 1; j < n; ++j) {
            for(ll k = j + 1; k < n; ++k) {
                if(length[i] < length[j] && length[j] < length[k] && length[i] + length[j] > length[k]) {
                    ans++;
                    //cout << i << ' ' << j << ' ' << k << endl;
                }
            }
        }
    }
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<tuple>
#include<cassert>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
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;}

const int mod = pow(10, 9) + 7;

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n)   cin >> d[i];
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 入力値
		String t = sc.next();
		sc.close();
		// 曜日
		List<String> holiday = new LinkedList<>();
		Collections.addAll(holiday, "SUN","MON","TUE","WED","THU","FRI","SAT");
		int todayIndex = holiday.indexOf(t);
		int sunIndex = holiday.indexOf("SUN");
//		System.out.println(todayIndex+":"+sunIndex);
		// 日曜日が何日後か判定する
		System.out.println(holiday.size()-todayIndex);
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=100005;

struct edge{int to,cost;};

int n,m,s,cnt[maxn];
int d[maxn];
int qh,qt,q[maxn];
bool ok=1,inq[maxn];
vector<edge>G[maxn];

int main() {
	cin>>n>>m>>s;
	for (int i=0;i<m;i++) {
		int u,v,w; cin>>u>>v>>w;
		G[u].pb(edge{v,w});
	}
	memset(d,0x3f,sizeof(d));
	d[s]=0;
	q[qt++]=s; inq[s]=1;
	while (qh!=qt) {
		int u=q[qh++]; if (qh>=maxn) qh=0;
		inq[u]=0;
		for (edge e:G[u]) {
			if (d[e.to]>d[u]+e.cost) {
				d[e.to]=d[u]+e.cost;
				if (!inq[e.to]) {
					q[qt++]=e.to; if (qt>=maxn) qt=0;
					inq[e.to]=1;
					++cnt[e.to];
					if (cnt[u]>m+5) {ok=0;break;}
				}
			}
		}
		if (!ok) break;
	}
	if (!ok) {
		cout<<"NEGATIVE CYCLE"<<'\n';
		return 0;
	}
	else for (int i=0;i<n;i++) 
		if (d[i]==INF) cout<<"INF"<<'\n';
		else cout<<d[i]<<'\n';
}



Measured memory_bytes: 13144
n=int(input())
i=0
pl=list()
while True:
    i=i+1
    if (26*(1-26**(i-1)))/(1-26)+1<=n and n<=(26*(1-26**(i-1)))/(1-26)+26**i:
        break
a=n-(26*(1-26**(i-1)))/(1-26)-1
for l in range (i):
    a,b=divmod(a,26)
    pl.insert(0,(chr(int(b)+97)))
print("".join(pl))

Measured memory_bytes: 9172
import std;
import core.bitop;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "B", long, "W");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    long h, w, k, cnt = 1;
    scan(h, w, k);
    auto cake = new string[](h);
    foreach (ref e; cake)
        e = sread();

    auto blocks = new long[][](h, w);
    blocks.each!((ref e) => e[] = -1);
    auto nostr = new bool[](h);

    foreach (i; iota(h))
    {
        if (cake[i].canFind('#'))
        {
            // 埋める処理
            long prev, next;
            while ((next = cake[i][prev .. $].countUntil('#')) >= 0)
            {
                foreach (j; iota(prev, prev + next + 1))
                    blocks[i][j] = cnt;

                prev += next + 1;
                cnt++;
            }

            foreach (j; iota(prev, w))
                blocks[i][j] = cnt - 1;
        }
        else
        {
            nostr[i] = true;
        }
    }

    foreach (i; iota(h))
    {
        if (nostr[i])
        {
            long nearFind()
            {
                long offset;
                while (1)
                {
                    if (i - offset >= 0 && !nostr[i - offset])
                    {
                        return i - offset;
                    }
                    if (i + offset < h && !nostr[i + offset])
                    {
                        return i + offset;
                    }
                    offset++;
                }
            }

            blocks[nearFind()].aryWrite();
        }
        else
        {
            blocks[i].aryWrite();
        }
    }
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void aryWrite(T = long)(T[] ary)
{
    ary.map!(x => x.text()).join(' ').writeln();
}


Measured memory_bytes: 5912
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K;
    cin >> K;
    if(K % 2 == 0){
        int ans = K*K/4;
        print(ans);
    }else{
        int ans = (K-1) /2;
        ans *= (ans+1);
        print(ans);
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

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



Measured memory_bytes: 3640