akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

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

const int N = (int)2e5 + 123, LOG = 20;


vector< int > g1[N], g2[N];
vector< pii > ch[N];
int n, x, y, dp[N], tin[N], tout[N], timer, up[LOG][N], depth[N];

void no(){
	printf("-1");
	exit(0);
}
void dfs1(int v, int pr){
	tin[v] = ++timer;
	depth[v] = depth[pr] + 1;
	up[0][v] = pr;    
	for(int i = 1; i < LOG; i++)
		up[i][v] = up[i - 1][ up[i - 1][v] ];
	for(auto to : g2[v])
		if(to != pr){
			dfs1(to, v);	
			ch[v].pb({tout[to], to});
		}
	tout[v] = timer;
}
bool upper(int v, int u){
	return tin[v] <= tin[u] && tin[u] <= tout[v];
}
int lca(int v, int u){
	if(upper(v, u))
		return v;
	if(upper(u, v))
		return u;
	for(int i = LOG - 1; i >= 0; i--)
		if(!upper(up[i][v], u))
			v = up[i][v];
	return up[0][v];
}
int dist(int v, int u){
	return depth[v] + depth[u] - 2 * depth[lca(v, u)];
}
void dfs2(int v, int u, int pr){
	dp[v] = dist(v, u);
	if(v == u)
		return;
	for(auto to : g1[v]){
		if(to != pr && to != u){
			int w;
			if(upper(u, to))                                                                         
				w = lower_bound(ch[u].begin(), ch[u].end(), mp(tin[to], 0)) -> s;
			else
				w = up[0][u];
			if(dist(v, to) > 2)
				no();
			dfs2(to, w, v);
        	dp[v] = max(dp[v], dp[to] + 1);
        }
	}
}
int main()
{                         
	scanf("%d%d%d", &n, &x, &y);
	for(int i = 1; i < n; i++){
		int v, u;
		scanf("%d%d", &v, &u);
		g1[v].pb(u);
		g1[u].pb(v);
	}
    for(int i = 1; i < n; i++){
		int v, u;
		scanf("%d%d", &v, &u);
		g2[v].pb(u);
		g2[u].pb(v);
	}
	dfs1(1, 1);
	dfs2(x, y, x);
	printf("%d", dp[x] * 2);
	return 0;
}


Measured memory_bytes: 69760
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;


void solve(long long A, long long B){
  int a = max(A, B);
  int b = max(a-1, min(A, B));
  cout << a + b << endl;
}

signed main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(A, B);
}


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

int main()
{
	int n, i;
	int a[100];
	
	cin >> n;
	
	for(i = 0; i < n; i++){
		cin >> a[i];
	}
	for(i = n - 1; i >= 0; i--){
		if(i != n - 1){
			cout << " ";
		}
		cout << a[i];
	}
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 3072
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func debug(a ...interface{}) {
	if os.Getenv("ONLINE_JUDGE") == "false" {
		fmt.Fprintln(os.Stderr, a...)
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	w := make([]string, n)
	c := map[string]bool{}
	for i := 0; i < n; i++ {
		w[i] = scanString()
		if c[w[i]] {
			fmt.Fprintln(wr, "No")
			return
		}
		c[w[i]] = true
	}
	for i := 0; i < n-1; i++ {
		if w[i][len(w[i])-1] != w[i+1][0] {
			fmt.Fprintln(wr, "No")
			return
		}
	}

	fmt.Fprintln(wr, "Yes")

}


Measured memory_bytes: 1804
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	const long o=1;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		int[][] a=new int[n+1][];
		a[0]=new int[3];
		for(int i = 1;i<n+1;i++) {a[i]=sc.Ia;}
		Array.Sort(a,(u,v)=>(u[0]+u[1])-(v[0]+v[1]));
		long[] dp=new long[20001];
		dp[0]=1;
		for(int i = 1;i<=n;i++) {
			for(int j = Math.Min(20000,a[i][1]+a[i][0]);j>=a[i][0];j--) {
				if(dp[j-a[i][0]]!=0){dp[j]=Math.Max(dp[j],dp[j-a[i][0]]+a[i][2]);}
			}
		}
		Console.WriteLine(dp.Max()-1);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 13476
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	ll sum=0,m=inf;
	bool flag=1;
	for(int i=0;i<n;i++){
		ll A,B;
		cin>>A>>B;
		sum+=B;
		if(A>B) m=min(m,B);
		if(A!=B) flag=0;
	}
	if(flag) cout<<0<<endl;
	else cout<<sum-m<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int n, ult;
    scanf("%d", &n);

    ult = n % 10;

    if(ult == 2 || ult == 4 || ult == 5 || ult == 7 || ult == 9)
        printf("hon");
    else if(ult == 0 || ult == 1 || ult == 6 || ult == 8)
        printf("pon");
    else
        printf("bon");

    return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int INF = 1e9 + 239;

int n;
vector<int> ans;
vector<vector<int>> g;

void bfs(int cur) {
	vector<int> d(n, INF);
	d[cur] = 0;
	queue<int> q;
	q.push(cur);
	int c = 0;
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		c++;
		for (auto u : g[v]) {
			if (d[u] > d[v] + 1) {
				d[u] = d[v] + 1;
				ans[u] = v;
				q.push(u);
			}
		}
	}
	if (c < n) {
		cout << "No\n";
		exit(0);
	}
}

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

	cin >> n;
	int m;
	cin >> m;
	g.resize(n);
	ans.resize(n);
	while (m--) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	bfs(0);
	cout << "Yes\n";
	for (int i = 1; i < n; i++) {
		cout << ans[i] + 1 << ' ';
	}
	cout << endl;
}

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

