akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL)
    {
      y = x; 
      if (z->key < x->key)x = x->left; 
      else x = x->right; 
    }
  z->parent = y;

  if (y == NIL)root=z;
  else if (z->key < y->key)y->left = z; // z を y の左の子にする
  else y->right = z; // z を y の右の子にする
}

void inorder(Node u){
  
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

}
void preorder(Node u){
  
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);

}
Node findkey(int key)
{
  Node X=root;
  
  while(1)
  {
    
      if(X==NIL)return NIL;
      if(X->key==key)return X;
      if(X->key < key)X=X->right;
      else X=X->left;
    }
}

Node Successor(Node A)
{
  Node X;
  Node B;
 
  // if(A->right!=NIL)
  // {
      A=A->right;
      while(A->left!=NIL)A=A->left;

      return A;
      //}
      /*else
    {
      A=A->parent;
      while(1)
	{
	  if(A==A->parent->left)return A->parent;
	  A=A->parent;
	}
    }*/
}

void delete(Node X)
{
  
  Node B;
  Node child;

  

  if(X->right==NIL && X->left==NIL)///////>< ><//
    {
     
      if(X->parent->right==X)X->parent->right=NIL;
      else X->parent->left=NIL;
       free(X);

      
    }
  
  else if(X->right!=NIL && X->left!=NIL)//o o//ココがおかしい
    {
       B= Successor(X);
       
       X->key=B->key;
      
       delete(B);
    }


  else//o ><
    {
     
      
	
      if(X->right==NIL)child=X->left;
      else child=X->right;

      if(X->parent==NIL)
	{
	  child->parent=NIL;
	  return ;
	}
     
      if(X->parent->key < X->key)X->parent->right=child;
      else X->parent->left=child;

      child->parent=X->parent;

 free(X);

    }


 
}


int main()
{
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  int count=0;
  
  for ( i = 0; i < n; i++ )
    {
      //printf("----%d\n",i);///////////////

      scanf("%s", com);
      if ( com[0] == 'i' )
        {
          scanf("%d", &x);
          insert(x);
        }
   else if (com[0] == 'f')//FIND
        {
          scanf("%d", &x);
          if(count)printf("\n");
          if(findkey(x)!=NIL)printf("yes\n");
          else printf("no\n");
        }
      else if(com[0] == 'd')
        {
          scanf("%d", &x);
          delete(findkey(x));

        }
      else if(com[0] == 'p')//PRINT
        {
	   inorder(root);
          printf("\n");
          preorder(root);
          printf("\n");
        }
    }
  return 0;
}



Measured memory_bytes: 20496
#include <stdio.h>

int main() {
    int a;
    int b;
    while (scanf("%d %d", &a, &b) != EOF) {
        int result = a + b;
        int digit = 0;
        while (result != 0) {
        digit++;
        result /= 10;
    }

    printf("%d\n", digit);
    }
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <vector>
#include <string.h>

int t1,t2;
int n,m;

int cnt[100005];
std::vector<int> g[100005];
bool vis[100005];

int avoid;
int cycle;
void dfs(int u,int par)
{
    vis[u]=1;
    for (int v:g[u]) {
        if (v==par) continue;
        if (v==avoid) continue;
        if (vis[v]) cycle=1;
        else dfs(v,u);
    }
}


int solve()
{
    scanf("%d%d",&n,&m);
    for (int i=0; i<m; i++) {
        scanf("%d%d",&t1,&t2);
        g[t1].push_back(t2);
        g[t2].push_back(t1);
        cnt[t1]++;
        cnt[t2]++;
    }
    for (int i=1; i<=n; i++) {
        if (cnt[i]&1) return 0;
    }
    for (int i=1; i<=n; i++) {
        if (cnt[i]>=6) return i;
    }
    // all vertices are deg 2 or 4
    // try removing a vertex of deg 4, and seeing if there's a cycle
    for (int i=1; i<=n; i++) {
        if (cnt[i]==4) {
            memset(vis,0,sizeof vis);
            cycle=0;
            avoid=i;
            for (int j=1; j<=n; j++) {
                if (!vis[j] && j!=i) dfs(j,0);
            }
            if (cycle) return i;
        }
    }
    return 0;
}

int main()
{
    #ifdef NOT_DMOJ
    freopen("data.txt","r",stdin);
    #endif // NOT_DMOJ
    //printf("%d\n",solve());return 0;
    if (solve()) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
 
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using ll = long long;
using ld = long double;
 
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
const int L = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = (1LL << 61);
 
int h, a;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    cin >> h >> a;
    cout << (h - 1) / a + 1;
 
    return 0;
}
 
/// ACTUAL CODE STARTS HERE:
/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */

Measured memory_bytes: 256
h,n = map(int,input().split())
mahou = []
for i in range(n):
	a,b = map(int,input().split())
	mahou.append((a,b))
dp = [10**18 for _ in range(h+1)]
dp[0] = 0
for i in range(h+1):
	for j, k in mahou:
		if j+i <= h:
			dp[j+i] = min(dp[i]+k, dp[j+i])
		else:
			dp[h] = min(dp[i]+k, dp[h])
print(dp[h])

Measured memory_bytes: 41708
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
 
#define MOD 1000000007
void init();
void solve();

signed main()
{
	init();
	solve();
}

ll N;
ll num[100];
ll val[100];

void init()
{
	cin >> N;
	rep(i, 100) num[i] = val[i] = -1;
	val[0] = num[0] = 0;
}


inline int keta(ll x)
{
	int res = 0;
	while (x) {
		res++;
		x /= 10;
	}
	return res;
}

inline ll getnum(int k) {
	if (num[k] != -1) return num[k];
	if (k == 1) num[k] = 5;
	ll& res = num[k];
	ll x = 1;
	rep(i, k) {
		x *= 10;
	}
	x--;
	ll n3 = x / 3;
	ll n5 = x / 5;
	ll n15 = x / 15;
	return res = x - (n3 + n5 - n15);
}

ll getval(int k) {
	if (val[k] != -1) return val[k];
	ll& res = val[k];
	res = getval(k-1);
	res += (getnum(k) - getnum(k-1)) * k;
	return res;
}

inline ll calc(ll x) {
	if (x == 0) return 0;
	ll res = 0;
	ll n3 = x / 3;
	ll n5 = x / 5;
	ll n15 = x / 15;
	ll nelse = x - (n3 + n5 - n15);
	res += n3 * 4;
	res += n5 * 4;
	int k = keta(x);
	res += getval(k-1);
	nelse -= getnum(k-1);
	res += nelse * k;
	return res;
}

bool isok(ll s, ll x)
{
	return s <= calc(x);
}

pair<ll, ll> find(ll s)
{
	ll ng = 0;
	ll ok = 1e17;
	while (ok - ng > 1) {
		ll mid = (ok + ng) / 2;
		if (isok(s, mid)) ok = mid;
		else ng = mid;
	}
	return MP(ok, s - calc(ok-1));
}

void print(pair<ll, ll> p) {
	ll num = p.first;
	ll pos = p.second;
	if (num % 15 == 0) {
		string s = "FizzBuzz";
		cout << s[pos-1];
		return;
	}
	if (num % 5 == 0) {
		string s = "Buzz";
		cout << s[pos-1];
		return;
	}
	if (num % 3 == 0) {
		string s = "Fizz";
		cout << s[pos-1];
		return;
	}
	int k = keta(num);
	ll m = 1;
	rep(i, k-1) m *= 10;
	ll t = num;
	while (1) {
		ll x = t / m;
		if (pos == 1) {
			cout << x;
			return;
		}
		t -= x * m;
		m /= 10;
		pos--;
	}
}

void solve()
{
	for (ll s = N; s < N + 20; s++) {
		print(find(s));
	}
	cout << endl;
}




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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }




