akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; string s;
    cin >> n >> s;
    vector<pair<int, int>> vals;
    vector<string> mx(n + 1);
    vector<int> go(2 * n);
    vector<int> label(2 * n);
    int it1 = 0, it2 = 0;
    while(it1 != 2 * n && it2 != 2 * n){
        while(s[it1] != 'a') it1++;
        while(s[it2] != 'b') it2++;
        vals.emplace_back(min(it1, it2), max(it1, it2));
        go[it1] = it2, go[it2] = it1;
        it1++, it2++;
    }
    sort(vals.begin(), vals.end());
    for(int i = 0; i < n; i++){
        label[vals[i].first] = i;
        label[vals[i].second] = i;
    }
    for(int loc = n - 1; loc >= 0; loc--){
        int st = vals[loc].first, ed = vals[loc].second;
        int last = st;
        if(s[st] == 'b'){
            int cut = ed;
            while(last != cut){
                cut = max(cut, go[last]);
                last++;
            }
            if(go[last] > last) last--;
        }
        else{
            last = ed;
        }
        string fin = "";
        if(s[st] == 'a'){
            fin = "ab";
        }
        else{
            for(int i = st; i <= last; i++){
                if(s[i] == 'a' && go[i] < st) continue;
                fin += s[i];
            }
        }
        int nxt = -1;
        for(int i = last + 1; i < 2 * n; i++){
            if(go[i] > i){
                nxt = i;
                break;
            }
        }
        if(nxt != -1) fin += mx[label[nxt]];
        mx[loc] = max(mx[loc + 1], fin);
    }
    cout << mx[0] << '\n';
    return 0;
}
	

Measured memory_bytes: 12124
import numpy as np
n, m = [int(i) for i in input().split()]
a =[]
d = 1000000007

for i in range(m):
    a1=int(input())
    a.append(a1)

a.append(n+1)
a = np.array(a)
#print(a)

if 1 in a[1:]-a[:-1]:
    print(0)

else:
    dp = [0]*110000
    dp[1]=1
    dp[2]=1
    for i in range(3,len(dp)):
        dp[i]=dp[i-1]+dp[i-2]
        dp[i]=dp[i]%d

    ans = []
    pre = 0
    for i in range(len(a)):
        if i == 0:
            ans.append(a[i]-pre)
        else:
            ans.append(a[i]-pre-1)
        pre = a[i]

    #print(ans)

    if m == 0:
        print(dp[n+1])
    else:
        x = 1
        for i in ans:
            x = x*dp[i]%d
        print(x)

Measured memory_bytes: 18820
#include<bits/stdc++.h>
#define U [7<<15]={}
#define G )+((c=A[a]+A[P[a]]+C[a])%k?c:0)-M(
typedef long long L;using namespace std;map<L,L>T U;
L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;
L M(L f){return f?B[f]+M(f^f&-f):0;}
L S(L a,L i){for(a=M(i++G i);i<2e5;i+=i&-i)B[i]+=a;}
L D(L f){L d;Z[f]=1;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)
  d=I->first,!Z[d]?P[d]=f,E[d]=E[f]+1,C[d]=I->second,D(d),Z[f]+=Z[d],!H[f]|Z[H[f]]<Z[d]?H[f]=d:0:0;}
L K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}
main(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
       for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)for(;!b|a;S(a=H[a],O[a]=++b))X[a]=n;
       for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}

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


def gcd(n, m):
    if n < m:
        temp = n
        n = m
        m = temp
    
    def ecd(n, m):
        if n % m == 0:
            return m
        else:
            temp = n % m
            a = ecd(m, temp)
        return a
           
    return ecd(n, m)

temp = gcd(A[0], A[1])
for i in range(0, N-1):
    temp = gcd(temp, A[i])
    
print(temp)

Measured memory_bytes: 14228
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <sstream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define EPS 1e-12
#define pri_max 60000
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

/*
bool memo[pri_max] = {};
vector<int> pri;
void calc()
{
	for (int i = 2; i < pri_max; i++)
	{
		if (memo[i] == false)
		{
			pri.push_back(i);
			for (int l = i; l < pri_max; l += i)
			{
				memo[l] = true;
			}
		}
	}
}*/

int main()
{
	int q;
	while (cin >> q&&q != -1)
	{
		double x = (double)q / 2.0;
		while (fabs(x*x*x - q) >= 0.00001*q)
		{
			x = x - (x*x*x - q) / (3 * x*x);
		}
		printf("%.6f\n", x);
	}
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N;
  vector<llong> ans;

  cin >> N;
  ans.resize(N);
  for (int in, i = 0; i < N-1; ++i) {
    cin >> in;
    ans[in-1]++;
  }
  
  for (auto &a: ans) {
    cout << a << endl;
  }

  return 0;
}

Measured memory_bytes: 4844
A,B,C,X,Y = map(int,input().split())
x = 0
y = 0
pay = 0
if X == Y:
  pay = min(A*X+B*Y,2*C*X)
elif X > Y:
  pay = min(A*X+B*Y,2*C*Y+A*(X-Y),2*C*X)
else:
  pay = min(A*X+B*Y,2*C*X+B*(Y-X),2*C*Y)
