akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter
import java.util.*
import java.math.*

val pw = PrintWriter(System.out)

fun main(args: Array<String>) {
    val n = readInt()
    val (d, x) = readListOfInt()
    val a = mutableListOf<Int>()
    for(i in 0 until n) {
        a.add(readInt())
    }

    var num = x 
    for(i in n-1 downTo 0) {
        val ca = a[i]
        num += 1 + (d - 1) / ca
    }
    println(num)
    pw.flush()
}

fun inputList() = 
    readLine()!!.split(" ").map(String::toInt)

fun sum_digits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

/****** Decrared Functions ******/

// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }


fun println(value : Any) {
    pw.println(value)
}

fun gcd(a: Long, b: Long): Long = 
    if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
    if(b==0L) a else gcd(b, a % b)


Measured memory_bytes: 37828
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
 
using namespace std;

typedef long long LL;

const int N = 3e5 + 10;

char q[N * 2], s[N];
int hh = N, tt = N - 1;
bool dir = true;

int main()
{
    int T;
    scanf("%s%d", s, &T);
    int n = strlen(s);
    for(int i = 0; i < n; i ++)  q[++ tt] = s[i];
    
    while(T --)
    {
        int t;
        scanf("%d", &t);
        if(t == 1)  dir = !dir;
        else{
            int f;
            scanf("%d%s", &f, s);
            
            if(!dir)  f = 3 - f;
            
            if(f == 1)  q[-- hh] = s[0];
            else  q[++ tt] = s[0];
        }
    }
    if(!dir)  reverse(q + hh, q + tt + 1);
    q[tt + 1] = 0;
    
    puts(q + hh);
    
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    rep(i,3)
    {
        if(s[i] == 'o') ans++;
    }
    cout << ans*100 + 700 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vii vector<int,int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define all(a) a.begin(),a.end()
const int mod=1e9+7;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main(){
    fast;
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int dp[n]={0};
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
        dp[i]=min((abs(a[i]-a[i-1])+dp[i-1]),(abs(a[i]-a[i-2])+dp[i-2]));
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>
#include <set>
using namespace std;
#define MAX 20000000

int H,A[MAX+1];

void maxheapify(int i){
  int l, r ,largest;
  l=2*i;
  r=2*i+1;

  if(l<=H && A[l]>A[i])largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest])largest=r;

  if(largest !=i){
    swap(A[i],A[largest]);
    maxheapify(largest);
  }
}

