akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll n,na,ans=0;
  cin>>n;
  na=n;
  ll p=pow(n,0.5);
  vector<ll> a(1000000,0);
  for(ll i=2;i<=p;i++){
    while(na%i==0){
      na/=i;
      a[i]++;
    }
    ll j=1;
    while(a[i]>=0){
      a[i]-=j;
      j++;
      ans++;
    }ans--;
  }
  if(na!=1) ans++;
  if(n!=1&&ans==0) ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 11656
import sys

n,m,l=map(int,raw_input().split())
list1 = [[0 for i in range(m)]for i in range(n)]
list2 = [[0 for i in range(l)]for i in range(m)]
list3 = [[0 for i in range(l)]for i in range(n)]
for i in range(n):
	list1[i] = map(int,raw_input().split())
for i in range(m):
	list2[i] = map(int,raw_input().split())
for i in range(n):
	for j in range(l):
		for k in range(m):
			list3[i][j] += list1[i][k] * list2[k][j]
for i in range(n):
	for j in range(l):
		if j==l-1:
			print'%d' %list3[i][j]
		else:
			sys.stdout.write(str(list3[i][j]))
			sys.stdout.write(' ')

Measured memory_bytes: 7364
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll X, Y;
vector<ll> fac(1000001);
vector<ll> ifac(1000001);
vector<ll> inv(1000001);

void cominit(){
    fac[0] = fac[1]  = 1;
    ifac[0] = ifac[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 1000001;i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        ifac[i] = ifac[i - 1] * inv[i] % mod;
    }
}
ll mpow(ll x,ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1)
            ans = ans * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a,ll b){
    if(a == 0 && b == 0)
        return 1;
    if(a < b || a < 0)
        return 0;
    ll tmp = ifac[a - b] * ifac[b] % mod;
    return tmp * fac[a] % mod;
}