print(pay)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 6 + 3

# 階乗たくさん使う時用のテーブル準備
# MAX：階乗に使う数値の最大以上まで作る
def init_fact_inv(MAX: int, MOD: int) -> list:
    # 階乗テーブル
    factorial = [1] * MAX
    factorial[0] = factorial[1] = 1
    for i in range(2, MAX):
        factorial[i] = factorial[i-1] * i % MOD
    # 階乗の逆元テーブル
    inverse = [1] * MAX
    # powに第三引数入れると冪乗のmod付計算を高速にやってくれる
    inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
    for i in range(MAX-2, 0, -1):
        # 最後から戻っていくこのループならMAX回powするより処理が速い
        inverse[i] = inverse[i+1] * (i+1) % MOD
    return factorial, inverse

fact, inv = init_fact_inv(MOD, MOD)

Q=INT()
for i in range(Q):
    x,d,n=MAP()

    # 例外処理
    if x==0:
        print(0)
        continue
    if d==0:
        print(pow(x, n, MOD))
        continue
    
    invd=pow(d, MOD-2, MOD)
    l=(x*invd-1)%MOD
    r=l+n

    # 例外処理
    if r>=MOD:
        print(0)
        continue

    print(fact[r]*inv[l]*pow(d, n, MOD)%MOD)


Measured memory_bytes: 84936
#include <bits/stdc++.h>
using namespace std;
using  unll = unsigned long long;

