akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >>N;
    if(N==1){
        cout <<0 <<endl;
        return 0;
    }
    vector<int>vec(N);
    for(int i=0;i<N;i++){
        cin >>vec.at(i);
    }
    int count=0;
    vector<int>vec2;
    int a=vec.at(0);
    for(int i=1;i<N;i++){
        if(i==N-1){
            if(a>=vec.at(i)){
                count ++;
                vec2.push_back(count);
                break;
            }
            else{
                vec2.push_back(count);
                break;
            }
        }
     if(a>=vec.at(i)){
         count ++;
         a=vec.at(i);
    }
    else {
        vec2.push_back(count);
        count =0;
        a=vec.at(i);
    }
    }
    sort(vec2.begin(),vec2.end());
    reverse(vec2.begin(),vec2.end());
    cout << vec2.at(0)<<endl;
}

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

int main() {
    int N, K;
    cin >> N >> K;

    vector<string> vstr(N);
    for (auto& i : vstr) cin >> i;

    vector<int> v(30);
    for (auto i : vstr) {
        v[i[0] - 'A']++;
    }

    int ans = N / K;
    while (1) {
        bool flag = false;
        for (int i = 0; i < 26; i++) {
            if (ans < v[i]) N-=v[i]-ans, v[i] = ans, ans = N / K, flag = true;
        }
        if (!flag) break;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(int n){
    int ans=0;
    for(int x=1;x*x<=n;x++){
       for(int y=1;y*y+x*x<=n;y++){
            int b=(x+y);
            int c=(x*x+y*y+x*y-n);
            if(c>=0) break;
            int D2=b*b-4*c;
            if(D2<=0) continue;
            int D=sqrt(D2);
            if(D*D!=D2) continue;
            if(D-b<=0) continue;
            ans++;
       }
    }
    cout<<ans<<endl;



    return 0;
}
signed main(){
    asdf
    int t=1;
    cin>>t;
    rep(1,t+1) solve(i);
    return 0;
}


Measured memory_bytes: 3528
#include<bits/stdc++.h>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
using namespace std;

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

const ll MOD = 1e9+7;

// Combinationの使い方
// vector<vector<ll>> v(N+1, vector<ll>(N+1, 0));
// comb(v);
void comb(vector<vector<ll>> &v){
    for(int i = 0; i < v.size(); i++){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(int k = 1; k < v.size(); k++){
        for(int j = 1; j < k; j++){
            v[k][j] = (v[k-1][j-1] + v[k-1][j]);
            //余りを求める問題は毎回計算ごとにやる
            // v[k][j] = (v[k-1][j-1] + v[k-1][j]) % MOD;
        }
    }
}

// Union Find
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

// 1 << 3 : int "3" change to bit "100"
// rep(pattern, 1 << N) if (pattern & (1 << x)) cnt++

// bool checkA = false;
// bool checkB = false;
// bool checkC = false;

// bool check(){
//     rep(i,l.size()){
//         if(l[i]==A) checkA = true;
//         if(l[i]==B) checkB = true;
//         if(l[i]==C) checkC = true;
//     }
//     if(checkA && checkB && checkC) return true;
//     return false;
// }

vector<int> l(8,0);
int N, A, B, C;
int INF = 1000000007;

// a || b || c の箱を用意して，そこに竹を入れていく（合成していく）
// 入れきったら，A || B || Cに対して何回延長（または縮小）すれば良いかを考える
int search(int i, int a, int b, int c){
    if(i>N){
        if(a>0 && b>0 && c>0) return abs(A-a) + abs(B-b) + abs(C-c) - 30;
        else return INF;
    }

    int mp0 = search(i+1, a, b, c); // l[i]をどこにも入れない
    int mp1 = search(i+1, a+l[i], b, c) + 10; // l[i]をaに入れる
    int mp2 = search(i+1, a, b+l[i], c) + 10; // l[i]をbに入れる
    int mp3 = search(i+1, a, b, c+l[i]) + 10; // l[i]をcに入れる

    return min(min(min(mp0, mp1), mp2),mp3);
}

int main(){
    cin >> N >> A >> B >> C;
    rep(i,N) cin >> l[i];
    cout << search(0, 0, 0, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int         int64_t
#define ii          pair<int,int>
#define dd          pair<double,double>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
using namespace std;
int inf = 2e9, mod = 1e9 + 7;

int32_t main()
{
    ios_base::sync_with_stdio(false); cout << fixed <<setprecision(0);
    int n, m; cin >> n >> m;
    vector<vector<ii>> fin(n+1);
    for(int i=0,l,r,a;i<m;i++){
        cin >> l >> r >> a;
        if(l == 1 && r == 1 && a != 1) return cout << 0 << endl, 0;
        else fin[r].pb({l,a});
    }
    vector<vector<vector<int>>> dp(n+1, vector<vi>(n+1, vi(n+1, 0)));
    dp[0][0][0] = 1;
    for(int i = 1;i <= n; i++){
        for(int j = 0; j <= i; j++){
            for(int k = 0;k <= j;k++){
                if(!dp[i-1][j][k]) continue;
                dp[i][j][k] = dp[i-1][j][k] % mod;
                dp[i][i-1][k] = (dp[i][i-1][k] + dp[i-1][j][k]) % mod;
                dp[i][i-1][j] = (dp[i][i-1][j] + dp[i-1][j][k]) % mod;
            }
        }

        for(int j = 0; j <= i; j++){
            for(int k = 0; k <= j; k++){
                for(auto &p : fin[i]){
                    int num = 1;
                    if(j >= p.first) ++num;
                    if(k >= p.first) ++num;
                    if(num != p.second) dp[i][j][k] = 0;
                }
            }
        }
    }
    int sum = 0;
    for(int j=0;j<=n;j++) for(int k=0;k<=j;k++) sum = (sum + dp[n][j][k]) % mod;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 216960
import itertools

flatten_iter = itertools.chain.from_iterable
def factors(n):
    return set(flatten_iter((i, n//i) 
                for i in range(1, int(n**0.5)+1) if n % i == 0))

line = input()
numbers = [int(n) for n in line.split()]
factors_a = factors(numbers[0])
factors_b = factors(numbers[1])
common_factors = list(factors_a.intersection(factors_b))
common_factors.sort(reverse=True)
predicted_value = common_factors[numbers[2] - 1]
print(predicted_value)

Measured memory_bytes: 3064
N = int(input())
a = list(map(int,input().split()))
count = 0
count2 = 0
for i in a:
    if i%4==0:
        count += 1
    elif i%2==0:
        count2 += 1
if count2 != 0:
    if (N-count2)%2 != 0:
        value = (N-count2)//2
    else:
        value = (N-count2)//2-1
else:
    if count >= N//2:
        value = N//2-1
    else:
        value = N//2

    value = N//2-1

if count > value:
    print('Yes')
else:
    print('No')

1414
414


Measured memory_bytes: 14252
from collections import deque

n = int(input())
as_ = map(int, input().strip().split())

d = deque()

reversed = False
for a in as_:
    if reversed:
        d.appendleft(a)
    else:
        d.append(a)
    reversed = not reversed

if reversed:
    d.reverse()

ans = ' '.join(map(str, d))

print(ans)


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

#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)

using namespace std;
int dp[100005]; // dp[i] = minimum weight which will give us exact i val
signed main(){
    int n,W;
    cin>>n>>W;
    int val[n],w[n],vmx=0;
    fr(i,0,n){
        cin>>w[i]>>val[i];
        vmx += val[i];
    }
    fill(dp,dp+100005,1000000005);
    dp[0]=0;
    fr(j,0,n){
        for(int i=vmx;i>=0;i--){
            if(i-val[j]>=0)
                dp[i] = min(dp[i],dp[i-val[j]]+w[j]);
        }
    }
    int ans=0;
    fr(i,0,vmx+1){
        // cout<<i<<" - "<<dp[i]<<"\n";
        if(dp[i]<=W){
            ans = max(ans,i);
        }
    }
    // cout<<dp[90]<<" this is max ";
    cout<<ans;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

const int mn = 30;
void calc(int a) {
	vector<int> ans(mn+1,mod);
	rep1(i, mn)ans[i] = i - 1;
	ans[1] = 0;
	Rep1(i,2, mn) {
		rep1(j, i) {
			int d = (i + j - 1) / j;
			ans[i] = min(ans[i],ans[j]+ a + d);
		}
	}
	rep1(i, mn) {
		cout << a<<" "<<i<<" "<<ans[i] << endl;
	}

}

ll calc_special(ll n,ll a) {
	ll x = 1;

	return 0;
}

void solve() {
	ll n, a; cin >> n >> a;
	ll ans = n;
	rep1(k, 40) {
		//cout << ans << endl;
		ld u = pow(n, 1 / (ld)(1 + k));
		ll r = (u - eps) + 1;
		ll sum = r + (a + r)*k;
		//cout << r << endl;
		//cout << r<<" "<<k << " " << sum << endl;
		ans = min(ans, sum);
		if (r > 2) {
			rep1(i, k + 1) {
				ll z = 1;
				rep(j, i) {
					z = z * (r - 1);
				}
				Rep(j, i, k + 1) {
					z = z * r;
				}
				if (z < n)continue;
				sum = a * k + r * (k + 1) - i;
				ans = min(ans, sum);
			}
		}
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}


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


const int Max = 5e5+10;
int num[Max << 2], mark[Max << 2];
int N;
string S;


void push_up(int node)
{
    num[node] = num[node << 1] | num[node << 1 | 1];
}


void push_down(int node, int l, int r)
{
    if (mark[node]) {
        mark[node << 1] = mark[node];
        mark[node << 1 | 1] = mark[node];
        num[node << 1] = mark[node];
        num[node << 1 | 1] = mark[node];
        mark[node] = 0;
    }
}


void build(int node, int l, int r)
{
    if (l == r) {
        int c = S[l-1] - 'a';
        num[node] = 1 << c;
        mark[node] = 0;
    } else {
        int mid = (l + r) >> 1;
        build(node << 1, l, mid);
        build(node << 1 | 1, mid + 1, r);
        push_up(node);
    }
}


void update(int node, int l, int r, int cl, int cr, int c)
{
    if (cl > r || cr < l) return;
    if (cl <= l && cr >= r) {
        mark[node] = c;
        num[node] = c;
        return;
    }
    push_down(node, l, r);
    int mid = (r + l) >> 1;
    update(node << 1, l, mid, cl, cr, c);
    update(node << 1 | 1, mid + 1, r, cl, cr, c);
    push_up(node);
}


int query(int node, int l, int r, int cl, int cr)
{
    if (cl > r || cr < l) return 0;
    if (cl <= l && cr >= r) return num[node];
    push_down(node, l, r);
    int mid = (r + l) >> 1;
    int ret = 0;
    ret |= query(node << 1, l, mid, cl, cr);
    ret |= query(node << 1 | 1, mid + 1, r, cl, cr);
    return ret;
}


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

    cin >> N;
    cin >> S;
    build(1, 1, N);
    int q, idx, iq, lq, rq;
    char cq;
    cin >> q;
    while (q--) {
        cin >> idx;
        if (idx == 1) {    // 1 iq cq
            cin >> iq >> cq;
            int c = cq - 'a';
            update(1, 1, N, iq, iq, 1 << c);
        } else {    // 2 lq rq
            cin >> lq >> rq;
            int res = query(1, 1, N, lq, rq);
            cout << __builtin_popcount(res) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 12164
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
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; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
ll dx[] = { 1, 0 , -1,  0 }, dy[] = { 0, 1, 0, -1 };
ll cb(ll a, ll b);

int main() {
	 string s;
	 cin >> s;
	
	 if (s[s.size() - 1] == 's') {
		 s += "es";
	 }
	 else s += 's';

	 cout << s;


	return 0;
}


ll cb(ll a, ll b) {
	ll ans = 1;
	rep(i, b) ans *= (a - i);
	rep(i, b) ans /= (b - i);

	return ans;
}


Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <algorithm>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(){
	double a, pre_a;
	double result = 0;

#if INPUT_FROM_FILE
	//std::ifstream ifs("test.txt");
	FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	while(fscanf(fp, "%lf", &a) != EOF){
#else
	while(scanf("%lf", &a) != EOF){
#endif

		result = a;

		pre_a = a;
		for(int i = 2; i <= 10; i++){
			if(i % 2 == 0){
				a = 2 * pre_a;
			}
			else{
				a = pre_a / 3.0;
			}
			result += a;
			pre_a = a;
		}
		printf("%.7lf\n", result);
	}

#if INPUT_FROM_FILE
	fclose(fp);
#endif
	return 0;
}


Measured memory_bytes: 3116
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ll INF = 1e15;
const ld eps = 1e-9;
const db PI = atan(1) * 4;

template<typename T, typename S>inline bool upmin(T&a, const S&b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S>inline bool upmax(T&a, const S&b) { return a < b ? a = b, 1 : 0; }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
ll pow(ll a, ll b) {
	if (b == 0) {
		return 1;
	}
	if (b == 1) {
		return a;
	}
	ll ans = pow(a, b / 2);
	ans *= ans;
	ans *= b % 2 == 1 ? a : 1;
	return ans;
}

namespace SOLVE {
	vector<VI> edges;
	VI lowlink;
	VI visited;
	VI firstvisit;
	VI ans;
	int time = 0;
	int children = 0;

	void dfs(int at, int previous) {
		firstvisit[at] = time;
		lowlink[at] = time;
		time++;

		visited[at] = 1;
		if (previous == 0) {
			children++;
		}


		for (int to : edges[at]) {
			if (!visited[to]) {
				dfs(to, at);
				lowlink[at] = min(lowlink[at], lowlink[to]);
				if (previous != -1 && lowlink[to] >= firstvisit[at]) {
					ans[at] = 1;
				}
			}
			else {
				if (to != previous) {
					lowlink[at] = min(lowlink[at], firstvisit[to]);
				}
			}
		}



		
		if (at == 0) {
			if (children >= 2) {
				ans[0] = 1;
			}
		}
		

	}

	void main() {
		int n, m, a, b;
		cin >> n >> m;
		edges.resize(n);
		REP(i, 0, m) {
			cin >> a >> b;
			edges[a].push_back(b);
			edges[b].push_back(a);
		}
		firstvisit.resize(n);
		lowlink.resize(n);
		visited.resize(n);
		ans.resize(n);

		dfs(0, -1);

		REP(i, 0, n) {
			if (ans[i]) {
				cout << i << endl;
			}
		}

	}
}


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

	int t;
	//    in(t);
	t = 1;
	while (t--) {
		SOLVE::main();

	}

	return 0;
}



Measured memory_bytes: 4668
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            int r = 0;
            int a = h[0];
            if (a - i >= 0) {
                r = 1;
            } else {
                r = -1;
            }
            int cc = 0;
            for (int j = 0; j < n; j++) {
                if (a - i >= 0) {
                    if (r == 1 && h[j] - i < 0) {
                        r = -1;
                        cc++;
                    }
                    if (r == -1 && h[j] - i >= 0) {
                        r = 1;
                        cc++;
                    }
                } else {
                    if (r == 1 && h[j] - i < 0) {
                        r = -1;
                        cc++;
                    }
                    if (r == -1 && h[j] - i >= 0) {
                        r = 1;
                        cc++;
                    }
                }

            }
            if (a - i >= 0) {
                count += cc  / 2  + 1;
            } else {
                count += (cc + 1)  / 2 ;
            }
        }
        System.out.println(count);

    }

}

Measured memory_bytes: 21844
#include <stdio.h>

int main(){

  char s[4];
  int y=700;

  scanf("%s", s);

  if(s[0]=='o') y+=100;
  if(s[1]=='o') y+=100;
  if(s[2]=='o') y+=100;

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

  return 0;
}

Measured memory_bytes: 128
import sys
   
def dfs(i, t, l, a, b):
   t += 1
   a[i] = t
   for j in l[i]:
      if not a[j-1]:
         t = dfs(j-1, t, l, a, b)
   t += 1
   b[i] = t
   return t
   
   
n = input()
l=[]
for i in range(n):
   l.append([int(s) for s in sys.stdin.readline().split()[2:]])
a = [0] * n
b = [0] * n
t = 0
for i in xrange(n):
   if not a[i]:
      t = dfs(i, t, l, a, b)
   
for i in xrange(n):
   print i+1, a[i], b[i] 
 

 

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

#define ll long long

inline ll read() {
    ll x = 0, f = 1; char ch = getchar();
    for(; ch < '0' || ch>'9'; ch = getchar())
        if(ch == '-') f = -f;
    for(; ch >= '0' && ch <= '9'; ch = getchar())
        x = x * 10 + ch - '0';
    return x * f;
}

inline void chkmin( int &a, int b ) { if(a > b) a = b; }

inline void chkmax( int &a, int b ) { if(a < b) a = b; }

#define _ read()

#define ln endl

int main()
{
	ll n = _;
	ll ans = 2e18;
	for( ll i = 1; i * i <= n; i++ ) 
		if(n % i == 0 )
			ans = min(ans, i + n / i - 2);
	cout << ans << ln;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h> 
 
using namespace std;
 
#define len(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second	
#define int long long
#define double long double       
#define vec vector            
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double> 
#define beg begin
#define print(x) cout << x << endl;
 
#ifdef LOCAL
    #define dbg(x) cerr << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 

template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(2);
    solve();    
    return 0;
}
 
const int INF = 1e18, MAXN = 1e6, MOD = 1e9 + 7, BASE = 37;	

void solve() {
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 1; i < n; ++i) {
		int a = i, b = n - i;
		if (a < b) {
			cnt++;
		}
	}
	print(cnt);
}

Measured memory_bytes: 256
import java.util.*;

 class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long K = sc.nextLong();
        double p=0;
        
        for(int i=1;i<=N;i++) {
        	double k = 1.0/N;
        	for(int j=i;j<K;j=j*2){
        		k=k/2;
        	}
        	p=p+k;
        }
        System.out.println(p);
    }

}

Measured memory_bytes: 21844
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int c = a+b;
		
		if(c<=9) System.out.println(c);
		else System.out.println("error");

	}
}

Measured memory_bytes: 21844
from fractions import gcd
import numpy as np


def get_primes(n):
    ans = []
    m = int(n**0.5) + 1
    flags = np.zeros(m + 1, dtype=bool)
    for i in range(2, m + 1):
        if flags[i]:
            continue
        while n % i == 0:
            n //= i
        ans.append(i)
        flags[i:m + 1:i] = 1
    if n > 1 and all(map(lambda x: n % x, ans)):
        ans.append(n)
    return ans


def solve(string):
    a, b = map(int, string.split())
    g = gcd(a, b)
    return str(len([p for p in get_primes(g) if g % p == 0]) + 1)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 19516
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;
int mod = 1e9+7;
int inf = 1e18;
const int N = 5e5+999;
int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
int arr[N];
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
        map<int,vector<string>> mp;
        int n,m;
        cin>>n>>m;
        int x;
        string s;
        rep(i,0,m)
        {
            cin>>x>>s;
            mp[x].pb(s);
        }
        int right = 0,wrong = 0;
        for(auto x:mp)
        {
            int ct = 0;
            bool flag = false;
            for(auto xxx:mp[x.ff])
            {
                if(xxx=="AC")
                {
                    right++;
                    flag = true;
                    break;
                }
                else
                    ct++;

            }
            if(flag)
                wrong+=ct;

        }
        cout<<right<<" "<<wrong<<el;

    }
   return 0;
}


Measured memory_bytes: 15872
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
x = int(input())
#開業されたN個要素を受け付ける
#list = [input() for i in range(N)]

a=150
while a > -150:
    b=a-1
    while b > -150:
        if pow(a, 5) - pow(b, 5)==x:
            print(a, b)
            exit()
        b=b-1
    a=a-1


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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  ll x, y; cin >> x >> y;
  if (abs(x-y) <= 1) cout << "Brown\n";
  else cout << "Alice\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define sq(a) (a)*(a)
#define nitro std::ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define debug(x) std::cerr<<#x<<"="<<x<<'\n'
#define text std::cerr<<"SacredCoupoid08\n"
#define endl '\n'
#define all(c) (c).begin(),(c).end()
#define U 1000000007
#define N 100005
#define sz(c) (int)c.size()
typedef long long ll;
typedef std::vector< int > vi;
typedef std::pair<int, int> pi;
#define cin std::cin
#define cout std::cout
#define vector std::vector
#define pb push_back
#define pv(x) for(auto y:x)    cerr<<y<<" ";    cerr<<'\n';
#define fr first
#define sc second
#define ppb pop_back
#define max(a,b) a=max(a,b)
#define min(a,b) a=min(a,b)
#define int ll
#define tr(c,it) for(typeof(c.begin()) it= c.begin();it != c.end();it++)
signed main()
{		
	nitro;
	int VASU=1;
	//cin>>VASU;
	while(VASU--)
	{
		string a,b;
		cin>>a>>b;
		int n=sz(a),m=sz(b);
		rep(i,0,n)
		{
			if(a[i]!=b[i])
			{cout<<"No"<<endl;return 0;}
		}
		if(m==n+1)
		cout<<"Yes"<<endl;
		else
		{cout<<"No"<<endl;return 0;}
		
		
	}
	

	
	
	
	return 0;
}



Measured memory_bytes: 3640
n,m=map(int,input().split())
ans=[0 for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    ans[a]+=1
    ans[b]+=1
for i in range(n):
    if ans[i]%2==1:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 79588
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	int a,b;
	cin>>a>>b;
	cout<<max(a+b,max(2*a-1,2*b-1))<<endl;


	return 0;
}


Measured memory_bytes: 256
def solve():
    a, b, c, x = read()
    result = think(a, b, c, x)
    write(result)


def read():
    a = read_int(1)[0]
    b = read_int(1)[0]
    c = read_int(1)[0]
    x = read_int(1)[0]
    return a, b, c, x


def read_int(n):
    return list(map(int, read_line().split()[:n]))


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a, b, c, x):
    count = 0
    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                if 500 * i + 100 * j + 50 * k == x:
                    count += 1
    return count


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 39920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> using Graph = vector<vector<T>>;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'

int N;
int A[100005];

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

  cin >> N;
  ll ans = 0;
  rep(i, N) cin >> A[i];

  rep(i, N) {
    if (A[i]%2 && A[i + 1] > 0) {
      ans += 1;
      A[i] -= 1; 
      A[i + 1] -= 1;
    }
  }
  rep(i, N) {
    ans += A[i]/2;
    A[i] %= 2;
  }
  rep(i, N) {
    ll mn = min(A[i], A[i + 1]);
    ans += mn;
    A[i] -= mn;
    A[i + 1] -= mn;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
//Apparat : drobucs, aleonov, vit_72
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iomanip>
#include <algorithm>
#include <string>
#include <queue>
#include <numeric>

//#pragma warning(disable : 4996)
//#pragma GCC optimize("O3")

using namespace std;

#define nptr nullptr
#define all(x) (x).begin(), (x).end()
#define drobucs ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define ff first
#define ss second
#define pb push_back
#define sz(x) (int)(x).size()

typedef  long long ll;

const int maxn = (int)1e5 + 13;
const ll INFL = 9223372036854775807;
const ll INF = 2147483647;
const ll MOD = (int)1e9 + 7, MOD2 = 998244353;//1e9 + 21, 1e9 + 33, 1e9 + 87, 1e9 + 93
const ll base = 101, base2 = 37;


int main() {
	drobucs;
	
	ll n;
	cin >> n;
	if (n <= 26) {
		cout << (char)(n - 1 + 'a') << "\n";
		return 0;
	}
	string s = "";
	ll a = 1;
	while (n > pow(26, a)) n -= pow(26, a++);
	if (n == 0) {
		for (int i = 0; i < a - 1; ++i) {
			cout << "z";
		}
		return 0;
	}
	n--;
	for (int i = 0; i < a; ++i)s += 'a';
	for (int i = 0; i < sz(s); ++i) {
		while (s[i] <= 'z' && n >= pow(26, sz(s) - i - 1))
			n -= pow(26, sz(s) - i - 1), s[i]++;
	}
	
	cout << s + '\n';
	return 0;
}

Measured memory_bytes: 4028
#include "bits/stdc++.h"
#define ll long long
#define mk make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
using namespace std;
const int MAXN=1e5+9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a)
	{
		cout<<k<<endl;
		return 0;
	}
	if(a+b>=k)
	{
		cout<<a<<endl;
	}
	else
	{
		cout<<a-(k-a-b)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

using VLL = vector <long long>;
using VPILL = vector < pair<long long, int> >;
int N;
VLL X;
VLL Y;
VLL P;
VLL ans;
VLL defaultMinDist;
VPILL PX;
VPILL PY;
VPILL RPX;
VPILL RPY;
int xcho;
int ycho;

const long long INF = 1000000000LL * 1000000000LL;

void solve(int now, int chosen) {
    if (now == N) {
        VLL minDist(defaultMinDist);

        long long res = 0;
        long long lastX = -INF;
        long long lastY = -INF;
        long long rlastX = INF;
        long long rlastY = INF;

        for (int i = 0; i < N; ++i) {
            // x axis
            if (xcho & (1 << PX[i].second)) {
                lastX = PX[i].first;
            }

            minDist[PX[i].second] = min(minDist[PX[i].second], PX[i].first-lastX);

            // y axis
            if (ycho & (1 << PY[i].second)) {
                lastY = PY[i].first;
            }

            minDist[PY[i].second] = min(minDist[PY[i].second], PY[i].first-lastY);

            // x axis
            if (xcho & (1 << RPX[i].second)) {
                rlastX = RPX[i].first;
            }

            minDist[RPX[i].second] = min(minDist[RPX[i].second], rlastX-RPX[i].first);

            // y axis
            if (ycho & (1 << RPY[i].second)) {
                rlastY = RPY[i].first;
            }

            minDist[RPY[i].second] = min(minDist[RPY[i].second], rlastY - RPY[i].first);
        }

        for (int i = 0; i < N; ++i) {
            res += P[i] * minDist[i];
        }

        ans[chosen] = min(ans[chosen], res);
        return ;
    }

    solve(now+1, chosen);

    xcho |= (1<<now);
    solve(now+1, chosen+1);
    xcho &= ~(1<<now);

    ycho |= (1<<now);
    solve(now+1, chosen+1);
    ycho &= ~(1<<now);
}

int main() {
    cin >> N;

    X = VLL(N);
    Y = VLL(N);
    P = VLL(N);
    defaultMinDist = VLL(N, INF);

    PX = VPILL(N);
    PY = VPILL(N);

    for (int i = 0; i < N; ++i) {
        cin >> X[i] >> Y[i] >> P[i];
        PX[i] = make_pair(X[i], i);
        PY[i] = make_pair(Y[i], i);
        defaultMinDist[i] = min(defaultMinDist[i], min(abs(X[i]), abs(Y[i])));
    }

    ans = VLL(N+1, INF);
    xcho = 0;
    ycho = 0;

    sort(PX.begin(), PX.end());
    sort(PY.begin(), PY.end());

    RPX = PX;
    RPY = PY;

    reverse(RPX.begin(), RPX.end());
    reverse(RPY.begin(), RPY.end());

    solve(0, 0);

    for (int k = 0; k <= N; ++k) {
        cout << ans[k] << endl;
    }

    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#include <map>
#include <iostream>
int main()
{
	map<string, int> mp;
	int n;
	while (scanf("%d", &n) != EOF)
	{
		string str;
		int num = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> str;
			mp[str]++;
		}
		for (map<string, int>::iterator it = mp.begin(); it != mp.end();it++)
		{
			if (it->second % 2 == 1)
				num++;
		}
		printf("%d\n", num);
	}
	return 0;
}

Measured memory_bytes: 12544
import sys
input = sys.stdin.buffer.readline

def main():
    N,K = map(int,input().split())
    a = list(map(int,input().split()))
    f = list(map(int,input().split()))
    
    a.sort()
    f.sort(reverse=True)
    
    l,r = -1,max(a)*max(f)+1
    
    while r-l>1:
        mid = (r+l)//2
        count = 0
        for cost,dif in zip(a,f):
            if mid >= cost*dif:
                continue
            rest = cost*dif-mid
            count += -(-rest//dif)
        if count <= K:
            r = mid
        else:
            l = mid
            
    print(r)

if __name__ == "__main__":
    main()


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

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

  vector<string> S (N);
  for(int i = 0; i < N; ++i){
    char tmp[256];
    scanf("%s", tmp);
    S.at(i) = tmp;
  }
  sort(S.begin(), S.end());

  vector<int> cnts (N);
  cnts.at(0) = 1;
  int maxCnt = 1;
  int cnt = 1;
  for(int i = 1; i < N; ++i){
    if(S.at(i-1) == S.at(i)){
      cnt++;
    }else{
      cnt = 1;
    }
    if(maxCnt < cnt){
      maxCnt = cnt;
    }
    cnts.at(i) = cnt;
  }

  string s = "";
  for(int i = 0; i < N; ++i){
    if(cnts.at(i) == maxCnt){
      s = S.at(i);
      cout << s << endl;
    }
  }
}


Measured memory_bytes: 13696
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> [Int] -> Int
solve n hs = let
    initAccum = (0,-1,0) -- prev height, current count, max count
    updator currentHeight (prevHeight, currentCount, maxCount) =
        if currentHeight >= prevHeight
         then (currentHeight, currentCount + 1, max maxCount (currentCount+1))
        else
         (currentHeight, 0, maxCount)
    (_, _, maxC) = foldr updator initAccum hs
    in
    maxC
    

main = do
    n <- readInt
    hs <- readInts
    print $ solve n hs


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9+7;

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

  int n;
  cin >> n;
  int p[n+1];
  for(int i=1;i<=n;i++) cin >> p[i];
  int a[n+1],b[n+1];
  for(int i=1;i<=n;i++) {
    a[i]=(n+1)*i;
    b[i]=(n+1)*(n-i+1);
  }
  for(int i=1;i<=n;i++){
      a[p[i]] += i-1;
  }
  for(int i=1;i<=n;i++){
    cout << a[i] << " ";
  }
  cout << endl;
  for(int i=1;i<=n;i++){
    cout << b[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 896
r = []
while True:
    n = int(input())
    if n == 0:
        break
    p = []
    for i in range(n):
        p.append(int(input()))
    p.remove(min(p))
    p.remove(max(p))
    r.append(sum(p)//len(p))
[print(i) for i in r]

Measured memory_bytes: 7620
#include <bits/stdc++.h>
using namespace std;
string S;
bool canM(int a){
    return a > 0 && a <= 12;
}
int main(){
    cin >> S;
    int a = (S[0] - '0') * 10 + (S[1] - '0');
    int b = (S[2] - '0') * 10 + (S[3] - '0');

    if(canM(a) && canM(b))cout << "AMBIGUOUS\n";
    else if(canM(a))cout << "MMYY\n";
    else if(canM(b))cout << "YYMM\n";
    else cout << "NA\n";
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] x = new int[n];

        for (int i = 0; i < n; i++) {
            x[i] = in.nextInt();
        }

        long minTime = Long.MAX_VALUE;
        for (int i = 0; i <= n - k; i++) {
            minTime = Math.min(minTime, Math.abs(x[i]) + x[i + k - 1] - x[i]);
        }

        for (int i = n - 1; i >= k - 1; i--) {
            minTime = Math.min(minTime, Math.abs(x[i]) + x[i] - x[i - (k - 1)]);
        }

        System.out.println(minTime);

    }
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,a[200000],memo[200001],sum;
vector<int> ans;

signed main () {
    cin >> n;
    rep(i,n) cin >> a[i];
    for(int i=n;i>=2;--i) {
        int cnt=0;
        for(int j=i*2;j<=n;j+=i) cnt += memo[j];
        if (cnt%2 != a[i-1]) ans.pb(i), memo[i]++,sum++;
    }
    if (sum%2 != a[0]) ans.pb(1);
    sort(all(ans));
    cout << ans.size() << endl;
    rep(i,ans.size()) cout << ans[i] << endl;
}


Measured memory_bytes: 4852
N=int(input())
L=list(map(int,input().split()))
c={}
for i in set(L):
  c[i]=0
for i in L:
  c[i]+=1
s=sum([(i*(i-1))//2 for i in c.values()])
for i in L:
  print(s-c[i]+1)

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

string S[3];

int main() {
	cin >> S[0] >> S[1] >> S[2];
	cout << S[0][0] << S[1][1] << S[2][2] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,1,-1,-1};
const int INF = 1e8;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> Pii;
typedef pair<int,vi > P;
typedef unsigned long long ll;
char stage[52][52];
int H,W;
Pii rect[8][2];
vector < char > letter;
bool isRect(int c){
	reps(i,rect[c][0].fr,rect[c][1].fr+1){
		reps(j,rect[c][0].sc,rect[c][1].sc+1){
			if(stage[i][j]  == letter[c] || stage[i][j] == '*'){
				;
			}
			else{
				return false;
			}
		}
	}
	return true;
}
void fill(int c){
	reps(i,rect[c][0].fr,rect[c][1].fr+1){
		reps(j,rect[c][0].sc,rect[c][1].sc+1){
			stage[i][j] = '*';
		}
	}
}
int main(){
    int N;
    scanf("%d",&N);
    int x = 0;
    while(N--){
    	letter.clear();
    	rep(i,8){
    		rect[i][0] = Pii(INF,INF);
    		rect[i][1] = Pii(0,0);
    	}
        scanf("%d%d",&H,&W);
        bool alpha_memo[128] = {false};
        rep(i,H){
            scanf("%s",stage[i]);
            rep(j,W){
                alpha_memo[stage[i][j]] = true;
            }
        }
 		reps(i,'A','Z'+1){
            if(alpha_memo[i]){
                letter.PB(i);
            }
        }
        rep(c,letter.size()){
            rep(i,H){
            	rep(j,W){
            		if(stage[i][j] == letter[c]){
            			rect[c][0].fr = min(rect[c][0].fr,i);
            			rect[c][0].sc = min(rect[c][0].sc,j);
            			rect[c][1].fr = max(rect[c][1].fr,i);
            			rect[c][1].sc = max(rect[c][1].sc,j);
            				
            		}
            	}
            }
        }
        bool ans = true;
        int cnt = letter.size();
        while(cnt--){
        	rep(i,letter.size()){
        		if(isRect(i)){
        			fill(i);
        			/*puts("******");
		        	rep(i,H){
			        	rep(j,W){
			        		printf("%c",stage[i][j]);
			        	}
			        	puts("");
			        }*/
        		}
        	}
        }

        rep(i,H){
        	rep(j,W){
        		if(isalpha(stage[i][j])){
        			ans = false;
        			break;
        		}
        	}
        	if(!ans){
        		break;
        	}
        }
        ans ? puts("SAFE") : puts("SUSPICIOUS");
    }
    return 0;
}

Measured memory_bytes: 1196
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		if(M == 0){
			Console.WriteLine("Yes");
			return;
		}
		
		List<int>[] E = new List<int>[N];
		for(int i=0;i<N;i++) E[i] = new List<int>();
		
		int[] Ind = new int[N];
		for(int i=0;i<M;i++){
			E[L[i]].Add(i);
			Ind[R[i]]++;
		}
		
		long[] dist = new long[N];
		long minf = -(long) 1e18;
		var Q = new Queue<int>();
		for(int i=0;i<N;i++){
			dist[i] = minf;
			if(Ind[i] == 0 && E[i].Count > 0) Q.Enqueue(i);
		}
		
		if(Q.Count == 0){
			Console.WriteLine("No");
			return;
		}
		while(Q.Count > 0){
			var now = Q.Dequeue();
			foreach(var ni in E[now]){
				int nxt = R[ni];
				long Di = D[ni];
				if(dist[now] == minf && dist[nxt] == minf){
					dist[now] = 0;
					dist[nxt] = Di;
					Ind[nxt]--;
					if(Ind[nxt] == 0) Q.Enqueue(nxt);
				} else if(dist[now] == minf && dist[nxt] != minf){
					dist[now] = dist[nxt] - Di;
					Ind[nxt]--;
					if(Ind[nxt] == 0) Q.Enqueue(nxt);
				} else if(dist[now] != minf && dist[nxt] == minf){
					dist[nxt] = dist[now] + Di;
					Ind[nxt]--;
					if(Ind[nxt] == 0) Q.Enqueue(nxt);
				} else if(dist[now] != minf && dist[nxt] != minf){
					if(dist[now] + Di == dist[nxt]){
						Ind[nxt]--;
						if(Ind[nxt] == 0) Q.Enqueue(nxt);
					} else {
						Console.WriteLine("No");
						return;
					}
				}
			}
		}
		
		Console.WriteLine("Yes");
		
		
	}
	int N,M;
	int[] L,R;
	long[] D;
	public Sol(){
		
		var d = ria();
		N = d[0];
		M = d[1];
		if(M == 0) return;
		L = new int[M];
		R = new int[M];
		D = new long[M];
		
		for(int i=0;i<M;i++){
			d = ria();
			L[i] = d[0] - 1;
			R[i] = d[1] - 1;
			D[i] = d[2];
		}
		
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 30192
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
vector<int> each[30];
int n,bit[200000+1][30];
int z[700000+1];
string b[30];
void z_function(string S){
//	cout<<S<<endl;
	int len=S.length();
	S='$'+S;
	int l,r;
	memset(z,0,sizeof(z));
	rb(i,2,len)
		if(S[i]!=S[i-1]) break;
		else z[2]++;
	l=2,r=z[2]+1;
	rb(i,3,len){
		if(i<=r){
			z[i]=z[i-(l)+1];
			z[i]=min(z[i],r-i+1);
			if(z[i]+i-1==r){
				int ite=z[i]+1;
				rb(j,r+1,len){
					if(S[j]!=S[ite++]) break;
					z[i]++;
				}
				l=i,r=i+z[i]-1;
			}
		}
		else{
			int ite=1;
			rb(j,i,len){
				if(S[j]!=S[ite++]) break;
				z[i]++;
			}
			l=i,r=i+z[i]-1;
		}
	}
}
int a[200000+1],sb[200000+1];
void run(int is){
	string A="";
	rb(i,1,n)
		A+=char('0'+bit[i][is]);
	z_function(A+'&'+b[is]+b[is]);
	rb(i,n+3,n+2+n){
		if(z[i]==n){
			each[is].PB(n+2+n-i);
		}
	}
	rb(i,1,n)
		if(A[i-1]=='0') A[i-1]='1';
			else A[i-1]='0';
	z_function(A+'&'+b[is]+b[is]);
	rb(i,n+3,n+2+n){
		if(z[i]==n){
			each[is].PB(n+2+n-i);
		}
	}
}
int main(){
	fastio;
	cin>>n;
	rb(i,1,n)
	{
		int ai;
		cin>>ai;
		a[i]=ai;
		rep(j,30)
		{
			bit[i][j]=bool(ai&(1<<j));
		}
	}
	rep(i,30)
		b[i]="";//return 0;
	rb(i,1,n){
		int bi;
		cin>>bi;
		sb[i]=bi;
		rep(j,30){
			b[j]+=char('0'+(bool)(bi&(1<<j)));
		}
	}
	rep(i,30){
		run(i);
		sort(ALL(each[i]));
	}
	rep(i,n){
		int ok=1;
		rep(j,30){
			if(binary_search(ALL(each[j]),i)){
				
			}
			else ok=0;
		}	if(ok) cout<<i<<" "<<(a[1+i] ^ sb[1])<<endl;
	}
	return 0;
}


Measured memory_bytes: 62824