akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int[] nums = sc.IntArray();

        int answer = nums.Sum() - nums.Max();

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n;
  string s;
  cin >> n >> s;
  int maxx = 0;
  int now =0;
  rep(i,0,s.size()){
    if(s[i]=='I') now++;
    if(s[i]=='D') now--;
    maxx = max(maxx,now);
  }
  cout << maxx << endl;
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split(" ", n).map(&:to_i)

if a.select{|x| x % 2 == 0 }.find{|x| x % 3 != 0 && x % 5 != 0}
  print "DENIED\n"
else
  print "APPROVED\n"
end

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if((a * b) % 2 != 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;


int main(){
  
  int h,w; cin >> h >> w;

   rep(i,h){
     string s; cin >> s;
     cout << s << endl;
     cout << s << endl;
   }
    
    return 0;   
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	ll A[100001];
	ll Asum[100001]={};
	scan(N);
	rep(i,N){
		scan(A[i]);
	}
	sort(A,A+N);
	rep(i,N){
		Asum[i+1]=Asum[i]+A[i];
	}
	for(int i=N-1;i>0;i--){
		if(upper_bound(A,A+N,Asum[i]*2)-A==i){
			prin(N-i);
			return 0;
		}
	}
	prin(N);
	return 0;
}


Measured memory_bytes: 1792
import java.util.*;

class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        System.out.println(a * b / 2);
        scan.close();
    }
    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 26964
K = int(input())

if K <= 9:
    print(K)
    exit()

memo = [[1]*10] + [[1]*10 for _ in range(9)]

n = 9
digit = 1
i = -1
ans = []
while True:
    i += 1
    if i == 10:
        i = 0
        digit += 1
    tmp = memo[digit-1][i]
    if i >= 1:
        tmp += memo[digit-1][i-1]
    if i <= 8:
        tmp += memo[digit-1][i+1]
    memo[digit][i] = tmp
    if i != 0:
        if n + tmp >= K:
            while digit >= 0:
                t = memo[digit][i]
                #if n + t == K:
                #    ans.append(i)
                #    for d in range(digit):
                #        ans.append(min(9, i+d))
                #    break
                if n + t >=  K:
                    ans.append(i)
                    digit -= 1
                    i = max(0, i-1)
                else:
                    n += t
                    i += 1
            break
        else:
            n += tmp

print(''.join(map(str, ans)))

Measured memory_bytes: 3064
N=int(input())
H=list(map(int,input().split()))

for i in range(len(H)-1,0,-1):
  if H[i]==H[i-1]-1:
    H[i-1]-=1
  elif H[i]<H[i-1]-1:
    print("No")
    break
else:
  print("Yes")
  

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
const ll inf = 1001001001;
const ll mod = 1000000007;
 
int main() {
    int h1, s1, h2, s2, k;
    cin >> h1 >> s1 >> h2 >> s2 >> k;
    cout << h2*60+s2-h1*60-s1-k << endl;
}

Measured memory_bytes: 3636
N = int(input())

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

ans = 'APPROVED'

for i in range(N):
    if A[i] % 2 != 0:
        continue
    else:
        if A[i] % 3 == 0 or A[i] % 5 == 0:
            continue
        else:
            ans = 'DENIED'

print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<limits>
#include<algorithm>
using namespace std;
long long INF = numeric_limits<long long>::max();
int main(){
  int n,k;
  cin>>n>>k;
  long long arr[n+1];
  for(int i=1; i<=n; i++) cin>>arr[i];
  long long mindist = INF;
  int p1 = 1;
  int p2 = k;
  while(p2<=n){
    if(arr[p2]<=0) mindist = min(mindist,arr[p1]*-1);
    else if(arr[p1]>=0) mindist = min(mindist,arr[p2]);
    else{
      mindist = min(mindist,arr[p2]-arr[p1]-arr[p1]);
      mindist = min(mindist,arr[p2]-arr[p1]+arr[p2]);
    }
    p1++;
    p2++;
  }
  cout<<mindist;
}

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



int main() {
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	int n;
	string s;
	set<string> t;
	cin >> n;
	while (n--) {
		cin >> s;
		t.insert(s);
	}
	cout << t.size() << '\n';
	return 0;
}

