akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
const int N=200005;
int n,m,u,v,t1,t2,t3,cnt,head[N],dep[N],to[N*2],nxt[N*2];
bool vis[N];
char ch[2500005],*p=ch;
inline int rd(){
	register int res=0;
	while(*p<'0'||*p>'9'){
		p++;
	}
	while(*p>='0'&&*p<='9'){
		res=res*10+*p-'0';
		p++;
	}
	return res;
}
void adde(int u,int v){
	to[++cnt]=v;
	nxt[cnt]=head[u];
	head[u]=cnt;
}
bool dfs(int u){
	vis[u]=true;
	int v;
	bool flag=true;
	for(int i=head[u];i;i=nxt[i]){
		v=to[i];
		if(!vis[v]){
			dep[v]=dep[u]+1;
			if(!dfs(v)){
				flag=false;
			}
		}else if(~(dep[u]-dep[v])&1){
			flag=false;
		}
	}
	return flag;
}
int main(){
	fread(ch,1,2500000,stdin);
	n=rd(),m=rd();
	for(int i=1;i<=m;i++){
		u=rd(),v=rd();
		adde(u,v);
		adde(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			if(!head[i]){
				vis[i]=true;
				t1++;
			}else if(dfs(i)){
				t2++;
			}else{
				t3++;
			}
		}
	}
	printf("%lld\n",1LL*t1*t1+2LL*t1*(n-t1)+2LL*t2*t2+2LL*t2*t3+1LL*t3*t3);
	return 0;
}

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

using namespace std;
 
int main(){
	char first, second, third, forth;
	bool YYMM, MMYY;
	cin >> first >> second >> third >> forth;
	if(first == '0' && second != '0' || first == '1' && second == '1' || first == '1' && second == '2'){
		MMYY = true;
	}else{
		MMYY = false;
	}
	if(third == '0' && forth != '0' || third == '1' && forth == '1' || third == '1' && forth == '2'){
		YYMM = true;
	}else{
		YYMM = false;
	}
	if(MMYY == true && YYMM == true){
		cout << "AMBIGUOUS" << endl;
	}else if(MMYY == true && YYMM == false){
		cout << "MMYY" << endl;
	}else if(YYMM == true && MMYY == false){
		cout << "YYMM" << endl;
	}else{
		cout << "NA" << endl;
	}
}

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

using namespace std;

constexpr int MAX = 7368792;

int main(int argc, char const *argv[]) {
    int m, n;
    bool flag[MAX];

    while (cin>>m>>n, m||n) {
        // init
        for (int i = 0; i < MAX; ++i) {
            flag[i] = false;
        }
        for (int i = 0; i < m; ++i) {
            flag[i] = true;
        }

        // solve
        for (int i = m; i < MAX; ++i) {
            if (n == 0) break;
            if (flag[i]) continue;
            for (int j = i; j < MAX; j += i) {
                flag[j] = true;
            }
            n--;
        }

        for (int i = 0; i < 15; ++i) {
        }

        // check
        int k;
        for (k = 0; k < MAX; ++k) {
            if (!flag[k]) break;
        }
        cout<<k<<endl;
    }
    return 0;
}

Measured memory_bytes: 10276
#include<iostream>
#include<vector>
using namespace std;
#define min(A,B) ((A>B)? B:A)
int main()
{
  int A,B,K;
  cin>>A>>B>>K;
  int i=1;
  vector<int> vec;
  while(i<=min(A,B)){
    if((A%i==0)&&(B%i==0)){
      vec.push_back(i);
    }
    i++;
  }
  
  cout<<*(vec.end()-K);
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll n, a, b;
    cin >> n >> a >> b;

    ll x[n];
    rep(i, 0, n){
        cin >> x[i];
    }

    ll sum = 0;
    rep(i, 0, n - 1){
        sum += min(b, (x[i + 1] - x[i]) * a);
    }

    cout << sum << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pir pair<int,int>
#define fi first
#define se second
using namespace std;

const int N=100010;
int n,a,cnt1[N],cnt2[N];
pir p[N],q[N];

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a);
		if(i&1) cnt1[a]++;
		else cnt2[a]++;
	}
	for(int i=1;i<=100000;i++) {
		p[i]=pir(cnt1[i],i);
		q[i]=pir(cnt2[i],i);
	}
	sort(p+1,p+100001);
	sort(q+1,q+100001);
	if(p[100000].se!=q[100000].se) {
		printf("%d\n",n-p[100000].fi-q[100000].fi);
		return 0;
	}
	printf("%d\n",n-max(p[99999].fi+q[100000].fi,p[100000].fi+q[99999].fi));
	return 0;
}


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

int main(void)
{
	int N;
	long long K;
	cin >> N >> K;

	int a, b;
	vector<pair<int, int>> pairs(N);
	for (int i = 0; i < N; ++i) {
		cin >> a >> b;
		pairs[i] = make_pair(a, b);
	}

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

	int i = -1;
	while (K > 0) {
		++i;
		K -= pairs[i].second;
	}

	cout << pairs[i].first << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a; i < n; i++)
