akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int t = Integer.parseInt(sc.next());
        double a = Double.parseDouble(sc.next());
        double minDiff = Integer.MAX_VALUE;
        int ans = 0;

        List<Integer> heightList = new ArrayList<>();

        for (int i = 1; i <= n; i++) {
        	int x = Integer.parseInt(sc.next());
        	double ti = t - x * 0.006;
        	if (Math.abs(a - ti) < minDiff) {
                ans = i;
                minDiff = Math.abs(a - ti);
        	}
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
let () =
  Scanf.scanf "%d %d" @@ fun m k ->
  if m <= 1 then
    if k = 0 then begin
      for i = 0 to (1 lsl m) - 1 do
        Printf.printf "%d %d " i i
      done;
      print_newline ()
    end
    else print_endline "-1"
  else if k < (1 lsl m) then begin
      for j = (1 lsl m) - 1 downto 0 do
        if j <> k then Printf.printf "%d " j
      done;
      Printf.printf "%d " k;
      for j = 0 to (1 lsl m) - 1 do
        if j <> k then Printf.printf "%d " j
      done;
      Printf.printf "%d " k;
      print_newline ()
  end else print_endline "-1"



Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mxn= 5e4+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
//#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    int n,k;
    cin>>n>>k;
    map<int, int> mp;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        mp[x]++;
    }
    vector<int> arr;
    for(auto x: mp){
        arr.push_back(x.second);
    }
    sort(arr.begin(),arr.end()); 
    int ans=0;
    for(int i=0;i<arr.size();i++){
        if((int)arr.size()-i<=k)break;
        else ans=ans+arr[i];
    }
    cout<<ans;
}

Measured memory_bytes: 13620
import java.util.*;
class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		StringBuffer sb = new StringBuffer();
		for(int i=n;i<=999;i++)
		{
			if(check(i))
			{
				System.out.println(i);
				break;
			}

		}
	}

	static boolean check(int n)
	{
		int x=n%10;
		n/=10;
		if(n%10!=x)
			return false;
		n/=10;
		if(n%10!=x)
			return false;
		return true;
	}
}

Measured memory_bytes: 21716
#include<iostream>
#include<vector>
#define N 1100001
using namespace std;


bool p[N];
vector<int> pr;
int num[N];

int main(){

  for(int i=0;i<N;i++)p[i] = true;
  p[0] = p[1] = false;

  for(int i=2;i*i<N;i++){
    if(p[i]){
      for(int j=2*i;j<N;j+=i)p[j] = false;
    }
  }

  for(int i=0;i<N;i++)if(p[i])pr.push_back(i);

  long long A,B;
  cin >> A >> B;

  long long m = max(2LL,A-B);
  for(int i=0;i<2*B+1;i++)num[i] = 100000000;

  for(int i=0;i<(int)pr.size();i++){
    if(A+B<pr[i])break;
    long long tmp = (m+pr[i]-1)/pr[i] * pr[i];
    for(long long j = tmp;j<=A+B;j+=pr[i]){
 
      if(num[j-(A-B)]<0)continue;
      int n = 0;
      long long hoge = j;
      while(!(hoge%pr[i])){
	hoge /= pr[i];
	n++;
      }

      if(num[j-(A-B)]>=n)num[j-(A-B)] = n;
      else num[j-(A-B)] = -1;
    }
  }

  int ans = 0;
  long long C = (A-B<2LL)?(2LL+B-A):0LL;
  for(int i=C;i<2*B+1;i++)if(0<=num[i])ans++;
  cout << ans << endl;
}

Measured memory_bytes: 6324
import heapq

N, M = map(int, input().split())
values = list(map(int, input().split()))
sortedValues = []

for v in values:
    heapq.heappush(sortedValues, (-1)*v)

for i in range(M):
    heapq.heappush(sortedValues, int((heapq.heappop(sortedValues) * 1/2)))

print((-1) * sum([heapq.heappop(sortedValues) for i in range(len(sortedValues))]))


Measured memory_bytes: 14180
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

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

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

int n, m, x;

int r = 0;
vector<int> nowm;
vector<vector<int>> a;
vector<int> c;

void func(int now, int sum)
{
	if (sum > r)
		return;

	if (now == n)
	{
		for (int i = 0; i < m; i++)
			if (nowm[i] < x)
				return;
		r = sum;
		return;
	}

	func(now + 1, sum);

	for (int i = 0; i < m; i++)
		nowm[i] += a[now][i];
	func(now + 1, sum + c[now]);
	for (int i = 0; i < m; i++)
		nowm[i] -= a[now][i];
}

int main()
{
	cin >> n >> m >> x;
	a.resize(n);
	c.resize(n);
	nowm.resize(m);
	int maxa = 1;

	for (int i = 0; i < n; i++)
	{
		a[i].resize(m);
		cin >> c[i];
		maxa += 100000;
		for (int j = 0; j < m; j++)
			cin >> a[i][j];
	}

	r = maxa;

	func(0, 0);

	if (r == maxa)
		r = -1;
	printf("%d", r);
	return 0;
}

