akhauriyash/Code-Regression huggingface dataset:
import numpy as np
n, k=map(int, input().split())
a=list(map(int, input().split()))

lst=[0]*(max(a)+1)
for i in a:
    lst[i]+=1

ruiseki=[0]*(max(a)+1)
for i,j in enumerate(lst):
    ruiseki[i] = ruiseki[i-1]+j
sm1=0
for i in a:
    sm1 += ruiseki[i-1]

ans1=(((k*(k-1))//2)%(10**9+7))*sm1

npr=np.array(ruiseki)
sm2=0
for i in a:
    sm2 += npr[i-1]
    npr[i:] -= 1

ans2=(sm2*k)%(10**9+7)
ans=(ans1+ans2)%(10**9+7)

print(ans)

Measured memory_bytes: 27340
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int a[] = new int[n];
		int max = 0;
		int min = 0;
		
		for (int i=0; i<n; i++){
			a[i] = sc.nextInt();
			
			if (i==0){
				max = a[i];
				min = a[i];
			}
			else {
				if (max < a[i]){
					max = a[i];
				}
				if (min > a[i]){
					min = a[i];
				}
			}
		}
		
		System.out.println(max-min);			
		
	}

}


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

using namespace std;

int main(){

    int n, d;
    cin >> n >> d;
    int cnt = 0;
    int mn[n][d];
    for(int i = 0; i < n; i++)
        for(int j = 0; j < d; j++)
            cin >> mn[i][j];
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            int tot = 0;
            for(int k = 0; k < d; k++)
                tot = tot + (mn[i][k] - mn[j][k])*(mn[i][k] - mn[j][k]);
            int sq = sqrt(tot);
            if( sq * sq == tot ){
                cnt++;
            }
               // cout << i << " " << j << " " << sq << " " << tot << endl;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
  int i = 0;
  int a,b,c;
  cin >> a >> b >> c;
  for(int x = a; x <= b; x++){
    if(c%x == 0){ i++; }
  }
  cout << i << endl;
  return 0;
}



Measured memory_bytes: 3108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer buffer = new StringTokenizer(br.readLine());
		
		double r =Double.parseDouble(buffer.nextToken());

		System.out.println(String.format("%.5f %.5f", Math.pow(r, 2) * Math.PI, 2 * Math.PI * r));
	}
}


Measured memory_bytes: 24852
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+9;
int n,a[N];
char *fs,*ft,buf[1<<21];
inline char gc(){return fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<21,stdin),fs==ft)?EOF:*fs++;}
inline void read(int &x){
  x=0;bool f=0;
  char c=gc();
  while(c<'0'||c>'9')f|=(c=='-'),c=gc();
  while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^'0'),c=gc();
  if(f)x=-x;
}
struct Edge{
  int v,id,nxt;
}e[N<<1];
int head[N],cnt;
inline void add(int u,int v,int id){
  e[cnt]=(Edge){v,id,head[u]};
  head[u]=cnt++;
}
int mx;
int ans[N];
void dfs(int u,int fa,int col){
  int bg=0;
  for(int i=head[u];~i;i=e[i].nxt){
    Edge e1=e[i];
    if(e1.v==fa)continue;
    bg++;if(bg==col)bg++;
    ans[e1.id]=bg;
    dfs(e1.v,u,bg);
  }
  mx=max(mx,bg);
}
int main(){
//  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
  read(n); 
  for(int i=1;i<=n;i++)head[i]=-1;
  for(int i=1,u,v;i<n;i++){
    read(u),read(v);
    add(u,v,i),add(v,u,i);
  }
  dfs(1,0,0);
  cout<<mx<<endl;
  for(int i=1;i<n;i++)cout<<ans[i]<<endl;   
  return 0;
}


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

#define INF 1e+9

struct Edge{
	  int s,t,w;
	  Edge(int si, int ti, int wi){
			s = si; t = ti; w = wi;
	  }
	  bool operator > (const Edge& e) const {
			return w > e.w;
	  }

};
typedef vector<vector<Edge> > AdjList;

struct state{
	  int v, w;
	  state(int vi, int wi){ v = vi; w = wi; }
	  bool operator > (const state& tgt) const {
			return w > tgt.w;
	  }
};

vector<int> dijk(int s, AdjList& G){
	  priority_queue<state,vector<state>, greater<state> > q;
	  vector<int> used(G.size(),INF);

	  q.push( state(s,0) );
	  while( q.size() ) {
			state corr = q.top(); q.pop();
			if(used[corr.v] != INF) continue;
			
			used[corr.v] = corr.w;
			// if(used[t] != -1) break;
			
			for(Edge e : G[corr.v])
				  if(used[e.t] == INF)
						q.push( state(e.t, corr.w + e.w) );
	  }
	  return used;
}

