akhauriyash/Code-Regression huggingface dataset:
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple

int ans,n,m,lnk[100005],sze[100005],a[100005],b[100005],res[100005];

int fnd(int x){
    while(x!=lnk[x])x = lnk[x];
    return x;
}

bool issame(int x, int y){
    return fnd(x)==fnd(y);
}

void unite(int x, int y){
x = fnd(x);
y = fnd(y);
if(sze[x]<sze[y])swap(x,y);
sze[x]+=sze[y];
lnk[y]=x;
}

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

cin >> n >> m;
for(int i=1;i<=n;i++){
    lnk[i]=i;
    sze[i]=1;
}
for(int i=1;i<=m;i++){
    cin >> a[i] >> b[i];
}
ans = n*(n-1)/(int)2;
for(int i=m;i>=1;i--){
    res[i] = ans;
    if(!issame(a[i],b[i])){
        ans-= sze[fnd(a[i])]*sze[fnd(b[i])];
        unite(a[i],b[i]);
    }
}
for(int i=1;i<=m;i++){
    cout << res[i] << endl;
}

return 0;}
///....


Measured memory_bytes: 5248
n,k = map(int,input().split())
x = list(map(int,input().split()))
kx = x[0:k]
l=kx[0]
r = kx[-1]
lrsmall = min(abs(l),abs(r))
res = r-l+lrsmall
for i in range(1,n-k+1):
    del kx[0]
    kx.append(x[i+k-1])
    l=kx[0]
    r = kx[-1]
    lrsmall = min(abs(l),abs(r))
    res = min(r-l+lrsmall,res)
print(res)

Measured memory_bytes: 14252
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    LL h; cin >> h;

    LL result = 0;
    LL now = 1;
    while(h > 0){
        result += now;
        now *= 2;
        h /= 2;
    }
    
    cout << result << endl;

	return;
}

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

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

int main()
{
	int count[26] = {0},len,i;
	string s;
	while(getline(cin,s))
	{
		len = s.size();
		for(i=0;i<len;i++)
		{
			if(s[i]>=65&&s[i]<=90)
				count[s[i]-65]++;
			else if(s[i]>=97&&s[i]<=122)
				count[s[i]-97]++;
		}
	}	
	for(i=0;i<26;i++)
	{
		cout<<char(i+'a')<<" "<<":"<<" "<<count[i]<<endl;
	}
	return 0;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,ans=0;
    vector<int>b[10];
    char a[30009];
    scanf("%d%s",&n,a);
    for(int i=0; i<n; i++)
        b[a[i]-'0'].push_back(i);
    for(int i=0; i<10; i++)
    {
        int tmp=upper_bound(b[i].begin(),b[i].end(),-1)-b[i].begin();
        if(tmp==b[i].size())
            continue;
        tmp=b[i][tmp];
        for(int j=0; j<10; j++)
        {
            int tmp1=upper_bound(b[j].begin(),b[j].end(),tmp)-b[j].begin();
            if(tmp1==b[j].size())
                continue;
            tmp1=b[j][tmp1];
            for(int k=0; k<10; k++)
            {
                int tmp2=upper_bound(b[k].begin(),b[k].end(),tmp1)-b[k].begin();
                if(tmp2==b[k].size())
                    continue;
                //printf("%d %d %d\n",i,j,k);
                ans++;
            }
        }
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 2147483647
int dp[120][120];
int n,a[120],b[120];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	for(int i=0;i<n;i++){
		dp[i][i]=0;
		for(int j=0;j<n;j++){
			if(i!=j)dp[i][j]=INF;
		}
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				for(int l=j;l<=k-1;l++){
					if(dp[j][l]==INF || dp[l+1][k]==INF)continue;
					int S=dp[j][l]+dp[l+1][k];
					dp[j][k]=min(dp[j][k],S+a[j]*b[l]*a[l+1]*b[k]);
				}
			}
		}
	}
	cout<<dp[0][n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	
	ll n; cin>>n; ll arr[n];
	for(int i = 0; i < n; i++){
		cin>>arr[i];
	}
	ll j = 1;
	for(int i = 0; i < n; i++){
		if(arr[i] == j) j++;
	}
	if(j == 1) {cout<<-1<<"\n"; return 0;}
	cout<<n-(j-1)<<"\n";
}

Measured memory_bytes: 1792
import bisect

def LIS():
    L.append(a[0])
    length[0] = 1
    
    for i in range(n-1):
        if L[-1]<a[i+1]:
            L.append(a[i+1])
            length[i+1] = length[i]+1
        else:
            L[bisect.bisect_left(L,a[i+1])] = a[i+1]
            length[i+1] = length[i]
            
    return length[-1]
    
n = int(input())
a = [int(input()) for _ in range(n)]

L = []
length = [None]*n

print(LIS())


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