int main() {
  int h,w;
  cin >> h >> w;
  vector<string> c(h);
  for(int i=0;i<h;i++){
    cin >> c.at(i);
  }
  for(int i=0;i<h;i++){
    cout << c.at(i) << endl;
    cout << c.at(i) << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

K = INT()

N = 50
d, m = divmod(K, N)
# 初期位置を決める
base = N - 1 + d
A = [base] * N
# 残りは逆操作をシミュレーション
for i in range(m):
    k = A.index(min(A))
    for j in range(N):
        if j == k:
            A[j] += N
        else:
            A[j] -= 1

print(len(A))
print(*A)


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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 100005
#define ALL(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;


int32_t main()
{
    IOS;

    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        string s; cin>>s;
		int cnt = 0;
		int l = 0;
		int r = s.size() - 1;
		while (l < r) if(s[l++] != s[r--]) cnt++;
		
		cout<<cnt;
		cout<<endl;
    }
    return 0;

}


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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int,int>;
using vMii = vector<Mii>;
using Si = set<int>;
using vSi = vector<Si>;
using vvSi = vector<vSi>;

#define fi first
#define se second
#define INF 1e9 + 5
#define mod(a,m) (a%m+m)%m
#define PB push_back
#define MP make_pair

int toMap(int a, int b) {
	return 1000 * min(a, b) + max(a, b);
}

int main(){
//	cout.setf(ios::fixed);
//	cout.precision(4);
	int n;
	const int MX = 1000001;
	while (cin >> n) {
		vvi G(MX);
		vi ind(MX, 0);
		for (int i = 0; i < n; ++i) {
			int last;
			cin >> last;
			last--;
			for (int j = 1; j < n-1; ++j) {
				int next;
				cin >> next;
				next--;
				int ear = toMap(i, last);
				int lat = toMap(i, next);
				G[ear].push_back(lat);
				last = next;
				ind[lat]++;
			}
		}
		int day = 0;
		int proc = 0;
		vi tbr;
		for (int i = 0; i < MX; ++i) {
			if(ind[i] == 0) tbr.push_back(i);
		}
		while(not tbr.empty()) {
			day++;
			proc += int(tbr.size());
			vi next_tbr;
			for (int x : tbr) {
				for (int y : G[x]) {
					ind[y]--;
					if(ind[y] == 0) next_tbr.push_back(y);	
				}
			}
			tbr = next_tbr;
		}
		cout << (proc == MX? day : -1) << '\n';
	}
}



Measured memory_bytes: 45432
#include<stdio.h>//??£????????????
 
void mincount();
int n,m[100][100],r[100];
 
main(){
  int c[100],i;
  scanf("%d",&n);//??\???????????????????????????????????° n
  for( i=0 ; i<n ; i++ ){
    scanf("%d%d", &r[i], &c[i]);//?????? Mi(i=1...n)????¬????????????????????????????????????´??° r ????????????????????°???c ????????????????????°?????¨???????????? 
    if( i==n-1 ) r[i+1] = c[i];
  }
  mincount();
  printf("%d\n",m[1][n]);//????°?????????°??????????????????????????????????????? 
  return 0;
}
 
void mincount(){
  int q,i,j,k,l;
  for( i=0 ;  i<n+1 ; i++ ) m[i][i]=0;
  for( l=2 ; l<n+1 ; l++ ){
    for( i=1 ; i<n-l+2 ; i++ ){
      j = i+l-1;
      m[i][j]=1000000;
      for(k = i ; k < j ; k++){
    q = m[i][k] + m[k+1][j] + r[i-1] * r[k] * r[j];
    if( m[i][j]>q ) m[i][j] = q;
      }
    }
  } 
}

Measured memory_bytes: 636
N = int(input())
A = list(map(int, input().split()))
dictA = {}
for x in A:
    dictA[x] = 0
for x1 in A:
    dictA[x1] += 1

combisum = 0
for y in dictA.values():
    combisum += y * (y - 1) // 2

for z in range(N):
    print(combisum - dictA[A[z]] + 1)


Measured memory_bytes: 88140
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main(){
    string S;
    int x,y;
    cin >> S >> x >> y;
    int MAX = S.size() * 2 + 10;
    vector<vector<int>> dpx(S.size()/2+10, vector<int>(MAX,-1));
    vector<vector<int>> dpy(S.size()/2+10, vector<int>(MAX,-1));
    vector<int> xarr,yarr;
    int cur = 0;
    bool nextisx = true;
    for(auto i = S.begin();i != S.end();i++){
        switch(*i){
            case 'F':
                cur++;
                break;
            case 'T':
                if(nextisx)xarr.push_back(cur);
                else yarr.push_back(cur);
                nextisx = !nextisx;
                cur = 0;
                break;
        }
    }
    if(nextisx)xarr.push_back(cur);
    else yarr.push_back(cur);
    if(yarr.size() == 0)yarr.push_back(0);
    // for(int i = 0;i < xarr.size();i++){
    //     cout << xarr[i] << " ";
    // }
    // cout << endl;
    // for(int i = 0;i < yarr.size();i++){
    //     cout << yarr[i] << " ";
    // }
    
    dpx[0] = vector<int>(MAX,0);
    dpy[0] = vector<int>(MAX,0);
    dpx[0][MAX/2+xarr[0]] = 1;
    dpy[0][MAX/2+yarr[0]] = 1;
    dpy[0][MAX/2-yarr[0]] = 1;
    for(int i = 1;i < max(xarr.size(), yarr.size());i++){
        for(int j = 0;j < MAX;j++){
            if(i < xarr.size()){
                int curx = xarr[i];
                bool a=false,b=false;
                if(j-curx >= 0){
                    a = dpx[i-1][j-curx];
                }
                if(j+curx < MAX){
                    b = dpx[i-1][j+curx];
                }
                dpx[i][j] = a || b;
            }
            if(i < yarr.size()){
                int cury = yarr[i];
                bool a=false,b=false;
                if(j-cury >= 0){
                    a = dpy[i-1][j-cury];
                }
                if(j+cury < MAX){
                    b = dpy[i-1][j+cury];
                }
                dpy[i][j] = a||b;
            }

        }
    }
    // for(int i = 0;i < dpx.size();i++){
    //     for(int j = 0;j < dpx[0].size();j++){
    //         cout << dpx[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // for(int i = 0;i < dpy.size();i++){
    //     for(int j = 0;j < dpy[0].size();j++){
    //         cout << dpy[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << ((dpx[xarr.size()-1][MAX/2+x] && dpy[yarr.size()-1][MAX/2+y]) ? "Yes" : "No") << endl;
    

}

Measured memory_bytes: 502272
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		//ツカツδ可ーツ表
		int [][] color = {{0,0,0},{0,0,255},{0,255,0},{0,255,255},
				{255,0,0},{255,0,255},{255,255,0},{255,255,255}};
		String [] colorName = {"black","blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

		while(true){
			if(n.equals("0")){
				break;
			}
			//ツ禿シツ療債値ツづー10ツ進ツ陛渉環キツつキツづゥ
			int [] nowColor = new int[6];
			for(int i=0; i < nowColor.length; i++){
				if(n.charAt(i+1) - 'a' >= 0){
					nowColor[i] = (n.charAt(i+1) - 'a') + 10;
				}
				else{
					nowColor[i] = n.charAt(i+1) - '0';
				}
			}

			//RGBツづ可つキツづゥ
			int [] nowRGB = new int[3];
			for(int i = 0; i < nowRGB.length; i++){
				nowRGB[i] = nowColor[i*2] << 4 | nowColor[i*2+1];
			}

			//d_kツづーツ仰づ淞、ツ催渉ャツ値ツづーindexツづーツ仰づ淞づゥ
			double min  = Math.pow(nowRGB[0], 2)+ Math.pow(nowRGB[1], 2) + Math.pow(nowRGB[2], 2);
			min = Math.sqrt(min);
			int index = 0;
			for(int i=1; i < color.length; i++){
				double now = Math.pow(color[i][0]-nowRGB[0], 2)+ Math.pow(color[i][1]-nowRGB[1], 2) +
					Math.pow(color[i][2]-nowRGB[2], 2);
				now = Math.sqrt(now);
				if(min > now){
					min = now;
					index = i;
				}
			}

			//ツ出ツ療債つキツづゥ
			System.out.println(colorName[index]);

			n = sc.next();
		}


	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();

	}

}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
 
       ll a[5];
       int n,ans;
       for(int i=0;i<5;i++)
           {
               cin>>n;
               if(n==0)
               cout<<i+1;
           }
 
 return 0;
}
 

Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define rep(i, l, r ) for(register int i = l; i <= r; ++ i)
using namespace std;
inline int read()
{
	char cc = getchar(); int cn(0), flus(1);
	while(cc > '9' || cc < '0') {if(cc == '-') flus = -flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = (cn << 1) + (cn << 3) + cc - '0'; cc = getchar();}
	return flus * cn;
}
const int N = 10010;
signed main()
{
	int a[4];
	a[1] = read();
	a[2] = read();
	a[3] = read();
	sort(a + 1, a + 4);
	if(a[1] == a[2])
	{
		if(a[3] != a[1])
		{
			printf("Yes\n");
			return 0;
		}
		else printf("No\n");
		return 0;
	}
	else if(a[2] == a[3])
	{
		if(a[1] != a[2])
		{
			printf("Yes\n");
			return 0;
		}
		else printf("No\n");
		return 0;
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>


using namespace std;
int main() {
	char c[101];
	int i = 0;
	int K;
	vector<int>N(102, 0);
	long long count = 0;
	cin >> c;
	for (i = 0; c[i] != 0; i++) {
		N[i] = c[i] - 48;
	}
	//N:i��
	cin >> K;
	int dp[101][2][4] = {0};//��,�ŏ�,0�ȊO������o����
	dp[0][0][0] = 1;
	dp[0][0][1] = N[0] - 1;
	dp[0][1][1] = 1;
	for (int j = 1; j < i; j++) {
		dp[j][0][0] = dp[j - 1][0][0] + dp[j - 1][1][0]*(!!N[j]);
		dp[j][0][1] = dp[j - 1][0][0] * 9 + dp[j - 1][0][1] + dp[j - 1][1][1] * (!!N[j]);
		dp[j][0][2]= dp[j - 1][0][1] * 9 + dp[j - 1][1][1] * (!!N[j])*(N[j]-1) + dp[j - 1][0][2]  + dp[j - 1][1][2] * (!!N[j]);
		dp[j][0][3] = dp[j - 1][0][2] * 9 + dp[j - 1][1][2] *(!!N[j]) * (N[j] - 1) + dp[j - 1][0][3] + dp[j - 1][1][3] * (!!N[j]);
		dp[j][1][1] =  dp[j - 1][1][1]*(!N[j]);
		dp[j][1][2] = dp[j - 1][1][1] * (!!N[j]) + dp[j - 1][1][2] * (!N[j]);
		dp[j][1][3] = dp[j - 1][1][2] * (!!N[j]) + dp[j - 1][1][3] * (!N[j]);
	}
	cout << dp[i - 1][1][K] + dp[i - 1][0][K] << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var (
		n int
		s string
	)
	fmt.Scan(&n, &s)

	xm := make(map[rune]int)
	for _, r := range s {
		xm[r]++
	}

	const mod = 1000000007
	ans := 1
	for _, v := range xm {
		ans *= v + 1
		ans %= mod
	}
	fmt.Println(ans - 1)
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int N; cin >> N;
  for(int i=1;i<=3500;i++){
    for(int j=1;j<=3500;j++){
      if(4*i*j-N*j-N*i>0 && (N*i*j)%(4*i*j-N*j-N*i)==0){
        cout << i << " " << j << " " << (N*i*j)/(4*i*j-N*j-N*i) << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back



int main() {
    char data[3][3];
    while(cin>>data[0][0]){
        if(data[0][0]=='0')break;
        rep(i,3){
            rep(j,3){
                if(i!=0 || j!=0){
                    cin>>data[i][j];
                }
            }
        }
        
        
        rep(i,3){
            if(data[i][0]==data[i][1] && data[i][1]==data[i][2] && data[i][0]!='+'){
                cout<<data[i][0]<<endl;
                goto next;
            }
        }

        rep(j,3){
            if(data[0][j]==data[1][j] && data[1][j]==data[2][j] && data[0][j]!='+'){
                cout<<data[0][j]<<endl;
                goto next;
            }
        }

        if( ( (data[0][0]==data[1][1] && data[1][1]==data[2][2]) || (data[0][2]==data[1][1] && data[1][1]==data[2][0]) ) && data[1][1]!='+'){
            cout<<data[1][1]<<endl;
            goto next;
        }
        
        
        cout<<"NA"<<endl;
        next:;
    }
    
    
    return 0;
}

Measured memory_bytes: 1132
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;
 
int main(){
  int N;
  cin >> N;
  int A[N], B[N], C[N-1];
  for(int i = 0;i<N;i++){
    cin >> A[i];
  }
  int64_t ans = 0;
  for(int i = 0;i<N;i++){
    cin >> B[i];
    ans += B[i];
  }
  for(int i = 0;i<N-1;i++){
    cin >> C[i];
  }
  for(int i=1;i<N;i++){
    if(A[i] - A[i-1] == 1){
      ans += C[A[i-1]-1];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1e9 + 7;

// Union-Find木
// 初期化 UF(N); Nは要素数
// 結合 unite(x,y); 同じ集合か判定 same(x,y);
// 集合の数 count
struct UnionFind {
  vector<ll> par, sizes;
  ll cnt;
  UnionFind(ll N) : par(N), sizes(N, 1), cnt(N) {
    for (ll i = 0; i < N; i++) par[i] = i;
  }

  ll find(ll x) { return par[x] == x ? x : par[x] = find(par[x]); }

  bool same(ll x, ll y) { return find(x) == find(y); }

  ll size(ll x) { return sizes[find(x)]; }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
    cnt--;
  }

  ll count() const { return cnt; }
};

int main() {
  ll n, w;
  cin >> n >> w;

  vll vs(n);
  vll ws(n);
  rep(i, n) { cin >> vs[i] >> ws[i]; }

  vvll dp(n + 1, vll(w + 1, 0));
  rep(i, n) {
    rep(j, w + 1) {
      ll cond = j - ws[i] >= 0;
      if (cond) {
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - ws[i]] + vs[i]);
      } else {
        dp[i + 1][j] = dp[i][j];
      }
    }
  }

  cout << dp[n][w] << endl;

  return 0;
}



Measured memory_bytes: 10828
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
long double F[3005][3005],A[3005],ans;
int i,j,n;
int main()
{
    cin >> n;
    for (i =1 ; i <= n; i++) {
        cin >> A[i];
    }
    F[0][0]=1;
    for (i = 1; i <= n; i++)
    {
        F[i][0]=F[i-1][0] * (1-A[i]);
        for ( j = 1; j <= i; j++)
        {
            F[i][j]=F[i-1][j] * (1-A[i]) + F[i-1][j-1] * A[i];
        }
    }
    for (i = n/2+1; i <= n; i++) {
        ans += F[n][i];
    }
    cout << setprecision(10) << fixed << ans;
    return 0;
}


Measured memory_bytes: 139392
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
n=int(input())
a=[int(input())for _ in range(n-1)]
def dfs(v):
  d=[dfs(i)for i in t[v]]
  d.sort()
  l=len(d)
  ans=0
  for i,j in enumerate(d):
    ans=max(ans,l-i+j)
  return ans
t=[[]for _ in range(n+1)]
for i in range(n-1):
  t[a[i]-1].append(i+1)
print(dfs(0))

Measured memory_bytes: 231980
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const int MAX = 1e5+5;

int h, w;

struct UnionFind
{
	vector<int> p;
	vector<int> s;
	UnionFind(int n) : p(n),s(n,1) {
		for (int i = 0; i < n; i++) {
			p[i] = i;
		}
	}

	int root(int x) {
		int px = p[x];
		if (px == x) {
			return x;
		}

		p[x] = root(px);
		return p[x];
	}

	
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);

		if (rx == ry) {
			return;
		}

		p[rx] = ry;
		s[ry] += s[rx];
		return;


	}
	bool isSame(int x, int y) {
		return root(x) == root(y);
	}

	int size(int x) {
		return s[root(x)];
	}
};

int to1d(int x, int y) {
	return x * w + y;
}

int main() {
	
	
	cin >> h >> w;

	int n = h * w;
	vector<string> s(h);
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}

	UnionFind uf(n);

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {

			if (i > 0) {

				if ((s[i][j] == '#') ^ (s[i - 1][j] == '#')) {
					uf.unite(to1d(i, j), to1d(i - 1, j));
					//cout << i << " " << j << endl;
				}
			}

			if (j > 0) {
				if ((s[i][j] == '#') ^ (s[i][j - 1] == '#')) {
					uf.unite(to1d(i, j), to1d(i, j - 1));
					//cout << i << " " << j << endl;
				}
			}
			//cout << convert(i, j) << endl;

		}
	}

	map<int, int> m;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int r = uf.root(to1d(i,j));
			//cout << uf.s[to1d(i, j)] << endl;
			if (m.find(r) == m.end()) {
				m[r] = uf.size(r);
				
			}

			if (s[i][j] == '#') {
				m[r]--;
			}
		}
	}

	/*
	for (auto it = m.begin(); it != m.end(); it++) {
		cout << it->first << " " << it->second << endl;
	}
	*/
	
	ll ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int r = uf.root(to1d(i, j));

			if (s[i][j] == '#') {
				ans += m[r];
			}
		}
	}


	cout << ans << endl;
}