int main(){
    cin >> X >> Y;
    if((X + Y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }
    cominit();
    ll x = (2 * Y - X) / 3, y = (2 * X - Y) / 3;
    if(x < 0 || y < 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = comb(x+y,y);
    cout << ans << endl;
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    bool ok = false;
    rep(i,s.size()-1) if (s[i] == s[i+1]) ok = true;
    if (ok) cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 3624
// https://atcoder.jp/contests/agc009/tasks/agc009_a
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() { 
    ll n;cin>>n;
    vector<ll> a(n),b(n);
    for(int i=0;i<n;i++) cin>>a[i]>>b[i];
    ll ans=0;
    for(int i=n-1;i>=0;i--) {
        a[i] += ans;
        a[i] %= b[i];
        if(a[i])
            ans += b[i]-a[i];
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 4848
N,A,B,C,D = map(int,input().split())
S = input()

if "##" in S[A-1:C] or "##" in S[B-1:D]:
  print("No")
elif C < D:
  print("Yes")
else:
  if "..." in S[B-2:D+1]:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 3516
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(Math.Min(a.Where(x => x < s[2]).Count(), a.Where(x => x > s[2]).Count()));
    }
}

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

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();
        int result = 0;
        for (int i = a; i <= b; i++) {
            if (i % k == 0) {
                result = 1;
            }
        }
        if (result == 1) {
            System.out.println("OK");
        } else {
            System.out.println("NG");   
        }
    }
}

Measured memory_bytes: 27092
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep01(i, n) for(int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for(int i = 1; i < (n); i++)
#define rep11(i, n) for(int i = 1; i < (n) + 1; i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
typedef struct { int x; int y; } Pos;
using namespace std;


int main()
{
    int sum = 0;
    ll ans = 0;
    const int MOD = 1000000007;

    int n;
    cin >> n;

    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
        sum %= MOD;
    }

    rep(i, n) {
        sum -= a[i];
        if (0 > sum) sum += MOD;
        ans += a[i] * (ll)sum;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4044
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
    cout << fixed << setprecision(10);

    int n, x, t;
    cin >> n >> x >> t;

    cout<<((n+x-1) / x)* t;

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
 
using namespace std;
 
#define MOD 1000000007
#define A first
#define B second
 
typedef long long ll;
 
inline int mulmd(ll a, ll b){
  ll ret = (a * b) % MOD;
  return (int) ret;
}
 
inline int power(ll x, ll y, int m){
  ll res = 1;
  x = x % m;
  while(y > 0){
    if(y & 1){
      res = mulmd(res, x);
    }
    y = y >> 1;
    x = mulmd(x, x);
  }
  return (int) res;
}
 
inline int submd(ll a, ll b){
  ll ret = (a - b);
  if(ret < 0) ret += MOD;
  return (int) ret;
}
 
inline int addmd(ll a, ll b){
  ll ret = (a + b) % MOD;
  return (int) ret;
}
 
inline int invPow(ll a){
  return power(a, MOD - 2, MOD);
}
 
inline int divmd(ll a, ll b){
  ll ret = mulmd(a, invPow(b));
  return (int) ret;
}
 
const int N = 1e5 + 5;

int arr[N];
map<string, int> mp;

void solve(){
  int n;
  cin >> n;
  int mx = 0;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    mp[s]++;
    mx = max(mx, mp[s]);
  }
  for(auto x: mp){
    if(x.B == mx){
      cout << x.A << "\n";
    }
  }

}

int main(){
  int t;
  t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
}



Measured memory_bytes: 25216
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
ll d1[313131], d2[313131];
int main()
{
	int num;
	scanf("%d", &num);
	vector<ll>v;
	for (int i = 0; i < num * 3; i++)
	{
		int z;
		scanf("%d", &z);
		v.push_back(z);
	}
	ll s = 0;
	priority_queue<ll>que1;
	for (int i = 0; i < num; i++)s += v[i], que1.push(-v[i]);
	d1[num] = s;
	for (int i = num; i < num + num; i++)
	{
		s += v[i];
		que1.push(-v[i]);
		s += que1.top();
		que1.pop();
		d1[i + 1] = s;
	}
	s = 0;
	priority_queue<ll>que2;
	for (int i = num * 3 - 1; i >= num * 2; i--)s += v[i], que2.push(v[i]);
	d2[num + num] = s;
	for (int i = num * 2 - 1; i >= num; i--)
	{
		s += v[i];
		que2.push(v[i]);
		s -= que2.top();
		que2.pop();
		d2[i] = s;
	}
	ll maxi = -1000000000000000000LL;
	for (int i = num; i <= num + num; i++)maxi = max(maxi, d1[i] - d2[i]);
	printf("%lld\n", maxi);
}

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

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

    int h, w, a, b;
    cin >> h >> w >> a >> b;
    rep(i, 0, h) {
        rep(j, 0, w) cout << ((b <= i) ^ (a <= j));
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>

using namespace std;

int main(){
    string s;
    cin >> s;
    int min = s.length(),max = 0;
    for(int i=0;i<s.length();i++){
        if(s[i] == 'A' && min > i){
            min = i;
        }
        if(s[i] == 'Z' && max < i){
            max = i;
        }
    }
    cout << max - min + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	string s;
	cin >> s;
	int size = s.size(), ans = 0, tmp;
	for (int bit = 0; bit < (1 << size - 1); bit++) {
		tmp = 0;
		for (int j = 0; j < size; j++) {
			tmp = 10 * tmp + s[j] - '0';
			if (bit & (1 << j) || j == size - 1) {
				ans += tmp;
				tmp = 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue<int>
#define PQR priority_queue<int,VE,greater<int>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

int n;
vector<int>to[1005];

vector<int>bfs(int sv) {
	VE dist(n, INF), pre(n, -1);
	queue<int>q;
	dist[sv] = 0;
	q.push(sv);
	while (!q.empty()) {
		int v = q.front(); q.pop();
		for (int u : to[v]) {
			if (dist[u] != INF)continue;
			pre[u] = v;
			dist[u] = dist[v] + 1;
			q.push(u);
		}
	}
	P best(INF, -1);
	rep(v, n) {
		if (v == sv)continue;
		for (int u : to[v]) {
			if (u == sv) {
				chmin(best, make_pair(dist[v], v));
			}
		}
	}
	if (best.first == INF)return vector<int>(n + 1);
	int v = best.second;
	vector<int> res;
	while (v != -1) {
		res.push_back(v); v = pre[v];
	}
	return res;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int m;
	cin >> n >> m;
	rep(i, m) {
		int a, b; cin >> a >> b; a--; b--;
		to[a].push_back(b);
	}
	vector<int>ans(n + 1);
	rep(s, n) {
		auto now = bfs(s);
		if (now.size() < ans.size())ans = now;
	}
	if (ans.size() == n + 1) {
		cout << -1 << endl; return 0;
	}
	cout << ans.size() << endl;
	for (int v : ans) {
		cout << v + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;


int main(void){

    int N,A,B; cin>>N>>A>>B;

    cout<<min(N*A, B)<<endl;

}


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

int main() {
  string a,b,c;cin >> a >> b >> c;
  a[0] = toupper(a[0]);
  b[0] = toupper(b[0]);
  c[0] = toupper(c[0]);

  cout << a[0] << b[0] << c[0] << endl;
}

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

int main(){
  int H, W;
  cin >> H >> W;
  char S[H+2][W+2];
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      cin >> S[i][j];
    }
  }
  string ans=("Yes");
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      if(S[i][j]=='#'){
        if(S[i-1][j]=='#' or S[i][j-1]=='#' or S[i+1][j]=='#' or S[i][j+1]=='#') ans=ans;
        else{
          ans="No";
          break;
        }
      }
    }
    if(ans=="No") break;
  }
  cout << ans << endl;
}

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

const int MAX_NM=101;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,sum1,sum2,d,ok;
    vector<int> T(MAX_NM),H(MAX_NM);
    while(cin >> n >> m,n,m){
        sum1=0,sum2=0;
        for (int i=0;i<n;++i){cin >> T[i]; sum1+=T[i];}
        for (int i=0;i<m;++i){cin >> H[i]; sum2+=H[i];}
        if (((sum1+sum2)%2)&1){
            cout << -1 << endl;
            continue;
        }
        sort(T.begin(),T.begin()+n);
        sort(H.begin(),H.begin()+m);
        d=sum1-(sum1+sum2)/2,ok=0;
        for (int i=0;i<n;++i){
            for (int j=0;j<m;++j){
                if (!ok&&T[i]-H[j]==d){
                    cout << T[i] << ' ' << H[j] << endl;
                    ok=1;
                }
            }
        }
        if (!ok) cout << -1 << endl;
    }
}


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

int main(){
  int a, b, n;
  cin >> n >> a >> b;
  if((b - a) % 2 == 0)
    cout << "Alice" << endl;
  else cout << "Borys" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n, k; cin >> n >> k;
	long long a1 = 0, a2 = 0;
	for (int i = n; i > 0; --i) {
		if (k % 2 == 0) a1 += (i % k == k / 2 ? 1 : 0);
		a2 += (i % k == 0 ? 1 : 0);
	}
	long long ans = a1 * a1 * a1 + a2 * a2 * a2;
	cout << ans << endl;

	return 0;
}

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

int main(){
    int n;
    cin >> n;
    n %=10;
    if(n==3){
        cout << "bon";
    }else if(n==0 || n==1 || n==6 || n==8){
        cout << "pon";
    }else{
        cout << "hon";
    }
}

Measured memory_bytes: 3592
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

using namespace std;

typedef long long int lli;

int gcd(int a, int b) {
	return b != 0 ? gcd(b, a%b) : a;
}
lli gcd(lli a, lli b) {
	return b != 0 ? gcd(b, a%b) : a;
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
lli lcm(lli a, lli b) {
	return a * b / gcd(a, b);
}

#define N_MAX 50
#define MOD 1000000007

//lli fac[N_MAX], finv[N_MAX], inv[N_MAX];
//
//void COMinit() {
//	fac[0] = fac[1] = 1;
//	finv[0] = finv[1] = 1;
//	inv[1] = 1;
//	for (int i = 2; i < N_MAX; i++) {
//		fac[i] = fac[i - 1] * i % MOD;
//		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
//		finv[i] = finv[i - 1] * inv[i] % MOD;
//	}
//}
//
//lli COM(int n, int k) {
//	if (n < k) return 0;
//	if (n < 0 || k < 0) return 0;
//	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
//}
//
//lli modpow(lli base, lli p)
//{
//	if (0 == p) {
//		return 1;
//	}
//	if (0 == p % 2) {
//		lli val = modpow(base, p / 2);
//		return (val*val) % MOD;
//	}
//	else {
//		return (modpow(base, p - 1)*base) % MOD;
//	}
//}

void solv()
{
	int H, W, N; scanf("%d%d%d", &H, &W, &N);
	int val = max(H, W);
	int ret;
	if (0 == N % val) {
		ret = N / val;
	}
	else {
		ret = N / val + 1;
	}
	printf("%d", ret);
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}


Measured memory_bytes: 128
open System.Collections.Generic

type Scanner() = class
    let mutable hold = [||]
    let mutable index = 0
    member public this.Next() =
        if hold.Length > index
        then 
            index <- index + 1
            hold.[index - 1]
        else
            let mutable st = stdin.ReadLine()
            while st = "" do st <- stdin.ReadLine()
            hold <- st.Split(' ')
            if hold.Length = 0
            then
                this.Next()
            else
                index <- 1
                hold.[index - 1]
            
    member public this.NextI32() =
        this.Next() |> int

    member public this.ArrayI32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI32()|]

    member public this.NextI64() =
        this.Next() |> int64
    
    member public this.ArrayI64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI64()|]

    member public this.NextF32() =
        this.Next() |> float32
    
    member public this.ArrayF32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF32()|]

    member public this.NextF64() =
        this.Next() |> double
    
    member public this.ArrayF64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF64()|]

    member public __.Tuple2Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 2 |> fun x -> x.[0], x.[1]|]
    
    member public __.Tuple3Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 3 |> fun x -> x.[0], x.[1], x.[2]|]

    member public __.CountDic n (f : unit -> 'a) =
        let seqs = seq {for _ in 0 .. n - 1 -> f()}
        let dic = new Dictionary<'a, int64>();
        for i in seqs do
            if dic.ContainsKey(i)
            then dic.[i] <- dic.[i] + 1L
            else dic.Add(i, 1L)
        dic

end

[<EntryPoint>]
let main _ =
#if DEBUG
    printfn "debuged"
#endif

    let scanner = Scanner()
    let s = scanner.Next()
    let t = scanner.Next()
    let mutable a = scanner.NextI32()
    let mutable b = scanner.NextI32()
    let c = scanner.Next()
    if c = s then a <- a - 1 else b <- b - 1
    printfn "%i %i" a b

    0


Measured memory_bytes: 14040
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  for (int i=0; i<s.size(); i++){
    s[i] += n;
    if (s[i]>'Z') s[i] -= 26;
  }
  cout<<s;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<string>
#define N 200010
using namespace std;
int head[N], k, sz[N];
double E[N], ans[N];
struct Edge
{
    int v, next;
}edge[2 * N];
void add_edge(int u, int v)
{
    edge[++k].v = v;
    edge[k].next = head[u];
    head[u] = k;
}
void dfs1(int u, int pre)
{
    for(int kk = head[u]; ~kk; kk = edge[kk].next)
    {
        int v = edge[kk].v;
        if(v == pre) continue;
        dfs1(v, u);
        E[u] += 1.0 / sz[u] * (E[v] + 1);
    }
}
void dfs2(int u, int pre)
{
    double t = 1.0 / sz[pre] * (E[u] + 1);
    t = ans[pre] - t;
    if(sz[pre] != 1)
        t = t * sz[pre] / (sz[pre] - 1);
    ans[u] = E[u] * (sz[u] - 1) / sz[u] + 1.0 / sz[u] * (t + 1);
    for(int kk = head[u]; ~kk; kk = edge[kk].next)
    {
        int v = edge[kk].v;
        if(v == pre) continue;
        dfs2(v, u);
    }
}
int main()
{
    int n, u, v, i;
    scanf("%d", &n);
    memset(sz, -1, sizeof(sz));
    k = -1;
    memset(head, -1, sizeof(head));
    for(i = 1; i < n; ++i)
    {
        scanf("%d%d", &u, &v);
        add_edge(u, v);
        add_edge(v, u);
        sz[u]++;
        sz[v]++;
    }
    sz[1]++;
    dfs1(1, -1);
    for(i = 2; i <= n; ++i) sz[i]++;
    ans[1] = E[1];
    for(i = head[1]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        dfs2(v, 1);
    }
    for(i = 1; i <= n; ++i)
    {
        printf("%.10lf\n", ans[i]);
    }
    return 0;
}
/*
3
1 2
1 3
*/


Measured memory_bytes: 13312
// after YouTube editorial
// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
use proconio::{input, fastout};

#[derive(Debug)]
struct BIT {
    n: usize,
    d: Vec<i32>,
}

impl BIT {
    fn new(i: usize) -> BIT {
        BIT {n: i, d: vec![0; i+1]}
    }
    fn add(&mut self, mut i: usize, x :i32) {
        i += 1;
        while i <= self.n {
            self.d[i] += x;
            i += i & (-(i as i64))as usize;
        }
    }
    fn sum(&self, mut i: usize) -> i32 {
        let mut x = 0;
        i += 1;
        while i > 0 {
            x += self.d[i];
            i -= i & (-(i as i64))as usize;
        }
        x 
    }
}

#[fastout]
fn main() {
    input! {
        n: usize, q: usize,
        c: [i32; n],
        lr: [(i32, i32); q],
    }
    let mut pi: Vec<i32> = vec![-1; n+1];
    let mut ps: Vec<Vec<i32>> = vec![vec![]; n];
    for i in 0..n {
        let l = pi[c[i]as usize];
        if l != -1 { ps[l as usize].push(i as i32) };
        pi[c[i]as usize] = i as i32;
    }
    let mut qs: Vec<Vec<(i32,i32)>> = vec![vec![]; n];
    for i in 0..q {
        let (mut l, mut r) = lr[i];
        l -= 1;
        r -= 1;
        qs[l as usize].push( (r,i as i32) );
    }
    let mut ans: Vec<i32> = vec![-1; q];
    let mut d = BIT::new(n);
    for x in (0..n).rev() {
        for y in ps[x].iter() { d.add(*y as usize,1) }
        for qq in qs[x].iter() {
            let r = (&qq).0;
            let i = (&qq).1;
            ans[i as usize] = r - x as i32 + 1 - d.sum(r as usize);
        }
    }
    for a in ans.iter() {
        println!("{}", *a);
    }
}


Measured memory_bytes: 72164
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  int N;cin >> N;
  N++;
  cout << N / 2 << endl;

  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui32;
const long long INFLL = 1e18;
using namespace std;

const int INF = 1000 * 1000 * 1000;
const int MAXN = 100000;
const int LEN = 50;

int dp[2][MAXN + 1], used[MAXN + 1];

int main() {
    //ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    //int st = clock();

    for (int i = 0; i < 2; i++)
        for (int j = 0; j <= MAXN; j++)
            dp[i][j] = INF;

    dp[0][0] = 0;

    int K;
    cin >> K;

    int nxt;
    int ans = INF;
    int cur;

    for (int len = 0; len < LEN; len++) {
        for (int rem = 0; rem < K; rem++) {
            if (dp[0][rem] > 45)
                continue;
            nxt = rem * 10 % K;
            for (int last = 1; last <= 9 && dp[0][rem] + last <= 45; last++) {
                cur = nxt + last;
                if (cur >= K)
                    cur -= K;

                dp[1][cur] = min(dp[1][cur], dp[0][rem] + last);
            }
        }

        if (len > 0) {
            memset(used, 0, sizeof(used));
            vector<pair<int, int> > vec;
            for (int rem = 0; rem < K; rem++)
                vec.push_back({ dp[0][rem], rem });

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

            for (auto now: vec) {
                int rem = now.second;
                int value = now.first;
                while (!used[(rem * 10) % K]) {
                    rem = rem * 10 % K;
                    dp[1][rem] = min(dp[1][rem], value);
                    used[rem] = 1;
                }
            }
        }

        ans = min(ans, dp[1][0]);

        for (int j = 0; j < K; j++) {
            dp[0][j] = dp[1][j];
            dp[1][j] = INF;
        }
    }

    //int en = clock();

    //cout << (en - st + .0) / CLOCKS_PER_SEC << endl;

    cout << ans << endl;
    return 0;
}

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

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

d = 1000000000 + 7

s = 0

sum_list = [A[0]]
for a in A[1:]:
    sum_list.append(a + sum_list[-1])
for i in range(N):
    s += A[i] * (sum_list[N-1] - sum_list[i])
print(s % d)

Measured memory_bytes: 104724
#include <bits/stdc++.h>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
struct UnionFind {
    vector<int> r;
    int ans;
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
    UnionFind(int n) {
        r.assign(n + 1, -1);
        ans = n - 1;
    }
    void unite(int a, int b) {
        if (root(a) == root(b)) return;
        ans--;
        r[root(b)] = root(a);
    }
};
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    while (m--) {
        int a, b;
        cin >> a >> b;
        uf.unite(a, b);
    }
    cout << uf.ans << endl;
}