Measured memory_bytes: 19228
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL K, X, Y;
	in >> K >> X >> Y;

	bool flag_x = false, flag_y = false, flag_swap = false;
	if (X < 0)
	{
		X *= -1;
		flag_x = true;
	}
	if (Y < 0)
	{
		Y *= -1;
		flag_y = true;
	}
	if (X < Y)
	{
		std::swap(X, Y);
		flag_swap = true;
	}
	if ((X + Y) % 2 == 1 && K % 2 == 0)
	{
		out << -1 << std::endl;
		return 0;
	}

	std::vector<std::pair<LL, LL>>ans;
	LL n = std::max<LL>((X + Y + K - 1) / K, 2);
	if ((X + Y) % 2 != n * K % 2) ++n;
	if (X + Y == K) ans.push_back(std::make_pair(X, Y));
	else if (n == 3 && X < K)
	{
		LL mid = (K + X - Y) / 2;
		ans.push_back(std::make_pair(X, X - K));
		ans.push_back(std::make_pair(X + mid, Y - K + mid));
		ans.push_back(std::make_pair(X, Y));
	}
	else
	{
		LL over = (n * K - X - Y) / 2;
		for (LL i = 1; i <= n; ++i)
		{
			LL d = i * K;
			if (d <= Y + over) ans.push_back(std::make_pair(0, d));
			else if (d <= Y + over + X) ans.push_back(std::make_pair(d - Y - over, Y + over));
			else ans.push_back(std::make_pair(X, Y + (n - i) * K));
		}
	}

	if (flag_swap) rep(i, ans.size()) std::swap(ans[i].first, ans[i].second);
	if (flag_x) rep(i, ans.size()) ans[i].first *= -1;
	if (flag_y) rep(i, ans.size()) ans[i].second *= -1;
	out << ans.size() << std::endl;
	rep(i, ans.size()) out << ans[i].first << " " << ans[i].second << std::endl;
}


Measured memory_bytes: 5872
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		String number = input.next();
		long sum = 0;
		for (int i = 0; i < number.length(); i++){
			sum += Character.getNumericValue(number.charAt(i));
		}
		if(sum%9==0){
			System.out.println("Yes");          
        }else{
			System.out.println("No");
        }
    }
}

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

namespace ABC087_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = new int[2][];

            for (int i = 0; i < 2; i++)
            {
                A[i] = new int[N];
                var input = Console.ReadLine().Split(' ');
                for (int j = 0; j < N; j++)
                {
                    A[i][j] = int.Parse(input[j]);
                }
            }
            var ans = new int[N];

            for (int i = 0; i < N; i++)
            {
                ans[i] = A[0].Where((x, y) => y <= i).Sum() + A[1].Where((x, y) => y >= i).Sum();
            }
            Console.WriteLine(ans.Max());
        }

    }
}


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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int exp(int n, int k) {
  if (k == 0) return 1;
  if (k == 1) return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2) ax = mod(ax * n);
  return ax;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}

int dp[1000001][2][2];

int solve(int n, bool f1, bool f2) {
  if (n == 0) return (f1 && f2);
  if (dp[n][f1][f2] != -1) return dp[n][f1][f2];
  int &ans = dp[n][f1][f2];
  ans = 0;
  ans = mod(ans + 8 * solve(n - 1, f1, f2));

  ans = mod(ans + solve(n - 1, true, f2));
  ans = mod(ans + solve(n - 1, f1, true));

  return ans;
}
//#define MULTIPLE_TEST_CASE
void solution() {
  int n;
  cin >> n;
  memset(dp, -1, sizeof dp);
  cout << solve(n, 0, 0) << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


Measured memory_bytes: 113020
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,m,a,i,s=0,ans=0;
  cin>>n>>m;
  map<int64_t,int64_t> c;
  c[0]=1;
  for(i=0;i<n;i++){
    cin>>a;
    s=(s+a)%m;
    if(c.count(s)) c.at(s)++;
    else c[s]=1;
  }
  for(auto z:c) ans+=z.second*(z.second-1)/2;
  cout<<ans<<endl;
}

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

int k,c,ans;
set<int> t;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>k;
    do{
        ans++;
        c=(c*10+7)%k;
        if(t.find(c)!=t.end()){
            cout<<-1<<endl;
            return 0;
        }
        t.insert(c);
    }while(c);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 50456
K = int(input())
S = input()
N = len(S)
mod = int(1e9+7)

### 123
### a1bb2ccc3dddd 10文字インサート
# pow(25,6) * pow(26,4) * 8C2
# (3はfixで、それより前の8mojiから1/2を入れる場所を決める）
# これを3の位置でループする（1-indexで 3<=i<=N)

# 123dddddddddd
# pow(25,0) * pow(26,10) * 2C2(1)
# 12x3ddddddddd
# pow(25,1) * pow(26,9) * 3C2( = 2C2 * 3 / 1)
# 12xx3dddddddd
# pow(25,2) * pow(26,8) * 4C2( = 3C2 * 4 / 2)
# ...
# 12xxxxxxxxxx3
# pow(25,10) * pow(26,0) * 12C2( = 11C2 * 12 / 10)

# 5C5, 6C5, 7C5 1, 6, 21, 56
def powinv(x,mod):
  return pow1(x,mod-2,mod)
  
def pow1(x, n, mod):
  ans = 1
  while n>0:
    if n % 2:
      ans *= x
      ans %= mod
    x *= x
    x %= mod
    n = n // 2 # n >>= 1
  return ans

wk = pow(26,K,mod)
inv26 = powinv(26,mod)