Measured memory_bytes: 3256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cctype>
#include <cstdio>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(x) sort(x.begin(),x.end())
#define REVE(x) reverse(x.begin(),x.end())
#define all(x) (x).begin(),(x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(),x.end(),x.begin() ,::toupper);
#define down(x) transform(x.begin(),x.end(),x.begin() ,::tolower);
using LL = long long;
using ULL = unsigned long long;
#define FOR(i, m, n) for(int i = m;i < n;i++)
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 main(){
    int n,a,b;
    vector<int> c{0,0,1,0,2,0,2,0,0,2,0,2,0};
    cin >> a >> b;
    cout<<(c[a]==c[b]?"Yes": "No");
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int p[100005]={0};

int find(int a){
    if(p[a]==a)
        return a;
    return p[a] = find(p[a]);
}
void disjoint(int a, int b){
    p[find(p[b])] = find(p[a]);
}

int main() {
    
    int poke,q,tmp;
    cin>>poke>>q;
    for(int i=0;i<=poke;i++){
        p[i] = i;
    }
    int n,m;
    for(int i=0;i<q;i++){
        cin>>n>>m>>tmp;
        disjoint(n,m);
    }
    int ans = 0;
    for(int i=1;i<=poke;i++)
        if(find(i)==i)ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if((a+b)==c || (a+c)==b || (b+c)==a)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
n,a,b,c = map(int,input().split())

sl = []
for _ in range(n):
    s = input()
    sl.append(s)

yusen = []
before = sl[0]
co = 0
for s in sl:
    if before == s:
        co += 1
    else:
        target = list(set(list(s)) & set(list(before)))[0]
        for i in range(co):
            yusen.append(target)
        before = s
        co = 1
else:
    for i in range(co):
        yusen.append("C")




ansl = []
for i in range(n):
    s = sl[i]
    if s == "AB":
        if a > b:
            ansl.append("B")
            a -= 1
            b += 1
        elif a < b:
            ansl.append("A")
            a += 1
            b -= 1
        else:
            if n-1 == i:
                ansl.append("A")
                a += 1
                b -= 1
            elif sl[i+1] == "AC":
                ansl.append("A")
                a += 1
                b -= 1
            else:
                ansl.append("B")
                a -= 1
                b += 1
    if s == "BC":
        if b > c:
            ansl.append("C")
            b -= 1
            c += 1
        elif b < c:
            ansl.append("B")
            b += 1
            c -= 1
        else:
            if n-1 == i:
                ansl.append("B")
                b += 1
                c -= 1
            elif  sl[i+1] == "AB":
                ansl.append("B")
                b += 1
                c -= 1
            else:
                ansl.append("C")
                b -= 1
                c += 1
    if s == "AC":
        if c > a:
            ansl.append("A")
            c -= 1
            a += 1
        elif c < a:
            ansl.append("C")
            c += 1
            a -= 1
        else:
            if n-1 == i:
                ansl.append("C")
                c += 1
                a -= 1
            elif sl[i+1] == "BC":
                ansl.append("C")
                c += 1
                a -= 1
            else:
                ansl.append("A")
                c -= 1
                a += 1
    if a < 0 or b < 0 or c < 0:
        print("No")
        exit()

print("Yes")
for a in ansl:
    print(a)


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

int k;

int main() {
    cin >> k;
    if(k%2 == 0 || k%5 == 0) {
        cout << -1;
        return 0;
    }

    int n = 0, i = 1;
    while(true) {
        n = (n*10+7)%k;
        if(n == 0) {
            cout << i;
            return 0;
        }
        i++;
    }
}


Measured memory_bytes: 3592
require 'set'

n, m = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| line.strip.split.map(&:to_i) }

graph = Array.new(n+1) { [] }
r_graph = Array.new(n+1) { [] }
edges = []
abc.each do |a, b, c|
  graph[a] << b
  r_graph[b] << a
  edges << [a, b, -c]
end

# calc from_1, from_n
def reachable(s, graph)
  q=[s]
  visited = Set.new(q)
  until q.empty?
    c = q.shift
    graph[c].each do |to|
      next if visited.include?(to)
      visited.add(to)
      q.push(to)
    end
  end
  visited
end
from_1 = reachable(1, graph)
from_n = reachable(n, r_graph)
available_nodes = from_1 & from_n

# retrench edges
edges = edges.select {|a, b, _| available_nodes.include?(a) && available_nodes.include?(b) }

# w-f method
INF = 10**14
updated = false
dist = Array.new(n+1, INF)
dist[1]=0
n.times do
  updated = false
  edges.each do |from, to, cost|
    next if dist[from]==INF
    if dist[to] > dist[from] + cost
      dist[to] = dist[from] + cost
      updated = true
    end
  end
  break unless updated
end

if updated
  puts 'inf'
  exit
end


#answer
#p from_1
#p from_n
#p available_nodes

#p dist
p -dist[n]


Measured memory_bytes: 2556
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int[] num = new int[n + 1];
			for (int i = 0; i < n; i++)
				num[i] = scanner.nextInt();
			num[n] = 1 << 30;
			System.out.print(num[0]);
			for (int i = 1; i < n; i++)
				if (num[i - 1] + 1 == num[i])
					if (num[i] + 1 == num[i + 1])
						continue;
					else
						System.out.print("-" + num[i]);
				else
					System.out.print(" " + num[i]);
			System.out.println();
		}
	}
}

Measured memory_bytes: 26468
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int INF = 1e9;
 
int main()
{
  int n, m;
  fscanf(stdin, "%d %d", &n, &m);
  vector<vector<ll> > a(n, vector<ll>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      fscanf(stdin, "%lld", &a[i][j]);
    }
  }
  vector<ll> b(m);
  for (int i = 0; i < m; ++i) {
    fscanf(stdin, "%lld", &b[i]);
  }
  vector<ll> c(n, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      c[i] += a[i][j] * b[j];
    }
  }
 
  for (int i = 0; i < n; ++i) {
    fprintf(stdout, "%lld\n", c[i]);
  }
  return 0;
}