Measured memory_bytes: 3672
N = int(input())

flg = 0

if N>7:
    for i in range(N//7+1):
        r = N-7*i
        if r%4==0:
            flg = 1
        
else:
    if N==4 or N==7:
        flg = 1

if flg==1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] num = Input.ScanIntArray();
          Console.WriteLine(Math.Abs(num[1]-num[0]) < Math.Abs(num[2]-num[0]) ? "A" : "B");
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

typedef struct {
    int index1;
    int index2;
    int max1;
    int max2;
} max_info;

int max(int a, int b) {
    if(a > b) {
        return a;
    }
    else {
        return b;
    }
}

int main() {
    int N;
    scanf("%d", &N);
    int i;
    int *v = (int*)malloc(N * sizeof(int));
    int *list_odd = (int*)malloc((100000+1) * sizeof(int));
    int *list_even= (int*)malloc((100000+1) * sizeof(int));
    for(i=0; i<100000+1; i++) {
        list_odd[i] = 0;
        list_even[i] = 0;
    }


    for(i=0; i<N; i++) {
        scanf("%d", &v[i]);
        if(i % 2 == 0) {
            list_odd[v[i]]++;
        }
        else {
            list_even[v[i]]++;
        }
    }

    max_info odd;
    odd.index1 = 0;
    odd.index2 = 0;
    odd.max1 = 0;
    odd.max2 = 0;
    max_info even;
    even.index1 = 0;
    even.index2 = 0;
    even.max1 = 0;
    even.max2 = 0;
    for(i=0; i<100000+1; i++) {
        if(odd.max1 < list_odd[i]) {
            odd.max2 = odd.max1;
            odd.index2 = odd.index1;
            odd.max1 = list_odd[i];
            odd.index1 = i;
        }
        else if(odd.max2 < list_odd[i]) {
            odd.max2 = list_odd[i];
            odd.index2 = i;
        }
        if(even.max1 < list_even[i]) {
            even.max2 = even.max1;
            even.index2 = even.index1;
            even.max1 = list_even[i];
            even.index1 = i;
        }
        else if(even.max2 < list_even[i]) {
            even.max2 = list_even[i];
            even.index2 = i;
        }
    }
    // printf("%d, %d, %d, %d\n", odd.index1, odd.max1, odd.index2, odd.max2);
    // printf("%d, %d, %d, %d\n", even.index1, even.max1, even.index2, even.max2);
    int odd_max, even_max;
    if(odd.index1 == even.index1) {
        printf("%d\n", N - max(odd.max1+even.max2, odd.max2+even.max1));
        return 0;
    }
    else {
        odd_max = odd.max1;
        even_max = even.max1;
    }


    printf("%d\n", N - odd_max - even_max);
    free(v);
    free(list_odd);
    free(list_even);
    return 0;
}

