akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int start = max(a, c);
  int end = min(b, d);

  if (start < end) cout << end - start << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>

#define	rep(i,n)	for(int i=0;i<n;i++)

using namespace std;

typedef	vector<int>	vi;

void rotx(vi &v){
	vi t=v;
	v[0]=t[3];	v[1]=t[2];	v[2]=t[6];	v[3]=t[7];
	v[4]=t[0];	v[5]=t[1];	v[6]=t[5];	v[7]=t[4];
}

void roty(vi &v){
	vi t=v;
	v[0]=t[4];	v[1]=t[0];	v[2]=t[3];	v[3]=t[7];
	v[4]=t[5];	v[5]=t[1];	v[6]=t[2];	v[7]=t[6];
}

void rotz(vi &v){
	vi t=v;
	v[0]=t[3];	v[1]=t[0];	v[2]=t[1];	v[3]=t[2];
	v[4]=t[7];	v[5]=t[4];	v[6]=t[5];	v[7]=t[6];
}

vi findRegularPaint(const vi &_a){
	vi a=_a,reg=_a;
	rep(i,4){
		rep(j,4){
			reg=min(reg,a);
			rotz(a);
		}
		rotx(a);
	}
	roty(a);
	rep(i,4){
		reg=min(reg,a);
		rotz(a);
	}
	roty(a),roty(a);
	rep(i,4){
		reg=min(reg,a);
		rotz(a);
	}

	return reg;
}

int vi2int(const vi &a){
	int res=0;
	rep(i,a.size())	res=res*10+a[i];
	return res;
}

int main(){
	while(1){
		string s[8];
		rep(i,8) if(!(cin>>s[i])) return 0;

		vi clr(8);
		{
			int id=0;
			map<string,int> colorid;
			rep(i,8){
				if(colorid.count(s[i])==0)	colorid[s[i]]=id++;
				clr[i]=colorid[s[i]];
			}
		}
		sort(clr.begin(),clr.end());

		set<int> cube;
		do{
			cube.insert(vi2int(findRegularPaint(clr)));
		}while(next_permutation(clr.begin(),clr.end()));

		cout<<cube.size()<<endl;
	}
}

Measured memory_bytes: 964
#include <iostream>

using namespace std;

int main() {
	int S, h, m, s;
	cin >> S;
	h = S / (60 * 60); S %= 60 * 60;
	m = S / 60; S %= 60;
	s = S;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

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

  int x, y;
  double dist;
  int count = 0;
  for (int i = 0; i < n; ++i){
    cin >> x >> y;
    dist = sqrt(pow(x, 2) + pow(y, 2));
    if (dist <= d){
      ++count;
    }
  }

  cout << count << endl;

  return 0;

}


Measured memory_bytes: 3684
// abc075_b
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};
int main(int argc, char *argv[])
{
  int h,w,cnt;
  cin>>h>>w;
  vector<string> s(h);
  rep(i,h){
    cin>>s.at(i);
  }
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(s.at(i)[j]=='#') {
        continue;
      } else {
        cnt=0;
        rep(k,8){
          if (j+dx[k]<0||j+dx[k]>=w) continue;
          if (i+dy[k]<0||i+dy[k]>=h) continue;
          if(s.at(i+dy[k])[j+dx[k]]=='#') cnt++;
        }
        s.at(i)[j]=char(cnt+'0');
      }
    }
  }
  rep(i,h)
    cout<<s.at(i)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <cassert>
using namespace std;

typedef long long ll;
int n,m,k,h;
int point[1001], num[1001];

struct Bar {
  int h,a,num[2],score[2];
  Bar(int h,int a) : h(h), a(a) {
    num[0] = num[1] = -1;
    score[0] = score[1] = -1; 
  }
};
bool operator<(const Bar &b, const Bar &c) {
  return (b.h != c.h)?b.h<c.h:b.a<c.a;
}

int main() {
  int a,b;
  while(cin>>n>>m>>h>>k, n|m|h|k) {
    for (int i=0; i<n; ++i) cin>>point[i];
    for (int i=0; i<n; ++i) num[i] = i;
    priority_queue<pair<int,int> > q;
    vector<Bar> v;
    for (int i=0; i<m; ++i) {
      cin>>a>>b; a--;
      v.push_back(Bar(b,a));
    }
    sort(v.begin(), v.end());
    ll sum = 0;

    for (int i=0; i<v.size(); ++i) {
      const int a = v[i].a;
      v[i].num[0] = num[a];
      v[i].num[1] = num[a+1];
      swap(num[a], num[a+1]);
    }
    for (int i=v.size()-1; i>=0; --i) {
      const int a = v[i].a;
      v[i].score[0] = point[a];
      v[i].score[1] = point[a+1];
      swap(point[a], point[a+1]);
    }

    ll ans = 1<<29;
    for (int i=0; i<k; ++i) sum += point[i];
    int diff = 0;
    for (int i=0; i<v.size(); ++i) {
      ans = min(ans, sum);
      if (v[i].num[0] < k && v[i].num[1] >= k) {
        ans = min(ans, sum - v[i].score[1] + v[i].score[0]);
      }
      if (v[i].num[0] >= k && v[i].num[1] < k) {
        ans = min(ans, sum + v[i].score[1] - v[i].score[0]);
      }
    }
    ans = min(ans, sum);
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 4204
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

//#include "atcoder/all"
//using namespace atcoder;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	int ans = max({a+b, a-b, a*b});
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3564
count = Array.new(26,0)
alp = "abcdefghijklmnopqrstuvwxyz"

while tmp = gets
  str = tmp.chomp.downcase
  for str_i in 0..(str.length-1)
    for a_i in 0..25 do #26
      if str[str_i] == alp[a_i]
      count[a_i] = count[a_i] + 1
      end
    end
  end
end

26.times do |t_i|
  puts alp[t_i].to_s + " : " + count[t_i].to_s
end


Measured memory_bytes: 6868
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;
typedef long long ll;

int main()
{
    ll a,b,c,d;

    cin>>a>>b>>c>>d;

    cout<<max(max(a*c,a*d),max(b*c,b*d))<<endl;

    return 0;
}


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

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

    int flag = 0;
    if(x+x == w  && y+y == h ){
        flag = 1;
    }
    //double ans = (1.0*w) * (1.0*h) / 2.0;

    //cout << ans << " " << flag << endl;
	printf("%lf %d\n", double(w)*double(h) / 2.0,  flag);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

	cout << (x < 1200 ? "ABC" : "ARC") << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))