Measured memory_bytes: 3300
N,x=map(int,input().split())

A=[int(a) for a in input().split()]

A.sort()

ans=0
for i in range(N):
  x-=A[i]
  if x >= 0:
    ans+=1
  else:
    break
    
if x>0:
  print(ans-1)
else:
  print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    int z=a+b;
    int x=a*b;
    int c=a-b;
    int mx=max(z,x);
    mx=max(mx,c);
    cout<<mx;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c=0,i,p[1010];
int main()
{
	cin>>a>>b;
	for(i=0;i<a;++i)cin>>p[i];
	sort(p,p+a);
	for(i=0;i<b;++i)c+=p[i];
	cout<<c;
}


Measured memory_bytes: 3580
#include<stdio.h>

int binarySearch(int,int *,int);

int main(){
  int a,S[100000],b,T[50000],i,j,k=0;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&b);
  for(j=0;j<b;j++){
    scanf("%d",&T[j]);
    if(binarySearch(a,S,T[j])==1)
      k++;
    else if(binarySearch(a,S,T[j])==0)
      continue;
  }
  printf("%d\n",k);
  return 0;
}
int binarySearch(int n,int *A,int key){
  int left,right,mid;
  left = 0;
  right = n;
  while(left<right){
    mid = (left+right)/2;
    if(A[mid]==key)
      return 1;
    else if(key<A[mid])
      right = mid;
    else
      left = mid+1;
  }
  return 0;
}
      
	      



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

struct Graph
{
    int N;
    struct Edge { int source, target, weight; };
    vector<vector<Edge>> adjacency_list;

    Graph(int N) : N(N), adjacency_list(N) {}

    int add_vertex()
    {
        adjacency_list.push_back({});
        return N++;
    }

    void add_edge(int a, int b, int w) { adjacency_list[a].push_back({a, b, w}); }

    int distance(const int start, const int finish) const
    {
        auto seen = vector<bool>(N);
        auto distances = vector<int>(N, -1);

        auto queue = std::priority_queue<pair<int,int>, vector<pair<int, int>>, greater<pair<int, int>>>();
        queue.push({0, start});
        while (!queue.empty())
        {
            auto s = queue.top(); queue.pop();
            if (seen[s.second]) continue;
            seen[s.second] = true;
            distances[s.second] = s.first;
            if (s.second == finish) break;

            for (const auto e : adjacency_list[s.second])
                queue.push({s.first+e.weight, e.target});
        }

        return distances[finish];
    }
};

struct Subway { int source, target, company; };

int solve(const int N, const vector<Subway>& subways)
{
    auto graph = Graph(N);

    auto ids = map<pair<int, int>, int>();
    const auto id = [&](int station, int company)
    {
        if (ids.count({station, company})) return ids[{station, company}];
        else
        {
            const auto substation = ids[{station, company}] = graph.add_vertex();
            graph.add_edge(station, substation, 1);
            graph.add_edge(substation, station, 0);
            return substation;
        }
    };

    for (const auto s : subways)
    {
        const auto v = id(s.source, s.company), w = id(s.target, s.company);
        graph.add_edge(v, w, 0);
        graph.add_edge(w, v, 0);
    }

    return graph.distance(0, N-1);
}

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

    auto subways = vector<Subway>();
    for (auto i = 0; i < M; i++)
    {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        subways.push_back({a, b, c});
    }

    cout << solve(N, subways) << endl;
}


Measured memory_bytes: 64472
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vll vector <pll>
#pragma 03
using namespace std;
ll INF = 1e18;
ll weight[100005], val[100005];
ll dp[105][100005];
int main(){
	ll n, w;
	cin >> n >> w;
	for (ll i = 0; i<n; i++) cin >> weight[i] >> val[i];
	for (ll i = 0; i<105; i++){
		for (ll j = 0; j<100005; j++) dp[i][j] = INF;
	}
	for (ll i = 0; i<100005; i++) dp[0][i] = INF;
	dp[0][0] = 0;
	for (ll i = 1; i<=n; i++){
		for (ll j = 0; j<100005; j++){
			if (j + val[i-1] < 100005) dp[i][j + val[i-1]] = min(dp[i][j + val[i-1]], dp[i-1][j] + weight[i-1]);
			dp[i][j] = min(dp[i][j], dp[i-1][j]);
		}
	}
	ll mx = 0;
	for (ll j = 0; j<100005; j++){
		for (int i = 0; i<=n; i++){
			if (dp[i][j] <= w) mx = max(mx, j); 
		}
	}
	cout << mx << endl;
	return 0;
}
 


Measured memory_bytes: 82304
N = int(input())
T, A = map(int, input().split())
H = map(lambda x: abs(1000 * A - (1000 * T - int(x) * 6)), input().split())
score = float("inf")
pos = 0
for i, a in enumerate(H, 1):
    if score > a:
        score = a
        pos = i
print(pos)


Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

res = 0
pre = -10
for a in A:
    a -= 1
    res += B[a]
    if pre == a - 1:
        res += C[pre]
    pre = a

print(res)

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    cnt1 = 0
    for j in range(N):
        cnt1 += (A[j]>>i)&1
    ans += cnt1 * (N-cnt1) * 2**i
    ans %= 10**9+7

print(ans)

Measured memory_bytes: 122936
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i,a,b) for(int i=a;i<=b;i++)
#define g(i,a,b) for(int i=a;i>=b;i--)
#define mp make_pair
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout<<"Case #"<<x<<": "
#define op1(x) cout<<"Scenario #"<<x<<": "
#define endl "\n"
using namespace std;
ll mod = 1000000007;
const ll INF = 1e18;
const int N = 20;
map<ll, ll> fr;