Measured memory_bytes: 1280
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import sys
#####################################
n=int(input())
A=list(input())
X=["0"]
for i in range(n):
    if X[-1]!=A[i]:
        X.append(A[i])
X.pop(0)
print(len(X))


Measured memory_bytes: 76524
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

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

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

	string S, T;
	cin >> S >> T;

	ll ans = 0;

	for (ll i = 0; i < S.size(); ++i)
	{
		if (S[i] != T[i]) ans++;
	}

	cout << ans << endl;
}


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

int main()
{
    int n;
    scanf("%d", &n);

    vector<int> b(n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &b[i]);
        --b[i];
    }

    vector<int> out;
    while((int)b.size())
    {
        static bool ok;

        ok = false;
        for (int i = (int)b.size() - 1; i >= 0; --i)
        {
            if (b[i] == i)
            {
                ok = true;
                out.push_back(b[i]);
                b.erase(b.begin() + i);
                break;
            }
        }

        if (!ok)
        {
            printf("-1");
            return 0;
        }
    }

    reverse(out.begin(), out.end());
    for (int x : out)
        printf("%d\n", x + 1);
}


Measured memory_bytes: 256
// let input = "1600";

function main(input){
  input = input.trim();
  let x = parseInt(input);
  let mainasu = Math.floor(x/200);
  let kyu = 10 - mainasu;
  console.log(kyu);
}