int main(){

	  int V,E,r; cin >> V >> E >> r;
	  
	  AdjList G(V);
	  for(int i=0; i<E; i++){
			int s,t,d; cin >> s >> t >> d;
			G[s].push_back(Edge(s,t,d));
	  }
	  vector<int> stlen = dijk(r,G);
	  for(int i=0; i<V; i++)
			if(stlen[i] != INF)
				  cout << stlen[i] << endl;
			else
				  cout << "INF" << endl;
			

}

Measured memory_bytes: 16388
use std::collections::BinaryHeap;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let m: usize = sc.read();
    let l: i64 = sc.read();

    let mut graph = vec![vec![]; n];
    for _ in 0..m {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        let c: i64 = sc.read();
        graph[a].push((b, c));
        graph[b].push((a, c));
    }

    let mut ans = vec![];
    for i in 0..n {
        ans.push(dijkstra(i, &graph, l));
    }

    let q: usize = sc.read();
    for _ in 0..q {
        let from = sc.read::<usize>() - 1;
        let to = sc.read::<usize>() - 1;
        let ans = ans[from][to];
        if ans == n as i64 {
            println!("-1");
        } else {
            println!("{}", ans);
        }
    }
}

fn dijkstra(start: usize, graph: &Vec<Vec<(usize, i64)>>, l: i64) -> Vec<i64> {
    let n = graph.len();
    let mut dist: Vec<(i64, i64)> = vec![(n as i64, l); n];
    dist[start] = (0, 0);
    let mut heap = BinaryHeap::new();
    heap.push((0, 0, start));

    while let Some((_, _, v)) = heap.pop() {
        let (cur_count, cur_cost) = dist[v];
        for &(next, cost) in graph[v].iter() {
            let next_cost = cur_cost + cost;
            if next_cost <= l {
                if dist[next] > (cur_count, next_cost) {
                    dist[next] = (cur_count, next_cost);
                    heap.push((-cur_count, -next_cost, next));
                }
            } else if cost <= l {
                let next_count = cur_count + 1;
                let next_cost = cost;
                if dist[next] > (next_count, next_cost) {
                    dist[next] = (next_count, next_cost);
                    heap.push((-next_count, -next_cost, next));
                }
            }
        }
    }
    dist.into_iter().map(|(count, _)| count).collect()
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main(void){
	char s[200];
  	int k;
  	int i;
  
  	scanf("%d %s",&k, s);
  	
  	if(strlen(s) <= k){
      printf("%s\n",s);
    }else{
      for(i = 0; i < k; i++){
        printf("%c",s[i]);
      }
      printf("...\n");
    }
  
  return 0;
}
          
  
  	

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

int n, m;

vector<vector<int>> g; // 各頂点から辺で結ばれる頂点の集合を記録
vector<int> indeg; // 各頂点の入次数を記録
vector<bool> sorted; // 各頂点についてソート済みか否かを判定
vector<int> t; // ソート結果を記録

void bfs(int start) {
    queue<int> q;
    q.push(start);
    while (not q.empty()) {
        int cur = q.front();
        q.pop();
        t.push_back(cur);
        sorted[cur] = true;
        for (int adj : g[cur]) {
            indeg[adj]--;
            if (sorted[adj] == false && indeg[adj] == 0) {
                q.push(adj);
            }
        }
    }
}

void topological_sort() {
    rep(i, n) {
        if (sorted[i] == false && indeg[i] == 0) {
            bfs(i);
        }
    }
    rep(i, n) {
        cout << t[i] << endl;
    }
}

int main() {
    cin >> n;
    cin >> m;
    g.resize(n);
    indeg.resize(n);
    sorted.resize(n, false);
    rep(i, m) {
        int s, t;
        cin >> s;
        cin >> t;
        g[s].push_back(t); // 頂点sは頂点tに対して辺をもつ
        indeg[t]++; // tの入次数を1増やす
    }
    topological_sort();
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for((i)=1;(i)<=(n);(i)++) 
using namespace std;
int n,m,i;
vector<int> f[7],t;
vector<int> mul(vector<int> a,vector<int> b){
	vector<int> ans;ans.resize(n+1);
	int i;rep(i,n) ans[i]=a[b[i]];
	return ans;
}
vector<int> inv(vector<int> a){
	vector<int> ans;ans.resize(n+1);
	int i;rep(i,n) ans[a[i]]=i;
	return ans;
}
vector<int> pw(vector<int> x,int y)
{
	vector<int> ans;
	int i;rep(i,n+1) ans.push_back(i-1);
//	return ans;
	while(y){
		if(y&1)ans=mul(ans,x);
		x=mul(x,x);
		y>>=1;
	}
	return ans;
}
int main(){
	cin>>n>>m;
	f[1].resize(n+1);
	f[2].resize(n+1);
	rep(i,n)cin>>f[1][i];
	rep(i,n)cin>>f[2][i];
	for(i=3;i<=6;i++){
		f[i]=mul(f[i-1],inv(f[i-2]));
	}
	t=mul(mul(f[2],inv(f[1])),mul(inv(f[2]),f[1]));
//	rep(i,n)cout<<t[i]<<' ';cout<<endl;
	t=pw(t,(m-1)/6);
//	rep(i,n)cout<<t[i]<<' ';cout<<endl;
//	rep(i,n)cout<<f[(m-1)%6+1][i]<<' ';cout<<endl;
	t=mul(mul(t,f[(m-1)%6+1]),inv(t));
	rep(i,n)cout<<t[i]<<' ';cout<<endl;
	return 0;
}

Measured memory_bytes: 9004
allSame xs = all (uncurry (==)) $ zip xs $ tail xs

edist' :: String -> Int
edist' (x:x':xs)
	| x == x'   = 1 + edist' xs
	| otherwise = edist' (x':xs)
