akhauriyash/Code-Regression huggingface dataset:
(defun sqrt-inequality ()
  (let ((a (read))
        (b (read))
        (c (read))
        (ans "No"))
    (if (and (< 0 (- c a b)) (< (* 4 a b) (expt (- c a b) 2)))
      (setf ans "Yes"))
    ans))

(format t "~A~%" (sqrt-inequality))

Measured memory_bytes: 11876
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramC
    {
        private class Pair
        {
            public int A {get;set;}
            public int B {get;set;}
            public int C {get;set;}
            public int D {get;set;}
        }
        static int n, m, q;
        static List<Pair> pairs;

        static void Main()
        {
            n = NextInt;
            m = NextInt;
            q = NextInt;
            pairs = TakeLine(q).Select(l => new Pair{A = (int)l[0], B = (int)l[1], C = (int)l[2], D = (int)l[3]}).ToList();

            System.Console.WriteLine(Dfs(new List<int>(), 1));
        }

        static int Dfs(List<int> list, int last)
        {
            if (list.Count() == n) return pairs.Where(p => list[p.B - 1] - list[p.A - 1] == p.C).Sum(p => p.D);

            return Enumerable.Range(last, m - last + 1).Max(x => Dfs(list.Concat(new int[]{x}).ToList(), x));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


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

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

    for (int i=1; i<n+1; i++)
    {
        if (i%3==0)
        {
            cout << " " << i;
        }
        else if (i%10==3)
        {
            cout << " " << i;
        }
        else 
        {
            for (int j=i; j; j/=10)
            {
                if (j%10==3)
                {
                    cout << " " << i;
                    break;
                }
            }
        }
    }

    cout << endl;
}



Measured memory_bytes: 3080
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	scanInit()

	n := nextInt()
	x := nextInt()
	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	sort.Ints(a)
	ans := 0
	for i := 0; i < n-1; i++ {
		if a[i] <= x {
			x -= a[i]
			ans++
		}
	}
	if x == a[n-1] {
		ans++
	}
	fmt.Println(ans)

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
#include<stdio.h>
int main(void)
{   int a,b,i;
    char op;
    for(i=1;i>0;i++){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+')
        {printf("%d\n",a+b);
        }
        else if(op=='-')
        {printf("%d\n",a-b);
        }
        else if(op=='*')
        {printf("%d\n",a*b);
        }
        else if(op=='/'){
            printf("%d\n",a/b);
        }else if(op=='?') {
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 2040
#include<iostream>
using namespace std;
int main(){
	string s;
	cin >> s;
	int ans=0;
	int tmp=0;
	for(int i=0;i<s.length();i++){
		if(i%2 && s[i]=='0') tmp++;
		else if(i%2==0 && s[i]=='1') tmp++;
	}
	ans=tmp;
	tmp=0;
	for(int i=0;i<s.length();i++){
		if(i%2 && s[i]=='1') tmp++;
		else if(i%2==0 && s[i]=='0') tmp++;
	}
	ans=min(ans,tmp);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>

int main(){
	std::string s;
	std::cin >> s;
			
	std::vector<int> bucket(26, 0);
	for(unsigned int i = 0; i < s.size(); ++i){
		int z = static_cast<int>(s.at(i)) - 'a';
		//std::cout << s.at(i) << " : " << z << std::endl;
		++bucket.at(z);
	}

	for(unsigned int i = 0; i < bucket.size(); ++i){
		if(bucket.at(i) == 0){
			std::cout << static_cast<char>(i + 'a') << std::endl;
			break;
		}
		else if(i == bucket.size() - 1){
			std::cout << "None" << std::endl;
		}
	}

	return 0;
}
	


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    System.out.println(a * b);
  }
}

Measured memory_bytes: 32612
using System;

class Sentence
{
    public static void Main()
    {
        string longest = null;
        var s = Console.ReadLine();
        var str = s.Split();
        int[] count = new int[str.Length];
        int max = 0, suffix=0, p = 0;
        for(int i=0;i<str.Length;i++) str[i] = str[i].ToLowerInvariant();

        for (int i = 0; i < str.Length; i++)
        {
            for (int j = i; j < str.Length; j++)
            {
                if (str[i] == str[j]) count[i]++;
            }
        }
        foreach (int x in count) { if (x > max) max = x; }
        for(int i = 0; i < str.Length; i++) { if (max == count[i]) suffix = i; }

        for(int i = 0; i < str.Length; i++)
        {
            if (p < str[i].Length)
            {
                p = str[i].Length;
                longest = str[i];
            }
        }

        Console.WriteLine("{0} {1}", str[suffix], longest);

    }
}

Measured memory_bytes: 8844
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		Integer[] A = nextIntegerArray(sc, N);

		sc.close();

		Map<Integer, Long> m = Arrays.stream(A).collect(Collectors.groupingBy(a -> a, Collectors.counting()));

		int k = m.size();

		Long ans = m.entrySet().stream()
				.sorted((e1, e2) -> e1.getValue().compareTo(e2.getValue()))
				.limit(Math.max(k - K, 0))
				.map(e -> e.getValue())
				.reduce((a, b) -> a + b)
				.orElse(0L);

		out.println(ans);

	}

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

	@SuppressWarnings("unused")
	private Integer[] nextIntegerArray(Scanner sc, int n) {
		Integer[] result = new Integer[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 101616
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

val = (n-1) // 2

arr = list(map(int, arr_data[1]))

arr_sort = sorted(arr)

val1 = arr_sort[(n // 2)-1]
val2 = arr_sort[(n // 2)]

for v in arr:
    
    if v<=val1:
        
        print(val2)
        
    else:
        
        print(val1)


Measured memory_bytes: 29712
import * as fs from 'fs'

function main(args: string) {
    // sardine
    // xxxxxxx
    let result: string = '';
    for (let i: number = 1; i < args.length; i++) {
        result = result + 'x';
    }

    console.log(result);
}

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


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())

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

const int n = 505;
const int INF = 1e5;

int N;
bool occ[n][n];
int dp[n][n];
int x[4] = {0, 1, 0, -1};
int y[4] = {1, 0, -1, 0};

void printOcc(){
  for(int i=1; i<=N; i++){
    for(int j=1; j<=N; j++)
      cout << occ[i][j];
    cout << endl;
  }
}
void printDp(){
  for(int i=1; i<=N; i++){
    for(int j=1; j<=N; j++)
      cout << dp[i][j] << " ";
    cout << endl;
  }
}

void calc(int orig=-1){
  deque<int> Q;
  if(orig == -1){
    for(int i=2; i<N; i++){
      for(int j=2; j<N; j++)
        dp[i][j] = INF;
    }
    for(int i=1; i<=N;i++){
      Q.push_back(i+N+1);
      Q.push_back(i+N*(N+1));
      Q.push_back(1+i*(N+1));
      Q.push_back(N+i*(N+1));
    }
  }
  else{
    Q.push_back(orig);
  }
  while(!Q.empty()){
    int r = Q.front()/(N+1);
    int c = Q.front()%(N+1);
    Q.pop_front();
    if(r > N || r < 1 || c < 1 || c > N)
      continue;
    for(int i=0; i<4; i++){
      if(occ[r][c]){
        if(dp[r+y[i]][c+x[i]] > dp[r][c]+occ[r][c]){
          dp[r+y[i]][c+x[i]] = dp[r][c]+occ[r][c];
          Q.push_back((r+y[i])*(N+1)+c+x[i]);
        }
      }
      else{
        if(dp[r+y[i]][c+x[i]] > dp[r][c]+occ[r][c]){
          dp[r+y[i]][c+x[i]] = dp[r][c]+occ[r][c];
          Q.push_front((r+y[i])*(N+1)+c+x[i]);
        }
      }
    }
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  for(int i=1; i<=N;i++)
    for(int j=1; j<=N; j++)
      occ[i][j] = true;
  ll res = 0;
  calc();
  vector<int> P(N*N);
  for(int i=0; i<N*N; i++){
    //printOcc();
    //printDp();
    //cout << endl;
    cin >> P[i]; P[i]--;
    int r = P[i]%N+1, c = P[i]/N+1;
    res += dp[r][c];
    occ[r][c] = false;
    calc(r*(N+1)+c);
  }
  cout << res << endl;

  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 1e5 + 5;

int n,m,ans,deg[N],pos[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1 ; i <= n ; i++) {
    deg[i] = 1;
    if (i == 1)
      pos[i] = 1;
  }
  for (int i = 1 ; i <= m ; i++) {
    int x,y;
    cin >> x >> y;
    if (pos[x])
      pos[y] = 1;
    deg[x]--;
    deg[y]++;
    if (deg[x] == 0)
      pos[x] = 0;
  }
  for (int i = 1 ; i <= n ; i++)
    if (pos[i])
      ans++;
  cout << ans << endl;
}

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

const int MOD = 1000000007;

ll modpow(ll a,ll n){
  a%=MOD;
  ll res=1;
  while(n){
    if(n&1) res=res*a%MOD;
    a=a*a%MOD;
    n>>=1;
  }
  return res;
}
ll modinv(ll a) {
    return modpow(a,MOD-2);
}

ll Per(ll n,ll k){
  if(k==1) return n;
  else return (n*Per(n-1,k-1))%MOD;
}

ll Com(ll n,ll k){
  return (Per(n,k)*modinv(Per(k,k)))%MOD;
}

int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  ll ans=modpow(2,n)-Com(n,a)-Com(n,b)-1;
  while(ans<0) ans+=MOD;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3328
"use strict";

const isCycle = function(s){
    let l = 0
    let r = s.length-1
    while(l<=r){
        if(s[l] !== s[r]) return false
        l++
        r--
    }
    return true
}

const main = arg => {
    const input = arg.trim().split("\n");

    const S = input[0];
    const N = S.length
    let first = isCycle(S)
    let sec = isCycle(S.slice(0, (N-1)/2))
    let third = isCycle(S.slice((N+3)/2-1))
    if(first && sec && third) console.log("Yes")
    else console.log("No")
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  


Measured memory_bytes: 7372
#include <iostream>
#include <numeric>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main()
{
	string s;
	cin >> s;

	vector<int> c(s.size() + 1, false);
	int h = 0;
	c[0] = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		switch (s[i])
		{
		case '_': break;
		case '\\': h -= 1; break;
		case '/': h += 1; break;
		}
		c[i + 1] = h;
	}

	int sum = 0;
	vector<int> area;
	stack<bool> d;
	for (int i = 0; i < s.size(); ++i)
	{
		switch (s[i])
		{
		case '_':
			sum += (1 * d.size());
			break;

		case '\\':
			for (int j = i + 1; j <= s.size(); ++j)
				if (c[i] <= c[j]) { d.push(true); break; }
			break;

		case '/':
			if (!d.empty())
				sum += 2 * d.size() - 1, d.pop();
			break;
		}

		if (d.empty() && sum != 0)
			area.push_back(sum), sum = 0;
	}

	cout << accumulate(area.begin(), area.end(), 0) << endl;
	cout << area.size();
	for (auto a : area)
		cout << " " << a;
	cout << endl;

	return 0;
}

Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#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 REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int MAX_N = 400;

int h,w;
vector<string> s;

ll bl=0, wh=0;
bool visited[MAX_N][MAX_N];

void dfs(int x, int y){
	visited[x][y]=true;
	if(s[x][y]=='#') bl++;
	else wh++;

	rep(i,4){
		int nx=x+dx[i], ny=y+dy[i];
		if(nx<0||nx>=h||ny<0||ny>=w) continue;
		if(s[x][y]==s[nx][ny]) continue;
		if(visited[nx][ny]) continue;
		dfs(nx,ny);
	}
}


signed main(){
	cin>>h>>w;
	s.resize(h); rep(i,h) cin>>s[i];
	ll ans=0LL;
	rep(x,h){
		rep(y,w){
			if(s[x][y]=='.') continue;
			if(visited[x][y]) continue;
			bl=wh=0LL;
			dfs(x,y);
			ans+=bl*wh;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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


int main()
{
    int n;
    cin>>n;
    map<int,int> mp;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        mp[x]++;
    }
    int cnt=0;
    for(auto it=mp.begin();it!=mp.end();it++){
        int val=it->first;
        int c=it->second;
        if(val<=c){
            cnt+=c-val;
            continue;
        }
        else{
            cnt+=c;
        }
    }
    cout<<cnt;



}


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

using ll = long long;

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  vector<ll> x(26);
  for(int i = 0; i < n; i++) x.at(s.at(i) - 'a')++;
  
  ll ans = 1;
  for(int i = 0; i < 26; i++){
    ans *= x.at(i) + 1;
    ans = ans % ((ll) 1e9 + 7);
  }
  
  cout << ans - 1 << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

typedef long long ll;

int main(){
    int N;
    cin >> N;
    int s[N];
    FOR(i,0,N) cin >> s[i];
    bool dp[N+1][10001];
    FOR(i,0,N+1)FOR(j,0,10001)dp[i][j] = false;
    dp[0][0] = true;
    FOR(i,0,N){
        FOR(j,0,10001){
            if(!dp[i][j]) continue;
            //if((j+s[i]) % 10 == 0) dp[i+1][0] = true;
            dp[i+1][j+s[i]] = true;
            dp[i+1][j] = true;
        }
    }
    int ans = 0;
    FOR(i,0,10001){
        if(dp[N][i]){
            if(i%10!=0) ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}


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

signed main() {
  int N;
  cin >> N;
  
  vector<int> slime(N);
  for( int i = 0; i < N; i++ ) cin >> slime.at(i);
  
  int ans = 0;
  int count = 1;
  for( int i = 1; i < N; i++ ){
    if( slime.at(i-1) == slime.at(i) ){
      count++;
    }else{
      ans += count/2;
      count = 1;
    }
  }
  ans += count/2;
  cout << ans << endl;
      
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define endl "\n"
const long long mod=1e9+7;const double pi=acos(-1);const long long inf=1e18;
int main(){	ios_base::sync_with_stdio(0); cin.tie(); cout.tie();	ll n,k,h[100100],dp[100100];	cin>>n>>k;	for(int i=1;i<=n;i++){		cin>>h[i];	}	dp[0]=dp[1]=0;	for(int i=2;i<=n;i++){		dp[i]=inf;	}	for(int i=2;i<=n;i++){		for(int j=i-1;j>=max(1ll,i-k);j--){			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));		}}cout<<dp[n]<<endl;}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

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

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

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////




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

	vector<ll> p(N + 1);

	repn(i, N) {
		ll a;
		cin >> a;
		p[a] = i;
	}

	set<ll> st,ts;
	st.insert(N + 1);
	st.insert(0);

	ts.insert(-N - 1);
	ts.insert(0);

	ll ans = 0;
	repn(i, N) {
		auto itr = st.upper_bound(p[i]);
		ll x = *itr;

		itr = ts.upper_bound(-p[i]);
		ll y = -*itr;

		//cout << p[i] << x << y << endl;

		ans += (x - p[i]) * (p[i]-y)*i;
		st.insert(p[i]);
		ts.insert(-p[i]);
	}
	cout << ans;

	system("PAUSE");
}


Measured memory_bytes: 20736
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int INF = Integer.MAX_VALUE;

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int H = scn.nextInt(), W = scn.nextInt();
		int d[][] = new int[H*W][H*W];
		boolean[] wall = new boolean[H*W];
		scn.nextLine();
		for(int i = 0;i < H;i++) {
			char[] ch = scn.nextLine().toCharArray();
			for(int j = 0;j < W;j++) {
				wall[W*i+j] = (ch[j]=='#')?true:false;
			}
		}

		for(int i = 0;i < H*W;i++) {
			Arrays.fill(d[i], INF);
		}
		for(int i = 0;i < H*W;i++) {
			if(wall[i])continue;
			d[i][i] = 0;
			if(i%W!=0) {
				if(!wall[i-1])d[i][i-1] = 1;
			}
			if(i%W!=W-1) {
				if(!wall[i+1])d[i][i+1] = 1;
			}
			if(i/W!=0) {
				if(!wall[i-W])d[i][i-W] = 1;
			}
			if(i/W!=H-1) {
				if(!wall[i+W])d[i][i+W] = 1;
			}
		}
		warshall_floyd(d);
		int max = 0;
		for(int i = 0;i < H*W;i++) {
			for(int j=0;j<H*W;j++) {
				if(d[i][j]!=INF) {
					max = Math.max(max, d[i][j]);
				}
			}
		}
		System.out.println(max);
	}


	public static void warshall_floyd(int[][] d) {// @param d[][]:最初の経路のコスト情報
		int V = d.length;
		for (int i = 0; i < V; i++) {
			d[i][i] = 0;
		}
		for (int k = 0; k < V; k++) {
			for (int i = 0; i < V; i++) {
				for (int j = 0; j < V; j++) {
					if (d[i][k] != INF && d[k][j] != INF)
						d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
	}

}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=1e18;
ll mod=1e9+7;
#define pb push_back
#define se second
#define fi first
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
vector<int> graph[205];
int color[205];
int nCk[100][100];
bool bipartite_jugding(int v, int c){
    color[v] = c;
    for(int i = 0; i < graph[v].size(); ++i){
        if(color[graph[v][i]] == c) return false;
        if(color[graph[v][i]] == 0 && !bipartite_jugding(graph[v][i], -c)){
            return false;
        }
    }
    return true;
}

 void combi() {
	for (int i = 0; i <= 99; ++i) nCk[i][0] = 1;
	for (int i = 1; i <= 99; ++i) for (int j = 1; j <= i; ++j) {
		nCk[i][j] = (nCk[i-1][j] + nCk[i-1][j-1]) % mod;
	}
}

long long expo(ll x,ll n,ll M)
{

    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*expo((x*x)%M,(n-1)/2,M))%M;

}
ll h;
void solve()
{
    cin>>h;
    ll ans=0;ll i=1;
    while(h)
    {
        h=h/2;
        ans+=i;
        i=i*2;
    }
    cout<<ans<<endl;

}

int main()
{
    boost;
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000


int main(){
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  vint water(f+1);
  vint sugar(f+1);
  erep(i,f){
    erep(j,f){
      int x = i*a + j*b;
      if(x<=f){
        water[x] = x;
      }
    }
  }

  erep(i,f){
    erep(j,f){
      int y = i*c + j*d;
      if(y<=f){
        sugar[y] = y;
      }
    }
  }

  double con = 0;
  int wa = 0;
  int su = 0;
  erep(i,f){
    erep(j,f){
      if(sugar[j] <= e*water[i] && water[i]*100 + sugar[j] <= f && (double)sugar[j]/((double)sugar[j] + (double)water[i]*100) >= con){
        con = (double)sugar[j]/((double)sugar[j] + (double)water[i]*100);
        wa = water[i]*100;
        su = sugar[j];
      }
    }
  }
  cout << wa + su << " " << su << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

int n,a,b,c,i;

long d=0;

b=-1000000;

c=1000000;

scanf("%d",&n);

for(a=0;a<n;a++){

scanf("%d",&i);

if(b<i){

b=i;

}

if(c>i){

c=i;

}

d+=i;

}

printf("%d %d %ld\n",c,b,d);

return 0;

}

Measured memory_bytes: 600
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

ll gcd(ll a, ll b) {
  if (a < b) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}

void solve() {
  ll N, K; cin >> N >> K;
  if (N <= K) outl(min(N, K - N));
  else if (N % K == 0) outl(0);
  else {
    N %= K;
    outl(min(N, abs(N - K)));
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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



int main(){

    int n;
    cin>>n;
    double dp[n+1];
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int coin=0;coin<n;coin++){
        double p_head;
        cin>>p_head;
        for(int i=coin+1;i>=0;i--){
            dp[i]=(i==0 ? 0 : dp[i-1]*p_head) + dp[i]*(1-p_head);
        }
    }
    double ans=0;
    for(int head=0;head<=n;head++){
        if(head>n-head){
            ans+=dp[head];
        }
    }
    cout<<fixed<<setprecision(10)<<ans;



return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define mem0(x) memset(x, 0, sizeof(x))
#define mem1(x) memset(x, -1, sizeof(x))
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define de(x) cout << #x << " = " << x << ", "
#define dl(x) cout << #x << " = " << x << endl
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i > b; i--)
#define setI freopen("input.txt", "r", stdin);
#define setIO freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout);
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
//---------------------------------------------------------//
const int N = 2e5 + 5;

struct Edge
{
	int to, next, id;
} e[N];
int head[N], tot;
LL n, s[N], sz[N], dep[N], ans[N], sum, cnt;

void insert(int u, int v, int id)
{
	e[tot] = Edge{v, head[u], id}; head[u] = tot++;
	e[tot] = Edge{u, head[v], id}; head[v] = tot++;
}

void dfssz(int u, int pre, int d)
{
	sz[u] = 1; dep[u] = d;
	for (int i = head[u]; ~i; i = e[i].next)
	{
		int v = e[i].to;
		if (v == pre)  continue;
		dfssz(v, u, d + 1);
		sz[u] += sz[v];
	}
}

void dfs1(int u, int pre)
{
	for (int i = head[u]; ~i; i = e[i].next)
	{
		int v = e[i].to;
		if (v == pre)  continue;
		dfs1(v, u);
		LL Tx = sz[v], Ty = n - Tx;
		if (Tx != Ty)  ans[e[i].id] = (s[u] - s[v]) / (Tx - Ty);
	}
}

void dfs2(int u, int pre, LL cur)
{
	for (int i = head[u]; ~i; i = e[i].next)
	{
		int v = e[i].to;
		if (v == pre)  continue;
		if (~ans[e[i].id])
		{
			sum += cur + ans[e[i].id];
			if (cnt > 0)  cnt++;
			dfs2(v, u, cur + ans[e[i].id]);
		}
		else
		{
			sum += cur;
			cnt++;
			dfs2(v, u, cur);
		}
	}
}

void init()
{
	sum = cnt = 0;
	mem1(head);
	mem1(ans);
}

int main()
{
	#ifdef LOCAL
//		setI;
	#endif
//	ios::sync_with_stdio(false);
	init();
	scanf("%d", &n);
	rep(i, 1, n)
	{
		int u, v; scanf("%d%d", &u, &v);
		insert(u, v, i);
	}
	rep(i, 1, n + 1)  scanf("%lld", &s[i]);
	dfssz(1, -1, 0);
	dfs1(1, -1);
//	rep(i, 1, n)  printf("%lld%c", ans[i], " \n"[i==n-1]);
	dfs2(1, -1, 0);
//	dl(cnt); dl(sum);
	int V = -1;
	rep(i, 0, 2 * n)
		if (!~ans[e[i].id])
		{
			if (V == -1 || dep[e[i].to] > dep[V])
			{
				V = e[i].to;
			}
		}
	if (~V)  cnt = sz[V];
	rep(i, 1, n)  if (!~ans[i])  ans[i] = (s[1] - sum) / cnt;
	rep(i, 1, n)  printf("%lld\n", ans[i]);
	
	return 0;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h = {0};
    for (auto i = 1, t=0; i != n + 1; ++i)
    {
        cin >> t;
        h.push_back(t);
    }
    vector<int> cost = {0, 0};

    for (auto i = 2; i != n + 1; ++i)
    {
        vector<int> temp;
        for (auto j = min(k, i-1); j > 0; --j)
            temp.push_back(cost[i - j] + abs(h[i - j] - h[i]));
        cost.push_back(*min_element(temp.begin(), temp.end()));
    }
    cout << *(cost.rbegin());
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <set>

using namespace std;


int main(void){
  int N;
  long int a;
  bool b = false;
  cin >> N;
  set<long int> s;
  for(int i = 0; i < N;++i){
    cin >> a;
    auto it = s.find(a);
    if(it == s.end()){
      s.insert(a);
    }
    else{
      b = true;
    }
  }
  if(b) cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>

using namespace std;

void dice3(){
        int d1,d2,d3,d4,d5,d6;
        cin >> d1 >> d2 >> d3 >> d4 >> d5 >> d6; 

        int e1,e2,e3,e4,e5,e6;
        cin >> e1 >> e2 >> e3 >> e4 >> e5 >> e6; 

        int tmp;
        for ( int i = 0; i < 4; i++){
                tmp = d1; d1 = d2; d2 = d6; d6 = d5; d5 = tmp;  //N 

                for ( int i = 0; i< 4; i++){
                        if(d1 == e1 and d2 == e2 and d3 == e3 and d4 == e4 and d5 == e5 and d6 == e6){
                                cout << "Yes" <<endl;
                                return ;
                        }   
                        tmp = d2; d2 = d3; d3 = d5; d5 = d4; d4 = tmp; //spin
                }   
        }    
        tmp = d1; d1 = d4; d4 = d6; d6 = d3; d3 = tmp; //E 
        for ( int i = 0; i< 4; i++){
                if(d1 == e1 and d2 == e2 and d3 == e3 and d4 == e4 and d5 == e5 and d6 == e6){
                        cout << "Yes" <<endl;
                        return ;
                }   
                tmp = d2; d2 = d3; d3 = d5; d5 = d4; d4 = tmp; //spin
        }   
        tmp = d1; d1 = d4; d4 = d6; d6 = d3; d3 = tmp; //E 
        tmp = d1; d1 = d4; d4 = d6; d6 = d3; d3 = tmp; //E 
        for ( int i = 0; i< 4; i++){
                if(d1 == e1 and d2 == e2 and d3 == e3 and d4 == e4 and d5 == e5 and d6 == e6){
                        cout << "Yes" <<endl;
                        return ;
                }   
                tmp = d2; d2 = d3; d3 = d5; d5 = d4; d4 = tmp; //spin
        }   
        cout << "No" << endl;
}

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

Measured memory_bytes: 3096
#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<memory.h>
using namespace std;
int main(){
	int in;
	int a[3] = { 0 };
	int b=0, c=0;
	int l;
	bool flag = true;
	while (flag){
		l = 0;
		memset(a, 0, sizeof(a));
		while ((in = getchar()) != '\n'){
			if (in == EOF){ cout << b << endl << c << endl; return 0; }
			if (in == ',')l++;
			if (in != ','&&in>='0'&&in<='9'){
				a[l] = a[l] * 10 + (in - '0');		
			}
		}
		if (a[0] == a[1])
			c++;
		if (a[2] * a[2] == a[0] * a[0] + a[1] * a[1])
			b++;
	}
}

Measured memory_bytes: 1120
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, P, *ABC = map(int, read().split())

    G = [[] for _ in range(N)]
    G_rev = [[] for _ in range(N)]
    edge = []
    for a, b, c in zip(*[iter(ABC)] * 3):
        a -= 1
        b -= 1
        c = P - c
        G[a].append(b)
        G_rev[b].append(a)
        edge.append((a, b, c))

    reachable_1 = [False] * N
    reachable_N = [False] * N

    reachable_1[0] = True
    reachable_N[N - 1] = True

    queue = deque([0])
    while queue:
        v = queue.popleft()
        for nv in G[v]:
            if not reachable_1[nv]:
                reachable_1[nv] = True
                queue.append(nv)

    queue = deque([N - 1])
    while queue:
        v = queue.popleft()
        for nv in G_rev[v]:
            if not reachable_N[nv]:
                reachable_N[nv] = True
                queue.append(nv)

    ok = [reachable_1[i] and reachable_N[i] for i in range(N)]

    dist = [INF] * N
    dist[0] = 0

    for i in range(N):
        for a, b, c in edge:
            if not ok[a] or not ok[b]:
                continue
            if dist[b] > dist[a] + c:
                if i < N - 1:
                    dist[b] = dist[a] + c
                else:
                    print(-1)
                    return

    score = -dist[N - 1]
    print(max(score, 0))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 70876
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int H, W;
  cin >> H >> W;

  // even even -> all degeneracies must be prop to 4
  // even, odd -> even*(odd-1)/4 4-pairs and even/2 two pairs
  // odd1, odd2 -> (odd1-1)*(odd2-1)/4 4 pairs and (odd1-1 + odd2-1)/2 two pairs and isolated

  map<char, int> count;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      char v; cin >> v;
      count[v]++;
    }
  }

  int four = 0, three = 0, two = 0, one = 0;
  for(auto x: count){
    four += x.second / 4;
    int r = x.second % 4;

    if(r == 3){
      two++;
      one++;
    }
    else if(r == 2) two++;
    else if(r == 1) one++;
  }


  string ans = "No";
  if(H % 2 == 0 && W % 2 == 0){
    if(four == H*W/4) ans = "Yes";
  } else if(H % 2 == 0 && W % 2 == 1){
    if(one == 0 && H*(W-1)/4 <= four) ans = "Yes";
  } else if(H % 2 == 1 && W % 2 == 0){
    if(one == 0 && (H-1)*W/4 <= four) ans = "Yes";
  } else {
    if((H-1)*(W-1)/4 <= four && one == 1) ans = "Yes";
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;


lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli L, R;
	cin >> L >> R;

	lli ans = 1000000000000;

	for (lli i = L; i <= min(L + 2020, R); i++) {
		for (lli j = i + 1; j <= min(L + 2020, R); j++) {
			CHMIN(ans, (i * j) % 2019);
		}
	}

	COUT(ans);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int ddx[6]={0,1,0,-1,1,-1},ddy[6]={-1,0,1,0,1,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


int n;
int f[55];
int day[55][33];
int alr[55][55];
vector<int> ans;

int main(){
	while(1){
		cin>>n;
		if(n==0)break;
		REP(i,n){
			cin>>f[i];
			REP(j,f[i]){
				cin>>day[i][j];
			}
		}
		REP(i,55){
			REP(j,55){
				alr[i][j]=0;
			}
		}
		REP(i,55)alr[i][i]=1;
		for(int i=1;i<=30;i++){
			vector<int> met;
			met.clear();
			REP(j,n){
				REP(k,f[j]){
					if(day[j][k]==i){
						met.push_back(j);
						break;
					}
				}
			}
			REP(j,met.size()){
				REP(k,met.size()){
					alr[met[j]][met[k]]=1;
					REP(l,n){
						if(alr[met[j]][l]==1){
							alr[met[k]][l]=1;
						}
					}
				}
			}
			REP(k,n){
				int flag=1;
				REP(j,n){
					if(alr[k][j]==0){
						flag=0;
						break;
					}
				}
				if(flag){
					cout<<i<<endl;
					goto A;
				}
				
			}
			if(i==30)cout<<-1<<endl;
		}
		A:;
	}
	return 0;
}


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

int main(){
  
  string S;
  cin >> S;
  int ans=0;
  
  for(int i=0; i<S.size(); i++) {   
    if(i%2 == 0) {
      if(S.at(i) == 'R' || S.at(i) == 'U' || S.at(i) == 'D');
      else ans = 1;
    }    
    else {
      if(S.at(i) == 'L' || S.at(i) == 'U' || S.at(i) == 'D');
      else ans = 1;
    }    
  }
  
  if(ans == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

	static int count;
	public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] A = new int[N];

        for(int i = 0; i < N; i++){
            A[i] = scan.nextInt();
        }

        //shellSort
        count = 0;
		int m = 0;
		int G[] = new int[N];
		//G = A.clone();

		for(int i = 1; i <= N; i = i*3 + 1){ //シェルはこれでいいらしいイミフ
            G[m] = i;
            m++;
        }

		//出力
		System.out.println(m);

        for(int i= m-1; i >= 0; i--){
            System.out.print(G[i]);
            if(i > 0){
                System.out.print(" ");
            } else {
                System.out.println();
                }
            }

		//for(int i = m-1; i >= 0; i--){
          //  System.out.print((i == m-1 ? "" : " ") + G[i] + (i == 0 ? "\n" : ""));
        //}

        //sort
        for(int i = m-1; i >= 0; i--) {
			insertionSort(A, N, G[i]);
		}

        System.out.println(count);

        //結果出力
        for(int i = 0; i < A.length; i++) {
        	System.out.println(A[i]);
        }
	}

	public static void insertionSort(int[] A, int n, int g){
		for(int i = g; i < n; i++) {
			int v = A[i];
			int j = i - g;

			while(j >= 0 && A[j] > v) {
				A[j+g] = A[j];
				j = j - g;
				count++;
			}
				A[j+g] = v;

			}
		}
	}


Measured memory_bytes: 299296
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int s[26] = {};
	string a;
	cin >> a;
	REP(i, a.size()) {
		s[a[i] - 'a']++;
	}
	REP(i, 26) {
		if (s[i] % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

int main(){
     int i, j, k;
     int n;
     cin >> n;
     ll ans=0;
     for(i=1; i<=n; ++i){
          ll t=n-i+1;
          ans+=t*(t+1)/2;
     }
     for(i=0; i<n-1; ++i){
          int u, v;
          cin >> u >> v;
          if(u>v) swap(u, v);
          ans-=u*ll(n-v+1);
     }
     cout << ans << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int x[4] = {-1 , 0 , 1 , 0};
int y[4] = {0 , -1 , 0 , 1};
int main(void){

    int N;
    while(cin >> N , N){

      //pair[i] = {x , y}
      P p[N];
      p[0] = {0 , 0};
      int max_x = 0, min_x = 0, max_y = 0, min_y = 0;
      for(int i = 1 ; i < N ; i++){
    	int num, dire;
    	cin >> num >> dire;
    	p[i].first = p[num].first + x[dire];
    	p[i].second = p[num].second + y[dire];

	    max_x = max(max_x , p[i].first);
    	min_x = min(min_x , p[i].first);
    	max_y = max(max_y , p[i].second);
    	min_y = min(min_y , p[i].second);
      }

      cout << max_x - min_x + 1 << " " << max_y - min_y + 1 << endl;

    }

    return 0;
}



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

int main()
{
	int N; cin >> N;
	vector<long long>A(N+1);
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] >= 3) {
			ans += (A[i]-1) / 2;
			if (A[i] % 2)A[i] = 1;
			else A[i] = 2;
		}
	}

	for (int i = 0; i < N; i++) {
		if (A[i] == 1 && A[i + 1] > 0) {
			A[i] = 0;
			A[i + 1]--;
			ans++;
		}
		else if (A[i] == 2) {
			ans++;
			A[i] = 0;
		}
	}
	
	cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
double PI = acos(-1);  // PI = 3.141593...

int main() {
    double a, b, c;
    double rad;

    cin >> a >> b >> c;
    //cout << a << b << c;
    double s;
    rad = c * PI / 180;
    s = a * b * 0.5 * sin(rad);

    double l;
    l = a + b + sqrt(a*a + b*b - 2 * a * b * cos(rad));

    double h;
    h = b * sin(rad);
    printf("%.8f\n", s);
    printf("%.8f\n", l);
    printf("%.8f\n", h);
}


Measured memory_bytes: 3620
import java.util.*;

public class Main {            
  
  static int H;
  static int W;
  static int dx[] = new int[]{-1,-1,-1,0,1,1,1,0};    
  static int dy[] = new int[]{-1,0,1,1,1,0,-1,-1};    
  
  public static void main(String[] args) {                                
    
    Scanner sc = new Scanner(System.in);      
    
    H = sc.nextInt();
    W = sc.nextInt();
        
    char start[][] = new char[H][W];
   
    for(int i = 0;i < H;i++){
        String S = sc.next();
        for(int j = 0;j < W;j++){
                start[i][j] = S.charAt(j);
        }
    }
    
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            if(start[i][j] == '.'){
               start[i][j] = check(start,i,j); 
            }            
        }
    }
    
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            System.out.print(start[i][j]);
        }
        System.out.println();
    }
  }    
  
  public static char check(char a[][],int i,int j){
      int count = 0;
      for(int k = 0;k < 8;k++){
          if(i + dy[k] < 0 || i + dy[k] >= H || j + dx[k] <0 || j + dx[k] >=W){
              continue;
          }          
         char ny = a[i + dy[k]][j + dx[k]];
         if(ny == '#'){
             count++;
         }
      }      
      return String.valueOf(count).charAt(0);
  }
  
}
        


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  ll N,K;
  cin >> N >> K;
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll left = 0;
  ll right = Mod * 3;
  while (right - left > 1) {
    ll mid = (left + right) / 2;
    ll cnt = 0;
    for (int i = 0; i < N; i++) {
      cnt += A[i] / mid;
      if (A[i] % mid == 0) {
        cnt--;
      }
    }
    if (cnt <= K) {
      right = mid;
    } else {
      left = mid;
    }
  }
  cout << right << endl;
  return 0;
}

Measured memory_bytes: 5148
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        boolean judge = a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0;
        String result = judge ? "Possible" : "Impossible";

        // 出力
        System.out.println(result);
    }
}


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

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}



//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

int main() {
	int N, K;
	cin >> N >> K;
	
	int ans = (N - 1) / (K - 1);
	if ((N - 1) % (K - 1) != 0) {
		ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
S = [Counter(input()) for _ in range(N)]
comS = {}
for key in S[0].keys():
  if all([True for s in S if key in s]):
    comS[key] = min([s[key] for s in S])
print(''.join([key*comS[key] for key in sorted(comS.keys())]))

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

typedef long long ll;
typedef unsigned long long ull;

int op(int a, int b){ return max(a, b);}
int e(){return numeric_limits<int>::min();}
int target;
bool f(int v){ return v < target;}

int main()
{
    int N, Q;
    cin >> N >> Q;
    segtree<int, op, e> seg(N);
    int Ai;
    for(int i=0;i<N;i++){
        cin >> Ai;
        seg.set(i, Ai);
    }
    int Ti, X, Y;
    vector<int> res;
    for(int i=0;i<Q;i++){
        cin >> Ti >> X >> Y;
        if(Ti == 1){
            seg.set(X-1, Y);
        }else if(Ti == 2){
            auto ret = seg.prod(X-1, Y);
            res.push_back(ret);
        }else if(Ti == 3){
            target = Y;
            res.push_back(seg.max_right<f>(X-1) + 1);
        }else{ abort();}
    }
    for(auto v : res) cout << v << endl;

    return 0;
}

Measured memory_bytes: 6804
// ARC094
// E - Tozan and Gezan

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int INF = 1e9 + 1;

int main() {
    int N, c;
    ll s;

    cin >> N;

    s = 0;
    c = INF;
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;

        s += a;
        if (a > b && c > b) {
            c = b;
        }
    }

    if (c == INF) {
        cout << 0 << endl;
        return 0;
    }
    cout << s - c << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <random>
#include <string.h>//文字列の代入に使う                                                                                
#include <bits/stdc++.h>//piの利用で必要(M_PI)                                                                         
#include <algorithm>


int main() {

  int X, happy_count;
  //あまりを代入                                                                                                       
  int amari500;
  //商を代入                                                                                                           
  int syo500;
  int syo5;

  std::cin >> X;
  //std::vector<int> A(N);                                                                                             

  syo500 = X / 500;
  amari500 = X % 500;
  syo5 = amari500 / 5;

  std::cout << syo500 * 1000 + syo5 * 5 << std::endl;

  return 0;
}


Measured memory_bytes: 256