// main(input);

main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 29628
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors


n = int(input())
div = make_divisors(n)
if len(div) % 2 == 0:
    print(len(str(div[int(len(div) / 2)])))
else:
    print(len(str(div[int(len(div) / 2)])))


Measured memory_bytes: 3188
class UnionFindTree():
    def __init__(self, N):
        self.__parent_of = [None] * N
        self.__rank_of = [0] * N
        self.__size = [1] * N

    def root(self, value):
        if self.__parent_of[value] is None:
            return value
        else:
            self.__parent_of[value] = self.root(self.__parent_of[value])
            return self.__parent_of[value]

    def unite(self, a, b):
        r1 = self.root(a)
        r2 = self.root(b)
        if r1 != r2:
            if self.__rank_of[r1] < self.__rank_of[r2]:
                self.__parent_of[r1] = r2
                self.__size[r2] += self.__size[r1]
            else:
                self.__parent_of[r2] = r1
                self.__size[r1] += self.__size[r2]
                if self.__rank_of[r1] == self.__rank_of[r2]:
                    self.__rank_of[r1] += 1

    def is_same(self, a, b):
        return self.root(a) == self.root(b)

    def size(self, a):
        return self.__size[self.root(a)]

    def groups(self):
        groups = {}
        for k in range(len(self.__parent_of)):
            r = self.root(k)
            if r not in groups:
                groups[r] = []
            groups[r].append(k)
        return [groups[x] for x in groups]