edist' _ = 0

edist xs k
	| allSame xs = (k * length xs) `div` 2
	| otherwise  = k * d + (k - 1) * m
		where
			dist = edist' (xs ++ xs)
			d = dist `div` 2
			m = dist `mod` 2

main :: IO ()
main = do
	xs <- getLine
	k <- readLn
	print $ edist xs k


Measured memory_bytes: 508
import java.util.*
import java.math.*
fun main(args: Array<String>) {

    var (N, M) = readLine()!!.split(" ").map { it.toInt() }
//    var N = readLine()!!.toInt()
//    val D = readLine()!!.split(" ").map { it.toLong() }
//    val A = readLine()!!.split(" ").map { it.toInt() }.toIntArray()

    val mod = 1000000007L

    val L = mutableListOf<Int>()
    val R = mutableListOf<Int>()
    for (n in 1..M) {
        var (l, r) = readLine()!!.split(" ").map { it.toInt() }
        L.add(l)
        R.add(r)
    }
    var ans = R.min()!! - L.max()!! + 1
    if (ans < 0) ans = 0
    println(ans)
//    println("%.9f".format(ans))
}


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

int selectsort(int n,int a[]){
	int sw=0,minj;
	for(int i=0;i<n;i++){
		minj=i;
		for(int j=i;j<n;j++){
			if(a[minj]>a[j]){
				minj=j;
			}
		}
		swap(a[minj],a[i]);
		if(i != minj) sw++;
	}
	return sw;
}


int main(){
	int n,a[100];
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	int sw=selectsort(n,a);
	for(int i=0;i<n;i++){
		if(i) printf(" ");
		printf("%d",a[i]);
	}
	printf("\n");
	printf("%d\n",sw);
	return 0;
}


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

using namespace std;

int main(){

	int n;

	while(cin>>n){
		if(n==0)break;

		vector<int> *v;
		v = new vector<int>[n];

		int m;
		for(int i=0;i<n;i++){
			cin>>m;
			for(int j=0;j<m;j++){
				int tmp;
				cin>>tmp;
				v[i].push_back(tmp);
			}
		}
		int *l;
		int *flag;
		int k;
		cin>>k;
		l = new int[k];
		flag = new int[k];

		for(int i=0;i<k;i++)cin>>l[i];

		int num=-1;
		for(int i=0;i<n;i++){
			for(int m=0;m<k;m++){
				flag[m] = 0;
			}
			for(int m=0;m<k;m++){
				for(int j=0;j<v[i].size();j++){
					if(l[m] == v[i].at(j)){
						flag[m]=1;
						break;
					}
				}
			}
			int state=0;
			for(int m=0;m<k;m++){
				if(flag[m]==0)state=1;
			}
			if(state==0){
				if(num==-1){
					num=i+1;
				}
				else{
					num=100000;
				}
			}
		}

		if(num==100000)cout<<-1<<endl;
		else{cout<<num<<endl;}

	}
	return 0;
}