ll dp[200001];

ll foo(ll n)
{
	if (n == 0) return dp[0] = 0;

	if (dp[n] != -1) return dp[n];

	ll res = 0;
	ll d = bits(n);
	res = 1 + foo(n % d);

	return dp[n] = res;
}

ll power(ll x, ll y)
{
	if (y == 0)
		return 1;
	ll p = power(x, y / 2) % mod;
	p = (p % mod * p % mod) % mod;

	return (y % 2 == 0) ? p % mod : (x % mod * p % mod) % mod;
}

void solve(int t)
{
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i <= 200000; i++) ll x = foo(i);

	//for (int i = 1; i <= 10; i++) cout << dp[i] << endl;
	ll n;
	cin >> n ;
	string s;
	cin >> s;
	ll cn = 0;
	ll a = 0, b = 0, c = 0;
	for (int i = 0; i < n; i++)
	{
		ll d = (s[i] - '0');
		cn += d;
	}

	if (cn == 0)
	{
		for (int i = 0; i < n; i++)
		{
			cout << 1 << endl;
		}
		return;
	}




	mod = cn + 1;
	//cout << mod << endl;
	for (int i = 0; i < n; i++)
	{
		ll d = (s[i] - '0');
		a += d * power(2, (n - i - 1)) % mod;
		a %= mod;
	}

	if (cn > 1) {
		mod = cn - 1;
		for (int i = 0; i < n; i++)
		{
			ll d = (s[i] - '0');
			c += d * power(2, (n - i - 1)) % mod;
			c %= mod;
		}
	}

	//cout << a << " " << b << " " << c << endl;


	for (int i = 0; i < n; i++)
	{
		ll d = (s[i] - '0');
		if (d == 0)
		{
			mod = cn + 1;
			cout << dp[(a + power(2, (n - i - 1))) % (mod)] + 1;
		}
		else
		{
			if (cn == 1)
			{
				cout << 0 << endl;
				continue;
			}
			mod = cn - 1;
			cout << dp[(c - power(2, (n - i - 1)) % (cn - 1) + mod) % (mod)] + 1;
		}
		cout << endl;

	}

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);


	int t = 1;
	//cin >> t;

	for (int i = 1; i <= t; i++)
	{
		solve(i);

	}
}