int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m, k; cin >> n >> m >> k;
  V<> D(m); for (auto&& e : D) cin >> e, --e;
  sort(begin(D), end(D));
  VV<> to(n, V<>(k)); for (auto&& v : to) for (auto&& e : v) cin >> e, --e;
  V<> d(1 << m, -1);
  queue<int> que;
  d.back() = 0;
  que.push(~(~0 << m));
  while (!que.empty()) {
    int bit = que.front(); que.pop();
    if (!bit) return cout << d[bit] << '\n', 0;
    for (int j = 0; j < k; ++j) {
      int nbit = 0;
      for (int i = 0; i < m; ++i) if (bit >> i & 1) {
        if (!binary_search(begin(D), end(D), to[D[i]][j])) continue;
        nbit |= 1 << lower_bound(begin(D), end(D), to[D[i]][j]) - begin(D);
      }
      if (d[nbit] == -1) {
        d[nbit] = d[bit] + 1;
        que.push(nbit);
      }
    }
  }
}


Measured memory_bytes: 3524
from collections import defaultdict
 
N = int(input())
raw_numbers = list(map(int, input().split()))
Q = int(input())
 
total = sum(raw_numbers)
 
numbers = defaultdict(int)
 
for num in raw_numbers:
    numbers[num] += 1

for _ in range(Q):
    a, b = map(int, input().split())
    taken = numbers[a]
    total -= numbers[a]*a
    numbers[b] += numbers[a]
    total += taken*b
    numbers[a] = 0
    print(total)

Measured memory_bytes: 89712
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int num, day;
    string str;
    char input[256];
    vector<int> mon;
    map<int, int> res;
    while (getline(cin,str)&&str.length()!=0) {
        string nstr="";
        for (int i=0; i<str.length(); i++) {
            if (str[i]==',') break;
            else nstr+=str[i];
        }
        stringstream ss;
        ss<<nstr;
        ss>>num;
        mon.push_back(num);
    }
    while (scanf("%s", input)!=EOF) {
        sscanf(input, "%d%*c%d", &num, &day);
        int cnt = count(mon.begin(), mon.end(), num);
        if (cnt != 0) {
            if (res.find(num) == res.end()) {
                res.insert(make_pair(num, cnt+1));
            } else {
                res[num]++;
            }
        }
    }
    map<int, int>::iterator itr;
    for (itr = res.begin(); itr != res.end(); itr++) {
        printf("%d %d\n", (*itr).first, (*itr).second);
    }
}

Measured memory_bytes: 0
S=input()
flg=0
for i in range(len(S)):
    if i%2==0:
        if S[i]=="L":
            flg=1
            break
    else:
        if S[i]=="R":
            flg=1
            break

if flg==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
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 int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    ll n;
    cin >> n;
    ll s = (n % 2 == 1? n:n + 1);
    queue<pl> ans;
    rep1(i, n)rep1(j, i - 1)if(i + j != s)ans.push(make_pair(i, j));
    pf(ans.size());
    while (!ans.empty()) {
        cout << ans.front().first << " " << ans.front().second << endl;
        ans.pop();
    }
    return 0;
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int,input().split(" ")))

N += 1
A.insert(0,0)

s = [0]*N

for i in range(1,N):
    s[i] = A[i]+s[i-1]

d = {}

for j in s:
    if not(j in d.keys()):
        d[j] = 0
    d[j] = d[j] + 1

s = 0

for k in d.values():
    s += (k-1)*k//2

print(s)

Measured memory_bytes: 41124
s=input()
t=input()
l1=len(s)
l2=len(t)
dp=[[0 for _ in range(l1)] for _ in range(l2)]
flg=False
for i in range(l1):
    if flg or t[0]==s[i]:
        flg=True
        dp[0][i]=1
flg=False
for i in range(l2):
    if flg or s[0]==t[i]:
        flg=True
        dp[i][0]=1
for i in range(1,l2):
    for j in range(1,l1):
        if t[i]==s[j]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
ans=''
i=l2-1
j=l1-1
while i>=0 and j>=0:
    if s[j]==t[i]:
        ans+=s[j]
        i-=1
        j-=1
    else:
        if i==0:
            j-=1
        elif j==0:
            i-=1
        elif dp[i-1][j]>dp[i][j-1]:
            i-=1
        else:
            j-=1
print(ans[::-1])

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

using namespace std;

const int MAXn = 1e5 + 10;

int a[MAXn];

int main(){
	int n, l;
	cin>>n>>l;
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
	}
	int ml = a[1] + a[2], k = 1;
	for(int i = 2; i < n; i++)
		if (a[i] + a[i+1] > ml){
			k = i;
			ml = a[i] + a[i + 1];
		}
	if (ml >= l){
		puts("Possible");
		for(int i = 1; i < k; i++)
			printf("%d\n", i);
		for(int i = n - 1; i > k; i--)
			printf("%d\n", i);
		printf("%d\n", k);
	}
	else{
		puts("Impossible");
	}
	return 0;
}

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

typedef unsigned long long ull;