#define INF 200000000

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

struct OwnEdge
{
	int s, t, c;
	OwnEdge(int s, int t, int c) :s(s), t(t), c(c) {}
	OwnEdge() :s(-1), t(-1), c(-1) {}
};

vector<OwnEdge> edges;
int d[10000];

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

	int V, E;
	scanf("%d %d", &V, &E);

	for (int i = 0; i < E; i++)
	{
		int u, v;
		scanf("%d %d", &u, &v);

		edges.push_back(OwnEdge(u, v, -1));
	}

	bool existCircle = false;
	for (int i = 0; i < V; i++)for (auto& e:edges)
	{
		if (d[e.t] > d[e.s] + e.c)
		{
			d[e.t] = d[e.s] + e.c;
			if (i == V - 1)
			{
				existCircle = true;
			}
		}
	}

	printf(existCircle ? "1\n" : "0\n");
	return 0;
}


Measured memory_bytes: 3268
from collections import deque
N = int(input())
B = deque(map(int, input().split()))
B.append(10 ** 5 + 1)
B.appendleft(10 ** 5 + 1)
ans = 0
for i in range(N):
  ans += min(B[i], B[i + 1])
  
print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

const long long MAX_ROW = 64; // to be set appropriately
const long long MAX_COL = 256; // to be set appropriately
struct BitMatrix {
    long long H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(long long m = 1, long long n = 1) : H(m), W(n) {}
    inline bitset<MAX_COL>& operator [] (long long i) {return val[i];}
};

ostream& operator << (ostream& s, BitMatrix A) {
    s << endl;
    for (long long i = 0; i < A.H; ++i) {
        for (long long j = 0; j < A.W; ++j) {
            s << A[i][j] << ", ";
        }
        s << endl;
    }
    return s;
}

