akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

int N,now,ans,len,l;

int main(){
    cin>>N;
    vector<int> v;
    rep(i,N){
        cin>>l;
        v.push_back(l);
    }
    sort(ALL(v));
    repi(i,1,N)repi(j,i+1,N){
        len=v[j]-v[i] + 1;
        int index = lower_bound(ALL(v),len) - v.begin();
        // cout<<index<<" : "<<i<<" : "<<j<<endl;
        ans+=max(i-index,0);
    }
    out(ans);

}


Measured memory_bytes: 384
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string str;cin>>str;
	int D,i,j,k,wa=0;cin>>D;
	vector<llint>dp(D);
	for(auto it:str){
		int c=it-'0';
		vector<llint>ep(D);
		for(i=0;i<c;i++){ep[(i+wa)%D]++;}
		wa+=c;
		for(i=0;i<D;i++){
			for(j=0;j<10;j++){
				ep[(i+j)%D]+=dp[i];
			}
		}
		for(i=0;i<D;i++){dp[i]=ep[i]%mod;}
	}
	if(wa%D!=0){dp[0]--;dp[0]+=mod;dp[0]%=mod;}
	cout<<dp[0]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int a[100], f[100010];
int n, k;

int dfs(int x) {
    if (f[x] != -1) {
        return f[x];
    }
    f[x] = 1;
    for (int i = 0; i < n; ++i) {
        if (x >= a[i]) {
            f[x] &= dfs(x - a[i]);
        }
    }
    return f[x] = 1 - f[x];
}

inline void work() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int bottom = *min_element(a, a + n);
    memset(f, -1, sizeof(f));
    // 0-lose 1-win
    for (int i = 0; i < bottom; ++i) {
        f[i] = 0;
    }
    cout << (dfs(k) ? "First" : "Second") << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

bool solve()
{
  int n, x;
  cin >> n >> x;
  if (n == 0 and x == 0)
    return false;
  else
  {
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
      for (int j = 1; j < i; j++)
      {
        for (int k = 1; k < j; k++)
        {
          if (i + j + k == x)
            ans++;
        }
      }
    }
    cout << ans << endl;
    return true;
  }
}

int main()
{
  while (solve())
  {
  }
  return 0;
}



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

int main() {
  string S, T;
  cin >> S >> T;

  int maxMatch = 0;
  for (int i = 0; i < (int)T.size(); i++) {
    for (int j = i; j < (int)S.size()-(T.size()-i)+1; j++) {
      if (T[i]==S[j]) {
        int match = 1;
        for (int k = 1; k < (int)T.size()-i; k++) {
          if(j+k>=(int)S.size()) break;
          if(T[i+k]==S[j+k]){
            match++;
          }
        }
        maxMatch = max(maxMatch, match);
      }
    }
  }
  cout << T.size()-maxMatch << endl;

  return 0;
}

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define ALL(v) begin(v), end(v)

/* REPmacro */
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (s); i >= (n); i--)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define rrep(i, n) RFOR(i, n - 1, 0)
#define rrepi(i, n) RFOR(i, n, 1)

/* debug */
#define pp(v) cerr << #v "=" << (v) << endl;

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using vs = vector<string>;
using Graph = vvi;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* iostream */
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define TIME system("date +%M:%S.%N")
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }
template<class T> T div_ceil(const T &a, const T &b) { return (a + b - 1) / b; }