s = input()
l = []
l.append(s[0])
count = 0
for i in range(1, len(s)):
    if l[i-1] == s[i]:
        count += 1
        if s[i] == "0":
            l.append("1")
        else:
            l.append("0")
    else:
        l.append(s[i])
print(count)

Measured memory_bytes: 4120
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> v;
  int k;
  for (int i = 0; i < n; i++) {
    cin >> k;
    int g;
    for (int j = 0; j < k; j++) {
      cin >> g;
      v[g]++;
    }
  }
  int ans = 0;
  for (auto x : v) {
    if (x.second == n)
      ans++;
  }
  cout << ans << endl;
}


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

using namespace std;
bool check(string s){
	string t=s;
	reverse(s.begin(),s.end());
	if(s==t)return true;
return false;
}
int main(){
	string s;
	cin>>s;
	string t1="",t2="";
	for(int i=0;i<(s.size()-1)/2;i++)t1+=s[i];
	for(int i=(s.size()+3)/2-1;i<s.size();i++)t2+=s[i];
	if(check(s)&&check(t1)&&check(t2))cout<<"Yes"<<endl;
	else cout<<"No"<<endl; 
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  @scala.annotation.tailrec
  def loop(words: Seq[String], previous: String, history: List[String]): Boolean =
    words match {
      case Seq() => true
      case x :: _ if history.contains(x) || previous.last != x.head => false
      case x :: xs => loop(xs, x, x :: history)
    }
  val sc = new java.util.Scanner(System.in)
  val first :: words = List.fill(sc.nextInt())(sc.next())
  println(if (loop(words, first, List(first))) "Yes" else "No")
}


Measured memory_bytes: 55456
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
from typing import overload
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def z_algo(S):
    N = len(S)
    Z = [0] * N
    Z[0] = N

    i = 1
    j = 0
    while i < N:
        while i + j < N and S[j] == S[i + j]:
            j += 1
        Z[i] = j

        if j == 0:
            i += 1
            continue

        k = 1
        while k < j and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        
        i += k
        j -= k
    return Z


def main():
    N = int(input())
    S = input().strip()

    res = 0
    for i in range(N - 1):
        Z = z_algo(S[i:])
        t = 0
        for i, z in enumerate(Z):
            if i < z:
                continue
            t = max(t, z)
        res = max(res, t)
        
    print(res)


if __name__ == "__main__":
    main()



Measured memory_bytes: 81576
/* ex5_4
   Acro  */
#include <stdio.h> 
/* ACGT文字列の長さを求める関数 */
int acgt(char *s){
    int max = 0, count = 0;
    /* null文字がくるまでループ */
    while (*s)
    {
        /* ACGT文字列かどうかで場合分け */
        if (*s == 'A' || *s == 'C' || *s == 'G' || *s == 'T' )
        {
            count ++;
        }
        else
        {
            /* 最大の長さを保存 */
            if (max < count)
            {
                max = count;
            }
            /* countの初期化 */
            count = 0;
        }
        *s ++;
    }
    /* 最後の部分文字列の長さの吟味 */
    if (max < count)
    {
        max = count;
    }
    return max;
}

int main(void){
    char string[80];
    scanf("%s",string);
    printf("%d\n",acgt(string));
    return 0;
}

Measured memory_bytes: 1724
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int grid[100][100];

int h, w;
int x = 0, y = 0;
int go = true;

void paint(int color, int n) {
    if (n == 0) return;
    grid[x][y] = color;
    if (go) {
        y++;
        if (y == w) {
            go = false;
            x++;
            y--;
        }
    } else {
        y--;
        if (y == -1) {
            go = true;
            x++;
            y++;
        }
    }
    paint(color, n - 1);
}