int main() {
    ll n; cin >> n;
    cout << (n*(n+1)/2)-n << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <list>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

const int MOD = 1e9 + 7;
int n, a, b, c, d;
ll D[1010][1010];
ll C[2010][2010];

ll pw(ll x, ll y){
	ll res = 1;
	while(y){
		if(y & 1)res = res * x % MOD;
		x = x * x % MOD;
		y >>= 1;
	}
	return res;
}

ll R[1010];

void solve(){
	for(int i=1;i<1010;i++)R[i] = pw(i, MOD-2);
	C[0][0] = 1;
	for(int i=1;i<2010;i++){
		C[i][0] = 1;
		for(int j=1;j<=i;j++){
			C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
		}
	}
	scanf("%d%d%d%d%d", &n, &c, &d, &a, &b);
	D[c-1][0] = 1;
	for(int i=c;i<=d;i++){
		for(int j=0;j<=n;j++){
			D[i][j] = D[i-1][j];
			ll T = 1;
			for(int k=i;k<=j && k<=i*b;k+=i){
				T = T * C[j-k+i][i] % MOD;
				T = T * R[k/i] % MOD;
				if(k >= i*a)D[i][j] = (D[i][j] + T * D[i-1][j-k]) % MOD;
			}
		}
	}
	printf("%lld", D[d][n]);
}

int main(){
	int Tc = 1;// scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 30976
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 100000;
const int MAXM = 100000;
const int MAXCOL = 100000;
typedef struct E { int a, b, c; } E;
bool operator<(const E &p, const E &q) { return p.c < q.c; }

int n, m, ncol;
int col[MAXN];
E e[MAXM];

int par1[MAXN], sz1[MAXN], col1[MAXN];
int par2[MAXCOL], sz2[MAXCOL];

int find1(int a) { if (par1[a] == a) return a; return par1[a] = find1(par1[a]); }
int find2(int a) { if (par2[a] == a) return a; return par2[a] = find2(par2[a]); }

void run() {
	scanf("%d%d%d", &n, &m, &ncol);
	REP(i, n) scanf("%d", &col[i]), --col[i];
	REP(i, m) scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].c), --e[i].a, --e[i].b;

	sort(e, e + m);
	REP(i, n) par1[i] = i, sz1[i] = 1, col1[i] = col[i];
	REP(i, ncol) par2[i] = i, sz2[i] = 1;
	int need = ncol - 1, have = 0;
	ll ret = 0;
	REP(i, m) {
		if (have >= need) break;
		int a = find1(e[i].a), b = find1(e[i].b); if (a == b) continue;
		int aa = col1[a], bb = col1[b];
		//printf("%d: merging %d with %d (col %d with %d)\n", e[i].c, a, b, aa, bb);
		if (sz1[a] < sz1[b]) swap(a, b); par1[b] = a, sz1[a] += sz1[b], col1[a] = aa != -1 ? aa : bb;
		if(aa!=-1&&bb!=-1) {
			aa = find2(aa), bb = find2(bb); if (aa == bb) continue;
			--need; ret += e[i].c;
			if (sz2[aa] < sz2[bb]) swap(aa, bb); par2[bb] = aa, sz2[aa] += sz2[bb];
		} else {
			++have; ret += e[i].c;
		}
	}
	printf("%lld\n", have >= need ? ret : -1LL);
}

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


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    string s;
    cin >> n >> k >> s;
    int an = 0;
    int i = 0, j = 0;
    while (i < n) {
        if (s[i] == '0') {
            if (k == 0) {
                while (s[j] == '1') ++j;
                while (s[j] == '0') ++j;
                ++k;
            }
            while (i < n-1 && s[i] == '0') ++i;
            --k;
        }
        an = max(an, i-j+1);
        ++i;
    }
    cout << an << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  double ans1 = a[n-1];
  double ans2 = -100LL;
  double c = (double)ans1/2;
  rep(i,n-1) if(abs(a[i]-c)<abs(ans2-c)) ans2 = a[i];
  cout << (int)ans1 << " " << (int)ans2 << endl;
  return 0;
}

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

