akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	int ans = 0;
	int active = 0;
	rep(i, n) {
		if (active >= h[i]) {
			active = h[i];
		} else {
			ans += h[i] - active;
			active = h[i];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

ll ans[1000000];
vector<vector<pair<ll,ll>>> p(1000000);
ll n;
ll u[1000000],v[1000000],w[1000000];

void ki(ll i,ll j){
    if(i==1 && j==1){
        for(ll k=0;k<p[j].size();k++){
            if(p[j][k].second==0){
                ans[p[j][k].first]=0;
            }else{
                ans[p[j][k].first]=1;
            }
            ki(j,p[j][k].first);
        }
    }else{
        for(ll k=0;k<p[j].size();k++){
            if(p[j][k].first!=i){
                if(p[j][k].second==0){
                    ans[p[j][k].first]=ans[j];
                }else{
                    ans[p[j][k].first]=1-ans[j];
                }
                ki(j,p[j][k].first);
            }
        }
    }
}

int main(){
    cin>>n;
    for(ll i=1;i<n;i++){
        cin>>u[i]>>v[i]>>w[i];
        w[i]=w[i]%2;
        p[u[i]].push_back(make_pair(v[i],w[i]));
        p[v[i]].push_back(make_pair(u[i],w[i]));
    }
    ans[1]=0;
    ki(1,1);
    for(ll i=1;i<=n;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}



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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int maxn = 100005;
const int maxk = 305;

deque<pair<ll, int>> curmax[maxk];

ll del[2 * maxn][maxk];
int a[maxn];
int n, m, k;

int main()
{
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    for (int i = 0; i < k; i++) curmax[i].push_back({-1e18 * (i > 0), -1});
    ll answer = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = k - 1; j >= 0; j--)
        {
//             cout << curmax[j].size() << endl;
            ll curans;
            if (j > 0) {
                while (curmax[j].front().se < i - m) curmax[j].pop_front();
                curans = curmax[j].front().fi + (ll)(j + 1) * a[i];
            } else curans = a[i];
            if (j + 1 == k) answer = max(answer, curans);
            while (!curmax[j + 1].empty() && curmax[j + 1].back().fi <= curans) curmax[j + 1].pop_back();
            curmax[j + 1].push_back({curans, i});
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
  long long n = 0;
  long long ai[100000] = {0};//数字の個数を格納
  long long a = 0;
  long long q = 0;
  long long b = 0, c = 0;
  long long sum = 0;
  
  scanf("%d",&n);
  while(n--){
    scanf("%d",&a);
    ai[a-1]++;
    sum += a;
  }
  
  scanf("%d",&q);
  while(q--){
    scanf("%d %d",&b,&c);
    sum += (c - b) * ai[b-1];
    ai[c-1] += ai[b-1];
    ai[b-1] = 0;
    printf("%lld\n",sum);
  }
  
  return 0;
}


Measured memory_bytes: 2508
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  int sum = A + B + C;
  int x = max(A, max(B, C));
  if (x * 3 % 2 == sum % 2)
  {
    cout << (x * 3 - sum) / 2 /*毎回2ずつ増えるため*/<< endl;
  }
  else
  {
    cout << ((x + 1) * 3 - sum) / 2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main()
{
    Hello
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5])
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;
#define ll long long
#define sorts(c) sort((c).begin(),(c).end());

using namespace std;

void solve() {
	string s;
	int n,sum;
	sum = 0;
	//cin >> n;
	fi(3) {
		int temp;
		cin >> temp;
		sum += temp;
	}
	if (sum >= 22) {
		ce("bust")
	}
	else {
			ce("win")

		 }


	

	
}



int main()
{

	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging;
using System.Security.Principal;
using System.Text;
class Simple
{
    int N;
    int[] p;
    void Solve() {
        //input
        N = io.Int;
        p = new int[N];
        for (int i = 0; i < N; ++i)
            p[i] = io.Int;
        //cal
        var bas = 20000+5;
        var A = p.Select((v, i) => bas * (i + 1)).ToArray();
        var B = p.Select((v, i) => bas * (N - i)).ToArray();
        for (int i = 0; i < N; ++i) {
            B[p[i] - 1] += i+1;
        }
        //ret
        foreach (var v in A) Console.Write(v + " ");
        Console.WriteLine("");
        foreach (var v in B) Console.Write(v + " ");
        Console.WriteLine("");
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    void Stream() {
        Solve();
        io.writeFlush();
    }
}
class SimpleIO
{
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


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

vector<string> split(string str, string sep) {
  vector<string> result;
  int index = 0;
  while (1) {
    int pos = str.find(sep, index);
    if (pos == string::npos) {
      result.push_back(str.substr(index));
      break;
    }
    result.push_back(str.substr(index, pos - index));
    index = pos + sep.size();
  }
  return result;
}

long long func(string s, int n) {
  if (n == 0) {
    vector<string> result = split(s, "+");
    long long sum = 0;
    for (string v : result) sum += stoll(v);
    return sum;
  }
  string copy_s = s;
  return func(copy_s, n-1) + func(s.insert(n, "+"), n-1);
}

int main() {
  string S;
  cin >> S;
  cout << func(S, S.size()-1) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int A[200000],i,j,n,min=999999999,max=-999999999,sa;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  min=A[0];
  for(i=1;i<n;i++){
    sa=A[i]-min;
    if(max<sa)max=sa;
    if(min>A[i])min=A[i];
  }
  printf("%d\n",max);
  return 0;
}



Measured memory_bytes: 2580
# 壊れている床を無視すればフィボナッチ数になってる
from collections import defaultdict

def Fib(n, broken):
    dd = defaultdict(int)

    dd[0] = 1
    dd[1] = 1

    for i in range(2, n+1):
        if broken[i-1] == 0:
            dd[i] += dd[i-1]
        if broken[i-2] == 0:
            dd[i] += dd[i-2]

    return dd[n]


n, m = map(int, input().split())
A = [int(input()) for _ in range(m)]
broken = defaultdict(int)
for c in A:
    broken[c] = 1

ans = Fib(n, broken)
print(ans % 1000000007)

Measured memory_bytes: 480844
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

template <typename T>
void say(vector<T>& vec, string pad = " ") {
	for (const T& elem : vec)
		cout << elem << pad;
}


/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	YN(b - a == c - b);

	return 0;
}

Measured memory_bytes: 256
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    n = gets.chomp.to_i
    as = gets.chomp.split.map(&:to_i)

    min, max = as.minmax

    puts max - min

  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2044
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define rall(x) x.rbegin() , x.rend()
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
// const int N = ;
#define singleCase
// #define multipleCase
int n,x;

void work() {
   in(n); in(x);
   vector <int> v(n);
   for (int i = 0 ; i < n ; i++) {
      in(v[i]);
   }
   sort(all(v));
   int sol = 0, lst = -1;
   for (int i = 0 ; i < n ; i++) {
      if (x >= v[i]) {
         sol++, lst = i, x -= v[i];
      }
   }
   if (lst == n - 1 && x > 0) sol--;
   printf("%d\n" , sol);
   return;
}

int main() {
   #ifdef multipleCase
      int nQ; in(nQ);
      while (nQ--)
         work();
   #endif
   #ifdef singleCase
      work();
   #endif
   return 0;
}

void in(int &x) {
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-') {
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	  x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


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

int main(){
    long long num=0, num1=0;
    string num1_str="";
    vector<ll> ans;
    cin>>num;
    queue<ll> que;
    for(ll i = 1; i < 10; i++){
        que.push(i);
        ans.push_back(i);
    }
    
    while (!que.empty()) {
        ll v = que.front(); // キューから先頭頂点を取り出す
        que.pop();
        string str = to_string(v);

        if(str[str.size() - 1] != '0'){
            ll tmp;
            ll degit;
            degit = ll(str[str.size() - 1] - '0')  - 1;
            string tmp_str = to_string(v);
            tmp_str += to_string(degit);
            tmp = atoll(tmp_str.c_str());
            que.push(tmp);
            ans.push_back(tmp);
        }

        if(1){
            ll tmp;
            ll degit;
            degit = ll(str[str.size() - 1] - '0');
            string tmp_str = to_string(v);
            tmp_str += (to_string(degit));
            tmp = atoll(tmp_str.c_str());
            que.push(tmp);
            ans.push_back(tmp);
        }


        if(str[str.size() - 1] != '9'){
            ll tmp;
            int degit;
            degit = ll(str[str.size() - 1] - '0')  + 1;
            string tmp_str = to_string(v);
            tmp_str += to_string(degit);
            tmp = atoll(tmp_str.c_str());
            que.push(tmp);
            ans.push_back(tmp);
        }
        if(ans.size() > num){
            break;
        }
    }
    sort(ans.begin(),ans.end());


    cout << ans[num - 1] << endl;
}   


Measured memory_bytes: 4636
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=2e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int fa[N],siz[N];
inline int find(int x) { return fa[x]==x?x:fa[x]=find(fa[x]); }
multiset<int>e[N];
int main()
{
	int n=gi(),i,a,b,t=n-1,k;pair<int,int>p;
	multiset< pair<int,int> >s;multiset<int>::iterator it;
	queue< pair<int,int> >q;
	for (i=(n-1)<<1;i;i--) {
		if ((a=gi())>(b=gi())) swap(a,b);
		e[a].insert(b);
		e[b].insert(a);
		s.insert(make_pair(a,b));
		if (s.count(make_pair(a,b))==2) q.push(make_pair(a,b)),s.erase(make_pair(a,b));
	}
	for (i=1;i<=n;i++) fa[i]=i,siz[i]=1;
	while (!q.empty()) {
		a=q.front().first;
		b=q.front().second;
		q.pop();
		if (fa[a]!=a||fa[b]!=b||a==b) continue;t--;
		if (siz[fa[a]]>siz[fa[b]]) swap(a,b);
		siz[b]+=siz[a];fa[a]=b;
		e[b].erase(a);
		e[a].erase(b);
		for (it=e[a].begin();it!=e[a].end();it++) {
			e[*it].erase(e[*it].find(a));
			k=find(*it);
			e[k].insert(b);
			e[b].insert(k);
			p=make_pair(min(k,b),max(k,b));
			s.insert(p);
			if (s.count(p)==2) s.erase(p),q.push(p);
		}
	}
	puts(t?"NO":"YES");
	return 0;
}


Measured memory_bytes: 40192
data Score = Score Int Int Int deriving (Show,Read,Eq)
data Grade = A|B|C|D|E|F deriving (Show)

total :: Score->Int
total (Score m f _) = m+f

isAbscent :: Score -> Bool
isAbscent (Score m f _)
	|m == -1 || f == -1 = True
	|otherwise = False
	
kyusai ::Score->Bool
kyusai (Score _ _ r)
	|r>=50 = True
	|otherwise = False
	
readScore :: String->Score
readScore = (\[a,b,c]->Score a b c).map (read :: String->Int).words

grading :: Score->Grade
grading x
	|isAbscent x || total x < 30 = F
	|total x < 50 && not (kyusai x) = D
	|total x < 50 && kyusai x = C
	|total x < 65 = C
	|total x < 80 = B
	|otherwise = A
	
haltSignal :: Score
haltSignal = Score (-1) (-1) (-1)

main = getContents >>= mapM_ print.map grading.takeWhile (/=haltSignal).map readScore.lines

Measured memory_bytes: 4072
package main

import (
	"fmt"
	"os"
)

var n, x, y int
var graph [][]int

type Que []int

func (q *Que) push(x int) {
	*q = append(*q, x)
}
func (q *Que) pop() int {
	top := (*q)[0]
	*q = (*q)[1:]
	return top
}

func main() {
	fmt.Scan(&n, &x, &y)
	graph = make([][]int, n)
	// build
	for i := 0; i < n-1; i++ {
		graph[i] = append(graph[i], i+1)
		graph[i+1] = append(graph[i+1], i)
	}
	graph[x-1] = append(graph[x-1], y-1)
	graph[y-1] = append(graph[y-1], x-1)

	dist := make([][]int, n)
	dists := make(map[int]int)
	for i := range dist {
		dist[i] = make([]int, n)
		for j := range dist[i] {
			dist[i][j] = -1
		}
		dist[i][i] = 0
		dists[0] += 2
	}

	for i := range dist {
		que := make(Que, 0)
		que.push(i)
		for len(que) > 0 {
			j := que.pop()
			d := dist[i][j]
			for _, nv := range graph[j] {
				if dist[i][nv] != -1 {
					continue
				}
				dist[i][nv] = d + 1
				dists[d+1]++
				que.push(nv)
			}
		}
	}

	fmt.Fprintln(os.Stderr, dist)
	for k := 1; k < n; k++ {
		fmt.Println(dists[k] / 2)
	}
}


Measured memory_bytes: 133504
package main

import (
	"fmt"
	"io"
	"os"
)

func Run(in io.Reader, out io.Writer) error {
	var a, b, c int64
	fmt.Fscan(in, &a, &b, &c)
	if a+b >= c {
		fmt.Fprint(out, "Yes\n")
	} else {
		fmt.Fprint(out, "No\n")
	}
	return nil
}

func main() {
	in, out := os.Stdin, os.Stdout
	Run(in, out)
}


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

int main()
{
    int h,w;
    cin>>h>>w;
    char sl[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)
            cin>>sl[i][j];
    }

    
    int dp[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)
            dp[i][j] = 0;
    }
    dp[0][0] = 1;
    // for(int i=0;i<h;i++){
    //     for(int j=0;j<w;j++)
    //         cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    
    for(int i=1;i<h;i++){
        if(sl[i][0] == '.')
            dp[i][0] = dp[i-1][0];
    }
    
    
    
    for(int i=1;i<w;i++){
        if(sl[0][i] == '.')
            dp[0][i] = dp[0][i-1];
    }
    
    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++){
            if(sl[i][j] == '.')
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
        }
    }
    cout<<dp[h-1][w-1];
    
    return 0;
}



Measured memory_bytes: 5120
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define N 110
using namespace std;

int n,i,j,g,k,p;
int x[N],y[N],h[N]; 

inline int Abs(int x){return (x<0)?-x:x;}
inline int Max(int a,int b){return (a>b)?a:b;} 

int main(){
//	freopen("zht.in","r",stdin);
//	freopen("zht.out","w",stdout);
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%d%d%d",&x[i],&y[i],&h[i]);
		if (h[i]>h[0])	h[0]=h[i];
	}
	int flag;
	for (i=h[0];i<=h[0]+110;i++){
		for (j=0;j<=100;j++){
			for (g=0;g<=100;g++){
				flag=0;
				for (k=1;k<=n;k++){
						p=Max(0,i-Abs(x[k]-j)-Abs(y[k]-g));
						if (p!=h[k])	goto END;
				}
			if (!flag){
				cout<<j<<" "<<g<<" "<<i<<endl;
				return 0;
			}
			END:
				flag=1;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#if 1
#ifdef LOCAL
#define _GLIBCXX_DEBUG 1
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)

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

#define ts to_string
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) { str res = ""; F0R(i,SZ) res += char('0'+b[i]); return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { bool fst = 1; str res = "{"; for (const auto& x: v) {if (!fst) res += ", ";	fst = 0; res += ts(x);}	res += "}"; return res;}
template<class A, class B> str ts(pair<A,B> p) {return "("+ts(p.f)+", "+ts(p.s)+")"; }
 
template<class A> void pr(A x) { cout << ts(x); }
template<class H, class... T> void pr(const H& h, const T&... t) { pr(h); pr(t...); }
void ps() { pr("\n"); }
template<class H, class... T> void ps(const H& h, const T&... t) { pr(h); if (sizeof...(t)) pr(" "); ps(t...); }
 
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {cerr << ts(h); if (sizeof...(t)) cerr << ", ";	DBG(t...); }
#endif

long long ans = 0;
int tree[1100000][26];
int tag[1100000][26];
vector<int> nd(26);
int nn = 1;

void add(const string& s) {
    fill(all(nd), 0);
    int cur = 0;

    for (int i = sz(s)-1; i >= 0; i--) {
        for (int i = 0; i < 26; i++) {
            nd[i] += tag[cur][i];
        }

        ans += nd[s[i]-'a'];
        nd[s[i]-'a'] = 0;

        if (i == 0) tag[cur][s[i]-'a']++;

        if (tree[cur][s[i]-'a'] == 0) tree[cur][s[i]-'a'] = nn++;
        cur = tree[cur][s[i]-'a'];
    }
}

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

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

    sort(all(strs), [](const str& a, const str& b) { return sz(a) < sz(b); });

    for (int i = 0; i < n; i++) add(strs[i]);

    cout << ans << endl;

    return 0;
}

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

using namespace std;

const int MAXN = 1e5 + 5;

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(17);
  int n;
  cin >> n;
  if(n <= 2){
    cout << "2\n"; return 0;
  }
  vector<int> v(n);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  vector<int> a(MAXN, 0), b(MAXN, 0);
  for(int i = 0; i < n; i++){
    if(i & 1) b[v[i]]++;
    else a[v[i]]++;
  }
  vector<pair<int,int>> x, y;
  for(int i = 0; i < MAXN; i++){
    if(!a[i] && !b[i]) continue;
    if(a[i]) x.push_back({a[i], i});
    if(b[i]) y.push_back({b[i], i});
  }
  sort(x.begin(), x.end()); reverse(x.begin(), x.end());
  sort(y.begin(), y.end()); reverse(y.begin(), y.end());
  int ans = 2e9;
  if(x[0].second == y[0].second){
    if(y.size() > 1) ans = min(ans, n - x[0].first - y[1].first);
    else ans = min(ans, n - max(x[0].first, y[0].first));
    if(x.size() > 1) ans = min(ans, n - y[0].first - x[1].first);
    else ans = min(ans, n - max(y[0].first, x[0].first));
  } else {
    ans = n - x[0].first - y[0].first;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 2428
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define fish        push_front
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Deque       std::deque
#define PQueue      std::priority_queue
#define Set         std::set
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    inline boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    int c[1010];

    signed call_of_Cthulhu( signed datum ) {

        int a, b;
        read a >> b;
        c[1] = 1;
        for ( int i = 2; i <= 1000; i++ ) {
            c[i] = c[i-1]+i;
            if ( c[i-1]-a == c[i]-b ) {
                echo c[i]-b fin;
            }
        }

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		for (int i = 0; i < N; ++i)
			A[i] = sc.nextInt();
		Main main = new Main();
		int swapcnt = main.bubbleSort(A, N);
		for (int i = 0; i < N; ++i) {
			if (i > 0) System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
		System.out.println(swapcnt);
	}
	public int bubbleSort(int A[], int N) {
		int swapcnt = 0;
		boolean fin = false; // Did sorting finish?
		while (!fin) {
			fin = true; // No swapping means finish of sorting.
			for (int j = N - 1; j > 0; --j) {
				if (A[j] < A[j - 1]) {
					// swapping A[j] for A[j - 1]
					int tmp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = tmp;
					++swapcnt;
					fin = false; // Swapping was found.
				}
			}
		}
		return swapcnt;
	}
}


Measured memory_bytes: 26196
main = do
  [a, b, k] <- map read . words <$> getLine
  let xs = [x | x <- [n, n-1..1], (b `mod` x) == 0, (a `mod` x) == 0]
  		where n = if (a > b) then a else b
  print $ xs !! (k - 1)

Measured memory_bytes: 508
def main():
    n = int(input())
    ans = solve1(n)
    print(ans)


def solve1(n):
    if n <= 1:
        return 1
    a, b = 1, 1

    for _ in range(2, n + 1):
        a, b = b, a + b
    return b

if __name__ == '__main__':
    main()

Measured memory_bytes: 5600
#include<stdio.h>
#include<stdlib.h>

int main(){
  int n,i,m;
  int *h;
  scanf("%d",&n);
  h=(int*)malloc(sizeof(int)*(n+1));
  h[0]=0;
  m=0;
  for(int j=1;j<n+1;j++){
    scanf("%d",&h[j]);
    if(h[0]<=h[j])
      {
      h[0]=h[j];
      m++;
    };
  };
  printf("%d\n",m);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <queue>
#define llint long long

using namespace std;

llint n;
string s;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	cin >> s;
	
	int ans = 0;
	for(int i = 1; i < n; i++){
		int cnt = 0;
		for(int j = 0; j+i < n; j++){
			if(s[j] == s[j+i]) cnt++;
			else cnt = 0;
			ans = max(ans, min(cnt, i));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long ans;
int main () {
	int n;
	string s;
	cin >> n >> s;
	set <int> r,g,b;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'R') {
			r.insert (i);
		}
		else if (s[i] == 'G') {
			g.insert (i);
		}
		else {
			b.insert (i);
		}
	}
	for (int rr : r) {
		for (int gg : g) {
			int x = max (rr, gg);
			int y = min (rr, gg);
			ans += (int)b.size();
			
			int d = (x - y);
			if (b.find(x + d) != b.end()) {
				ans--;
			}
			if (d % 2 == 0 && b.find (y + (d / 2)) != b.end()) {
				ans--;
			}
			if (b.find(y - d) != b.end()) {
				ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3768
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.Queue;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EVirusTree2 solver = new EVirusTree2();
        solver.solve(1, in, out);
        out.close();
    }

    static class EVirusTree2 {
        public static long mod = 10000_0000_7;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            ArrayList<Integer> a[] = new ArrayList[n];
            boolean visited[] = new boolean[n];
            int neighbour[] = new int[n];
            for (int i = 0; i < n; i++) a[i] = new ArrayList<Integer>();
            for (int i = 0; i < n - 1; i++) {
                int u = in.nextInt() - 1;
                int v = in.nextInt() - 1;
                a[u].add(v);
                a[v].add(u);
            }
            Queue<Integer> q = new LinkedList<>();
            q.add(0);
            long ans = 1;
            while (q.size() > 0) {
                int node = q.poll();
                long count = 0;
                if (visited[node]) {
                    continue;
                }
                visited[node] = true;
                for (int x : a[node]) {
                    if (!visited[x]) q.add(x);
                    else count++;
                    count += neighbour[x];
                    neighbour[x]++;
                }
                if (k - count < 0) ans = 0;
                ans *= (k - count) % mod;
                ans %= mod;
            }
            out.println(ans);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 56892
from collections import deque

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

ans = 0
tmp = 0
buf = deque()

for a in A:
    while tmp & a:
        item = buf.popleft()
        tmp ^= item
    buf.append(a)
    tmp |= a
    ans += len(buf)
print(ans)


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

int main(){

int n,input[10000],cont,bon,dice[7];
char bin[10];

while(1){

scanf("%d",&n);

if(n==0){
break;
}

for(int i=0;i<7;i++){
dice[i]=i;
}
for(int i=0;i<n;i++){
scanf("%s",bin);
switch(bin[0]){
case 'N':input[i]=1;break;
case 'E':input[i]=2;break;
case 'W':input[i]=3;break;
case 'S':input[i]=4;break;
case 'R':input[i]=5;break;
case 'L':input[i]=6;break;
}
}

cont=0;

for(int i=0;i<n;i++){
cont+=dice[1];
switch(input[i]){
case 1:
bon = dice[1];
dice[1]=dice[2];
dice[2]=dice[6];
dice[6]=dice[5];
dice[5]=bon;
break;
case 2:
bon = dice[1];
dice[1]=dice[4];
dice[4]=dice[6];
dice[6]=dice[3];
dice[3]=bon;
break;
case 3:
bon = dice[1];
dice[1]=dice[3];
dice[3]=dice[6];
dice[6]=dice[4];
dice[4]=bon;
break;
case 4:
bon = dice[1];
dice[1]=dice[5];
dice[5]=dice[6];
dice[6]=dice[2];
dice[2]=bon;
break;
case 5:
bon = dice[2];
dice[2]=dice[3];
dice[3]=dice[5];
dice[5]=dice[4];
dice[4]=bon;
break;
case 6:
bon = dice[2];
dice[2]=dice[4];
dice[4]=dice[5];
dice[5]=dice[3];
dice[3]=bon;
break;
}
}
cont+=dice[1];
printf("%d\n",cont);
}



}

Measured memory_bytes: 0
li1 = []
li2 = []
ans = 0
for i, s in enumerate(input()):
    if s == "\\":
        li1.append(i)
    elif s == "/" and li1:
        j = li1.pop()
        c = i - j
        ans += c
        while li2 and li2[-1][0] > j:
            c += li2[-1][1]
            li2.pop()
        li2.append((j, c))
print(ans)
if li2:
    print(len(li2), *list(zip(*li2))[1])
else:
    print(0)



Measured memory_bytes: 6500
from sys import stdin

case = 0
while(True):
    case += 1
    W = int(stdin.readline())
    if not W: break
    print("Case %d:"%case)
    N = int(stdin.readline())
    v = [0] * N
    w = [0] * N
    dp = [[0]*(W + 1) for _ in range(N + 1)]

    for k in range(N):
        v[k], w[k] = map(int, stdin.readline().split(","))
    for i in range(N-1,-1,-1):
        for j in range(W+1):
            if j < w[i]:
                dp[i][j] = dp[i + 1][j]
            else:
                dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i])
    print(dp[0][W])
    for i in range(W+1):
        if dp[0][i] == dp[0][W]: print(i); break




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

int main(int argc, char const *argv[])
{
	int l;
	cin>>l;
	--l;
	int n=0,m=0;
	++l;
	while (l>=(1<<n))
	{
		++n;
	}
	--l;
	m=(n-1)*2;
	vector<pair<pair<int,int>,int>> ans;
	for (int i = 0; i < n-1; ++i)
	{
		ans.push_back(make_pair(make_pair(i+1,i+2),0));
		ans.push_back(make_pair(make_pair(i+1,i+2),(1<<(n-i-2))));
	}
	int now=l-(1<<(n-1))+1;
	while (now>0)
	{
		++m;
		int r=0;
		while (now>=(1<<r))
		{
			++r;
		}
		--r;
		ans.push_back(make_pair(make_pair(1,n-r),l-now+1));
		now-=(1<<r);
	}
	cout<<n<<" "<<m<<endl;
	for (auto v:ans)
	{
		cout<<v.first.first<<" "<<v.first.second<<" "<<v.second<<endl;
	}
	return 0;
}


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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int a[] = new int[N];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
        }
        BubbleSort(a);
    }
    

    static void BubbleSort(int[] a){
    int count = 0;
    for (int i = 0; i <  a.length- 1; i++) {
        for (int j = a.length - 1; j > i; j--) {
            if (a[j - 1] > a[j]) {     
                int tmp = a[j - 1];
                a[j - 1] = a[j];
                a[j] = tmp;
                count++;
            }
        }
    }
    System.out.println(Arrays.toString(a) .replaceAll("[\\[\\],]", ""));

        System.out.println(count);
}
    
}




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

n,m = list(map(int, input().split()))

N = [[] for _ in range(n)]
V = [0] * n
counter = -1

for _ in range(m):
  x,y = list(map(int, input().split()))
  x -= 1
  y -= 1
  N[x].append(y)
  N[y].append(x)
  
for i in range(n):
  #print(i, V)
  if V[i]==0:
    Q = [i]
    while Q:
      node = Q.pop()
      V[node]=1
      for child in N[node]:
        if V[child]==0:
          Q.append(child)
          V[child] = 1
    counter += 1
    
print(counter)

Measured memory_bytes: 80888
n, q = [int(s) for s in input().split()]
max_n = 2**31-1
m = 1
while m < n:#nが2の冪乗でないときに2の冪乗
    m *= 2

dat = [max_n] * (2*m-1)
#print(len(dat))

def update(i, x):
    i += m-1
    dat[i] = x
    while i > 0:
        i = int((i-1)/2)
        dat[i] = min(dat[2*i+1], dat[2*i+2])

def find(a, b, k, l, r):
    if r <= a or b <= l:
        return max_n
    elif a <= l and r <= b:
        return dat[k]
    else:
        vl = find(a, b, 2*k+1, l, int((l+r)/2))
        vr = find(a, b, 2*k+2, int((l+r)/2), r)
        return min(vl, vr)

for _ in range(q):
    com, i, x = [int(s) for s in input().split()]
    if com == 0:
        update(i, x)
    else:
        ans = find(i, x+1, 0, 0, m)
        print(ans)



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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end()))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
double p[3300];
double dp[3300][3300];
signed main() {
    cin >> N;
    rep(i, N) { cin >> p[i]; }
    dp[0][0] = 1;
    rep(i, N) {
        for (int j = 0; j <= i; j++) {
            dp[i + 1][j] += dp[i][j] * (1 - p[i]);
            dp[i + 1][j + 1] += dp[i][j] * p[i];
        }
    }
    double ans = 0;
    for (int i = cdiv(N, 2); i <= N; i++) { ans += dp[N][i]; }
    cout << ans << endl;
}


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

int main() {
 double W, H, x, y, r;
 cin >> W >> H >> x >> y >> r;
 if (x + r > H){
   cout << "No";
 } else if (x - r < 0){
   cout << "No";
 } else if (y + r > H){
   cout << "No";
 } else if (y - r < 0){
   cout << "No";
 } else {
   cout << "Yes" ;
 }
 cout << endl;
 return 0;
}


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

int main()
{
    int n, p = 1, x[10] = {}, y[10] = {};
    cin >> n;
    for (int i = 1; i <= n - 1; ++i) p *= i;
    double lung, s = 0;
    for (int i = 1; i <= n; ++i)
    {
        cin >> x[i] >> y[i];
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = i + 1; j <= n; ++j)
        {
            lung = 1.0 * 1LL * sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
            s += 2 * lung * p;
        }
    }
    cout << fixed << setprecision(9) << s / (p * n);
    return 0;
}


Measured memory_bytes: 256
(* O(n + m) *)
let n = Scanf.scanf " %d" @@ (+) 0
let ts = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let m = Scanf.scanf " %d" @@ (+) 0
let pxs = Array.init m @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a - 1, b
let sum = Array.fold_left (+) 0 ts
let _ =
  let f (p, x) = Printf.printf "%d\n" @@ sum - ts.(p) + x in
  Array.iter f pxs

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int main(void){
    char str[200];
    char s1[200];
    char s2[200];
    int num;
    int shuf;
    int i,j;
    while(1){
        scanf("%s",str);
        if(strcmp(str,"-")==0) break;
        scanf("%d",&num);
        for(i=0;i<num;i++){
            scanf("%d",&shuf);
            for(j=0;j<shuf;j++)
                s1[j]=str[j];
            for(j=0;j<strlen(str)-shuf;j++)
                str[j]=str[j+shuf];
            for(j=0;j<shuf;j++)
                str[strlen(str)-shuf+j]=s1[j];
        }
        printf("%s\n",str);
    }
    return 0;
}

Measured memory_bytes: 584
#include<iostream>
#include<algorithm>
#include<set>
#include <string>
using namespace std;

int main(){
    while (1) {
        string str;
        cin>>str;
        if("#"==str){
            break;
        }
        int y,m,d;
        cin>>y>>m>>d;
        if(y > 31 || y == 31 && m >= 5){
            std::cout<<"? "<<y-30<<" "<<m<<" "<<d<<endl;
        }else{
            std::cout<<str<<" "<<y<<" "<<m<<" "<<d<<endl;
        }
    }
}



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

int main()
{
  int d[500][500];
  int n, m;

  while (cin >> n >> m, n){

    for (int i = 0; i < n; i++){
      for (int j = 0; j < n; j++){
        d[i][j] = 1e9;
      }
    }

    for (int i = 0; i < n; i++){
      d[i][i] = 0;
    }

    for (int i = 0; i < m; i++){
      int a, b;
      cin >> a >> b;
      a--; b--;
      d[a][b] = 1;
      d[b][a] = 1;
    }

    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 cnt = 0;
    for (int i = 1; i < n; i++){
      if (d[0][i] < 3) cnt++;
    }

    cout << cnt << endl;
  }
}

Measured memory_bytes: 4016
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int n;
int s[110];


signed main(){
    while(cin >> n, n > 0){
        rep(i, 0, n) cin >> s[i];
        int a = accumulate(s, s+n, 0LL);
        a -= *max_element(s, s+n);
        a -= *min_element(s, s+n);
        cout << a/(n-2) << endl;
    }

    return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <utility>
#include <map>
#include <set>
#include <list>
#include <limits>

using namespace std;

using Pos = pair<int64_t, int64_t>; // station, company

int64_t N, M;

map<Pos, list<Pos> > Way;
set<Pos> Path;

int main()
{

  cin >> N >> M;
  for (int64_t i=0; i<M; ++i) {
    int64_t p, q, c;
    cin >> p >> q >> c;

    Way[make_pair(p, c)].push_back(make_pair(q, c));
    Way[make_pair(q, c)].push_back(make_pair(p, c));

    Way[make_pair(p, c)].push_back(make_pair(p, -1));
    Way[make_pair(p, -1)].push_back(make_pair(p, c));

    Way[make_pair(q, c)].push_back(make_pair(q, -1));
    Way[make_pair(q, -1)].push_back(make_pair(q, c));
  }

  list<Pos> updated;
  for (auto it=Way.lower_bound(make_pair(1, 1)); it!=Way.end() && it->first.first == 1; ++it) {
    if (Path.insert(it->first).second)
      updated.push_back(it->first);
  }

  for (uint64_t cost=1; ! updated.empty(); ++cost) {
    list<Pos> nexts;

    for (const auto& p : updated) {

      for (const auto& q : Way[p]) {
        if (q.first == N) {
          cout << cost << endl;
          return 0;
        }

        if (Path.insert(q).second) {
          if (q.second == -1)
            nexts.push_back(q);
          else
            updated.push_back(q);
        }
      }
    }

    swap(updated, nexts);
  }

  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 121216
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 
 using namespace std;
 
 struct stu
 {
   int num;
   int score;
   int rank;      
 };
 
 stu mm[10000+5];
 
 int comp(stu a,stu b)
 {
   return a.score>b.score;    
 }

 int main()
 {
   int n,m;
   char temp;
   int count=0;
   while(cin>>n>>temp>>m&&(n||m))
   {
     mm[count].num=n;
     mm[count].score=m;
     count++;                                
   }
   sort(mm,mm+count,comp);
   //for(int i=0;i<count;i++) cout<<mm[i].num<<endl;
   int count2=1;
   bool flag=false;
   for(int i=0;i<count;i++)
   {
     if(!flag)
     {
       mm[i].rank=1;
       flag=true;         
     }          
     else if(mm[i].score==mm[i-1].score)
     {
       mm[i].rank=mm[i-1].rank;     
     }
     else
     {
       count2++;
       mm[i].rank=count2;    
     }
   }
   int query;
   while(cin>>query) 
   {
     for(int i=0;i<count;i++)
     {
       if(mm[i].num==query)
       {
         cout<<mm[i].rank<<endl;
         break;                    
       }        
     }                  
   }
   //while(1);
   return 0;
 }

Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;

ll sumdigits(ll N){
    ll ans=0;
    while(N>0){
        ans+=N%10;
        N-=N%10;
        N/=10;
    }
    return ans;
}

int main() {
    ll N,A,B,ans=0;cin>>N>>A>>B;
    rep1(i,N){
        ll a=sumdigits(i);
        if(A<=a&&a<=B){ans+=i;}
    }
    cout<<ans<<endl;
}

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

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

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

using namespace std;

vector<int> countingSort(const vector<int> &a, int k) {
	int n = a.size();
	vector<int> res(k + 1, 0);
	vector<int> ans(n);
	REP(i, n) {
		res[a[i]]++;
	}
	REP(i, k) {
		res[i + 1] += res[i];
	}
	RREP(i, n) {
		ans[res[a[i]]-1] = a[i];
		res[a[i]]--;
	}
	return ans;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k = 10000;
	cin >> n;
	vector<int> a(n);
	REP(i, n) {
		cin >> a[i];

	}
	vector<int> v=countingSort(a, k);
	REP(i, n) {
		cout << v[i];
		if (i == n - 1) cout << endl;
		else cout << " ";
	}
	return 0;
}

Measured memory_bytes: 18516