int main() {
    cin >> h >> w;
    int n;
    cin >> n;
    REP(i,n) {
        int a;
        cin >> a;
        paint(i + 1, a);
    }
    
    REP(i,h) {
        REP(j,w-1) {
            cout << grid[i][j] << " ";
        }
        cout << grid[i][w-1] << endl;
    }
}


Measured memory_bytes: 384
fun main(args: Array<String>) {
    var s = 0
    var ans = 0
    var len = 0
    for (c in readLine()!!) {
        len++
        if (c == 'S') s++ else {
            if (s > 0) { ans++; s-- }
        }
    }
    println(len - 2 * ans)
}

Measured memory_bytes: 21136
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	unsigned long long p[m],y[m],x[m] ;
	for(int i=0;i<m;i++)
	{
		cin>>p[i]>>y[i];
		x[i]=(p[i]<<47)+(y[i]<<17)+i;;
	}
	sort(x,x+m);
	int c=1;
	y[(x[0]<<47)>>47]=c;//改装为排名 
	for(int i=1;i<m;i++){
		if(x[i]>>47==x[i-1]>>47)
		   c++;
		else
		   c=1;
		y[(x[i]<<47)>>47]=c;
	}
	for(int i=0;i<m;i++){
		x[i]=p[i]*1000000+y[i];
		printf("%012lu\n",x[i]); 
	}
	return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=10000;
const int Max = 1e6+10;
const double pi = acos(-1);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
void solve(){
    int n;
    cin>>n;
    VI a(n+1,0);
    rep(i,2,n+1){
        int t;
        cin>>t;
        a[t]++;
    }
    rep(i,1,n+1)cout<<a[i]<<"\n";
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}






Measured memory_bytes: 3988
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var N  = long.Parse(Console.ReadLine());
            Console.WriteLine((N-1)*N/2);

        }
    }
}


Measured memory_bytes: 13140
#!/usr/bin/perl
my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @l = map { $_ - 0 } split(/\s+/,<STDIN>);

my @d = ();
$#d = 2000;

for(my $i=0;$i<$n-1;$i++){
  for(my $j=$i+1;$j<$n;$j++){
    my $v = $l[$i] + $l[$j];
    $d[$v] ++;
  }
}

my @dsum = ();
$#d = 2000;
my $sm = 0;
for(my $i=$#d;$i>=0;$i--){
  $sm += $d[$i];
  $dsum[$i] = $sm;
}

my $r = 0;
my @sl = sort { $b <=> $a } @l;
my $a = 0;
for(my $i=0;$i<$n;$i++){
  my $h1 = $sl[$i];
  $a += ($n - 1 - $i) if ($n - 1 - $i)>=0;
  $r += ( $dsum[$h1+1] - $a );
}
print "$r\n";

exit(0);



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

#define ll long long

ll a[100005], k, n;

ll dp[100005][4];
ll mat[100001][4];

int main()
{
	cin >> n;

	for(int i=1;i<=n;i++)
		cin >> mat[i][1] >> mat[i][2] >> mat[i][3];

	dp[1][1]=mat[1][1];
	dp[1][2]=mat[1][2];
	dp[1][3]=mat[1][3];

	ll ans=-1;

	for(int i=2;i<=n;i++)
	{
		dp[i][1]=max(dp[i-1][2]+mat[i][1],dp[i-1][3]+mat[i][1]);
		dp[i][2]=max(dp[i-1][1]+mat[i][2],dp[i-1][3]+mat[i][2]);
		dp[i][3]=max(dp[i-1][1]+mat[i][3],dp[i-1][2]+mat[i][3]);

		//cout << dp[i][1] << " " << dp[i][2] << " " << dp[i][3] << endl;

		ans=max(max(dp[i][1],dp[i][2]),max(dp[i][3],ans));
	}

	ans=max(max(dp[1][1],dp[1][2]),max(dp[1][3],ans));

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6528
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    bool solve() {
        int N;
        cin >> N;
        if (N == 0) return false;
        vector<string> vs(N);
        vector<int> level(N);
        for (int i = 0; i < N; ++i) {
            cin >> vs[i];
            int cnt = 0;
            for (auto e : vs[i]) {
                if (e == '.') cnt++;
                else break;
            }
            level[i] = cnt;
        }

        for (int i = 0; i < N; ++i) {
            int idx = 0;
            for (int j = i + 1; j < N; ++j) {
                if (level[i] >= level[j]) {
                    break;
                } else if (level[i] + 1 == level[j]) {
                    vs[j][level[i]] = '|';
                    chmax(idx, j);
                }
            }

            for (int j = idx; j > i + 1; --j) {
//                if (i == 52 && j == 3) {
//                    int tapi = 1333;
//                }
                if (vs[j][level[i]] == '|' && vs[j - 1].size() > level[i] && vs[j - 1][level[i]] == '.') {
                    vs[j - 1][level[i]] = '|';
                }
//                if (vs[9][4] == '|') {
//                    int tapi = 1333;
//                }
            }
//            if (i == 51) {
//                int tapi = 1333;
//            }
//            if (vs[9][4] == '|') {
//                int tapi = 1333;
//            }
        }
        for (int i = 0; i < N; ++i) {
            if (level[i] > 0) {
//                assert(vs[i][level[i] - 1] == '|');
                vs[i][level[i] - 1] = '+';
            }
        }

        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < vs[i].size(); ++j) {
                if (vs[i][j] == '.')vs[i][j] = ' ';
            }
        }

        for (int i = 0; i < N; ++i) {
            cout << vs[i] << endl;
        }

        return true;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    while (Solve().solve());

    return 0;
}



