akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
typedef long long ll;
typedef long double ld;
using namespace std;

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

  int n, k;
  string s;
  cin >> n >> k >> s;

  vpii v;
  for (int i = 0; i < n; i++) {
    if (i == 0 || v.back().f != s[i]) {
      v.pb({s[i], 1});
    } else {
      v.back().s++;
    }
  }

  int cur = 0;
  for (auto& p : v) {
    cur += p.s - 1;
  }

  if (v.size() & 1) {
    int h = v.size() / 2;
    for (int i = 1; i <= min(h, k); i++) {
      cur += 2;
    }
  } else {
    int h = (v.size() - 1) / 2;
    for (int i = 1; i <= min(h, k); i++) {
      cur += 2;
    }
    if (k > h) {
      cur++;
    }
  }

  cout << cur << endl;

  return 0;
}

Measured memory_bytes: 1480
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, w, v = 0;
    scanf("%d %d",&n, &w);
    int weight[n], value[n];
    for(int i = 0; i < n; i++){
        scanf("%d %d",&weight[i], &value[i]);
        v += value[i];
    }
    vector<vector<long long> >dp(n+1, vector<long long>(v+1, INT_MAX));
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= v; j++){
            if(j == 0){
                dp[i][j] = 0;
                continue;
            }
            else if(value[i-1] <= j){
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-value[i - 1]] + weight[i-1]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
  // cout << "value of v = " << v << endl;
    for(int i = v; i >= 0; i--){
        if(dp[n][i] <= w) {
           // cout << dp[n][i] << endl;
            printf("%d\n",i);
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int n, a = 0;
  scanf("%d", &n);
  v1i v(n);
  rep(i, n) scanf("%d", &v[i]);
  map<int, int> m;
  rep(i, n) m[v[i]] += 1;
  for(auto p: m){
    if(p.se >= p.fi) a += p.se - p.fi;
    else a += p.se;
  }
  printf("%d\n", a);
  return 0;
}

Measured memory_bytes: 5120
#include <stdio.h>

int a(int);
int main() {
  int n;

  while(scanf("%d", &n) != EOF){
 
    printf("%d\n", a(n));
  }
  return 0;
}


int a(int n){
  if (n == 1) return 2;
  
  return n + a(n - 1);
}

Measured memory_bytes: 596
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
const double EPS=1e-8;
typedef vector<double>vec;
typedef vector<vec>mat;
double ABS(double a){return max(a,-a);}
vec gauss_jordan(const mat &A,const vec &b){
	int n=A.size();
	mat B(n,vec(n+1));
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)B[i][j]=A[i][j];
	for(int i=0;i<n;i++)B[i][n]=b[i];
	for(int i=0;i<n;i++){
		int pivot=i;
		for(int j=i;j<n;j++){
			if(ABS(B[j][i])>ABS(B[pivot][i]))pivot=j;
		}
		swap(B[i],B[pivot]);
		if(ABS(B[i][i])<EPS)return vec();
		for(int j=i+1;j<=n;j++)B[i][j]/=B[i][i];
		for(int j=0;j<n;j++){
			if(i!=j){
				for(int k=i+1;k<=n;k++)B[j][k]-=B[j][i]*B[i][k];
			}
		}
	}
	vec x(n);
	for(int i=0;i<n;i++)x[i]=B[i][n];
	return x;
}
double now[30][30][30];
int main(){
	int a,m,b,n;
	while(scanf("%d%d%d%d",&a,&m,&b,&n),a){
		for(int i=0;i<30;i++)for(int j=0;j<30;j++)for(int k=0;k<30;k++)
			now[i][j][k]=0;
		now[0][0][0]=1;
		for(int i=0;i<m*n;i++){
			for(int j=0;j<m;j++){
				for(int k=0;k<n;k++){
					now[i+1][j+1][k]+=now[i][j][k];
					now[i+1][j][k+1]+=now[i][j][k];
				}
			}
			for(int j=0;j<n;j++)now[i+1][0][j]+=now[i+1][m][j]*a;
			for(int j=0;j<m;j++)now[i+1][j][0]+=now[i+1][j][n]*b;
			now[i+1][0][0]+=now[i+1][m][n]*a*b;
		}
		mat A(m*n,vec(m*n));
		vec B(m*n);
		for(int i=0;i<m*n;i++){
			for(int j=0;j<m;j++){
				for(int k=0;k<n;k++){
					A[j*n+k][i]=now[i][j][k];
				}
			}
		}
		for(int i=0;i<m;i++)for(int j=0;j<n;j++)
			B[i*n+j]-=now[n*m][i][j];
		vec x=gauss_jordan(A,B);
		printf("1");
		for(int i=m*n-1;i>=0;i--){
			printf(" %d",(int)(round(x[i])));
		}
		printf("\n");
	}
}

Measured memory_bytes: 1292
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
using namespace std;

#define ll long long int

const int MOD = 1000000007;

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
int main() {

	int a, b, c;
	cin >> a >> b >> c;

	if (a + b == c || a + c == b || b + c == a)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

ll A[100000];
ll bitsum[2][42];

ll bs(ll N, int b, int i){
    ll ans = 0;
    for(int j=0;j<N;j++){
        ans += (((A[j]>>b)&1)^i)&1;
    }

    return ans<<b;
}

int main(){
    ll N, K;

    cin >> N >> K;
    for(int i=0;i<N;i++) cin >> A[i];

    for(int b=0;b<=41;b++){
        for(int i=0;i<2;i++){
            bitsum[i][b] = bs(N, b, i);
        }
    }

    ll f1 = 0, f2 = 0;
    ll count = 0;
    bool flg = false;
    for(int b=41;b>=0;b--){
        if(bitsum[1][b] > bitsum[0][b] && (count+(1LL<<b)) <= K){
            f1 += bitsum[1][b];
            count += 1LL<<b;
        }else{
            f1 += bitsum[0][b];
        }
    }
    count = 0;
    for(int b=41;b>=0;b--){
        if(bitsum[1][b] > bitsum[0][b] && (count+(1LL<<b)) <= K){
            if(!flg){
                f2 += bitsum[0][b];
                flg = true;
            }else{
                f2 += bitsum[1][b];
                count += 1LL<<b;
            }
        }else{
            f2 += bitsum[0][b];
        }
    }

    cout << max(f1,f2) << endl;
    return 0;
}

Measured memory_bytes: 1024
l,r=map(int,input().split())
n=2019
if r-l>2019:
  print(0)
else:
  for i in range(l,r+1):
    for j in range(l,r+1):
      if i==j:
        break
      n=min(n,(i*j)%2019)
  print(n)


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  /*
  i:余り
  (n-i)/i = m ⇔ n-i = i*m
  m > i より n-i > i*i
  n-i < n より n > i*i
  */
  for (ll i = 1; i*i < n; i++) {
    if (n%((n-i)/i) == i)
      ans += (n-i)/i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
using namespace std;

//seg[n]にxを足す
void add(vector<int>& seg, int n, int x, int k = 1, int l = 0, int r = -1) {
	if (r == -1)r = seg.size() / 2 - 1;
	if (k == seg.size() / 2 + n)seg[k] += x;
	else if (l <= n && n <= r) {
		add(seg, n, x, 2 * k, l, (l + r) / 2);
		add(seg, n, x, 2 * k + 1, (l + r) / 2 + 1, r);
		seg[k] = seg[2 * k] + seg[2 * k + 1];
	}
}

//[a,b]の和
int get(vector<int>& seg, int a, int b, int k = 1, int l = 0, int r = -1) {
	if (r == -1)r = seg.size() / 2 - 1;
	if (b < l || r < a)return 0;
	if (a <= l && r <= b)return seg[k];
	return get(seg, a, b, 2 * k, l, (l + r) / 2) + get(seg, a, b, 2 * k + 1, (l + r) / 2 + 1, r);
}

void solve() {
	int N;
	vector<int> P;   //数字nがどこにあるか(1-index)
	vector<int> seg;
	cin >> N;
	int RN = 1;
	while (RN < N+2)RN *= 2;
	P.resize(N+2);
	seg.resize(RN * 2);
	for (int n = 1; n <= N; n++) {
		int a;
		cin >> a;
		P[a] = n;
	}
	long long ans = 0;
	add(seg, P[N], 1);
	add(seg, 0, 1);
	add(seg, N + 1, 1);
	for (int n = N - 1; n >= 1; n--) {
		//左右直近の自分より大きい数を探す
		int R, L;
		//seg[e]まで0 seg[s]から1
		int s = 0, e = P[n];
		while (e - s > 1) {
			int m = (e + s) / 2;
			if (get(seg, m, P[n]) > 0)s = m;
			else e = m;
		}
		L = s;
		//seg[s]まで0
		s = P[n], e = N+1;
		while (e - s > 1) {
			int m = (e + s) / 2;
			if (get(seg, P[n], m) == 0)s = m;
			else e = m;
		}
		R = e;
		int LL;
		if (L == 0)LL = 0;
		else {
			//seg[e]まで1
			s = 0, e = L;
			while (e - s > 1) {
				int m = (e + s) / 2;
				if (get(seg, m, P[n]) == 1)e = m;
				else s = m;
			}
			LL = s;
		}
		int RR;
		if (R == N + 1)RR = N+1;
		else {
			//seg[s]まで1
			s = R, e = N + 1;
			while (e - s > 1) {
				int m = (e + s) / 2;
				if (get(seg, P[n], m) == 1)s = m;
				else e = m;
			}
			RR = e;
		}
		int tmp = (L - LL) * (R - P[n]) + (P[n] - L) * (RR - R);
		ans += (long long)tmp * (long long)n;
		add(seg, P[n], 1);
	}
	cout << ans << endl;
	return;
}

//////////////////////////////
//////////////////////////////

int main() {
#ifdef DEBUGTIME
	for (int time = 0; time < DEBUGTIME; time++) {
		solve();
		cout << "####################" << endl;
	}
#else
	solve();
#endif
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace  std;
#define f(i,n) 		for(i=0;i<n;i++)
#define fr(i,n,a) 	for(i=n;i>=a;i--)
#define fa(i,a,n) 	for(i=a;i<n;i++)
#define deb(x)		cout<<#x<<" "<<x<<endl;
#define deb2(x,y)	cout<<#x<<","<<#y<<" "<<x<<","<<y<<endl;
#define buf(x)		cout<<"Check"<<x<<endl;
#define ll			long long int 
#define ft			first
#define s			second
#define pb			push_back
#define mp			make_pair
#define d			double
#define all(v)		v.begin(),v.end()	
#define et(v)		for(auto itr:v)
inline void p(int x[],int n)	{	int i;f(i,n)cout<<x[i]<<" ";cout<<endl; }


 


void solve()
{  	
	ll N,K,i,j,a=0,b=0;
	//cin>>N;
	string s;
	cin>>s;
	ll len=0;
	f(i,3)
	{
		if(s[i]=='R')
			++len;
		else
		{
			a=max(len,a);
			len=0;
		}
			
	}	
	a=max(len,a);
	cout<<a;
}
int main()
{	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll t=1,c=1;
	//cin>>t;
	while(t--)
	{
		

		//cout<<"Case #"<<c++<<": "<<endl;
		solve();
		cout<<endl;
		
	}
	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
using namespace std;
int main(void){
  string a, b;
  cin >> a >> b;
  if (a == "H") cout << b <<endl;
  if (a == "D"){
    if (b == "H") cout << "D" <<endl;
    else if (b == "D") cout << "H" <<endl;
  }
  return 0;
}

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

typedef long long ll;

int main(){
	static ll m;
	static ll d[200010],c[200010];
	scanf("%lld",&m);
	for(int i = 0 ; i < m ; i ++){
		scanf("%lld%lld",&d[i],&c[i]);
	}
	
	ll ret = -1;
	ll sum = 8;
	for(int i = 0 ; i < m ; i ++){
		ret += c[i];
		sum += c[i]*d[i];
	}
	cout << ret + sum/9-1 << endl;
}
	

Measured memory_bytes: 3328
#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

const int tam = 1e6 + 10;

int t[tam][26];
int nxt = 1;
bool isLeaf[tam];
string v[200010];
vi path[200010];

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int n;
    cin >> n;
    fore(i, 0, n) {
        cin >> v[i];
        reverse(all(v[i]));
        string &s = v[i];
        int node = 0;
        for (char c : s) {
            path[i].pb(node);
            if (t[node][c-'a'] == 0) {
                t[node][c-'a'] = nxt++;
            }
            node = t[node][c-'a'];
        }
        isLeaf[node] = true;
    }
    ll res = 0;
    fore(i, 0, n) {
        string &s = v[i];
        set<char> sc;
        for (int j = sz(s) - 1; j >= 0; j--)
        {
            int node = path[i][j];
            sc.insert(s[j]);
            for (char c : sc) {
                int child = t[node][c-'a'];
                res += isLeaf[child];
            }
        }
    }
    cout << res - n << '\n';
    return 0;
};
// Dinosaurs are cool!

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

using namespace std;

void insertionSort(vector<int> &data) {
  int n = data.size();
  for (int i = 0; i < n; i++) {
    cout << data[i] << (i == n-1 ? "\n" : " ");
  }
  for (int i = 1; i < n; i++) {
    int tmp = data[i];
    int j = i-1;
    while (j >= 0 && data[j] > tmp) {
      data[j+1] = data[j];
      j--;
    }
    data[j+1] = tmp;
    for (int i = 0; i < n; i++) {
      cout << data[i] << (i == n-1 ? "\n" : " ");
    }
  }
}

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

  vector<int> data(n);
  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }

  insertionSort(data);

  return 0;
}



Measured memory_bytes: 3084
#include <stdio.h>



int main(){

	int a,b,c,count=0;

	scanf("%d %d %d",&a,&b,&c);
	
	for(int i=a;i<(b+1);i++){
		if(c%i==0){
			count++;
		}
	}

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

	return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    string s;
    cin >> s;
    int q;
    cin >> q;

    bool flag = true;
    string l, r;
    rep(i, q)
    {
        int t;
        cin >> t;
        if (t == 1) {
            flag = !flag;
            continue;
        } else {
            int f;
            string c;
            cin >> f >> c;
            if (flag) {
                if (f == 1)
                    l += c;
                if (f == 2)
                    r += c;
            } else {
                if (f == 1)
                    r += c;
                if (f == 2)
                    l += c;
            }
        }
    }

    if (flag) {
        reverse(l.begin(), l.end());
        cout << l + s + r << endl;
    } else {
        reverse(r.begin(), r.end());
        reverse(s.begin(), s.end());
        cout << r + s + l << endl;
    }
}

Measured memory_bytes: 1348
n, l = gets.split(" ").map(&:to_i)
aps = Array.new
min = 0
count=0
for k in 1..n
  aps << k + l - 1
  count+=1
  if count >= 2
    if aps[count-1].abs <=  aps[count-2].abs
      min = count-1
    end
  end
end
##p min
aps.delete_at(min)
p aps.inject(:+)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define endl        '\n'
#define pi          2*acos(0.0)
#define pb(a)       push_back(a)
#define db          double
#define ld          long double
#define ll          long long
#define ull         unsigned long long
#define mod         1000000007
#define inf         1000000000000000001
#define sqr(x)      (x) * (x)
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)   ((a/gcd(a,b)) * b)
#define debug(x) 	cerr << #x << " = " << (x) <<endl
#define all(x)      (x).begin(), (x).end()
#define unsyncIO    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;

int main()
{
    //freopen("/home/taalpatar_shepai/Documents/my_codes/out.txt", "w", stdout);
    string s, ans;
    cin >> s;
    vector<char> vch;
    for (int i = 0; i < s.length(); i++) {
        if(s[i] != 'B')
            vch.pb(s[i]);
        else if(s[i] == 'B') {
            if(!vch.empty()) {
                vch.pop_back();
            }
        }
    }
    for (int i = 0; i < vch.size(); i++) {
        cout << vch[i];
    }
    cout << endl;
    return 0;
}

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

int main()
{
	int A, B, C, X;
	cin >> A >> B >> C >> X;

	int ans = 0;
	for (int i = 0; i <= A; ++i)
	{
		for (int j = 0; j <= B; ++j)
		{
			for (int k = 0; k <= C; ++k)
			{
				if (500 * i + 100 * j + 50 * k == X)
				{
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

input = sys.stdin.readline


def calc_prime_factors(n):
    """Trial division"""
    factors = []
    # factor: 2
    while n % 2 == 0:
        factors.append(2)
        n //= 2
    # factor: 3, 5, 7, 11, ...
    f = 3
    while f ** 2 <= n:
        if n % f == 0:
            factors.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        factors.append(n)
    return Counter(factors).keys()


def main():
    A, B = map(int, input().split())

    A_keys = calc_prime_factors(A)
    B_keys = calc_prime_factors(B)
    ans = len(set(A_keys) & set(B_keys)) + 1
    print(ans)


if __name__ == "__main__":
    main()


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

typedef long long ll;
ll k, a[100001],p[100001],q[100001];

int main(void){
    cin>>k;
    a[0]=1;
    for(int i=1;i<=k;i++){
        cin>>a[i];
    }
    if(a[k]!=2){
        cout<<-1<<endl;
        return 0;
    }
    p[k]=q[k]=1;
    for(int i=k-1;i>=0;i--){
        p[i]=(p[i+1]*a[i+1]+a[i+1]-1-(p[i+1]*a[i+1]+a[i+1]-1)%a[i])/a[i];
        q[i]=(q[i+1]*a[i+1]+(a[i]-(q[i+1]*a[i+1])%a[i])%a[i])/a[i];
        if(p[i]<q[i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<q[0]<<" "<<p[0]<<endl;
}


Measured memory_bytes: 2560
n=int(input())
s=[]
for i in range(n):
    s.append(input())
a=[0]*4
for i in range(n):
    if s[i]=='AC':
        a[0]+=1
    elif s[i]=='WA':
        a[1]+=1
    elif s[i]=='TLE':
        a[2]+=1
    else:
        a[3]+=1
print("AC x {}".format(a[0]))
print("WA x {}".format(a[1]))
print("TLE x {}".format(a[2]))
print("RE x {}".format(a[3]))






    

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

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

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


int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int x = max({a,b,c});
    int z = min({a,b,c});
    int y = a + b + c - x - z;
    int ans = 0;
    ans += (x - y);
    if((y - z) % 2 == 0){
        ans += (y-z) / 2;
    }else{
        ans += (y-z) / 2;
        ans += 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
vector<ll> fact(1000000);
void init_fact(int n){
	fact[0]=1;
	for (int i = 1; i < n+1; i++){
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}
}

ll mod_pow(ll x, ll p){
	ll res=1;
	ll n=x;
	while(p>0){
		if(p&1==1)res=(res*n)%MOD;
		n=(n*n)%MOD;
		p=(p>>1);
	}
	return res;
}
ll nCr(int n, int r){
	ll res=1;
	res*=fact[n];
	res*=mod_pow(fact[r],MOD-2);
	res%=MOD;
	res*=mod_pow(fact[n-r],MOD-2);
	res%=MOD;
	return res;
}
int main() {
    int X,Y; cin>>X>>Y;
    if((X+Y)%3!=0){
        cout<<0<<endl;
        return 0;
    }
    int n=(X+Y)/3;
    int a=2*n-X;
    int b=n-a;
    init_fact(n);
    if(a<0 || b<0){
        cout<<0<<endl;
        return 0;
    }
    cout<<nCr(n,a)<<endl;
}

Measured memory_bytes: 10940
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#include <unistd.h>
using namespace std; 
using namespace std::chrono; 
using namespace __gnu_pbds;
//mp.reserve(1024);
//mp.max_load_factor(0.25);
typedef tree<int, null_type, less<int>, rb_tree_tag,  
                tree_order_statistics_node_update>  
        ordered_set;  
#define ll long long int 

void addEdge(vector<ll> adj[], ll u, ll v) 
{ 
   adj[u].push_back(v); 
   adj[v].push_back(u); 
} 
int main() 
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
  return 0; 
} 


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 2100
#define ll long long
using namespace std;
 
int read_p,read_ca;
inline int read(){
    read_p=0;read_ca=getchar();
    while(read_ca<'0'||read_ca>'9') read_ca=getchar();
    while(read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
    return read_p;
}
long long l,r,mmh;
inline ll max(ll a,ll b){return a>b?a:b;}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll work(ll l,ll r,ll up){
    if (l>r) swap(l,r);
    int i;
    if (l==r) return 0;
    for (i=60;;i--) if (((r>>i)&1)&&(!((l>>i)&1))) break;
    r&=(1ll<<(i+1))-1;l&=(1ll<<(i+1))-1;r^=1ll<<i;up^=1ll<<i;
    if (r+1>=l) return min(1ll<<i,up)-r-1;
    ll mmh=work(1,r,l);
    mmh+=min((1ll<<i),up)-l;
    return mmh;
}
int main(){
    int i,j;
    scanf("%lld%lld",&l,&r);
    if (l==r) return puts("1"),0;
    printf("%lld\n",work(l,r,1ll<<62)+r-l+1);
}

Measured memory_bytes: 128
N,D = map(int,input().split())
X = [[int(i) for i in input().split()] for j in range(N)]
ans = 0

for i in range(N):
    for j in range(i+1,N):
        L = 0
        for k in range(D):
            L += (X[i][k] - X[j][k]) ** 2
        M = L ** 0.5
        if(M == int(M)):
            ans += 1

print(ans)

Measured memory_bytes: 9336
w, h, n = map(int, input().split())
g = [[1]*h for _ in range(w)]
for _ in range(n):
  x, y, a = map(int, input().split())
  for i in range(w):
    for j in range(h):
      if (a==1 and i<x) or (a==2 and i>=x) or (a==3 and j<y) or (a==4 and j>=y):
        g[i][j] = 0

print(sum(map(sum, g)))

Measured memory_bytes: 3064
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

int n;

void main() {
    while (true) {
        scan(n);

        if (n == 0) break;

        writeln(solve(n));
    }
}

int solve(int n) {
    int res;

    foreach (l ; 0 .. n) {
        foreach (r ; l + 2 .. n) {
            int x = r * (r + 1) / 2 - l * (l + 1) / 2;

            if (x == n) {
                debug {
                    writeln('[', l, ", ", r, ']');
                }
                res++;
            }
        }
    }
    return res;
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 2456
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll ans, n, C;
ll loc[111111];
ll val[111111];
ll ps[111111];
ll vv[111111];
ll pmax[111111];

ll gv(ll coef_1, ll coef_2)
{
	ll ret=0, cc=0, i;
	for(i=1 ; i<=n ; i++) ps[i]=ps[i-1]+val[i];
	for(i=1 ; i<=n ; i++) vv[i]=ps[i]-coef_1*loc[i];
	for(i=1 ; i<=n ; i++) pmax[i]=max(pmax[i-1],vv[i]);
	ret=pmax[n];
	for(i=n ; i>=1 ; i--)
	{
		cc+=val[i];
		ll cst=cc-coef_2*(C-loc[i]);
		ret=max(ret,pmax[i-1]+cst);
	}
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n>>C; ll i;
	for(i=1 ; i<=n ; i++) cin>>loc[i]>>val[i];
	ans=max(gv(1,2),gv(2,1));
	cout<<ans; return 0;
}


// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 4352
#include<stdio.h>

int main(){
  int i,j,n,m,P[10000],Q[500],c=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&P[i]);
  }
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d",&Q[i]);
  }
  for(i=0;i<m;i++){
    for(j=0;j<n;j++){
      if(P[j]==Q[i]){
	c++;
	break;
      }
    }
  }
  printf("%d\n",c);
  return 0;
}



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {

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

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

	int[] A = new int[b];

	int sum = 0;

	for(int i = 0; i < b ; i++){
		A[i] = scanner.nextInt();
	}
	for(int c : A)
		sum += c;

	if(a - sum < 0)
		System.out.println(-1);
	else
		System.out.println(a - sum);
    }
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string x;
  cin >> x;
  stack<char> st;
  rep(i, x.size()) {
    if(x[i] == 'S') st.push(x[i]);
    else if(x[i] == 'T') {
      if(st.empty() || st.top() == 'T') st.push(x[i]);
      else st.pop();
    }
  }
  cout << st.size() << endl;

  return 0;
}


Measured memory_bytes: 720
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner dd = new Scanner(System.in);
		for(int i = 1; i <= 10000; i++) {
			int x = dd.nextInt();
			if(x != 0) {
				if(x >=1 && x <= 10000) {
					System.out.println("Case " + i + ": " + x);
				}
			} else {
				break;
			}		  
		}
	}
}

Measured memory_bytes: 42088
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int white[10][1005]; // そのグループ、その列にあるホワイトチョコレート

int main() {
  // 縦をbit全探索、横はgreedyに、一列でKを超えたら無理
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> S(H);
  rep(i, H) cin >> S[i];
  int ans = 100000;
  for (int bit = 0; bit < (1<<(H-1)); bit++) {
    int group = 0;
    vector<int> id(H);
    rep(i, H) {
      id[i] = group;
      if (bit>>i & 1) group++;
    }
    group++;
    int temp = group - 1;
    rep(i, group) rep(j, W) white[i][j] = 0;
    rep(i, H) rep(j, W) {
      if (S[i][j] == '1') white[id[i]][j]++;
    }
    vector<int> cur(group);
    auto add = [&] (int j) {
      rep(i, group) cur[i] += white[i][j];
      rep(i, group) if (cur[i] > K) return false;
      return true;
    };
    rep(j, W) {
      if (!add(j)) {
        temp++;
        cur = vector<int> (group);
        if (!add(j)) {
          temp = 100000;
          break;
        }
      }
    }
    ans = min(ans, temp);
  }
  cout << ans << '\n';
  return 0;
}
// 58

Measured memory_bytes: 3664
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

from collections import Counter

N = int(input())
A = list(map(int, input().split()))

c = Counter(A)
#print(c)

key = []
for k, v in c.items():
    if v >= 4:
        # 1 1 1 1 とか
        key.append(k)
        key.append(k)

    elif v >= 2:
        key.append(k)

if len(key) < 2:
    print(0)
    exit()

key.sort(reverse=True)
print(key[0]*key[1])

Measured memory_bytes: 18728
#include<stdio.h>
int main(void)
{
	int s;
	scanf("%d",&s);
	if(s==111){
		printf("3\n");
	}
	else if(s==110){
		printf("2\n");
	}
	else if(s==101){
		printf("2\n");
	}
	else if(s==11){
		printf("2\n");
	}
	else if(s==100){
		printf("1\n");
	}
	else if(s==10){
		printf("1\n");
	}
	else if(s==1){
		printf("1\n");
	}
	else if(s==0){
		printf("0\n");
	}
	else if(s==11){
		printf("2\n");
	}
	else if(s==1){
		printf("1\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<string>
//#include<algorithm>
//#include<vector>
#include<cmath>

using namespace std;

int main()
{
	double A, B;
	cin >> A >> B;
	double minA = ceil(A / 0.08);
	double maxA = floor((A + 1.0) / 0.08);

	double minB = B * 10.0;
	double maxB = (B + 1.0) * 10.0;

	if ((minA < minB && maxA <= minB)||(minA > minB && maxB <= minA))
	{
		cout << -1;
	}
	else
	{
		cout << (minA > minB ? minA : minB);
	}
	cout << endl;
	return 0;
}


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

string hon = "hon";
string bon = "bon";
string pon = "pon";

int main(){
  
  int N = 0;
  int kt = 1;
  cin>>N;
  
  int tmp = N;
  for(int i=0;i<3;i++){
  	if(tmp>=10){
  	tmp = tmp/10;
      kt++;
  	}
  }
  
  
  switch(kt){
    case 1:
      
      break;
      
    case 2:
      N = N%10;
      
      break;
      
    case 3:
      N = N%10;
      N = N%10;
      
      break;
  }
  
  switch(N){
    case 0:
      cout<<pon;
      break;

    case 1:
      cout<<pon;
      break;
      
    case 2:
      cout<<hon;
      break;
    
    case 3:
      cout<<bon;
      break;
      
    case 4:
      cout<<hon;
      break;
      
    case 5:
      cout<<hon;
      break;
      
    case 6:
      cout<<pon;
      break;
      
    case 7:
      cout<<hon;
      break;
      
    case 8:
      cout<<pon;
      break;
      
    case 9:
      cout<<hon;
      break;
  
  }
  
  
  
  return 0;
}

Measured memory_bytes: 3612
N, M = map(int, input().split())
a = set([int(input()) for _ in range(M)])
INF = 1000000007

dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, N + 1):
	if i in a:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF

print(dp[N])

Measured memory_bytes: 19128
import math
import numpy as np
inp = list(map(int, input().split()))

A = inp[0]
B = inp[1]
H = inp[2]
M = inp[3]

H = H*60 + M
A_theta = H*0.5
B_theta = M*6
theta = abs(A_theta - B_theta)
if theta > 180.0:
    theta = 360-theta

ans = (A**2) + (B**2) - (2*A*B*math.cos(theta*(2*np.pi/360)))
print(np.sqrt(ans))

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

int main(){
  pair<int,int> day1,day2;
  cin >> day1.first >> day1.second >> day2.first >> day2.second;

  if(day1.first!=day2.first)
  cout << "1" << endl; 
  else
  cout << "0" << endl;
}

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

int N, M, x, s = 0;

int main() {
    cin>>N>>M;
    for(int i = 0; i < M; i++) {
        cin>>x;
        s += x;
    }
    if(N - s >= 0)
        cout<<N - s;
    else cout<<"-1";
    return 0;
}


Measured memory_bytes: 3676
program atcoder_contest_scheduling
  implicit none
  integer :: d, c(26) = 0, s(26, 365) = 0, t(365) = 0, u(365), m, n, p, q, i
  real(8) :: t1, t2
  call cpu_time(t1)
  call random_seed_clock()
  read(*,*) d
  read(*,*) c
  read(*,*) (s(:, i), i = 1, d)
  t = [(maxloc(s(:, i), 1), i = 1, d)]
  m = score()
  u = t
  do
    p = next_int(365)
    q = next_int(26)
    t(p) = q
    n = score()
    if (m < n) then
      m = n
      u(p) = q
    else
      t(p) = u(p)
    end if
    call cpu_time(t2)
    if (t2 - t1 > 1.975d0) exit
  end do
  write(*,'(i0)') (u(i), i = 1, d)
contains
  integer function score() result(res)
    integer :: last(26), i
    last = 0
    res = 0
    do i = 1, d
      last(t(i)) = i
      res = res + s(t(i), i) - sum(c * (i - last))
    end do
  end
  subroutine random_seed_clock()
    integer :: nseed, clock
    integer, allocatable :: seed(:)
    call system_clock(clock)
    call random_seed(size = nseed)
    allocate(seed(nseed))
    seed = clock
    call random_seed(put = seed)
    deallocate(seed)
  end
  integer function next_int(m) result(res)
    integer, intent(in)  :: m
    real(8) :: r
    call random_number(r)
    res = int(m * r) + 1
  end
end program atcoder_contest_scheduling

Measured memory_bytes: 3028
N, X, M = map(int, input().split())

acc = [0]
S = dict()
Ai = X
i = 0
while Ai not in S:
    S[Ai] = i
    acc.append(acc[-1] + Ai)
    i += 1
    Ai = (Ai * Ai) % M

t = S[Ai]
T = i - t
if N <= t:
    ans = acc[N]
else:
    ans = acc[t] + (acc[-1] - acc[t]) * ((N - t) // T) 
    if (N - t) % T > 0:
        ans += acc[((N - t) % T) + t] - acc[t]
print(ans)


Measured memory_bytes: 17556
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int N,K;
	cin>>N;
	cin>>K;
	int i;
	int x=1;
	int Sum;
	for (i=0;i<N;i++){
		if (x*2<x+K){
			x*=2;
		}else{
			x+=K;
		}
		Sum=x;
	}
	cout<<Sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],dp[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);    
    long long n,b,k,i,x,y,t,f,z;
    cin>>n;
    for (i=0;i<n;i++)
    {
    	cin>>arr[i];
	}
	dp[0]=0;
	dp[1]=abs(arr[0]-arr[1]);
	for (i=2;i<n;i++)
	{
		x=abs(arr[i-2]-arr[i])+dp[i-2];
		y=abs(arr[i-1]-arr[i])+dp[i-1];
		dp[i]=min(x,y);
	}
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 5120
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const double PI=3.1415926535897932;
using namespace std;
typedef long long ll;
ll c;
ll q(ll n){
    for(int i=1;i<=sqrt(n);i++){
        for(int j=i;j<=sqrt(n);j++){
            for(int k=j;k<=sqrt(n);k++){
                if(i*i+k*k+j*j+i*j+k*j+i*k==n){
                    //cout<<i<<" "<<j<<" "<<k<<endl;
                    if(i==j&&j==k)c+=1;
                    else if(i!=j&&j!=k&&k!=i)c+=6;
                    else c+=3;
                }
            }
        }
    }
    cout<<c<<endl;
    return 0;
}
int main(void){
    ll n;
    cin>>n;
    for(int x=1;x<=n;x++){
        c=0;
        q(x);
    }
    
}

Measured memory_bytes: 3652
import itertools

n, cc = list(map(int, input().split()))
d = [list(map(int, input().split())) for i in range(cc)]
c = [list(map(int, input().split())) for i in range(n)]

counter = [[0 for i in range(cc)] for j in range(3)]
for i in range(n):
    for j in range(n):
        counter[(i+j)%3][c[i][j]-1] += 1

m = 250000000
for y in itertools.permutations(range(cc), 3):
    new = 0
    for i in range(3):
        for x in range(cc):
            new += counter[i][x-1]*d[x-1][y[i]]
    m = min(m, new)

print(m)

Measured memory_bytes: 5620
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//

int main(void){
	int small,N;
	string S;
	cin>>S;
	N = S.size();
	small=N;
	//0と1の間をなくすことを考える．
	rep(i,N-1){
		if(S[i]!=S[i+1]){
			int large = max(i+1,N-(i+1));
			if(small>large)small=large;
		}
	}
	printf("%d\n",small);
	return 0;
}

Measured memory_bytes: 512
c = [list(map(int,input().split())) for i in range(3)]

import sys
for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            if c[0][0]-a1 == c[1][0]-a2 ==c[2][0]-a3 and c[0][1]-a1 == c[1][1]-a2 == c[2][1]-a3 and c[0][2]-a1 == c[1][2]-a2 == c[2][2]-a3:
                print('Yes')
                sys.exit()

print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>
#include <cstdint>
#include <cstring>

using namespace std;

int main()
{
	long long int N;

	cin >> N;

	//string new s[99999];
	string * s;
	s = new string[1000000];

	for (long long int i =0; i<N; i++){
		cin >> s[i];
	}

	for (long long int i = 0; i < N; i++){
		//cout << s[i] << "   ";
		sort(s[i].begin(), s[i].end());
		//cout << s[i] << endl;
	}

	long long int count = 0;

	//for (long long int j = 0; j < N-1; j++){
	//	for (long long int i = j+1; i < N; i++){
	//		if (s[j] == s[i]){
	//			++count;
	//		}
	//	}
	//}

	sort(s,s+N);

	//for (int i = 0; i < N; i++){
	//	cout << s[i] << endl;
	//}

	//for (long long int i = 0; i < N; i++){
	//	if (s[i] == s[i+1]){
	//		++count;
	//		for (long long int j = 2; j < N; j++){
	//			if (s[i] == s[i + j]){
	//				++count;
	//			}
	//			else{
	//				break;
	//			}
	//		}
	//	}
	//}

	for (int i = 0; i < N - 1;) {
		int j = i + 1;
		for (j = i + 1;; j++) {
			if (j == N || s[i] != s[j]) {
				int n = j - i;
				if (n >= 2) {
					for (int k = 1; k < n; k++)
						count += k;
				}
				break;
			}
		}
		i = j;
	}

	cout << count << endl;
	//system("pause");
	delete[]s;
	return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

int main(){
	ll n;
	cin>>n;
	ll S=0;
	rep(i,n){
		ll t;
		cin>>t;
		S+=t;
	}
	cout<<S/n<<endl;
}

Measured memory_bytes: 1156
N = int(input())
C = [0]*100
for i in range(1,N+1):
  s = str(i)
  C[10*int(s[0])+int(s[-1])] += 1
print(sum([C[10*i+j]*C[10*j+i] for i in range(10) for j in range(10)]))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() {return abs((int) mt());}
inline int mrand(int k) {return abs((int) mt()) % k;}
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
#define endln cerr << "\n";

void chemthan() {
    int x; cin >> x;
    FOR(i, 1, 360 + 1) {
        if (x * i % 360 == 0) {
            cout << i << "\n";
            return;
        }
    }
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
using namespace std;
int n, m;

bool isIn(int w, int* width){
  int sum = 0, step = 1;
  for (int i = 0; i < n; i++) {
    if(sum + width[i] > w){
      sum = 0;
      step++;
    }
    sum += width[i];
  }
  if(step > m)
    return false;
  return true;
}

int bs(int* width){
  int begin =  0, end = 1500000;
  for (int i = 0; i < n; i++) {
    if(begin < width[i])
      begin = width[i];
  }
  int mid = (begin + end) / 2;
  while(begin < mid){
    if(isIn(mid, width)){
      end = mid;
    }else{
      begin = mid;
    }
    mid = (begin + end) / 2;
  }
  if(isIn(mid, width)){
    return mid;
  }else{
    return mid + 1;
  }
}


int main(int argc, char *argv[]){
  while(cin >> m >> n, n){
    int width[n];
    for (int i = 0; i < n; i++) {
      cin >> width[i];
    }
    std::cout << bs(width) << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  // Here, try [0, 2*(max(x,y))] of pizza c.
  ll ans = INF;
  rep(i, max(x,y)+1) {
    ll now = i*2*c; // i*2
    now += max(0ll, x-i)*a;
    now += max(0ll, y-i)*b;
    chmin(ans, now);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
struct P{
	int col;
	ll lef;
};
bool operator <(P a,P b){
	if(a.col==b.col) return a.lef<b.lef;
	return a.col<b.col;
}
struct edge{
	int k,next;
}e[200005];
int n,home[100005],cnt=-1,E[105][2],fa[100005],tot;
void add(int x,int y){
	cnt++;
	e[cnt].k=y;
	e[cnt].next=home[x];
	home[x]=cnt;
}
void init(int k,int F){
	fa[k]=F;
	for(int i=home[k];~i;i=e[i].next) if(e[i].k!=F)
		init(e[i].k,k);
}
int q[100005];
P bfs(int x,int y,int op){
	int tou=0,wei=1,k;
	P ans;
	ans.col=0;
	q[0]=x;
	if(op) q[wei++]=y;
	ans.lef=wei;
	while(tou<wei){
		int o=tou,mx=0;
		tou=wei;
		ans.col++;
		for(int i=o;i<tou;i++){
			int g=0;
			for(int p=home[q[i]];~p;p=e[p].next) if(e[p].k!=fa[q[i]]) g++;
			mx=max(mx,g);
		}
		if(mx) ans.lef=ans.lef*mx;
		for(int i=o;i<tou;i++){
			for(int p=home[q[i]];~p;p=e[p].next) if(e[p].k!=fa[q[i]]) q[wei++]=e[p].k;
		}
	}
	return ans;
}
int main(){
	memset(home,-1,sizeof(home));
	scanf("%d",&n);
	for(int i=1,x,y;i<n;i++){
		scanf("%d%d",&x,&y);
		E[i][0]=x;E[i][1]=y;
	}
	tot=n;
	P ans;ans.col=1e9;ans.lef=0;
	for(int i=1;i<=tot;i++){
		n=tot;
		memset(home,-1,sizeof(home));
		cnt=-1;
		for(int p=1;p<tot;p++) add(E[p][0],E[p][1]),add(E[p][1],E[p][0]);
		init(i,0);
		P t=bfs(i,0,0);
		ans=min(ans,t);
	}
	for(int i=1;i<=tot;i++){
		n=tot;
		memset(home,-1,sizeof(home));
		cnt=-1;
		for(int p=1;p<tot;p++) add(E[p][0],E[p][1]),add(E[p][1],E[p][0]);
		for(int p=home[i];~p;p=e[p].next) if(e[p].k>i){
			init(e[p].k,i);
			init(i,e[p].k);
			P t=bfs(i,e[p].k,1);
			ans=min(ans,t);
		}
	}
	printf("%d %lld",ans.col,ans.lef);
	return 0;
}

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

int main(){
  int N;
  cin >>N;
  
  double ans = 0.0;
  double x;
  string u;
  rep(i,0,N){
    cin >>x>>u;
    if(u=="JPY") ans += (double)x;
    else if(u=="BTC") ans += 380000.0*x;
  }
    
  cout <<ans<<endl;
}

Measured memory_bytes: 256