ans = wk
for i in range(1,K+1):
  wk = (wk * 25 * inv26) % mod
  wk = (wk * (N-1+i) * powinv(i,mod) % mod)
  ans = (ans + wk)%mod
    
print(ans)


Measured memory_bytes: 76288
h, w = gets.split.map(&:to_i)


def min(ans, arr)
  d = arr.minmax.inject(&:-).abs
  return ((d < ans) ? d : ans)
end

def solver(h, w)
  ans = 1e11
  (h + 1).times do |i|
    sa = w * i
    # tate
    wi = w / 2
    sb = (h - i) * wi
    sc = (h - i) * (w - wi)
    ans = min(ans, [sa, sb, sc])
    # yoko
    hi = (h - i) / 2
    sb = hi * w
    sc = (h - hi - i) * w
    ans = min(ans, [sa, sb, sc])
  end
  ans
end

# 1
# (h + 1).times do |i|
#   sa = w * i
#   # tate
#   wi = w / 2
#   sb = (h - i) * wi
#   sc = (h - i) * (w - wi)
#   ans = min(ans, [sa, sb, sc])
#   # yoko
#   hi = (h - i) / 2
#   sb = hi * w
#   sc = (h - hi - i) * w
#   ans = min(ans, [sa, sb, sc])
# end
# # 2
# (w + 1).times do |i|
#   sa = h * i
#   # yoko
#   hi = h / 2
#   sb = (w - i) * hi
#   sc = (w - i) * (h - hi)
#   ans = min(ans, [sa, sb, sc])
#   # tate
#   wi = (w - i) / 2
#   sb = wi * h
#   sc = (w - wi - i) * h
#   ans = min(ans, [sa, sb, sc])
# end
p [solver(h, w), solver(w, h)].min


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
#define pi pair<int,int>
#define pb emplace_back
#define SZ(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define REP(i, j, k) for(int i = j; i < k; ++i)
#define debug(a) cout << #a << " = " << a << endl;
using namespace std;

int a, b, c;

signed main()
{
	cin >> a >> b >> c;
	if(c == 0) return cout << b, 0;
	--c;
	if(b > c) cout << 1 + b + c << endl;
	else cout << 1 + 2 * b + min(a, (c - b));
}

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

# top, bot
C = [[0 for _ in range(10)] for _ in range(10)]

for i in range(1,N+1):
  topi = int(str(i)[0])
  boti = i % 10
  C[topi][boti] += 1
  
#for i in range(10):
#  print(C[i])

ans = 0
for i in range(10):
  for j in range(10):
    ans += C[i][j] * C[j][i]
      
print(ans)

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 L, R, d;
	cin >> L >> R >> d;
	cout << R/d - (L-1)/d << endl;
}


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && a == c)cout << "1" << endl;
	else if (a == b || a == c || b == c)cout << "2" << endl;
	else cout << "3" << endl;
	int x;
	cin >> x;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <typeinfo>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007
using namespace std;


int main(){
  int a,b;
  cin >> a >> b;
  
  int ans = 0;
  for(int i=a;i<=b;i++){
	string s = to_string(i);
	int l=0,r=s.length()-1;
	bool flag = true;
	while(flag && l < r){
	  if(s[l] != s[r]) flag = false;
	  r--;
	  l++;
	}
	if(flag) ans++;
  }
   
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    double a = sc.nextDouble();
    double p = Math.PI;
    double answer1 = a*a*p;
    double answer2 = 2*a*p;
    System.out.printf("%f %f", answer1,answer2);
    sc.close();
  }
}



Measured memory_bytes: 28132
#include <stdio.h>
long long a [100010];
int main ()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
  scanf("%lld",&a[i]);
int zero =0;

for(int i=0;i<n;i++)
  if(a[i]==0) 
    zero ++;
if(zero >0){
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){
// This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}

Measured memory_bytes: 2516
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.Collections;
import java.math.BigDecimal;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String s = sc.next();
        String p = sc.next();
        for (int i = 0; i < s.length(); i++) {
            s = s.substring(s.length()-1, s.length()) + s.substring(0, s.length()-1);
            if (s.indexOf(p) != -1) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}

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

int main(void){
	int cnt=0;
	string s;
	cin>>s;
	rep(i,s.size()-1){
		if(s[i]!=s[i+1])cnt++;
	}
	cout<<cnt<<endl;

	return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
ll INF = LLONG_MAX;
 
using vc = vector<char>;
using vi = vector<int>;
using vb = vector<bool>;

int N, M;
vector<vi> graph; 
vb visited;

void dfs(int pos) {
    visited[pos] = true;
    for (int n : graph[pos]) {
        if (!visited[n]) dfs(n);
    }
}
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> N >> M;
    graph.resize(N);
    F0R(i, M) {
        int a, b, _; cin >> a >> b >> _;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    
    visited = vb (N);
    int components = 0;
    F0R(i, N) {
        if (!visited[i]) dfs(i), ++components;
    }

    cout << components << endl;
}

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

const int mod = 1e9 + 7;

long long x[101010], y[101010];
int n, m;

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> x[i];
	}
	for (int j = 1; j <= m; ++j) {
		cin >> y[j];
	}

	long long izryt=0, latte=0;
	for (int i = 1; i <= n; ++i) {
		izryt += ((i - 1) * x[i] - (n - i) * x[i]);
	}
	for (int i = 1; i <= m; ++i) {
		latte += ((i - 1) * y[i] - (m - i) * y[i]);
	}
	
	cout << (izryt % mod) * (latte % mod) % mod << endl;
}