int main() {
  int n;cin>>n;
  vi h(n);cin>>h;
  vi dp(n+1,INF);dp[0]=0;
  rep(i,n-1) {
    chmin(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
    chmin(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
  }
  int ans = dp[n-1];
  cout << ans << endl;
}


Measured memory_bytes: 1024
n,d=map(int,input().split())
hoge=[]
for i in range(n):
  huga=list(map(int,input().split()))
  hoge.append(huga)

ans=0
for i in range(n):
  for j in range(n):
    x=0
    for k in range(d):
      x+=(hoge[i][k]-hoge[j][k])**2
    if(x!=0 and x**0.5%1==0):
      ans+=1
      
print(ans//2)

Measured memory_bytes: 3064
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n;
int a[100010],ret;

signed main(){
    I(n);
    REPS(i,n){
        I(a[i]); ret+= abs( a[i-1] - a[i]);
    }
    ret += abs(a[n]);
    REPS(i,n){
        int ri = ret + abs( a[i-1] - a[i+1]) - abs( a[i-1] - a[i]) - abs( a[i] - a[i+1]);
        printf("%lld\n",ri);
    }
}

Measured memory_bytes: 2048
#include<iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int c[n], s[n], f[n];
    for (int i = 0; i < n - 1; ++i) {
        cin >> c[i] >> s[i] >> f[i];
    }
    for (int i = 0; i < n - 1; ++i) { //output
        int time = 0;
        time += s[i] + c[i];
        for (int j = i + 1; j < n - 1; ++j) { //pass
            int cnt = 0;
            while (time > s[j] + cnt * f[j]) {
                cnt++;
            }
            time = s[j] + cnt * f[j] + c[j];
        }
        cout << time << endl;
    }
    cout << 0 << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

ll N, X, D;

ll solve() {
    if (D == 0){
        if (X == 0) return 1;
        else return N+1;
    }
    if (D < 0) {
        D = -D;
        X = -X;
    }

    map<int, vii> modD;
    ll mn = 0, mx = 0;
    modD[0].push_back(make_pair(0, 0));
    FOR (i, 1, N+1) {
        int k = (i * X % D + D) % D;
        mn += X + ((i-1) * D);
        mx += X + (N - i) * D;
        modD[k].push_back(make_pair(mn, mx));
    }

    ll ans = 0;
    for (auto iter = modD.begin(); iter != modD.end(); iter++) {
        vii ranges = iter->second;
        sort(ALL(ranges));
        int idx = 0;
        while (idx < ranges.size()) {
            mn = ranges[idx].first, mx = ranges[idx].second;
            idx++;
            while (idx < ranges.size() && ranges[idx].first <= mx) {
                mx = max(mx, ranges[idx].second);
                idx++;
            }
            ans += (mx - mn) / D + 1;
        }
    }

    return ans;
}

int main() {
    cin >> N >> X >> D;
    cout << solve() << endl;
}

Measured memory_bytes: 22144
#include <stdio.h>

int main(void)
{
	int a;
	int b;

	scanf("%d", &a);
	scanf("%d", &b);

	if (a > b)
		printf("a > b\n");
	if (a == b)
		printf("a == b\n");
	if (a < b)
		printf("a < b\n");
	return 0;
}


Measured memory_bytes: 2120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> G[m+1];
    int p[m+1];
    int k, s;
    for(int i = 1; i <= m; i++){
        cin >> k;
        for(int j = 0; j < k; j++){
            cin >> s;
            G[i].push_back(s);
        }
    }
    for(int i = 1; i <= m; i++){
        cin >> p[i];
    }
 
    int ans = 0;
    for(int bit = 0; bit < (1<<n); bit++){
        vector<int> a;
        for (int i = 0; i < n; i++) {
            if (bit & (1<<i)) {
                a.push_back(i+1);
            }
        }
        int isOn = 0;
        for(int i = 1; i <= m; i++){
            int b = 0;
            for(int j = 0; j < a.size(); j++){
                vector<int>::iterator vIter = find(G[i].begin(), G[i].end(), a.at(j));
                if(vIter != G[i].end()){
                    b++;
                }
            }
            if(b % 2 == p[i]){
                isOn++;
            }
        }
        if(isOn == m){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind uf(N);
    vector<set<int>> ng(N);
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;a--,b--;
        ng[a].insert(b);
        ng[b].insert(a);
        uf.unite(a, b);
    }
    for (int i = 0; i < K; i++)
    {
        int c, d;
        cin >> c >> d;c--, d--;
        if(uf.issame(c, d)){
            ng[c].insert(d);
            ng[d].insert(c);
        }
    }
    
    for (int i = 0; i < N; i++)
    {
        int ans = uf.size(i)-1;
        ans-=ng[i].size();
        cout << ans ;
      if(i==N-1)cout << "\n";else cout << ' ';
    }
}

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

int main()
{
	int k, x;
	int w1, w2;

	cin >> k >> x;

	if (x + k - 1 <= 1000000) {
		w1 = x + k - 1;
	}

	w2 = x - k + 1;

	for (int i = w2; w2 <= w1; w2++) {
		cout << w2 << " ";
	}

	cout << endl;

	return 0;
}

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

const int maxn = 1e5+7;
int fa[maxn];
int ans[maxn];
int cnt[maxn];
int f(int x)
{
    if(fa[x]==x)return x;
    return fa[x]=f(fa[x]);
}
void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C, std::vector<long long> D){
    for(int i=1;i<=N;++i)fa[i]=i;
    for(int i=0;i<M;++i)
    {
        fa[f(A[i])]=f(B[i]);
    }
    for(int i=1;i<=N;++i)
    {
        cnt[f(i)]++;
    }
    for(int i=1;i<=N;++i)
    {
        ans[i] = cnt[f(i)]-1;
    }
    for(int i=0;i<M;++i)
    {
        ans[A[i]]--;
        ans[B[i]]--;
    }
    for(int i=0;i<K;++i)
    {
        if(f(C[i])==f(D[i]))
        {
            ans[C[i]]--;
            ans[D[i]]--;
        }
    }
    for(int i=1;i<=N;++i)
    {
        cout<<ans[i]<<(i==N?'\n':' ');
    }
}

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


Measured memory_bytes: 5376
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#define N 100005
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;
int n, m;
ll t;
int main() {
	cin>>n>>t;
	ll b = 0, e = 0;
	ll tot=0;
	for (int i = 0; i < n; ++i) {
		ll tt;
		cin>>tt;
		if (i == 0) {
			b = tt;
			e = tt+t;
		} else {
			if (tt > e) {
				tot += e-b;
				b = tt;
				e = tt+t;
			} else {
				e = max(e, tt+t);
			}
		}
	}
	tot += e-b;
	cout<<tot<<endl;
	return 0;
}

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

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

  for (int b = 0; b <= n; b++) {
    for (int c = 0; c <= n-b; c++) {
      int a = n - b - c;
      if(10000*a+5000*b+1000*c==y){
	printf("%d %d %d\n", a, b, c);
	return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}


int main() {

    int N = in(); int Y = in();
    
    for (auto a = 0; a <= N;a++){
        for (auto b = 0; b <= N-a; b++){
                if (Y == 10000*a + 5000*b + 1000*(N - a - b)){
                    cout << a << " " << b << " " << N - a - b << endl;
                    return 0;
                }

        }
    }
    
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef pair <int, int> cn;
const int N = 1e5 + 100;

int main() {
	long long sum = 0;
	int n, m, a[N];
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) {
		scanf("%d", a + i);
	}
	sort(a, a + n);
	cn z[m];
	for (int i = 0; i < m; ++i) {
		scanf("%d%d", &z[i].first, &z[i].second);
	}
	sort(z, z + m, [](const cn &p1, const cn &p2) {
			return p1.second < p2.second;
		});
	int i = 0;
	--m;
	for (; i < n; ++i) {
		if (a[i] >= z[m].second) { break; }
		sum += z[m].second;
		if (z[m].first-- == 1 && m-- == 0) {
			i++;
			break;
		}
	}
	for (;i < n; ++i) {
		sum += a[i];
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define pb push_back
int main(){
	string s;
	
	int n,k;
	cin>>n>>k>>s;
	k--;
	if(s[k]=='A'){
		s[k]='a';
	}else if(s[k]=='B'){
		s[k]='b';
	}else{
		s[k]='c';
	}
	cout<<s<<endl;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;
#define sd(n) scanf("%d", &n)
#define sdd(n, m) scanf("%d%d", &n, &m)
#define sddd(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n, m) printf("%d %d\n", n, m)
#define pddd(n, m, z) printf("%d %d %d\n", n, m, z)
#define pld(n) printf("%lld\n", n)
#define pldd(n, m) printf("%lld %lld\n", n, m)
#define plddd(n, m, z) printf("%lld %lld %lld\n", n, m, z)
#define sld(n) scanf("%lld", &n)
#define sldd(n, m) scanf("%lld%lld", &n, &m)
#define slddd(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)
#define sf(n) scanf("%lf", &n)
#define sc(n) scanf("%c", &n)
#define sff(n, m) scanf("%lf%lf", &n, &m)
#define sfff(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define ss(str) scanf("%s", str)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = a; i >= n; i--)
#define mem(a, n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ce i == n ? '\n' : ' '
#define mod(x) ((x) % MOD)
#define gcd(a, b) __gcd(a, b)
#define lowbit(x) (x & -x)
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
	int ret = 0, sgn = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-')
			sgn = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		ret = ret * 10 + ch - '0';
		ch = getchar();
	}
	return ret * sgn;
}
inline void Out(int a) //ê?3?ía1ò
{
	if (a > 9)
		Out(a / 10);
	putchar(a % 10 + '0');
}

ll gcd(ll a, ll b)
{
	return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
///快速幂m^k%mod
ll qpow(ll x, ll n, ll mod)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = (res * x) % mod;
		x = x * x % mod, n >>= 1;
	}
	return res;
}

const int N = 1e6 + 50;
const double pi = 3.141592653589;
int main()
{
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	long double rad = pi * 2 * ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);
	long double rsq = (long double)(a * a + b * b) - (long double)(2 * a * b) * cosl(rad);
	printf("%20.20Lf\n", sqrtl(rsq));
	return 0;
}

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

ll solver(ll n){
  if(n%2!=0) return 0;
  else{
    ll ans=0;
    ll start=10;
    while(start<=n){
      ans += (n / start);
      start = start*5;
    }

    return ans;
  }
}

int main() {
  ll n;
  ll ans;
  cin >>  n;
  ans = solver(n);
  //ll a=0;
  /*while((ans%10)==0){
    a++;
    ans = ans / 10;
  }*/
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int LLI;
int main()
{
    int n;
    cin >> n;
    
    string tmp;
    unordered_map <string, int> s, t;
    
    for(int i = 0; i < n; i++)
    {
        cin >> tmp;
        s[tmp]++;
    }
    
    int m;
    cin >> m;
    
    for(int i = 0; i < m; i++)
    {
        cin >> tmp;
        t[tmp]++;
    }
    
    int max = 0;
    for(auto x: s)
    {
        if( max < s[x.first] - t[x.first] )
            max = s[x.first] - t[x.first];
    }
    
    cout << max;
}

Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<vector>
#include<numeric>

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

int n;

int solve(vector<string> cities){
    int merged[n+1][n+1];
    fill_n(merged[0], (n+1)*(n+1), 0);

    int length[n+1];
    fill_n(length, n+1, 0);
    for(int i=0;i<n;i++) length[i] = cities[i].length();

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i == j){
                merged[i][i] = cities[i].length();
            }else{
                bool flag = false;
                
                // iの後ろにjをくっつける
                int k_max = 0, k_tmp = 0;
                while(k_tmp <= min(length[i], length[j])){
                    flag = true;
                    for(int k=0;k<k_tmp;k++){
                        if(cities[i][length[i]-k_tmp+k] != cities[j][k]){
                            flag = false;
                            break;
                        }
                    }
                    if(flag) k_max = k_tmp;
                    k_tmp++;
                }
                merged[i][j] = k_max;
            }
        }
    }

    int dp[1<<n][n];
    fill_n(dp[0], (1<<n)*n, accumulate(length, length+n, 0));
    dp[0][n] = 0;
    for(int c=0;c<n;c++){
        dp[1 << c][c] = length[c];
    }
    for(int i=1;i<(1 << n);i++){
        for(int j=0;j<n;j++){
            for(int c=0;c<n;c++){
                if(i & (1 << c)) continue;
                int nxt = i | (1 << c);
                dp[nxt][c] = min(dp[nxt][c], dp[i][j] + length[c] - merged[j][c]);
            }
        }
    }

    return *min_element(dp[(1<<n)-1], dp[(1<<n)-1]+n);
}

vector<string> preprocess(vector<string> cities){
    int length[n];
    for(int i=0;i<n;i++) length[i] = cities[i].length();
    // 他の都市の部分文字列都市は削除
    vector<string> ret;
    bool flag;
    int m = 0;
    for(int i=0;i<n;i++){
        flag = false;
        for(int j=0;j<n;j++){
            if(i == j) continue;
            if(length[i] > length[j]) continue;
            for(int k=0;k<length[j]-length[i]+1;k++){
                if(cities[j].substr(k, length[i]) == cities[i]){
                    flag = true;
                    break;
                }
            }
            if(flag) break;
        }
        if(!flag){
            ret.push_back(cities[i]);
            m++;
        }
    }

    n = m;
    return ret;
}

int main(void){
    while(scanf("%d", &n) && n){
        vector<string> cities(n);
        for(int i=0;i<n;i++) cin >> cities[i];
        cout << solve(preprocess(cities)) << endl;
    }
}


Measured memory_bytes: 4008
n = int(input())
v_cnt = 0
e_cnt = 0

def triangle(x):
    return x * (x + 1) // 2

for l in range(1, n+1):
    v_cnt += triangle(n - l + 1)

for i in range(n-1):
    u, v = map(int, input().split())
    e_cnt += min(u,v) * (n - max(u,v) + 1)

print(v_cnt - e_cnt)

Measured memory_bytes: 9128
s = input()
t = input()
len_s = len(s)
a = ord('a')
dictionary = {chr(a + i): [[], 0] for i in range(26)}
for i in range(len_s):
  dictionary[s[i]][0].append(i)
  dictionary[s[i]][1] += 1
repeat = 0
cur_index = -1
for c in t:
  indices, len_indices = dictionary[c]
  if len_indices == 0:
    repeat = 0
    cur_index = -2
    break
  inf = -1
  sup = len_indices
  while sup - inf > 1:
    x = (inf + sup) // 2
    if indices[x] > cur_index:
      sup = x
    else:
      inf = x
  if sup == len_indices:
    repeat += 1
    cur_index = indices[0]
  else:
    cur_index = indices[sup]
print(len_s * repeat + cur_index + 1)

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

using namespace std;

typedef long long int ll;

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

  string s;
  cin >> s;
  int n = s.length();
  vector < vector < ll > > cnt(n, vector < ll > (26, 0));
  vector < vector < ll > > occurence(26, vector < ll > ());

  cnt[0][s[0] - 'a'] = 1;
  occurence[s[0] - 'a'].push_back(0);
  for(int i = 1; i < n; i++){
    for(int j = 0; j < 26; j++){
      cnt[i][j] = cnt[i - 1][j];
      if(j == s[i] - 'a'){
        cnt[i][j] = cnt[i - 1][j] + 1;
        occurence[j].push_back(i);
      }
      //cout << " cnt[" << i << "][" << j << "] = " << cnt[i][j] << '\n';
    }
  }

  for(int i = 0; i < 26; i++){
    if(occurence[i].size() == 0) continue;
    int min_val = 2 - occurence[i][0], min_idx = occurence[i][0];
    for(int j = 1; j < occurence[i].size(); j++){
      ll idx = occurence[i][j];
      if(2 * cnt[idx][i] - idx + 1 > min_val){
        cout << min_idx + 1 << " " << idx + 1<< '\n';
        return 0;
      }
      min_val = 2 * cnt[idx][i] - idx;
      min_idx = idx;
    }
  }

  cout << -1 << " " << -1 << '\n';
}