def main():
    N, M = map(int, input().split())
    adj = [set() for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())
        adj[A-1].add(B-1)
        adj[B-1].add(A-1)
    uft = UnionFindTree(N)
    for i in range(N):
        adji = list(adj[i])
        x = adji[0]
        for y in adji[1:]:
            uft.unite(x, y)
    groups = uft.groups()
    if len(groups) == 1:
        print(N * (N-1) // 2 - M)
    else:
        print(len(groups[0]) * len(groups[1]) - M)


if __name__ == "__main__":
    main()


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<long long> A(N);
    bool zero = false;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        if (A[i] == 0) {
            zero = true;
        }
    }
    if (zero) {
        cout << "0\n";
        return 0;
    }
    long long MAX = 1E18, cur = 1;
    for (int i = 0; i < N; ++i) {
        if (A[i] > (MAX / cur)) {
            cout << "-1\n";
            return 0;
        }
        cur *= A[i];
    }
    if (cur > MAX) {
        cout << "-1\n";
        return 0;
    }
    cout << cur << '\n';
    return 0;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int k; cin >> k;
    VI a(k); cin >> a;
    ll Min = 2, Max = 2;
    rFOR(i, 0, k) {
        Min = (Min + a[i] - 1) / a[i] * a[i];
        Max = Max / a[i] * a[i] + a[i] - 1;
        if (Min > Max) {
            cout << "-1\n";
            return 0;
        }
    }
    cout << Min << " " << Max << "\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