int main(){
  cin>>H;
  for(int i=1;i<=H;i++){
    cin>> A[i];
  }
  for(int i=H/2;i>=1;i--) maxheapify(i);
  for(int i=1;i<=H;i++){
    cout << " " << A[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 5068
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x,y=0,sum,count=0;
    cin >> x >> sum;
    for(int i=0;i<=x;i++){
        y=2*i+4*(x-i);
        if(y==sum){
            cout << "Yes" << endl;
            count++;
        }
    }
    if(count==0){
        cout << "No" << endl;
    }
    return 0;
}

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

mod = 10**9+7
ans = 1

if n % 2 == 0:
    for i in range(n):
        if i % 2 == 0:
            if a[i] != i + 1:
                ans = 0
        else:
            if a[i] != i:
                ans = 0
else:
    for i in range(n):
        if i % 2 == 0:
            if a[i] != i:
                ans = 0
        else:
            if a[i] != i + 1:
                ans = 0

for i in range(n//2):
    ans *= 2
    ans %= mod

print(ans)


Measured memory_bytes: 14008
N = int(input())
A = [int(zz) for zz in input().split()]

if sum(A) == 0:
    print('Yes')
    exit()

B = set(A)
if N%3 == 0:
    C = list(B)
    ans = 0
    for i in range(N):
        ans = ans^A[i]

    if ans == 0:
        print('Yes')
        exit()

print('No')


Measured memory_bytes: 60784
N, L = map(int,input().split())
list = [L + i for i in range(N)]
sum = 0
if L > 0 :
    for i in range(1,N):
        sum += list[i]
elif L < 0 and L + N - 1 < 0 :
    for i in range(N-1):
        sum += list[i]
else:
    for i in range(N):
        sum += list[i]
print(sum)

Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

var ans int

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	m, _ := strconv.Atoi(stringLineScan())
	ab := make([][]int, m)
	for i := 0; i < m; i++ {
		t := make([]int, 2)
		t[0], _ = strconv.Atoi(stringLineScan())
		t[1], _ = strconv.Atoi(stringLineScan())
		ab[i] = t
	}
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		t := make([]int, n)
		g[i] = t
	}
	for _, i := range ab {
		a, b := i[0]-1, i[1]-1
		g[a][b] = 1
		g[b][a] = 1
	}
	for _, i := range ab {
		a, b := i[0]-1, i[1]-1
		h := make([][]int, n)
		for j := 0; j < n; j++ {
			t := make([]int, n)
			for k := 0; k < n; k++ {
				t[k] = g[j][k]
			}
			h[j] = t
		}
		h[a][b], h[b][a] = 0, 0
		searched := make([]bool, n)
		searched = graphSplitJudge(h, 0, searched)
		ans += all(searched)
	}
	fmt.Println(ans)
}
func graphSplitJudge(g [][]int, pos int, searched []bool) []bool {
	c := g[pos]
	n := len(c)
	for i := 0; i < n; i++ {
		if c[i] == 1 && searched[i] == false {
			searched[i] = true
			searched = graphSplitJudge(g, i, searched)
		}
	}
	return searched
}
func all(a []bool) int {
	for _, i := range a {
		if !i {
			return 1
		}
	}
	return 0
}


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

using namespace std;

const int max_n = 100011, inf = 1000111222;

int n, a[max_n], b[max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 0; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &b[i]);
        int x = min(a[i], b[i]);
        a[i] -= x;
        b[i] -= x;
        ans += x;
        x = min(a[i + 1], b[i]);
        a[i + 1] -= x;
        b[i] -= x;
        ans += x;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

bool a[10];
int main() {
	ll n,k;
	cin>>n>>k;
	for(int i=0;i<k;i++){
		ll x;
		cin>>x;
		a[x]=true;
	}
	for(ll i=n;;i++){
		ll now=i;bool CH=false;
		while(now!=0){
			ll ch=now%10;
			if(a[ch]==true){
				CH=true;
				break;
			}
			now/=10;
		}
		if (CH==false){
			cout << i;
			return 0;
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
    char S[10];

    scanf("%s", S);

    if(strcmp(S, "Sunny") == 0){
	printf("Cloudy");
    }

    else if(strcmp(S, "Cloudy") == 0){
	printf("Rainy");
    }

    else{
	printf("Sunny");
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define sz 2333
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(register int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n,K,Q;
int a[sz];
pii aa[sz];int rnk[sz];

int bel[sz],cnt[sz],T;
int L[sz],R[sz];

int main()
{
	file();
	read(n,K,Q);
	rep(i,1,n) read(a[i]),aa[i]=MP(a[i],i);
	sort(aa+1,aa+n+1);
	rep(i,1,n) rnk[aa[i].sec]=i;
	int ans=1e9;
	rep(i,1,n)
	{
		L[T=1]=0;
		rep(j,1,n) if (a[j]<a[i]) R[T]=j,L[++T]=j;
		R[T]=n+1;
		rep(i,1,T) rep(j,L[i]+1,R[i]-1) bel[j]=i;
		rep(i,1,T) cnt[i]=0;
		int cur=0;
		rep(j,rnk[i],n)
		{
			int p=aa[j].sec;++cnt[bel[p]];
			if (cnt[bel[p]]+K-1<=R[bel[p]]-L[bel[p]]-1) ++cur;
			if (cur>=Q) chkmin(ans,aa[j].fir-a[i]);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;

	if (0<=x-r && x+r<= W && 0<=y-r && y+r<= H)cout<<"Yes"<<endl;
	else cout << "No" <<endl;
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int main() {
    int i, j, n;
    char mark;
    char marks[4] = {'S', 'H', 'C', 'D'};
    int num;
    bool cards[4][13] = {false};
    
    cin >> n;
    
    for(i = 0; i < n; i++) {
        cin >> mark >> num;
        
        for(j = 0; j < 4; j++) {
            if(mark == marks[j]) {
                cards[j][num-1] = true;
                break;
            }
        }
    }
    for(i = 0; i < 4; i++) {
        for(j = 0; j < 13; j++) {
            if(!cards[i][j]) {
                cout << marks[i] << " " << j+1 << endl;
            }
        }
    }

}

Measured memory_bytes: 1160
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.trim().split("\n");
	i = input[0].split(' ').map(n => parseInt(n))[0]
	n = input[1].split(' ').map(n => parseInt(n))
	ans = n[0]
	if (n.indexOf(0) >= 0)  {
		ans = 0n
	} else {
		for (i = 1; i < n.length; i++) {
			if ((BigInt(ans) * BigInt(n[i])) > 1000000000000000000) {
				ans = -1
				break
			}
			ans = BigInt(ans) * BigInt(n[i])
		}
	}



	//出力
	console.log(ans.toString())
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require('fs').readFileSync('./input.txt', 'utf-8'));

Measured memory_bytes: 44044
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int[]X=new int[N];
        for(int i=0;i<N;i++){
            X[i]=sc.nextInt();
        }
        int[]Y=new int[N];
        for(int i=0;i<N;i++){
            Y[i]=X[i];
        }
        Arrays.sort(Y);
        int l=Y[N/2];
        for(int i=0;i<N;i++){
            if(X[i]<l){
                System.out.println(l);
            }else{
                System.out.println(Y[N/2-1]);
            }
        }

        


}
        
        
    }


Measured memory_bytes: 115272
/* ITP1_8_B */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    int sum = 0;

    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder sb = new StringBuilder();
      String str = "";

      while((str = br.readLine()).equals("0") == false){
        char[] input = str.toCharArray();
        sum = 0;

        for(int i = 0; i < input.length; i++){
          sum += Character.getNumericValue(input[i]);
        }
        sb.append(sum).append("\n");
      }
      System.out.print(sb);

    }catch(Exception e){
      System.out.println(e);
    }
  }
}

Measured memory_bytes: 24192
# -*- coding: utf-8 -*-
# input
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
# calc
avg_tmp = t - h[0] * 0.006
if a < avg_tmp:
    dif = avg_tmp - a
else:
    dif = a - avg_tmp
ans = 1
for i in range(1, n):
    avg_tmp = t - h[i] * 0.006
    if a < avg_tmp:
        sub_dif = avg_tmp - a
    else:
        sub_dif = a - avg_tmp
    if dif > sub_dif:
        dif = sub_dif
        ans = i + 1
# output
print(ans)

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

int main() {
  int n, A, B;
  string s;
  cin >> n >> A >> B >> s;

  int yosen = 0;
  int rankB = 1;

  for(int i=0;i<n;i++) {
    if(s[i] == 'a') {
      if(yosen < A + B) {
        cout << "Yes" << endl;
        yosen++;
      } else {
        cout << "No" << endl;
      }
    } else if(s[i] == 'b') {
      if(yosen < A + B && rankB <= B) {
        cout << "Yes" << endl;
        yosen++;
      } else {
        cout << "No" << endl;
      }
      rankB++;
    } else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 896
import java.util.Scanner;
public class Main{
     public static void main(String[] args) {
      try (Scanner sc = new Scanner(System.in)){
           String line = sc.nextLine();
            String answer = "";
             int length = line.length();
              for (int i = 0; i < length; i++){
                   char ch = line.charAt(i);
                   if(Character.isLowerCase(ch)){
                       ch=Character.toUpperCase(ch);
                   }else if(Character.isUpperCase(ch)){
                       ch=Character.toLowerCase(ch);
                   }
                   answer=answer+ch;
                }
                System.out.println(answer);
            }
        }
    }


Measured memory_bytes: 31632
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<Pii> ans(m);
    int s = 1;
    for(int i=m/2*2;i>=2;i-=2) {
        ans[i-1] = {s, s+i};
        ++s;
    }
    s = 2 + m/2*2;
    for(int i=(m+1)/2*2-1;i>=1;i-=2) {
        ans[i-1] = {s, s+i};
        ++s;
    }

    for(int i=0;i<m;++i) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}


Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
int read();
int n, k;
char s[10004], res[10004], c = 'z';
int l[10004], len, mx, vis;

void cpy(int p) {
    for (int i = 1; i <= n; ++i) res[i] = s[p + i - 1];
}

void check(int p) {
    if (!vis) cpy(p), vis = 1;
    for (int i = 1; i <= n; ++i) {
        if (res[i] < s[p + i - 1]) return;
        if (res[i] > s[p + i - 1]) return cpy(p);
    }
}

int main() {
    scanf("%d%d%s", &n, &k, s + 1);
    for (int i = 1; i <= n; ++i) c = min(c, s[(n << 1) + 1 - i] = s[i]);
    if (k >= 15) {
        for (int i = 1; i <= n; ++i) putchar(c);
        return 0;
    }
    if (k == 1) {
        for (int i = 1; i <= n + 1; ++i) check(i);
        for (int i = 1; i <= n; ++i) putchar(res[i]);
        return 0;
    }
    for (int i = 1; i <= n + n; ++i)
        (s[i] == c) ? mx = max(mx, l[i] = l[i - 1] + 1) : 0;

    if ((len = mx << k - 1) >= n) {
        for (int i = 1; i <= n; ++i) putchar(c);
        return 0;
    }
    for (int i = 1; i <= n + mx; ++i)
        if (l[i] == mx) check(i - l[i] + 1);
    for (int i = 1; i <= len; ++i) putchar(c);
    for (int i = len + 1; i <= n; ++i) putchar(res[i - len + mx]);
    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
   // freopen("ina.txt", "r", stdin);
   // freopen("outa.txt", "w", stdout);
    vector<int> data(3);
    data[0] = 10000; data[1] = 5000; data[2] = 1000;
    int n, y;
    while (cin >> n >> y) {
        int orig = y;
        int a = y / data[0];
        y -= a * data[0];
        int b = y / data[1];
        y -= b * data[1];
        int c = y / data[2];
        y -= c * data[2];
        bool found = false;
        if (a + b + c <= n) {
            b = orig / data[1];
            for (int x = 0; x <= a; x++) {
               for (int yy = 0; yy <= b; yy++) {
                   int z = n - x - yy;
                   if (z < 0) break;
                   if (x * data[0] + yy * data[1] + z * data[2] == orig) {
                       cout << x << " " << yy << " " << z << "\n";
                       x = a + 1;
                       found = true;
                       break;
                   }
               }
           }
        }
        if (!found) {
            cout << "-1 -1 -1\n";
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define int ll
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 1e10; //10^10
const double PI = acos(-1.0L);
const int dx[4] = {1, 0, -1, 0} , dy[4] = {0, 1, 0, -1};
/*mod逆元*/long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    int ans = 0;
    FOR(i,1,n+1){
        if(!(i&1)) continue;
        auto a = divisor(i);
        if(a.size()==8) ans++;
    }
    out(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int fa[maxn];
int gfa(int a) {
	if (fa[a] == a) return a;
	return fa[a] = gfa(fa[a]);
}
int n;
ll m;
int q;
int a[maxn], b[maxn], c[maxn];
int main() {
	cin >> n >> m >> q;
	for (int i = 0; i < n; i++) fa[i] = i;
	for (int i = 0; i < q; i++) {
		scanf("%d%d%d", &a[i], &b[i], &c[i]);
		if (c[i] == 0) fa[gfa(a[i])] = gfa(b[i]);
	}
	int fl = 0, afl = 1;
	for (int i = 0; i < q; i++) {
		if (c[i] == 0) continue;
		if (gfa(a[i]) == gfa(b[i])) afl = 0;
		fl = 1;
	}
	int tot = 0;
	for (int i = 0; i < n; i++)
		if (fa[i] == i) tot++;
	ll l = n, r = n - tot + 1ll * tot * (tot - 1) / 2;
	if (!fl) l--;
	if (m > r || m < l) afl = 0;
	if (afl) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int main(void) {
  int W, H, N;
  cin >> W >> H >> N;
  int color[W][H] = { 0 };

  int x, y, a;
  for (int n = 0; n < N; ++n) {
    cin >> x >> y >> a;

    if (a == 1) {
      for (int w = 0; w < x; ++w) {
        for (int h = 0; h < H; h++) {
          color[w][h] = 1;
        }
      }
    } else if (a == 2) {
      for (int w = x; w < W; ++w) {
        for (int h = 0; h < H; h++) {
          color[w][h] = 1;
        }
      }
    } else if (a == 3) {
      for (int w = 0; w < W; ++w) {
        for (int h = 0; h < y; h++) {
          color[w][h] = 1;
        }
      }
    } else if (a == 4) {
      for (int w = 0; w < W; ++w) {
        for (int h = y; h < H; h++) {
          color[w][h] = 1;
        }
      }
    }
  }

  int res = 0;
  for (int w = 0; w < W; ++w) {
    for (int h = 0; h < H; ++h) {
      if (color[w][h] == 0) ++res;
    }
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n;cin >> n;
    int cnt = 0;
    rep(i,n){
        int a,b;cin >> a>>b;
        if(a == b){
            cnt++;

        }
        else {
            cnt = 0;
        }
        if(cnt == 3){
            cout << "Yes" << endl;
            return 0;
        }
        
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>

using namespace std;

class DisjointSet{
  public:
    vector<int> r, p;

    DisjointSet(){}
    DisjointSet(int num){
      r.resize(num, 0);
      p.resize(num, 0);
      for(int i=0 ; i<num ; ++i) makeSet(i);
    }
    ~DisjointSet(){}

    void makeSet(int x){
      p[x] = x;
      r[x] = 0;
    }

    void unite(int x, int y){
      link(findSet(x), findSet(y));
    }

    void link(int x, int y){
      if(r[x] > r[y]){
        p[y] = x;
      }else{
        p[x] = y;
        if(r[x] == r[y]) r[y] = r[y]+1;
      }
    }

    bool same(int x, int y){
      return findSet(x) == findSet(y);
    }

    int findSet(int a){
      if(a != p[a]) p[a] = findSet(p[a]);
      return p[a];
    }
};

int main(){
  int n=0, m=0;
  int x=0, y=0, com=0;

  cin >> n >> m;
  DisjointSet ds = DisjointSet(n);

  for(int i=0 ; i<m ; ++i){
    cin >> com >> x >> y;

    if(com == 0) ds.unite(x, y);
    else if (com == 1){
      if(ds.same(x, y)) cout << 1 << endl;
      else cout << 0 << endl;
    }
  }
}



Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

vector<bool> PRIME_TABLE(ll n) {
	vector<bool> prime(n + 1, true);
	if (n >= 0) prime[0] = false;
	if (n >= 1) prime[1] = false;
	for (int i = 2; i * i <= n; i++) {
		if (!prime[i]) continue;
		for (ll j = i + i; j <= n; j += i) {
			prime[j] = false;
		}
	}
	return prime;
}

map<ll, ll> PRIME_FACTOR(ll n) {
	const auto& pt = PRIME_TABLE((ll)ceil(sqrt(n)));
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++)
	{
		if (!pt[i]) continue;
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

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

	ll L;
	cin >> L;

	vector<bool> proc;
	while (true)
	{
		if (L == 2) break;
		if (L % 2 == 0)
		{
			L /= 2;
			proc.push_back(true);
		}
		else
		{
			L -= 1;
			proc.push_back(false);
		}
	}

	reverse(proc.begin(), proc.end());

	vector<PP> graph;
	graph.emplace_back(0, P(1, 2));
	graph.emplace_back(1, P(1, 2));
	ll N = 2;
	ll cL = 2;

	for (auto p : proc)
	{
		if (p)
		{
			for (auto& e : graph)
			{
				e.first *= 2;
			}
			graph.emplace_back(0, P(N, N + 1));
			graph.emplace_back(1, P(N, N + 1));
			N += 1;
			cL *= 2;
		}
		else
		{
			graph.emplace_back(cL, P(1, N));
			cL += 1;
		}
	}

	cout << N << " " << graph.size() << endl;

	for (const auto& e : graph)
	{
		cout << e.second.first << " " << e.second.second << " " << e.first << endl;
	}
	//cout <<cL << endl;

	//system("pause");
}


Measured memory_bytes: 256
def inp():
    return(int(input()))


dp = [0]*87
dp[0] = 2
dp[1] = 1


def lucas(n):
    if dp[n] != 0:
        return dp[n]
    dp[n] = lucas(n-1) + lucas(n-2)
    return dp[n]


n = inp()
print(lucas(n))


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
#define VL vector<lol>
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

lol a[3001][3001] = {};
lol dp[3001][3001][4] = {};

int main()
{
    lol result{0};
    lol r, c, k; cin >> r >> c >> k;
    FOR(i, 1, k)
    {
        lol ri, ci, vi;
        cin >> ri >> ci >> vi;
        a[ri][ci] = vi;
    }
    FOR(i, 1, r)
    {
        FOR(j, 1, c)
        {
            dp[i][j][0] = max(dp[i-1][j][3], dp[i][j-1][0]);
            result = max(result, dp[i][j][0]);
            FOR(x, 1, 3)
            {
                dp[i][j][x] = max(dp[i-1][j][3]+a[i][j], max(dp[i][j-1][x], dp[i][j-1][x-1]+a[i][j]));
                result = max(result, dp[i][j][x]);
            }
        }
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 355120
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
#define all(v) sort(v.begin(),v.end())
#define ALL(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n+1);
    vector<ll> b(n);
    ll ans = 0;
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];

    rep(i,n){
        if(b[i] > a[i]){
            int d = b[i] - a[i];
            int e = a[i+1];
            a[i+1] -= d;
            if(a[i+1] < 0){
                a[i+1] = 0;
                d = e;
            }
            ans += a[i] + d;
        }else{
            ans += b[i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
//入力
  int N, M;
  cin >> N;
  vector<string> aka(N);
  for (int i = 0; i < N; i++) cin >> aka.at(i);
  cin >> M;
  vector<string> ao(M);
  for (int i = 0; i < M; i++) cin >> ao.at(i);
  
//カウント
  vector<int> akaC(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (aka.at(j) == aka.at(i)) akaC.at(i)++;
    }
    for (int k = 0; k < M; k++) {
      if (ao.at(k) == aka.at(i)) akaC.at(i)--;
    }
  }
  
//出力
  int best = 0;
  for (int i = 0; i < N; i++) {
    if (akaC.at(i) > best) best = akaC.at(i);
  }
  cout << best << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	//half and half


	public static void main(String[] args){
		int A,B,C,X,Y;
		Scanner sc = new Scanner(System.in);
		A= sc.nextInt();
		B= sc.nextInt();
		C= sc.nextInt();
		X= sc.nextInt();
		Y= sc.nextInt();
		int v0=C*2*X+Math.max(0, B*(Y-X));
		int v1=C*2*Y+Math.max(0, A*(X-Y));
		int v2=X*A+Y*B;
		int v=Math.min(v0, v1);
		v=Math.min(v, v2);
		System.out.println(v);
	}
}

Measured memory_bytes: 21716
#ABC150-A
if False:
    K,X=map(int,input().split())
    print('Yes' if 500*K>=X else 'No')

#ABC150-B
if False:
    N=int(input())
    S=input()
    print(S.count('ABC'))

#ABC150-C
if True:
    import itertools
    N=int(input())
    dic=list(itertools.permutations(list(range(1,N+1))))
    # print(dic)
    P=tuple(int(i) for i in input().split())
    Q=tuple(int(i) for i in input().split())

    print(abs(dic.index(P)-dic.index(Q)))


Measured memory_bytes: 8052
// https://atcoder.jp/contests/abc175/tasks/abc175_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int32_t i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N, K;
    cin >> N >> K;
    vector<int> P(N), C(N);
    REP(i, N) cin >> P[i], P[i]--;
    REP(i, N) cin >> C[i];

    int ans = -1e12;
    // スタート位置
    REP(i, N) {
        vector<int> v;
        int now = i;
        while (true) {
            now = P[now];
            v.emplace_back(C[now]);
            if (now == i) {
                break;
            }
        }
        int loopSum = accumulate(ALL(v), 0LL);
        int cnt = v.size();
        int t = 0;
        REP(j, min(cnt, K)) {
            t += v[j];
            // ループ内の合計x残りループ回数を加算する
            // ループ内の合計が負なら無視
            ans = max(ans, t + max(0LL, loopSum) * ((K - j - 1) / cnt));
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3788
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

R = INT()
G = INT()
print(2 * G - R)

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

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

  int n;
  cin >> n;

  pair<string,int> p[n];
  for (int i = 0; i < n; ++i) cin >> p[i].first >> p[i].second;

  string s;
  cin >> s;

  bool ok = false;
  int ans = 0;

  for (int i = 1; i < n; ++i) {
    if (s == p[i-1].first) ok = true;
    if (ok) ans += p[i].second;
  }

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 3672
import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.*;
     
    public class Main {
    	public static void main(String[] args) throws IOException {
    		BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    		String s;
    		String sl[];
     
    		s = r.readLine();
    		sl = s.split(" ");
    		int n = Integer.parseInt(sl[0]);
            int k = Integer.parseInt(sl[1]);
          	s = r.readLine();
    		sl = s.split(" ");
          	int a[] = new int[50];
          	for(int i = 0; i < n; i++)
            {
              a[i] = Integer.parseInt(sl[i]);
            }
          	
            int vmax = 0;
          	int minkn = Math.min(k, n);
            for(int i = 1; i <= minkn; i++)
            {
              int js[] = new int[i];
              for(int j = 0; j <= i; j++)
              {
                int v = 0;
                for(int l = 0; l < j; l++)
                {
                  js[l] = a[l];
                }
                for(int l = 0; l < i - j; l++)
                {
                  js[i - 1 - l] = a[n - 1 - l];
                }
                Arrays.sort(js);
                int kii = Math.min(k - i, i);
                int z = 0;
                for(z = 0; z < kii; z++)
                {
                  if(js[z] >= 0) break;
                }
                for(; z < i; z++)
                {
                  v += js[z];
                }
                vmax = Math.max(v, vmax);
              }
            }
            System.out.println(vmax);
    	}
    }

Measured memory_bytes: 33500
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios::sync_with-stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    char d;
    cin>>d;
    if(d>=97 && d<=122)
    cout<<"a\n";
    else
    cout<<"A\n";

}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;
const ll MAX_N=1e5;
ll N,K,W[MAX_N],D[MAX_N];
bool C(ll y){
	ll c=0;
	REP(i,N){
		if(W[i]>y)continue;
		c+=(y-W[i])/D[i]+1;
		if(c>=K)return true;
	}
	return false;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>K;
	REP(i,N){
		cin>>W[i]>>D[i];
	}
	ll lb=0,ub=2e18;
	while(ub-lb>1){
		ll m=(lb+ub)>>1;
		if(C(m)){
			ub=m;
		}else{
			lb=m;
		}
	}
	cout<<ub<<endl;
}

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

int main()
{
  int n;
  int sum;
  int min=999999;
  cin >> n;
  cin >> sum;
  for (size_t i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    if (temp<min)
    {
      min=temp;
    }
    sum=sum-temp;
  }
  int ans=n+sum/min;
  cout << ans;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vpii work(n);
    int a,b;
    rep(i,n){
        cin>>a>>b;
        work[i]=mp(b,a);
    }
    sort(all(work));
    ll time=0;
    rep(i,n){
        time+=(ll)work[i].second;
        if(time>(ll)work[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <vector>
using namespace std;

const int N = 200000;
vector<int> g[N];
int p[N];
int n;

void dfs(int v, int prev = -1) 
{
	for (int i = 0; i < g[v].size(); ++i) if (g[v][i] != prev) {
		p[g[v][i]] = v;
		dfs(g[v][i], v);
	}
}

int main() 
{
	scanf("%d", &n);
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}
	long long r = n;
	dfs(0);
	for (int i = 1; i < n; ++i) {
		int v = p[i];
		if (i < v) r += (long long)(i + 1) * (v - i);
		else r += (long long)(i - v) * (n - i);
	}
	printf("%lld\n", r);
	return 0;
}


Measured memory_bytes: 24192
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll Q,H,S,D,N;
int main(){
	cin>>Q>>H>>S>>D>>N;
	ll ans = min(4*N*Q,min(2*N*H,N*S));
	if(N%2==0) ans=min(ans,N*D/2);
	else ans=min(ans,D*(N/2)+min(S,min(2*H,4*Q)));
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <queue>

using namespace std;

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

const ll MOD = 1000000007;
const ll fuel = (ll) 1e14;
const ll inf = (ll) 1e18;

ll L;

vector<ll> dijkstraDistOnly(const vector<set<Pii> > &edge, int start) {
  vector<ll> length(edge.size(), inf);
  vector<bool> visited(edge.size(), false);
  priority_queue<pair<ll, int> > que;
  que.push(pair<ll, int>(0, start)); // negative distance
  length[start] = 0;
  while (!que.empty()) {
    auto now = que.top();
    que.pop();
    if (visited[now.second]) continue;
    visited[now.second] = true;
    for (auto x : edge[now.second]) {
      if (visited[x.first]) continue;
      ll d = -now.first + x.second;
      if (d % fuel > L) {
        d = (d / fuel * fuel) + fuel + x.second;
      }
      if (d < length[x.first]) {
        length[x.first] = d;
        que.push(pair<ll, int>(-d, x.first));
      }
    }
  }
  return length;
}

vector<vector<ll> > dijkstraAll(const vector<set<Pii> > &edge) {
  int n = edge.size();
  vector<vector<ll> > d;
  for (int i = 0; i < n; i++) {
    d.push_back(dijkstraDistOnly(edge, i));
  }
  return d;
}

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

  int n, m;
  cin >> n >> m >> L;
  vector<set<Pii> > edge;
  for (int i = 0; i < n; i++) edge.push_back(set<Pii>());
  for (int i = 0; i < m; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    if (c > L) continue;
    edge[a-1].insert(Pii(b-1, c)); // zero index
    edge[b-1].insert(Pii(a-1, c)); // zero index
  }
  int q;
  cin >> q;
  vector<int> s(q), t(q);
  for (int i = 0; i < q; i++) cin >> s[i] >> t[i];
  for (int i = 0; i < q; i++) {
    s[i]--;
    t[i]--;
  }

  auto distanceMatrix = dijkstraAll(edge);

  for (int i = 0; i < q; i++) {
    if (distanceMatrix[s[i]][t[i]] >= inf) cout << -1 << endl;
    else cout << (distanceMatrix[s[i]][t[i]] / fuel) << endl;
  }

  return 0;
}


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

ans = 0
total = 0
r = 0
for i in range(N):
    l = i
    while r < N and total ^ A[r] == total + A[r]:
        total += A[r]
        r += 1
    ans += r - l
    if l == r:
        r += 1
    else:
        total -= A[l]

print(ans)
         

Measured memory_bytes: 32248
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                while (true) {
                        sc.nextLine();
                        String c = sc.nextLine();
                        if (c.equals("=")) {
                                System.out.println(N);
                                break;
                        } else if (c.equals("+")) {
                                N += sc.nextInt();
                        } else if (c.equals("-")) {
                                N -= sc.nextInt();
                        } else if (c.equals("*")) {
                                N *= sc.nextInt();
                        } else if (c.equals("/")) {
                                N /= sc.nextInt();
                        }
                }
        }
}

Measured memory_bytes: 26560
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

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

int main() {
    int A, B;
    cin >> A >> B;
    cout << max(A + B, max(A - B, A * B)) << endl;
}


Measured memory_bytes: 256
N = int(input())
S = input()

# at position 0
l_b = 0
r_w = S.count('.')

needHand = l_b + r_w
for i in S:
  if i == '#': #black
    l_b += 1
  else:
    r_w -= 1  
  needHand = min(needHand, l_b + r_w)

ans = needHand
print("{}".format(ans))

Measured memory_bytes: 3500
#include <iostream>
using namespace std;
main () {
	
	int a, b, c;
	cin>>a>>b>>c;
	if (a == b && b == c && a == c) {
		cout<<"No"<<endl;
	} else 
	if (a == b) {
		if (b != c) {
			cout<<"Yes"<<endl;
		}
	} else if (b == c) {
		if (c != a) {
			cout<<"Yes"<<endl;
		}
	} else if (a == c) {
		if (a != b) {
			cout<<"Yes"<<endl;
		}
	} else {
		cout<<"No"<<endl;
	}
}

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

int main(){
    int n;
    while(scanf("%d",&n), n != 0){
        int a[1001]={0};
        for(int i=0;i<n;++i)scanf("%d ",&a[i]);
        int mini = INT_MAX;
        for(int i=0;i<n;++i){
            for(int j=i+1;j<n;++j){
                int d = abs(a[i] - a[j]);
                if(d < mini)mini = d;
            }
        }
        printf("%d\n",mini);
    }

    return 0;
}

Measured memory_bytes: 3188
object Main {
  def main(args: Array[String]) = {
    import scala.io.StdIn.readLine

    /*
    val sc = new java.util.Scanner(System.in)
    val A = sc.nextInt
    val B = sc.nextInt
    val T = sc.nextInt
    sc.close()

    val createCount = Math.floor((T + 0.5) / A).toInt
    val createNum = createCount * B
    println(createNum)
     */

    val Array(a, b, t) = readLine.split(" ").map(_.toInt)
    val count = t / a * b
    println(count)
  }
}

Measured memory_bytes: 27312
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var n int
	fmt.Sscan(getNextLine(scanner), &n)
	vv := getIntList(scanner)
	cc := getIntList(scanner)
	ans := 0
	for i := 0; i < n; i++ {
		if vv[i] > cc[i] {
			ans += vv[i] - cc[i]
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640