long long GaussJordan(BitMatrix &A, bool is_extended = false) {
    long long rank = 0;
    for (long long col = 0; col < A.W; ++col) {
        if (is_extended && col == A.W - 1) break;
        long long pivot = -1;
        for (long long row = rank; row < A.H; ++row) {
            if (A[row][col]) {
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        swap(A[pivot], A[rank]);
        for (long long row = 0; row < A.H; ++row) {
            if (row != rank && A[row][col]) A[row] ^= A[rank];
        }
        ++rank;
    }
    return rank;
}

long long linear_equation(BitMatrix A, vector<long long> b, vector<long long> &res) {
    long long m = A.H, n = A.W;
    BitMatrix M(m, n + 1);
    for (long long i = 0; i < m; ++i) {
        for (long long j = 0; j < n; ++j) M[i][j] = A[i][j];
        M[i][n] = b[i];
    }
    long long rank = GaussJordan(M, true);

    // check if it has no solution
    for (long long row = rank; row < m; ++row) if (M[row][n]) return -1;

    // answer
    res.assign(n, 0);
    for (long long i = 0; i < rank; ++i) res[i] = M[i][n];
    return rank;
}

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

int main() {
  long long t,N,K,fl;
  cin >> t;
  while(t>0){
    t--;
    fl=0;
    cin >> N;
    vector<long long> a(N);
    for (long long i = 0; i < N; ++i) cin >> a[i];
    string s;
    cin >> s;

    for(long long i=0;i<N;i++){
      if(s[i]=='1'){
        //printf("<%lld %lld>\n",t,i);
        if(i==(N-1)){fl=1;break;}
        K=a[i];
        const long long DIGIT = 60;
        long long cnt=0;
        for(long long j=i+1;j<N;j++){if(s[j]=='0'){cnt++;}}
        BitMatrix A(DIGIT,cnt);
        vector<long long> b(DIGIT),res;
        for(long long d=0;d<DIGIT;d++){
          cnt=0;
          for(long long j=i+1;j<N;j++){
            if(s[j]=='1'){continue;}
            if(a[j]&(1ll<<d)){A[d][cnt]=1;}
            else{A[d][cnt]=0;}
            cnt++;
          }
          if(K&(1ll<<d)){b[d]=1;}else{b[d]=0;}
        }
        long long rank = linear_equation(A,b,res);
        //printf("%lld\n",rank);
        if(rank==-1){fl=1;break;}
      }
    }

    printf("%lld\n",fl);
  }
}


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

int main(){
 	int H, W, i, j;
 	
	while(1) {
 		cin >> H >> W;
		if(H == 0 && W == 0) {
			break;
		}
 		for(i = 0; i < H; i++) {
			for(j = 0; j < W; j++) {
				if(j == 0 || j == W - 1 || i == 0 || i == H - 1) {
				cout << '#';
			}else{
				cout << '.';
			}
		}
 		cout << endl;
 		}
	cout << endl;
	}
 	return 0;
}

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

using namespace std;

using ll = long long;

vector<int> solve(int n, int a, int b) {
    if (a != 0) {
        vector<int> res = solve(n, 0, a ^ b);
        for (int& x : res) x ^= a;
        return res;
    }
    if (n == 1) {
        return {0, 1};
    }

    int idx = 0;
    while ((b & (1 << idx)) == 0) {
        idx++;
    }

    int tar = b;
    tar = ((tar >> (idx + 1)) << idx);

    vector<int> v1 = solve(n - 1, 0, 1);
    vector<int> v2 = solve(n - 1, 1, tar);

    vector<int> res;
    for (int x : v1) {
        int foo = (x & ((1 << idx) - 1));
        int bar = ((x >> idx) << (idx + 1));
        x = foo + bar;  
        res.push_back(x);      
    }

    for (int x : v2) {
        int foo = (x & ((1 << idx) - 1));
        int bar = ((x >> idx) << (idx + 1));
        x = foo + bar + (1 << idx);      
        res.push_back(x); 
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;

    if (n == 1) {
        cout << "YES" << endl;
        cout << a << " " << b << endl;
        return 0;
    }

    if (__builtin_popcount(a ^ b) % 2 == 0) {
        cout << "NO" << endl;
        return 0;
    }

    vector<int> ans = solve(n, a, b);
    cout << "YES" << endl;
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << " \n"[i + 1 == ans.size()];
    }
    return 0;
}

Measured memory_bytes: 1756
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define End return 0

int main ()
{
   ll n,a;
   cin>>n>>a;
   ll aa[a];
   ll s=0;
   for(ll i=0; i<a; i++){
     cin>>aa[i];
     s+=aa[i];
   }
   if(n<=s)
    cout<<"Yes"<<endl;
   else
   cout<<"No"<<endl;
}
/* pray for me
All is well
*/


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
 size_t strlen(const char *s);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int N=10010;
int compare_int(const void *a, const void *b)
{
    return *(long long int*)b - *(long long int*)a;
}
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}

int main(){
	int n, len, x, y;
	int ans=0;
	int bnuma[2][2]={};
//	long long int  a[N];
	char b[20];
	cin>>n;
	rep(i, n){
		memset(b, '\0', sizeof(b));
//		b[0] = '\0';
		x=0;
		y=0;
		cin>>b;
		len = strlen(b);
		rep(j, 20){
			if(b[j]=='A'&&b[j+1]=='B'){
				ans++;
			}
		}
//printf("hoge\n");
		if(b[0]=='B') x=1;
		if(b[len-1]=='A') y=1;
		bnuma[x][y]++;
//printf("hoge%d\n", ans);
	}
	if(bnuma[1][0]>bnuma[0][1]){
		ans=ans+bnuma[0][1]+bnuma[1][1];
	}
	if(bnuma[1][0]<bnuma[0][1]){
		ans=ans+bnuma[1][0]+bnuma[1][1];
	}
	if(bnuma[1][0]==bnuma[0][1]){
		ans=ans+bnuma[1][1]+bnuma[1][0];
		if((bnuma[1][0]==0)&&(bnuma[1][1]>0)) ans--;
	}
	cout<<ans<<endl;
//printf("%d%d%d%d\n",bnuma[0][1],bnuma[1][1],bnuma[1][0],bnuma[0][0]);
//	qsort(b, 5, sizeof(long long int), compare_int);
/*	rep(i, 5){
		if((b[i]-1)%10<k){
			k=b[i]%10;
		}
		ans=ans+(b[i]+9)/10;
	}
	anss=ans*10+k-10;
	if(k==0){
		anss=anss+10;
	}
	cout<<anss<<endl;




/*	qsort(b, 5, sizeof(int), compare_int);
	if(b[4]-b[0]>k){
		printf(":(\n");
	}
	else{
		printf("Yay!\n");
	}
		rep(i, n){
		ans=c;
		rep(j, m){
			cin>>imp;
			ans=ans+imp*b[j];
		}
		if(ans>0){
			anss++;
		}
	}
	cout<<anss<<endl;
}*/
//		memset(b, '\0', sizeof(b));初期化
/*#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
 size_t strlen(const char *s);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int N=10010;
int compare_int(const void *a, const void *b)
{
    return *(long long int*)b - *(long long int*)a;
}
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}

int main(){
	long long int n;
	long long int ans=0;
	//	long long int  a[N];
	cin>>n;
//	nn=n/10000;
//	nm=n%10000;

	for(long long int i=1;i*(i+1)+i<=n;i++){
		if(n%i==0) ans=ans+n/i-1;
	}

	cout<<ans<<endl;*/
//printf("%d%d%d%d\n",bnuma[0][1],bnuma[1][1],bnuma[1][0],bnuma[0][0]);
//	qsort(b, 5, sizeof(long long int), compare_int);
/*	rep(i, 5){
		if((b[i]-1)%10<k){
			k=b[i]%10;
		}
		ans=ans+(b[i]+9)/10;
	}
	anss=ans*10+k-10;
	if(k==0){
		anss=anss+10;
	}
	cout<<anss<<endl;




/*	qsort(b, 5, sizeof(int), compare_int);
	if(b[4]-b[0]>k){
		printf(":(\n");
	}
	else{
		printf("Yay!\n");
	}
		rep(i, n){
		ans=c;
		rep(j, m){
			cin>>imp;
			ans=ans+imp*b[j];
		}
		if(ans>0){
			anss++;
		}
	}
	cout<<anss<<endl;
}*/
//		memset(b, '\0', sizeof(b));初期化
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

vector<ll> divisor(ll N) {
    vector<ll> res;
    for (ll i = 1L; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            ll j = N / i;
            if (j != i) {
                res.push_back(j);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}

void solve() {
    ll N;
    cin >> N;
    vector<ll> ans(N + 1, 0);
    for (ll x = 1; x * x <= N; x++) {
        for (ll y = 1; y * y <= N; y++) {
            for (ll z = 1; z * z <= N; z++) {
                ll v = x * x + y * y + z * z + x * y + y * z + x * z;
                if (v <= N) {
                    ans[v]++;
                }
            }
        }
    }
    rep(i, N) {
        cout << ans[i + 1] << '\n';
    }
}

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


Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int q;
    cin >> q;
    q--;
    int a, b, t;
    cin >> t >> a >> b;
    int y = b;
    
    multiset<int> s{a};
    auto med = s.begin();
    int med_i = 1;
    int v = 0;
    
    while(q--) {
        cin >> t;
        if(t == 2) {
            cout << *med << ' ' << v + y << '\n';
        } else {
            cin >> a >> b;
            y += b;
            s.insert(a);
            int i = (s.size() + 1) / 2; // new median index
            int old_med = *med;

            int old_med_i = med_i;
            int old_size = s.size() - 1;
            
            if(a >= *med) {
                if(med_i < i) {
                    med_i = i;
                    med = next(med);
                    int dif = abs(*med - old_med);
                    v -= (old_size - old_med_i) * dif;
                    v += old_med_i * dif;
                }

                v += abs(*med - a);
            } else {
                med_i++;
                if(med_i > i) {
                    med_i = i;
                    med = prev(med);
                    int dif = abs(*med - old_med);
                    v += (old_size - old_med_i + 1) * dif;
                    v -= (old_med_i - 1) * dif;
                }

                v += abs(*med - a);
            }
        }
    }
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int N, M, X;
vector<int> a;
int main() {
    cin >> N >> M >> X;
    for (int i = 0; i < M; i++)
    {
        int b;
        cin >> b;
        a.push_back(b);
    }

    auto t = upper_bound(a.begin(), a.end(), X);
    int ans;
    if(t == a.end() || t == a.begin()) ans = 0;
    else ans = min(t - a.begin(), a.end() - t);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 200005
using namespace std;
long long ans = 0;
int a[MAXN];
bool cmp(int a,int b) {
	return a > b;
}
int main() {
	int n; scanf("%d",&n);
	for(int i = 1;i <= n;i ++) {
		scanf("%d",&a[i]);
	}
	sort(a + 1,a + n + 1,cmp);
	if(n == 1) {
		printf("0\n");
		return 0;
	}
	if((n - 1) % 2 == 0) {
		ans += a[1];
		for(int i = 2;i <= (n - 1) / 2 + 1;i ++) {
			if(i != (n - 1) / 2 + 1) ans += a[i] * 2;
			else ans += a[i];
		}
	}
	else {
		ans += a[1];
		for(int i = 2;i <= n / 2;i ++) {
			ans += a[i] * 2;
		}
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 4628
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;

const long long MOD = 998244353;

long long a, b, c;


int main()
{
	scanf("%lld%lld%lld", &a, &b, &c);
	long long total = 0;
	
	if (((a + b) + 1) >= c)
	{
		total = b + c;
	}
	else
	{
		long long res = a + b + 1;
		total = b + a + b + 1;
	}
	
	printf("%lld\n", total);

	return 0;
}


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

int main() {
  int K;
  string S;
  cin >> K >> S;
  
  if(S.size() <= K){
    cout << S; 
  }else{
    for(int i = 0;i < K;i++){
      cout << S.at(i);
    }
    cout << "...";
  }
}


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

int main() {
    int N;
    cin >> N;
    int64_t A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    int64_t H = A[0];
    int64_t C = 0; 
    for (int i = 0; i < N; i++) {
        if (H < A[i]) {
            H = A[i];
        }
        if (H > A[i]) {
            C = C + (H - A[i]); 
        }
    }

    cout << C << endl;
}

Measured memory_bytes: 5168
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

n,m=map(int,input().split())
G=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    G[a].append(b)
    G[b].append(a)
C=[-1]*n
C[0]=0
def dfs(x):
    for v in G[x]:
        if C[v]==C[x]:
            print(n*(n-1)//2-m)
            exit()
        if C[v]==-1:
            C[v]=1-C[x]
            dfs(v)
dfs(0)
q=C.count(0)
#print(C)
print(q*(n-q)-m)

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

int main(void) {
	string s;
	int sum = 700;
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'o') sum += 100;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 998244353;
const int N = 1e5;
int n, d[N], c[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n) cin >> d[i];
  if(d[0]){
    cout << 0 << endl;
    return 0;
  }
  sort(d, d+n);
  c[0]++;
  ll ans = 1;
  FOR(i, 1, n){
    if(!d[i]){
      cout << 0 << endl;
      return 0;
    }
    ans = ans * c[d[i]-1] % MOD;
    c[d[i]]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define pii pair<int, int>

using namespace std;

int main() {
    //freopen("output.txt", "w", stdout);

    int n; cin >> n;
    
    int val = 7;
    int cnt = 1;

    while(val%n != 0 and cnt < 2e7) {
        cnt++;
        val = val * 10 + 7;
        val = val % n;
    }

    if (cnt !=20000000) cout << cnt << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(void)
{
int x,y;
cin>>x;
cin>>y;
int num[x+1][y+1];
for(int i=0;i<x;i++)
{
int sum1=0;
	for(int j=0;j<y;j++)
	{
	cin>>num[i][j];
	sum1+=num[i][j];
	
	}
	
	num[i][y]=sum1;
}
for(int i=0;i<y+1;i++)
{
int sum2=0;
	for(int j=0;j<x;j++)
	{
	sum2+=num[j][i];
	}
	num[x][i]=sum2;
}
for(int i=0;i<x+1;i++)
{
	for(int j=0;j<y+1;j++)
	{
	
	cout<<num[i][j]<<(j==y?"":" ");
	}
	cout<<endl;
}
return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  pair<int,int> a[4];
  REP(i,N){
    int x,y;
    cin>>x>>y;
    if(i==0){
      REP(j,4)a[j]=make_pair(x,y);
    }else{
      REP(j,4){
        auto& X=a[j].first;
        auto& Y=a[j].second;
        int s1=(j>=2?-1:1);
        int s2=(j%2?-1:1);
        if(s1*(x+s2*y)>s1*(X+s2*Y))a[j]=make_pair(x,y);
      }
    }
  }
  int ans=0;
  REP(i,4)cerr<<a[i].first<<","<<a[i].second<<endl;
  REP(i,4)REP(j,4){
    auto dx=a[i].first-a[j].first;
    auto dy=a[i].second-a[j].second;
    ans=max(ans,max(dx,-dx)+max(dy,-dy));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3616
n = int(input())
a = list(map(int, input().split()))


ans=a.pop(a.index(max(a)))

for i in range(n - 1):
    if a[i] > ans / 2:
        a[i] = [ans - a[i],a[i]]
    else:
        a[i] = [a[i],a[i]]
a = sorted(a,reverse = True)

print(str(ans) + " " + str(a[0][1]))

Measured memory_bytes: 19164
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a >= b+b) {
            System.out.println(a - (b+b));
        } else {
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 21844
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        x: usize,
        y: usize,
    }
    for a in 0..=x {
        let b = x - a;
        if 2 * a + 4 * b == y {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 2148
#import math
#import collections
#n,k = map(int, input().split( ))
#A = list(map(int, input().split( )))
h = int(input())
w = int(input())
N = int(input())

m = max(h,w)
d = N//m
if N%m == 0:
  print(d)
else:
  print(d+1)

Measured memory_bytes: 9092
def dfs(A):
    if len(A) > n:
        total = 0
        for i in range(q):
            if A[b[i]]-A[a[i]] == c[i]:
                total += d[i]
        global ans
        if total > ans:
            ans = total
        return
    A.append(A[-1])
    while A[-1] <= m:
        dfs(A[:])
        A[-1] += 1

if __name__ == "__main__":
    ans = 0
    n, m, q = map(int, input().split())
    a, b, c, d = [None]*q, [None]*q, [None]*q, [None]*q
    for i in range(q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
    dfs([1])
    print(ans)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
using Int = int64_t;

int main() {
  Int K, N;
  cin >> K >> N;
  auto A = vector<Int>(N);
  for(auto& a : A) {
    cin >> a;
  }
  A.insert(A.begin(), -1);

  auto m = A[N] - A[1];
  for(int i=2; i<=N; i++) {
    auto m2 = K-A[i] + A[i-1];
    m = min(m, m2);
  }

  cout << m << endl;
  return 0;
}


Measured memory_bytes: 4736
#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>;

int main()
{
    int k, a, b;
    cin >> k >> a >> b;
    if (a % k != 0 && a / k == b / k) {
        cout << "NG" << endl;
    } else {
        cout << "OK" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
using ll = long long;

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

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

#define abs(x) ((x) > 0 ? (x) : (-(x)))
int S[2001], T[2001];
int dp[2001][2001][2];

int main() {
  int n, m; cin >> n >> m;
  char tmp;
  FOR(i,1,n+1) {
    cin >> tmp;
    S[i] = tmp == 'O' ? 0 : 1;
  }
  FOR(i,1,m+1) {
    cin >> tmp;
    T[i] = tmp == 'O' ? 0 : 1;
  }
  FOR(s,1,n+1) if (S[s] || dp[s-1][0][1]) dp[s][0][S[s]] = dp[s-1][0][abs(S[s]-1)] + 1;
  FOR(t,1,m+1) if (T[t] || dp[0][t-1][1]) dp[0][t][T[t]] = dp[0][t-1][abs(T[t]-1)] + 1;
  int ans = 0;
  FOR(s,1,n+1) FOR(t,1,m+1) {
    if (S[s] || dp[s-1][t][1]) chmax(dp[s][t][S[s]], dp[s-1][t][abs(S[s]-1)] + 1);
    if (T[t] || dp[s][t-1][1]) chmax(dp[s][t][T[t]], dp[s][t-1][abs(T[t]-1)] + 1);
    chmax(ans, dp[s][t][1]);
  }
  cout << ans << endl;
  return 0;
}



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

using namespace std;

int main(){
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  
  vector<long long> p(A), q(B), r(C);
  multiset<long long> s;
  int temp;
  for(int i=0; i<A; i++) cin >> p[i];
  for(int i=0; i<B; i++) cin >> q[i];
  for(int i=0; i<C; i++) {cin >> temp; s.emplace(temp);}
  
  std::sort(p.begin(), p.end());
  std::sort(q.begin(), q.end());
  
  for(int i=p.size()-X; i<p.size(); i++) s.emplace(p[i]);
  for(int i=q.size()-Y; i<q.size(); i++) s.emplace(q[i]);

  int count = 0;
  long long sum = 0;
  for(auto it=s.rbegin(); it!= s.rend(); it++){
    if (count == X + Y) break;
    sum += (*it);
    ++count;
  }
    
  cout << sum;
  return 0;
}

Measured memory_bytes: 15744
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
        if self.root[x] > self.root[y]:
            x, y = y, x
        self.root[x] += self.root[y]
        self.root[y] = x 
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
    def Count(self, x): # xが属するグループのサイズを返す
        return -self.root[self.Find_Root(x)]
    def Members(self, x): # xが属するグループに属する要素をリストで返す
        return [i for i in range(self.n) if self.Find_Root(i)==self.Find_Root(x)]
    def Roots(self): # 全ての根の要素をリストで返す
        return [i for i, x in enumerate(self.root) if x < 0]
    def Group_Count(self): # グループの数を返す
        return len(self.Roots())
    
N, M = map(int, input().split())
uf = UnionFind(N+1)
p = list(map(int, input().split()))
roots = {i:i for i in range(N)}
proots = {i:i for i in range(N)}
for _ in range(M):
    x, y = map(lambda x:int(x)-1, input().split())
    uf.Unite(x, y)

for i in range(N):
    r = uf.Find_Root(i)
    roots[i] = r
    proots[p[i]-1] = r 

ans = 0
for i in range(N):
    if roots[i] == proots[i]:
        ans += 1
print(ans)


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

public class Main implements Runnable {
	public static void main (String[] args) {new Thread(null, new Main(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		long r = fs.nextInt(), D = fs.nextInt();
		long x = fs.nextInt();
		for(int i = 1; i <= 10; i++) {
			x = r*x - D;
			out.println(x);
		}
		
		out.close();
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}

	}

}

Measured memory_bytes: 24660
#include <bits/stdc++.h>
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 all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

struct UnionFind{
    vector<int> Parent;
    vector<int> sizes;
    UnionFind(int n):Parent(n),sizes(n,1){ rep(i,n)Parent[i]=i; }
    //find the root of x
    int root(int x){
        if(x!=Parent[x]){
        Parent[x] = root(Parent[x]);
        }
        return Parent[x];
    }
    //merge x and y
    void unite(int x,int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        Parent[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x,int y){ return root(x) == root(y); }
    int size(int x){ return sizes[root(x)]; }
};

/*~使い方講座~
まず、main関数内で 
    UnionFind uni(N);
と呼び出します（これでUnionFind木のuniちゃんが呼び出されます）。
uniちゃんの中には、NodeがN個あり、
それぞれの親とそれが属する集合の数（size）が定義されています。
    ①二つのNode xとy が同じ集合に属するか確認するとき
    uni.same(x, y);
    とすることで、それらが同じかどうかをtrue/falseで返す
    ②あるNode x が含まれる集合の大きさを知りたいとき
    uni.size(x);
    ③二つのNode xとyを同じ集合に属させたいとき
    uni.unite(x, y);
    ④あるNode xの根を知りたいとき
    uni.root(x);
*/
/*~UnionFind木が出題された問題~
①D-Decayed Bridges
https://beta.atcoder.jp/contests/abc120
/Users/knaga/procon/Atcoder/abc120
UnionFind木は繋がりを断つことはできないが、
構成することはできるので、逆からやるやつ。
②D-Equals
https://beta.atcoder.jp/contests/abc097
/Users/knaga/procon/Atcoder/abc097
swapすればそれらは行き来可能になるので、実質パイプ。
③B-Union Find
https://beta.atcoder.jp/contests/atc001
/Users/knaga/procon/Atcoder/atc001
典型問題。uniteして、繋がってるか聞かれたら答えるだけ。
④B-道路工事
https://beta.atcoder.jp/contests/arc032/
/Users/knaga/procon/Atcoder/arc032
すべての点に対して根を考えることで、
グループが幾つに分かれているかを知ることができる
*/

int main() {
	int N,K,L;
	cin>>N>>K>>L;
	UnionFind roads(N), rails(N);
	rep(i,K){
		int p,q;
		cin>>p>>q;
		p--;q--;
		roads.unite(p,q);
	}
	rep(i,L){
		int r,s;
		cin>>r>>s;
		r--;s--;
		rails.unite(r,s);
	}
	std::map<P, ll> map;
	rep(i,N){
		map[{roads.root(i),rails.root(i)}]++;
	}
	rep(i,N){
		if(i)cout<<" ";
		cout<<map[{roads.root(i), rails.root(i)}];
	}
	cout<<endl;
}

Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()

template<class T> using V = vector<T>;
template<class T> using V2 = V<V<T>>;

void solve(){
  int n; cin >> n;
  V2<int> t(n,V<int>(26,0));
  FOR(i,0,n){
    string s; cin >> s;
    FOR(j,0,10) ++t[i][s[j]-'a'];
  }
  sort(ALL(t));
  ll ans = 0;
  int l=0, r=l+1;
  for(;l<n && r<n;){
    while(t[l]==t[r]){
      ++r;
      if(r==n) break;
    }
    ans += (ll)(r-l)*(r-l-1)/2;
    l = r;
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 13568
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
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;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	
	int i,j,n,m,x;
	cin>>n>>m>>x;
	int a[m];
	for(i=0;i<m;i++)cin>>a[i];
	int b[2]={0};
	for(i=x;i<=n;i++){
		for(j=0;j<m;j++)if(a[j]==i)b[1]++;
	}
	for(i=x;i>=0;i--){
		for(j=0;j<m;j++)if(a[j]==i)b[0]++;
	}
	cout<<min(b[0],b[1])<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N = I()
T,A = MI()
for _ in range(N-1):
    t,a = MI()
    x = (T+t-1)//t
    y = (A+a-1)//a
    if x >= y:
        T,A = t*x,a*x
    else:
        T,A = t*y,a*y

print(T+A)


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

long max(long x, long y){
  return (x>y ? x : y);
}

int main() {
  long k,x;
  cin >> k >> x;
  if(k==1L){
    cout << x;
    return 0;
  }else{
    long ans=x-k+1L;
    for(int i=1; i<k; i++){
      cout << ans << endl;
      ans++;
    }
    cout << x << endl;
    for(int i=0; i<k-1; i++){
      ans++;
      cout << ans << endl;
    }
  }
}



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

int prime[max+1];
int i, j;
void sievePrime()
{
	for(i = 0; i <= max; i++) prime[i] = true;
	prime[0] = prime[1] = false;
	for(i = 2; i*i <= max; i++)
		if(prime[i])
			for(j = i*i; j <= max; j+=i)
				prime[j] = false;
}

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	sievePrime();
  	int n;
  	cin >> n;
  	for(i = n; i <= max; i++)
  		if(prime[i])
  		{
  			cout << i;
  			return 0;
		}
}



Measured memory_bytes: 640
/*
我的心脏怦怦跳，监管者就在附近
name:
Algorithm:
writer:Lxs(cdx)
place:
nothing is impossible
*/
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
bool prime(int x){
	 int i;
	 if(x<2) return 0;
	 for(i=2;i*i<=x;i++){
		if(x%i==0){return 0;}
	 }
	 return 1;
}
int f[101010];
int main()
{
	int a[6];
	int i;
	for(i=0;i<6;i++){
		cin>>a[i];
		f[a[i]]=1;
	}
	for(i=0;i<6;i++){
		if(f[i]==0){
			cout<<i<<endl;
		}
	}
	return 0;
}


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

int main() {
  long long a, b, x, ans = 0;
  cin >> a >> b >> x;
  if (a == 0)
    cout << b / x + 1 << endl;
  else
    cout << b / x - (a - 1) / x << endl;
  return 0;
}


Measured memory_bytes: 256
// problem: "https://atcoder.jp/contests/abc147/tasks/abc147_f"

#include<bits/stdc++.h>
#define ll long long
#define Pair pair<ll,ll>

using namespace std;

vector<vector<Pair>> Merge(map<ll,vector<Pair>>&M)
{
    vector<vector<Pair>>V(M.size());
    ll i,j,k;
    i = 0;
    k = 0;
    for(auto it=M.begin();it!=M.end();it++)
    {
        k = 0;
        V[i].push_back(it->second[0]);
        for(j=1;j!=it->second.size();j++)
        {
            if(it->second[j].first <= V[i][k].second)
            {
                V[i][k].second = max(it->second[j].second,V[i][k].second);
            }
            else
            {
                V[i].push_back(it->second[j]);
                k++;
            }
        }

        i++;
    }

    return V;
}

ll SumDif(ll n,ll x,ll d)
{
    if(d == 0)
    {
        if(x == 0)
            return 1;
        else
            return n+1;
    }

    map<ll,vector<Pair>>M;
    ll m;

    for(m=0;m!=n+1;m++)
    {
        ll r = (m*x%d + d)%d;
        ll L,R;
        L = m*x + m*(m-1)*d/2;
        R = m*x + (m*n - m*(m+1)/2) * d;

        M[r].push_back(Pair(min(L,R),max(L,R)));
    }

    for(auto it=M.begin();it!=M.end();it++)
        sort(it->second.begin(),it->second.end());

    vector<vector<Pair>>V = Merge(M);       // define
    ll i,j;
    ll c = 0;
    for(i=0;i!=V.size();i++)
        for(j=0;j!=V[i].size();j++)
            c += (V[i][j].second - V[i][j].first)/abs(d) + 1;

    return c;
}

int main()
{
    ll n,x,d;
    cin>>n>>x>>d;

    cout<<SumDif(n,x,d);        // define

    return 0;
}


Measured memory_bytes: 33024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define N 108

int a,b,c,d,tog = 0;
int flag[N];

int main()
{
	scanf("%d%d%d%d", &a, &b, &c, &d);
	for (int i = 0; i < N; i++)
		flag[i] = 0;
	for (int i = a; i < b; i++)
		flag[i] ++;
	for (int i = c; i < d; i++)
		if (flag[i] != 0)
			tog++;
	printf("%d\n", tog);
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n,k = list(map(int,input().split()))
MOD = 10**9+7

L = [i for i in range(k+1)]

for i in range(1,k):
    for j in range(i*2,k+1,i):
        L[j]-=L[i]
ans = 0
for i in range(1,k+1):
    ans = (ans+pow(k//i,n,MOD)*L[i])%MOD
print(ans)

Measured memory_bytes: 73704
//#pragma GCC optimize("trapv")
#include <iostream>
#include <vector>
#include <tuple>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <unordered_set>
#define int long long
#define aint(x) (x).begin(), (x).end()
#define aintr(x) (x).rbegin(), (x).rend()

using namespace std;

const int MOD = 1e9 + 7;
const int INF = 2e18;

void fast()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

signed main()
{
	fast();
	int h, w, m, ans = 0;
	cin >> h >> w >> m;
	vector <pair <int, int> > tmp;
	vector <int> rows(h), smth(w);
	set <pair <int, int> > bomb;

	for (int i = 0; i < m; ++i) 
	{
		int u, v;
		cin >> u >> v;
		--u;
		--v;
		++rows[u];
		++smth[v];
		tmp.push_back(make_pair(u, v ));
		bomb.insert(make_pair( u, v ));
	}

	for (auto cur : tmp) 
	{
		ans = max(ans, smth[cur.second] + rows[cur.first] - 1);
	}

	int mxl = -1, mxpl = -1;
	for (int i = 0; i < rows.size(); ++i) 
	{
		mxl = max(mxl, rows[i]);
	}

	for (int i = 0; i < smth.size(); ++i) 
	{
		mxpl = max(mxpl, smth[i]);
	}

	vector <int> now, temp;
	for (int i = 0; i < rows.size(); ++i) 
	{
		if (mxl == rows[i]) 
		{
			now.push_back(i);
		}
	}

	for (int i = 0; i < smth.size(); ++i)
	{
		if (mxpl == smth[i]) 
		{
			temp.push_back(i);
		}
	}

	for (int i = 0; i < now.size(); ++i) 
	{
		for (int j = 0; j < temp.size(); ++j) 
		{
			if (bomb.find({ now[i], temp[j] }) == bomb.end()) 
			{
				cout << mxl + mxpl << '\n';
				return 0;
			}
		}
	}
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 40124
N = int(input())
H = [0] + list(map(int, input().split()))

ans = 'Yes'
for i in range(N):
    if H[i + 1] > H[i]:
        H[i + 1] -= 1
    if H[i] > H[i + 1]:
        ans = 'No'

print(ans)


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n; cin >> n;
    if(n%2 == 0) cout << n/2 << endl;
    else cout << (n/2)+1 << endl;
}

Measured memory_bytes: 3556
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main(){
	FIO
	
	int n;
	cin >> n;
	cout << n / 3 << '\n';
	return 0; 
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

int main(void) {
    double BTC = 380000.0;
    int n;
    cin >> n;

    double sum = 0;
    REP(i, n) {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY") {
            sum += x;
        }
        else {
            sum += x * BTC;
        }
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String s = sc.next();
    int[] sum = new int[n];
    int cnt = 0;
    for (int i = 1; i < n; i++) {
      if (s.charAt(i) == 'C') {
        if (s.charAt(i-1) == 'A') {
          cnt++;
        }
      }
      sum[i] = cnt;
    }
    int[] l = new int[q];
    int[] r = new int[q];
    for (int i = 0; i < q; i++) {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }
    for (int i = 0; i < q; i++) {
      int ans = (sum[r[i]-1]) - sum[l[i]-1];
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 81872