using namespace std;
int c[4][4], a[4], b[4];
int main() {
	for(int i= 1; i <= 3; i++) {
		for(int j= 1; j <= 3; j++) {
			cin >> c[i][j];
		}
	}
	for(a[1]= 0; a[1] <= 100; a[1]++) {
		b[1]= c[1][1] - a[1];
		b[2]= c[1][2] - a[1];
		b[3]= c[1][3] - a[1];
		for(a[2]= 0; a[2] <= 100; a[2]++) {
			if(c[2][1] - a[2] != b[1]) continue;
			if(c[2][2] - a[2] != b[2]) continue;
			if(c[2][3] - a[2] != b[3]) continue;
			for(a[3]= 0; a[3] <= 100; a[3]++) {
				if(c[3][1] - a[3] != b[1]) continue;
				if(c[3][2] - a[3] != b[2]) continue;
				if(c[3][3] - a[3] != b[3]) continue;
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

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

int binarySearch(int A[], int begin, int end, int key) {
  if (begin == end) {
    if (A[begin] == key) return 1;
    else return 0;
  }
  int middle = begin - (begin - end) / 2;
  if (A[middle] == key) return 1;
  else if (A[middle] > key) return binarySearch(A, begin, middle, key);
  else return binarySearch(A, middle + 1, end, key);
}

int main() {
  int n;
  cin >> n;
  int S[100000];
  for (int i = 0; i < n; ++i) cin >> S[i];

  int q;
  cin >> q;
  int dep = 0;
  for (int i = 0; i < q; ++i) {
    int key;
    cin >> key;
    dep += binarySearch(S, 0, n - 1, key);
  }
  cout << dep << endl;
}



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

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i = 0;i < h;i++){
            cin >> a[i];
    }

    for (int i = 0;i < w + 2;i++) cout << '#';
    cout << endl;
    for (int i = 0;i < h;i++){
        cout << '#';
        cout << a[i];
        cout << '#' << endl;
    }

    for (int i = 0;i < w + 2;i++) cout << '#';
    cout << endl;
}

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

int main() {
    int p, q, r;
    int ans = 0;
    vector<int> vec(3);

    cin >> p >> q >> r;;

    vec[0] = p+q;
    vec[1] = r+q;
    vec[2] = p+r;

    ans = *min_element(vec.begin(), vec.end());
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define s second
#define int long long
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 1e9+7;
const int MAXN = 1e6+5;


int32_t main() {
	int n;
	cin >> n;
	ll m[10][10], ans = 0;
	memset(m, 0, sizeof m);
	
	for(int i = 1; i <= n; i++) {
		
		int x = i;
		string s;
		stringstream ss;
		ss << x;
		ss >> s;
		
		if(s[0] == '0') continue;
		m[s[0]-'0'][s[s.size()-1]-'0']++;
		
	}
	
	for(int i = 1; i <= 9; i++)
		for(int j = 1; j <= 9; j++)
			ans += m[i][j]*m[j][i];
	cout << ans << endl;
}


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

const int SENTINENTAL=1e9+7;

using namespace std;

int cnt=0;
int n;
int A[500009];

void merge(int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  vector<int>L, R;
  for(int i=0;i<n1;i++)L.push_back(A[left+i]);
  for(int i=0;i<n2;i++)R.push_back(A[mid+i]);
  L.push_back(SENTINENTAL);
  R.push_back(SENTINENTAL);
  int i=0, j=0;
  for(int k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j])A[k]=L[i++];
    else A[k]=R[j++];
  }
}

void mergeSort(int left, int right){
  if(left+1<right){
    int mid=(left + right)/2;
    mergeSort(left, mid);
    mergeSort(mid, right);
    merge(left, mid, right);
  }
}

int main(){
  cin >> n;
  int tmp;
  for(int i=0;i<n;i++){
    cin >> A[i];
  }
  mergeSort(0, n);
  for(int i=0;i<n;i++)cout << A[i] << (i<n-1?' ': '\n');
  cout << cnt << endl;
}


Measured memory_bytes: 7368
#include <iostream>
#include <list>
#include <string>
#include <ios>
using namespace std;
struct Trie
{
	struct Node
	{
		Node() :isEnd(false) {}
		Node(char _v) : v(_v), isEnd(false) {}
		~Node()
		{
			for (list<Node*>::iterator it = nodes.begin();
				it != nodes.end();
				++it)
			{
				//delete *it;
			}
		}
		Node* FindChild(char c){
			for (list<Node*>::iterator it = nodes.begin();
				it != nodes.end();
				++it)
			{
				if ((*it)->v == c)
					return *it;
			}
			return 0;
		}

		bool isEnd;
		char v;
		list<Node*> nodes;
	};

	void Add(const string& str){
		Node* n = &root;
		Node* cn = 0;
		int s = str.size();
		std::string::size_type p = 0;
		for (; p < s; ++p){
			char c = str[p];
			cn = n->FindChild(c);
			if (cn)
				n = cn;
			else{
				cn = new Node(c);
				n->nodes.push_back(cn);
				n = cn;
			}
		}
		n->isEnd = true;
	}
	bool Find(const string& str){
		Node* n = &root;
		Node* cn = 0;
		int s = str.size();
		std::string::size_type p = 0;
		for (; p < s; ++p){
			char c = str[p];
			cn = n->FindChild(c);
			if (!cn)
				return false;
			n = cn;
			if (p == s - 1)
				return n->isEnd;
		}
	}
	Node root;
};

int main()
{
	ios::sync_with_stdio(false);

	int n, i;
	cin >> n;
	string com, str;
	Trie trie;
	for (i = 0; i < n; ++i){
		cin >> com >> str;
		if (com == "insert") trie.Add(str);
		if (com == "find")
			cout << (trie.Find(str) ? "yes\n" : "no\n");
	}

	return 0;
}

Measured memory_bytes: 22948
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
const double pi=acos(-1.0);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int main(void){
    long long n,d,cnt;
    double s;
    cin>>n>>d;
    vector<long long> x(200050),y(200050);
    cnt=0;
    rep(i,n){cin>>x.at(i);cin>>y.at(i);}
    rep(i,n){s=sqrt(x.at(i)*x.at(i)+y.at(i)*y.at(i));if(s<=d)cnt++;}
    cout<<cnt<<endl;
    
    
    return 0;
    
}


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

int main() {
  
  int A, B, X;
  cin >> A >> B >> X;
  
  if (X - A <= B && X - A >= 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int n = 1000000000;
  for (int i = 0; i < N; i++){
  		int A;
    cin >> A;
    
	int a = 0;
    
    while ( A % 2 == 0){
      a++;
      A /= 2;
    }
    
	if(n > a)
      n = a;
  }
  
  cout << n << endl;

}


Measured memory_bytes: 3596
use strict;
use warnings;
use utf8;
use feature qw/say/;
use POSIX qw/ceil/;

my $inp = <STDIN>;
chomp($inp);
my ($t_hp, $t_ap, $a_hp, $a_ap) = split(/ /, $inp);

my $t_cnt = ceil($a_hp/$t_ap);
my $a_cnt = ceil($t_hp/$a_ap);

if ($t_cnt <= $a_cnt) {
    say 'Yes';
} else {
    say 'No';
}

Measured memory_bytes: 6728
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//
		int n = sc.nextInt();
		int[] l = new int[n];
		for(int i=0; i<n; i++){
			l[i] = sc.nextInt();
		}
		Arrays.sort(l);
		int sum = 0;
		for(int i=0; i<n-1 ; i++){
			sum += l[i];
		}
		System.out.println(l[n - 1] < sum ? "Yes" : "No");
	}
}