int main(){
  string s; cin >> s;
  int state = 0;
  for(int i=0; i<s.length(); i++){
    if(s[i] == 'C'){state = 1;}
    if(s[i] == 'F' && state == 1){state = 2;}
  }
  if(state == 2){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i],y[i] = map(int,input().split())
    

ans = 1000

for i in range(N):
    for j in range(N):
        if i==j:continue
        cnt = 0
        p = x[i]-x[j]
        q = y[i]-y[j]
        for l in range(N):
            for m in range(N):
                if l==m : continue
                if x[l] - x[m] == p and y[l] - y[m] == q:
                    cnt += 1
        ans = min(ans,max(1,N-cnt))        
        
                
        
        
if N == 1 :
    print(1)
else:
    print(ans)
                
                
                
        
        
        
        
        
        


Measured memory_bytes: 3188
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int A[3][3];
    for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) cin >> A[i][j];
    int n; cin >> n;
    bool B[9] = {};
    while (n--) {
        int b; cin >> b;
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                if (A[i][j] == b) B[3*i+j] = true;
    }
    vector<vector<int>> idxs = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}};
    for (vector<int> &v : idxs) {
        bool ok = true;
        for (int i : v) ok = ok && B[i];
        if (ok) { cout << "Yes\n"; return 0; }
    }
    cout << "No\n";
}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0
for i in range(N):
  A = list(map(int, input().split()))
  tmp = 0
  for i,j in zip(B,A):
    tmp += i*j
  if tmp + C > 0:
    ans += 1
print(ans)


Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,k,j,x=0;
  cin>>m>>k;
  vector<int> t(m);
  for(j=0;j<m;j++){
    cin>>t.at(j);
    if(j==0) x+=k;
    else x+=min(k,t.at(j)-t.at(j-1));
  }
  cout<<x<<endl;
}

Measured memory_bytes: 3860
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

cost1 = len(list(filter(lambda x: x in range(0, X), A[:])))
cost2 = len(list(filter(lambda x: x in range(X, N + 1), A[:])))

print(min(cost1, cost2))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define me(a,x) memset(a,x,sizeof(a))
#define sc scanf
#define pr printf
#define IN freopen("in.txt","r",stdin);
#define OUT freopen("out.txt","w",stdout);
typedef long long ll;
typedef unsigned long long ull;
const int N=1e6+6;
const int mod=1e9+7;
template<typename T>int O(T s){cout<<s<<endl;return 0;}
template<typename T>void db(T *bg,T *ed){while(bg!=ed)cout<<*bg++<<' ';pr("\n");}
template<typename T>void db(vector<T>it){for(auto i:it)cout<<i<<' ';pr("\n");}
inline ll mul_64(ll x,ll y,ll c){return (x*y-(ll)((long double)x/c*y)*c+c)%c;}
inline ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=a*a%c)if(b&1)ans=ans*a%c;return ans;}
inline void exgcd(ll a,ll b,ll &x,ll &y){if(!b)x=1,y=0;else exgcd(b,a%b,y,x),y-=(a/b)*x;}
int n;
int a[N];
ll b[N];
int main(){
    //IN
    cin>>n;
    ll ans=0;
    for(int i=0;i++<n;sc("%d",&a[i]),b[a[i]]++);
    for(int i=1;i<=n;i++){
        ans+=b[i]*(b[i]-1)/2;
    }
    for(int i=1;i<=n;i++){
        pr("%lld\n",ans-(b[a[i]]-1));
    }
}