Measured memory_bytes: 1940
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (h, w, _n) = i.read3::<usize, usize, usize>();
    let (y, x) = i.read2::<usize, usize>();
    let s: Vec<_> = i.read_line().as_bytes().iter().cloned().collect();
    let t: Vec<_> = i.read_line().as_bytes().iter().cloned().collect();

    let ans = if solve(y - 1, x - 1, h, w, &s, &t) {
        "YES"
    } else {
        "NO"
    };
    writeln!(o, "{}", ans).unwrap();
}
fn solve(y: usize, x: usize, h: usize, w: usize, s: &[u8], t: &[u8]) -> bool {
    let mut rx0 = 0;
    let mut rx1 = 0;
    let mut ry0 = 0;
    let mut ry1 = 0;
    for (&s, &t) in s.iter().zip(t).rev() {
        if rx0 + rx1 == w {
            return false;
        }
        if ry0 + ry1 == h {
            return false;
        }
        match t {
            b'L' => {
                if rx1 > 0 {
                    rx1 -= 1;
                }
            }
            b'R' => {
                if rx0 > 0 {
                    rx0 -= 1;
                }
            }
            b'U' => {
                if ry1 > 0 {
                    ry1 -= 1;
                }
            }
            b'D' => {
                if ry0 > 0 {
                    ry0 -= 1;
                }
            }
            _ => unreachable!(),
        }
        match s {
            b'L' => rx0 += 1,
            b'R' => rx1 += 1,
            b'U' => ry0 += 1,
            b'D' => ry1 += 1,
            _ => unreachable!(),
        }
    }
    !(rx0 >= x + 1 || ry0 >= y + 1 || rx1 >= w - x || ry1 >= h - y)
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef long long ll;

int main(){
    ll n, m1, m2, ans = 2;

    scanf("%lld", &n);
    if (n == 2){
        printf("1");
        return 0;
    }

    for (ll k = 2; k < sqrt(n) + 1; k++){
        m1 = n;
        m2 = n;
        if (k * k == n - 1) ans++;
        else if ((n - 1) % k == 0) ans += 2;
        if (k * k == n) ans++;
        else if (n % k == 0){
            while (m1 % k == 0) m1 /= k;
            while (m2 % (n / k) == 0) m2 /= n / k;
            if (m1 % k == 1) ans++;
            if (m2 % k == 1) ans++;
        }
    }
    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SC second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll cnt = 0;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}


int main()
{
  int n ;
  cin >> n ;
  vector<int> poi(n+2) ;
  poi.at(0) = 0 ;
  poi.at(n+1) = 0 ;
  int sum = 0 ;
  int x ;
  
  REP(i,n){
    cin >> poi.at(i+1) ;
  }
  
  REP(i,n+1){
    sum += abs(poi.at(i+1)-poi.at(i)) ;
  }
  
  FOR(i,1,n+1){
  if((poi.at(i)-poi.at(i-1))*(poi.at(i+1)-poi.at(i))>=0){
    x = 0 ;
  }
  else{
    if((poi.at(i+1)-poi.at(i-1))*(poi.at(i-1)-poi.at(i))>=0){
      x = 2*(abs(poi.at(i)-poi.at(i-1))) ;
    }
    else{
        x = 2*(abs(poi.at(i+1)-poi.at(i))) ;
      }
  }
    
  
  cout << sum-x <<endl ;
  }

  return 0 ;
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int uc = 0;
vector<vector<int>> grid, gridps, res;

int query(int i1, int j1, int i2, int j2) {
  return gridps[i2][j2]
    - (i1 ? gridps[i1 - 1][j2] : 0)
    - (j1 ? gridps[i2][j1 - 1] : 0)
    + (i1 && j1 ? gridps[i1 - 1][j1 - 1] : 0);
}

void solve(int i1, int j1, int i2, int j2) {
  if (query(i1, j1, i2, j2) == 1) {
    ++uc;
    rep(i, i1, i2 + 1) rep(j, j1, j2 + 1)
      res[i][j] = uc;
    return;
  }

  rep(i, i1, i2) {
    if (query(i1, j1, i, j2) && query(i + 1, j1, i2, j2)) {
      solve(i1, j1, i, j2);
      solve(i + 1, j1, i2, j2);
      return;
    }
  }

  rep(j, j1, j2) {
    if (query(i1, j1, i2, j) && query(i1, j + 1, i2, j2)) {
      solve(i1, j1, i2, j);
      solve(i1, j + 1, i2, j2);
      return;
    }
  }
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int h, w, cnt; read(h, w, cnt);
  vector<string> mp(h);
  grid = vector<vector<int>>(h, vector<int>(w, 0));
  gridps = vector<vector<int>>(h, vector<int>(w, 0));
  res = vector<vector<int>>(h, vector<int>(w, 0));
  rep(i, 0, h) {
    read(mp[i]);
    rep(j, 0, w) {
      grid[i][j] = mp[i][j] == '#' ? 1 : 0;
    }
  }
  rep(i, 0, h)
    rep(j, 0, w) {
      gridps[i][j] = 
        grid[i][j]
        + (i ? gridps[i - 1][j] : 0)
        + (j ? gridps[i][j - 1] : 0)
        - (i && j ? gridps[i - 1][j - 1] : 0);
    }
  solve(0, 0, h - 1, w - 1);
  rep(i, 0, h) {
    rep(j, 0, w) cout << res[i][j] << " ";
    cout << endl;
  }
}


Measured memory_bytes: 4804
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    
    ans = 10 ** 9
    for i in range(A[0], A[-1]+1):
        c = 0
        for a in A:
            c += (abs(a-i)) ** 2
        ans = min(ans, c)
        
    return ans

print(solve())

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int n,a[100000],L;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    L=a[0];
    for(int i=1;i<n;i++){
        L=a[i]-L;
    }
    for(int i=0;i<n;i++){
        cout<<L<<endl;
        L=(a[i]-L/2)*2;
    }
}


Measured memory_bytes: 1664
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    private static void exchange(int[] cookies, int turn) {
        int c = (cookies[turn] >> 1);
        cookies[turn] = c;
        cookies[turn ^ 1] += c;
    }

    public static void main(String[] args) {
        try (
                Scanner in = new Scanner(System.in);
                PrintWriter out = new PrintWriter(System.out))
        {
            final int[] AB = new int[2];
            AB[0] = in.nextInt();
            AB[1] = in.nextInt();
            final int K = in.nextInt();

            int turn = 0;
            for (int k = 0; k < K; ++k) {
                exchange(AB, turn);
                turn ^= 1;
            }

            out.printf("%d %d%n", AB[0], AB[1]);
        }
    }
}