Measured memory_bytes: 11096
#include<bits/stdc++.h>
 
using namespace std;
 
#define D(x) cout << (#x) << " is " << x << endl;
#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
 
 
int main()
{
    int n;
    cin >> n;
    int ck=0, cnt=0;
    while(n--){
		int a, b;
		cin >> a >> b;
		if(a == b){
			cnt++;
		}
		else{
			cnt = 0;
		}
		if(cnt >= 3) ck = 1;
	}
	if(ck){
		cout << "Yes\n";
	}
	else cout << "No\n";
 
    return 0;
}


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

int main(){
   FILE*fi,*fout;
   int a,b,c;
   //fi=fopen("A.in" ,"r");
   //fout=fopen("A.out" ,"w");
   fi=stdin;
   fout=stdout;
   fscanf(fi,"%d%d%d" ,&a,&b,&c);
   if(a<=c&&c<=b)
     fprintf(fout,"Yes\n");
   else
     fprintf(fout,"No\n");
   //fclose(fi);
   //fclose(fout);
   return 0;
}


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

using namespace std;

using ll = long long;

const long long MOD = 1e9+7;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

void ALLOUT_NUMBER(vector<ll> V)
{
    ll N = V.size();
    for(ll i=0;i<N;i++)
    {
        cout << V[i];
        if(i<N-1) cout << ' ';
    }
    cout << endl;
}