Measured memory_bytes: 1792
N,M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
index = []
ans = 0
s = 0
for i in range(len(X)-1):
    index.append([i,X[i+1]-X[i]])
index.sort(key=lambda x: x[1],reverse=True)
if N<M:
    for i in range(N-1,len(index)):
        ans += index[i][1]

print(ans)



Measured memory_bytes: 21552
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] As = new int[N];
        int[] Bs = new int[N];

        for (int i = 0; i < N; i++) {
            As[i] = sc.nextInt();
            Bs[i] = sc.nextInt();
        }

        long count = 0;
        for (int i = N - 1; i >= 0; i--) {
            long a = As[i] + count;
            long b = Bs[i];
            if (a % b > 0) {
                count += b - (a % b);
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 60412
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double T = sc.nextDouble();
        double A = sc.nextDouble();
        double[] H = new double[N];
        for(int i = 0; i < N; i++) H[i] = sc.nextDouble();
        int ans = 0;
        for(int i = 0; i < N; i++) {
            if(dif(A,temp(T,H[ans])) > dif(A,temp(T,H[i])))
                ans = i;
        }
        System.out.println(ans+1);
    }

    static double temp(double T, double h) {
        return T - h * 0.006;
    }

    static double dif(double T, double A) {
        return Math.abs(A - T);
    }
}

Measured memory_bytes: 28236
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    ll N;
    cin >> N;
    vector<ll> L(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> L.at(i);
    }

    sort(L.begin(), L.end());

    ll count = 0;
    for (ll i = 0; i < N - 2; i++)
    {
        ll a = L.at(i);
        for (ll j = i + 1; j < N - 1; j++)
        {
            ll b = L.at(j);
            ll cmin = abs(a - b) + 1;
            ll cmax = a + b - 1;
            auto imin = lower_bound(L.begin() + j + 1, L.end(), cmin);
            auto imax = upper_bound(L.begin() + j + 1, L.end(), cmax);
            count += distance(imin, imax);
        }
    }

    cout << count << endl;

    return;
}

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


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

typedef struct{
  long long int a;
  long long int b;
}sigoto;

bool asc(const sigoto& l,const sigoto& r){
  return l.b == r.b ? l.a < r.a : l.b < r.b;
}


