akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#if ONLINE_JUDGE
    #define DEBUG false
#else
    #define DEBUG true
#endif
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define rrep(i, n) rREP(i, 0, n)
#define forlist(i, vec) for(auto &&i : vec)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) cerr << #x << ": " << (x) << endl
using namespace std;
typedef long long LL;
typedef long long int64;
typedef std::vector<int> VI;
typedef std::vector<VI> VVI;
typedef std::vector<LL> VL;
typedef std::vector<VL> VVL;
typedef std::vector<std::string> VS;
typedef std::pair<int, int> PII;
typedef std::pair<LL, LL> PLL;
typedef std::queue<int> QI;
typedef std::priority_queue<int> PQI;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>inline void vcinpb(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}
template<class T>inline void dumpv(T &v){
    if(!DEBUG)return;cout<<"{";rep(i,v.size()){cout<<v[i]<<",";}cout<<"}"<<endl;
}

const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;
// M_PI 3.1415...

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cill(n);
    VL v(n+10), ph(201000), mh(201000), idxes;
    LL ans = 0;
    rep(i, n){
        cin >> v[i];
    }
    rep(i, n){
        if(i+1 + v[i] < 200900){
            ph[ i+1 + v[i] ]++;
            if (ph[ i+1 + v[i] ] == 1){
                idxes.pb(i+1 + v[i]);
            }
        }
        if(i+1 - v[i] > 0){
            mh[ i+1 - v[i] ]++;
            if (mh[ i+1 - v[i] ] == 1){
                idxes.pb(i+1 - v[i]);
            }
        }

    }
    SORT(idxes);
    idxes.erase(unique(all(idxes)), idxes.end());
    for(auto&& i : idxes){
        ans += ph[i] * mh[i];
    }
    co(ans);
    return 0;
}

Measured memory_bytes: 10016
#include<bits/stdc++.h>
using namespace std;
char str[1<<20];
int f[21][1<<20];
int nex[21][1<<20];
int main(){
//	freopen("F.in","r",stdin);
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<=n;i++){
		scanf("%s",str);
		for(int j=0;j<(1<<i);j++)
			f[i][j]=str[j]-'0';
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<(1<<i);j++){
			int x=j>>(i-1)&1,p;
			for(p=i-1;p>=0&&(j>>p&1)==x;p--);
			nex[i][j]=p;
		}
	}
	int ans1=0,ans2=0;
	for(int i=0;i<=n;i++){
		for(int j=1;i+j<=n;j++){
			for(int k=0;k<(1<<(i+j));k++){
				f[i][k>>j]+=f[i+j][k];
				int d=nex[j][k&((1<<j)-1)];
				if(d!=-1){
					f[i+d+1][(k&((1<<(d+1))-1))|((k>>j)<<(d+1))]+=f[i+j][k];
				}
			}
		}
		for(int k=(1<<i)-1;k>=0;k--)
			if(f[i][k]>=m)
				ans1=i,ans2=k;
	}
	for(int i=ans1-1;i>=0;i--)
		printf("%d",ans2>>i&1);
	return 0;
}


Measured memory_bytes: 93440
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
using namespace std;

typedef pair <int, int> pii;
typedef pair <int, pii> ppi;

const int MAX_N = 2e3 + 6, MOD = 1e9 + 7;
int n, k;
int cnt;
int choose[MAX_N][MAX_N];

int _sum (int a, int b) {
	int c = a + b;
	if (MOD <= c)
		c -= MOD;

	return c;
}

int _mul (int a, int b) {
	int c = 1LL * a * b % MOD;
	return c;
}

int main() {
	choose[0][0] = 1;
	for (int i = 1; i < MAX_N; i++) {
		choose[0][i] = 1;
		for (int j = 1; j <= i; j++)
			choose[j][i] = _sum(choose[j][i - 1], choose[j - 1][i - 1]);
	}
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= k; i++)
		cout << _mul(choose[i - 1][k - 1], choose[i][n - k + 1]) << "\n";
	return 0;
}