int compare_ints(const void* a, const void* b)
{
    ull arg1 = *(const int*)a;
    ull arg2 = *(const int*)b;
 
    if (arg1 < arg2) return -1;
    if (arg1 > arg2) return 1;
    return 0;
}

int	main(void)
{
  	ull	n;
  	ull	a[100002];
 	ull	i;
  	ull	m;
  
  	scanf("%llu\n", &n);
  	for(i=0ULL; i<n; i++)
    { 
      	scanf("%llu", &a[i]);
      	if (a[i] == 0ULL)
      	{
      	    printf("0");
      	    return (0);
      	}
    }
    
    qsort(a, n, sizeof(ull), compare_ints);

    m = 1ULL;
    for(i=0ULL; i<n; i++)
    {
        if (a[i] > 1000000000000000000ULL / m)
        {
            printf("-1");
            return (0);
        }
      	m = m * a[i];
      	if (m > 1000000000000000000ULL)
        {
          	printf("-1");
          	return (0);
        }
    }
  	
  	printf("%llu", m);
  	return (0);
}

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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

int main() {
    ll n;cin>>n;
    ll m;cin>>m;
    ll a[m];
    ll dp[n+1];
    for(ll i=0;i<m;i++){
        cin>>a[i];
        dp[a[i]]=-1;
    }
    dp[0]=1;
    ll x;x=1000000007;
    if(a[0]!=1){
        dp[1]=1;
    }
    for(ll i=2;i<=n;i++){
        if(dp[i]!=-1){
            dp[i]=(max(dp[i-1],0)+max(dp[i-2],0))%x;
        }
    }
    cout<<dp[n]<<endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001; // > 10^9
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

string alphabet_up = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lo = "abcdefghijklmnopqrstuvwxyz";
char to_upper(char s){
    char t;
    int count = 0;
    for (char i = 'a'; i <= 'z'; i++) {
        if (s == i) {
            t = alphabet_up[count];
            break;
        } 
        count++;
    }
    return t;
}
char to_lower(char s){
    char t;
    int count = 0;
    for (char i = 'A'; i <= 'Z'; i++) {
        if (s == i) {
            t = alphabet_lo[count];
            break;
        } 
        count++;
    }
    return t;
}

int main () {

    string s,t,v; cin >>s>>t>>v;

    cout << to_upper(s[0]);
    cout << to_upper(t[0]);
    cout << to_upper(v[0]);
    cout << endl;
    
    return 0;
}




Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
dp = [0 for n in range(N)]
dp[1] = abs(H[1] - H[0])
for i in range(2, N):
	dp[i] =  min(dp[i-1] + abs(H[i]-H[i-1]), dp[i-2] + abs(H[i]-H[i-2]))
print(dp[N-1])


Measured memory_bytes: 52720
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

// O(n^3)
// dp[i][j] := [i,j]????????????????????????????°?????????????????????°
// i??????????????????(?????°????????°)??????(p[i - 1], p[i])
int matrixChainMultiplication(int n, int p[105]){
    int dp[105][105] = {{0}};
    range(seg, 2, n + 1){ //?¨????????????????????????°
        range(i, 1, n - seg + 2){
            int j = i + seg - 1;
            dp[i][j] = INT_MAX;
            range(k,i,j){
                int cost = dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j];
                dp[i][j] = min(dp[i][j], cost);
            }
        }
    }
    return dp[1][n];
}

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

    int p[105];
    rep(i,n){
        cin >> p[i] >> p[i + 1];
    }
    cout << matrixChainMultiplication(n, p) << endl;
}

Measured memory_bytes: 3124
def resolve():
    N, M = list(map(int, input().split()))
    interval = []
    l, r = 0, 10**5
    for i in range(M):
        L, R = list(map(int, input().split()))
        l = max(l, L)
        r = min(r, R)

    interval = set(list(range(l, r + 1)))
    interval = interval & set(range(1, N + 1))

    print(len(interval))

    return


resolve()

Measured memory_bytes: 64340
//SugarWater.cpp (C)
#include <iostream>
using namespace std;

int main(){
  int A,B,C,D,E,F;
  int W,x;
  int ans[2];
  ans[0] = 0;
  ans[1] = -1;
  double d;
  double dMax = 0;
  cin >> A >> B >> C >> D  >> E >> F;
  for(int i = 0; i <= F/(100*A); i++){
    for(int j = 0; j <= (F-100*A*i)/(100*B); j++){
      W = 100*(A*i + B*j);
      for(int k = 0; (C*k <= F-W)&&(C*k <= E*W/100); k++){
        for(int l = 0; (D*l <= F-W-C*k)&&(C*k + D*l <= E*W/100); l++){
          x = C*k + D*l;
          // if(k+l != 0) d = 100.0*x/(W + x);
          // else d = 0;
          // if(d > dMax) dMax = d, ans[0] = W + x, ans[1] = x;
          if(x*ans[0] > ans[1]*(W+x)) ans[0] = W + x, ans[1] = x;
        }
      }
    }
  }
  printf("%d %d\n",ans[0],ans[1]);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
int n,a[300005];ll Ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=3*n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n*3+1);
	for (int i=n+1;i<=n*3;i+=2)
		Ans+=a[i];
	printf("%lld",Ans);
}

