akhauriyash/Code-Regression huggingface dataset:
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

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

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const ll INF = 1e18;
const double pi = acos(-1);
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

#define int long long
#define rng(i,l,r) for(size_t i=(l);i<(r);++i)
#define rep(i,n) rng(i,0,n)
#define gnr(i,l,r) for(size_t i=(r)-1;i>=(l);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()


template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int counter(int x){
    if(x==0) return 0;
    return counter(x >> 1) + (x & 1);
}

ll nC2(ll n){
    if(n<2) return 0;
    return n*(n-1)/2;
}


void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    map<string,ll> anag;
    rep(i,n){
        string s; cin >> s;
        sort(ALL(s));
        if(anag.count(s)){
            anag[s]++;
        }else{
            anag.emplace(s,1);
        }
    }
    
    int ans = 0;
    for (auto itr = anag.begin(); itr != anag.end(); itr++){
        ans += nC2(itr->second);
    }
        
    cout << ans << endl;
 
}



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



Measured memory_bytes: 11264
#[allow(unused_macros)]
macro_rules! input {
    ($x:expr) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        $x = buf.trim().parse().unwrap();
    };

    ($x:expr, $($y:expr), +) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        input_iter!(buf.split_whitespace(), $x, $($y), +);
    };

    ($v:expr; $size:expr) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        for v in buf.split_whitespace() {
            $v.push(v.parse().unwrap());
        }
    };

    ($v:expr; $h_size:expr, $w_size:expr) => {
        for _ in 0..$h_size {
            let mut part_vec = Vec::new();
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).ok();
            for v in buf.split_whitespace() {
                part_vec.push(v.parse().unwrap());
            }
            $v.push(part_vec);
        }
    };
}

#[allow(unused_macros)]
macro_rules! input_iter {
    ($iter:expr, $x:expr) => {
        $x = $iter.next().unwrap().parse().unwrap();
    };

    ($iter:expr, $x:expr, $($y:expr), +) => {
        let mut iter = $iter;
        $x = iter.next().unwrap().parse().unwrap();
        input_iter!(iter, $($y), *);
    };
}

use std::collections::*;
use std::collections::hash_map::Entry::*;

fn main() {
    let (n, q): (usize, usize);
    input!(n, q);
    let mut tree = vec![Vec::new(); n];
    for _ in 0..(n - 1) {
        let (mut a, mut b): (usize, usize);
        input!(a, b);
        a -= 1;
        b -= 1;
        tree[a].push(b);
        tree[b].push(a);
    }
    let mut counts = vec![0; n];
    for _ in 0..q {
        let (mut p, x): (usize, usize);
        input!(p, x);
        p -= 1;
        counts[p] += x;
    }
    let mut acum = vec![0; n];
    let mut reached = vec![false; n];
    let mut q: VecDeque<(usize, usize)> = VecDeque::new();
    q.push_back((0, 0));
    while !q.is_empty() {
        let (cur, cur_count) = q.pop_front().unwrap();
        acum[cur] = cur_count + counts[cur];
        reached[cur] = true;
        for v in tree[cur].iter() {
            if !reached[*v] {
                q.push_back((*v, acum[cur]));
            }
        }
    }
    for a in acum.iter() {
        print!("{} ", a);
    }
}


Measured memory_bytes: 29684
n=int(input())
a=sorted(list(map(int,input().split())))