int main (void){
  long int n = 0,t = 0;
  cin >> n;

  vector<sigoto> s(n);

  for(int i = 0;i < n;i++){
    cin >> s[i].a >> s[i].b;
  }

  sort(s.begin(),s.end(),asc);

  for(int i = 0;i < n;i++){
    t = t + s[i].a;
    if(t > s[i].b){
      cout << "No\n";
      return 0;
    }
  }

  cout << "Yes\n";

  return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

ll c[510],s[510],f[510];


int main(void){
	          int i,j;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);

	      	  int N;
	      	  cin >> N;

	      	  for(i=1;i<=N-1;i++){
	      		  cin >> c[i] >> s[i] >> f[i];
	      	  }

	      	  for(i=1;i<=N-1;i++){
	      		  ll t=s[i]+c[i];
	      		  for(j=i+1;j<=N-1;j++){
	      			  if(t-s[j]<0) t=s[j]+c[j];
	      			  else{
	      				  t=((t-s[j]+f[j]-1)/f[j])*f[j]+s[j]+c[j];
	      			  }
	      		  }

	      		  cout << t << endl;

	      	  }

	      	  cout << 0 << endl;


	          return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
char c[4];
bool ans=true;
signed main(){
    rep(i,4)cin>>c[i];
    rep(i,3){
        if(c[i]==c[i+1])ans=false;
    }
    if(ans)puts("Good");
    else puts("Bad");
    return 0;
}



Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    v = LI()

    vset = set(v)
    if len(vset) == 1:
        print(len(v)//2)
        exit()

    #  n = 10**5
    #  #  v = [10**5 - i%18 for i in range(n)]
    #  v = [random.randint(0, 100) for i in range(n)]
    #  print(v[:10])

    odd = []
    even = []
    for idx, i in enumerate(v):
        if idx % 2 == 0:
            even.append(i)
        else:
            odd.append(i)

    # Counterが速い
    odd_count = collections.Counter(odd)
    even_count = collections.Counter(even)

    #  print(odd_count, even_count)
    if len(odd_count) == len(even_count) == 1:
        # 変更の必要なし
        print(0)
        exit()

    if odd_count.most_common(1)[0][0] != even_count.most_common(1)[0][0]:
        # 楽なほう
        if len(odd_count) == 1:
            even_result = sum([i[1] for i in even_count.most_common()[1:]])
            print(even_result)
        elif len(even_count) == 1:
            odd_result = sum([i[1] for i in odd_count.most_common()[1:]])
            print(odd_result)
        else:
            odd_result = sum([i[1] for i in odd_count.most_common()[1:]])
            even_result = sum([i[1] for i in even_count.most_common()[1:]])
            print(odd_result + even_result)
    else:
        # 全部同じ数字にならないようにしたい
        # ２個め同士で比べて、２個めをより多く含んでる方はそっちにしちゃう
        if len(odd_count) == 1:
            even_result = even_count.most_common(1)[0][1]
            even_result += sum([i[1] for i in even_count.most_common()[2:]])
            print(even_result)
        elif len(even_count) == 1:
            odd_result = odd_count.most_common(1)[0][1]
            odd_result += sum([i[1] for i in odd_count.most_common()[2:]])
            print(odd_result)
        elif odd_count.most_common(2)[1][1] > even_count.most_common(2)[1][1]:
            # oddは２つめに多いものを不変にする
            # evenは１つめを不変に
            odd_result = odd_count.most_common(1)[0][1]
            odd_result += sum([i[1] for i in odd_count.most_common()[2:]])
            even_result = sum([i[1] for i in even_count.most_common()[1:]])
            print(odd_result + even_result)
        else:
            odd_result = sum([i[1] for i in odd_count.most_common(len(odd_count))[1:]])
            even_result = even_count.most_common(1)[0][1]
            even_result += sum([i[1] for i in even_count.most_common()[2:]])
            print(odd_result + even_result)

main()


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

struct Student {int prev, next;};

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;

  vector<bool> alive(N, true);
  vector<Student> student(N);
  for(int i = 0; i < N; ++i) {
    student[i].prev = (i - 1 + N) % N;
    student[i].next = (i + 1) % N;
  }

  int button = 0;
  for(int i = 0; i < M; ++i) {
    int a;
    cin >> a;
    bool odd = a & 1;
    while(a-- > 0) {
      button = odd ? student[button].prev : student[button].next;
    }
    alive[button] = false;
    student[student[button].prev].next = student[button].next;
    student[student[button].next].prev = student[button].prev;
    button = student[button].next;
  }

  for(int i = 0; i < Q; ++i) {
    int q;
    cin >> q;
    cout << (alive[q] ? 1 : 0) << endl;
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> stud(n);
  rep(i, n) {
    int num;
    cin >> num;
    stud[i].first = num;
    stud[i].second = i + 1;
  }
  sort(stud.begin(), stud.end());
  rep(i, n) cout << stud[i].second << endl;
  return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n;cin>>n;
    int sum = 0;
    int temp = n;
    while(n)
    {  
         sum+= (n%10);
         n/=10;
    }
    if(temp%sum==0) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,m,dp[50001],a;
int main(void){
    cin>>n>>m>>a;
    for(int i=0;i<=n;i++){
        dp[i]=i;
    }
    for(int j=1;j<m;j++){
        cin>>a;
        for(int i=0;i<=n-a;i++){
            dp[i+a]=min(dp[i+a],dp[i]+1);
        }
    }
    cout<<dp[n]<<endl;
}



Measured memory_bytes: 3296
//%std
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out = 0, fh = 1;
	char jp = getchar();
	while ((jp > '9' || jp < '0') && jp != '-')
		jp = getchar();
	if (jp == '-')
		fh = -1, jp = getchar();
	while (jp >= '0' && jp <= '9')
		out = out * 10 + jp - '0', jp = getchar();
	return out * fh;
}
const int N = 2e5 + 10;
int n, T, a[N], b[N], p[N];
bool cmp(const int &i, const int &j)
{
	return 1LL * (b[i] + 1) * a[j] < 1LL * (b[j] + 1) * a[i];
}
bool cmp2(const int &i, const int &j)
{
	return b[i] < b[j];
}
ll calc(int t, int i)
{
	return 1LL * a[i] * t + b[i];
}
map<int, int> dp, tmp;
int main()
{
	n = read(), T = read();
	for (int i = 1; i <= n; ++i)
	{
		p[i] = i;
		a[i] = read(), b[i] = read();
	}
	dp[0] = 0;
	sort(p + 1, p + 1 + n, cmp);
	int ans = 0, k = n + 1;
	for (int i = 1; i <= n; ++i)
	{
		if (a[p[i]] == 0)
		{
			k = i;
			break;
		}
		tmp = dp;
		for (auto pr : dp)
		{
			int cnt = pr.first, t = pr.second;
			if (calc(t + 1, p[i]) + t + 1 <= T)
			{
				t = calc(t + 1, p[i]) + t + 1;
				if (!tmp.count(cnt + 1))
					tmp[cnt + 1] = t;
				else
					tmp[cnt + 1] = min(tmp[cnt + 1], t);
			}
		}
		dp = tmp;
	}
	sort(p + k, p + 1 + n, cmp2);
	for (auto pr : dp)
	{
		int cnt = pr.first, t = pr.second;
		for (int i = k; i <= n; ++i)
		{
			if (calc(t + 1, p[i]) + t + 1 <= T)
				t = t + 1 + calc(t + 1, p[i]), ++cnt;
		}
		ans = max(ans, cnt);
	}
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

const int INF = 1e9;

int c[15], a[15][15], cur[15];

int main() {
	int n, m, x;
	scanf("%d%d%d", &n, &m, &x);
	
	for (int i = 0; i < n; i++) {
		scanf("%d", &c[i]);
		for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
	}
	
	int res = INF;
	
	for (int i = 0; i < (1 << n); i++) {
		memset(cur, 0, sizeof(cur));
		int cost = 0;
		for (int j = 0; j < n; j++) {
			if ((i >> j) & 1) {
				cost += c[j];
				for (int k = 0; k < m; k++) cur[k] += a[j][k];
			}
		}
		
		bool ok = 1;
		for (int j = 0; j < m; j++) {
			if (cur[j] < x) ok = 0;
		}
		
		if (ok) res = min(res, cost);
	}
	
	if (res == INF) printf("-1\n");
	else printf("%d\n", res);
}


Measured memory_bytes: 3820
import sys
readline = sys.stdin.readline
from collections import Counter

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    c = Counter(A)
    A = [a for a in A if c[a] > 1]
    if len(A) < 4:
        print(0)
        exit()
    c = Counter(A)
    keys = c.keys()
    vals = c.values()
    z = zip(keys, vals)
    z = sorted(z, reverse=True)
    keys, vals = zip(*z)
    if vals[0] >= 4:
        a1, a2 = keys[0], keys[0]
    else:
        a1, a2 = keys[0], keys[1]
    print(a1 * a2)


if __name__ == '__main__':
    main()

Measured memory_bytes: 18600
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

template <class T>
struct SegmentTree/*{{{*/
{
    vector<T> nodes;
    SegmentTree(int size) {
        nodes.resize(size*2, 0);
    }

    void maintain_consistency(int pos) {
        // テ」ツδ偲」ツδシテ」ツδ嘉」ツ?ョテ・ツ?、テ」ツ?古・ツュツ静」ツ?ョテ・ツ青暗ィツィツ暗」ツ?ィテ、ツクツ?ィツ?エテ」ツ?療」ツ?ェテ」ツ??・ツ?エテ・ツ青暗ッツシツ古、ツクツ催・ツョツ古・ツ?ィテ」ツ?ェテヲツ崢エテヲツ鳴ーテ」ツ?古ィツ。ツ古」ツ?ェテ」ツつ湘」ツつ古」ツ?ヲテ」ツ??」ツつ凝」ツ?淌」ツつ?
        // テ、ツクツ凝」ツ?ョテ」ツδ偲」ツδシテ」ツδ嘉」ツ?ォテ、ツシツ敕ヲツ青ャテ」ツ?陛」ツ?崚」ツつ凝ッツシツ?
        int children_sum = nodes[pos*2+1] + nodes[pos*2+2];
        if(children_sum != nodes[pos]) { 
            //cout << "maintain: " << pos << ' ' << nodes[pos] << ' ' << children_sum << endl;
            int diff = nodes[pos] - children_sum;
            nodes[pos*2+1] += diff/2;
            nodes[pos*2+2] += diff/2;
        }
    }

    // [left, right) テ」ツ?ォテ・ツッツセテ」ツ?凖」ツつ凝」ツつッテ」ツつィテ」ツδェテッツシツ?
    // テァツ渉セテ・ツ慊ィテ」ツ?ョテ」ツδ偲」ツδシテ」ツδ嘉」ツ?ッpos テ」ツ?ァテッツシツ?[pl, pr) テ」ツつ津ィツ。ツィテ」ツつ湘」ツ?療」ツ?ヲテ」ツ??」ツつ凝ッツシツ?
    int get_inner(int left, int right, int pos, int pl, int pr) {
        //cout << left << ' ' << right << ' ' << pos << ' ' <<  pl << ' ' << pr << endl;
        if(pr <= left || right <= pl) return 0; // テ、ツコツ、テ・ツキツョテ」ツ?療」ツ?ェテ」ツ??
        if(left <= pl && pr <= right) return nodes[pos]; // テ・ツョツ古・ツ?ィテ」ツ?ォテ・ツ青ォテ」ツ?セテ」ツつ古」ツつ?

        maintain_consistency(pos);

        const int center = (pl+pr) / 2;
        int lv = get_inner(left, right, pos*2+1, pl, center);
        int rv = get_inner(left, right, pos*2+2, center, pr);
        return lv + rv;
    }

    int get(int left, int right) {
        return get_inner(left, right, 0, 0, nodes.size()/2);
    }

    int add_inner(int left, int right, int pos, int pl, int pr) {
        //cout << left << ' ' << right << ' ' << pos << ' ' <<  pl << ' ' << pr << endl;
        if(pr <= left || right <= pl) return nodes[pos]; // テ、ツコツ、テ・ツキツョテ」ツ?療」ツ?ェテ」ツ??
        if(left <= pl && pr <= right) return nodes[pos] += pr-pl; // テ・ツョツ古・ツ?ィテ」ツ?ォテ・ツ青ォテ」ツ?セテ」ツつ古」ツつ?

        maintain_consistency(pos);

        const int center = (pl+pr)/2;
        int lv = add_inner(left, right, pos*2+1, pl, center);
        int rv = add_inner(left, right, pos*2+2, center, pr);
        return nodes[pos] = lv+rv;
    }

    int add(int left, int right) {
        return add_inner(left, right, 0, 0, nodes.size()/2);
    }
};/*}}}*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int N;
    cin >> N;
    SegmentTree<int> segtree(1<<17);
    for(int i = 0; i < N; ++i) {
        int minval, maxval;
        cin >> minval >> maxval;
        segtree.add(minval-1, maxval);
    }
    //cout << "Added" << endl;
    //cout << segtree.nodes[0] << ' ' << segtree.nodes[1] << ' ' << segtree.nodes[2] << endl;
    int ans = 0;
    for(int n = N; n >= 0; --n) {
        //cout << segtree.nodes[0] << ' ' << segtree.nodes[1] << ' ' << segtree.nodes[2] << endl;
        const int val = segtree.get(n, n+1);
        //cout << val << endl;
        if(val >= n) {
            ans = n;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#define REP0(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REP1(i,n) for((i)=1;(i)<=(long long)(n);(i)++)
#define ll long long
using namespace std;

ll i,j;
const ll MOD = 1000000000 + 7;

int main(){
    string t,s;

    int ans=INT32_MAX;
    ll time=0;
    int count;
    cin>>s>>t;

    REP0(i,s.length()-t.length()+1){
        count=0;
        REP0(j,t.length()){
            if(s[i+j]!=t[j]){
                count++;
            }
        }
        ans=min(ans,count);
    }
   
    
    cout<<ans<<'\n';
    return 0;
}

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

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

const int MAXN = 100005;

int N, M;
vector <int> E[MAXN];
int color[MAXN];

void load() {
	scanf("%d%d", &N, &M);
	while (M--) {
		int u, v;
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
}

bool dfs(int x, int c) {
	if (color[x] != -1)
		return color[x] == c;
	color[x] = c;
	bool ans = true;
	for (auto it : E[x])
		ans &= dfs(it, c ^ 1);
	return ans;
}

ll square(int x) {
	return (ll)x * x;
}

ll solve() {
	memset(color, -1, sizeof color);	
	int cnt[2] = {0}, iso = 0;
	for (int i = 1; i <= N; i++)
		if (E[i].empty())
			iso++;
		else if (color[i] == -1)
			cnt[dfs(i, 0)]++;
	
	return (ll)iso * (2 * N - iso) + square(cnt[0] + cnt[1]) + square(cnt[1]);
}

bool mat[105][105];
pii dad[105][105];
int rnk[105][105];

pii find(pii p) {
	return dad[p.first][p.second] == p ? p : dad[p.first][p.second] = find(dad[p.first][p.second]);
}

void join(pii x, pii y) {
	x = find(x);
	y = find(y);
	if (x == y)
		return;
	if (rnk[x.first][x.second] > rnk[y.first][y.second])
		swap(x, y);
	dad[x.first][x.second] = y;
	rnk[y.first][y.second] += rnk[x.first][x.second] == rnk[y.first][y.second];
}

ll brute() {
	for (int i = 1; i <= N; i++)
		for (auto it : E[i])
			mat[i][it] = true;
	
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++)
			dad[i][j] = {i, j};
			
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++)
			for (int k = 1; k <= N; k++)
				for (int l = 1; l <= N; l++)
					if (mat[i][k] && mat[j][l])
						join({i, j}, {k, l});
	
	ll sol = 0;
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++)
			sol += find({i, j}) == pii(i, j);
	
	return sol;
}

int main() {
	load();
	printf("%lld\n", solve());
	//printf("%lld\n", brute());
	return 0;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p[i];

  sort(p.begin(),p.end());

  int ans = 0;
  rep(i,k){
    ans += p[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fr first
#define se second
#define pb push_back

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

vector<vector<int>>dp(30,vector<int>(500,0));

signed main(){
  int N;cin>>N;
  vector<P> M(N);
  REP(i,0,N)cin>>M[i].fr>>M[i].se;
  vector<vector<int>> dp(N+1,vector<int>(N+1,INF));
  REP(i,0,N+1)dp[i][i]=0;

  REP(w,1,N)REP(i,0,N-w){
    int j=i+w;
    REP(k,i,j){
        int prod=M[i].fr*M[k].se*M[j].se;
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+prod);
    }
  }
  print(dp[0][N-1])
}



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

using namespace std;

int main (void) {
    int N;
    cin >> N;
    map<int, int> A;
    int a;
    for ( int i=0; i<N; i++ ) {
        cin >> a;
        A[a]++;
    }

    int ans = 0;
    for ( pair<int, int> itr : A ) {
        if ( itr.second % 2 != 0 )
            ans ++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4864
(defun solver ()
  (let* ((n (read))
         (ai (make-array (+ n 2)))
         (sum 0) tmp)
    (loop for i from 1 to n do
          (setf (aref ai i) (read)))
    (loop for j from 0 below (+ n 1) do
          (incf sum (abs (- (aref ai (1+ j)) (aref ai j)))))
    (loop for i from 1 to n do
          (format t "~a~%"
                  (+ (- sum
                        (abs (- (aref ai i) (aref ai (1- i))))
                        (abs (- (aref ai (1+ i)) (aref ai i))))
                     (abs (- (aref ai (1+ i)) (aref ai (1- i)))))))))

(solver)

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

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

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

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

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

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

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

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

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

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



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

	vector<ll> A(N + 1);
	repn(i,N) cin >> A[i];

	vector<ll> B(N + 1, 0);
	repn(i, N) B[i] = B[i - 1] ^ A[i];

	ll M = 1 << 20;
	vector<bool> f(M, 0);
	vector<mint> d(M, 0), r(M, 0);
	vector<ll> z(M, 0);
	ll zn = 0;

	repn(i, N) {
		if (B[i] == 0) { zn++; }
		else {
			if (f[B[i]] == 0) { d[B[i]] = 1; f[B[i]] = 1; }
			else { d[B[i]] += r[B[i]] * (zn - z[B[i]]); }

			r[B[i]] += d[B[i]];
			z[B[i]] = zn;
		}
		//cout << B[i] << d[B[i]] << r[B[i]] << z[B[i]] << endl;
	}

	mint ans = 0;

	if (B[N] != 0) { ans = d[B[N]]; }
	else {
		repn(i, M - 1) { ans += r[i]; }
		ans += (mint)2 ^ (zn-1);
	}

	cout << ans;
	system("PAUSE");
}


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

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

const int MX = 100005;

#define F0R(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define sz(x) (int)x.size()
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define f first
#define s second

void setIO(string name) {
	ios_base::sync_with_stdio(0); cin.tie(0);
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}


int N, a[MX][3];
int dp[MX][3];

int main() {
	cin >> N;
	F0R(i, N) F0R(j, 3) cin >> a[i][j];

	for (int i = 1; i <= N; i++) {
		dp[i][0] = max(dp[i - 1][1] + a[i - 1][0], dp[i][0]);
		dp[i][0] = max(dp[i - 1][2] + a[i - 1][0], dp[i][0]);

		dp[i][1] = max(dp[i - 1][0] + a[i - 1][1], dp[i][1]);
		dp[i][1] = max(dp[i - 1][2] + a[i - 1][1], dp[i][1]);

		dp[i][2] = max(dp[i - 1][0] + a[i - 1][2], dp[i][2]);
		dp[i][2] = max(dp[i - 1][1] + a[i - 1][2], dp[i][2]);

		//cout << "The maximum number of points we can have on day " << i << " is " <<  max(dp[i][0], max(dp[i][1], dp[i][2])) << "\n";
	}

	cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << "\n";
}

// watch out for int overflow

Measured memory_bytes: 2560
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;

template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<<(i+1==n?'\n':' '); }
template<class T>void pp(T v){ EACH(it,v) cout<<(it==v.begin()?"":" ")<<*it; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

inline void write_bool(bool b, const string &tval, const string &fval) {
  cout << (b ? tval : fval) << endl;
} 
inline void YESNO(bool b) { return write_bool(b, "YES", "NO"); }
inline void YesNo(bool b) { return write_bool(b, "Yes", "No"); }
inline void yesno(bool b) { return write_bool(b, "yes", "no"); }

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;
  while (cin >> n) {
    vdouble v(n);
    REP(i,n) cin >> v[i];
    sort(ALL(v));
    reverse(ALL(v));
    REP(i,n-1) {
      double a = v.back(); v.pop_back();
      double b = v.back(); v.pop_back();
      v.push_back((a + b) * 0.5);
    }
    printf("%.12lf\n", v[0]);
  }
}


Measured memory_bytes: 888