Measured memory_bytes: 25932
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#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) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string n;
    cin >> n;
    ll cnt = 0;
    for(int i = 0;i < n.size();i++){
        cnt = (cnt+n[i]-'0')%9;
    }
    if(cnt%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3772
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	int N;
	int con = 0;
	vector<int> A, B;
	// priority_queue<pair<int,int>> P;
	queue<int> Q;
	cin>>N;
	
	A.resize(N);
	B.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
	}
	
	for(int i = 0; i < N; i++){
		cin>>B[i];
		Q.push(i);
	}
	

	for(int i = 0; i < N; i++){
		int x = B[(i-1+N)%N] + B[(i+1)%N];
		
		if( B[i] - x >= A[i]){
			Q.push(i);
		}
	}
	
	while(!Q.empty()){
		int i = Q.front(); Q.pop();
		int x = B[(i-1+N)%N] + B[(i+1)%N];
		int y = (B[i]-A[i])/x;
		
		if(y){
			con += y;
			B[i] -= y*x;
			Q.push(i);
			Q.push((i+1)%N);
			Q.push((i+N-1)%N);
		}
	}

	
	if(A == B) cout<<con<<endl;
	else cout<<-1<<endl;
	
	return 0;
}

Measured memory_bytes: 6656
#include <stdio.h>