Measured memory_bytes: 23124
A,B=map(int,input().split())
ans = 0
for i in range(A,B+1):
  i1 = i % 10
  i2 = (i // 10) % 10
  i4 = (i // 1000) % 10
  i5 = (i // 10000) % 10
  if (i1 == i5) and (i2 == i4):
    ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
typedef long long ll;
//
int main(){
   string s;
   cin>>s;
   bool ans=false;
   int num=-1,numa=-1;
   vector<char> v;
   for(auto e:s){
      v.push_back(e);
   }
   if(v.size()==1) {
      cout<<-1<<' '<<-1<<endl;
      return 0;
   }
   rep(i,v.size()-1){
      if(v[i]==v[i+1]){
         num=i;
         ans=true;
         break;
      }
   }
   if(v.size()>2){
   rep(i,v.size()-2){
      if(v[i]==v[i+2]){
         numa=i;
         ans=true;
         break;    
      }
   }
   }
   if(ans&&num>=0) cout<<num+1<<' '<<num+2<<endl;
   else if(ans&&numa>=0) cout<<numa+1<<' '<<numa+3<<endl;
   else cout<<-1<<' '<<-1<<endl;
}

Measured memory_bytes: 3772
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;

int mod=1e9+7;
ll gcd(ll a,ll b)
{
  if(a>b)swap(a,b);
  if(a==0){return b;}
  else return gcd(b%a,a);
}
map<ll,ll>prime_factor(ll m)
{
  map<ll,ll>res;
  ll sqrm=sqrt(m)+1;
  for(int i=2;i<sqrm+1;i++)
  {
    while(m%i==0){res[i]++;m/=i;}
    if(m==1)break;
  }
  if(m>1)res[m]++;
  return res;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;
  cin>>a>>b;
  ll  g=gcd(a,b);
  auto ma=prime_factor(g);
  cout<<ma.size()+1<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vvi vector<vector<int>>
using namespace std;

int main() {
    int n, q; cin >> n >> q;
    int time = 0;
    queue<pair<string, int>> que;

    rep(i, n) {
        string s;
        int ti;
        cin >> s >> ti;
        pair<string, int> p = make_pair(s, ti);
        que.push(p);
    }

    while (!que.empty()) {
        pair<string, int> p = que.front(); que.pop();

        if (p.second > q) {
            p.second -= q;
            que.push(p);
            time += q;
        }
        else {
            time += p.second;
            cout << p.first << " " << time << endl;
        }
    }
}


Measured memory_bytes: 6312
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define PI 3.1415926535
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define eps 0.000000000001
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
int main(){
	int a,b,h,m;cin>>a>>b>>h>>m;
	double dh=1.0000000000*h/12.0000000000*360+1.00000000000*m/720.0000000000*360;
	double dm=1.0000000000*m/60.0000000000*360;
	double dis=min(fabs(dh-dm),min(fabs(dh+(360-dm)),fabs(dm+(360-dh))));
	if(fabs(dis-0.0000000000)<=eps){
		double ans=fabs(a-b);
		printf("%.10lf\n",ans);
		return 0;
	}
	if(fabs(dis-180.0000000000)<=eps){
		double ans=fabs(a+b);
		printf("%.10lf\n",ans);
		return 0;
	}	
	double ans;
	if(fabs(dis-90.0000000000)<=eps){
		ans=sqrt(a*a+b*b);
		printf("%.10lf\n",ans);
	}else if(dis>eps+90.0000000000){
		double l=1.0000000000*a*sin(dis*PI/180.0);
		double r=1.0000000000*a*(-cos(dis*PI/180.0))+b;
		ans=sqrt(l*l+r*r);
		printf("%.10lf\n",ans);
	}else if(dis<90.0000000000-eps){
		double l=1.0000000000*a*sin(dis*PI/180.0);
		double r=1.0000000000*b-a*cos(dis*PI/180.0);
		ans=sqrt(l*l+r*r);
		printf("%.10lf\n",ans);		
	}
}


Measured memory_bytes: 4064
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
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-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
const int DX[8]={-1,0,1,0,-1,-1,1,1},DY[8]={0,-1,0,1,-1,1,-1,1};


int main(){;
	while(1){
		int n,m,x;
		cin>>n>>m>>x;
		if(n==0) break;
		vi a(n-1);
		for(int i=0;i<n;i++){
			int y;
			cin>>y;
			if(y>=x){
				if(i<n-1) a[i]++;
				if(i+m<n-1) a[i+m]--;
			}
		}
		int res=0;
		for(int i=1;i<n-1;i++) a[i]+=a[i-1];
		for(auto i:a) if(i) res++;
		cout<<res<<endl;
	}
}


Measured memory_bytes: 3492
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
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 main() {
  int K, S;
  cin >> K >> S;

  int ans = 0;
  for (int X = 0; X < (int)(K + 1); ++X) for (int Y = 0; Y < (int)(K + 1); ++Y) {
    int Z = S - X - Y;
    if (0 <= Z && Z <= K) ++ans;
  }

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


Measured memory_bytes: 256
#include <stdio.h>
#define N 8
#define Free -1
#define NotFree 1
#define False -2
#define True 2
int row[N];
int col[N];
int dpos[2*N-1];
int dneg[2*N-1];
int k;
int X[N][N];
void init(){
        int i;
        for(i=0; i<N; i++) {
                row[i]=Free;
                col[i]=Free;
        }
        for(i=0; i<2*N-1; i++) {
                dpos[i]=Free;
                dneg[i]=Free;
        }
}
void PrintQ(){
        int i,j;
        for(i=0; i<N; i++) {
                for(j=0; j<N; j++) {
                  if(X[i][j]==True){
                    if(row[i] != j){
                      return;
                    }
                  }
                }
        }
        for(i=0; i<N; i++) {
                for(j=0; j<N; j++) {
                        if(row[i]==j) {
                                printf("Q");
                        }
                        else{
                                printf(".");
                        }
                }
                printf("\n");
        }
}
void Rescusive(int i){
        int j;
        if(i==N) {
                PrintQ();
                return;
        }
        for(j=0; j<N; j++) {
                if(col[j]==NotFree||dpos[i+j]==NotFree||dneg[i-j+N-1]==NotFree) {
                        continue;
                }
                row[i]=j;
                col[j]=dpos[i+j]=dneg[i-j+N-1]=NotFree;
                Rescusive(i+1);
                col[j]=dpos[i+j]=dneg[i-j+N-1]=Free;

        }
}
int main(){
  init();
        int i,j,k,r,c;
        for(i=0; i<N; i++) {
                for(j=0; j<N; j++) {
                        X[i][j]=False;
                }
        }
        scanf("%d",&k);
        for(i=0; i<k; i++) {
                scanf("%d%d",&r,&c);
                X[r][c]=True;
        }
        Rescusive(0);

        return 0;
}

Measured memory_bytes: 572
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


#define _x first
#define _y second;

int diff(pii p1, pii p2) {
    return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

int main(void) {
    int num;
    cin >> num;
    int tcur = 0;
    pii curp = make_pair(0, 0);
    bool flag = true;
    for(int i = 0; i < num; i++) {
        pii nextp;
        int tnext;
        cin >> tnext >> nextp._x >> nextp._y;
        int dist = diff(curp, nextp);
        debug("time: %d -> dist: %d\n", tnext-tcur, dist);
        if(tnext - tcur < dist) flag = false;
        if(((tnext - tcur)-dist)%2 == 1) flag = false;
        curp = nextp;
        tcur = tnext;
    }
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

const int MAXX = 310000;
bool isPrime[MAXX];
vector<int> primes;

int pro(int i){
    if(i%7==1) return 5;
    else return 2;
}
void sieve(){
    for(int i=2;i<MAXX;i++){
        if(i%7 != 1 and i%7!=6) continue;
        isPrime[i] = true;
    }
    for(int i=6;i<MAXX;i+=pro(i)){
        if(!isPrime[i]) continue;
        for(int j=2*i;j<MAXX;j+=i){
            isPrime[j] = false;
        }
    }
    rep(i,MAXX){
        if(isPrime[i]) primes.push_back(i);
    }
}

int main(){
    sieve();
    while(true){
        vector<int> div;
        int n;
        cin >> n;
        if(n==1) break;

        for(int i=2;i<=n;i++){
            if(isPrime[i] and n % i == 0){
                div.push_back(i);
            }
        }

        cout << n << ":";
        tr(it,div){
            cout << " " << (*it);
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1652
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(all(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int m = in();
  ll digit = 0;
  ll sum = 0;
  rep(i,m) {
    ll d, c;
    cin >> d >> c;
    digit += c;
    sum += d*c;
  }
  ll ans = (digit-1) + (sum-1)/9;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef unsigned long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;
const int MOD=1000000007;

int N,A,B;
int v[51];
int pascal[51][51];

void comb_table(int N){
	for(int i=0;i<=N;i++){
		for(int j=0;j<=i;j++){
			if(j==0||j==i){
				pascal[i][j]=1;
			}
			else{
				pascal[i][j]=pascal[i-1][j-1]+pascal[i-1][j];
			}
		}
	}
}


signed main(){
	cin>>N>>A>>B;
	REP(i,N){
		cin>>v[i];
	}
	sort(v,v+N,greater<>());
	comb_table(50);
	if(v[0]==v[A-1]){
		printf("%.8f\n",(double)v[0]);
		int cnt=0;
		int ans=0;
		REP(i,N){
			if(v[0]==v[i]){
				cnt++;
			}
		}
		for(int i=A;i<=B;i++){
			ans+=pascal[cnt][i];
		}
		cout<<ans<<endl;
	}
	else{
		int e=v[A-1];
		double ave=0;
		REP(i,A){
			ave+=v[i];
		}
		printf("%.8f\n",ave/A);
		int r=0;
		REP(i,A){
			if(v[i]==e){
				r++;
			}
		}
		int n=0;
		REP(i,N){
			if(v[i]==e){
				n++;
			}
		}
		DEB(n)END
		cout<<pascal[n][r]<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

void solve() {
    cini(n);
    cinai(l,n);
    sort(all(l));

    int ans=0;
    for(int i=0; i<n; i++) {
        for(int j=i+1; j<n; j++) {
            if(l[i]==l[j])
                continue;

            for(int k=j+1; k<n; k++) {
                if(l[j]==l[k])
                    continue;

                if(l[i]+l[j]>l[k])
                    ans++;
            }
        }
    }
    cout<<ans<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 3584
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
#include <time.h>  
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9) << flush;
//memset(a, 0, sizeof(a));
//--------------------------

ll a, b, c, x, y;

int main()
{
	cin >> a >> b >> c >> x >> y;

	ll ans = a * x + b * y;
	ll lim = max(x, y);

	for (ll i = 0;i <= 2 * lim;i++) {
		ll tmp = i * c;
		if (x - i / 2 > 0) {
			tmp += (x - i / 2) * a;
		}
		if (y - i / 2 > 0) {
			tmp += (y - i / 2) * b;
		}
		ans = min(ans, tmp);
	}

	cout << ans << endl;

	return 0;
}


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

int N, id;
string s[1000];
char c[1000];
int depth[1000];

int f(int d){
    if(isdigit(c[id])){
        int ret = c[id] - '0';
        id++;
        return ret;
    }
    if(c[id] == '+'){
        id++;
        int ret = 0;
        while(id < N && depth[id] == d + 1){
            ret += f(d + 1);
        }
        return ret;
    }

    // *
    id++;
    int ret = 1;
    while(id < N && depth[id] == d + 1){
          ret *= f(d + 1);
    }
    return ret;
}

int main(){
    while(cin >> N, N){
        for(int i = 0; i < N; i++) {
            cin >> s[i];
            depth[i] = s[i].size() - 1;
            c[i] = s[i].back();
            //cerr << depth[i] << " " << c[i] << endl;
        }
        id = 0;
        cout << f(0) << endl;
    }

}

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

#define rep(i, n) for(int i = 0; i < n; i++)
int main()
{
	map <string, int> mp;
	int n, m;
	string s = "";
	cin >> n;
	rep(i, n) {
		cin >> s;
		if (mp.find(s) == mp.end())  mp[s] = 1;
		else  mp[s]++;
	}
	cin >> m;
	rep(i, m) {
		cin >> s;
		if (mp.find(s) == mp.end())  mp[s] = -1;
		else  mp[s]--;
	}

	int ans = 0;
	for (auto v : mp)  ans = max(ans, v.second);
	cout << ans << endl;
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

signed main() {
	i64 N;
	cin >> N;
	vector<string> S(N);
	cin >> S;
  queue<i64> que;
  que.push(0);
  vector<bool> used(N, false);
  used[0] = 1;
  vector<i64> parity(N, -1);
  parity[0] = 0;
  while (que.size()) {
    i64 i = que.front();
    que.pop();
    REP(j, N) {
      if (S[i][j] == '1') {
        if (used[j]) {
          if (parity[i] == parity[j]) {
            cout << -1 << endl;
            return 0;
          }
        } else {
          que.push(j);
          used[j] = true;
          parity[j] = 1 - parity[i];
        }
      }
    }
  }
	vector<vector<i64>> d(N, vector<i64>(N));
	REP(i, N) REP(j, N) {
		d[i][j] = i == j ? 0 : S[i][j] == '1' ? 1 : inf<i64>;
	}
	REP(k, N) REP(i, N) REP(j, N) {
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	}
	i64 ans = 0;
	REP(i, N) REP(j, N) {
		if (d[i][j] < inf<i64>)
			ans = max(ans, d[i][j]);
	}
	cout << ans + 1 << endl;
}


Measured memory_bytes: 640
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

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

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

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    int64 x;
    cin >> x;

    int64 a = 100;
    rep(i, 1000000) {
        if (a >= x) {
            print(i);
            return 0;
        }
        a += a / 100;
    }


    return 0;
}



Measured memory_bytes: 3648
import sys
sys.setrecursionlimit(30000)

out_ = [0 for i in range(20000)]

def out(n):
    if n == 1:
        out_[n-1] = 0
        return out_[n-1]
    elif n % 5**6 == 0:
        out_[n-1] = 6 + out(n-1)
        return out_[n-1]
    elif n % 5**5 == 0:
        out_[n-1] = 5 + out(n-1)
        return out_[n-1]
    elif n % 5**4 == 0:
        out_[n-1] = 4 + out(n-1)
        return out_[n-1]
    elif n % 5**3 == 0:
        out_[n-1] = 3 + out(n-1)
        return out_[n-1]
    elif n % 5**2 == 0:
        out_[n-1] = 2 + out(n-1)
        return out_[n-1]
    elif n % 5**1 == 0:
        out_[n-1] = 1 + out(n-1)
        return out_[n-1]
    else:
        out_[n-1] = out(n-1)
        return out_[n-1]

out(20000)
    
while(1):
    n = int(input())
    if n == 0:
        break
    print(out_[n-1])



Measured memory_bytes: 24772
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int i,n,cnt=1,r,p1=1,q1=1;
	vector<int> vec,p,q;
	cin>>n;
	for(i=1; i<=n; i++)
	{
	  vec.push_back(i);
	}

    for(i=1; i<=n; i++)
    {
      cin>>r;
      p.push_back(r);
    }
    
    for(i=1; i<=n; i++)
    {
      cin>>r;
      q.push_back(r);
    }
    while(next_permutation(vec.begin(),vec.end()))
    {
    	cnt++;
    	if(vec==p)
    	{
    		p1=cnt;
    		//cout<<"p"<<" "<<cnt<<endl;
    	}

    	if(vec==q)
    	{
    		q1=cnt;
    		//cout<<"q"<<" "<<cnt<<endl;
    	}
    }
    cout<<fabs(p1-q1)<<endl;

    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ITP1_9-A
//
//  Created by Saicj on 2015/08/03.
//  Copyright (c) 2015??´ saicj. All rights reserved.
//

#include <iostream>
#include <sstream> 
#include <string>
#include <vector>
#include <ctype.h>
#include <algorithm>
#include <cctype>
#include <cstdio>

using namespace std;

char ToUpper (char cX) { return toupper(cX); }

int main(int argc, const char * argv[]) {

    
    string W;
    cin >> W;
    
    transform(W.begin(), W.end(), W.begin(), ToUpper);
    
    
    string T;
    
    int index = 0;
    
    while (true) {
    
        cin >> T;
        
        if (T == "END_OF_TEXT") {
            break;
        }
        
         transform(T.begin(), T.end(), T.begin(), ToUpper);
        
        if (T == W){
            index++;
        }
    
        
    }
    
    cout << index << endl;

    
    return 0;
}

Measured memory_bytes: 1192