Measured memory_bytes: 35772
#include <iostream>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; ++i)
	{
		int Num;
		cin >> Num;
		cout << "Case " << i << ":" << endl;
		for(int j = 0; j < 10; ++j)
		{
			Num *= Num;
			Num %= 1000000;
			Num /= 100;
			cout << Num << endl;
		}
	}
}

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

Measured memory_bytes: 0
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define CIN(s) int (s);cin>>(s);
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;

int main(){
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    if(s.size()!=a+b+1){
        cout<<"No"<<endl;
        return 0;
    }
    rep(i,s.size()){
        if(i==a){
            if(s[i]!='-'){
                cout<<"No"<<endl;
                return 0;
            }
        }else{
            if(s[i]-'0'>=10||s[i]-'0'<0){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	//input = input.trim().split("\n");
	input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var H = input[0];
  var W = input[1];
  var A = input[2];
  var B = input[3];
  var output = [];
  for(var i = 0; i < H; i++){
    var tmp = "";
    for(var j = 0; j < W; j++){
      if((i < B && j < A) || (i >= B && j >= A)){
          tmp += "0";
         }else{
         tmp += "1";
         }
    }
    output.push(tmp);
  }
  myout(output.join("\n"));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 67532
n=int(input())
l=[sorted(list(input())) for i in range(n)]

d={}
for i in l:
  i=''.join(i)
  if i in d:
    d[i]+=1
  else:
    d[i]=1

ans=0
for v in d.values():
  if v>=2:
    ans+=v*(v-1)//2
print(ans)

Measured memory_bytes: 39040