Measured memory_bytes: 1408
n = int(input())
s = [n for n in range(1, 14)]
h = [n for n in range(1, 14)]
c = [n for n in range(1, 14)]
d = [n for n in range(1, 14)]
suits = ['S', 'H', 'C', 'D']
for i in range(n):
    x, y = [z for z in input().split()]
    y = int(y)
    if x == 'S':
        s[y - 1] = 0
    elif x == 'H':
        h[y - 1] = 0
    elif x == 'C':
        c[y - 1] = 0
    else:
        d[y - 1] = 0

data = [s, h, c, d]
for i in range(4):
    for x in data[i]:
        if x != 0:
            print(suits[i], str(x))

Measured memory_bytes: 7784
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	s := IOInitialize()
	S := String(s)
	strs := strings.Split(S, "")
	m := map[string]int{}
	for _, str := range strs {
		m[str] = 1
	}
	if len(m) == 3 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func IOInitialize() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func String(s *bufio.Scanner) string {
	if !s.Scan() {
		panic("scan error")
	}

	return s.Text()
}

Measured memory_bytes: 640
// 3_abc127_c
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int mi = 1;
    int ma = n;

    rep(i, m){
        int l, r;
        cin >> l >> r;
        mi = max(mi, l);
        ma = min(ma, r);
    }

    if(mi > ma) cout << 0 << endl;
    else{
        cout << ma - mi + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
S = gets.chomp.chars

count_list = Array.new(N + 1)
count_list[0] = { left: 0, right: 0 }
S.each.with_index do |ch, i|
  prev = count_list[i]
  if ch == 'E'
    count_list[i + 1] = { left: prev[:left], right: prev[:right] + 1 }
  else
    count_list[i + 1] = { left: prev[:left] + 1, right: prev[:right] }
  end
end
ans = 10 << 60
N.times do |i|
  first = count_list[1]
  last = count_list[-1]
  current = count_list[i + 1]
  cost = if S[i] == 'E' # ->
    current[:left] + (last[:right] - current[:right])
  else # <-
    (current[:left] - 1) + (last[:right] - current[:right])
  end
  ans = cost if cost < ans
end
puts ans


Measured memory_bytes: 107240
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

int fv[31];
int main(){
    int n,m;
    cin >> n >> m;
    rep(i, n){
       int k, a;
       cin >> k;

       rep(j,k){
           cin >> a;
           fv[a]++;
       }
    }
    int ans = 0;
    reps(i, m){
        if(fv[i]==n)ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 384
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

n = I()
a = Intl()
s = 1
a.sort()
for i in range(n):
    s *= a[i]
    if s > 10**18:
        print(-1)
        exit()
print(s)

Measured memory_bytes: 22732
#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;
typedef pair<int, int> P;


int main(){
  int N;
  while(cin>>N && N){
    char s[100000];
    char t[100000];
    vector<P> edge[200];
    map<string, int> id;
    REP(i, N){
      int n, v1, v2;
      scanf(" 1 %s = 10^%d %s ", s, &n, t);
      string u1(s);
      string u2(t);
      if(!id.count(u1)){
        int tmp = id.size();
        id[u1] = tmp;
      }
      if(!id.count(u2)){
        int tmp = id.size();
        id[u2] = tmp;
      }
      v1 = id[u1], v2 = id[u2];
      edge[v1].push_back(P(v2, n));
      edge[v2].push_back(P(v1, -n));
    }
    int M = id.size();
    vector<int> value(M);
    fill(value.begin(), value.end(), INF);
    bool ans = true;
    REP(i, M)if(value[i] == INF){
      queue<P> que;
      que.push(P(i, 0));
      while(!que.empty()){
        P p = que.front(); que.pop();
        int idx = p.first, t = p.second;
        if(value[idx] != INF){
          if(value[idx] != t) ans = false;
          continue;
        }
        value[idx] = t;
        REP(j, edge[idx].size()){
          P e = edge[idx][j];
          que.push(P(e.first, t + e.second));
        }
      }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <cmath>
#include <functional>
using namespace std;

#define INF (int)1e7
int N, M, K;
vector<vector<int>>Room;
int status[800][800];
int cost[800][800];
int v[] = { -1, 0, 1, 0 };
int h[] = { 0, 1, 0, -1 };

vector<pair<int,int>> dijkstra(pair<int,int>s) {
	vector<pair<int, int>>pos;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			status[i][j] = 0;
			cost[i][j] = INF;
		}
	}
	cost[s.first][s.second] = 0;
	status[s.first][s.second] = 1;

	priority_queue<pair<int, pair<int,int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>>U;
	U.push(make_pair(cost[s.first][s.second], s));
	while (!U.empty()) {
		//探索が終わってない中でコスト最小の点
		pair<int,int>u = U.top().second; U.pop();

		if (status[u.first][u.second] == -1) continue;
		if(cost[u.first][u.second] <= K)pos.push_back(u);
		status[u.first][u.second] = -1;

		//コスト最少の点を探る
		for (int i = 0; i < 4; i++) {
			if (status[u.first + v[i]][u.second + h[i]] != -1 && u.first + v[i]>= 0 && u.second + h[i]>= 0 && u.first + v[i] < N && u.second + h[i] < M) {
				if (Room[u.first + v[i]][u.second + h[i]])continue;
				if (cost[u.first + v[i]][u.second + h[i]] > cost[u.first][u.second] + 1) {
					cost[u.first + v[i]][u.second + h[i]] = cost[u.first][u.second] + 1;
					status[u.first + v[i]][u.second + h[i]] = 1;
					U.push(make_pair(cost[u.first + v[i]][u.second + h[i]], make_pair(u.first + v[i], u.second + h[i])));
				}
			}
		}
	}

	return pos;
}

int main()
{
	cin >> N >> M >> K;
	Room.resize(N);
	pair<int, int>pos;
	for (int i = 0; i < N; i++) {
		Room[i].resize(M);
		for (int j = 0; j < M; j++) {
			char c; cin >> c;
			if (c == '#')Room[i][j] = 1;
			else if (c == 'S')pos = make_pair(i, j);
		}
	}

	vector<pair<int,int>>nextpos = dijkstra(pos);
	vector<int>ans;
	for (int k = 0; k < nextpos.size(); k++) {
		int dist = min(min(nextpos[k].first,N - 1 - nextpos[k].first), min(nextpos[k].second, M - 1 - nextpos[k].second));
		ans.push_back(dist);
	}
	sort(ans.begin(), ans.end());

	cout << int(ceil((double)ans[0] / K)) + 1 << endl;

    return 0;
}

Measured memory_bytes: 22136
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int n, a;
    int b[200009]={};
    
    cin >> n;
    
    for(int i=1; i<=n; i++){
        
        cin >> a;
        
        if(n%2==0){
            
            if(i%2==1){
                
                b[n/2+(i+1)/2] = a;
                
            } else {
                
                b[n/2-i/2+1] = a;
                
            }
            
        } else {
            
            if(i%2==0){
                
                b[n/2+1+i/2] = a;
                
            } else {
                
                b[n/2-(i+1)/2+2] = a;
                
            }
            
        }
        
    }
    
    for(int i=1; i<=n; i++){
        
        cout << b[i];
        
        if(i<=n-1){
            
            cout << " ";
            
        }
        
    }
    
    return 0;
    
}

Measured memory_bytes: 2944
a,b,c,d=input()
ym,my=int(a+b),int(c+d)
if 0<ym<13 and 0<my<13:
    print('AMBIGUOUS')
elif 0<ym<13:
    print('MMYY')
elif 0<my<13:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
#define P pair<int,int>
const int N=2010;
int n;
int a[N];
bool cmp(int i,int j){
    return i>j;
}
int find(int *q,int l,int r,int val){
    if(l>=r) return l;
    if(q[l]<val) return l;
    int i=l,j=r;
    int mid=(i+j)>>1;
    while(i<j){
        if(j-i==1){
            if(q[j]>val) return j;
            else return i;
        }
        mid=(i+j)>>1;
        if(q[mid]<=val) j=mid-1;
        else i=mid;
    }
    return i;
}
map<int,int> s;
int main(){
    cin>>n;
    for(int i=0;i<n;++i) cin>>a[i];
    sort(a,a+n,cmp);
    int ans=0;
    for(int i=0;i<n-1;++i){
        for(int j=i+1;j<n;++j){
            int k=a[i]-a[j];
            int t=find(a,j+1,n-1,k);
            if(a[t]>k) ans+=(t-j);
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		String a = sc.nextLine();
		int count = 0;
		for(int i = 0;i<a.length(); i++) {
			if(a.charAt(i) == 'o') count++;
		}
		System.out.println(700 + (100*count)); 
	}
}

Measured memory_bytes: 22612
/* 

	 - If you fail to prepare, you are prepared to fail.	

	(C) Mark Spitz

*/

#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;

const bool dbg_flg = 1;
#define NAME(x) #x
#define debug if (dbg_flg) cerr

const int inf = 1e9 + 7;
const int MAXN = 1e5 + 5;

void solve() {
	string s;


	cin >> s;

	if (s == "ABC") cout << "ARC";
	else cout << "ABC";
	
}

int main() {
	
	//~ freopen(".in", "r", stdin);
	//~ freopen(".out", "w", stdout);
	
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
	}

	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> hw(h, vector<char>(w));
    rep(i, h) rep(j, w) cin >> hw[i][j];
    vector<vector<int>> ans(h, vector<int>(w, 0));
    int cnt = 0;
    rep(i, h) {
        bool flg = false;
        rep(j, w) {
            if (hw[i][j] == '#') {
                ++cnt;
                if (!flg) {
                    for (int k = j; k >= 0; --k) {
                        ans[i][k] = cnt;
                    }
                    flg = true;
                }
            }
            ans[i][j] = cnt;
        }
        if (!flg) {
            rep(j, w) {
                if (i != 0) {
                    ans[i][j] = ans[i-1][j];
                }
            }
        }
    }
    for (int i = h - 1; i >= 0; --i) {
        bool flg = false;
        rep(j, w) {
            if (hw[i][j] == '#') flg = true;
        }
        if (!flg && i < h - 1) {
            rep(j, w) {
                ans[i][j] = ans[i+1][j];
            }
        }
    }
    rep(i, h) {
        rep(j, w) {
            if (j != 0) cout << " ";
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 4080
#include <stdio.h>
 
using namespace std;
 
 
int main(){
    int n,a,b,c,A,B,C;
    scanf("%d",&n);
 
    for(int i=0;i<n;i++){
        scanf("%d %d %d",&a,&b,&c);
        A = a*a;
        B = b*b;
        C = c*c;
        if(A+B==C||B+C==A||C+A==B){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
 
    return 0;
}


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

int main() {

    int A, B;

    cin >> A >> B;

    int sum, sub, mult;

    sum = A + B;

    sub = A - B;

    mult = A * B;

    if (sum >= sub && sum >= mult) {
        cout << sum << endl;
    }
    else if (sub >= sum && sub >= mult) {
        cout << sub << endl;
    }
    else {
        cout << mult << endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define rep(i,f,t) for(int i=f;i<t;i++)
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define ll long long
    #define mkp make_pair
    using namespace std;
    int main(){
      	ios::sync_with_stdio(0);
	cin.tie(0);
    	ll n,d,a;
        cin>>n>>d>>a;
        vector<pair<ll,ll> > arr;
        ll c[n];
        rep(i,0,n){
        	c[i]=0;
            int x,y;
            cin>>x>>y;
            arr.push_back(mkp(x,y));
         }
         ll ans=0;
         sort(arr.begin(),arr.end());
      int j=0;   
      rep(i,0,n){
            while(j<n&&arr[j].fi<=arr[i].fi+2*d)j++;
            ll need=max((arr[i].se-c[i]*a+a-1)/a,0ll);
            ans+=need;
            c[i]+=need;
            c[j]-=need;
            c[i+1]+=c[i];
         }
         cout<<ans<<endl;
    }

Measured memory_bytes: 6896
#include <iostream>
#include<string>
using namespace std;
int n, v[3], m, op[100000];
char ans[100000] = {};
void g(int x, int y) {
        v[x]++;
        v[y]--;
}
int mov(int i) {
    int x, y;
    if (op[i] == 0) {
        x = 0;
        y = 1;
    }
    else if (op[i] == 1) {
        x = 1;
        y = 2;
    }
    else {
        x = 0;
        y = 2;
    }
    if (v[x] == 0 && v[y] == 0)return -1;
    if (v[x] == 1 && v[y] == 1) {
        if (i + 1 < n)
            if(op[i+1]!=op[i]) {
            int k = op[i + 1] ^ op[i];
            k = (k == 2 ? 0 : (k == 3 ? 2 : 1));
            g(k, x ^ y ^ k);
            return k;
        }
    }
    if (v[x] > v[y]) {
        g(y, x);
        return y;
    }
    else {
        g(x, y);
        return x;
    }
}
int main()
{
    cin >> n >> v[0] >> v[1] >> v[2];
    string s;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s == "AB") {
            op[i] = 0;
        }
        else if (s == "BC") {
            op[i] = 1;
        }
        else {
            op[i] = 2;
        }
    }
    for (int i = 0; i < n; i++) {
        int t = mov(i);
        if (t < 0) {
            cout << "No\n";
            return 0;
        }
        else ans[i] = (t == 0 ? 'A' : (t == 1 ? 'B' : 'C'));
    }
    cout << "Yes\n";
    for (int i = 0; i < n; i++) {
        cout << ans[i] << "\n";
    }
}

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

int main()
{
	int N, M, P;
	scanf("%d%d%d", &N, &M, &P);
	using vpi = std::vector<std::pair<int, int>>;
	using vvpi = std::vector<vpi>;

	vvpi edges(N);
	for (int i{}; i < M; i++)
	{
		int A, B, C;
		scanf("%d%d%d", &A, &B, &C);
		A--; B--;
		edges[A].push_back({B, C - P});
	}
	std::vector<int64_t> distance(N, -(1ll << 60));
	distance[0] = 0;
	for (int loop{}; loop < N; loop++)
		for (int from{}; from < N; from++)
			for (auto& e: edges[from])
				distance[e.first] = std::max(distance[e.first], distance[from] + e.second);
	
	int64_t ans{distance.back()};
	for (int loop{}; loop < N; loop++)
		for (int from{}; from < N; from++)
			for (auto& e: edges[from])
				distance[e.first] = std::max(distance[e.first], distance[from] + e.second);
	
	if (ans != distance.back()) puts("-1");
	else printf("%lld\n", std::max(0l, ans));

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long N,M;
  cin >> N >> M;
  vector<long long> A(100009),B(100009);
  for(int i=0;i<N;i++)cin >> A[i] >> B[i];
  vector<pair<long long,long long>> p(N);
  for(int i=0;i<N;i++)p[i]=make_pair(A[i],B[i]);
  sort(p.begin(),p.end());
  long long ans=0;
  for(int i=0;i<N;i++){
    if(M>=p[i].second){M-=p[i].second; ans+=p[i].first*p[i].second;}
    else{ans+=p[i].first*M; break;}
  }
  cout << ans << endl;
}

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

int main () {
	string s;
	cin >> s;
	int a = 0, z = 0; 

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A') {
			a = i;
			break;
		}
	}

	for (int i = s.size() - 1; i >= 0; i--) {
		if (s[i] == 'Z') {
			z = i;
			break;
		}
	}

	cout << z - a + 1 << endl;
	
	return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int64_t i = 0; i < (int64_t) (n); ++i)
#define endl '\n'

template<typename T> void _dbg(const char*_s,T _h) { cerr<<_s<<" = "<<_h<<"\n"; }

template<typename T, typename... Ts> void _dbg(const char*_s,T _h,Ts... _t) {
    for(int _b=0;((_b+=*_s=='(')-=*_s==')')!=0||*_s!=',';)cerr<<*_s++;
    cerr<<" = "<<_h<<",";_dbg(_s+1,_t...);
}

#define int long long

#ifdef LOCAL
    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
    #define dbg(...)
#endif

const int N = 5 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, k;
int h[N];
int dp[N][N];

bool read() {
    if (!(cin >> n >> k))
        return false;

    forn (i, n)
        cin >> h[i + 1];

    return true;
}

void solve() {
    int ans = MOD * MOD;

    if (n == k)
        ans = 0;

    for (int i = 1; i <= n; ++i)
        for (int t = 0; t <= k; ++t) {
            dp[i][t] = MOD * MOD;

            for (int j = 0; j < i; ++j)
                if (t - i + j + 1 >= 0)
                    dp[i][t] = min(dp[i][t], dp[j][t - i + j + 1] + max(0ll, h[j] - h[i]));

            if (n - i + t <= k)
                ans = min(ans, dp[i][t] + h[i]);
        }

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



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

#define N_MAX 100002

using namespace std;

int n;

int h[N_MAX];

int dp[N_MAX];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> h[i];
    dp[1] = 0;
    dp[2] = abs(h[1] - h[2]);
    for(int i = 3; i <= n; i++)
        dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
    cout << dp[n] << "\n";
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int count = 0;
    int n = sc.nextInt();
    int h[] = new int[n];
    int max = 1;
    for (int i = 0; i < n; i++){
      h[i] = sc.nextInt();
      if (h[i] >= max) {
        count++;
        max = h[i];
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21204
#include <iostream>
#include <iterator>
#include <map>

long long factorial(long long a){
    long long write = 1;
    for(long long i = 1; i <= a; ++i){
        write *= i;
    }
    return write;
}

long long choose(long long n, long long r){
    long long write = 1;
    if(n < r){
        write = 0;
    }else{
        for(long long i = 0; i < r; ++i){
            write *= n - i;
        }
    }
    write /= factorial(r);
    return write;
}

int main(){
    long long n;
    std::cin >> n;
    
    std::multimap<long long, long long> sticks;
    for(long long i = 0; i < n; ++i){
        long long val;
        std::cin >> val;
        auto itr = sticks.find(val);
        if(sticks.end() != itr){
            ++itr->second;
        }else{
            sticks.insert(std::make_pair(val, 1));
        }
    }

    long long count = 0;
    for(auto itrA = sticks.begin(); sticks.end() != itrA; ++itrA){
        long long a = itrA->first, aNum = itrA->second;

        for(auto itrB = itrA; sticks.end() != itrB; ++itrB){
            long long b = itrB->first, bNum = itrB->second;

            for(auto itrC = itrB; sticks.end() != itrC; ++itrC){
                long long c = itrC->first, cNum = itrC->second;

                if(a < b + c && b < c + a && c < a + b){
                    if(3 <= aNum && a == b && b == c && c == a){
                        count += choose(aNum, 3);
                    }else if(2 <= aNum && a == b && c != a){
                        count += choose(aNum, 2) * cNum;
                    }else if(2 <= bNum && b == c && a != b){
                        count += choose(bNum, 2) * aNum;
                    }else if(2 <= cNum && c == a && b != c){
                        count += choose(cNum, 2) * bNum;
                    }else if(a != b && b != c && c != a){
                        count += aNum * bNum * cNum;
                    }
                }
            }
        }
    }

    std::cout << count << std::endl;

    return 0;
}


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

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
    #include "lib/dump.hpp"
#else
    #define dump(...) 42
    #define dump_1d(...) 42
    #define dump_2d(...) 42
    #define cerrendl 42
#endif
//}}}

signed main() {
    int n;cin>>n;
    vector<int> a(n);
    rep(i, n) {
        cin>>a[i];
    }
    sort(all(a));
    dump(a);

    int ans = n*(n-1)*(n-2)/3/2;
    dump(ans);

    rep(Mi, 2, n){
        rep(mi, 0, Mi-1){
            int u = a[Mi] - a[mi];
            int j = ub(a.begin()+mi+1, a.begin()+Mi, u) - a.begin();
            ans -= j-1-mi;
            dump(Mi, mi, j-1-mi);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  int R;
  cin >> R;

  if(R < 1200)
    cout << "ABC" << endl;
  else if(R < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;

  return 0;
}


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

using ull = unsigned long long;
using ll = long long;

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

    vector<string> S(n);

    for(auto&& x : S)
    {
        cin >>x;
    }

    sort(S.begin(),S.end());

    string result = "";

    for(auto&& x : S)
    {
        result += x;
    }

    cout << result << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(void){
    double a,x;
    while(cin>>a,a!=-1){
        x=a*0.5;
        while(fabs(x*x*x-a)>=0.00001*a)x=x-(x*x*x-a)/(3*x*x);
        printf("%.6lf\n",x);
    }
    return 0;
}

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


int main() {
  int N,K;
  cin>>N>>K;
  vector<int>l(N);
  rep(i,N){
      cin>>l[i];
  }
  int ans=0;
  sort(l.rbegin(),l.rend());
  rep(i,K){
      ans+=l[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String strIn = scan.nextLine();
		String strAns = "";
		char charTemp;
		for(int i = 0; i < strIn.length(); i++){
			charTemp = strIn.charAt(i);
			if(Character.isLowerCase(charTemp)){
				charTemp = Character.toUpperCase(charTemp);
			}else if(Character.isUpperCase(charTemp)){
				charTemp = Character.toLowerCase(charTemp);
			}
			strAns += charTemp;
		}
		System.out.println(strAns);
		scan.close();
	}
}

Measured memory_bytes: 24220
n, k = map(int, input().split())
s = list(input())
if s.count("L") == 0 or s.count("R") == 0:
    print(n-1)
else:
    if s[0] == "L":
        target = "R"
        fir = "L"
    if s[0] == "R":
        target = "L"
        fir = "R"
    cnt = 0
    mode = False
    for i in range(n):
        if s[i] != target:
            if mode:
                cnt += 1
                mode = False
                if cnt == k:
                    break
        else: # TARGET
            mode = True
            s[i] = fir
    #print(s)
    import itertools
    res = itertools.groupby(s)
    final = 0
    #print(res)
    for a,b in res:
        final += len(list(b)) -1
    print(final)



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

public class Main {

	static int[][] s = new int[100][1000]; // point[演技][それぞれの審査員の点]
	static int[] n = new int[100]; // 演技ごとの審査員の人数
	static int[] ave = new int[100];
	static int section = 0;
	static int[] max = new int[100];
	static int[] min = new int[100];
	static int i = 0, j = 0;


	/**
	 * 入力をn,sのそれぞれの配列に格納するメソッド
	 */
	public static void inPoint() throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (j < 1000) {
			j = 0;
			String str = br.readLine();
			n[i] = Integer.parseInt(str);

			if (n[i] == 0) {
				section = i;
				break;
			}

			while (j < n[i]) { // すべての審査員の点を配列に格納
				str = br.readLine();
				s[i][j] = Integer.parseInt(str);
				j++; // 次の審査員
			}

			i++; // 次の演技
		}

	}

	/**
	 * 最大値および最小値を探すメソッド
	 */
	public static void findMaxMin(int s[][]) {

		for(i = 0; i < 100; i++){
			max[i] = 0;
			min[i] = 1000;
		}

		for (i = 0; i < section; i++) { // i（演技）が0から末尾まで繰り返す
			for (j = 0; j < n[i]; j++) { // j（審査員）が1から末尾のひとつ手前まで繰り返す

				if (s[i][j] < min[i]){
					min[i] = s[i][j];
				}
				if(s[i][j] > max[i]){
					max[i] = s[i][j];
				}
			} // jについてのループ

		}
	}

	/**
	 * 演技のそれぞれの平均を求めるメソッド
	 */
	public static void average(int s[][]) {

		for (i = 0; i < section; i++) {
			for (j = 0; j < n[i]; j++) { // 1番目から末尾の1つ前まで
				ave[i] += s[i][j]; // 合計を求める
			}
			ave[i] = (ave[i] - max[i] - min[i]) / (n[i] - 2); // 審査員の数-2で割る
		}

	}

	public static void main(String[] args) throws IOException {

		inPoint();
		findMaxMin(s);
		average(s);

		for (i = 0; i < section; i++) {
			System.out.println(ave[i]);
		}

	}

}



Measured memory_bytes: 24576