int main(){
    int a, b, d, r;
    double f;
    
    scanf("%d %d", &a, &b);
    d = a / b;
    r = a % b;
    f = (double)a / b;
    
    printf("%d %d %lf\n", d, r, f);
}


Measured memory_bytes: 2044
#include <iostream>
#include <cstdio>

using namespace std;
typedef long long LL;
const int maxn=305;
int n, data[maxn][maxn];

int main()
{
    while(~scanf("%d", &n)){
        LL ans=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                scanf("%d", &data[i][j]);
                ans+=data[i][j];
            }
        }
        ans/=2;
        for(int k=0;k<n;k++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    if(data[i][j]>data[i][k]+data[k][j]){
                        ans=-1;break;
                    }
                }
            }
        }
        if(ans!=-1){
            for(int i=0;i<n;i++){
                for(int j=i+1;j<n;j++){
                    for(int k=0;k<n;k++){
                        if(i==k||j==k)continue;
                        if(data[i][j]==data[i][k]+data[k][j]){
                            //cout<<i<<"  "<<j<<"  "<<data[i][j]<<endl;
                            ans-=data[i][j];
                            break;
                        }
                    }
                }
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 640
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    odd = 0
    even = 0

    for a in A:
        if a % 2 == 0:
            even += 1
        else:
            odd += 1

    if odd % 2 == 1:
        print("NO")
        return

    print("YES")


if __name__ == '__main__':
    main()


Measured memory_bytes: 14048
#include <iostream>

using namespace std;

#define M 1046527

class Hash {
  int table[M];

  int h1(int key) { return key % M; }
  int h2(int key) { return 1 + (key % (M - 1)); }

  int h(int key, int i) { return (h1(key) + i * h2(key)) % M; }

  int getKey(string s) {
    int key = 0;
    for (string::iterator ptr = s.begin(); ptr != s.end(); ptr++) {
      // cout << *ptr << endl;
      switch (*ptr) {
        case 'A':
          key = key * 5 + 1;
          break;
        case 'T':
          key = key * 5 + 2;
          break;
        case 'C':
          key = key * 5 + 3;
          break;
        case 'G':
          key = key * 5 + 4;
          break;
        default:
          break;
      }
    }
    return key;
  }

 public:
  Hash() {
    for (int i = 0; i < M; i++) {
      table[i] = 0;
    }
  }

  void insert(string s) {
    int i = 0;
    int key = getKey(s);
    while (true) {
      if (table[h(key, i)] == 0) {
        table[h(key, i)] = key;
        break;
      }
      i++;
    }
  }

  bool find(string s) {
    int i = 0;
    int key = getKey(s);
    while (true) {
      if (table[h(key, i)] == 0) {
        return false;
      } else if (table[h(key, i)] == key) {
        return true;
      } else {
        i++;
      }
    }
    return false;  // should not reach
  }
};

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

  Hash H;

  for (size_t i = 0; i < n; i++) {
    string cmd, s;
    cin >> cmd >> s;
    if (cmd == "insert") {
      // cout << "insert " << h(s) << endl;
      H.insert(s);
    } else if (cmd == "find") {
      if (H.find(s)) {
        cout << "yes\n";
      } else {
        cout << "no\n";
      }
    }
  }
  return 0;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

//nの素因数分解する
map<ll,ll> factorize(ll n){
    map<ll,ll> ret;
    ll x = n;
    for(ll i = 2; i*i<=n;i++){
        while(x % i == 0){
            ret[i]++;
            x /= i;
        }
    }
    if(x != 1)ret[x]++;
    return ret;
}
signed main()
{   
    gearup;
    ll n; cin >> n;
    if(n==1){
        out(0);
        return 0;
    }
    auto res = factorize(n);
    ll ans = 0;
    for(auto re:res){
        ll now = 1;
        ll num = re.first;
        int m = re.second;
        rep(i,m){
            now*=num;
            if(n % now == 0){
                n/=now;
                ans++;
            }
        }
    }
    out(ans);
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int dp[3005][3005];
char ans[3005];
inline void solve(string &s, string &t)
{
	for (int i = 0; i < s.length(); ++i)
		for (int j = 0; j < t.length(); ++j) {
			if (s[i] == t[j])
				dp[i + 1][j + 1] = dp[i][j] + 1;
			else
				dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
		}
}
void get_s(string &s, string &t)
{
	int sl = s.length(), tl = t.length(), index = 0;
	while (sl > 0 && tl > 0) {
		if (s[sl - 1] == t[tl - 1]) {
			ans[index++] = s[sl - 1];
			--sl; --tl;
		}
		else if (dp[sl][tl] == dp[sl - 1][tl])
			--sl;
		else
			--tl;
	}
	reverse(ans, ans + index);
	ans[index] = '\0';
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s, t;
	cin >> s >> t;
	solve(s, t);
	get_s(s, t);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 35456
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

P = [int(x) for x in readline().split()]
Q = [int(x) for x in readline().split()]

def tour_win_rate(x):
    if x<0: return 1000
    if x>1: return 1000
    # petrが、Pをx、Qを1-xで選ぶとする。
    return sum(max(p*x,q*(1-x)) for p,q in zip(P,Q))/100

from scipy.optimize import fmin

xopt = fmin(tour_win_rate,x0=0.5,disp=False,xtol=1e-10)[0]
print(tour_win_rate(xopt))

Measured memory_bytes: 30124
#include <bits/stdc++.h>
using namespace std;
const int INF = 2100100100;
using ll = long long;

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> s(m);
    vector<char> c(m);
    for (int i=0;i<m;i++){
        cin >> s.at(i);
        cin >> c.at(i);
    }
    for (int x=pow(10,n-1);x<pow(10,n);x++){
        bool can = true;
        string num_s = to_string(x);
        if (m == 0 ){
            if( n==1 ){
            cout << 0 << endl;
            return 0;
            }
            cout << x << endl;
            return 0;
        }
        if ( n==1 && c.at(0)=='0'){
            cout << 0 << endl;
            return 0;
        }
        for (int i=0;i<m;i++){
            int num = s.at(i)-1;
            if(!(num_s.at(num) == c.at(i))){
                can = false;
                break;
            }
        }
        if (can == true){
            cout << x << endl;
            return 0;
        }

    }   

    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int N;
long long W, weight[110],value[110];
long long dp[110][100100] = {0};

int main()
{
  cin >> N >> W;
  rep(i,N) cin >> weight[i] >> value[i];
  rep(i,N)
  {
    rep(sum_w,W+1)
    {
      if(sum_w-weight[i]>=0)
      {
        chmax(dp[i+1][sum_w],dp[i][sum_w-weight[i]]+value[i]);
      }
      chmax(dp[i+1][sum_w],dp[i][sum_w]);
    }
  }
  cout << dp[N][W] << endl;
  return 0;
}


Measured memory_bytes: 81700
//header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
 
#include <boost/sort/spreadsort/spreadsort.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
//#include <boost/graph/graph_utility.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/trie_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
//using namespace boost::multiprecision;
//using namespace boost::math;
 
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS,
        boost::no_property, boost::property<boost::edge_weight_t, int> > Graph;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define bsort boost::sort::spreadsort::spreadsort
#define int int_fast64_t
using pii = pair<int,int>;
 
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
template <class Func>
 
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}
 
    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};
 
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
 
template <typename T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using Umap = gp_hash_table<K, V>;
using Trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};
 
struct negrightshift {
    inline int operator() (const int &x, const unsigned offset) {
        return -(x >> offset);
    }
};
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	umap<string,int> mp;
    mp.reserve(n);
	int sum = 0;
	rep(i,n){
		string s;
		cin >> s;
		sort(all(s));
		++mp[s];
		sum += mp[s]-1;
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 10260
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
  int key;
  Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while( cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList() {
  Node *cur = nil->next;
  int isf = 0;
  while( 1 ) {
    if (cur == nil ) break;
    if ( isf++ > 0 ) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if ( t == nil ) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst() {
  deleteNode(nil->next);
}

void deleteLast() {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main() {
  int key, n ,i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ) {
    scanf("%s%d", com, &key);
    if ( com[0] == 'i') { insert(key); np++; size++;}
    else if ( com[0] == 'd') {
      if (strlen(com) > 6 ) {
	if (com[6] == 'F') deleteFirst();
	else if ( com[6] == 'L') deleteLast();
      } else {
	deleteKey(key); nd++;
      }
      size--;
    }
  }

  printList();

  return 0;
}



Measured memory_bytes: 33808
#include <stdio.h>
int main(){
	int N,K;
	int Stock[100];
	int D;
	int i,j;
	int chk;
	while(1){
		scanf("%d%d",&N,&K);
		if(N==0 && K==0)break;
		for(i=0;i<K;i++)scanf("%d",&Stock[i]);
		chk=1;
		for(j=0;j<N;j++){
			for(i=0;i<K;i++){
				scanf("%d",&D);
				Stock[i]-=D;
				if(Stock[i]<0)chk=0;
			}
		}
		if(chk)printf("Yes\n");
		if(!chk)printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        int M = ni();
        int Q = ni();
        int[][] lr = new int[N][N];
        for (int i = 0; i < M; i++) {
            int l = ni()-1;
            int r = ni()-1;
            lr[l][r]++;
        }
        int[][] csum = new int[N+1][N+1];
        for (int i = 0; i < N; i++) { 
            for (int j = 0; j < N; j++) {
                csum[i+1][j+1] = csum[i][j+1] + csum[i+1][j] - csum[i][j] + lr[i][j];
            }
        }
        // for (int i = 0; i < N; i++) {
        //     for (int j = 0; j < N; j++) {
        //         System.out.print(lr[i][j]);
        //     }
        //     System.out.println();
        // }
        // for (int i = 0; i < N+1; i++) {
        //     for (int j = 0; j < N+1; j++) {
        //         System.out.print(csum[i][j]);
        //     }
        //     System.out.println();
        // }
        for (int i = 0; i < Q; i++) {
            int p = ni()-1;
            int q = ni()-1;
            out.println(csum[q+1][q+1] - csum[q+1][p] - csum[p][q+1] + csum[p][p]);
        }
    }

    final int mod = 1000000007;
    int mul(int x, int y){
        return (int)((x * 1L * y) % mod);
    }
    int add(int x, int y) {
        x += y;
        return x >= mod ? (x - mod) : x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        return x >= mod ? (x - mod) : x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 58336
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[n-1] - a[0]);
	}
}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main()
{
	int x, y;
	cin >> x >> y;

	int sum = 0;
	while (x != 0 || y != 0) {
		if (x < y) {
			cout << x << " " << y << endl;
		}
		else {
			cout << y << " " << x << endl;
		}

		cin >> x >> y;
	}
	
	return 0;
}


Measured memory_bytes: 3076