Measured memory_bytes: 7296
#include<iostream>
using namespace std;
int main()
{
	int H[100000], W[100000];
	int i,j,r,d;
	for (i = 0; i < 98000; i++){
		cin >> H[i] >> W[i];
		if (H[i] == 0 && W[i] == 0){
			j = i;
			break;
		}
	}
	for (i = 0; i < j; i++){
		for (r=0;r<H[i];r++){
			for (d=0;d<W[i];d++){
				if ((r % 2) != 0 && (d % 2) != 0){
					cout << "#";
				}
				else if ((r% 2) == 0 && (d% 2) == 0){
					cout << "#";
				}
				else{
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std ;

int main () { 

ios_base::sync_with_stdio(false) ;
cin.tie(0) ; 
cout.tie(0) ; 

int k ; 
int a, b ; 
cin >> k ; 
cin >> a >> b ; 
int fo = 0 ; 
for ( int i = a ; i <=b ; i ++ ) { 
	if ( i % k == 0 ) {
		cout << "OK"<< endl; 
		return  0 ; 
	}
}
cout << "NG" << endl ;
}



Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;

bool cmp(const string &a, const string &b) {
  if(a.size() != b.size()) return a.size() < b.size();
  
  for(int i=0; i<a.size(); i++)
    if(a[i] != b[i]) return a[i] < b[i];
  
  return true;
}

string dp[71][71];

int main() {
  
  int W, H;
  
  while(cin >> W >> H && (W|H)) {
    
    for(int i=0; i<=H; i++)
      for(int j=0; j<=W; j++)
	dp[i][j] = "0";
    
    string ans = "0";
    
    for(int i=1; i<=H; i++) {
      for(int j=1; j<=W; j++) {
	char c;
	cin >> c;
	if(isdigit(c)) {
	  dp[i][j] = max(dp[i-1][j], dp[i][j-1], cmp);
	  
	  if(dp[i][j] == "0")
	    dp[i][j] = "";
	  
	  dp[i][j] += c;
	}
	else dp[i][j] = "";
	ans = max(ans, dp[i][j], cmp);
      }
    }
    cout << ans << endl; 
  }
  
  return 0;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string x;
    cin>>x;
    int s=0,t=0,n=x.size();
    rep(i,n){
        if(x[i]=='S')s++;
        if(x[i]=='T'&&s==0)t++;
        if(x[i]=='T'&&s!=0)s--;
    }
    cout<<s+t<<endl;
}

Measured memory_bytes: 640
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,p,m,x=0;
     cin>>n;
     ll int ara[n];
     for(i=0;i<n;i++){
        cin>>ara[i];
        if(ara[i]==0){
            x=1;
        }
     }
     p=1;
     if(x==1){
        cout<<0<<endl;return 0;
     }
     p=ara[0]*p;
     for(i=1;i<n;i++){
        m=ara[i]*p;
        if(m>1000000000000000000 || m<0 || m<p){
        cout<<-1<<endl;return 0;
        }
        p=m;
     }
     cout<<m<<endl;

     return 0;
}






Measured memory_bytes: 4412
#include <iostream>
#include <array>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;

    array <int, (const int)1e5 + 1> order;
    for (int i = 1; i <= n; i++) {
        cin >> order[i];
    }

    int currentPoint = 1, nrIterations = 0;
    const int maxIter = (const int)1e5;
    while (currentPoint != 2 && nrIterations <= maxIter) {
        ++nrIterations;
        currentPoint = order[currentPoint];
    }

    cout << ((nrIterations > maxIter) ? -1 : nrIterations);

    return 0;
}


Measured memory_bytes: 768
#include <stdio.h>

int linear_search(int s[], int n,  int t) {
  for (int i = 0; i < n; i++)
    if (s[i] == t)
      return 1;
  return 0;
}

int main(void) {
  int n ,q;
  int s[10000];
  int t[500];
  int i;
  int count = 0;
  
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &s[i]);
  scanf("%d", &q);
  for (i = 0; i < q; i++)
    scanf("%d", &t[i]);

  for (i = 0; i < q; i++) {
    count += linear_search(s, n, t[i]);
  }

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



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

template<class T>bool chmax(T &a, const T &b)
{ return (a<b ? (a=b)||1 : 0); }

int main() {
	
	int n,W; cin>>n>>W;
	vector<vector<int64_t>> dp(n+1,vector<int64_t>(W+1));
	vector<int64_t> w(n),v(n);
	for(int i=0; i<n; i++) cin>>w.at(i)>>v.at(i);
	for(int i=0; i<n; i++){
		for(int j=0; j<=W; j++){
			chmax(dp.at(i+1).at(j), dp.at(i).at(j));
			if(j-w.at(i)>=0) chmax(dp.at(i+1).at(j), dp.at(i).at(j-w.at(i))+v.at(i));
		}
	}
	cout << dp.at(n).at(W)<<endl;
	
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, m, r; cin >> n >> m >> r;
  VI t(r); for (int i = 0; i < r; i++) { cin >> t[i]; t[i]--; }
  sort(t.begin(), t.end());
  VVI d(n, VI(n, 1e9));
  for (int i = 0; i < m; i++) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;
    d[a][b] = d[b][a] = c;
  }
  //for (int i = 0; i < n; i++) {
    //d[i][i] = 0;
  //}
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int res = 2e9;
  do {
    int tmp = 0;
    for (int i = 0; i < t.size() - 1; i++) {
      tmp += d[t[i]][t[i + 1]];
    }
    res = min(res, tmp);
  } while (next_permutation(t.begin(), t.end()));
  cout << res << '\n';
  return 0;
}


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

using namespace std;
using ll = long long;

int main(void){
	ll n;
	cin >> n;

	vector<pair<ll,int> > fs;
	for(ll i=2;i*i<=n;i++){
		int x = 0;
		while(n%i == 0){
			n/=i;
			x++;
		}
		fs.emplace_back(i,x);
	}
	if(n != 1) fs.emplace_back(n,1);

	int ans = 0;
	for(auto p : fs){
		int x= p.second;
		int b = 1;
		while(b<=x){
			x -= b;
			b++;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 19744
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

int main(){
    // 引数の受け取り
    int A,C;
    char B;
    scanf("%d %c %d", &A, &B, &C);
    int F = 0;
    if (B == '+'){
        F = A + C;
    } else {
        F = A - C;
    }

    printf("%d", F);
    return 0;
}


Measured memory_bytes: 256
x=int(input())
for i in range(1,400000):
  a=i
  b=int(abs((a**5-x)**0.2))
  for j in range(-1,2):
    if (b+j)**5==a**5-x:
      print(a,b)
      quit()
    if (-b+j)**5==a**5-x:
      print(a,-b)
      quit() 
    
  #else:pass

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

const int MAX_N = 100010;
int memo[MAX_N];

int rec(int n){
    if(n == 0) return 0;
    if(memo[n] != -1) return memo[n];

    int res = n;
    
    // 1, 6, 36, ...
    for(int i = 1; i <= n; i *= 6){
        res = min(res, rec(n - i) + 1);
    }

    // 1, 9, 81, ...
    for(int i = 1; i <= n; i *= 9){
        res = min(res, rec(n - i) + 1);
    }

    return memo[n] = res;
}

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

    int N;
    cin >> N;
    for(int i = 0; i < MAX_N; i++){
        memo[i] = -1;
    }

    cout << rec(N) << endl;

    return 0;
}

Measured memory_bytes: 3712
#include<stdio.h>
int main(){
    int S;
    scanf("%d",&S);
    
    int a = S/100; //上2桁
    int b = S%100; //下2桁
    
    if(1 <= a && a <= 12 && 1 <= b && b <= 12){
        printf("AMBIGUOUS\n");
        return 0;
    }
    if(a == 0 || a > 12){ //YYMM
        if(1 <= b && b <= 12) printf("YYMM\n");
        else printf("NA\n");
        return 0;
    }
    if(b == 0 || b > 12){ //MMYY
        if(1 <= a && a <= 12) printf("MMYY\n");
        else printf("NA\n");
        return 0;
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

int main() {
    ll n;
    cin>>n;
    
    ll sum=0;
    
    rep2(i,1,n){
        if(i%3!=0&&i%5!=0){
            sum+=i;
        }
    }
    cout<<sum<<endl;
}



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

int px[90001],py[90001];
int D[90001];


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

	for(int i = 0;i<h;i++){
		for(int j = 0;j<w;j++){
			int t;
			cin>>t;
			px[t]=i,py[t]=j;
		}
	}

	for(int i = d;i<=h*w;i++){
		D[i] = D[i-d]+abs(px[i] - px[i-d])+abs(py[i] - py[i-d]);
	}
	int q;
	cin>>q;

	while(q--){
		int l,r;
		cin>>l>>r;
		cout<<D[r] - D[l]<<endl;
	}
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
//解説AC
using namespace std;

typedef long long ll;

const ll INF = 1LL << 60;


int main(){
 int N,M; cin >> N >> M;
 vector<vector<int>> jobs(M+1);
 for(int i = 0; i < N; i++){
   int a,b; cin >> a >> b;
   
   if( a > M){ continue;}
   jobs[M-a].push_back(b);
 }
  
  priority_queue<int> q;
  
  ll ans = 0;
  
  for(int i = M - 1; i >= 0; i--){
    for(int b : jobs[i]){
      //jobs[i]に含まれる仕事（の報酬）をqにpush_backしていく
      q.push(b);}
    // i日目までに選択可能な仕事の報酬が追加されたことになる
    if(!q.empty()){
      ans += q.top(); //queueはデフォルトででかい順
      q.pop();}
  }



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

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

using namespace std;

struct Operation {
  int h1, w1, h2, w2;
  Operation(int h1_, int w1_, int h2_, int w2_)
    : h1{h1_}, w1{w1_}, h2{h2_}, w2{w2_}
  {
  }
};

void dump(const Operation& o)
{
  cout << (o.h1 + 1) << " " << (o.w1 + 1) << " "
    << (o.h2 + 1) << " " << (o.w2 + 1) << endl;
}

int main()
{
  int H, W;
  cin >> H >> W;
  vector<vector<int>> grid(H, vector<int>(W, 0));
  for (int h = 0; h < H; ++h) for (int w = 0; w < W; ++w) cin >> grid[h][w];

  vector<Operation> operations;
  for (int h = 0; h < H; ++h) {
    for (int w = 0; w < W; ++w) {
      if (grid[h][w] % 2 == 1) {
        if (h > 0 and grid[h - 1][w] % 2 == 1) {
          operations.push_back(Operation(h, w, h - 1, w));
          ++grid[h - 1][w];
          --grid[h][w];
        } else if (w > 0 and grid[h][w - 1] % 2 == 1) {
          operations.push_back(Operation(h, w, h, w - 1));
          ++grid[h][w - 1];
          --grid[h][w];
        } else if (h < H - 1 and grid[h + 1][w] % 2 == 1) {
          operations.push_back(Operation(h, w, h + 1, w));
          ++grid[h + 1][w];
          --grid[h][w];
        } else if (w < W - 1 and grid[h][w + 1] % 2 == 1) {
          operations.push_back(Operation(h, w, h, w + 1));
          ++grid[h][w + 1];
          --grid[h][w];
        } else if (h < H - 1) {
          operations.push_back(Operation(h, w, h + 1, w));
          ++grid[h + 1][w];
          --grid[h][w];
        } else if (w < W - 1) {
          operations.push_back(Operation(h, w, h, w + 1));
          ++grid[h][w + 1];
          --grid[h][w];
        }
      }
    }
  }
  cout << operations.size() << endl;
  for (const auto& operation: operations) dump(operation);
  return 0;
}

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

constexpr long long mod{1'000'000'007};

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<std::pair<int, int>> ab(2 * N);
	for (auto& e: ab) scanf("%d", &e.first);
	for (int i{}; i < N; i++) ab[i].second = -1;
	for (int i{N}; i < 2 * N; i++) ab[i].second = 1;
	std::sort(ab.begin(), ab.end());

	int count{};
	long long ans{1};
	for (auto& e: ab)
	{
		if (e.second * count < 0)
			ans = ans * std::abs(count) % mod;
		count += e.second;
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 1792
a_1 = gets.split.map(&:to_i)
a_2 = gets.split.map(&:to_i)
a_3 = gets.split.map(&:to_i)
n = gets.chomp.to_i
b = []
n.times do |i|
    b[i] = gets.chomp.to_i
end
result = Array.new(9,0)
for i in 0..2
    for j in 0..(n-1)
        if a_1[i] == b[j]
            result[i] = 1
        end
    end
end

for i in 0..2
    for j in 0..(n-1)
        if a_2[i] == b[j]
            result[i+3] = 1
        end
    end
end

for i in 0..2
    for j in 0..(n-1)
        if a_3[i] == b[j]
            result[i+6] = 1
        end
    end
end

if result[0] == 1 && result[1] == 1 && result[2] == 1 ||
    result[0] == 1 && result[3] == 1 && result[6] == 1 ||
    result[0] == 1 && result[4] == 1 && result[8] == 1 ||
    result[1] == 1 && result[4] == 1 && result[7] == 1 ||
    result[2] == 1 && result[5] == 1 && result[8] == 1 ||
    result[2] == 1 && result[4] == 1 && result[6] == 1 ||
    result[3] == 1 && result[4] == 1 && result[5] == 1 ||
    result[6] == 1 && result[7] == 1 && result[8] == 1
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
n, m = map(int, input().split())
ab = [tuple(int(x) for x in input().split()) for _ in range(m)]

class UnionFind:
    def __init__(self, size):
        self.rank = [-1 for _ in range(size)]
        self.number = [1 for _ in range(size)]

    def find(self, x):
        while self.rank[x] >= 0:
            x = self.rank[x]
        return x

    def union(self, s1, s2):
        if s1 == s2:
            return
        if self.rank[s1] == self.rank[s2]:
            self.rank[s1] -= 1
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        elif self.rank[s1] < self.rank[s2]:
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        else:
            self.rank[s1] = s2
            self.number[s2] += self.number[s1]

uft = UnionFind(n)
ans = [0 for _ in range(m)]
temp = n * (n - 1) // 2
ans[m - 1] = temp
for i in range(m-1, 0, -1):
    ra = uft.find(ab[i][0] - 1)
    rb = uft.find(ab[i][1] - 1)
    if ra != rb:
        temp -= uft.number[ra] * uft.number[rb]
        uft.union(ra, rb)
    ans[i - 1] = temp

for x in ans:
    print(x)





Measured memory_bytes: 24868
# それぞれのボールの文字列を取得
a, b = input().split()

# それぞれのボールの個数を取得
aCount, bCount = input().split()
aNumber = int(aCount)
bNumber = int(bCount)

ball = []
ball.append(aNumber)
ball.append(bNumber)

# 取り出したボールの文字列を取得
selectBall = input()

if selectBall == a:
    aNumber = aNumber-1
    ball[0] = aNumber
    print(' '.join(map(str,ball)))
elif selectBall == b:
    bNumber = bNumber-1
    ball[1] = bNumber
    print(' '.join(map(str,ball)))
else:
    print(' '.join(map(str,ball)))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define F first
#define S second
const ll base = 541;
const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 9;

const int N = 2e5 + 10;

char s[N];
int cnt[26];

int main(){	
	
	string s; cin >> s;
	int n = s.length();
	// s = " " + s;
	for (char c : s)  {
		cnt[c-'a']++;
	}
	ll ans = 1 + n * (n+1ll) / 2;
	for (int i=0; i<26; i++) {
		ans -= cnt[i] * (cnt[i] + 1ll) / 2;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
N,M = map(int,input().split())
 
ac = [0]*N
p = [0]*N
ans = 0
for _ in range(M):
    a,b = input().split()
    a = int(a)-1
 
    if not ac[a]:
        if b == "AC":
            ac[a] = 1
            ans += p[a]
        else:
            p[a] += 1
 
print(sum(ac),ans)

    
      
    
  
  
  
  

Measured memory_bytes: 10328
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) (i%(ll)(1e9 + 7))


int main(){
	string a,b,c;
	cin >> a >> b >> c;

	if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0])cout << "YES" << endl;
	else cout << "NO" << endl; 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

struct Unionfind {
  // tree number
  vector<int> par;
  // tree rank
  vector<int> treerank;
  // constructor
  Unionfind(int n = 1) { stree(n + 1); }
  // make and initialization
  void stree(int n = 1) {
    par.resize(n);
    treerank.resize(n);
    for(int i = 0; i < n; ++i) {
      par[i] = -1;
      treerank[i] = 0;
    }
  }
  // search root
  int root(int x) {
    if(par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }

  // add
  // already added, return 0
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return 0;
    if(treerank[x] > treerank[y]) swap(x, y);
    if(treerank[x] == treerank[y]) ++treerank[y];
    par[y] -= size(x);
    par[x] = y;
    return 1;
  }
  int size(int x) { return -par[root(x)]; }
};

long long n, m;
long long cnt[100005] = {0};
vector<pair<int, int>> v;
Unionfind uf;
vector<long long> ans;

void solve();

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    v.push_back(make_pair(a, b));
  }
  reverse(v.begin(), v.end());
  ans.assign(m, 0);
  solve();
  for(int i = 0; i < m; ++i) cout << ans[m - 1 - i] << endl;
  return 0;
}

void solve() {
  ans[0] = n * (n - 1) / 2;
  uf = Unionfind(n + 1);
  for(int i = 0; i < n; ++i) cnt[i] = 1;
  for(int i = 0; i < m - 1; ++i) {
    long long now = 0;
    if(uf.issame(v[i].fi, v[i].se)) {
      ans[i + 1] = ans[i];
      continue;
    }
    now = uf.size(v[i].fi);
    now *= uf.size(v[i].se);
    uf.uni(v[i].fi, v[i].se);
    ans[i + 1] = ans[i] - now;
  }
}

Measured memory_bytes: 4468
#include<iostream>
#include<deque>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    deque<char> s;
    string buf;
    cin>>buf;
    rep(i,buf.size()) s.push_back(buf[i]);
    int q;
    cin>>q;
    bool flag=false;
    rep(i,q)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            if(flag)flag=false;
            else flag=true;
        }
        else if(t==2)
        {
            int f;
            char c;
            cin>>f>>c;
            if(f==1)
            {
                if(flag)s.push_back(c);
                else s.push_front(c);
            }
            else if(f==2)
            {
                if(flag) s.push_front(c);
                else s.push_back(c);
            }
        }
    }
    int size=s.size();
    rep(i,size)
    {
        if(flag)
        {
            char c=s.back();
            cout<<c;
            s.pop_back();
        }
        else
        {
            char c=s.front();
            cout<<c;
            s.pop_front();
        }
    }

    return 0;
}

Measured memory_bytes: 896
#pylint: disable=missing-docstring,bad-whitespace,invalid-name,len-as-condition,trailing-newlines,multiple-statements,unnecessary-semicolon,trailing-whitespace,superfluous-parens
import math as M

num = input()
sum = 0
for ch in num :
    sum += ord(ch)-ord('0')
if sum%9==0 :
    print('Yes')
else :
    print('No')
exit()      

n,x,t = (map(int,input().split()))
print(t*(n//x) + t*(min(n%x,1)))
exit()

n = int(input())
a = list(map(int,input().split()))
cm = 1000
p1 = p2 = a[0]
for i in range(1,n):
    #print(i,a[i],p1,p2)
    if(a[i]>=p2):
        p2 = a[i]
    elif(a[i]<p2):
        cm += (cm//p1)*(p2-p1)
        p1 = p2 = a[i]
cm += (cm//p1)*(p2-p1)
print(cm)
exit()

cm = 1000
for i in range(0,40):
    st = cm//100
    cm -= st*100
    cm += st*200
print(cm)
print(M.log10(cm))
print(M.log2(10**16))
exit()

isPrime = [1]*101
isPrime[0]=isPrime[1]=0
for i in range(2,int(M.sqrt(101)+1)) :
    if not isPrime[i] : continue
    for j in range(i*i,101,i) :
        isPrime[j]=0

pa = 5
pb = 1
ctr= 0
for i in range(2,101) : 
    if not isPrime[i] : continue
    if i==5 : 
        ctr+=1
        continue
    if(ctr&1) : 
        pa *= i
    else : 
        pb *= i
    ctr+=1
print(pa,' ',pa<=2*(10**18))
print(pb,' ',pb<=2*(10**18))


#init pa = 5, pb = 1
#into b  2
#into a  3
#into a  7
#into b  11
#into a  13
#into b  17
#into a  19
#into b  23
#into a  29
#into b  31
#into a  37
#into b  41
#into a  43
#into b  47
#into a  53
#into b  59
#into a  61
#into b  67
#into a  71
#into b  73
#into a  79
#into b  83
#into a  89
#into b  97
#1931237034633205845   True
#1193829614179601806   True


Measured memory_bytes: 9268
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
pair<int,int> p[10];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>p[i].first>>p[i].second;
	}
	double ans=0;
	sort(p,p+N);
	double cnt=0;
	do{
		REP(i,N-1){
			double x=p[i+1].first-p[i].first;
			double y=p[i+1].second-p[i].second;
			double d=sqrt(x*x+y*y);
			ans+=d;
		}
		cnt++;
	}while(NP(p,p+N));
	setp(ans/cnt,10);cout<<endl;
	return 0;
}


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

long long M, a, b;
vector<pair<long long, long long>> p;

int main(){
  scanf("%lld%lld", &a, &M);
  for(int i = 0; i < M; ++i){
    scanf("%lld%lld", &a, &b);
    p.emplace_back(a, b - 1);
  }
  sort(p.rbegin(), p.rend());
  a = 0;
  b = 0;
  for(auto i : p){
    if(i.first <= b && b <= i.second)continue;
    ++a;
    b = i.first;
  }
  cout << a << endl;
}

Measured memory_bytes: 2420
# B - Battle
# https://atcoder.jp/contests/abc164/tasks/abc164_b

a, b, c, d = map(int, input().split())

while a > 0 or c > 0:
    c -= b
    a -= d
    if c <= 0:
        print('Yes')
        break
    if a <= 0:
        print('No')
        break


Measured memory_bytes: 9080
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
m = 10**9+7
sumA = 0
for i in range(60):
    cnt1 = 0
    for a in A:
        if a>>i & 1:
            cnt1 += 1
    sumA += (cnt1*(N-cnt1)*2**i)%m
print(sumA%m)


Measured memory_bytes: 118416
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let b: i32 = read();

    println!("{}", if a <= 8 && b <= 8 { "Yay!" } else { ":(" });
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[test]
mod test {
    fn test() {
        assert!(true);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll mod = 1e9+7;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}

int main(){
    int N;
    cin >> N;
    vector<vector<int>> edge(N+1, vector<int>());
    for (int i = 0; i < N-1; i++) {
        int A, B;
        cin >> A >> B;
        edge[A].push_back(B);
        edge[B].push_back(A);
    }
    vector<int> parent(N+1, 0);
    vector<vector<int>> child(N+1, vector<int>());
    queue<int> q;
    vector<int> ts;
    ts.push_back(1);
    q.push(1);
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (int nxt : edge[now]) {
            if (nxt == parent[now]) continue;
            parent[nxt] = now;
            child[now].push_back(nxt);
            q.push(nxt);
            ts.push_back(nxt);
        }
    }
    vector<ll> rs(N+1, 0);
    for (int i = N-1; i >= 0; i--) {
        rs[ts[i]] = 1;
        for (int t : child[ts[i]]) {
            rs[ts[i]] += rs[t];
        }
    }
    vector<ll> pow(N+1, 1);
    vector<ll> hpow(N+1, 1);
    hpow[1] = modinv(2);
    for (int i = 1; i <= N; i++) pow[i] = pow[i-1]*2%mod;
    for (int i = 2; i <= N; i++) hpow[i] = hpow[i-1]*hpow[1]%mod;
    /*
    vector<vector<ll>> dp(N+1, vector<ll>(2, 0));
    for (int i = N-1; i >= 0; i--) {
        int now = ts[i];
        if (child[now].empty()) continue;
        for (int c : child[now]) {
            dp[now][1] += dp[c][1]+1;
        }
        dp[now][1] %= mod;
        for (int c : child[now]) {
            dp[now][0] += (dp[c][0]*pow[rs[now]-rs[c]] + dp[c][1])%mod;
            dp[now][0] += 
        }
        dp[now][0] %= mod;
        cout << now << " " << dp[now][0] << " " << dp[now][1] << endl;
    }*/
    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        ll t = pow[N-1]-1;
        t += mod-(pow[N-rs[i]]-1);
        //cout << t%mod << endl;
        for (int c : child[i]) {
            t += mod-(pow[rs[c]]-1);
        }
        ans += t;
        ans %= mod;
        //cout << t%mod << endl << endl;
    }
    cout << ans%mod*hpow[N]%mod << endl;
    return 0;
}


Measured memory_bytes: 27764
// cout << "Case #" << test << ": ";
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    string s;
    cin >> s;
    if(count(all(s), '7')) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;

void Diverta2019_D()
{
	long long int N;
	cin >> N;
	long long int M = static_cast<long long int>(sqrt(static_cast<double>(N))) + 1;

	long long int sum = 0;
	for (size_t i =1; i < M; ++i)
	{
		if (N % i == 0)
		{
			long long int x = N / i - 1;
			if(x > i)
				sum += x;
		}
	}
	cout << sum << endl;
}

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

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
double v;
while(scanf("%lf",&v) != EOF){
double y=v*v/19.6;
int z=y;
if(y==z){
if(z%5==0){
	z=y/5+1;
printf("%d\n",z);
continue;
}
}
int q=y/5;
q += 2;
printf("%d\n",q);
}
return 0;
}

Measured memory_bytes: 1056
import java.util.Scanner;

public class Main{

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

	private Scanner scan;

	int n;
	int a,b,c;

	private void mainrun() {
		scan = new Scanner(System.in);

		n = scan.nextInt();

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

		scan.close();

	}

	private void looprun() {
		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();

		if(a > c) {
			int tmp = a;
			a = c;
			c = tmp;
		}

		if(b > c) {
			int tmp = b;
			b = c;
			c = tmp;
		}

		String ans = (Math.pow(a,2) + Math.pow(b,2) == Math.pow(c,2))? "YES": "NO";

		System.out.println(ans);
	}
}


Measured memory_bytes: 32724
n = int(input())
a = list(map(int, input().split()))

from itertools import accumulate
cumsum = list(accumulate(a[::-1]))[::-1]

MOD = 10**9+7
ans = 0
for i,A in enumerate(a[:-1]):
    ans += A * cumsum[i+1]
    ans = ans % MOD
print(ans)

Measured memory_bytes: 31636
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count=0
for a in [a*500 for a in range(A + 1)]:
    for b in [b*100 for b in range(B + 1)]:
        for k in range(C + 1):
            if a + b + 50*k == X:
                count += 1
print(count)

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

int main() {
  int N;
  cin >> N;
  
 vector<tuple<string, int, int>> res(N);
  
  for( int i = 0; i < N; i++ ) {
    string s;
    int p;
    cin >> s >> p;
    res.at(i) = make_tuple( s, -p , i );
  }
  
  sort( res.begin(), res.end() );
  
  for( int i = 0; i < N; i++ ) {
    cout << get<2>(res.at(i))+ 1 << endl;
  }
}

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

#define REP(i, n) for(int i = 0; i < n; ++i)

template<class T>
T read() {
    T x{};
    cin >> x;
    return x;
}
 
template<class T>
vector<T> read(int N){
    vector<T> x(N);
    for(int i = 0; i < N; ++i){
        cin >> x[i];
    }
    return x;
}
 
template<class T>
void write(const T &x){ cout << x << endl; }

vector<vector<ll>> edges(1000+1);
vector<bool> visit(1000+1);
vector<bool> visit_gray(1000+1);

bool is_derived(vector<ll> &path){
    auto loop_v = path.back();
    auto it_loop_v = find(path.begin(), path.end(), loop_v);
    set<ll> vs(it_loop_v + 1, path.end());
    for(ll i = it_loop_v - path.begin() + 1; i < (ll)path.size(); ++i){
        auto v = path[i];
        auto nxt_i = (i + 1) < (ll)path.size() ? (i+1): (it_loop_v - path.begin() + 1) ;
        for(auto x : edges[v]){
            if(x != path[nxt_i] && 
               vs.find(x) != vs.end())
            {
                return false;
            }
        }
    }
    path = vector<ll>(it_loop_v + 1, path.end());
    return true;
};

auto dfs(ll node, vector<ll> &path){
    visit_gray[node] = true;
    path.push_back(node);
    if(visit[node]){ 
        // loop;
        if(is_derived(path)){ return true; }
        path.pop_back();
        return false;
    }
    visit[node] = true;
    for(auto v: edges[node]){
        if(dfs(v, path)){ return true;}
    }
    visit[node] = false;
    path.pop_back();
    return false;
};

int main(){
    auto N = read<ll>();
    auto M = read<ll>();
    REP(i, M){
        auto a = read<ll>();
        auto b = read<ll>();
        edges[a].push_back(b);
    }
    
    
    for(int n = 1; n <= N; ++n){
        if(visit_gray[n]){ continue; }
        
        vector<ll> path;
        if(dfs(n, path)){
            write(path.size());
            for(auto x : path){ write(x); }
            return 0;
        }
    }
    write(-1);
    
}

Measured memory_bytes: 384
import os

def main():
    n,x = map(int, input().split())
    list_a = list(map(int, input().split()))
    ans = 0
    count = 1

    for i in range(n):
        ans += list_a[i]
        if (ans <= x):
            count += 1
        else:
            break

    print(count)

if __name__ == "__main__":
    main()

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

using namespace std;
using ll = long long;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll K, X;
    cin >> K >> X;

    if(500 * K >= X) _PR("Yes");
    else _PR("No");

    return 0;
}

/*



*/

Measured memory_bytes: 256