Measured memory_bytes: 5320
(defun num-to-char (num)
  (code-char (+ num (char-code #\0))))

(defun solve (n m pairs)
  (declare (ignore m))
  (let ((num (make-array n :element-type 'character :initial-element #\-)))
    (loop for (s . c) in pairs
          if (char= #\- (aref num (1- s)))
          do (setf (aref num (1- s)) (num-to-char c))
          else if (char/= (aref num (1- s)) (num-to-char c))
          do (return-from solve -1))
    (when (and (< 1 n)
               (char= (aref num 0) #\-))
      (setf (aref num 0) #\1))
    (loop for i from 0
          for n across num
          if (char= n #\-)
          do (setf (aref num i) #\0))
    (if (and (< 1 n)
             (char= (aref num 0) #\0))
        -1
        (read-from-string num))))

#-swank
(let* ((n (read))
       (m (read))
       (pairs (loop repeat m collect (cons (read) (read)))))
  (format t "~A~%" (solve n m pairs)))


Measured memory_bytes: 20456
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

struct eg {
  int src, dst, w;
};

int construct(int l, vector<eg> &es) {
  if(l == 1) {
    return 1;
  }
  if(l == 2) {
    construct(1, es);
    es.push_back({1, 2, 0});
    es.push_back({1, 2, 1});
    return 2;
  }
  if(l % 3 == 0) {
    int sz = construct(l / 3, es);
    es.push_back({sz, sz + 1, 0});
    es.push_back({sz, sz + 1, l / 3});
    es.push_back({sz, sz + 1, (l / 3) * 2});
    return sz + 1;
  }
  if(l % 3 == 1) {
    int sz = construct(l - 1, es);
    es.push_back({1, sz, l - 1});
    return sz;
  }
  int sz = construct(l - 2, es);
  es.push_back({1, sz, l - 1});
  es.push_back({1, sz, l - 2});
  return sz;
}

int main() {
  ios::sync_with_stdio(false);
  int l;
  cin >> l;
  vector<eg> es;
  int n = construct(l, es);
  cout << n << " " << es.size() << endl;
  FOR(e,es) {
    cout << e.src << " " << e.dst << " " << e.w << endl;
  }

  return 0;
}


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

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

typedef long long lint;

using namespace std;

int main(){
  bool a[3]={true,true,true};
  REP(i,2){
    int A;
    cin>>A;
    a[A-1]=false;
  }
  REP(i,3)if(a[i])cout<<i+1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

int main(void){
    int N=0;
    long long H, ans=0;
    std::cin >> H;

    while (true){
        H /= 2LL;
        if (H == 0) break;
        ++N;
    }

    for (int i=0; i<=N; i++){
        ans += pow(2, i);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 4052
a,b,m = map(int,input().split())

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

ans = min(A)+min(B)

for i in range(m):
  x,y,c = map(int,input().split())
  cost = A[x-1] + B[y-1] - c
  if cost < ans:
    ans = cost

print(ans)    

Measured memory_bytes: 24780
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

#define REP(I, S, E) for (decltype(S + E) I = (S), _E = (E); I < _E; ++I)
#define REP_REV(I, S, E) for (decltype(S + E) I = (E)-1, _S = (S); I >= _S; --I)

using namespace std;
using ll = long long;

// T のラッパー。T に定まった順序とは逆順の大小関係を持つ。
template<typename T>
struct Rev {
    T inner_;

    auto operator <(const Rev<T>& other) const -> bool {
        return other.inner_ < inner_;
    }
};

auto main() -> int {
    int N;
    string S;
    int P;
    cin >> N;

    vector<tuple<string, Rev<int>, int>> R;
    REP(i, 0, N) {
        cin >> S >> P;
        R.emplace_back(S, Rev<int>{P}, i);
    }

    sort(begin(R), end(R));

    REP(i, 0, N) {
        cout << get<2>(R[i]) + 1 << endl;
    }
    return 0;
}


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

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  
  for (A; A <= B; A++) {
    if (A % K == 0) {
      cout << "OK" << endl;
      break;
    }
    else if (A == B) {
      cout << "NG" << endl;
    }
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int N; cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++) cin>>a[i];
    sort(a.begin(),a.end());

    int ans=0;
    for(int i=0;i<N-1;i++) for(int j=i+1;j<N;j++){
        int k=lower_bound(a.begin(),a.end(),a[i]+a[j])-a.begin();
        ans+=k-(j+1);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <cstring>
//#define LOCAL
using namespace std;
typedef long long ll;
const int mx=2e5+10;
ll a[mx], b[mx];

void display(ll n, ll num[mx]){
    for(ll i=1;i<=n;i++){
        if(1==i)printf("%lld", num[i]);
        else printf(" %lld", num[i]);
    }
    puts("");
}


int main() {
#ifdef LOCAL
ifstream fin("1.txt");
streambuf*p;
p=cin.rdbuf(fin.rdbuf());
#endif // LOCAL
ll n, m;
cin>>n;
for(ll i=0;i<n;i++) cin>>a[i];
cin>>m;
for(ll i=0;i<m;i++) cin>>b[i];
(includes(a, a+n, b, b+m))?puts("1"):puts("0");


#ifdef LOCAL
fin.close();
#endif // LOCAL
}




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

int n, m;
vector<int> g[100005];
bool used[100005];
vector<int> ans;
int conv[100005];
int ret[100005];

void dfs(int u)
{
	if (used[u]) return;
	used[u] = true;

	for (int i = 0;i < g[u].size();i++) {
		dfs(g[u][i]);
	}
	ans.push_back(u);
}

void tsort()
{
	for (int i = 0;i < n;i++) dfs(i);
	reverse(ans.begin(), ans.end());
}

int root[100005];

int main()
{
	cin >> n >> m;
	for (int i = 0;i < n - 1 + m;i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		root[v]++;
		g[u].push_back(v);
	}

	tsort();


	int Root = -1;
	for (int i = 0;i < n;i++) {
		if (root[i] == 0) Root = i;
	}

	for (int i = 0;i < n;i++) {
		conv[ans[i]] = i;
		ret[i] = Root;
	}

	ret[Root] = 0;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < g[i].size();j++) {
			int v = g[i][j];
			if (conv[i] > conv[ret[v]]) {
				ret[v] = i;
			}
		}
	}

	for (int i = 0;i < n;i++) {
		if (i != Root)
			cout << ret[i] + 1 << endl;
		else
			cout << 0 << endl;
	}

	return 0;
}


Measured memory_bytes: 10228
A, B, C, D, E, F = map(int, input().split())
W = set()
S = set()
wtr = 100*A
sgr = 0

i = 1
j = 0
while(wtr <= F):
  while(wtr <= F):
    W.add(wtr)
    wtr = i*A*100 + j*B*100
    j +=1
  i +=1
  j = 0
  wtr = i*A*100 + j*B*100
  
i = 0
j = 0
while(sgr <= F):
  while(sgr <= F):
    S.add(sgr)
    sgr = i*C + j*D
    j +=1
  i +=1
  j = 0
  sgr = i*C + j*D
answtr = 100*A
anssgr = 0
  
for wtr in W:
  for sgr in S:
    if (sgr*(answtr+anssgr) > anssgr*(wtr+sgr)) and (sgr*(100+E)<=E*(wtr+sgr) and (wtr+sgr<=F)):
      answtr = wtr
      anssgr = sgr
print("{} {}".format(answtr+anssgr, anssgr))

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

int main(){
    int x, a, b;
    cin >> x >> a >> b;
    if ( (x-a)*(x-a) > (x-b)*(x-b) ){
        cout << "B" << endl;
    }
    else {
        cout << "A" << endl;
    }
}

Measured memory_bytes: 3516
def getInput():
    a = input().split()
    return a

def convNum(s):
    if s.isdigit():
        return int(s)
    else:
        return s
def initArr(len_a):
    return 0, [0 for i in range(len_a+1)]

def initTop():
    return 0

def isEmpty(top):
    return top == 0
    
def isFull(top, len_a):
    return top >= len_a-1

def pop(top, a):
    if isEmpty(top):
        print("Err: Empty")
    val = a[top]
    top -= 1
    return top, val

def push(top, a, val):
    if isFull(top, len(a)):
        print("Err: Full")
    top += 1
    a[top] = val
    return top

a = getInput()
a = [convNum(i) for i in a]

top, s = initArr(len(a))
for i in range(len(a)):
    top = push(top, s, a[i])
    if type(a[i]) == str:
        top, val = pop(top, s)
        top, val_b = pop(top, s)
        top, val_a = pop(top, s)
        if val == "+":
            top = push(top, s, val_a + val_b)
        elif val == "-":
            top = push(top, s, val_a - val_b)
        elif val == "*":
            top = push(top, s, val_a * val_b)        
        else:
            print("Error: Invalid Operand")
print(s[1])


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

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

  int A[N];
  rep(i,N){
    cin >> A[i];
  }

/*
  ll b[N]={};
  ll c[N]={};
*/

  ll ans = 0;

  rep(i,N){
    rep(j,N){
      if(A[i] > A[j] && i > j ){
        ll x = (K*(K-1)/2)%MM;
        ans += x;
        ans %= MM;
      }
      if(A[i] > A[j] && i < j ){
        ll y = ((K+1)*K/2)%MM;
        ans += y;
        ans %= MM;
      }
    }
  }


/*
  rep(i,N){
    ll x = (c[i] * (K*(K+1)/2)%MM ) % MM;
    ll y = (b[i] * ((K-1)*K/2)%MM ) % MM;
    ll z = (x + y) % MM;
    ans = (ans + z) % MM;
  //  cout << x << " " << y << " " << ans << endl;    
  }*/


  cout << ans << endl;


}


Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
no = list(map(int, input().split()))

red = sorted(red, reverse=True)[:X]
green = sorted(green, reverse=True)[:Y]
no = sorted(no, reverse = True)[:X+Y]

co = sorted(red+green)

for i in range(len(no)):
    if no[i]>co[i]:
        co[i] = no[i]
    else:
        break
        
print(sum(co))

Measured memory_bytes: 109164
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] edge = new int[m][2];
		for(int i = 0; i < m; i++){
		    edge[i][0] = sc.nextInt()-1;
		    edge[i][1] = sc.nextInt()-1;
		}
		
		// 計算
		int result = 0;
		for(int i = 0; i < m; i++){
		    int[][] dist = new int[n][n];
		    for(int j = 0; j < m; j++){
		        if(i == j) continue;
		        int a = edge[j][0];
		        int b = edge[j][1];
		        dist[a][b] = 1;
		        dist[b][a] = 1;
		    }
		    wf(dist);
		    if(dist[edge[i][0]][edge[i][1]] == 1001001001) result++;
		}
		
		
		// 出力
		System.out.println(result);
	}

	static void wf(int[][] dist) {
		int n = dist[0].length;
		int INF = 1001001001;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(dist[i][j] == 0) dist[i][j] = INF;
				if(i == j) dist[i][j] = 0;
			}
		}

		for(int k = 0; k < n; k++){
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
	}
	
}


Measured memory_bytes: 23764
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static boolean solve() {
		double x = in.nextInt();
		double h = in.nextInt();
		if (x + h == 0) return false;

		double l = Math.sqrt((x/2)*(x/2) + h*h);
		double s = x*x + x*l/2*4;

		out.println(s);
		return true;
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(solve());
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 26428
n = gets.to_i
m = Array.new(4){Array.new(3){Array.new(10,0)}}

n.times do
  b,f,r,v = gets.split.map(&:to_i)
  m[b-1][f-1][r-1] += v
end

puts m.map{|x| x.map{|y| ' '+y.join(' ')}.join("\n")}.join("\n"+"#"*20+"\n")

Measured memory_bytes: 8744
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(N: int, a: "List[int]"):
    c = Counter()
    for aa in a:
        c[min(aa//400, 8)] += 1

    tot = 0
    for k in c:
        if k == 8:
            continue
        else:
            tot += 1
    if tot == 0 and c[8] > 0:
        print(1, c[8])
    else:
        print(tot, tot+c[8])

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> X(N);
  for (int i = 0; i < N; ++i)
  {
    cin >> X[i];
  }
  int ans = 0;
  for (int i = 0; i < N; ++i)
  {
    int tmp = min(X[i], K - X[i]);
    ans += tmp;
  }
  cout << ans * 2 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Problem E: Binary Digit A Doctor Loved
 */
public class Main {

	static int LEN_I = 8;
	static int LEN_D = 4;

	static double[] D;

	static {
		D = new double[LEN_D];
		double j = 1.0;
		for (int i = 0; i < LEN_D; i++) {
			D[i] = j /= 2;
		}
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			if (line.equals("-1.0")) break;

			words = line.split("\\.");

			String si, sd = ".0000";

			//
			int ni = parseInt(words[0]);

			if (ni >= 1 << LEN_I) {
				System.out.println("NA");
				continue;
			}

			si = Integer.toBinaryString((1 << LEN_I) + ni).substring(1);

			//
			if (words.length == 2) {
				
				double nd = Double.parseDouble("0." + words[1]);
				sd = ".";

				for (int i = 0; i < LEN_D; i++) {
					if (nd >= D[i]) {
						nd -= D[i];
						sd += "1";
					} else {
						sd += "0";
					}
				}

				if (nd != 0) {
					System.out.println("NA");
					continue;
				}
			}

			System.out.println(si + sd);
		}
	}
}

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

int main(){
    int a=0,b=0,k=0,count=0;
    cin >> a >> b;
    k = b-a+1;
    for(int i=0;i<k;i++){
        if(a/10000==a%10&&((a/1000)%10)==((a/10)%10))count++;
        a++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
A = gets.chomp.to_i
array =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
p array[A-1]

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

int main(){
  int N;
  cin >> N;
  int a,C=0;
  for(int i=0;i<N;i++){
    cin >> a;
    while(a%2==0){
      a/=2;
      C++;
    }
  }
  cout << C;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
	int a,b;
	char x[5];
	scanf("%d %d",&a,&b);
	sprintf(x,"%d",b);
	for(int i=0;i<strlen(x);i++)
		a=a*10+x[i]-'0';
	if(((int)sqrt(a))*((int)sqrt(a))==a)
		printf("Yes");
	else printf("No");
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;

struct LowLink {
  const int N;
  vector<vector<int>> G;
  vector<bool> vis;
  vector<int> ord, parent, low;
  LowLink(int size) : N(size), G(size), vis(size, false), ord(size), parent(size), low(size) { }
  void add(int a, int b) {
    G[a].push_back(b); G[b].push_back(a);
  }
  void dfs(int v, int &k) {
    ord[v] = low[v] = k++;
    vis[v] = true;
    for(int u : G[v]) {
      if(!vis[u]) {
        parent[u] = v;
        dfs(u, k);
        low[v] = min(low[v], low[u]);
      }
      else if(u != parent[v]) {
        low[v] = min(low[v], ord[u]);
      }
    }
  }
  void compute() {
    int k = 0;
    dfs(0, k);
  }
  vector<pair<int, int>> bridge() {
    compute();
    vector<pair<int, int>> ret;
    for(int i = 0; i < N; ++i) {
      if(ord[parent[i]] < low[i]) ret.emplace_back(parent[i], low[i]);
    }
    return ret;
  }
  vector<int> articulation() {
    compute();
    vector<int> ret;
    int c = 0;
    for(int i = 1; i < N; ++i) {
      int p = parent[i];
      if(p == 0) ++c;
      else if(ord[p] <= low[i]) ret.push_back(p);
    }
    if(c >= 2) ret.push_back(0);
    sort(ret.begin(), ret.end());
    ret.erase(unique(ret.begin(), ret.end()), ret.end());
    return ret;
  }
};

int main() {
  ios::sync_with_stdio(false);
  int V, E; cin >> V >> E;
  LowLink lowlink(V);
  for(int i = 0; i < E; ++i) {
    int a, b; cin >> a >> b;
    lowlink.add(a, b);
  }
  vector<int> a = lowlink.articulation();
  for(int v : a) cout << v << endl;
}

Measured memory_bytes: 2580
def main():
    L = list(map(int,list(input())))
    MOD = 10 ** 9 + 7
    dp = [[0] * 2 for _ in range(len(L) + 5)]
    dp[0][0] = 1
    for i in range(len(L)):
        if L[i] == 0:
            dp[i+1][1] = 3 * dp[i][1]
            dp[i+1][0] = dp[i][0]
        else:
            dp[i+1][0] = 2 * dp[i][0]
            dp[i+1][1] = 3 * dp[i][1] + dp[i][0]

        dp[i+1][0] %= MOD
        dp[i+1][1] %= MOD

    print((dp[len(L)][0] + dp[len(L)][1]) % MOD)


if __name__ == "__main__":
    main()

Measured memory_bytes: 59768
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a,b;
    cin >> a;
    cin >> b;

    if (a != 1 && b != 1)
    {
        cout << 1;
    }

    if (a != 2 && b != 2)
    {
        cout << 2;
    }

    if (a != 3 && b != 3)
    {
        cout << 3 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int A, B; cin >> A >> B;
	cout << (B % A == 0 ? A + B : B - A) << endl;

	return 0;
}

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

using usize = ::std::size_t;
using u64 = ::std::uint_least64_t;
u64 N;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;
vector<u64> rows(110), columns(110);
vector<vector<u64>> dp(110, vector<u64> (110, -1));

u64 mcm(u64 i, u64 j){
    if (~dp[i][j]) {
        return dp[i][j];
    }
    dp[i][j] = Inf;
    if (i == j) {
        dp[i][j] = 0;
    } else {
        for (u64 k = i; k < j; k++) {
            dp[i][j] = min(dp[i][j], mcm(i, k) + mcm(k + 1, j) + rows[i] * columns[k] * columns[j]);
        }
    }
    return dp[i][j];
}

int main(int argc, char *argv[])
{
    
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N;
    
    
    for (int i = 0; i < N; i++) {
        cin >> rows[i] >> columns[i];
    }
    
    cout << mcm(0, N - 1) << endl;
    
    return 0;
}



Measured memory_bytes: 3320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define F first
#define S second
typedef vector<pli> vpli;
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end() 
#define tests int t; cin>>t; while(t--)
#define take(a,b,c) for(b=0;b<c;b++) cin>>a[b];
#define INF 1e18
// https://codeforces.com/problemset/page/3?tags=1500-1800
int main()
{	
  //auto start = std::chrono::high_resolution_clock::now();
  int n;
  cin>>n;
  ll a[n+3];
  unordered_map <ll,ll> m;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    m[a[i]]++;
  }
  ll ans=0;
  for(auto i: m){
    ll x = i.second;
    ans+=(x*(x-1))/2; 
  }
  for(int i=1;i<=n;i++){
    ll t = ans;
    t-= ((m[a[i]])*(m[a[i]]-1))/2;
    ll ne = m[a[i]]-1;
    t+= (ne*(ne-1))/2;
    cout<<t<<'\n';
  }
  //auto stop = std::chrono::high_resolution_clock::now(); 
  //auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start);
  //cout << duration.count() << endl; 

}

Measured memory_bytes: 9160
import math

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

prab = 0

for i in range(1, N+1):
    lo = math.log2(K/i)
    if lo < 0:
        lo = 0
    elif lo != int(lo):
        lo += 1

    prab += 1/pow(2., int(lo))

print(prab/N)


Measured memory_bytes: 3060
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline
    from heapq import heappush, heappop

    class Mincostflow():
        def __init__(self, N):
            self.N = N
            self.adj = [[] for _ in range(N + 1)]
            self.inf = 1 << 60

        def add_edge(self, fr, to, cap, cost):
            # [to, cap, cost, rev]
            forward = [to, cap, cost, None]
            backward = forward[3] = [fr, 0, -cost, forward]
            self.adj[fr].append(forward)
            self.adj[to].append(backward)

        def flow(self, s, t, f):
            N = self.N
            adj = self.adj
            inf = self.inf

            res = 0
            H = [0] * (N + 1)
            prev_v = [0] * (N + 1)
            prev_e = [None] * (N + 1)

            dist0 = [inf] * (N + 1)
            dist = [inf] * (N + 1)

            while f:
                dist[:] = dist0
                dist[s] = 0
                pq = [(0, s)]
                while pq:
                    d, v = heappop(pq)
                    if d > dist[v]:
                        continue
                    r0 = dist[v] + H[v]
                    for e in adj[v]:
                        u, cap, cost, _ = e
                        if cap > 0 and r0 + cost - H[u] < dist[u]:
                            dist[u] = r = r0 + cost - H[u]
                            heappush(pq, (r, u))
                            prev_v[u] = v
                            prev_e[u] = e

                # flow f doesn't exist
                if dist[t] == inf:
                    return None

                for i in range(1, N + 1):
                    H[i] += dist[i]

                g = f
                v = t
                while v != s:
                    g = min(g, prev_e[v][1])
                    v = prev_v[v]
                f -= g
                res += g * H[t]
                v = t
                while v != s:
                    e = prev_e[v]
                    e[1] -= g
                    e[-1][1] += g
                    v = prev_v[v]

            return res

    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(input().rstrip('\n'))

    s = H*W + 1
    t = H*W + 2
    mcf = Mincostflow(H*W + 2)
    cnt = 0
    no_move = 0
    for h in range(H):
        for w in range(W):
            if grid[h][w] == "#":
                continue
            else:
                if grid[h][w] == "o":
                    cnt += 1
                    no_move += H + W - h - w
                    mcf.add_edge(s, h*W+w+1, 1, 0)
                if h+1 < H:
                    if grid[h+1][w] != "#":
                        mcf.add_edge(h*W+w+1, (h+1)*W+w+1, 100, 0)
                if w+1 < W:
                    if grid[h][w+1] != "#":
                        mcf.add_edge(h*W+w+1, h*W+w+2, 100, 0)
                mcf.add_edge(h*W+w+1, t, 1, H+W-h-w)
    print(no_move - mcf.flow(s, t, cnt))


if __name__ == '__main__':
    main()


Measured memory_bytes: 77600
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
#define all(v) v.begin(), v.end()

int main(){
  string S;
  cin >> S;
  cout << S.at(0) << S.at(1) << S.at(2) << endl;
}

Measured memory_bytes: 3576
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    x, a, b = list(map(int, input().rstrip('\n').split()))
    if b - a <= 0:
        print("delicious")
    elif b - a <= x:
        print("safe")
    else:
        print("dangerous")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
$max=<>;
$\="\n";
@nums=split(' ',<>);
$each_num[$nums[$_] - 1]++for(0..$max-1);
$_>=2&($sum+=$_*~-$_/2)for@each_num;
print($sum-$each_num[$_-1]+1)for@nums;

Measured memory_bytes: 28452
#include <vector>
#include <iostream>
using namespace std;
int main(){
  int n,a,b,c,x;
  while(cin >> n >> a >> b >> c >> x,n || a || b || c || x){
    vector<int> y(n);
    for(int i = 0;i < n;i++){
      cin >> y[i];
    }
    int current = x;
    int cnt = 0;
    int flag = -1;
    for(int i = 0;i <= 10000;i++){
      if(y[cnt] == current)cnt++;
      if(cnt == n){
	
	flag = i;
	break;
      }
      current = (a*current+b)%c;
    }
    if(flag == -1)cout << -1 << endl;
    else cout << flag << endl;
  }
  return 0;
}

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

using namespace std;

int a,b,c,d,ans=0;

int main() {
	cin>>a>>b>>c>>d;
	
	if(c>=a&&c<=b) ans=min(b,d)-c;
	if(a>=c&&a<=d) ans=min(b,d)-a;
	cout<<ans<<endl;
	
	return 0;
}

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

using namespace std;
typedef long long ll;

#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define out(ans) cout << ans << endl
#define in(n) cin >> n
ll n;
ll ans;

void solve();

int main()
{
    solve();
}

void solve()
{
    in(n);
    if (n < 10)
    {
        ans = n;
    }
    else if (n < 100)
    {
        ans = 9;
    }
    else if (n < 1e3)
    {
        ans = n - 100 + 10;
    }
    else if (n < 1e4)
    {
        ans = 999 - 100 + 10;
    }
    else if (n < 1e5)
    {
        ans = n - 1e4 + 999 - 100 + 11;
    }
    else if (n == 1e5)
    {
        ans = 99999 - 1e4 + 999 - 100 + 11;
    }
    out(ans);
}

Measured memory_bytes: 256
// finish date: 2018/07/22
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N, P;
    cin >> N >> P;
    vi A(N);

    int even_cnt = 0;
    rep(i, N) {
        cin >> A[i];
        even_cnt += (A[i] + 1) % 2;
    }
    if (even_cnt == N) {
        cout << (1LL << N) * ((P + 1) % 2);
    } else {
        cout << (1LL << (N - 1));
    }


    return 0;
}



Measured memory_bytes: 256