class Mll
{
    public:
    ll x;

    Mll() : x(0){}
    Mll(ll x=0) : x((x%MOD+MOD)%MOD){}

    Mll operator-() const
    {
        return Mll(-x);
    }

    Mll& operator+=(const Mll& A)
    {
        if((x += A.x) >= MOD) x -= MOD;
        return *this;
    }
    Mll& operator-=(const Mll& A)
    {
        if((x += MOD - A.x) >= MOD) x -= MOD;
        return *this;
    }
    Mll& operator*=(const Mll& A)
    {
        (x *= A.x) %= MOD;
        return *this;
    }
    
    Mll operator+(const Mll& A)
    {
        Mll res(*this);
        return res+=A;
    }
    Mll operator-(const Mll& A)
    {
        Mll res(*this);
        return res-=A;
    }
    Mll operator*(const Mll& A)
    {
        Mll res(*this);
        return res*=A;
    }
    
    Mll pow(ll t) const // t乗
    {
        if(t==0) return 1;
        Mll A = pow(t>>1);
        A *= A;
        if(t&1) A *= *this;
        return A;
    }

    // for prime mod
    Mll inv() const
    {
        return pow(MOD-2);
    }
    Mll& operator/=(const Mll& A)
    {
        return (*this) *= A.inv();
    }
    Mll operator/(const Mll& A) const
    {
        Mll res(*this);
        return res/=A;
    }