if n%3==0:
    for j in range(3):
        for i in range(j*(n//3),(j+1)*(n//3)-1):
            if a[i]!=a[i+1]:
                print("No")
                exit()
    if a[0]^a[n//3]==a[2*n//3]:
        print("Yes")
    else:
        print("No")
    exit()
for i in range(0,n-1):
    if a[i]!=a[i+1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 14116
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(void){
    int N;
    int K;
    long long A[100010];
    long long B[100010];
    long long CAN[30];


    cin >> N >> K;

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

    CAN[0] = K;
    int count = 1;
    for(int i=0;i<30;i++){
        if((K & 1<<i) == 1<<i){
            CAN[count] = (K - (1<<i)) | ((1<<i) - 1);
            count++;
        }
    }

    long long res = 0;
    long long tmp_sum = 0;
    for(int i=0;i<count;i++){
         for(int ii=0;ii<N;ii++){
            if((CAN[i] | A[ii]) == CAN[i]){
                tmp_sum += B[ii];
                /*cout << CAN[i] << ' ' << A[ii] << ' ' << B[ii] << endl;*/
            }
        }
        res = max(res, tmp_sum);
        tmp_sum = 0;
    }
    for(int ii=0;ii<N;ii++){
        if(CAN[0] == A[ii]){
            tmp_sum += B[ii];
        }
    }
    res = max(tmp_sum, res);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1920
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc = new Scanner(System.in);

        String n = sc.next();

        int count=0;
        for(int i = 0;i < 4;i++){
            if(n.charAt(i)=='2'){
                count++;
            }
        }

        System.out.println(count);

    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 23252
#include "bits/stdc++.h"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<vd> vvd;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
int num[3][3];
int main(){
  ll n;
  cin>>n;
  if(n==1){cout<<"Hello World"<<endl;}
  else{
    int a,b;cin>>a>>b;
    cout<<a+b<<endl;
  }
}

Measured memory_bytes: 256
s = input()
length = len(s)
ns = list(map(int,s))
total_sum = 0
for mask in range(2 ** (length-1)):
  sum_ = 0
  num = ns[0]
  for i in range(1, length):
    if (mask & 1) > 0:
      sum_ += num
      num = ns[i]
    else:
      num = (num * 10 + ns[i])
    mask = mask >> 1
  total_sum += sum_ + num
print(total_sum)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
n, k = map(int,input().split())
h = [int(i) for i in input().split()]
"""
if k >= n:
    ans = 0
else:
    h.sort()
    tmp = 0
    for i in range(n-k, n):
        tmp += h[i]
    ans = (sum(h) - tmp)
print(ans)
"""

if k >= n:
    ans = 0
else:
    h.sort()
    ans = 0
    for i in range(n - k):
        ans += h[i]
print(ans)


Measured memory_bytes: 26764
program sample
    implicit none
    real(8)::p,a
    integer(8) :: i,j,m,n,s,t,t1,t0,k
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n,k
    
    if(n>=k)then
        p=real(n-k+1)
        t=k-1
        s=(k-1)/2
        m=1
    else
        p=0.0
        t=n
        s=(k-1)/2
        m=1
        do while(s>t)
            m=m+1
            s=s/2
        end do

    end if
    do while(t>0)
        p=p+real(t-s)/2**m

        t=s
        s=s/2
        m=m+1
    end do
        
    write(*,*) p/n
  
    stop
end program sample
  



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

int main(){
  int Q,c,a,n;
  int ans = 0;
  
  cin >> Q;

  for(int ix=0;ix<Q;++ix){
    cin >> c >> a >> n;

    while(true){
      if(c > 0 && a > 0 && n > 0){
	++ans;
	--c;
	--a;
	--n;
      }else if(c > 1 && a > 0){
	++ans;
	c-=2;
	--a;
      }else if(c > 2){
	++ans;
	c-=3;
      }else{
	break;
      }
    }

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



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

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

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

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

	std::vector<std::string> s(h, std::string(4, '.'));
	while(n--) {
		int x, y; scanf("%d%d", &x, &y);

		s[y][x] = '#';
	}

	auto put = [](std::vector<std::string> s, int y) {
		std::pair<int, std::string> p = {0, s[1]};
		if(s[0][y] == '.' and s[0][y + 1] == '.' and s[1][y] == '.' and s[1][y + 1] == '.') p.first = 1;
		p.second[y] = p.second[y + 1] = '#';
		return p;
	};

	std::vector<std::map<std::string, int>> dp(h + 1); dp[1][s[0]] = 0;
	for(int i = 1; i < h; i++) {
		for(auto from: dp[i]) {
			std::vector<std::string> t = {from.first, s[i]};
			int val = from.second;

			auto A = put(t, 0);
			auto B = put(t, 1);
			auto C = put(t, 2);
			auto D = put(std::vector<std::string>{from.first, A.second}, 2);
			dp[i + 1][s[i]] = std::max(dp[i + 1][s[i]], val);
			if(A.first) dp[i + 1][A.second] = std::max(dp[i + 1][A.second], val + 1);
			if(B.first) dp[i + 1][B.second] = std::max(dp[i + 1][B.second], val + 1);
			if(C.first) dp[i + 1][C.second] = std::max(dp[i + 1][C.second], val + 1);
			if(A.first and C.first) dp[i + 1][D.second] = std::max(dp[i + 1][D.second], val + 2);
		}
	}
	int ans = 0;
	for(auto v: dp[h]) ans = std::max(ans, v.second);
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 8520
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	a, b, c, d := sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()
	if (abs(a-b) <= d && abs(b-c) <= d) || abs(a-c) <= d {
		fmt.Fprintln(wtr, "Yes")
	} else {
		fmt.Fprintln(wtr, "No")
	}

	wtr.Flush()
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			String line = sc.nextLine();
			String answer = "";
			int length = line.length();
			for (int i = 0; i < length; i++) {
				char ch = line.charAt(i);
				if (Character.isLowerCase(ch) == true) {
					answer += Character.toUpperCase(ch);
				} else {
					answer += Character.toLowerCase(ch);
				}
			}
			System.out.println(answer);
		}
	}

}


Measured memory_bytes: 31480
#include <stdio.h>

int H, N, W;
int isRange(int i, int j){
    if(i < 0 || j < 0 || i > H - 1 || j > W - 1){
        return 0;
    }
    return 1;
}

int main(void){
    scanf("%d%d", &H, &W);
    int s[50][50];
    int i, j;
    char tmp[51];
    int black_cnt = 0;
    for(i = 0; i < H; i++){
        scanf("%s", tmp);
        for(j = 0; j < W; j++){
            if(tmp[j] == '.'){
                s[i][j] = 1;
            }else if(tmp[j] == '#'){
                s[i][j] = 0;
                black_cnt++;
            }
        }
    }

    int l = 0;
    int r = 1;
    int queue[2500][2], dist_mat[50][50], q_tmp[2], ii, jj;

    queue[0][0] = 0;
    queue[0][1] = 0;

    for(i = 0; i < H; i++){
        for(j = 0; j < W; j++){
            dist_mat[i][j] = -1;
        }
    }
    dist_mat[0][0] = 0;
    while(l != r){
        q_tmp[0] = queue[l][0];
        q_tmp[1] = queue[l][1];
        l++;

        ii = q_tmp[0] + 1;
        jj = q_tmp[1];

        if(isRange(ii, jj) && s[ii][jj] && dist_mat[ii][jj] == -1){
            dist_mat[ii][jj] = dist_mat[q_tmp[0]][q_tmp[1]] + 1;
            queue[r][0] = ii;
            queue[r][1] = jj;
            r++;
        }
        ii = q_tmp[0] - 1;
        jj = q_tmp[1];
        if(isRange(ii, jj) && s[ii][jj] && dist_mat[ii][jj] == -1){
            dist_mat[ii][jj] = dist_mat[q_tmp[0]][q_tmp[1]] + 1;
            queue[r][0] = ii;
            queue[r][1] = jj;
            r++;
        }     
        ii = q_tmp[0];
        jj = q_tmp[1] + 1;   
        if(isRange(ii, jj) && s[ii][jj] && dist_mat[ii][jj] == -1){
            dist_mat[ii][jj] = dist_mat[q_tmp[0]][q_tmp[1]] + 1;
            queue[r][0] = ii;
            queue[r][1] = jj;
            r++;
        }
        ii = q_tmp[0];
        jj = q_tmp[1] - 1;
        if(isRange(ii, jj) && s[ii][jj] && dist_mat[ii][jj] == -1){
            dist_mat[ii][jj] = dist_mat[q_tmp[0]][q_tmp[1]] + 1;
            queue[r][0] = ii;
            queue[r][1] = jj;
            r++;
        }        
    }

    int dist = dist_mat[H - 1][W - 1];

    if(dist == -1){
        printf("%d\n", -1);
        return 0;
    }
    //塗りつぶせないマスは，移動にかかったマス目距離+1マス=dist+1
    //迷路の全体のマスはH*W,うち黒マスはblack_cnt
    //なので，　H*W - black_cnt - (dist + 1)
    int ans;
    ans = H * W - black_cnt - (dist + 1);
    printf("%d\n", ans);
    return 0;
    
}

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    string st;
    cin >> st;

    int n = 0;
    int w = 0;
    int s = 0;
    int e = 0;

    int size = st.size();

    rep(i, size){
        if(st[i] == 'N'){
            n++;
        }else if(st[i] == 'W'){
            w++;
        }else if(st[i] == 'S'){
            s++;
        }else{
            e++;
        }
    }

    bool ans = true;

    if((n == 0 && s > 0) || (s == 0 && n > 0)) ans = false;

    if((e == 0 && w > 0) || (w == 0 && e > 0)) ans = ans && false;

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
mi = min(a)
ma = max(a)
if mi == ma:
    print(0)
    exit()
ans = 0
for i in a:
    ans += (i - mi)**2
for i in range(mi + 1, ma + 1):
    val = 0
    for j in a:
        val += (i - j)**2
    ans = min(ans, val)
print(ans)

Measured memory_bytes: 9032
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	int d=sc.nextInt();
	int count=0;
	for(int i=0;i<n;i++) {
		int x=Math.abs(sc.nextInt());
		int y=Math.abs(sc.nextInt());
		double ans2=Math.pow(x, 2)+Math.pow(y,2);
		
		double ans=Math.sqrt(ans2);
	if((double)d>=ans) {
		count++;
	}
	
		
	}
	System.out.println(count);
	}

}


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

namespace abc092_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ret = x[1];
            for (int i = 0; i < n; i++)
            {
                int a = int.Parse(Console.ReadLine());
                ret += x[0] / a;
                if (x[0] % a > 0) ret++;
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

struct Point {
	double x;
	double y;
	Point(): x(0.0), y(0.0) {}
	Point(double x, double y) :x(x), y(y) {}
};

void print(const Point &p) {
	cout << p.x << ' ' << p.y << endl;
}

void koch(int n, const Point &p1, const Point &p2) {
	if (n == 0)
		return;
	
	Point s, u, t;
	s.x = (2.0*p1.x + p2.x) / 3.0;
	s.y = (2.0*p1.y + p2.y) / 3.0;
	t.x = (p1.x + 2.0*p2.x) / 3.0;
	t.y = (p1.y + 2.0*p2.y) / 3.0;
	u.x = (t.x - s.x)/2.0 - (t.y - s.y)*sqrt(3.0)/2.0 + s.x;
	u.y = (t.x - s.x)*sqrt(3.0)/2.0 + (t.y - s.y)/2.0 + s.y;

	koch(n-1, p1, s);
	print(s);
	koch(n-1, s, u);
	print(u);
	koch(n-1, u, t);
	print(t);
	koch(n-1, t, p2);
}

int main() {
	cout << fixed << setprecision(15);
	int n;
	cin >> n;

	Point p1(0.0, 0.0), p2(100.0, 0.0);
	print(p1);
	koch(n, p1, p2);
	print(p2);
}



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

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> cnt(n, 0);
    int d_min = n, d_max = 0;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        cnt[tmp]++;
        d_min = min(d_min, tmp);
        d_max = max(d_max, tmp);
    }
    if (d_min != (d_max + 1) / 2) {
        cout << "Impossible\n";
        return 0;
    }
    if (d_max % 2) {
        if (cnt[d_min] != 2) {
            cout << "Impossible\n";
            return 0;
        }
    } else {
        if (cnt[d_min] != 1) {
            cout << "Impossible\n";
            return 0;
        }           
    }
    for (int i = d_min + 1; i <= d_max; i++) {
        if (cnt[i] < 2) {
            cout << "Impossible\n";
            return 0;            
        }
    }
    cout << "Possible\n";
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int N, M;
vector<int> a[50];
int visited[50] = {0};
pair<int, int> p[50];
int ngx, ngy;

void dfs(int x) {
  visited[x] = 1;
  for(int i = 0; i < a[x].size(); i++) {
    int nx = a[x][i];
    if((x == ngx && nx == ngy) || (x == ngy && nx == ngx)) continue;
    if(visited[nx] == 0) {
      dfs(nx);
    }
  }
}

int main() {
  cin >> N >> M;
  rep(i, M) {
    int x, y;
    cin >> x >> y;
    x--;y--;
    a[x].push_back(y);
    a[y].push_back(x);
    p[i].first = x;
    p[i].second = y;
  }

  int ans = 0;

  for(int i = 0; i < M; i++) {
    ngx = p[i].first;
    ngy = p[i].second;
    dfs(p[i].first);
    bool f = false;
    rep(i, N) {
      if(visited[i] == 0) f = true;
    }
    if(f) ans++;
    rep(i, N) {
      visited[i] = 0;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define llint long long

using namespace std;

llint N;

int count(llint n)
{
	int ret = 0;
	for(;n;n/=10) ret++;
	return ret;
}

int main(void)
{
	cin >> N;
	
	int ans = 100;
	llint rootN = sqrt(N + 1e-9);
	
	for(int i = 1; i <= rootN; i++){
		if(N % i) continue;
		ans = min(ans, count(N/i));
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a, b;
	
	for(a = 1;a < 10;a++){
		for(b = 1;b < 10;b++){
			printf("%dx%d=%d\n", a ,b ,a*b);
		}
	}
	
	return 0;
}

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

using namespace std;

int main(){
	string S;
	cin >> S;
	
	vector<int> vec(2);
	
	for(int i = 0; i < S.size(); i++){
		if(S.at(i) == '0'){
			vec.at(0)++;
		}else{
			vec.at(1)++;
		}
	}
	
	sort(vec.begin(), vec.end());
	
	cout << vec.at(0) * 2 << endl;
	
	return 0;
	
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    int n;
    string s, t;
    cin >> n >> s >> t;
    string ans = "";
    for(int i = 0; i< n; i++){
        ans = ans + s[i] + t[i];
    }
    cout << ans << endl;
    return 0;
}

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

#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

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

#define fixed asldkjasld

const int N = 1e5 + 5;

struct Query {
  int v, d, c;
};

int n, m, q;
int c[N];
bool fixed[N];
vector<pii> g[N];
int maxDist[N];
Query qs[N];
map<int, int> pos[N];
int que[11 * N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--; v--;
    g[u].push_back(pii(v, -1));
    g[v].push_back(pii(u, -1));
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < SZ(g[i]); j++) {
      int to = g[i][j].first;
      pos[i][to] = j;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < SZ(g[i]); j++) {
      int to = g[i][j].first;
      g[i][j].second = pos[to][i];
    }
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int v, d, c;
    scanf("%d%d%d", &v, &d, &c);
    v--;
    qs[i] = {v, d, c};
  }
  for (int i = 0; i < n; i++) {
    maxDist[i] = -1;
  }
  for (int i = q - 1; i >= 0; i--) {
    int start, d, newC;
    start = qs[i].v;
    d = qs[i].d;
    newC = qs[i].c;
    if (maxDist[start] >= d) {
      continue;
    }
    int qh = 0, qt = -1;
    que[++qt] = start;
    maxDist[start] = d;
    while (qh <= qt) {
      int u = que[qh];
      if (!fixed[u]) {
        fixed[u] = true;
        c[u] = newC;
      }
      qh++;
      int nxt = maxDist[u] - 1;
      for (const auto &it : g[u]) {
        if (maxDist[it.first] < nxt) {
          maxDist[it.first] = nxt;
          que[++qt] = it.first;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%d\n", c[i]);
  }
  return 0;
}



Measured memory_bytes: 23668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    char a,b;
    cin >>a>>b;

    if(a==b){
        cout<<"H"<<endl;
    }else{
        cout<<"D"<<endl;
    }
    
    


    return 0;
    

}

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

ll gcd(ll x, ll y) {
    if (x < y) swap(x, y);
    return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
    return x * y / gcd(x, y);
}

int main(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    
    A--;
    ll x = B - B / C - B / D + B / lcm(C, D);
    ll y = A - A / C - A / D + A / lcm(C, D);

    cout << x - y << endl;
}

Measured memory_bytes: 256
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
  //  FI(); /// skip this line for compile
    int a,b,c,k,cnt=0;
    cin >> a >> b >> c >> k;
    while(b<=a){
        b*=2;
        cnt++;
    }

    while(c<=b){
        c*=2;
        cnt++;
    }

    if(cnt<=k) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}



Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//infinity
#define INTINF 2000000000
#define LONGINF 2000000000

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
	int n;
	cin >> n;
	if(n % 2 ==0){
		cout << n << endl;
	}else{
		cout << n * 2 << endl;
	}
	return 0;
}


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

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

	std::vector<int> V(N);
	for (auto& v : V)
	{
		std::cin >> v;
	}

	std::vector<int> C(N);
	for (auto& c : C)
	{
		std::cin >> c;
	}

	int Max = 0;

	std::vector<int> S(N);

	for (int i = 0; i < N; i++)
	{
		S[i] = V[i] - C[i];
	}

	for (auto s : S)
	{
		if (s > 0)Max += s;
	}

	std::cout << Max;
}


Measured memory_bytes: 256
/**
       ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
      AnTi-MiRaGe on Anti-Mage xD
       ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <memory.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define show puts("Debug")

using namespace std;

const int N = 1005;

int n, mt[N], u[N], mx[N], ans;

pair <int, int> ar[N];

vector < vector <int> > g;

bool dfs (int v)
{
    if (u[v])
        return 0;

    u[v] = 1;
    for (auto to : g[v])
    {
        if (mt[to] == -1 || dfs(mt[to]) )
        {
            mt[to] = v;
            return 1;
        }
    }
    return 0;
}

main()
{
    memset(mt, -1, sizeof(mt));

    cin >> n;

    g.resize(2 * n + 1);

    for (int i = 1; i <= 2 * n; i++)
        cin >> ar[i].fr >> ar[i].sc;

    for (int i = 1; i <= n; i++)
    {
        for (int j = n + 1; j <= n + n; j++)
        {
            if ( ar[i].fr < ar[j].fr && ar[i].sc < ar[j].sc )
                g[i].pb(j), g[j].pb(i);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        dfs(i);
        memset(u, 0, sizeof(u));
    }
    for (int i = n + 1; i <= n + n; i++)
        if (mt[i] != -1)
            ans++;

    cout << ans << endl;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*n
        self.rank=[-1]*n

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

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)

        if x==y:return
        elif self.rank[x]>self.rank[y]:
            self.root[x] +=self.root[y]
            self.root[y]=x
        else:
            self.root[y] +=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y] +=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def size(self,x):
        return -self.root[self.Find_Root(x)]

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

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

    def group_members(self):
        return {i:self.members(i) for i in self.roots()}

    def group_count(self):
        return len(self.roots())


N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))

UnionFind=UnionFind(N+1)
for i in range(N):
    UnionFind.Unite(i+1,P[i])

D=UnionFind.group_members()
E=[]
for i in D:
    A,length=D[i],len(D[i])
    if A[0]==0:continue
    index,F=A[0]-1,[]
    while len(F)!=length:
        index=P[index]-1
        F.append(C[index])
    E.append(F)

ans=-float("inf")
for A in E:
    length=len(A)
    if sum(A)<0:
        A=A*2
        for i in range(length):
            point=0
            for j in range(min(K,length)):
                point +=A[i+j]
                ans=max(ans,point)
    else:
        div,mod=divmod(K,length)
        base=(div-1)*sum(A)
        A=A*3
        for i in range(length):
            point=0
            for j in range(mod+length):
                point +=A[i+j]
                ans=max(ans,base+point)
print(ans)

Measured memory_bytes: 75064
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] pic = new String[h];

		for(int i=0; i<pic.length*2; i++){
			if(i % 2 == 0)
				pic[i/2] = sc.next();
			System.out.println(pic[i/2]);
		}
	}
}

Measured memory_bytes: 11212
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;

using ll = long long;

std::vector<ll> divisor(ll n) { 
  std::vector<ll> ret;
  for (ll i = 1; (ll)i*i <= n; ++i) { 
    if (n % i == 0) {
      ret.push_back(i);
      if (i*i != n) { ret.push_back(n/i); }
    }
  }
  std::sort(ret.begin(), ret.end());
  return ret;
};

template< typename T >
T extgcd(T a, T b, T &x, T &y) {
  T d = a;
  if(b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

int main() {
  ll n; cin >> n;
  if (n == 1) {
    cout << n << endl;
    return 0;
  }
  ll n2 = 1;
  bool ok = false;
  while (n2 < n) {
    n2 *= 2;
    if (n2 == n) { ok = true; break; }
  }
  if (ok) {
    cout << 2*n-1 << endl;
    return 0;
  }
  vector<ll> divs = divisor(2*n);
  ll ans = 3*n;
  for (ll a: divs) {
    ll b = -2*n/a;
    ll x, y;
    ll sol = extgcd(a, b, x, y);
    if (x == 0 || y == 0) continue;
    if (sol != 1) continue;
    ans = min(ans, a*x-1);
    // cout << sol << " " << a << " " << b << " " << x << " " << y << endl;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3752
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


signed main(void) {
    int i,j;
    int n;
    cin >> n;
    map<int,vi> ma;
    vi a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    rep(i,n)ma[a[i]].push_back(i);
    int ans = 0;
    vi used(n);
    for(int i = n-1; i >= 0; i--)if(used[i] == 0){
        rep(j,34)if(a[i]<(1LL<<j)){
            int p = (1LL<<j) - a[i],ind;
            if(ma[p].size()){
                while(used[ma[p].back()]){
                    ma[p].pop_back();
                    if(ma[p].empty())goto END;
                }
                ind = ma[p].back();
                if(ind == i){
                    if(ma[p].size() == 1)goto END;
                    ind = ma[p][ma[p].size()-2];
                }
                used[i]++;
                used[ind]++;
                ans++;
                ma[p].pop_back();
                break;
                END:;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 104448
#pragma GCC optimize("Ofast")
#include <iostream>
#define ll long long
using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  ll vec[n];
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  int x=0;
  for(int i=k;i<n;i++){
    if(vec[i]>vec[x]){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
    x++;
  }
}

Measured memory_bytes: 5168
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



signed main() {

	int N;
	cin >> N;
	vector<int> a(N);
	double ans = 0.0;
	rep(i, N) {
		cin >> a[i];
		ans += (double)1.0 / a[i];
	}
	cout << fixed << setprecision(15) << 1.0 / ans << endl;
	

	return 0;
}


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

int main() {
    int N;
    cin >> N ;
    vector<int> S(N);
    for (int i = 0; i < N; i++){
        cin >> S.at(i) ;
    }
    sort(S.begin(),S.end());
    reverse(S.begin(),S.end());
    int A = 0, B = 0;
    for (int k = 0; k < N; k += 2){
        A += S.at(k);
    }
    for (int l = 1; l < N; l += 2){
        B += S.at(l);
    }
    cout << A - B << endl;
}

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

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

int main(){
  int n, m, x;
  cin >> n >> m >> x;

  vector<vector<int>> hon(n, vector<int>(m+1));
  rep(i, n){
    cin >> hon.at(i).at(0);
    rep(j, m){
      cin >> hon.at(i).at(j+1);
    }
  }

  int money = 10000000;

  for(int i=0; i<pow(2, n); i++){
    string hantei;
    int p=i;
    for(int j=0; j<n; j++){
      hantei += to_string(p%2);
      p = p/2;
    }
    
    //cout << hantei << endl;

    vector<int> skill(m,0);
    int kingaku = 0;
    for(int j=0; j<n; j++){
      if(hantei.at(j)=='1'){
        kingaku += hon.at(j).at(0);
        for(int k=0; k<m; k++){
          int now = skill.at(k);
          now += hon.at(j).at(k+1);
          skill.at(k) = now;
        }
      }
    }

    bool flag = true;
    for(int j=0 ;j<m; j++){
      if(skill.at(j)<x) flag = false;
    }

    if(flag&&kingaku<=money) money = kingaku;
  }

  if(money != 10000000) cout << money;
  else cout << -1;
  
}

Measured memory_bytes: 4176
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a[] = new long[n];
        boolean flags[] = new boolean[n];
        for (int i = 0;i < n;++i){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        LinkedList<Long> output = new LinkedList<>();
        output.push(a[0]);
        int i1 = 1;
        int i2 = n - 1;
        for (int i = 1;i < n;++i){
            long t1 = Math.abs(output.getFirst() - a[i1]);
            long t2 = Math.abs(output.getLast() - a[i1]);
            long t3 = Math.abs(output.getFirst() - a[i2]);
            long t4 = Math.abs(output.getLast() - a[i2]);
            long m = Math.max(Math.max(t1,t2),Math.max(t3,t4));
            if(t1 == m){
                output.addFirst(a[i1]);
                ++i1;
            }
            else if(t2 == m){
                output.addLast(a[i1]);
                ++i1;
            }
            else if(t3 == m){
                output.addFirst(a[i2]);
                --i2;
            }
            else{
                output.addLast(a[i2]);
                --i2;
            }
        }
        long r = 0;
        long last = -1;
        for (long l:output){
            if(last >= 0)r += Math.abs(l - last);
            last = l;
        }
        System.out.println(r);

    }




}




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

using namespace std;

int main(void) {
	int num, c, k, i, ans = 1, n = 0, t = 0;
	cin >> num >> c >> k;
	vector<int> d(num);
	for (i = 0; i < num; i++)
		scanf("%d", &d[i]);
	sort(d.begin(), d.end());
	for (i = 0; i < num; i++) {
		if (n == 0) {
			t = d[i];
			n = 1;
		}
		else if (d[i] > t + k || n == c) {
			ans++;
			n = 0;
			i--;
		}
		else
			n++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc116/editorial.pdf
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
tdN = [[0]*2 for i in range(N)]
for i in range(N):
    t, d = MAP()
    tdN[i][0] = t
    tdN[i][1] = d

tdN.sort(key=itemgetter(1),reverse=True)
base = 0
bonus = 0
c = Counter()
changes = []
ans = 0
for i in range(K):
    t, d = tdN[i]
    base += d
    if c[t] == 0:
        bonus += 1
    c[t] += 1
    # 交換候補を集める
    if c[t] >= 2:
        heappush(changes, (d, i))
bonus *= bonus
ans = base + bonus

for i in range(K, N):
    t, d = tdN[i]
    # 既に持ってるネタならスキップ
    if c[t] != 0:
        continue
    else:
        # 1つずつ候補から交換してみて、最大値を取る
        if len(changes):
            _, idx = heappop(changes)
            t2, d2 = tdN[idx]
            base -= d2 - d
            bonus = (sqrt(bonus)+1) ** 2
            ans = max(base + bonus, ans)
            # 今回交換した分を更新
            c[t2] -= 1
            c[t] += 1
print(int(ans))


Measured memory_bytes: 28240
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
int main(){
    map<int, int> mm;
    int n, m;
    cin >> n >> m;
    rep(i,m){
        int a, b;
        cin >> a >> b;
        mm[a] ++;
        mm[b] ++;
    }
    rep(i,n){
        cout << mm[i + 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def enum_divisors(n):
    res = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            res.append(i)
            res.append(n//i)
    return res
def f(a, b):
    return max(len(str(a)), len(str(b)))
def main():
    N = int(input())
    divisors = enum_divisors(N)
    ans = 10**8
    for i in range(len(divisors)-1):
        ans = min(ans, f(divisors[i], divisors[i+1]))
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 39408
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, a[100000];
	cin >> n;
	REP(i, n) cin >> a[i];

	map<int, int> mp;

	REP(i, n){
		mp[a[i]]++;
		mp[a[i] - 1]++;
		mp[a[i] + 1]++;
	}

	int max = -1, ans = -1;
	for(auto itr = mp.begin();itr != mp.end();++itr){
		if(itr->second > ans){
			max = itr->first;
			ans = itr->second;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
 
#define PB push_back
#define MP make_pair
#define ff first
#define ss second
#define ll long long 
#define inf 1000000000
#define iPair pair< ll , ll >
using namespace std;
#define lp(n,i) for(ll i=0;i<n;i++)
#define rlp(n) for(ll i=n-1;i>=0;i--)
#define pq 	priority_queue<int, vector<int> , greater<int> >
 
/*ll pw(ll x, ll  y) ;
ll mi(ll  a) 
{ return pw(a, e-2); } 
 
ll pw(ll x, ll  y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = pw(x, y/2) % e; 
    p = (p * p) % e; 
  
    return (y%2 == 0)? p : (x * p) % e; 
} 
  
  
 bool sortbysec(const pair<int,int> &a,  const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
int mod(string num, int a) 
{ 
    // Initialize result 
    int res = 0; 
  
    // One by one process all digits of 'num' 
    for (int i = 0; i < num.length(); i++) 
         res = (res*10 + (int)num[i] - '0') %a; 
  
    return res; 
} */












int main()
{
ll a,b;
cin>>a>>b;
if((a+b)%2==0)cout<<(a+b)/2;
else cout<<"IMPOSSIBLE";
	
	
	
 
	cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
	return 0;
}
 
 
 
 

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << max(stoi(string(a, '0' + b)), stoi(string(b, '0' + a))) << "\n";
    return 0;
}



Measured memory_bytes: 256