Measured memory_bytes: 3372
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
vector<long long> divisor(long long val) {
  vector<long long> res;
  for (long long i = 1; i * i <= val; ++i) {
    if (val % i == 0) {
      res.emplace_back(i);
      if (i * i != val) res.emplace_back(val / i);
    }
  }
  sort(ALL(res));
  return res;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> a(n + 1); FOR(i, 1, n + 1) cin >> a[i];
  vector<long long> cnt(n + 1, 0);
  vector<int> ans;
  for (int i = n; i >= 1; --i) {
    bool plus = false;
    if (a[i] == 0 && (cnt[i] & 1)) plus = true;
    if (a[i] == 1 && cnt[i] % 2 == 0) plus = true;
    if (plus) {
      ans.emplace_back(i);
      auto d = divisor(i);
      for (long long ll : d) ++cnt[ll];
    }
  }
  reverse(ALL(ans));
  cout << ans.size() << '\n';
  REP(i, ans.size()) cout << ans[i] << (i + 1 == ans.size() ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 3832
// Aizu Vol-1 0187: Stoning Fortune
// 2017.8.10

#include <stdio.h>
#include <math.h>

#define EPS 1e-6

typedef struct { long long x, y; } PP;
typedef struct { double x, y; } fPP;

char *kichi[] = { "dai-kichi", "chu-kichi", "kichi", "syo-kichi", "kyo" };
int std[] = { 1900000, 1000000, 100000, 0, -1 };

PP pp[6];
fPP fp[3];

double dis(fPP *p1, fPP *p2);
int intersection(fPP *p, PP *p1, PP *p2, PP *p3, PP *p4);

int main()
{
	int i, ans;
	double a, b, c, s, t;

	while (1) {
		for (i = 0; i < 6; i += 2) {
			scanf("%lld%lld%lld%lld", &(pp[i].x), &(pp[i].y), &(pp[i + 1].x), &(pp[i + 1].y));
			if (!i && !pp[0].x && !pp[0].y && !pp[1].x && !pp[1].y) return 0;
		}
		ans = 4;
		if (!intersection(fp, pp, pp + 1, pp + 2, pp + 3)) goto NG;
		if (!intersection(fp + 1, pp + 2, pp + 3, pp + 4, pp + 5)) goto NG;
		if (!intersection(fp + 2, pp + 4, pp + 5, pp, pp + 1)) goto NG;

		a = dis(fp, fp + 1), b = dis(fp + 1, fp + 2), c = dis(fp + 2, fp);
		s = (a + b + c) / 2.0;
		t = sqrt(s*(s - a)*(s - b)*(s - c));

		if (fabs(t) > EPS) {
			for (i = 0; ans == 4 && i < 4; i++) {
				if (fabs(t - std[i]) <= EPS || t >= std[i]) ans = i;
			}
		}
	NG:		puts(kichi[ans]);
	}
	return 0;
}

double dis(fPP *p1, fPP *p2)
{
	double x = p1->x - p2->x, y = p1->y - p2->y;
	return sqrt(x*x + y*y);
}

int isPointOnSegment(PP *p, PP *p1, PP *p2)
{
	long long x1 = p1->x, y1 = p1->y, x2 = p2->x, y2 = p2->y;
	long long d;
	if (x1 > x2) { d = x1, x1 = x2, x2 = d; d = y1, y1 = y2, y2 = d; }
	return x1 <= p->x && p->x <= x2 &&
		((y1 <= y2 && y1 <= p->y && p->y <= y2) ||
		(y1 > y2 && y2 <= p->y && p->y <= y1))
		&& (p->y - y1)*(x2 - x1) == (y2 - y1)*(p->x - x1);
}

int intersection(fPP *p, PP *p1, PP *p2, PP *p3, PP *p4)
{
	long long t1, t2, t3, t4;
	long long bo, ua;

	if ((p2->y - p1->y)*(p4->x - p3->x) == (p4->y - p3->y)*(p2->x - p1->x)) return 0;

	t1 = (p1->y - p3->y)*(p3->x - p4->x) - (p1->x - p3->x)*(p3->y - p4->y);
	t2 = (p2->y - p3->y)*(p3->x - p4->x) - (p2->x - p3->x)*(p3->y - p4->y);
	t3 = (p3->y - p1->y)*(p1->x - p2->x) - (p3->x - p1->x)*(p1->y - p2->y);
	t4 = (p4->y - p1->y)*(p1->x - p2->x) - (p4->x - p1->x)*(p1->y - p2->y);

	if (t1*t2 < 0 && t3*t4 < 0) {
		// ??????????????§??????
		bo = (p4->y - p3->y)*(p2->x - p1->x) - (p4->x - p3->x)*(p2->y - p1->y);
		ua = (p4->x - p3->x)*(p1->y - p3->y) - (p4->y - p3->y)*(p1->x - p3->x);
		p->x = p1->x + (double)ua / bo * (p2->x - p1->x);
		p->y = p1->y + (double)ua / bo * (p2->y - p1->y);
		return 1;
	}
	t1 = isPointOnSegment(p1, p3, p4), t2 = isPointOnSegment(p2, p3, p4);
	if (t1) p->x = p1->x, p->y = p1->y;
	else if (t2) p->x = p2->x, p->y = p2->y;
	t3 = isPointOnSegment(p3, p1, p2), t4 = isPointOnSegment(p4, p1, p2);
	if (t3) p->x = p3->x, p->y = p3->y;
	else if (t4) p->x = p4->x, p->y = p4->y;
	return t1 || t2 || t3 || t4;
}

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

int main(){
    int N ,K;
    cin >> N >> K;
    int l[N];
    for(int i=0;i<N;i++){
        cin >> l[i];
    }

    sort(l,l+N,greater<int>());

    int res = 0;
    for(int i=0;i<K;i++){
        res = res + l[i];
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	string s;
	cin >> s;
	int size = SZ(s), ans = 0;

	rep(i, size / 2) {
		char c1 = s[i], c2 = s[size - i - 1];
		bool flag = false;

		if (c1 == 'i'&&c2 == 'i')flag = true;
		else if (c1 == 'w'&&c2 == 'w')flag = true;
		else if (c1 == '('&&c2 == ')')flag = true;
		else if (c1 == ')'&&c2 == '(')flag = true;

		if (!flag)ans++;
	}

	if (size % 2 == 1) {
		char c = s[size / 2];
		if (c == '(' || c == ')')ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3208
import java.util.Arrays;

public class Main {


  private static void solve() {
    int n = ni();
    int[] a = na(n);
    int sum = Arrays.stream(a).sum();
    
    int diff = Integer.MAX_VALUE;
    int arg = 0;
    for (int i = 0; i < n; i ++) {
      int now = Math.abs(n * a[i] - sum);
      if (now < diff) {
        diff = now;
        arg = i;
      }
    }
    System.out.println(arg);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 28116
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<pair<string, int64_t>> st(n);
    for (auto&& v : st) {
        cin >> v.first >> v.second;
    }

    string x;
    cin >> x;

    int64_t ans = -1;
    for (auto i : irange(0L, n)) {
        if (ans >= 0) {
            ans += st[i].second;
        } else if (x == st[i].first) {
            ans = 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


A, B, C, D = map(int, sys.stdin.readline().split())

print(max(0, min(B, D) - max(A, C)))

Measured memory_bytes: 63852
#include <bits/stdc++.h>
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 int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = INT_MAX;
const ll LLINF = INT64_MAX;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

template <typename Monoid>
struct SegmentTree
{
    using F = function<Monoid(Monoid, Monoid)>;

private:
    int n;
    vector<Monoid> node;
    Monoid E;
    F f;

public:
    SegmentTree(vector<Monoid> &v, Monoid e, const F func) : f(func), E(e)
    {
        int sz = v.size();
        n = 1;
        while (n < sz)
        {
            n *= 2;
        }
        node.resize(2 * n - 1, E);
        for (int i = 0; i < sz; i++)
        {
            node[i + n - 1] = v[i];
        }
        for (int i = n - 2; i >= 0; i--)
        {
            node[i] = f(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    void update(int i, Monoid val)
    {
        i += (n - 1);
        node[i] = val;
        while (i > 0)
        {
            i = (i - 1) / 2;
            node[i] = f(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    Monoid query(int a, int b, int i = 0, int l = 0, int r = -1)
    {
        if (r < 0)
        {
            r = n;
        }
        if (r <= a || b <= l)
        {
            return E;
        }
        if (a <= l && r <= b)
        {
            return node[i];
        }
        Monoid vl = query(a, b, 2 * i + 1, l, (l + r) / 2);
        Monoid vr = query(a, b, 2 * i + 2, (l + r) / 2, r);
        return f(vl, vr);
    }

    Monoid operator[](const int &i) const
    {
        return node[i + n - 1];
    }
};

ll GCD(ll a, ll b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

ll LCM(ll a, ll b)
{
    return a * b / GCD(a, b);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    SegmentTree<ll> seg(a, 0, GCD);
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ll l = seg.query(0, i);
        ll r = seg.query(i + 1, n);
        chmax(ans, GCD(l, r));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3200
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
#define Int int64_t
using ll = long long;

int main() {
	int n;

	cin >> n;

	int m = n % 10;

	if (m == 3) {
		cout << "bon" << endl;
	}
	else if (m == 0 || m == 1 || m == 6 || m == 8){
		cout << "pon " << endl;
    }
     else {
        cout << "hon" << endl;
	}
	


}

Measured memory_bytes: 3584
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
#include <limits.h>
//#include <math.h>

int main() {
  int h, n;
  scanf("%d%d", &h, &n);
  int a[n], b[n];
  for (int i=0; i<n; i++) scanf("%d%d", a+i, b+i);
  int dp[h+1];
  for (int i=0; i<h+1; i++) {
    dp[i] = INT_MAX;
  }
  for (int i=0; i<n; i++) {
    for (int j=0; j<h+1; j++) {
      if (j-a[i] <= 0) {
        if (dp[j] < b[i]) {
          continue;
        } else {
          dp[j] = b[i];
        }
      }
      else if (dp[j] < dp[j-a[i]]+b[i]) {
        continue;
      } else {
        dp[j] = dp[j-a[i]]+b[i];
      }
    }
  }
  printf("%d\n", dp[h]);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define RFOR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define PI (acos(-1.0))
#define POSARG(a) (arg((a)) > 0.0? arg((a)) : 2.0*PI + arg((a)))

using namespace std;

typedef complex<double> P;

int n, r, q, center;//center...回転の中心となる点のある添字
vector<P> vc;

P rotate_p(P a, P c, double t)
{
	a = a - c;
	
	a = P(a.real()*cos(t) - a.imag()*sin(t),
			a.real()*sin(t) + a.imag()*cos(t));
	
	return a + c;
}

vector<P> rotate_vc(vector<P> vc, P c, double t)
{
	for(int i = 0; i < (int)vc.size(); i++)
	{
		vc[i] = rotate_p(vc[i], c, t);
	}
	
	return vc;
}


void solve()
{	
	FOR(k, 0, q)
	{
		double upper = 2.0*PI, lower = 0;
		
		FOR(j, 0, 50)
		{
			double mid = (upper+lower)/2;
			vector<P> vc_r = rotate_vc(vc, vc[center], mid);
			bool out = false;
			
			FOR(i, 0, n)
			{
				if( abs(vc_r[i]) > r )
				{
					out = true;
				}
			}
			
			if(out)
			{
				upper = mid;
			}
			else
			{
				lower = mid;
			}
		}
		
		vector<P> vc_r = rotate_vc(vc, vc[center], lower);
		int newcenter = -1;
		
		FOR(i, 0, n)
		{
			if( i != center && EQ(abs(vc_r[i]), r) )
			{
				if( newcenter < 0 || 
					abs(vc_r[i] - vc[center]) > abs(vc_r[newcenter] - vc[center]) )
				{
					newcenter = i;
				}
			}
		}
		
		printf("%.12lf %.12lf\n", vc_r[newcenter].real(), vc_r[newcenter].imag());
		vc = vc_r;
		center = newcenter;
	}
	
	return;
}

int main()
{
	while(cin >> n >> r >> q, (n||r||q))
	{
		vc.clear();
		
		FOR(i, 0, n)
		{
			double x, y;
			cin >> x >> y;
			
			vc.push_back(P(x, y));
			
			if( EQ(x*x+y*y, r*r) )
				center = i;
		}
		
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1272
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    l=[(-2)**i for i in range(32)]
    S=[0]*34
    for i in range(16):
        S[i*2+2]=S[i*2]+l[i*2]
        S[i*2+3]=S[i*2+1]+l[i*2+1]
    ans=0
    while N!=0:
        for i in range(16):
            if abs(S[i*2+2+(N<0)])>=abs(N):
                ans|=1<<(i*2+(N<0))
                N-=l[i*2+(N<0)]
                break
    print(format(ans,'b'))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

lint Solve(vector<lint>& a, bool start_left){
  int left=0;
  int right=a.size()-1;
  bool should_put_left=start_left;
  vector<lint> sorted;
  if(a.size()%2==0){
    if(start_left){
      sorted.push_back(a[(a.size())/2]);
    }else{
      sorted.push_back(a[(a.size()/2-1)]);
    }
  }else{
    sorted.push_back(a[a.size()/2]);
  }

  while(sorted.size()<a.size()){
    if(should_put_left){
      sorted.push_back(a[left]);
      left++;
    }else{
      sorted.push_back(a[right]);
      right--;
    }
    should_put_left=!should_put_left;
  }
  lint result=0;
  for(int i=0;i<a.size()-1;i++){
    result+=abs(sorted[i+1]-sorted[i]);
  }
  return result;
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  vector<lint> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  std::sort(a.begin(), a.end());
  cout<<max(Solve(a,true),Solve(a,false));

  return 0;
}




Measured memory_bytes: 2916
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    int h = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    double hRad = (double) 90 - 360 * (double) h / 12 - 30 * ((double) m % 60) / 60;
    double hX = (double) a * Math.cos(Math.toRadians(hRad));
    double hY = (double) a * Math.sin(Math.toRadians(hRad));
    double mRad = (double) 90 - 360 * ((double) m % 60) / 60;
    double mX = (double) b * Math.cos(Math.toRadians(mRad));
    double mY = (double) b * Math.sin(Math.toRadians(mRad));
    double diffX = hX - mX;
    double diffY = hY - mY;
    pw.println(
      Math.sqrt(diffX * diffX + diffY * diffY)
    );
  }
}


Measured memory_bytes: 35944
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, groupby
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
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

N = INT()
B = LIST()
A = []

A.append(B[0])

for i in range(1, N-1):
  A.append(min(B[i], B[i-1]))
  
A.append(B[N-2])
print(sum(A))

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

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int n;
    cin>>n;
    string s1="AC",s2="WA",s3="TLE",s4="RE";
    map<string,int> mp;
    for (int i = 0; i < n; i++)
    {
      string s;
      cin>>s;
      mp[s]++;
    }
    cout<<s1<<" "<<"x"<<" "<<mp[s1]<<"\n";
    cout<<s2<<" "<<"x"<<" "<<mp[s2]<<"\n";
    cout<<s3<<" "<<"x"<<" "<<mp[s3]<<"\n";
    cout<<s4<<" "<<"x"<<" "<<mp[s4]<<endl;
    
    
    
 
    
   
	
	return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{

	int from,to;
};

#define SIZE 55

ll N;
ll POW[55],table[55];
vector<int> G[SIZE];

int root; //根ノードの番号
int MAX_LOG_V = 6;

int parent[7][SIZE];
int depth[SIZE];
int LCA[55][55];
Info info[25];

//parentとdepthを再帰的に設定
void dfs(int node_id,int parent_id,int d){
	parent[0][node_id] = parent_id;
	depth[node_id] = d;
	for(int i = 0; i < G[node_id].size(); i++){
		if(G[node_id][i] != parent_id)dfs(G[node_id][i],node_id,d+1);
	}
}

//初期化
void init(){
	//parent[0]とdepthを初期化する
	dfs(root,-1,0);
	//parentを初期化する
	for(int k = 0; k + 1 < MAX_LOG_V; k++){
		for(int node_id = 0; node_id < N; node_id++){
			if(parent[k][node_id] < 0)parent[k+1][node_id] = -1; //node_idの2^k上のノードがルートノードより上なら、2^(k+1)上も同様とする
			else{
				parent[k+1][node_id] = parent[k][parent[k][node_id]];
			}
		}
	}
}

//leftとrightのLCAを求める
int lca(int left,int right){
	//leftとrightの深さが同じになるまで親を辿る
	if(depth[left] > depth[right])swap(left,right); //rightの方が深い所にいる

	for(int k = MAX_LOG_V-1; k >= 0; k--){
		if(depth[right]-depth[left] >= POW[k]){ //たとえば深さの差が39なら、32+4+2+1のように、ノードを上方に移動させる
			right = parent[k][right];
		}
	}

	if(left == right)return left;

	for(int k = MAX_LOG_V-1; k >= 0; k--){
		if(parent[k][left] == parent[k][right]){
			//Do nothing
		}else{
			left = parent[k][left];
			right = parent[k][right];
		}
	}
	return parent[0][left]; //最後は、leftの親とrightの親が必ず一致している
}

ll calc(int node_id,int parent){

	ll ret = 0;

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i];
		if(child == parent)continue;

		ret += calc(child,node_id);
		if(table[child] > 0)ret++;

		table[node_id] += table[child];
	}

	return ret;
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%lld",&N);

	int from,to;
	for(int i = 0; i < N-1; i++){

		scanf("%d %d",&from,&to);
		from--;
		to--;
		G[from].push_back(to);
		G[to].push_back(from);
	}

	root = 0;
	init();

	ll ans = POW[N-1];

	ll M;
	scanf("%lld",&M);

	for(ll i = 0; i < M; i++){

		scanf("%d %d",&info[i].from,&info[i].to);
		info[i].from--;
		info[i].to--;
	}

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++){

			LCA[i][k] = lca(i,k);
		}
	}

	ll minus = 0;

	for(ll state = 1; state < POW[M]; state++){ //すくなくとも1つ条件を満たさない場合の数を計上するので、1スタート

		for(int k = 0; k < N; k++){

			table[k] = 0;
		}

		ll count = 0;
		for(ll loop = 0; loop < M; loop++){
			if(state & POW[loop]){
				count++; //この区間を条件を満たさなくするので、count:条件を満たさない個数
				table[info[loop].from]++;
				table[info[loop].to]++;
				table[LCA[info[loop].from][info[loop].to]] -= 2;
			}
		}

		ll tmp = calc(root,-1);
		tmp = (N-1)-tmp; //自由にして良い辺の数

		//printf("state:%lld tmp:%lld\n",state,tmp);

		tmp = POW[tmp];

		if(count%2 == 0){

			minus -= tmp;
		}else{

			minus += tmp;
		}
		//printf("minus:%lld\n",minus);
	}

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

	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m, l int
	fmt.Scan(&n, &m, &l)
	A := make([][]int, n)
	for i := range A {
		A[i] = make([]int, m)
	}
	B := make([][]int, m)
	for i := range B {
		B[i] = make([]int, l)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Scan(&A[i][j])
		}
	}
	for i := 0; i < m; i++ {
		for j := 0; j < l; j++ {
			fmt.Scan(&B[i][j])
		}
	}
	for i := 0; i < n; i++ {
		for j := 0; j < l; j++ {
			var sum int
			for k := 0; k < m; k++ {
				sum += A[i][k] * B[k][j]
			}
			if j != l-1 {
				fmt.Printf("%d ", sum)
			} else {
				fmt.Println(sum)
			}
		}
	}
}



Measured memory_bytes: 2488
def main():
    has_said = set()
    n = int(input())
    last = ""
    for i in range(n):
        w = input()
        if i > 0 and (w[0] != last or w in has_said):
            print("No")
            break
        last = w[-1]
        has_said.add(w)
    else:
        print("Yes")


if __name__ == '__main__':
    main()



Measured memory_bytes: 9152
N,K = map(int, input().split())
d = [0]*2*K
for i in range(K):
    d[2*i], d[2*i+1] = map(int, input().split())
a=[0]*(N+1)
b=[0]*(N+1)
a[1]=1
b[1]=1
for i in range(2,N+1):
    t=0
    for j in range(K):
        if i-d[2*j]>0:
            t+=b[i-d[2*j]]
        if i-d[2*j+1]-1>0:
            t-=b[i-d[2*j+1]-1]
    a[i]=t%998244353
    b[i]=(b[i-1]+a[i])
print(a[N])


Measured memory_bytes: 76784
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#define mp make_pair
#include <iostream>

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n, i, j, k, temp;
    string s, t;
    cin >> s >> t;
    LL len = s.length();
    LL len1 = t.length();
    if (len1 != len + 1)
    {
        cout << "No\n";
        return 0;
    }
    for (i = 0; i < len; i++)
    {
        if (s[i] != t[i])
        {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}


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

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

	const int MAXN = 20000;
	static int p[MAXN];

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

	static int a[MAXN], b[MAXN];
	for (int i = 0; i < N; i++) {
		a[i] += 30000 * (i + 1);
		b[i] += 30000 * (N - i);

		b[p[i]] += i;
	}

	for (int i = 0; i < N; i++) {
		cout << a[i] << " ";
	}
	cout << endl;

	for (int i = 0; i < N; i++) {
		cout << b[i] << " ";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 896