    friend ostream& operator<<(ostream& os, const Mll& M)
    {
        os << M.x;
        return os;
    }
};

vector<Mll> ALLIN_MLL(ll N)
{
    vector<ll> numbers_ll(N);
    ALLIN1_NUMBER(numbers_ll);

    vector<Mll> numbers_Mll;
    for(ll i=0;i<N;i++)
    {
        Mll add(numbers_ll[i]);
        numbers_Mll.push_back(add);
    }

    return numbers_Mll;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

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

    vector<ll> a(N);
    ALLIN1_NUMBER(a);

    ll ret = 0;

    for(ll i=0;i<N;i++)
    {
        if(i%2==0 && a[i]%2==1)
        {
            ret++;
        }
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 3720
#include<stdio.h>
#define MOD (1000000000+7)
#define MAX (1000000*2+5)
long fac[MAX];
long inv[MAX];
long finv[MAX];

void COMinit(){
    fac[0]=1;
    fac[1]=1;
    finv[0]=1;
    finv[1]=1;
    inv[1]=1;
    for(long i=2;i<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;
    }
}

long COM(long n,long k){
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  int x,y;
  scanf("%d %d",&x,&y);
  if((2*y-x)%3!=0 || (2*x-y)%3!=0)
      printf("0");
  else{
      long n=(2*y-x)/3;
      long m=(2*x-y)/3;
      if(n<0 || m<0)
        printf("0");
      else{
        COMinit();
        printf("%ld\n",COM(n+m,n));
      }
  }
  return 0;
}

Measured memory_bytes: 46976
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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 long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  stack<char> st;
  string s;
  int n;
  cin>>n>>s;
  rep(i,n)
  {
    char c;
    c=s[i];
    if(!st.empty()&&st.top()=='('&&c==')')st.pop();
    else st.push(c);
  }
  while(!st.empty())
  {
    if(st.top()=='(')s+=")";
    else s="("+s;
    st.pop();
  }
  cout<<s<<endl;


  return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {    
    public static void main(String[] args) { 
        Scanner in = new Scanner(System.in);
      	int n = in.nextInt(),zero=0;
        long[] arr = new long[n];
        long ans = 1;
        for(int i=0;i<n;++i) {
            arr[i] = in.nextLong();
            if(arr[i]==0) zero=1;
        }
        if(zero==1) {
            System.out.println("0");
            return ;
        }
        
        for(int i=0;i<n;++i) {
            if(ans <= 1000000000000000000L/arr[i]) ans = ans*arr[i];
            else {
                System.out.println("-1");
                return;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 61196
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

void solve(ll n){
	ll ans=0;
	vl v(201);
	rep(i,v.size())v[i]=i*i;
	rep(i,201){if(v[i]>n)break;
		range(j,i,201){if(v[i]+v[j]>n)break;
			range(k,j,201){if(v[i]+v[j]+v[k]>n)break;
				range(l,k,201){if(v[i]+v[j]+v[k]+v[j]>n)break;
					if(v[i]+v[j]+v[k]+v[l]==n)ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	while(cin>>n,n)solve(n);
}


Measured memory_bytes: 3128
N = int(input())
X = list(map(int, input().split()))

"""
    min(X) 以上、 max(X) 以下の整数を全探索
    1 <= X[i] <= 100 なので時間計算量は O(N(Xmax - Xmin)) <= O(N^2)
"""

X.sort()
ans = 10 ** 12
# for p in range(X[0], X[N - 1] + 1):
for p in range(1, 101):
    total = 0
    for x in X:
        total += (x - p)** 2
    ans = min(ans, total)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int dp[3001][3001];

void calc(string s, string t){
	for(int i=0;i<s.length()+1;i++){
		for(int j=0;j<t.length()+1;j++){
			if(i==0 || j==0){
				dp[i][j]=0;
			}else if(s[i-1]==t[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
			}else{
				dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
			}
			//cout<<dp[i][j]<<" ";
		}//cout<<endl;
	}
}

int main()
{
	string s,t;
	cin>>s;
	cin>>t;
	calc(s,t);
	string ans="";
	int i=s.length(), j=t.length();
	while(i>0&&j>0){
		if(dp[i][j]==dp[i-1][j]){
			i--;
		}else if(dp[i][j]==dp[i][j-1]){
			j--;
		}else{
			i--;
			j--;
			ans=s[i]+ans;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 38804
a1,b1 = map(int,input().split())
a2,b2 = map(int,input().split())
a3,b3 = map(int,input().split())

ls = [a1,b1,a2,b2,a3,b3]

ans = "YES"
for i in range(1,5,1):
  if ls.count(i) == 3:
    ans ="NO"
print(ans)

Measured memory_bytes: 3064
{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes,TupleSections #-}
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace
import Text.Printf

import Data.List
import Data.Int
import Data.Bits
import Data.Maybe
import Data.Monoid
import Data.Array.Unboxed
import Data.Array.ST
import Data.Array.Base
import Data.Function(on)
import Data.Tuple(swap)
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
    n <- readLn :: IO Int
    as <- readInts
    let score i = sum [ (a - i)^(2 :: Int) | a <- as ]
    let x = minimum as
        y = maximum as
    print $ minimum $ map score [x..y]


-- IO
readInt :: B.ByteString -> Int
readInt = fromJust . fmap fst . B.readInt
readInts :: IO [Int]
readInts = map readInt . B.words <$> B.getLine
readIntPair :: IO (Int,Int)
readIntPair = l2p . map readInt . take 2 . B.words <$> B.getLine
readAllInts :: IO [[Int]]
readAllInts = map (map readInt . B.words) . B.lines <$> B.getContents
readLns :: Read a => IO [a]
readLns = map read . words <$> getLine

-- Utilities
l2p :: [a] -> (a,a)
l2p (a:b:_) = (a,b)
l2p _ = error "l2p: the input list is too short"
p2l :: (a,a) -> [a]
p2l (a,b) = [a,b]
itof :: Int -> Double
itof = fromIntegral
inf :: Int
inf = maxBound `div` 2

-- Monad
stepM_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m ()
stepM_ i0 judge incr step = sub i0 where 
    sub i | judge i = step i >> sub (incr i) 
          | otherwise = return ()
rep_ :: Monad m => Int -> (Int -> m ()) -> m ()
rep_ n = stepM_ 0 (<n) (+1)
thru :: Monad m => (v -> m ()) -> v -> m v
thru m v = m v >> return v
memoize :: (Monad m) => (k -> m (Maybe v)) -> (k -> v -> m ()) -> k -> m v -> m v
memoize getter setter key action = do
    mv <- getter key
    case mv of
        Just v -> return v
        Nothing -> action >>= thru (setter key)

-- Array
newUArray :: (MArray (STUArray s) e (ST s),Ix i) => 
             (i,i) -> e -> ST s (STUArray s i e)
newUArray = newArray
newBArray :: (Ix i) => (i,i) -> e -> ST s (STArray s i e)
newBArray = newArray
defaultArray :: (IArray a e,Ix i) => e -> (i,i) -> [(i,e)] -> a i e
defaultArray = accumArray $ curry snd
fromEdges :: Ix i => (i,i) -> [(i,e)] -> Array i [e]
fromEdges = accumArray (flip (:)) []


Measured memory_bytes: 508
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
map<char,ll> mp;
int main(){
ll n;
cin>>n;
ll now=0,ans=0;
for(int i=1;i<=100000;i++){

   now+=i;
   if(now>=n){ans=i;break;}
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	int n;
	cin >> n;
	map<string, int> mp;
	rep(i, n) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		mp[s]++;
	}
	ll ans = 0;
	for(auto it = mp.begin(); it != mp.end(); it++) {
		ll tmp = it->second;
		if(tmp == 1) continue;
		ans += tmp * (tmp - 1) / 2;
	}
	cout << ans << endl;	
}


Measured memory_bytes: 11264
import queue
n,m=map(int,input().split())
road_list=[set() for i in range(n)]
mitisirube=[0]*n
mitisirube[0]=1
for i in range(m):
    a,b=map(int,input().split())
    road_list[a-1].add(b)
    road_list[b-1].add(a)

q = queue.Queue()

counter_set=set()
counter_set.add(1)
for i in road_list[0]:
    q.put(i)
    mitisirube[i-1]=1
    counter_set.add(i)

while not q.empty():
    tmp=q.get()
    for i in road_list[tmp-1]:
        if i not in counter_set:
            q.put(i)
            counter_set.add(i)
            if mitisirube[i-1]==0:
                mitisirube[i-1]=tmp

if mitisirube.count(0)>0:
    print("No")
else:
    print("Yes")
    for i in range(1,len(mitisirube)):
        print(mitisirube[i])

Measured memory_bytes: 132348
//左子右兄弟表达法
#include<iostream>
#include<cstdio>

using namespace std;

const int maxn=1e5+5;
const int NIL=-1;

struct node{
    int p,l,r;
};

node t[maxn];
int n,d[maxn];

void print(int u)
{
    int i,c;
    cout<<"node "<<u<<": ";
    cout<<"parent = "<<t[u].p<<", ";
    cout<<"depth = "<<d[u]<<", ";
    if(t[u].p==NIL){
        cout<<"root, ";
    }else if(t[u].l==NIL){
        cout<<"leaf, ";
    }else{
        cout<<"internal node, ";
    }
    cout<<"[";
    for(int i=0,c=t[u].l;c!=NIL;i++,c=t[c].r){
        if(i){
            cout<<", ";
        }
        cout<<c;
    }
    cout<<"]"<<endl;
}

int rec(int u,int p)
{
    d[u]=p;
    if(t[u].r!=NIL){
        rec(t[u].r,p);
    }
    if(t[u].l!=NIL){
        rec(t[u].l,p+1);
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        t[i].p=t[i].l=t[i].r=NIL;
    }
    int v,d,c,l,r;
    for(int i=0;i<n;i++){
        cin>>v>>d;
        for(int j=0;j<d;j++){
            cin>>c;
            if(j==0){
                t[v].l=c;
            }else{
                t[l].r=c;
            }
            l=c;
            t[c].p=v;
        }
    }
    for(int i=0;i<n;i++){
        if(t[i].p==NIL){
            r=i;
        }
    }
    rec(r,0);
    for(int i=0;i<n;i++){
        print(i);
    }
    return 0;
}
/*
13
0 3 1 4 10
1 2 2 3
2 0
3 0
4 3 5 6 7
5 0
6 0
7 2 8 9
8 0
9 0
10 2 11 12
11 0
12 0
*/



Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=201000;

int n,u,v,deg2[N];
vector<PII> e1;
set<PII> e2;
int main() {
	scanf("%d",&n);
	rep(i,1,n) {
		scanf("%d%d",&u,&v);
		if (u>v) swap(u,v);
		e1.pb(mp(u,v));
	}
	rep(i,1,n) {
		scanf("%d%d",&u,&v);
		deg2[u]++; deg2[v]++;
		if (u>v) swap(u,v);
		e2.insert(mp(u,v));
	}
	int x=(n-1)*powmod(2,mod-2)%mod;
	ll y=0;
	for (auto f:e1) {
		y+=n-1-deg2[f.fi]-deg2[f.se]+e2.count(f);
	}
	y=y%mod;
	x=(x+y*powmod(16,mod-2))%mod;
	printf("%d\n",x);
}


Measured memory_bytes: 14712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9 + 7;
const int INT_MOD=1e9+7;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
   string s,t;
   int n;cin>>n;
   cin>>s;
   if(n%2!=0) cout<<"No"<<endl;
   else{
       char x[n];
       for(int i=0;i<n/2;i++){
           x[i]=s[i];
       }
       for(int i=0;i<n/2;i++){
           if(x[i]!=s[i+n/2]){
               cout<<"No"<<endl;
               return 0;
           }
       }
       cout<<"Yes"<<endl;
   }
    return 0;
}

Measured memory_bytes: 256
"use strict";
main(require("fs").readFileSync("/dev/stdin", "UTF-8"));

function main(input) {
  input = input.split("\n");
  const N = parseInt(input.shift());
  input = input[0].split(" ");

  const denominator = commonMult(input, N);

  let culc = 0;
  for (const n of input) {
    culc += denominator / parseInt(n);
  }

  console.log(1 / (culc / denominator));
}

function commonMult(array, length) {
  let result = 1;
  for (const n of array) {
    result *= parseInt(n);
  }
  return result;
}


Measured memory_bytes: 21064
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i,N) cin >> p[i];
    int sum=0;
    for(int i=0; i<N-1; i++){
        if(i+1==p[i]){
            p[i]=p[i+1];
            p[i+1]=i+1;
            sum++;
        }
    }
    if(N==p[N-1]){
        p[N-1]=p[N-2];
        p[N-2]=N;
        sum++;
    }
    cout << sum << endl;
    return 0;
}

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

class Program {
    static void Main (string[] args) {

        string[] str = new string[5];
        for (var i = 0; i < 5; i++) str[i] = Console.ReadLine ();
        int K = int.Parse (Console.ReadLine ());

        var ary = str.Select (int.Parse);
        int x = ary.Max () - ary.Min ();
        if (K >= x) {
            Console.WriteLine ("Yay!");
        } else {
            Console.WriteLine (":(");
        }

    }
}

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

int a,b;
int main () {
	cin>>a>>b;
	if(a==b){
		cout<<"Draw";
	}else if(a==1 && b!= 1){
		cout<< "Alice";
	}else if(b==1 && a!= 1){
		cout<<"Bob";
	}else if(a<b){
		cout<<"Bob";
	}else{
		cout<<"Alice";
	}
}

Measured memory_bytes: 256