Measured memory_bytes: 15360
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
12 5 22
100 3 7 5 3 1 3 7 5 3 1 12
164 3 7 5 3 1 3 7 5 3 1 12
100 3 7 5 3 1 3 7 5 3 1 12
164 3 7 5 3 1 3 7 5 3 1 12
100 3 7 5 3 1 3 7 5 3 1 12
164 3 7 5 3 1 3 7 5 3 1 12
100 3 7 5 3 1 3 7 5 3 1 12
164 3 7 5 3 1 3 7 5 3 1 12
100 3 7 5 3 1 3 7 5 3 1 12
164 3 7 5 3 1 3 7 5 3 1 12
100 3 7 5 3 1 3 7 5 3 1 12
164 3 7 5 3 1 3 7 5 3 1 12
'''

def solve(l,n,m,x):
	totPossible = defaultdict(int)
	for j in range(1,m+1):
		for i in range(n):
			totPossible[j] += l[i][j]
	for i in totPossible:
		if(totPossible[i] < x):
			return -1
	combs = []
	for i in range(1,n+1):
		ll = [i for i in range(n)]
		c = list(combinations(ll,i))
		combs.append(c)
	minn = maxsize
	ccc = []
	for i in combs:
		for j in i:
			ccc.append(j)

	for c in ccc:
		ll = [0]*m
		bought = [0]*n
		curr = 0
		for i in c:
			bought[i] = 1
		for i in range(n):
			if(bought[i]):
				for j in range(1,m+1):
					ll[j-1] += l[i][j]
		f = 1
		for i in range(len(ll)):
			if(ll[i] < x):
				f = 0
				break
		if(f):
			for i in range(n):
				if(bought[i]):
					curr += l[i][0]
			minn = min(minn,curr)
	return minn
	

N,M,X = list(map(int, stdin.readline().rstrip().split()))
L = []
for i in range(N):
	l = list(map(int, stdin.readline().rstrip().split()))
	L.append(l)
ans = solve(L,N,M,X)
print(ans)



Measured memory_bytes: 78820
#include<bits/stdc++.h>
#define MAX 100005
using namespace std;
 
int n, a[MAX], b, ans = 0;

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &b);
    a[b]++;
  }
  for(int i = 0; i < MAX-2; i++){
    ans = max(ans, a[i]+a[i+1]+a[i+2]);
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const ll INF = 10e16;
const int maxN = 100010;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 1000000007;

char a[maxD];
int main()
{
	scanf("%s",a+1);
	int x = a[1] - 48;
	int y = a[2] - 48;
	if(x==9 || y==9)
		puts("Yes");
	else
		puts("No");
	return 0;
}  

Measured memory_bytes: 256
n,k=map(int,input().split())
s=input()+"."
a,b=[1],1
for i in range(1,n):
  if s[i-1]==s[i]:a[-1]+=1
  else:a.append(1)
s=0
for i in a:s+=max(i,1)-1
l=len(a)
for i in range(k):
  if l==1:break
  if l==2:s+=1;break
  l-=2
  s+=2
print(s)

Measured memory_bytes: 3956
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
    int N, M;
    if (scanf("%d%d", &N, &M) < 2) return 0;

    vector<int> num;
    vector<bool> red;

    for (int i = 0; i < N; i++)
    {
        num.push_back(1);
        red.push_back(false);
    }

    red[0] = true;

    for (int i = 0; i < M; i++)
    {
        int x, y;
        if (scanf("%d%d", &x, &y) < 2) return 0;
        if (red[x - 1]) red[y - 1] = true;
        num[x - 1]--;
        num[y - 1]++;
        if (!num[x - 1]) red[x - 1] = false;
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (red[i]) ans++;
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 892
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;
int main(){
	map<string,int> mp;
	set<string> st;
	int n,m,max=0;
	string s[110],t[110];
	cin>>n;
	REP(i,n){
		cin>>s[i];
		st.insert(s[i]);
	}
	cin>>m;
	REP(i,m){
		cin>>t[i];
		st.insert(t[i]);
	}
	for(auto x:st){
		mp[x]=0;
	}
	REP(i,n){
		mp[s[i]]++;
	}
	REP(i,m){
		mp[t[i]]--;
	}
	for(auto x:mp){
		if(x.second>max){
			max=x.second;
		}
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
# obs = []
H = [int(i) for i in input().split()]
H = [0] + H
bgs = [[] for _ in range(N+1)]
for _ in range(M):
    A, B = map(int, input().split())
    bgs[A].append(B)
    bgs[B].append(A)

# print(H)
# print(bgs)

ans = 0
for i, bg in enumerate(bgs):
    if i == 0:
        continue
    flag = True
    for ob in bg:
        if H[i] <= H[ob]:
            flag = False
            break
    if flag or len(bg) == 0:
        # print(i)
        ans += 1

print(ans)


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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    string S;
    cin >> S;
    int ans = INF;
    rep(i,26) {
        char x = 'a' + i;
        string T = S;
        bool c = true;
        rep(j,T.size()) {
            if (T[j]!=x){
                c = false;
            }
        }
        if (c){
            ans = 0;
            break;
        }
        else {
            int tmp = 0;
            while(1) {
                bool b = true;
                tmp++;
                rep(j,T.size()-1) {
                    if (T[j+1]==x) {
                        T[j] = x;
                    }
                    else if (T[j]==x) {
                        continue;
                    }
                    else {
                        b = false;
                    }
                }
                if (b) {
                    ans = min(ans,tmp);
                    break;
                }
                T.pop_back();

            }
        }

    }
    cout << ans << endl;
}


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

using namespace std;

int main()
{
  string s, t, u;
  int a, b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;

  if (u == s)
  {
    a--;
  } else
  {
    b--;
  }

  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


pair<int, int> a[200000];
bool f(int i, int j) {
    return a[i + 1].first - a[i].first == a[j + 1].first - a[j].first ? i < j : a[i + 1].first - a[i].first > a[j + 1].first - a[j].first;
}

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



    ll n;
    cin >> n;
    cout << (n - 1) / 2;


}

//20
//668 684 759 389 948 900 70 733 713 903 940 207 297 687 512 891 498 2 564 465

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

int main()
{
    int a,b,k;
    cin>>a>>b>>k;
    int memo;
    for(int i=a;i<a+k;i++){
      if(i>b){
        break;
      }
      cout<<i<<endl;
    }
    memo=a+k;
    for(int i=b-k+1;i<b+1;i++){
        if(i>=memo){
            cout<<i<<endl;

        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

int N, M;
vector<int> length, parent;

int calcLength(const vector<vector<int>> &edges_rev, int current)
{
  if (length[current] != -1)
    return length[current];
  int longest = -1;
  for (const int &fr : edges_rev[current])
  {
    int len = calcLength(edges_rev, fr) + 1;
    if (longest < len)
    {
      longest = len;
      parent[current] = fr;
      length[current] = longest;
    }
  }
  return longest;
}

int main(int argc, char const *argv[])
{
  cin >> N >> M;
  parent.resize(N + 1, -1);
  length.resize(N + 1, -1);
  vector<vector<int>> edges(N + 1);
  vector<vector<int>> edges_rev(N + 1);
  for (int i = 0, l = N + M - 1; i < l; ++i)
  {
    int fr, to;
    cin >> fr >> to;
    edges[fr].push_back(to);
    edges_rev[to].push_back(fr);
  }

  int root;
  for (int to = 1; to <= N; ++to)
  {
    auto &fr = edges_rev[to];
    if (fr.size() == 0)
    {
      root = to;
      break;
    }
  }

  parent[root] = 0;
  length[root] = 0;
  for (int i = 1; i <= N; ++i)
  {
    calcLength(edges_rev, i);
  }

  for (int i = 1; i <= N; ++i)
  {
    cout << parent[i] << '\n';
  }
  cout.flush();
}


Measured memory_bytes: 15488
n=int(input())  
li,L=[],[]
for i in range(n):
    a,b=map(int, input().split())  
    li.append([a,b])

for i in range(n):
    for j in range(n):
        L.append(((li[i][0]-li[j][0])**2 + (li[i][1]-li[j][1])**2)**0.5)
    
print(sum(L)/n)

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

int main() {
	int n, m, p;
	while (cin >> n >> m >> p) {
		if (n == 0 && m == 0 && p == 0)break;

		int a = 0;
		int w;
		for (int i = 0;i < n;i++) {
			int b;
			cin >> b;
			a += b;
			if (i + 1 == m)w = b;
		}

		a *= 100;
		a = a*(100 - p) / 100;

		if (w == 0)cout << '0' << endl;
		else cout << a / w << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
n,d=map(int,input().split())
lis=[]
for i in range(0,n):
  lis.append(list(map(int,input().split())))

count=0
for j in range(0,n-1):
  for k in range(j+1,n):
    dist=0
    for l in range(0,d):
      dist+=(lis[j][l]-lis[k][l])**2
    if (dist**(1/2))%1==0:
      count+=1
print(count)

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

#define ll long long

using namespace std;

string s;
int maxim;
int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    for (int i=0; i<s.size(); i++){
        int j=i;
        int nr=0;
        while ((s[j]=='A' || s[j]=='C' || s[j]=='G' || s[j]=='T') && j<s.size()){
            nr++;
            j++;
        }
        if (nr>maxim) maxim=nr;
    }
    cout<<maxim;
    
    
    return 0;
}

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

typedef long long int ll;

int main(){

ll n, count = 0;
string number;

cin >> number;

n = stoi(number);


for (auto el : number)
    count += (el - 48);

if(n%count == 0) cout << "Yes" << endl;
else cout << "No" << endl;




    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
void solve()
{
    int s,w;
    cin>>s>>w;
    if(w>=s) puts("unsafe");
    else puts("safe");
}
int main()
{
	//int _;cin>>_;while(_--)
	solve();
}


Measured memory_bytes: 3592
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_I(): return map(int, stdin)
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))

##### main #####



def main():
	x,y = LI()

	ans=0
	while x<=y:
		x*=2
		ans+=1
		
	print(ans)

if __name__ == '__main__':
	main()

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

using namespace std;

#define MAX2 48
#define MAX5 24
#define MAX 200005
#define ll long long

ll cnt2[MAX], cnt5[MAX], decimal[MAX];
ll cnt[10][MAX2][MAX5];

void add(ll id)
{
    ll x = decimal[id];
    for(int i=0; i<=cnt2[id]; i++){
        for(int j=0; j<=cnt5[id]; j++){
            cnt[x][i][j]++;
        }
    }
}

void dlt(ll id)
{
    ll x = decimal[id];
    for(int i=0; i<=cnt2[id]; i++){
        for(int j=0; j<=cnt5[id]; j++){
            cnt[x][i][j]--;
        }
    }
}

ll query(ll id)
{
    ll hasTwo = cnt2[id];
    ll hasFive = cnt5[id];
    ll hasDec = decimal[id];
    ll ans = 0;
    for(int k=0; k<=9; k++){
        ll totDec = k+hasDec;
        ll needTwo = max(totDec-hasTwo, 0LL);
        ll needFive = max(totDec-hasFive, 0LL);
        //cout << k << " " << needTwo << " " << needFive << endl;
        ans += cnt[k][needTwo][needFive];
    }
    return ans;
}

void gen(ll id, string str)
{
    bool foundDot = false;
    int cnt = 0;
    ll nows = 0;
    for(int i=0; i<str.length(); i++){
        if(str[i] == '.'){
            foundDot = true;
            continue;
        }
        if(foundDot) ++cnt;
        ll digit = str[i]-'0';
        nows = nows*10 + digit;
    }
    decimal[id] = cnt;
    while(nows%2 == 0){
        nows = nows/2;
        cnt2[id]++;
    }
    while(nows%5 == 0){
        nows = nows/5;
        cnt5[id]++;
    }
}

int main()
{
    memset(cnt2, 0, sizeof cnt2);
    memset(cnt5, 0, sizeof cnt5);
    memset(decimal, 0, sizeof decimal);
    memset(cnt, 0, sizeof cnt);
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        string str;
        cin >> str;
        gen(i, str);
        add(i);
    }
    ll ans = 0;
    for(int i=0; i<n; i++){
        dlt(i);
        ans += query(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8468
import java.util.Arrays;
import java.util.Scanner;

public class Main{
    static int binarySearch(long Y , long A[]){
        int N = A.length;
        if(A[N - 1] < Y){
            return N;
        }
        if(A[0] >= Y){
            return 0;
        }
        int low = 0; // false
        int high = N - 1; // true
        while(low < high - 1){
            int mid = (low + high) / 2;
            if(A[mid] >= Y){
                high = mid;
            }else{
                low =  mid;
            }
        }
        return high;
    }
    // 幸福度X以上の握手の数
    static long numberOfHandshake(long X , long A[] ){
        int N = A.length;
        long ret = 0;
        for(int i = 0 ; i < N ; ++i){
            ret += N - binarySearch(X - A[i], A);
        }
        return ret;
    }
    static long totalHappiness(long X , long A[]){
        int N = A.length;
        long S[] = new long[N + 1];
        for(int i = 0 ; i < N ; ++i){
            S[i + 1] = S[i] + A[i];
        }
        long ret = 0;
        for(int i = 0 ; i < N ; ++i){
            int idx = binarySearch(X - A[i], A);
            ret += S[N] - S[idx] + (N - idx) * A[i];
        }
        return ret;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long M = sc.nextLong();
        long A[] = new long[N];
        for(int i = 0 ; i < N ; ++i){
            A[i] = sc.nextLong();
        }
        sc.close();
        Arrays.sort(A);
        long low = 0; // ?
        long high = A[N - 1] * 2 + 1; // true
        while(low < high){
            long mid = (low + high) / 2;
            long c = numberOfHandshake(mid , A);
            if(c <= M){
                high = mid;
            }else{
                low = mid + 1;
            }
        }
        long c = numberOfHandshake(low, A);
        long h = totalHappiness(low, A);
        if(c != M){
            h += (low - 1) * (M - c);
        }
        System.out.println(h);
    }
}


Measured memory_bytes: 58860
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c[3],d;
    cin>>a>>b;
    c[0]=a*b;
    c[1]=a+b;
    c[2]=a-b;
    sort(c,c+3);
    cout<<c[2]<<endl;


}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define pll pair<ll,ll>
const int mod = 1e9 + 7;
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int n,H[100101],dp[101010];
int main(){
    ios::sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++)cin>>H[i];
    for(int i = n-1;i>=1;i--)
        dp[i] = min(dp[i+1]+abs(H[i]-H[i+1]) , (i+2<=n?dp[i+2]+abs(H[i]-H[i+2]):(int)1e9));
    cout << dp[1] << endl;
    return 0;
}


Measured memory_bytes: 1024
A, B, C, D = map(int, input().split())
x = 0
while A > 0 and C > 0:
    if x % 2 == 0:
        C -= B
        x += 1
    else:
        A -= D
        x += 1
if C <= 0:
    print('Yes')
else:
    print('No')


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

using namespace std;

typedef long long ll;
typedef long double ld;

int niz[1000005];

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
    }
    sort(niz+1, niz+1+n);
    int x = niz[1];
    for(int i=2; i<n; i++){
        if(abs(1.0*niz[n]/2-x) > abs(1.0*niz[n]/2-niz[i])) x = niz[i];
    }
    cout << niz[n] << " " << x;
    return 0;
}


Measured memory_bytes: 640
s = gets
t = gets

min = t.size

(s.size - t.size + 1).times do |i|
  a = s.slice(i, t.size - 1).chars
  b = t.chars
  count = 0

  a.zip(b).each do |c, d|
    count += 1 if c != d
  end

  min = count if min > count
end

puts min


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

int main() {
    char C;
    cin >> C;
    if(C == 'a' || C == 'i' || C == 'u' || C == 'e' || C == 'o'){
        cout << "vowel\n";
    }
    else {
        cout << "consonant\n";
    }
}


Measured memory_bytes: 256
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;


signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int r;
	cin >> r;
	cout << r * r * 3 << '\n';
	return 0;
}


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

int main() {
	int N,M,s,x;
	char c;
	cin >> N >> M;
	vector<char> t(N,'0');
	string r="";
	set<int> y;

	rep(i,M) {
		cin >> s >> c;
		if(y.count(s) && t.at(s-1)!=c) {
			cout << -1 << endl;
			return 0;
		}
		y.insert(s);
		t.at(s-1) = c;
	}


	rep(i,N)
		r += t.at(i);
	if(r.at(0)=='0') {
		if(N==1) {
			cout << 0 << endl;
			return 0;
		}
		
		if(y.count(1)) {
			cout << -1 << endl;
			return 0;
		} else {
			r.at(0) = '1';
		}
	}

	cout << r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
   
using namespace std;
     
#define PB(x) push_back(x)
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define MP(x) make_pair(x);
    
#define debug(x) cerr << #x << '=' << x << endl;
#define debug2(x, y) cerr << #x << '=' << x << ' ' << #y << '=' << y << endl;
#define debugn(a) for (int x: a) cerr << x << ' '; cerr << endl;
#define debugm(a, n, m) for (int i = 0; i < n; i++, cout << endl)           \
						for (int j = 0; j < m; j++) cout << a[i][j] << ' ';

#define int long long
     
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef vector<string> vs;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX;
const int NINF = LONG_LONG_MIN;
const int mmod = 1000000007;

int32_t main()
{
	int a;
	cin >> a;
	string s;
	cin >> s;
	if (a < 3200) {
		
		cout << "red" << endl;
	} else {
		cout << s << endl;
	}
}


Measured memory_bytes: 256
#pragma region noncode
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#pragma endregion

int main() {
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];

    ll ans = 0;
    ll ma = 0;
    rep(i, n) {
        if(ma <= h[i]) {
            ans++;
            ma = h[i];
        }
    }
    cout << ans << endl;
}


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

int sum_(vector<int> vec){
  int su = 0;
  for(int v : vec){
    su+=v;
  }
  return su;
}
 
int main(){
  int N;
  cin >> N;
  vector<int> B(N-1);
  
  for(int i; i<N-1; i++){
    cin >> B.at(i);
  }
  
  vector<int> A(N);
  
  for(int i ; i<N; i++){
    if(i==0){
      A.at(i)=B.at(i);
    }else if(i==N-1){
      A.at(i)=B.at(i-1);
    }else{
      A.at(i)=min(B.at(i-1),B.at(i));
    }
    
    
  }
  
  cout << sum_(A) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;


int main(void){
  int k;

  cin>>k;

  if(k%2==0)std::cout<<(k/2)*(k/2)<<std::endl;
  else std::cout<<(k/2+1)*(k/2)<<std::endl;

  return 0;
}

Measured memory_bytes: 256
from collections import deque
n, m = map(int, input().split())
g = [[] for _ in range(n + 1)]
q = deque([])
visited = set()
dist = [None] * (n + 1)

for i in range(m):
    a, b, k = map(int, input().split())
    g[a].append((b, k))
    g[b].append((a, -k))

def dfs(u):
    q.append(u)
    while q:
        v = q.pop()
        visited.add(v)
        for x, d in g[v]:
            if x not in visited:
                if dist[x] is None:
                    dist[x] = dist[v] + d
                elif dist[x] != dist[v] + d:
                    return False
                q.append(x)
    return True

for i in range(1, n + 1):
    if i not in visited:
        dist[i] = 1
        if not dfs(i):
            print("No")
            exit()
print("Yes")


Measured memory_bytes: 76512
import math
a, b, h, m = map(int, input().split())

x = h * 30
tmp = max(6 * m, x + m * 0.5) - min(6 * m, x + m * 0.5)
if tmp > 180:
    tmp = 360 - tmp
print((a ** 2 + b ** 2 - 2 * a * b * math.cos(tmp * (math.pi / 180))) ** 0.5)

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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int g[3][3];
    rep (i, 3) rep (j, 3) cin >> g[i][j];
    vector<int> a(3), b(3);
    rep (i, 3) b[i] = g[0][i] - a[0];
    rep (i, 3) a[i] = g[i][0] - b[0];
    rep (i, 3) {
        rep (j, 3) {
            if (a[i] + b[j] != g[i][j]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    
    return 0;
}



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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

const int charnum = 2;
const char firstchar = '0';

class Trie {
public:
	Trie *next[charnum];

	Trie() {
		fill(next, next + charnum, (Trie *)NULL);
	}

	/*
	void insert(char *s) {
		if (*s == '\0') return;
		if (this->next[*s - 'a'] == NULL)
			this->next[*s - 'a'] = new Trie();
		this->next[*s - 'a']->insert(s + 1);
	}
	*/
	void insert(string s) {
		Trie* now = this;
		for (int i = 0; i < s.size(); i++) {
			if (now->next[s[i] - firstchar] == NULL) {
				now->next[s[i] - firstchar] = new Trie();
			}
			now = now->next[s[i] - firstchar];
		}
	}

	/*
	bool find(char *s) {
		if (*s == '\0') return true;
		if (this->next[*s - 'a'] == NULL)
			return false;
		return this->next[*s - 'a']->find(s + 1);
	}
	*/
	bool find(string s) {
		Trie* now = this;
		for (int i = 0; i < s.size(); i++) {
			if (now->next[s[i] - firstchar] == NULL)
				return false;
			now = now->next[s[i] - firstchar];
		}
		return true;
	}
};

ll n, l;
ll grundy = 0;

void dfs(Trie* now, ll d) {
	if (now->next[0] == NULL && now->next[1] == NULL) {
		return;
	}
	else if (now->next[0] != NULL && now->next[1] != NULL) {
		dfs(now->next[0], d + 1);
		dfs(now->next[1], d + 1);
		return;
	}
	else if (now->next[0] == NULL) {
		grundy ^= (l - d) & (-l + d);
		dfs(now->next[1], d + 1);
		return;
	}
	else {
		grundy ^= (l - d) & (-l + d);
		dfs(now->next[0], d + 1);
		return;
	}
}


int main() {
	cin >> n >> l;
	int i, j;
	Trie* t = new Trie();
	for (i = 0; i < n; i++) {
		string s;
		cin >> s;
		t->insert(s);
	}
	dfs(t, 0LL);
	if (grundy == 0) {
		cout << "Bob" << endl;
	}
	else {
		cout << "Alice" << endl;
	}
}

Measured memory_bytes: 3584
N,x=map(int,input().split())
A=list(map(int,input().split()))

sumA=[A[i]+A[i+1] for i in range(N-1)]

count=0
for i in range(N-1):
    if A[i]+A[i+1]>x:
        count+=A[i]+A[i+1]-x
        A[i+1]-=A[i]+A[i+1]-x
        if A[i+1]<0:
            A[i]+=A[i+1]
            A[i+1]=0
print(count)


Measured memory_bytes: 14468
import java.util.*;
import java.io.*;
import java.math.*;

public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String a = in.readLine();
    String s = a.substring(0, a.length()-1);
    int n = s.length() % 2;
    for(int i=s.length();i>=0;i--){
      String sub = s.substring(0, i-n);
      if(sub.substring(0,sub.length()/2).equals(sub.substring(sub.length()/2,sub.length()))){
        System.out.println(sub.length());
        return;
      }
    }
  }
}


Measured memory_bytes: 22996
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
string IntToString(int);
int StringToInt(string);

vector<string> split(string str,string delim){
  vector<string> items;
  size_t dlm_idx;
  if(str.npos == (dlm_idx = str.find_first_of(delim))){
    items.push_back(str.substr(0,dlm_idx));
  }
  while(str.npos != (dlm_idx = str.find_first_of(delim))){
    if(str.npos == str.find_first_not_of(delim)){
      break;
    }
    items.push_back(str.substr(0,dlm_idx));
    dlm_idx++;
    str = str.erase(0,dlm_idx);
    if(str.npos == str.find_first_of(delim) && "" != str){
      items.push_back(str);
      break;
    }
  }
  return items;
}
void fill(vector<int> &a,int s,int l){
  for(int i = s;i < l;i++){
    a[i]++;
  }
}
int make_time(vector<string> &a){
  int time = 0;
  time = StringToInt(a[0])*60*60+StringToInt(a[1])*60+StringToInt(a[2]);
  return time;
}
int main(){
  while(1){
    int n;
    cin >> n;
    if(n == 0)break;
    vector<int> zone(60*60*24+1,0);
    for(int i = 0;i < n;i++){
      string tmp;
      cin >> tmp;
      vector<string> from = split(tmp,":");
      cin >> tmp;
      vector<string> to = split(tmp,":");
      fill(zone,make_time(from),make_time(to));
    }
    int ans = 0;
    for(int i = 0;i < 60*60*24+1;i++){
      ans = max(zone[i],ans);
    }
    cout << ans << endl;
      
    
  }
  return 0;
}
string IntToString(int number){
  stringstream ss;
  ss << number;
  return ss.str();
}
int StringToInt(string number){
  stringstream ss;
  ss << number;
  int numInt;
  ss >> numInt;
  return numInt;
  
}

Measured memory_bytes: 1592
#include<bits/stdc++.h>
using namespace std;
    int n,m,l;
    int a[100005]={},u[100005]={},v[100005]={};
    long long ans;
    long long f[100005]={};
void qs(int l,int r)
{
    int i=l,j=r;
    int x=a[(l+r)/2];
    do
    {
        while (a[i]<x) i++;
        while (a[j]>x) j--;
        if (i<=j)
        {
            swap(a[i],a[j]);
            swap(v[i],v[j]);
            i++;j--;
        }
    }while (i<=j);
    if (l<j) qs(l,j);
    if (i<r) qs(i,r);
}
int main()
{
    cin >> n >> m;

        memset(f,0,sizeof(f));
        memset(a,0,sizeof(a));
        memset(u,0,sizeof(u));
        memset(v,0,sizeof(v));
        for (int i=1;i<=n;i++)
        {
            scanf("%d%d",&a[i],&v[i]);
        }
        qs(1,n);
        u[0]=1;
        l=0;
        for (int i=1;i<=n;i++)
        {
            for (int j=l;j>=0;j--)
            {
                if ((u[j]==1)&&(a[i]+j<=m))
                {
                    u[j+a[i]]=1;
                    l=max(l,j+a[i]);
                    f[j+a[i]]=max(f[j+a[i]],f[j]+v[i]);
                }
            }
        }
        ans=0;
        for (int i=m;i>=0;i--)
            if (f[i]>ans) ans=f[i];
        cout << ans << endl;

}


Measured memory_bytes: 5624
#include<iostream>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define MAX 100000
#define INF 1000000001

int a[MAX];
int l[MAX];
int main()
{
	int n;
	cin >> n;
	REP(i, n)
	{
		cin >> a[i];
		l[i] = INF;
	}
	int length = 0;
	l[length] = a[0];
	length++;
	FOR(i, 1, n)
	{
		if (l[length-1] < a[i])
		{
			l[length] = a[i];
			length++;
		}
		else
		{
			REP(j, length)
			{
				if (j == 0 && l[0] > a[i])
				{
					l[0] = a[i];
					break;
				}
				else if (l[j] < a[i]&&l[j+1]>a[i])
				{
					l[j+1] = a[i];
					break;
				}
			}
		}
	}
	cout << length << endl;

	return 0;
}

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

#define f first
#define s second
#define lc (rt<<1)
#define rc (rt<<1|1)
#define mp make_pair
#define pb push_back
#define lowbit(a) (a&(-a))
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define mst(a,v) memset(a,v,sizeof(a))
#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

const int N=100010;
const int mod=1e9+7;
const ld PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;

char s[10];

int main()
{
    IOS
    cin>>s;
    if(strlen(s)==2) cout<<s;
    else
    {
        reverse(s,s+3);
        cout<<s;
    }
    return 0;
}


Measured memory_bytes: 256
while True:
    calc = input().split()
    a = int(calc[0])
    b = int(calc[2])
    if calc[1] == "-":
        print (a - b)
    elif calc[1] == "+":
        print (a + b)
    elif calc[1] == "*":
        print (a * b)
    elif calc[1] == "/":
        print (a // b)
    else:
        break



Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,M ;
  cin>>N>>M;
  vector<pair<long long,long long>>AB(N);
  for(int i=0;i<N;i++)
    cin>>AB.at(i).first>>AB.at(i).second;
  sort(AB.begin(),AB.end());
  long long res=0;
  
  
  for(int i=0;i<N;i++){
    if(AB.at(i).second<M){
      res+=AB.at(i).first * AB.at(i).second;
      M-=AB.at(i).second;
    }
    else{
      res+=AB.at(i).first * M;
      break;
    }
  }
  cout<<res;
}

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

using namespace std;

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

#define int ll

int n;
int num[100001];

main(){
	cin >> n;
	for(int i=0;i<n;i++){
		int d;
		cin >> d;
		num[d]++;
		if(i==0 && d!=0){
			cout << 0 << endl;
			return 0;
		}
	}

	int sum = 0;
	int ans = 1;
	for(int i=0;i<=100000;i++){
		if(num[0]!=1) break;
		if(i!=0){
			for(int j=0;j<num[i];j++){
				ans *= num[i-1];
				ans %= 998244353;
			}
		}
		sum += num[i];
	}
	if(sum!=n) ans = 0;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4308
#include <stdio.h>
 
int main() {
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if(x >= r && y >= r && (H - r) >= y && (W - r) >= x) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 2092
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()

string s; int d;
int mod = 1e9 + 7;

void solution(){
	cin >> s >> d;
	int n = s.size(); // num of digits
	// state -- depends only on which position we are at, 
	// if we are on the edge of the given number K, and 
	// the sum we are looking for (also can be thought of 
	// as the remainder of the sum modulo d)
	// dp[i][on_edge][sum] -- number of ways to get 'sum' as sum of digits modulo d
	// upto ith digit, with 'on_edge' telling whether we are on edge of K or not
	// this is kind of state DP that is used in the buy and sell stock problems
	// we create transitions based on the states of the previous digit
	// there are two states, namely on_edge and not_on_edge
	// in the first case, upto the ith digit all other remaining digits have
	// been fixed to their respective values in the corresponding number k
	ll dp[n][2][d];
	memset(dp,0LL,sizeof(dp));
	for(int i = 0; i < (s[0]-'0'); i++) dp[0][0][i%d] += 1;
	dp[0][1][(s[0]-'0')%d] += 1;
	for(int i = 1; i < n; i++){
		int lim = s[i]-'0';
		for(int r = 0; r < d; r++){
			for(int cur = 0; cur < 10; cur++){
				int need = (r-cur%d+d)%d;
				assert(need >= 0 && need < d);
				if(cur < lim){
					dp[i][0][r] += dp[i-1][0][need] + dp[i-1][1][need];
				}
				else if(cur == lim){
					dp[i][1][r] += dp[i-1][1][need];
					dp[i][0][r] += dp[i-1][0][need];
				}
				else{
					dp[i][0][r] += dp[i-1][0][need];
				}
				dp[i][0][r] %= mod;
				dp[i][1][r] %= mod;
			}
		}
	}
	cout << (dp[n-1][0][0] + dp[n-1][1][0] - 1 + mod) % mod << endl;


	

	
}   


int main(){ 

	fio;
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}


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

using namespace std;

int main() {
  map<string, int> count;
  int n;
  cin >> n;
  string s;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    sort(s.begin(), s.end());
    count[s] += 1;
  }
  long long res = 0;
  for (auto& kv : count) {
    res += (1ll * kv.second * (kv.second - 1) / 2);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 11136
#include<iostream>
using namespace std;
int main()
{
   int n,s,t;
   cin>>n;
   if(n<=1000)
   {
       s=1000-n;
   }
   else
   {
       if(n%1000==0)
       {
           s=0;
       }
       else
       {
           t=(n/1000)+1;
           s=(t*1000)-n;
       }
   }
   cout<<s<<endl;
   return 0;



}


Measured memory_bytes: 3672
#include <iostream>

// A=3, B=5
// 高橋 ooo
// 青木 ooooo

// K=4
// 高橋 000 青木 0oooo

int main(int argc, char *argv[]) {
  long a, b, k;
  std::cin >> a >> b >> k;

  if (k <= a)
    std::cout << a - k << " " << b << std::endl;
  else if (k <= (a + b))
    std::cout << 0 << " " << b - (k - a) << std::endl;
  else
    std::cout << 0 << " " << 0 << std::endl;
}


Measured memory_bytes: 256
a1, b1 = map(int,input().split())
a2, b2 = map(int,input().split())
a3, b3 = map(int,input().split())
l = [a1, a2, a3, b1, b2, b3]
if (1 <= l.count(1) and l.count(1) < 3) and (1 <= l.count(2) and l.count(2) < 3) and (1 <= l.count(3) and l.count(3) < 3) and (1 <= l.count(4) and l.count(4) < 3):
    print("YES")
else:
    print("NO")

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

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

    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i = 2; i < n; ++i) {
        int cand1 = dp[i-2] + abs(h[i] - h[i-2]);
        int cand2 = dp[i-1] + abs(h[i] - h[i-1]);
        dp[i] = min(cand1, cand2);
    }

    cout << dp[n-1] << endl;
    
    return 0;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 


void solve(){
    int n;
    cin >> n;
    vector<int> v;
    for(int i = 0; i < n ;i++){
		int x;
		cin >> x;
		v.push_back(x);
   }
   int ans = v[0];
   for(auto it : v) ans = lcm(ans, it);
   cout << ans << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <queue>
#define REP(i,n) for(int i=0;i<n;i++)
struct edge{
    long long to, cost;
};

using namespace std;

//ダイクストラで多用する型
typedef pair<long long, int> P;//(その頂点までの距離,頂点)として使う。

vector<edge> G[100000];//頂点iから出る辺の配列G[i]の配列。
long long dist[100000];//特定の頂点から各頂点への距離が格納される。
bool used[100000];//dijkstra実行中に、頂点iまでの距離を確定したかどうかを持つ。

void dijkstra(int v){//vは始点。
    //以下のリンクでpriority_queueの使い方を参照
    //http://shirokurostone.hatenablog.com/entry/20110522/1306052844
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, v));
    while(!que.empty()){
        P top = que.top();
        que.pop();
        int u = top.second;
        long long d = top.first;
        //cout << u << ' ' << d << endl;
        if(used[u]) continue;
        dist[u] = d;
        used[u] = true;
        for(int i = 0; i < G[u].size(); i++){
            if(!used[G[u][i].to]){
                que.push(P(d+G[u][i].cost, G[u][i].to));
                //cout << G[u][i].to << ' ' <<  d+G[u][i].cost << endl;
            }
        }
    }
}

int main(){
  int N;
  cin >> N;
  int u,v,w;
  for(int i = 1; i < N; i++){
    cin>>u>>v>>w;
    u--;v--;
    G[u].push_back(edge{v, w});
    G[v].push_back(edge{u, w});
  }
  dijkstra(0);
  REP(i,N){
    if(dist[i]%2==0){
      cout<<0<<endl;
    }else{
      cout<<1<<endl;
    }
  }
  return 0;
}

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

int main() {
    string s;
    vector<int>cnt(26, 0);
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
        cnt[s[i] - 'a']++;
    }
    for (int i = 0; i < 26; i++) {
        if (cnt[i] % 2 == 1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define ll long long
#include<vector>
#include<set>
//vector<ll>adj[100001];
ll parent[100001];
ll tao[100001];
ll find(ll i) {
    if(parent[i]==i)
        return i;
    else
        return parent[i]=find(parent[i]);
}
void union_set(ll a,ll b) {
    ll x=find(a);
    ll y=find(b);
    if(tao[x]<tao[y])swap(x,y);
    parent[y]=x;
    if(tao[x]==tao[y])tao[x]++;

}
set<ll>s;
int main()
{
    ll n,m;
    cin>>n>>m;
    for(int i=1; i<=n; i++) {
        parent[i]=i;
        tao[i]=1;
    }
    while(m--) {
        ll l,r;
        cin>>l>>r;
        union_set(l,r);
    }
    for(int i=1; i<=n; i++)
        s.insert(find(i));
    cout<<s.size()-1<<endl;

    return 0;
}

Measured memory_bytes: 8808
#include "bits/stdc++.h"
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	string s;
	cin >> s;
	int a = count(s.begin(), s.end(), 'R');
	if (a != 2) cout << a;
	else cout << (s[1] == 'R' ? 2 : 1);
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint h, w, k;
llint a[3005][3005];
llint dp[3005][3005][4];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w >> k;
	llint x, y, v;
	for(int i = 1; i <= k; i++){
		cin >> y >> x >> v;
		a[x][y] += v;
	}
	
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			for(int i = 0; i <= 3; i++){
				dp[x][y][i] = -inf;
			}
		}
	}
	dp[1][1][0] = 0, dp[1][1][1] = a[1][1];
	
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			for(int i = 0; i <= 3; i++){
				if(x+1 <= w){
					chmax(dp[x+1][y][i], dp[x][y][i]);
					if(i+1 <= 3) chmax(dp[x+1][y][i+1], dp[x][y][i] + a[x+1][y]);
				}
				if(y+1 <= h){
					chmax(dp[x][y+1][0], dp[x][y][i]);
					chmax(dp[x][y+1][1], dp[x][y][i] + a[x][y+1]);
				}
			}
		}
	}
	llint ans = 0;
	for(int i = 0; i <= 3; i++) ans = max(ans, dp[w][h][i]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 355600