akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, a, b;
ll comb[51][51];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> a >> b;
  vector<ll> v(n);
  REP(i, n) cin >> v[i];

  comb[0][0] = 1;
  FOR(i, 1, 51) REP(j, i + 1) {
    comb[i][j] += comb[i - 1][j];
    if(j > 0) comb[i][j] += comb[i - 1][j - 1];
  }

  sort(v.begin(), v.end(), greater<ll>());

  ll sum = 0;
  REP(i, a) sum += v[i];
  cout << fixed << setprecision(8) << (double)sum / a << endl;

  int p;
  REP(i, n) if(v[a - 1] == v[i]) p++;
  if(v[a - 1] == v[0]) {
    ll ans = 0;
    FOR(i, a, min(b, p) + 1) {
      ans += comb[p][i];
    }
    cout << ans << endl;
  } else {
    int ap = 0;
    REP(j, a) if(v[a - 1] == v[j]) ap++;
    cout << comb[p][ap] << endl;
  }
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    map<int, int> A;
    for(int i = 0; i < N; i++) {
        int a; cin >> a;
        if(!A.count(a)) A[a] = 1;
        else A[a]++;
    }
    int ans = 0;
    for(auto p: A) {
        if(p.second % 2 != 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int n,i;
	cin>>n;
	int a,b,c;
	cin>>a>>b>>c;
	int dp1[n],dp2[n],dp3[n];
	dp1[0]=a;
	dp2[0]=b;
	dp3[0]=c;
	for(i=1;i<n;i++)
	{
		cin>>a>>b>>c;
		dp1[i]=max(a+dp2[i-1],a+dp3[i-1]);
		dp2[i]=max(b+dp1[i-1],b+dp3[i-1]);
		dp3[i]=max(c+dp1[i-1],c+dp2[i-1]);
	}
	cout<<max(dp1[n-1],max(dp2[n-1],dp3[n-1]));
	return 0;
}

Measured memory_bytes: 1408
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			@SuppressWarnings("unused")
			int n = scanner.nextInt(), m = scanner.nextInt();
			Set<Integer> commonSet = new HashSet<>();
			IntStream.range(0, n).forEach(i -> {
				int k = scanner.nextInt();
				Set<Integer> set = IntStream.range(0, k).map(j -> scanner.nextInt()).boxed()
						.collect(Collectors.toSet());
				if (0 == i) {
					commonSet.addAll(set);
				} else {
					commonSet.retainAll(set);
				}
			});
			System.out.println(commonSet.size());
		}
	}
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  A.emplace_back(0);
  int na = A[0], nc = 0, res = 0;
  for (int i = 0; i <= N; i++) {
    if (na == A[i]) {
      nc++;
    } else {
      res += (nc >= na ? nc - na : nc);
      na = A[i];
      nc = 1;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	//freopen("modulo.in","r",stdin);
	//freopen("modulo.out","w",stdout);
	int n,i,s=0,tmp;
	scanf("%d",&n);
	s=-n;
	for(i=0;i<n;i++)
	{
		scanf("%d",&tmp);
		s+=tmp;
	}
	printf("%d",s);
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
v = list(map(int, input().split()))

v.sort()
t = []

for i in range(N):
    if i == 0:
        t.append(v[i])
    else:
        t.append(v[i] * 2**(i-1))

print(sum(t)/(2**(N-1)))

Measured memory_bytes: 3060
#include <stdio.h>
#define MIN(x,y) ((x) < (y) ? (x) : (y))

int main(void) {
	int n, x, i, j, p, q, c;
	for(;;) {
		scanf("%d %d", &n, &x);
		if ((n == 0) && (x == 0)) {
			break;
		}
		c = 0;
		for (i = n; i>0; i--) {
			p = x - i; 
			for (j = i-1; j>1; j--) {
				q = p - j;
				if ((q>0)&(q<j)) {
					c++;
				} else if (q>=j) {
					break;
				}
			}
		}
		printf("%d\n", c);
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	map<string, ll> mp;
	ll ans = 0;
	rep(i, 0, n - 1)
	{
		string s; cin >> s;
		sort(all(s));
		++mp[s];
	}
	for (auto x : mp)
	{
		ans += (x.second * (x.second - 1)) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 11136
while 1:
    a, op, b = raw_input().split()
    a=int(a)
    b=int(b)
    if op == '+':
        print a+b
    elif op == '-':
        print a-b
    elif op == '*':
        print a*b
    elif op == '/':
        print a/b
    elif op == '?':
        break

Measured memory_bytes: 6356
#148_F
import queue
n, u, v = map(int, input().split())
inf = 10 ** 6
ans = 0

edges = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

def bfs(d,start):
    d[start] = 0
    que = queue.Queue()
    que.put(start)
    while not que.empty():
            x = que.get()
            for to in edges[x]:
                if d[to] == inf:
                    que.put(to)
                    d[to] = d[x] + 1
                    
du, dv = [inf]*n, [inf]*n
bfs(du,u-1)
bfs(dv,v-1)
for i in range(n):
    if dv[i] > du[i]:
        ans = max(ans, dv[i] - 1)
    
print(ans)

Measured memory_bytes: 71580
using System;
using System.Linq;

namespace _0123
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string s = Console.ReadLine();
                if (s == null)
                {
                    break;
                }
                double[] x = s.Split().Select(double.Parse).ToArray();
                if (x[0] < 35.5 && x[1] < 71)
                {
                    Console.WriteLine("AAA");
                }
                else if (x[0] < 37.5 && x[1] < 77)
                {
                    Console.WriteLine("AA");
                }
                else if (x[0] < 40 && x[1] < 83)
                {
                    Console.WriteLine("A");
                }
                else if (x[0] < 43 && x[1] < 89)
                {
                    Console.WriteLine("B");
                }
                else if (x[0] < 50 && x[1] < 105)
                {
                    Console.WriteLine("C");
                }
                else if (x[0] < 55 && x[1] < 116)
                {
                    Console.WriteLine("D");
                }
                else if (x[0] < 70 && x[1] < 148)
                {
                    Console.WriteLine("E");
                }
                else
                {
                    Console.WriteLine("NA");
                }
            }
        }
    }
}

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

int main(){
  int n;cin >> n;
  vector<float> v(n);for(int i=0;i<n;++i)cin >> v[i];
  float ans = 0;
  sort(v.begin(),v.end());
  ans = v[0];
  for(int i=0;i<n-1;i++){
    ans = (ans + v[i+1])/2.0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, bool isFront) {
	if (first_itr < 0 || first_itr > str.size()) {
		return str;
	}
	else {
		if (isFront) {
			std::string tmp;
			for (size_t i = 0; i < first_itr; i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
		else {
			std::string tmp;
			for (size_t i = first_itr; i < str.size(); i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
	}
}


bool dfs(int depth, str s) {
	/*if (depth == n) {
		ans.push_back(s);
		return false;
	}
	for (int i = 0; i < n; i++) {
		if (dfs(depth + 1, s + dic.at(i))) {
			return true;
		}
	}*/
	return false;
}


int main() {
	int n; cin >> n;
	map<string, int> map;
	ll max = 1;
	rep(i, n) {
		string str; cin >> str;
		if (map.count(str) == 0) {
			map[str] = 1;
		}
		else {
			map[str]++;
			if (max < map[str]) {
				max = map[str];
			}
		}
	}
	vector<str> v;
	for (auto itr = map.begin(); itr != map.end(); itr++) {
		if (itr->second == max) {
			v.push_back(itr->first);
		}
	}
	sort(all(v));
	for (size_t i = 0; i < v.size(); i++) {
		cout << v[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 27252
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
    return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
      x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def num_roots(self):
    return len([i for i, x in enumerate(self.parents) if x < 0])

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def num_members(self,x):
    return abs(self.parents[self.find(x)])

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
P = list(map(int, input().split()))
uf = UnionFind(N)
for _ in range(M):
  x,y = map(int, input().split())
  uf.union(x-1,y-1)
from collections import defaultdict
d = defaultdict(lambda: [])
for i in range(N):
  d[uf.find(i)].append(i)
from bisect import bisect_left
def binary_search(A,p):
  if A[0]<=p and p<=A[-1]:
    if p == A[bisect_left(A,p)]:
      return True
  return False
ans = 0
for v in d.values():
  lis = sorted(v)
  for a in v:
    if binary_search(lis,P[a]-1):
      ans += 1
print(ans)





Measured memory_bytes: 104360
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int MAX = 110000;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];

    ll xsum = 0;
    rep(i, n-1) {
        int j = i + 1;
        xsum += (x[j]-x[i]) * (i+1) % MOD * (n-j) % MOD;
        xsum %= MOD;
    }

    ll ysum = 0;
    rep(i, m-1) {
        int j = i + 1;
        ysum += (y[j]-y[i]) * (i+1) % MOD * (m-j) % MOD;
        ysum %= MOD;
    }

    ll ans = xsum * ysum % MOD;
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define repz(i, z, n) for(decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for(decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(all(v)))
#define MIN(v) (*min_element(all(v)))
#define INF 1000000000000 //1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<

using namespace std;
void debug_out(){ cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

typedef long long ll;
typedef unsigned long long ul;
// 1s間で可能なループ回数2E+8回
// intの最大値2147483647~2E+9
// long longの最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<> push_back
// 連想配列map<key,value> insert,
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// 大文字65-90(-32)
// 小文字97-122(+32)
// 1E+9 +7
const ll mod = 1000000000+7;
int main(){
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n,m; cin >> n >> m;
  cout << n*(n-1)/2+m*(m-1)/2 << endl;
  
  return 0;
}


Measured memory_bytes: 256
use std::cmp::max;
use std::collections::HashMap;

fn input_one<T: std::str::FromStr> () -> Result<T, T::Err> {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    n.trim().parse()
}

fn input_pair<T: std::str::FromStr + Copy> () -> (T, T) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let arr: Vec<_> = s.trim().split_whitespace().flat_map(str::parse).collect();
    (arr[0], arr[1])
}

fn main() {
    let n: usize = input_one().unwrap();
    let mut c: HashMap<(usize, usize), usize> = HashMap::new();
    let mut v = vec![vec![]; n + 1];
    let mut l = vec![];
    for _ in 1..n {
        let (a, b) = input_pair::<usize>();
        v[a].push(b);
        v[b].push(a);
        l.push((a, b));
    }
    let mut visited = vec![false; n + 1];
    let mut k = 0;
    let mut q = vec![(1, 0)];
    while let Some((p_node, p_color)) = q.pop() {
        let mut color_offset = 0;
        // println!("{} {}", p_node, p_color);
        visited[p_node] = true;
        let mut i = 0;
        for &node in v[p_node].iter() {
            if visited[node] {
                continue
            }
            i += 1;
            if i + color_offset == p_color {
                color_offset += 1;
            }
            let color = i + color_offset;

            c.insert((p_node, node), color);
            c.insert((node, p_node), color);
            q.push((node, color));
            k = max(k, color);
            // println!("{} {} {}", p_node, node, color);
        }
    }
    println!("{}", k);
    for (a, b) in l.into_iter() {
        println!("{}", c[&(a, b)]);
    }
}


Measured memory_bytes: 19292
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

set<char> S {
  'M', 'A', 'R', 'C', 'H'
};
  
int main() {
  int n; cin >> n;
  map<char, ll> M;
  loop(i,0,n) {
    string s; cin >> s;
    if (!S.count(s[0])) continue;
    M[s[0]]++;
  }
  ll ans = 0;
  string u = "MARCH";
  loop(i,0,3) loop(j,i+1,4) loop(k,j+1,5) {
    ans += M[u[i]] * M[u[j]] * M[u[k]];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3580
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int i, k;
    cin >> i >> k;
    
    while(i !=0 && k!=0){
        for (int m=0; m<i; m++){
            for (int n=0; n<k; n++){
               cout << "#";    
            }
            cout << endl;
        }
        cout << endl;
        cin >> i >> k;
    }
}



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

void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}

int main(int argc, char const *argv[])
{
	// fastio();
	int n, k;
	cin >> n >> k;
	vector<int> nums(n);
	for (int i = 0; i < n; ++i)	 {
		cin >> nums[i];
	}
	vector<int> ans(n, INT_MAX);
	ans[0] = 0;
	for (int i = 1; i < n; ++i) {
		int count = 0;
		for (int j = i-1; j >= 0 && count < k; --j) {
			ans[i] = min(ans[i], ans[j]+abs(nums[i]-nums[j]));
			count++;
		}
	}
	cout << ans[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<queue>
#include<map>
using namespace std;
priority_queue<int,vector<int>,greater<int> > q1;

int main(){
	int n,x;
	int i,j,k;
	int a,b,c;
	int s=0;
	cin>>n>>x;
	for(i=0;i<n;i++){
		cin>>a;
		q1.push(a);
	}
	while(!q1.empty()){
		a=q1.top(),q1.pop();
		if(x<a)break;
		x-=a;
		s++;
	}
	if(x>0 && s==n)s--;
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
  int n,m;
  while(1){
    cin>>n>>m;
    if(n==0 && m==0)break;

    int people[n];
    for(int i=0;i<n;i++){
      people[i]=1;
    }
    int count=0;
    int ind=n-1;
    int rest=n;
    while(rest>1){
      ind=(ind+1)%n;
      if(people[ind]==1){
        count+=1;
        if(count==m){
          rest-=1;
          count=0;
          people[ind]=0;
        }
      }
    }
    for(int i=0;i<n;i++){
      if(people[i]==1){
        cout<<i+1<<endl;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2992
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n, sum=0; cin >> n;
    vector<int> s(n);
    REP(i, n){
        cin >> s[i];
        sum += s[i];
    }
    if(sum % 10){
        cout << sum << "\n";
        return 0;
    }
    sort(s.begin(), s.end());
    REP(i, n){
        if(s[i] % 10){
            cout << sum - s[i] << "\n";
            return 0;
        }
    }
    cout << 0 << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n,temp;
    string a,b;
    scanf("%d",&n);
    while(n--){
        scanf("%d",&temp);
        a+=temp;
    }
    scanf("%d",&n);
    while(n--){
        scanf("%d",&temp);
        b+=temp;
    }
    printf("%d\n",a<b?1:0);
}


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

K,S=map(int,input().split())

z = list(range(0,K+1))
ans = []

for i in z:
  s_z = S - i
  if s_z < 0:
    pass
  elif K < s_z:
    if (K + 1) > (s_z - K):
      ans.append(K + 1 - (s_z - K))
  else:
    ans.append(s_z + 1)

print(sum(ans))

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;


class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        string inpt = Reader.ReadLine();

        for (int i = 0; i < inpt.Length; i++)
        {
            if (!PosDic.ContainsKey(inpt[i]))
            {
                PosDic.Add(inpt[i], new List<int>());
            }
            PosDic[inpt[i]].Add(i);
        }

        foreach (char key in PosDic.Keys)
        {

            int[] ret = this.GetAns(PosDic[key]);
            if (ret != null)
            {
                Console.WriteLine(ret[0] + " " + ret[1]);
                return;
            }
        }
        Console.WriteLine("-1 -1");


    }

    private int[] GetAns(List<int> idxList)
    {
        if (idxList.Count <= 1)
        {
            return null;
        }

        for (int i = 2; i <= 3; i++)
        {
            for (int j = 0; j < idxList.Count - (i - 1); j++)
            {
                if (idxList[j + i - 1] - idxList[j] < i * 2 - 1)
                {
                    return new int[] {idxList[j] + 1, idxList[j + i - 1] + 1};
                }

            }
        }
        return null;
    }

    private Dictionary<char, List<int>> PosDic = new Dictionary<char, List<int>>();



    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"

atcoder

";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 4952
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

int main(){
  int N;
  int T, A;
  double min_diff = 10000000;
  int id = -1;

  cin >> N;
  cin >> T >> A;
  for(int i=0;i<N;i++){
    int H;
    cin >> H;

    double tempture = T - H*0.006;
    double diff = abs(A - tempture);
    if(diff < min_diff){
      min_diff = diff;
      id = i+1;
    }
  }

  cout << id << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define clr(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f

using namespace std;

typedef long long ll;

int n, m, l, q, cost[304][305];

void floyd() {
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
}

int main(){
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    cin >> n >> m >> l;
    int a, b, c;
    clr(cost, inf);
    for (int i = 1; i <= m; i++) {
        cin >> a >> b >> c;
        cost[a][b] = cost[b][a] = c;
    }
    floyd();
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            cost[i][j] = (cost[i][j] <= l ? 1 : inf);
    floyd();
    cin >> q;
    while (q--) {
        cin >> a >> b;
        cout << (cost[a][b] == inf ? -1 : cost[a][b] - 1) << endl;
    }
}

Measured memory_bytes: 896
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define mo 1000000007
typedef long long ll;
using namespace std;
int n;
ll sum[300009],a[300009],ans;
int main()
{
  scanf("%d",&n);sum[0]=0;
  for (int i=1;i<=n;i++)
  {
  	scanf("%lld",&a[i]);
  	sum[i]=(sum[i-1]+a[i])%mo;
  }
  ans=0;
  for (int i=1;i<=n;i++)
  {
  	ans=(ans+(a[i]*(sum[i]-a[i]))%mo)%mo;
  }
  ans=(ans+mo)%mo;
  printf("%lld\n",ans);
  return 0;	
} 

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

// one-based numbering
struct UnionFind {
    vector<int> data;
    // i: (data[i] < 0) -> group size, (data[i] > 0) -> parent;
    UnionFind(int n) {
        data.resize(n+1, -1);
    }
    int find(int x) {
        if(data[x] < 0) return x;
        else return data[x] = find(data[x]);
    }
    int size(int x) {
        return -data[find(x)];
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    bool same(int x, int y) {
        x = find(x); y = find(y);
        return x == y;
    }
};

vector<int> v[100010];
int main() {
    int n; cin >> n;
    UnionFind uf(100010);
    for (int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        v[a].emplace_back(b);
    }
    for (int i = 1; i <= 100010; i++) {
        for (auto &x: v[i]) {
            uf.unite(v[i].front(), x);
        }
    }
    long long cnt = 0;
    for (int i = 1; i <= 100010; i++) {
        if (v[i].empty()) continue;
        cnt += uf.size(v[i].front());
    }
    cout << cnt - n << endl;
    return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int e[100];
	int f[100];
	int g=-1000;
	int h=1000;
	for(int i=0;i<a;i++){
		cin>>e[i];
		g=max(g,e[i]);
	}
	for(int i=0;i<b;i++){
		cin>>f[i];
		h=min(h,f[i]);
	}
	
	for(int i=g+1;i<=h;i++){
		if(i>c&&i<d){
			cout<<"No War"<<endl;
			return 0;
		}
	}
	cout<<"War"<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Remoting.Contexts;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;

namespace Contest
{
    class Program
    {
        private Scanner sc;

        public void Solve()
        {
            sc = new Scanner();
            int n = sc.NextInt();
            int a = sc.NextInt();
            int b = sc.NextInt();
            int aa = a * n;
            int bb = b;
            Console.WriteLine(Math.Min(aa,bb));
        }

        static void Main() => new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _stream = new StreamReader(Console.OpenStandardInput());
        _pos = 0;
        _line = new string[0];
        _separator = ' ';
    }
    private readonly char _separator;
    private readonly StreamReader _stream;
    private int _pos;
    private string[] _line;
    #region get a element
    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = _stream.ReadLine().Split(_separator);
            _pos = 0;
        }
        return _line[_pos++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    #endregion
    #region convert array
    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }
    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }
    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }
    #endregion
    #region get array
    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = _stream.ReadLine().Split(_separator);
        _pos = _line.Length;
        return _line;
    }
    public int[] IntArray()
    {
        return ToIntArray(Array());
    }
    public long[] LongArray()
    {
        return ToLongArray(Array());
    }
    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }
    #endregion
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    ll N,maxi = 0;
    cin >> N;
    for(ll i = 1;i * i <= N;i++){
        if(N % i == 0)maxi = i;
    }
    cout << floor(log10(max(maxi,N/maxi))) + 1 << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

// $ g++ -std=c++11 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
int N,X;
const string yes="Yes",no="No";
const int MAX_N=1e5;
int res[2*MAX_N-1];
int viz[2*MAX_N];
void put(int i, int n) {
  assert(viz[n]==0);
  viz[n]=true;
  res[i]=n;
}

void solve() {
  if(X==2*N-1||X==1) {
    cout<<no<<endl;
    return;
  }
  ZERO(viz);
  MINUS(res);
  put(N-1,X);
  if(X==2) {
    put(N,1);
    put(N-2,3);
    put(N+1,4);
  } else {
    put(N,X+1);
    put(N-2,X-1);
    put(N+1,X-2);
  }
  int cur=1;
  REP(i,2*N-1) if(res[i]==-1) {
    while(viz[cur]) ++cur;
    put(i,cur++);
  }
  cout<<yes<<endl;
  REP(i,2*N-1) cout<<res[i]<<endl;
  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N>>X;
  solve();
  return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

#define roop(a,b) for(int a=0;a<b;++a)

int main(){
	int n;
	cin >> n;
	if(n%2 == 0)printf("%.8f\n",1.0/2.0);
	else printf("%.8f\n",(double)(n/2+1)/n);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;


bool* isPrime;

vector<int> CreatePrimes(int n)
{
	bool* work = new bool[n+1];

	fill(work, work+(n+1), true);
	work[0] = work[1] = false;

	vector<int> res;
	res.push_back(2);
	for (int i = 4; i <= n; i += 2)
		work[i] = false;

	for (int i = 3; i <= n; i += 2)
	{
		if (work[i])
		{
			res.push_back(i);
			for (int j = 2*i; j <= n; j += i)
				work[j] = false;
		}
	}

	isPrime = work;

	return res;
}

int main()
{
	vector<int> primes = CreatePrimes(50000);
	while (true)
	{
		int n;
		scanf("%d\n", &n);
		if (n == 0)
			break;

		int c = 0;
		for (int i = 2; i <= n/2; ++i)
		{
			if (isPrime[i] && isPrime[n-i])
				++c;
		}
		printf("%d\n", c);
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef unsigned long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
//---------------------------------------------
 
 
int main(void)
{
	ll h,n;
	cin>>h>>n;
	ll ans=0;
	vector<int> a(n);
	rep(i,n)
	{
		cin>>a[i];
		ans+=a[i];
	}
 
	if(ans>=h) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
 
 
 
	
 
 
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <iomanip> 
#include <math.h>
#include <unordered_map>
#include <set>
#include <functional> 

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

using namespace std;


int main() {

	ios_base::sync_with_stdio(0);cin.tie(0);
	
	set<int> s;

	int n;
	
	cin >> n;

	rep(i, n) {
		int x;
		cin >> x;
		s.insert(x);
	}

	cout << s.size() << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n; cin >> n;
    vector<char> c(n);
    set<char> st;
    for(int i = 0; i < n; i++)
    {
        cin >> c[i];
        st.insert(c[i]);
    }
    if(st.size() == 3) cout << "Three" << endl;
    else cout << "Four" << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
  int a;
  cin>>a;
  string s;
  cin>>s;
  if(a>=3200){
    cout<<s<<endl;}
  else{
    cout<<"red"<<endl;}
  return 0;
 
 
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return 1;}return 0;}

int n,k;

bool proc(vector<int> a,int l){
    vector<vector<bool>> dp(n+1,vector<bool>(k,0));
    dp[0][0] = true;
    REP(i,n){
        if(i!=l){
            REP(j,k){
                if(j>=a[i]){
                    dp[i+1][j] = (dp[i][j-a[i]]||dp[i][j]);
                }else{
                    dp[i+1][j] = dp[i][j];
                }
            }
        }else{
            REP(j,k){
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    bool rtn = false;
    REP(i,min(a[l],k)){
        if(dp[n][k-1-i]){
            rtn = true;
            break;
        }
    }
    return rtn;
}

int main(){
    cin >> n >> k;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }
    SORT(a);
    int left = -1;
    int right = n;
    int mid;
    
    while(right-left>1){
        mid = (left+right)/2;
        if(proc(a,mid)){
            right = mid;
        }else{
            left = mid;
        }
    }
    put(right);
    return 0;
}



Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {

	public static final int SENTINEL = 2000000000;
	static int[] MERGETMPA;
	static int[] MERGETMPB;
	static int[] S;
	static int count = 0;

	public static void main(String[] args) throws Exception {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();

		MERGETMPA = new int[n / 2 + 2];
		MERGETMPB = new int[n / 2 + 2];
		S = new int[n];
		for(int i = 0 ; i < n ; i++) S[i] = input.nextInt();
		mergeSort(0,n);
		input.close();
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < S.length ; i++){
			sb.append(String.valueOf(S[i]));
			sb.append(" ");
		}
		System.out.println(sb.toString().trim());
		System.out.println(count);
	}


	public static void mergeSort(int left,int right){
		if(right - left > 1){
			int mid = (right + left) / 2;
			mergeSort(left,mid);
			mergeSort(mid,right);
			merge(left,mid,right);
		}
	}

	public static void merge(int left,int mid,int right){
		int i = 0;
		int s = left;
		for(i = 0 ; i < mid - left ; i++) MERGETMPA[i] = S[s++];
		MERGETMPA[i] = SENTINEL;
		s = mid;
		for(i = 0 ; i < right - mid ; i++) MERGETMPB[i] = S[s++];
		MERGETMPB[i] = SENTINEL;

		int x = 0;
		int y = 0;
		for(i = left ; i < right; i++){
			count++;
			if(MERGETMPA[x] <= MERGETMPB[y]){
				S[i] = MERGETMPA[x];
				x++;
			}else{
				S[i] = MERGETMPB[y];
				y++;
			}
		}

	}

}

Measured memory_bytes: 169844
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;

int main(){
	vector<char> v;
	int n;
	int count;
	string s;
	while(1){
		cin >> s;
		if(s[0] == '#')break;
		v.clear();
		for(int i = 0;i < s.size();i++){
			if(s[i] == 'w'){
				v.push_back('w');
			}
			else if(s[i] == 'n'){
				v.push_back('n');
			}
		}
		count = 1;
		int res = 0;
		for(int j = v.size()-1;j >= 0;j--){
			if(j == v.size()-1){
				if(v[j] == 'w')res = 90;
				else if(v[j] == 'n')res = 0;
				continue;
			}
			res *= 2;
			count *= 2;
			if(v[j] == 'w'){
				res += 90;
			}
			else if(v[j] == 'n'){
				res -= 90;
			}
		}

		while(res % 2 == 0 && count > 1){
			res /= 2;
			count /= 2;
		}

		if(res != 0 && count != 1)cout << res << '/' << count << endl;
		else cout << res << endl;
	}
	return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
template <typename T> using vec = vector<T>;
typedef vec<int> vi;
typedef vec<ll> vl;


template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }


const int MAX_N = 100000;
int n;
int a[MAX_N];
ll ans[MAX_N];

int main()
{
  cin >> n;
  forn(i,n) {
    cin >> a[i];
  }


  vec<pii> idx;
  map<int,int, greater<int>> cnt;
  idx.emplace_back(0,-1); // 狭義単調増加列

  for (int i = 0; i < n; i++) {
    if (idx.back().fst < a[i]) {
      idx.emplace_back(a[i],i);
    }

    cnt[a[i]]++;
  }


  vec<pil> cnt2;

  for (auto p : cnt) {
    cnt2.push_back(p);
  }

  ll ci = 0;
  ll c = 0;
  for (int i = idx.size()-1; i >= 1; i--) {
    int x,y;
    tie(x,y) = idx[i];

    ans[y] = 1LL*(x-idx[i-1].fst)*c;

    while (ci < cnt2.size() && cnt2[ci].fst > idx[i-1].fst) {
      ans[y] += 1LL*(cnt2[ci].fst-idx[i-1].fst)*cnt2[ci].snd;
      c += cnt2[ci].snd;
      ci++;
    }
  }

  forn(i,n)
    cout << ans[i] << "\n";

  return 0;
}


Measured memory_bytes: 9456
#include <stdio.h>

int main(void) {

	int x,y;
	scanf("%d %d",&x,&y);

    while(x!=0 || y!=0){
    	if(x<=y){
    		printf("%d %d\n",x,y);
    	}else {
    		printf("%d %d\n",y,x);
    	}
    	scanf("%d %d",&x,&y);
    }

	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#include <math.h>
#include <iomanip>
using namespace std;
bool pr(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    { if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int q;
   	int ans=0;
   	cin>>q;
   	int l[q],r[q];
	bool p[100001]={};
	vector<int> prim;
	p[2]=1;
	p[3]=1;
	p[5]=1;
	p[7]=1;
	p[11]=1;
	p[13]=1;
	p[17]=1;
	p[19]=1;
	p[23]=1;
	p[29]=1;
	p[31]=1;
	p[37]=1;
	p[41]=1;
	p[43]=1;
	p[47]=1;
	
	prim.push_back(2);
	for(int i=29;i<=100000;i=i+2){
		if((i%2)!=0&&(i%3)!=0&&(i%5)!=0&&(i%7)!=0&&(i%7)!=0&&(i%11)!=0&&(i%13)!=0&&(i%17)!=0&&(i%19)!=0&&(i%23)!=0&&(i%29)!=0&&(i%31)!=0&&(i%37)!=0&&(i%41)!=0&&(i%43)!=0&&(i%47)!=0){
		p[i]=pr(i);}
	}
	for(int i=3;i<=100000;i=i+2){
		if(p[i]){prim.push_back(i);}
	}
	int si=prim.size();
   	for(int i=0;i<q;++i){
   		ans=0;
   		cin>>l[i]>>r[i];
   		vector<int>::iterator lit = lower_bound(prim.begin(), prim.end(), l[i]);
   		int tmp=lit-prim.begin();
   		if(tmp>=si-1){goto end1;}
   		for(int j=tmp;prim[j]<r[i]+1;j++){
   			if(p[(prim[j]+1)/2]){ans++;}
   			if(j==si-1){break;}
   		}
   		end1:;
   		cout<<ans<<endl;
   	}
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
using namespace std;
void kaitou1(){
    int n;
    string s;
    cin>>n>>s;
    int rsum[1000000];
    rsum[0]=(s[0]=='E'?1:0);
    for(int i=1;i<n;i++){
        rsum[i]=(s[i]=='E'?1:0)+rsum[i-1];
    }
    int ans=1000000;
    for(int i=0;i<n;i++){
        int mi=i-(i==0?0:rsum[i-1])+rsum[n-1]-rsum[i];
        ans=min(ans,mi);
        
    }
    cout<<ans<<endl;
    
 
}
void kaitou2(){
    int n;
    string s;
    cin>>n>>s;
    int esum[1000000],wsum[1000000];
    
    for(int i=0;i<n;i++){wsum[i]=(i==0?0:wsum[i-1])+(s[i]=='W'?1:0);}
    for(int i=n-1;i>=0;i--){esum[i]=(i==n-1?0:esum[i+1])+(s[i]=='E'?1:0);}
    int ans=10000000;
    for(int i=0;i<n;i++){
        int mi=(i==0?0:wsum[i-1])+(i==n-1?0:esum[i+1]);
        ans=min(ans,mi);
    }
    cout<<ans<<endl;
}
int main(){
    //kaitou1();
    kaitou2();
 
return 0;
}


Measured memory_bytes: 7812
#include <cstdio>
#include <cstring>
#include <algorithm>
#define max_n 15
using namespace std;
struct pt{
	int x,y,p,id;
};
pt a[max_n+1],b[max_n+1];
int n;
long long ans[max_n+1];
int typ[max_n+1],dis[max_n+1],dis2[max_n+1];
template<typename T1,typename T2>void minify(T1&x,const T2&y){
	y<x&&(x=y);
}
void dfs(int top,int num=0,int now=1,int bef=0){
//	printf("dfs %d %d %d %d\n",top,num,now,bef);
	if(top==n){
		while(now<=n){
			dis[a[now].id]=min(a[now].x-a[bef].x,dis2[a[now].id]);
			++now;
		}
//		for(int i=0; ++i<=n; printf("&&%d:%d %d\n",i,dis[i],dis2[i]));
		long long tas=0;
		int tmp=1,j=0;
//		puts("A");
		for(int i=0; ++i<=n; )
			if(typ[b[i].id]==2){
//				printf("*%d\n",i);
				while(tmp<i&&b[i].y-b[tmp].y>=b[tmp].y-b[j].y){
					tas+=min(dis[b[tmp].id],b[tmp].y-b[j].y)*(long long)(b[tmp].p);
					++tmp;
				}
				while(tmp<=i){
					tas+=min(dis[b[tmp].id],b[i].y-b[tmp].y)*(long long)(b[tmp].p);
					++tmp;
				}
				j=i;
			}
//		puts("B");
		while(tmp<=n){
			tas+=min(dis[b[tmp].id],b[tmp].y-b[j].y)*(long long)(b[tmp].p);
			++tmp;
		}
		minify(ans[num],tas);
//	puts("ret");
		return;
	}
	++top;
	while(now<top&&a[top].x-a[now].x>=a[now].x-a[bef].x){
		dis[a[now].id]=min(dis2[a[now].id],a[now].x-a[bef].x);
//		printf("%d %d %d %d %d\n",now,bef,a[now].x,a[bef].x,dis[a[now].id]);
		++now;
	}
	dfs(top,num,now,bef);
	++num,typ[a[top].id]=2;
	dfs(top,num,now,bef);
	typ[a[top].id]=1;
	while(now<=top){
		dis[a[now].id]=min(dis2[a[now].id],a[top].x-a[now].x);
		++now;
	}
	dfs(top,num,now,top);
//	puts("ret");
}
bool cmp1(const pt&x,const pt&y){
	return x.x<y.x;
}
bool cmp2(const pt&x,const pt&y){
	return x.y<y.y;
}
int main(){
	scanf("%d",&n),memset(ans,127,sizeof(ans)),memset(typ,0,sizeof(typ));
	for(int i=0; ++i<=n; scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].p),a[i].id=i);
	memcpy(b,a,sizeof(a));
	for(int i=0; ++i<=n; dis2[i]=min(abs(a[i].x),abs(a[i].y)));
	stable_sort(a+1,a+n+1,cmp1),stable_sort(b+1,b+n+1,cmp2),b[0].y=a[0].x=-10000000;
	dfs(0);
	for(int i=-1; ++i<=n; printf("%lld\n",ans[i]));
	return 0;
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pi 3.1415926535
#define endl '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll inf=1e18;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
//ll fac[250001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   ll h,w,n,a,b;
   cin>>h>>w>>n;
   a=max(h,w);
   b=n/a;
   if(n%a!=0)b++;
   cout<<b<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)n;++i)
int ans;
void dfs(int d,int sum,int *a,int c, int rem) {
  if (c+rem/10<ans) return;
  ans = max(ans, c);
  if (sum==10) dfs(1,0,a,c+1,rem);
  else {
    if (d<9)dfs(d+1,sum,a,c,rem);
    if (a[d]&&sum+d<=10) {
      a[d]--;
      dfs(d,sum+d,a,c,rem-d);
      a[d]++;
    }
  }
}
int main() {
  int n;
  while(cin>>n,n) {
    int a[10]={};
    REP(i,n) {
      int b;cin>>b;
      a[b]++;
    }
    int t = 0;
    for (int i=1; i<=4; ++i) {
      int m = min(a[i], a[10-i]);
      a[i] -= m;
      a[10-i] -= m;
      t += m;
    }
    t += a[5] / 2;
    a[5] %= 2;
    int rem = 0;
    REP(i,10) rem+=a[i]*i;
    ans = 0;
    dfs(1,0,a,0,rem);
    cout << t+ans << endl;
  }
}

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

int main()
{
  int N;
  std::cin >> N;
  std::vector<int> v(N);
  for (int i = 0; i < N; i++) std::cin >> v.at(i);
  sort(v.begin(), v.end());
  double ans = v.at(0);
  for (int i = 1; i < N; i++) ans = (ans + v.at(i))/2.0;
  std::cout << ans << std::endl;
}


Measured memory_bytes: 256