#define per(i,a,n) for (int i=n-1; i >= a; i--)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
using namespace std;
int main(){
    string s;
    cin >> s;
    if (s[s.length()-1] == 's') cout << s << "es";
    else cout << s << "s";

}

Measured memory_bytes: 3628
N = int(input())
C = input()

num_R = C.count("R")
num_W = C.count("W")

C_fin = ["R" if i < num_R else "W" for i in range(len(C))]

count = 0
for c, c_fin in zip(C, C_fin):
    if(c == c_fin):
        count += 1

ans = (len(C) - count)//2

print(ans)

Measured memory_bytes: 87072
using System;

namespace _1601
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                int[] a = new int[n];
                for (int i = 0; i < n; i++) a[i] = Console.ReadLine().Length;
                int[] tanku = new int[] { 5,7,5,7,7 };
                for (int i = 0; i < n; i++)
                {
                    bool flag = true;
                    int findat = 0;
                    int sum = 0;
                    for (int j = i; j < n && findat < 5; j++)
                    {
                        sum += a[j];
                        if (sum == tanku[findat])
                        {
                            findat++;
                            sum = 0;
                        }
                        else if (sum > tanku[findat])
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        Console.WriteLine(i + 1);
                        break;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 9196
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

int main(void)
{
    string S;
    cin >> S;
    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] == '1')
        {
            cout << "9" ;
        }else{
        	cout << "1" ;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int[] dp;
    static int n, x;
    static int[] value;
    static boolean[] prime;
    public static void main(String[] args) {

        while(read()){
            makePrime();
            solve();
        }

    }

    static void makePrime(){
        prime = new boolean[1000001];
        Arrays.fill(prime, true);
        prime[0] = false;
        prime[1] = false;
        for(int i = 2; i < prime.length; i++){
            if(prime[i]){
                for(int j = i*2; j < prime.length; j += i)prime[j] = false;
            }
        }
    }

    static boolean read(){
        n = sc.nextInt();
        x = sc.nextInt();
        if( n == 0 && x == 0)return false;

        dp = new int[x+1];
        value = new int[n];

        for(int i = 0; i < value.length; i++){
            value[i] = sc.nextInt();
        }

        return true;
    }

    static void solve(){
        boolean f = false;
        int max = 0;

        for(int i = 0; i < n; i++){
            for(int j = value[i]; j <= x; j++){

                dp[j] = Math.max(dp[j], dp[j - value[i]] + value[i] );

                int k = dp[j];
                if(prime[k]){
                    max = k;
                    f = true;
                }

            }
        }

        if(f){
            System.out.println(max);
        }else{
            System.out.println("NA");
        }

    }
}

Measured memory_bytes: 22000
#include<stdio.h>

main(){
  int a,b,c;
  while((scanf("%d %d",&a,&b))!=EOF){
    c=1;
    a=a+b;
    while(a>=10){
      a=a/10;
      c=c+1;
    }
    printf("%d\n",c);
  }
  return(0);
}

Measured memory_bytes: 600
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		
		// 計算
		long result = 0;
		result += (n/(a+b))*a;
		result += min(a, n%(a+b));
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 23764
times = int(input())
numbers = list(map(int, input().split()))
result = 0
sum_numbers = sum(numbers)
calc = []

for i in range(times - 1):
  sum_numbers -= numbers[i]
  calc.append(sum_numbers)

for i in range(times - 1):
  calc[i] *= numbers[i]
  
print(sum(calc) % (10 ** 9 + 7))

Measured memory_bytes: 31620
#include <cstdio>
#include <algorithm>

typedef long long int64;

const int MAXN = 100000 + 10;

int n, m;
int a[MAXN], b[MAXN];

int main() {
	int i, j, k, m0;
	int64 tot, ans = 0;
	
	scanf("%d %d", &n, &m);
	for(i=1; i<=n; i++) 
		scanf("%d %d", &a[i], &b[i]);
	
	for(i=1; i<=n; i++)
		if((a[i] & m) == a[i])
			ans += b[i];
		
	for(k=31; ~k; k--) {
		if(m >> k & 1) {
			m0 = m >> (k + 1) << (k + 1) | ((1 << k) - 1);
			tot = 0;
			for(i = 1; i <= n; i++) 
				if((a[i] & m0) == a[i]) 
					tot += b[i];
			ans = std::max(ans, tot);
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 896
from collections import deque
N,M=map(int,input().strip().split())
l=list()
dp=[list() for _ in range(N)]
id=[-1 for _ in range(N)] #友人グループid 友人のいない者に-1をつける
for _ in range(M):
    a,b=map(int,input().strip().split())
    l.append((a,b))
    dp[a-1].append(b)
    dp[b-1].append(a)
    id[a-1]=0
    id[b-1]=0

i=1
c=[]
for n in range(1,N+1):
    cnt=0
    if id[n-1]==0:
        q=deque([n])
        while q:
            tmp=q.popleft()
            cnt+=1
            id[tmp-1]=i
            for e in dp[tmp-1]:
                if id[e-1]==0:
                    id[e-1]=i
                    q.append(e)
                else:
                    continue
        i+=1
        c.append(cnt)
    else:
        continue
if c:
    print(max(c))
else:
    print(1)

Measured memory_bytes: 58776
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
	long x;
	scanf("%ld",&x);
	long i;
	for(i=1;;i++){
		if(x<=i*(i+1)/2){
			break;
		}
	}
	
	printf("%ld\n",i);
	
    return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
blst = []
cnt = 0
for i in range(2 ** N):
    slst = []
    for j in range(N):
        if i >> j & 1:
            slst.append(j)
    blst.append(slst)

for i in blst:
    ansF = False
    for j in range(M):
        ctmp1 = 0
        for k in i:
            if ks[j][1:].count(k + 1) == 1:
                ctmp1 += 1
        if ctmp1 % 2 == p[j]:
            ansF = True
        else:
            ansF = False
            break
    if ansF:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, _ = map(int, input().split())
    X = sorted(map(int, input().split()))

    diff = sorted([b - a for a, b in zip(X[:-1], X[1:])], reverse=True)
    print(sum(diff[N-1:]))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 13960
/*
 * @Autor: valk
 * @Date: 2020-07-17 16:50:40
 * @LastEditTime: 2020-09-19 20:20:28
 * @Description: 如果邪恶  是华丽残酷的乐章 它的终场 我会亲手写上 晨曦的光 风干最后一行忧伤 黑色的墨 染上安详
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define emplace_back push_back
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const int seed = 12289;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;

char s[N], t[N];

int main()
{
    scanf("%s%s",s+1,t+1);
    int lens = strlen(s + 1);
    int lent = strlen(t + 1);
    int ans = inf;
    for (int i = 1; i + lent - 1 <= lens;i++){
        int now = 0;
        for (int j = 1; j <= lent;j++){
            now += (s[i + j - 1] != t[j]);
        }
        ans = min(ans, now);
    }
    printf("%d\n", ans);
    return 0;
}

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

const ll mod = 1000000007;
const int INF = 1001001001;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	string s; cin >> s;
	int ans = 0;
	bool suc = false;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'R'){
			if(suc){
				ans++;
			}
			else{
				ans = 1;
				suc = true;
			}
		}
		else suc = false;
	}
	cout << ans << endl;
	
} 

Measured memory_bytes: 3656
S = input()
T = input()
len_S = len(S) - len(T)

ans = 0

for i in range(len_S+1):
    temp = 0
    for j in range(len(T)):
        if S[i+j] == T[j]:
            temp += 1
    ans = max(ans,temp)

print(len(T)-ans)

Measured memory_bytes: 9040
#include<iostream>
using namespace std;
int n, m, i, j;
int d[105][105][2];
char a[105][105];
int main(){
    cin>> n >> m;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            cin>> a[i][j];
            if(a[i][j] == '.'){
                a[i][j] = 0;
            }
            else{
                a[i][j] = 1;
            }
        }
    }
    d[1][1][ 1 - a[1][1] ] = 1000000;
    d[1][1][ a[1][1] ] = a[1][1];
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            if(i == 1 && j == 1){
                continue;
            }
            d[i][j][0] = d[i][j][1] = 1000000;
            if(i != 1){
                d[i][j][ a[i][j] ] = min(d[i][j][ a[i][j] ], min(d[i - 1][j][ a[i][j] ], d[i - 1][j][ 1 - a[i][j] ] + a[i][j]) );
            }
            if(j != 1){
                d[i][j][ a[i][j] ] = min(d[i][j][ a[i][j] ], min(d[i][j - 1][ a[i][j] ], d[i][j - 1][ 1 - a[i][j] ] + a[i][j]) );
            }
        }
    }
    cout<< d[n][m][ a[n][m] ];
}


Measured memory_bytes: 384
N = int(input())
S = list(input())
cnt = 0

for i in range(N - 1) :
  if(S[i] == "O" and S[i + 1] == "X") :
    S[i] = "l"
    S[i + 1] = "l"
    cnt += 1
  elif(S[i] == "X" and S[i + 1] == "O") :
    S[i] = "l"
    S[i + 1] = "l"
    cnt += 1
  else :
    pass

print(cnt)


Measured memory_bytes: 6492
import sys
import numpy as np
import math
import collections
import copy
from collections import deque 
from functools import reduce
from itertools import product

# input = sys.stdin.readline

N = int(input())
ai = list(map(int, input().split()))
cnt = 0
for i, a in enumerate(ai):
    if (i+1) % 2 == 1 and a % 2 == 1:
        cnt += 1
print(cnt)

















Measured memory_bytes: 27012
#include <stdio.h>
#include<string.h>
int main(void)
{
          char w[100] ;
          char s[100] = "Sunny" ;
          char c[100] = "Cloudy" ;
          char r[100] = "Rainy" ;
          scanf("%s", w) ;
          if ( strcmp(w, s)==0)
          {
                    printf("%s", c) ;
          }
          if ( strcmp(w, c)==0)
           {
                    printf("%s", r) ;
          }

          if ( strcmp(w, r)==0)
           {
                    printf("%s", s) ;
          }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n,m;
    cin >> n >> m;
    ll x[n],y[n],z[n];
    rep(i,n){
        cin >> x[i] >> y[i] >> z[i];
    }
    ll res=0;
    ll tmp[n]={};
    rep(i,2)rep(j,2)rep(k,2){
        rep(l,n){
            tmp[l]=0;
            if(i==0)tmp[l]+=x[l];
            else tmp[l]-=x[l];
            if(j==0)tmp[l]+=y[l];
            else tmp[l]-=y[l];
            if(k==0)tmp[l]+=z[l];
            else tmp[l]-=z[l];
        }
        sort(tmp,tmp+n, greater<ll>());
        ll sum=0;
        rep(l,m)sum+=tmp[l];
        res = max(res,sum);
    }
    cout << res << endl;
    return 0;
}


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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

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

int h, w;

int func(int y, bool f, int a[15][10005]) {
  if (y >= h) return 0;
  int ans = 0, res = max(func(y + 1, true, a), func(y + 1, false, a));
  if (f) {
    rep(i, w) a[y][i] = abs(a[y][i] - 1);
  }
  rep(i, w) {
    int cnt = 0;
    rep(j, h) cnt += a[j][i];
    ans += (cnt > h / 2) ? cnt : h - cnt;
  }
  return max(ans, res);
}

signed main()
{
  while (cin >> h >> w, h + w) {
    int table[15][10005];
    rep(i, h) rep(j, w) cin >> table[i][j];
    cout << max(func(0, true, table), func(0, false, table)) << '\n';
  }

  return (0);
}

Measured memory_bytes: 3484
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    var(int, W, H, N);
    bool mat[105][105] {};

    rep(_, 0, N) {
        var(int, x, y, a);
        int sx = 0;
        int tx = W;
        int sy = 0;
        int ty = H;

        if (a == 1) tx = x;
        if (a == 2) sx = x;
        if (a == 3) ty = y;
        if (a == 4) sy = y;

        rep(i, sy, ty) rep(j, sx, tx) mat[i][j] = true;
    }

    int cnt = 0;
    rep(i, 0, H) rep(j, 0, W) {
        if (!mat[i][j]) ++cnt;
    }

    print(cnt);

    return 0;
}


Measured memory_bytes: 256
//Binary Tree
#include <stdio.h>
#define NIL -1
int setHeight(int );
void setDepth(int ,int );
int getSibling(int );
typedef struct{
  int parent,left_child,right_child,height,depth;
}Tree;

Tree Node[25];
int n;

int main(void){
  int i,j,node,left,right,degree;
  scanf("%d",&n);

  i=0;
  while(i<n){
    Node[i].parent=NIL;
    Node[i].left_child=NIL;
    Node[i].right_child=NIL;
    i++;
  }

  i=0;
  while(i<n){
    scanf("%d%d%d",&node,&left,&right);
    Node[node].left_child=left;
    Node[node].right_child=right;
    if(Node[node].left_child!=NIL)
      Node[Node[node].left_child].parent=node;
    if(Node[node].right_child!=NIL)
      Node[Node[node].right_child].parent=node;
    i++;
  }

  i=0;
  while(i<n){
    //find element of root
    if(Node[i].parent==NIL)
      j=i;
    i++;
  }

  setHeight(j);
  setDepth(j,0);


  i=0;
  while(i<n){
    printf("node %d: parent = %d, sibling = %d, ",i,Node[i].parent,getSibling(i));
    degree=0;
    if(Node[i].left_child!=NIL)degree++;
    if(Node[i].right_child!=NIL)degree++;
    printf("degree = %d, depth = %d, height = %d, ",degree,Node[i].depth,Node[i].height);
    if(Node[i].parent==NIL)
      printf("root");
    else if(Node[i].left_child==NIL && Node[i].right_child==NIL)
      printf("leaf");
    else printf("internal node");
    printf("\n");
    i++;
  }
  return 0;
}

int setHeight(int node){
  int height1=0,height2=0;
  //If there is(are) a child(s) of left or right, height is added 1
  if(Node[node].left_child!=NIL)
    height1=setHeight(Node[node].left_child)+1;
  if(Node[node].right_child!=NIL)
    height2=setHeight(Node[node].right_child)+1;
  if(height1>height2)
    Node[node].height=height1;
  else Node[node].height=height2;
  return Node[node].height;
}

void setDepth(int node,int deep){
  if(node!=NIL){
    Node[node].depth=deep;
    setDepth(Node[node].left_child,deep+1);
    setDepth(Node[node].right_child,deep+1);
  }
}

int getSibling(int node){
  if(Node[node].parent==NIL)return NIL;
  if(Node[Node[node].parent].left_child!=node && Node[Node[node].parent].left_child!=NIL)
    return Node[Node[node].parent].left_child;
  if(Node[Node[node].parent].right_child!=node && Node[Node[node].parent].right_child!=NIL)
    return Node[Node[node].parent].right_child;
  return NIL;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll V, E, allcost = 0;
    cin >> V >> E;
    vvc<ll> dist(V, vl(V, INF));

    vl vcnt(V);

    rep(i,E){
        ll s, t, d;
        cin >> s >> t >> d;
        allcost += d;
        if (chmin(dist[s][t], d)) dist[t][s] = d;

        vcnt[s]++, vcnt[t]++;
    }

    rep(k, V) rep(i, V) rep(j, V) chmin(dist[i][j], dist[i][k] + dist[k][j]);

    vl odl;
    rep(i, V) if (vcnt[i] & 1) odl.eb(i);
    

    ll on = odl.size();
    vl dp(1 << on, INF);
    dp[0] = 0;

    rep(bit,1<<on){
        rep(u, on){
            if(1<<u & bit) continue;
            rep(v, u){
                if (1 << v & bit) continue;
                chmin(dp[bit | 1 << u | 1 << v], dp[bit] + dist[odl[u]][odl[v]]);
            }
        }
    }

    cout << allcost + dp[(1 << on) - 1] << endl;
}


Measured memory_bytes: 3228
def main():
    n,m=map(int,input().split())
    a=sorted(list(map(int,input().split())),reverse=True)+[0]
    b=sorted(list(map(int,input().split())),reverse=True)+[0]
    h=w=0
    ans=1
    mod=10**9+7
    for i in range(n*m,0,-1):
        cnt=n*m-i
        if a[h]==i and b[w]==i:
            h+=1
            w+=1
        elif a[h]==i:
            h+=1
            ans=(ans*w)%mod
        elif b[w]==i:
            w+=1
            ans=(ans*h)%mod
        else:
            ans=(ans*(h*w-cnt))%mod
    print(ans)
main()

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

char c[4];
int clc[4];

int main(void) {
    for (int i = 0; i < 4; i++) {
        cin >> c[i];
        clc[i] = atoi(&c[i]);
    }
    int a = clc[0], b = clc[1], c = clc[2], d = clc[3];
    string op1, op2, op3;
    if (a+b+c+d == 7) {
        op1 = "+", op2 = "+", op3 = "+";
    }
    else if (a+b+c-d == 7) {
        op1 = "+", op2 = "+", op3 = "-";
    }
    else if (a+b-c+d == 7) {
        op1 = "+", op2 = "-", op3 = "+";
    }
    else if (a+b-c-d == 7) {
        op1 = "+", op2 = "-", op3 = "-";
    }
    else if (a-b+c+d == 7) {
        op1 = "-", op2 = "+", op3 = "+";
    }
    else if (a-b+c-d == 7) {
        op1 = "-", op2 = "+", op3 = "-";
    }
    else if (a-b-c+d == 7) {
        op1 = "-", op2 = "-", op3 = "+";
    }
    else if (a-b-c-d == 7) {
        op1 = "-", op2 = "-", op3 = "-";
    }

    cout << a << op1 << b << op2 << c << op3 << d << "=7"<< endl;
    return 0;
}


Measured memory_bytes: 256
# 幅優先探索（行きがけ）
import collections
import sys
import math


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    if N <= 5:
        for i in range(N):
            print(0)
        return

    def yy(x, y, z):
        return x**2+y**2+z**2+x*y+y*z+z*x

    for i in range(5):
        print(0)

    for i in range(6, N+1):
        cn = 0
        n = math.floor(math.sqrt(i)+1)
        start = math.floor(math.sqrt(i/6))
        for j in range(start, n):
            if j**2 >= i-4:
                break
            for k in range(1, j+1):
                if j**2+k**2+j*k >= i-2:
                    break
                for l in range(1, k+1):
                    y = yy(j, k, l)
                    if y > i:
                        break
                    if y == i:
                        if j == k == l:
                            cn += 1
                        elif j != k != l:
                            cn += 6
                        else:
                            cn += 3
        print(cn)


if __name__ == '__main__':
    main()


Measured memory_bytes: 72116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A){
    if(A.size() == n+1){
        int tmp = 0;
        rep(i,q){
            if (A[b[i]] - A[a[i]] == c[i]) tmp += d[i];
        }
        ans = max(ans, tmp);
        return;
    }

    A.push_back(A.back());
    while (A.back() <= m){
        dfs(A);
        A.back()++;
    }

}


int main(){
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q); 
    rep(i,q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    dfs(vector<int>(1,1));

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 3616
import math
n = int(input())
dp = [[-1] * n for i in range(n)]
for i in range(n):
    for j in range(i,n):
        dp[i][j] = math.gcd(i + 1, j + 1)
ans=0
for i in range(n):
    for j in range(i, n):
        for k in range(j, n):
            tmp=len({i, j, k})
            if  tmp == 3:
                ans += dp[dp[i][j]-1][k]*6
            elif tmp == 2:
                ans += dp[dp[i][j]-1][k] * 3
            else:
                ans += dp[dp[i][j]-1][k]
print(ans)

Measured memory_bytes: 9320
import sys
input = sys.stdin.readline
def main():
    Wr, Hu, N = map(int, input().split())
    C =  [list(map(int, input().split())) for i in range(N)]
    Wl, Hd = 0, 0
    for x, y ,a in C:
        if a == 1:
            if Wl <= x:
                Wl = x
        if a == 2:
            if Wr >= x:
                Wr = x
        if a == 3:
            if Hd <= y:
                Hd = y
        if a == 4:
            if Hu >= y:
                Hu = y
        if Wr <= Wl or Hu <= Hd:
            print(0)
            return
    W = Wr - Wl
    H = Hu - Hd
    print(W*H)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9108
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <queue>
#include <string>
#include <stack>
#include <unordered_map>
#include <unordered_set>
 
using namespace std;
 
using ll          = long long;
using db          = double;
using ld          = long double;
using uint        = unsigned int;
using ull         = unsigned long long;
 
using pii         = pair<int, int>;
using pll         = pair<ll, ll>;
using tiii        = tuple<int, int, int>;
 
#define mod7        1000000007
#define mod9        1000000009
 
#define forall(v)   v.begin(), v.end()
#define prec(x)     setprecision(x) << fixed
 
/* [💭] [💡] [🎈] */
 
int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
 
    ll n, k;
    cin >> n >> k;
    
    if ((n + 1) / 2 >= k) {
        cout << "YES";
    } else {
        cout << "NO";
    }
 
    return 0;
}

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

ll n;
cin>>n;
ll a[2*n];
for(int i=0;i<2*n;i++) cin>>a[i];
 sort(a,a+2*n);
 ll sum=0;
 for(int i=0;i<2*n;i+=2) sum+=a[i];
    cout<<sum;

    return 0;
}


Measured memory_bytes: 3564
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
struct  aa
{
    char name[20];
    int year1;
    int year2;
}sb[1010];
int main()
{
    int n,m,i,j,query,ans;
    while(~scanf("%d%d",&n,&m))
    {
        if(n==0&&m==0)break;
        for(i=0;i<n;i++)
            scanf("%s%d%d",sb[i].name,&sb[i].year1,&sb[i].year2);
        for(i=0;i<m;i++)
        {
            ans=0;
            scanf("%d",&query);
            for(j=0;j<n;j++)
                if(sb[j].year2>=query)
                {
                    ans=sb[j].year1-sb[j].year2+query;
                    if(ans>0)break;
                }
            if(ans>0)
                printf("%s %d\n",sb[j].name,ans);
            else printf("Unknown\n");
        }
    }
return 0;
}

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

typedef long long ll;

int main(){
	ll n,a,b,c,d,e;
	cin >> n >> a >> b >> c >> d >> e;
	cout << (n-1)/min({a,b,c,d,e})+5 << endl;

	return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main{
	static long mod = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt(), C = sc.nextInt();
		int[] B = new int[M];
		for(int i = 0; i < M; i++) B[i] = sc.nextInt();
		int ans = 0;
		for(int i = 0; i < N; i++) {
			int time = 0;
			for(int j = 0; j < M; j++) {
				int A = sc.nextInt();
				time += A * B[j];
			}
			if(time + C > 0) ans++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const double pi=3.1415926535;
const int MI=2147483647;
const int mod=1e9+7;
const int Max=1e4+25;

int main()
{
    cin.sync_with_stdio(false);
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <stack>
#include <vector>
using namespace std;

using i64 = long long;

#define REP(i, stop) for (register int i = 1; i <= stop; ++i)

const int is = 1 << 17;
char ib[is], *ip = ib + is, it;
inline char getc() {
	if (ip == ib + is) { fread_unlocked(ib, 1, is, stdin); ip = ib; }
	return *ip++;
}
inline int read() {
	int r = 0;
	if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
	else while ((it = *ip++) & 16) r = r * 10 + it - '0';
	return r;
}

const int os = 1 << 17;
char ob[os], *op = ob, ot;
inline void putc(const char c) {
	*op++ = c;
	if (op == ob + os) { fwrite_unlocked(ob, 1, os, stdout); op = ob; }
}
// x shoud be greater than or equal to zero
inline void write(i64 x) {
	char d[20];
	int i = 0;
	while (true) {
		d[i] = x % 10 + 48;
		x /= 10;
		++i;
		if (x <= 0) break;
	}
	while (i--) {
		putc(d[i]);
	}
	putc(' ');
}

i64 cnt[200001];
bool used[200001];
signed main() {
  i64 N = read(), Q = read();
  vector<vector<i64>> G(N + 1);
  REP(_, N - 1) {
    i64 a = read(), b = read();
    G[a].push_back(b);
    G[b].push_back(a);
  }
  REP(_, Q) {
    i64 p = read(), x = read();
    cnt[p] += x;
  }
  stack<i64> st;
  st.push(1);
  while (st.size()) {
    i64 a = st.top();
    st.pop();
    used[a] = true;
    for (i64 b : G[a]) {
      if (!used[b]) {
        cnt[b] += cnt[a];
        st.push(b);
      }
    }
  }
  REP(i, N) {
//    printf("%d ", cnt[i]);
    write(cnt[i]);
  }
  fwrite_unlocked(ob, 1, op - ob, stdout);
}


Measured memory_bytes: 18288
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;

int main(){

    string a, b;
    cin >> a >> b;

    int size = a.size() - b.size() + 1;
    for(int i=0; i<size; i++){
        if(b==a.substr(i, b.size())) printf("%d\n", i);
    }
    return 0;
}


Measured memory_bytes: 3960
#include<bits/stdc++.h>
#include<iomanip>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define KETA 40

using namespace std;

typedef long long  ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	ll z,r;
	cin>>z>>r;

	if(r-z>=2019){
		cout<<"0"<<endl;
		return 0;
	}
	z%=2019;
	r%=2019;

	if(z<r){
		int t=2018;
		for(int i=z; i<r; i++){
			for(int j=i+1; j<r+1; j++){
				t=min(t,(i*j)%2019);
			}
		}
		cout<<t<<endl;
	}else cout<<"0"<<endl;


	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ar array
#define pb push_back
#define input(arr,n) for(int i = 0; i<n; i++) cin>>arr[i]
const int mod = 1e9+7;
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<ar<int,2>> v;
	for(int i = 0, j,k ; i<n; i++)
	{
		cin>>j>>k;
		v.pb({j,k});
	}
	bool ans = false;
	for(int i = 0; i<n-2; i++)
	{
		if(v[i][0]==v[i][1])
		{
			if(i+1<n)
			{
				if(v[i+1][0]==v[i+1][1])
				{
					if(i+2<n)
					{
						if(v[i+2][0]==v[i+2][1]) ans = 1;
					}
				}
			}
		}
	}
	if(ans) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>
#include<string.h>
int main(){
	int index;
	scanf("%d", &index);
	char string[index+2];
	scanf("%s", &string);
	if(index%2==1){
		printf("No");
	}
	else{
		int flag=1;
		int i=0,j=0;
		for(i=0;i<=(index/2)-1;i++){
			j=(index/2)+i;
			if(string[i]==string[j]){
				flag=1;
			}
			else{
				flag=0;
				break;
			}
		}
		flag==1? printf("Yes\n"):printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1700
N = list(map(int,input().split()))
for i in range(len(N)):
	N[i]+=1000
direction = ["U","L","D","R"]
sub_ans1=[]
sub_ans2=[]
sub_ans1 += ["U"]*(N[3]-N[1])
sub_ans1 += ["R"]*(N[2]-N[0])
#print(sub_ans1)

for i in range(len(sub_ans1)):
	sub_ans1 += direction[direction.index(sub_ans1[i])-2]

#print(sub_ans1)
sub_ans2 += ["L"]*1
sub_ans2 += ["U"]*(N[3]-N[1]+1)
sub_ans2 += ["R"]*(N[2]-N[0]+1)
sub_ans2 += ["D"]*1
#print(sub_ans2)
for i in range(len(sub_ans2)):
	sub_ans2 += direction[direction.index(sub_ans2[i])-2]
#print(sub_ans2)

for i in range(len(sub_ans1)):
	print(sub_ans1[i],end="")
for i in range(len(sub_ans2)):
	print(sub_ans2[i],end="")

Measured memory_bytes: 4596
#include <iostream>
using namespace std;
#define ll long long
int main()
{
    ll n1, n2, hcf, temp, lcm;
    cin >> n1 >> n2;
    hcf = n1;
    temp = n2;
    
    while(hcf != temp)
    {
        if(hcf > temp)
            hcf -= temp;
        else
            temp -= hcf;
    }
    lcm = (n1 * n2) / hcf;
    cout<<lcm;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)			a.begin(), a.end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define	MAX_QWORD		((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, ll>	P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;
	vector<int> A(N + 2);
	A[0] = 0;
	REP(i, N) cin >> A[i + 1];
	A[N + 1] = 0;

	int sum = 0;
	REP(i, N + 1) {
		sum += abs(A[i + 1] - A[i]);
	}
	REPN(i, 1, N + 1) {
		int nashi = abs(A[i - 1] - A[i + 1]);
		int ari = abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1]);
		cout << sum - (ari - nashi) << endl;
	}
	return 0;
}



Measured memory_bytes: 1664
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	string s,t,u;
	cin>>s;
	cin>>t;
	ll a; cin>>a;
	ll b; cin>>b;
	cin>>u;
	if(s==u)a--;
	else b--;
	cout<<a<<" "<<b<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long int lli;

lli gcd(lli a, lli b)
{
  return (b>0)? gcd(b, a%b) : a;
}

lli lcm(lli a, lli b)
{
  return (a/gcd(a,b)*b);
}

int main()
{
  lli a, b;

  while(cin>>a>>b){cout << gcd(a, b) << " " << lcm(a, b) << endl;}

  return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
	int m,f,r;
	cin>> m >> f >> r;
	if(m == -1 && f == -1 && r == -1) break;
	string ans;
	if(m == -1 || f == -1) ans = "F";
	else if(m + f >= 80) ans = "A";
	else if(m + f >= 65) ans = "B";
	else if(m + f >= 50) ans = "C";
	else if(m + f >= 30) {
	  if(r >= 50) ans = "C";
	  else ans = "D";
	}
	else ans = "F";
	  cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3164
A, B, K = map(int, input().split())

# A, B, K = [8, 12, 2]
# A, B, K = [100, 50, 4]
# A, B, K = [1, 1, 1]

ans = [1]

for i in range(2, min(A, B)+1):
    if (A % i == 0) and (B % i == 0):
        ans.append(i)

print(ans[-K])

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

int main()
{
  int N;
  cin >> N;
  // string w;
  map<string,int> mp;
  rep(i,N) {
    string w;
    cin >> w;
    sort(w.begin(),w.end());
    mp[w]++;
  }
  ll ans=0;
  for(auto& p : mp){
    int count = p.second;
    ans +=(ll)  count * (count-1) /2;
 // ans +=(ll) (count * (count-1))/2;  //WAになる
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 11136
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

T lcm(T)(T a, T b) {
    return a * (b / gcd(a, b));
}

// 区間 [a, b] で c でも d でも割り切れない数の個数を求める
long calc(long a, long b, long c, long d) {
    // 区間 [1, n] で x で割り切れる数の個数
    long f(long n, long x) {
        return n / x;
    }

    // 区間 [1, n] で x or y で割り切れる数の個数
    long g(long n, long x, long y) {
        return f(n, x) + f(n, y) - f(n, lcm(x, y));
    }

    // 区間 [1, n] で x or y で割り切れない数の個数
    long h(long n, long x, long y) {
        return n - g(n, x, y);
    }

    return h(b, c, d) - h(a - 1, c, d);
}

long calc2(long a, long b, long c, long d) {
    long f(long n) {
        return n - n/c - n/d + n/lcm(c, d);
    }

    return f(b) - f(a - 1);
}

void main() {
    long a, b, c, d; scan(a, b, c, d);
    writeln(calc2(a, b, c, d));
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef int64_t Int;
typedef std::vector<Int> LI;
typedef std::queue<Int> QI;
#define rep(i,n) for(Int i = 0; i < (Int)n; ++i)
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   template<typename T> std::vector<T> swapRange(const std::vector<T>& xs, Int part) {
      std::vector<T> res;
      for(Int i = part; i < (Int)xs.size(); ++i) {
         res.push_back(xs[i]);
      }
      for(Int i = 0; i < part; ++i) {
         res.push_back(xs[i]);
      }
      return res;
   }
   void solve() {
      Int n; scan(n);
      LI xs(n); scan(xs);
      LI ys(112345, 0);
      for(Int x : xs) {
         ys[x-1  +1] += 1;
         ys[x+1+1+1] -= 1;
      }
      Int t = 0;
      Int res = 0;
      for(Int i = 0; i < 112345; ++i) {
         t += ys[i];
         res = std::max(res, t);
      }
      printf("%ld\n", res);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ

int main(){
    int64_t x,y;
    cin>>x>>y;
    if(x==0){
        if(y>=0){
            cout<<y-x<<endl;
        }
        else{
            cout<<-y+1<<endl;
        }
    }
    else if(y==0){
        if(x>=0){
            cout<<x+1<<endl;
        }
        else{
            cout<<-x<<endl;
        }
    }
    else if(x*y>0){
        if(x>y){
            cout<<2+x-y<<endl;
        }
        else{
            cout<<y-x<<endl;
        }
    }
    else if(x>0){
        if(x<=abs(y)){
            cout<<abs(y)-x+1<<endl;
        }
        else{
            cout<<1+x+y<<endl;
        }
    }
    else{
        if(abs(x)<y){
            cout<<1+y-abs(x)<<endl;
        }
        else{
            cout<<1+abs(x)-y<<endl;
        }
    }
}

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

int main()
{
	int n; char s[110];
	cin>>n;
	scanf("%s",s+1);
	int r=0,b=0;
	for (int i=1;i<=n;i++) 
		if (s[i]=='R') r++; else b++;
	if (r>b) puts("Yes"); else puts("No");
	return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
V = LIST()
R = min(N, K)

max_ = 0
for A in range(R+1):
	for B in range(R+1):
		if A+B > R:
			continue
		if B == 0:
			lis = V[:A]
		else:
			lis = V[:A] +  V[-B:]
		# print(A, B)
		# print(lis)
		lis.sort()
		for i in range(K-(A+B)):
			if lis and lis[0] < 0:
				lis.pop(0)
		tmp = sum(lis)
		max_ = max(max_, tmp)
print(max_)


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


int main() {
  int N; cin >> N;
  int A = N;
  int S;

  while(A != 0) {
    S += A%10;
    A /= 10;
  }

  if(N%S == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {IoSetup() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout <<fixed<<setprecision(12);
    cerr <<fixed<<setprecision(12);
}}IoSetup;
constexpr int INF = 0x3f3f3f3f;

vector<int> e[200200];
int a[200200];
int ans[200200];

void dfs(int v, vector<int>&arr) {
    
    auto p = lower_bound(ALL(arr), a[v]);
    
    int pre = *p;
    *p = a[v];

    ans[v] = lower_bound(ALL(arr), INF) - arr.begin();
    
    for(auto&&u:e[v]) {
        if(!ans[u]) 
            dfs(u, arr);
    }
    *p = pre;
    
}        

signed main() {

    int n;
    cin >> n;
    
    for(int i = 1; i <= n; i++)
        cin >> a[i];

    int x, y;
    for(int i = 0; i < n-1; i++) {
        cin >> x >> y;
        e[x].bash(y);
        e[y].bash(x);
    }

    vector<int> arr(n+1, INF);
    dfs(1, arr);

    for(int i = 1; i <= n; i++) {
        cout << ans[i] << endl;
    }

  
    return 0;
}



Measured memory_bytes: 27904