akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`

				`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())
	//https://atcoder.jp/contests/abc165/tasks/abc165_f
	//https://www.dropbox.com/sh/nx3tnilzqz7df8a/AAA0887IQFx5BcrZcrpRD7uga/ABC165/F?dl=0&subfolder_nav_tracking=1

	n := nextInt()
	d := nextInts(n)

	m := map[int]int{}

	for i := 0; i < n; i++ {
		m[d[i]] = 1
	}

	ans := len(m)

	//	fmt.Fprintln(out, "[DEBUG]]", a)
	fmt.Fprintln(out, ans)
}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    cin >> S;
    n = S.length();
    
    ll ans = 0;
    rep(i, 1 << (n - 1)) {
        ll sm = 0;
        ll a = S[0] - '0';
        rep(j, n - 1) {
            if (i & (1 << j)) {
                sm += a;
                a = 0;
            }
            a = a * 10 + S[j + 1] - '0';
        }
        sm += a;
        ans += sm;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(6);

  int INF = 1000000;

  int n,m;
  while(cin >> n >> m){
    if(n==0&&m==0) break;
    queue<int> line;
    REP(i,n) line.push(i+1);
    
    int num=0;
    while(line.size()!=1){
      int a = line.front();
      line.pop();
      num++;
      if(num == m)
	num = 0;
      else
	line.push(a);
    }
    cout << line.front() << endl;
  }

  return 0;
}

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

using namespace std;
typedef long long LL;
const int MaxN = 1e5;


int a, b, c, x, y;

int main()
{
	cin >> a >> b >> c >> x >> y;
	if(a + b > 2 * c)
	{
		if(x > y)
		{
			if(a > 2 * c)
				cout << 2 * c * x << endl;
			else 
			cout << (2 * c * y) + (x - y) * a << endl;
		}
		else
		{
			if(b> 2 * c)
				cout << 2 * c * y << endl;
			else
			cout << (2 * c * x) + (y - x) * b << endl;
		}
	}
	else  cout << x * a + b * y << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef unsigned long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const int i_INF = 2147483647;

int main() {
  int a,b;
  cin>>a>>b;
  cout<<a+b/2<<endl;
}

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

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

  vector<int> a(n, 0);
  for (int i = 0; i < 2*m; i++) {
    int index;
    cin >> index;
    a.at(index-1) += 1;
  }

  for (int i = 0; i < n; i++) {
    cout << a.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[2000001],b[2000001];
 
 
void CountingSort(int n){
  int c[10001]={};
  for(int i=0;i<n;i++) c[a[i]]++;
  for(int i=1;i<=10000;i++) c[i]+=c[i-1];
  for(int i=n-1;i>=0;i--) {
    b[c[a[i]]-1]=a[i];
    c[a[i]]--;
  }
}
 
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  CountingSort(n);
  for(int i=0;i<n-1;i++) cout << b[i]<<" ";
  cout <<b[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 18740
#include<bits/stdc++.h>
using namespace std;
int main(){
  int cnt=0;
  vector<int> CD(100);
  int a,b,k;
  cin>>a>>b>>k;
  for(int i=0;i<100;i++){
   if(a%(i+1)==0&&b%(i+1)==0){
    CD.at(cnt)=i+1;
     cnt++;
   }
  }
  cout<<CD.at(cnt-k)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int read(){
	int sum=0,f=1;
	char s=getchar();
	while (s<'0' or s>'9'){
		if (s=='-')f=-1;
		s=getchar();
	}
	while (s>='0' and s<='9'){
		sum=sum*10+s-'0';
		s=getchar();
	}
	return sum*f;
}
int n;
int main(){
	int k=read();
	int a,b;
	a=read(),b=read();
	int t=a/k;
	if (a%k==0)printf("OK\n");
	else{
		t=a/k;
		t=t*k+k;
		if (a<=t and t<=b)printf("OK\n");
		else printf ("NG\n");
	}
	
	return 0;
}



Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;


public class Main{

	
	public static void main(String[] args){
		
		byte[] bof = new byte[80];
		Arrays.fill(bof, (byte)9);
		BigInteger overflow = new BigInteger(bof);
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n; i++){
			String str1 = sc.next();
			String str2 = sc.next();
			byte[] b1 = strToByteArray(str1);
			byte[] b2 = strToByteArray(str2);
			BigInteger i1 = new BigInteger(b1);
			BigInteger i2 = new BigInteger(b2);
			
			BigInteger sum = BigInteger.sum(i1, i2);
			
			if(BigInteger.isABiggerThanB(i1, overflow) || BigInteger.isABiggerThanB(i2, overflow) || BigInteger.isABiggerThanB(sum, overflow)) System.out.println("overflow");
			else System.out.println(sum);
		}
		sc.close();
	}
	
	static byte[] strToByteArray(String cs) {
		byte[] result = new byte[cs.length()];
		for(int i = 0; i < cs.length(); i++) {
			result[cs.length() - i - 1] = Byte.parseByte(Character.toString(cs.charAt(i)));
		}
		return result;
	}
}

class BigInteger{
	byte[] ds;
	BigInteger(byte[] d){
		int i;
		for(i = d.length-1; i > 0; i--) {
			if(d[i] != 0) break;
		}
		this.ds = Arrays.copyOfRange(d, 0, i+1);
	}
	
	static boolean isABiggerThanB(BigInteger a, BigInteger b) {
		if(a.ds.length > b.ds.length) return true;
		else if(a.ds.length < b.ds.length) return false;
		else {
			return a.ds[a.ds.length-1] > b.ds[b.ds.length-1];
		}
	}

	
	static BigInteger sum(BigInteger i1, BigInteger i2) {
		if(isABiggerThanB(i1, i2)) return subsum(i1, i2);
		else return subsum(i2, i1);
	}
	
	static BigInteger subsum(BigInteger i1, BigInteger i2) {
		int digit = (i1.ds.length > i2.ds.length)? i1.ds.length + 2: i2.ds.length + 2;
		byte[]	ds = new byte[digit];
		boolean c_up = false;
		int i;
		for(i = 0; i < i1.ds.length; i++) {
			ds[i] = (i < i2.ds.length)? (byte) (i1.ds[i] + i2.ds[i]): i1.ds[i];
			if(c_up) ds[i]++;
			if(ds[i] > 9) {
				ds[i] = (byte) (ds[i] % 10);
				c_up = true;
			}else c_up = false;
		}
		if(c_up) ds[i]++;
		return new BigInteger(ds);
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer();
		for(int i = ds.length - 1; i >= 0; i-- ) {
			sb.append(ds[i]);
		}
		return sb.toString();
	}
}

Measured memory_bytes: 17276
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a[3],n=3;
    for(ll i=0; i<n; i++) cin>>a[i];
    sort(a,a+n);
    cout<<a[0]<<" "<<a[1]<<" "<<a[2];
    cout<<endl;
    return 0;
}





Measured memory_bytes: 3128
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
c = gets.chomp.split.map(&:to_i)

result = 0

(a << 0).each_cons 2 do |i, j|
  result += b[i-1]
  result += c[i-1] if j - i == 1
end

puts result

Measured memory_bytes: 1916
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define pb push_back
    #define mk make_pair
    #define ft first
    #define sc second
    #define ppb pop_back
    #define sz size
    #define forn(i,a,n) for(i=a;i<n;i++)
    #define M 1000000007
    #define inf 2e18


    int main() {


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
        
    ll a,b;
    cin>>a>>b;
    if(a==b)cout<<"Yes";
    else
        cout<<"No";

    return 0;
    }

Measured memory_bytes: 256
// Aizu Vol0 0083: Era Name Transformation
// 2017.7.29

#include <stdio.h>
#include <stdlib.h>

int start[5] = { 19890108, 19261225, 19120730, 18680908, 0 };
char *era[5] = { "heisei", "showa", "taisho", "meiji", "pre-meiji" };

int main()
{
	int y, m, d, date;
	int i;
	
	while (scanf("%d%d%d", &y, &m, &d) == 3) {
		date = y * 10000 + m * 100 + d;
		for (i = 0; ; i++) {
			if (i >= 4) {
				puts("pre-meiji");
				break;
			}
			if (date >= start[i]) {
				printf("%s %d %d %d\n", era[i], y - (start[i] / 10000) + 1, m, d);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 608
/*
  AOJ 1302
  Title:
  @kankichi573
 14/07/13 TLE
*/
#include <stdio.h>
#include <limits.h>
#include <string.h>
#define min(x,y) ((x<y)?(x):(y))
#define max(x,y) ((x>y)?(x):(y))

int m,n;
int data[128];

int log2ceil(int n)
{
  int i;
  for(i=8;i>=0;i--)
    if(n > (1<<i))
      return(i+1);
  return(0); // never reach if n > 0 && n <= 128
}

dump(int data[],int count)
{
  int i;

  printf("[%d]",count);
  for(i=0;i<count;i++)
    printf("%d:",data[i]);
  printf("\n");
}
solve(int data[],int count,int used_mask)
{
  int i,j,mask,min_,c1,c0,mydata[2][128],ret1,ret0,ret10,ceil_;

  //dump(data,count);

  if(count==1)
    return(0);
  if(count==2)
    return(1);
  if(count==3)
    return(2);
  ceil_=log2ceil(count);
  memset(mydata,0,256);
  min_=INT_MAX;
  for(i=0;i<m;i++)
    {
      mask = 1<<i;
      if(mask & used_mask)
	continue;
      c0=c1=0;
      for(j=0;j<count;j++)
	if(data[j] & mask)
	  mydata[1][c1++]=data[j];
	else
	  mydata[0][c0++]=data[j];
      //printf("m=%d c0=%d C1=%d\n",mask,c0,c1);
      if(c0 && c1)
	{
	  ret0=solve(&mydata[0][0],c0,used_mask|mask);
	  ret1=solve(&mydata[1][0],c1,used_mask|mask);
	  ret10=max(ret0,ret1);
	  min_ = min(min_,(ret10+1));
	  if(min_==ceil_)
	    return(ceil_);
	}
    }
  return(min_);
}
int conv_bin(char buf[],int len)
{
  int i,ret;

  ret=0;
  for(i=0;i<len;i++)
    if(buf[i] & 1)
      ret+=(1<<(len-1-i));
  return(ret);
}
main()
{
  int i,ret;
  char buf[13];

  while(scanf("%d %d",&m,&n) && (m||n))
    {
      for(i=0;i<n;i++)
	{
	  scanf("%s",&buf[0]);
	  data[i]=conv_bin(buf,m);
	}
      
      ret=solve(data,n,0);
      printf("%d\n",ret);
    }
  
  return(0);

}

Measured memory_bytes: 612
N, M, C = map(int,input().split(' '))
import numpy as np
B = np.array(list(map(int,input().split(' '))))
def f(A, B, C):
    A = np.array(list(map(int,A.split(' '))))
    return np.sum(A*B) +C >  0
print(np.sum([f(input(), B, C) for i in range(N)]))

Measured memory_bytes: 12452
n = int(input())
l = [i for i in range(1, n+1) if i % 2 == 1]
ans = 0
for i in l:
  cnt = 0
  for x in range(1, i+1):
    if i % x == 0:
      cnt += 1
  if cnt == 8:
    ans += 1
print(ans)   
  

Measured memory_bytes: 9112
import sys
h, w = map(int, input().split(" "))
p = []
for i in range(h):
  l = []
  s = input()
  for j in range(w):
    l.append(s[j])
  p.append(l)
  
         
for i in range(h):
  for j in range(w):
    if p[i][j] == "#":
      try:
        if p[i-1][j] == "#":
          continue
      except IndexError:
        pass
      try:
        if p[i][j+1] == "#":
          continue
      except IndexError:
        pass
      try:
        if p[i+1][j] == "#":
          continue
      except IndexError:
        pass
      try:
        if p[i][j-1] == "#":
          continue
      except IndexError:
        pass
      print("No")
      sys.exit()
      
print("Yes")
      

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;

    /*if(n == 4) {
        cout << "Yes" << endl;
        return 0;
    }*/

    if(c < d) {
        for(int i = a; i <= d-2; i++) {
            if(s[i] == '#' && s[i+1] == '#') {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }

    for(int i = b-2; i <= d-2; i++) {
        if(s[i] == '.' && s[i+1] == '.' && s[i+2] == '.') {
            cout << "Yes" << endl;
            return 0; 
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 640
// ABC 159-D
// 2020.3.24 bal4u

#include <stdio.h>

typedef long long ll;

#define gc() getchar()//getchar_unlocked()
#define pc(c) putchar(c)//putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0; int c;
	c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
	//(c & 0xf)：字符0-9 Ascii码0x30-0x39 与0xf（即00001111）按位与运算 只保留个位数（0x0-0x9）
}

void out(ll n) { // 非負整数の表示（出力）
	int i; char b[30];

	if (!n) pc('0');
	else {
		//		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int f[200005];
int A[200005];

int main()
{
	int i, N, a, ma;
	ll s;

	N = in();
	ma = 0;
	for (i = 0; i < N; ++i) {
		A[i] = a = in(), f[a]++;
		if (a > ma) ma = a;
	}
	s = 1; for (i = 1; i <= ma; ++i) s += (ll)f[i] * (f[i] - 1) >> 1;// >> 1:右移运算符 将其二进制右移1位 即/2
	for (i = 0; i < N; ++i) out(s -f[A[i]]);
	return 0;
}

Measured memory_bytes: 3584
import numpy as np
N=int(input())
A=[np.array(list(map(int,input().split()))) for i in range(N)]
ans=sum([sum(A[i]) for i in range(N)])
ans//=2
for i in range(N):
    A[i][i]=10**10
def main(ans):
    for i in range(N):
        for j in range(i+1,N):
            Min=np.min(A[i]+A[j])
            if Min<A[i][j]:
                return -1
            if Min==A[i][j]:
                ans-=A[i][j]
    return ans
print(main(ans))

Measured memory_bytes: 21804
D,N = map(int,input().split())

count = 0
i = 1
while count<N:
    if (i%(100**(D+1)) != 0) and (i%(100**(D+2)) != 0) and (i%(100**D)) == 0:
        count += 1
    i += 1
print(i-1)            

Measured memory_bytes: 9072
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {
    
    string S; cin >> S;
    int n, w, s, e;
    n = w = s = e = 0;
    rep(i,S.size()) {
        if (S[i] == 'N') ++n;
        if (S[i] == 'W') ++w;
        if (S[i] == 'S') ++s;
        if (S[i] == 'E') ++e;
    }

    bool flag = true;
    if ((n != 0 && s == 0) || (n == 0 && s != 0)) flag = false;
    if ((w != 0 && e == 0) || (w == 0 && e != 0)) flag = false;

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;



    
    return 0;
}






Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a, b, c;  scanf("%d %d %d", &a, &b, &c);

  int gcd;

  while(a % b){
    int t = a;
    a = b, b = t % b;
  }

  gcd = b;

  printf("%s\n", (c%gcd ? "NO" : "YES")); 
  return 0;
}


Measured memory_bytes: 1636
from itertools import permutations

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

g = [[0] * (n + 1) for _ in range(n + 1)]
for a, b in ab:
    g[a][b] = 1
    g[b][a] = 1

ans = 0
for nxt in permutations(range(2, n + 1), n - 1):
    bl = 1
    u = 1
    for v in nxt:
        if not g[u][v]:
            bl = 0
            break
        u = v

    ans += bl

print(ans)


Measured memory_bytes: 9192
def main():
    n, m = map(int, input().split())
    food_list = [0] * m

    for _ in range(n):
        a_list = list(map(int, input().split()))
        for i in range(1, a_list[0] + 1):
            food_list[a_list[i] - 1] += 1

    cnt = 0
    for food in food_list:
        if food == n:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62672
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,m;
	while(cin>>a>>b>>m)
	{
		int l[a];
		int minl=-1,minr=-1;
		for(int i=0;i<a;i++) 
		{
			cin>>l[i];	
			if(l[i]<minl||minl==-1) minl=l[i];
		}
		int r[b];
		for(int i=0;i<b;i++) 	{
			cin>>r[i];	
			if(r[i]<minr||minr==-1) minr=r[i];
		}
		int ans=minl+minr;
		while(m--)
		{
			int x,y,c;
			cin>>x>>y>>c;
			ans=min(ans,l[x-1]+r[y-1]-c);
		}
		cout<<ans<<"\n";
	}
 } 

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

using namespace std;
using ll=long long;

// when range [l, r), has property P~notP, want last P.
// when return l-1, means not found.
template <typename T>
T bs_last(T l, T r, function<bool (T)> f) {
    assert(l < r);
    T mid;
    while (l != r) {
        mid = l + (r-l)/2;
        if (f(mid)) {
            l = mid + 1;
        }else {
            r = mid;
        }
    }
    return r-1;
}

void solve() {
    int n; ll m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<ll> sum(n+1);
    for (auto& x: a) {
        cin >> x;
    }
    sort(a.begin(), a.end(), greater<ll>());
    for (int i = 0; i < n; i++) {
        sum[i+1] = sum[i] + a[i];
    }

    ll C,S;
    auto ck = [&](ll x){
        ll cnt = 0;
        S = 0;
        for (int i = 0; i < n; i++) {
            if (a[i]*2<x)break;
            int j = bs_last<int>(i, n, [&](int j){
                    return a[i]+a[j] >= x;
                    });
            cnt += 2*(j-i)+1;
            S += a[i] * (2*(j-i)+2) + (sum[j+1]-sum[i+1]) * 2;
        }
        C = cnt;
        return cnt >= m;
    };
    ll x = bs_last<ll>(0, 2e5+10, ck);
    ck(x);
//cout << S << "\n";
    ll res = S - (C-m)*x;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
 
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
   	    String t = sc.next();
      
      System.out.println(t+s);
      
 
      
      
 
 
 
		
		
	}
 
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

struct Combination {
    vector<lint> fac, finv, inv;
    Combination(lint maxN) : fac(maxN + 100), finv(maxN + 100), inv(maxN + 100) {
        maxN += 100; // for safety
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1]            = 1;
        for (lint i = 2; i <= maxN; ++i) {
            fac[i]  = fac[i - 1] * i % mod;
            inv[i]  = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    lint operator()(lint n, lint k) {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    vector<lint> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    Combination nCk(100000);
    mint ret = 0;
    // lint r   = 0;
    for (int i = 0; i < n; ++i) {
        ret += nCk(i, k - 1) * a[i];
        ret -= nCk(n - i - 1, k - 1) * a[i];
        // r += nCk(i, k - 1) * a[i];
        // r -= nCk(n - i - 1, k - 1) * a[i];
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 3456
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
   struct node *right;
   struct node *left;
   struct node *parent;
  int key;
 };
typedef struct node * Node;

struct node *root, *NIL;

struct node *find(struct node *u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

void insert(int k){
  struct node *y = NIL;
  struct node *x = root;
  struct node *z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }

  z->parent = y;
  if(y == NIL){
    root = z;
  }else{
    if(z->key < y->key){
      y->left = z;
    }else{
      y->right = z;
    }
  }
}

void inorder(struct node *u){
  if(u == NIL) return ;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(struct node *u){
  if( u == NIL) return;

  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[5000];
  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%s", com);
    if(strcmp(com,"find")==0){
      scanf("%d", &x);
      struct node *t = find(root, x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    }else if(strcmp(com,"insert")==0){
      scanf("%d", &x);
      insert(x);
    }else if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}





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

using namespace std;
using ll =long long;
//nCm 
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//nCmここまで

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	ll k ,  a, b; 
	cin >> k >>  a>> b; 
	ll cokkie = 1 ;
	if(a + 2 < b){
		while(1){
			//交換した後のクッキーも交換に使える。
			//a-1回とりあえずやる。
			ll m = min(a-1,k);
			cokkie += m;
			k-=m;
			cokkie += (b-a) * ( k / 2 ); 
			cokkie += k % 2 ;
			cout << cokkie << endl;
			return 0 ;
		}
	}
	else {
		cout << k + 1 << endl; 
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1300005,INF=1<<29;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    while(N--){
        string S,T;cin>>S>>T;
        reverse(all(S));
        
        for(auto c:S){
            if(c=='J'){
                string sub=T;
                for(int i=0;i<T.size();i++){
                    sub[(i+1)%T.size()]=T[i];
                }
                T=sub;
            }else if(c=='C'){
                string sub=T;
                for(int i=0;i<T.size();i++){
                    sub[(T.size()+i-1)%T.size()]=T[i];
                }
                T=sub;
            }else if(c=='E'){
                string left=T.substr(0,T.size()/2),right=T.substr(T.size()-T.size()/2,T.size()/2),mid=T.substr(T.size()/2,T.size()%2);
                T=right+mid+left;
            }else if(c=='A'){
                reverse(all(T));
            }else if(c=='P'){
                for(int i=0;i<T.size();i++){
                    if('0'<=T[i]&&T[i]<='9'){
                        if(T[i]!='0') T[i]--;
                        else T[i]+=9;
                    }
                }
            }else if(c=='M'){
                for(int i=0;i<T.size();i++){
                    if('0'<=T[i]&&T[i]<='9'){
                        if(T[i]!='9') T[i]++;
                        else T[i]-=9;
                    }
                }
            }
        }
        
        cout<<T<<endl;
    }
}




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

using namespace std;

#define ll long long

const int N = 1e5 + 5;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 0, x; i < n; ++i) {
        cin >> x;
        cnt += (x & 1);
    }
    if (cnt & 1) {
        cout << "NO\n";
    } else {
        cout << "YES\n";
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int N, M; cin >> N >> M;
    string ans = "No";
    vector<string> A, B;

    for(int i = 0; i < N; i++){
        string tmp; cin >> tmp; A.push_back(tmp);
    }

    for(int i = 0; i < M; i++){
        string tmp; cin >> tmp; B.push_back(tmp);
    }



    for(int i = 0; i <= N-M; i++){
        for(int j = 0; j <= N-M; j++){
            bool flag = true;
            for(int k = 0; k < M; k++){
                for(int l = 0; l < M; l++){
                    if(A[i+k][j+l] != B[k][l]){
                        flag = false;
                        break;
                    }
                }
                if(flag == false) break;
            }
            if(flag == true){
                ans = "Yes";
                break;
            }
        }
        if(ans == "Yes"){
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n)                                                              \
    for (int64_t i = 0; i < (int64_t)(n); i++)                                 \
        ;
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;
using namespace std;
int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a, b;
    string res = "";
    cin >> a >> b;
    if (a <= b) {
        for (int i = 0; i < b; i++) {
            cout << a;
        }
    } else {
        for (int i = 0; i < a; i++) {
            cout << b;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
n, k , q = map(int, input().split())
a = []
for i in range(q):
  a.append(int(input()))

ans = [k] * n

for i in range(n):
  ans[i] -= q
for i in range(q):
  ans[a[i]-1] +=1
for i in range(n):
  if ans[i] > 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 11780
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;
typedef vector<int> Vec;
typedef vector<Vec> Mat;

Mat mul(Mat &A, Mat &B) {
    Mat C(A.size(),Vec(B[0].size()));
    rep(i,A.size()) rep(k,B.size()) rep(j,B[0].size()) {
        C[i][j]+=A[i][k]*B[k][j];
        if(C[i][j]) C[i][j]=1;
    }

    return C;
}

Mat pow(Mat A, int n) {
    Mat B(A.size(), Vec(A.size()));
    rep(i,A.size()) B[i][i]=1;
    while(n) {
        if(n&1) B=mul(B,A);
        A=mul(A,A);
        n>>=1;
    }
    return B;
}

vector<int> G[52];
int n,m;
int a,b,c;
int steps[3];
Mat mat[3];
int d[52];
int goal;

bool ok(int v,int u) {
    bool f=true;
    rep(i,3) f&=mat[i][v][u]!=0;
    return f;
}

int nextCost(int u) {
    int ret=-1;
    rep(i,3) {
        int t=INF;
        rep(v,n) {
            if(mat[i][v][u]>0) {
                t=min(t,d[v]);
            }
        }

        ret=max(ret,t);
    }

    return ret;
}

void bfs() {
    d[goal]=0;
    bool f=true;
    while(f) {
        f=false;
        //printf("debug %d %d\n",v,d[v]);
        rep(u,n) {
            int t=nextCost(u);
            if(t==-1||t==INF) continue;
            if(d[u]>t+1) {
                f=true;
                d[u]=t+1;
            }
        }
    }
}

int main() {
    rep(i,52) d[i]=INF;
    cin>>n>>m;
    cin>>a>>b>>c;
    steps[0]=a; steps[1]=b; steps[2]=c;
    goal = n-1;
    rep(i,3) mat[i]=Mat(52,Vec(52));
    rep(i,m) {
        int s,t;
        cin>>s>>t; s--;t--;
        G[t].pb(s);
        rep(i,3) mat[i][t][s]=1;
    }
    rep(i,3) mat[i]=pow(mat[i],steps[i]);
    bfs();
    int ans=d[0];

    if(ans==INF) cout<<"IMPOSSIBLE"<<endl;
    else cout<<ans<<endl;
    return 0;
}

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

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; i++) cin >> a[i];
    int homework = 0;
    for (int i = 0; i < m; i++) homework += a[i];
    if (n < homework) cout << -1 << endl;
    else cout << n - homework << endl;
    return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int x[111];

int main(void){
	int n,i,p,ans=INF,tmp;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> x[i];
	}
	for(p=0; p<101; ++p){
		tmp = 0;
		for(i=0; i<n; ++i){
			tmp += (x[i]-p)*(x[i]-p);
		}
		ans = min(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 1e5+5;
const int mod = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
   	int n;
   	cin>>n;
   	vector<pair<int,int>> a(n);
   	for(int i=0;i<n;i++) {
   		cin>>a[i].first;
   		a[i].second = i+1;
   	}
   	sort(a.begin(),a.end());
   	for(int i=0;i<n;i++)
   		cout<<a[i].second<<' ';
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<map>
using namespace std;
typedef map<int, int> mii;

bool check(int *numl, int *newl, int n = 0){
  for (int i = 0; i < n; i++) {
    if(numl[i] != newl[i])return false;
  }
  return true;
}

void printline(int *line, int n){
  std::cout << "printline:" << std::endl;
  for (int i = 0; i < n; i++) {
    std::cout << line[i] << " ";
  }
  std::cout << std::endl;
}

int main(){
  int n;
  while(cin >> n, n){
    int numl[n], newl[n], ans = 0;
    mii counter;

    for (int i = 0; i < n; i++) {
      cin >> numl[i];
      
      if(counter.find(numl[i]) == counter.end()){
        counter[numl[i]] = 1;
      }else{
        counter[numl[i]]++; 
      }
    }
    
    while(!check(newl, numl, n)){
      ans++;
      for (int i = 0; i < n; i++) {
        newl[i] = numl[i];
        numl[i] = counter[numl[i]];
      }
      
      counter.clear();

      for (int i = 0; i < n; i++) {
        if(counter.find(numl[i]) == counter.end()){
          counter[numl[i]] = 1;
        }else{
          counter[numl[i]]++; 
        }        
      }

      //printline(numl, n);
    }
    std::cout << ans - 1 << std::endl;
    for (int i = 0; i < n - 1; i++) {
      std::cout << newl[i] << " ";
    }
    std::cout << newl[n - 1] <<std::endl;
  }
  return 0;
}

Measured memory_bytes: 1196
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.math.*;

public class Main {
	
    public static void main(String[] args) {
	FastScanner sc = new FastScanner();
	
	int K = sc.nextInt();
	int A = sc.nextInt();
	int B = sc.nextInt();
	
	if((B-A) <=2){
		System.out.println(K+1);
	}
	else{
		//まずはA枚ためる
		BigInteger num = BigInteger.valueOf(A);
		K = K-(A-1);
		
		//2回でB-A枚ふえる
		num = num.add(BigInteger.valueOf((B-A)).multiply(BigInteger.valueOf(K/2)));
		
		//操作1回余ったら1枚増やす
		if(K%2 == 1){
			num = num.add(BigInteger.valueOf(1));
		}
		
		System.out.println(num);
	}
	
    }
    
}

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: 22228
#include <bits/stdc++.h>
using namespace std;

std::vector<long long int> enum_div(long long int n) {
    std::vector<long long int> ret;
    for(long long int i=1 ; i*i<=n ; ++i) {
        if(n%i == 0) {
            ret.push_back(i);
            if(i!=1 && i*i!=n) {
                ret.push_back(n/i);
            }
        }
    }
    ret.push_back(n);
    return ret;
}

int main() {
    int a, b, c, ans = 0;
    cin >> a >> b >> c;
    vector<long long int> v = enum_div(c);
    if(c == 1) v.pop_back();
    for(int i = 0; i < v.size(); ++i) {
        if(v[i] >= a && v[i] <= b) {
            ans++;
        }
    }
    cout << ans << '\n';
}



Measured memory_bytes: 3148
import numpy as np

a = int(input())
b = input().split()
c = []
for i in range(a):
  c.append(int(b[i]))
ans = 0
for i in range(a):
  for j in range(a):
    d = c[i] - c[j]
    d = np.abs(d)
    if(ans < d):
       ans = d
print(ans)

Measured memory_bytes: 21536
from math import factorial as step
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in range(n):
  if a[i] in dic:
    dic[a[i]] += 1
  else:
    dic[a[i]] = 1

def ncr(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return step(n) // (step(r) * step(n-r))

# valueのncrのリストを作っておく
all = sum([ncr(v,2) for v in dic.values()])
for i in range(n):
  print(all-dic[a[i]]+1)

Measured memory_bytes: 112332
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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 V, E;
typedef pair<int, pair<int, int>> edge;
vector<edge> g;
int par[10010];

void init() {
    rep(i, V) par[i] = i;
}

// xの根を求めるときにxを根につなぎ直す
int root(int x) {
    if (par[x] == x) return x;
    par[x] = root(par[x]);
    return par[x];
}

void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[ry] = rx;
}

bool same(int x, int y) {
    return root(x) == root(y);
}

int main() {
    cin >> V >> E;
    g.resize(V);
    rep(i, E) {
        int s, t, d; cin >> s >> t >> d;
        g.pb(make_pair(d, make_pair(s,t)));
    }
    sort(g.begin(), g.end());

    init();
    ll ans = 0;
    for (edge e: g) {
        int cost = e.first;
        int from = e.second.first;
        int to = e.second.second;
        if (!same(from, to)) {
            ans += cost;
            unite(from, to);
        }
    }
    cout << ans << endl;
}



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

#define ll long long
using namespace std;

int main()
{
	int a, b, q;
	cin >> a >> b >> q;
	vector<ll> s;
	s.push_back(-1145141919810364364);
	for (int i = 0; i < a; i++)
	{
		ll _;
		cin >> _;
		s.push_back(_);
	}
	s.push_back(1145141919810364364);
	vector<ll> t;
	t.push_back(-1145141919810364364);
	for (int i = 0; i < b; i++)
	{
		ll _;
		cin >> _;
		t.push_back(_);
	}
	t.push_back(1145141919810364364);
	for (int i = 0; i < q; i++)
	{
		ll x;
		cin >> x;
		ll ls = abs(x - *(upper_bound(s.begin(), s.end(), x) - 1));
		ll rs = abs(x - *lower_bound(s.begin(), s.end(), x));
		ll lt = abs(x - *(upper_bound(t.begin(), t.end(), x) - 1));
		ll rt = abs(x - *lower_bound(t.begin(), t.end(), x));
		ll left = max(ls, lt);
		ll mid = min(ls, rs) + min(lt, rt) + min(min(ls, rs), min(lt, rt));
		ll right = max(rs, rt);
		cout << min(min(left, mid), right) << endl;
	}
	return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15); 
    int n; 
    cin >> n;
    for (int i = n; i <= 999; ++i) {
        int x = i; 
        int o1 = x % 10; x /= 10;
        int o2 = x % 10; x /= 10; 
        int o3 = x; 
        if (o1 == o2 && o2 == o3) {
            cout << i << endl; 
            break; 
        }
    }
    return 0; 
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(D: int, T: int, S: int):
    if S*T>=D:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    D = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    solve(D, T, S)

if __name__ == '__main__':
    main()


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

#define pb push_back
#define ll long long int
#define mod 100000
#define for1(k,n) for(ll i=k;i<n;i++)
#define for2(k,n) for(ll j=k;j<n;j++)
#define E cout<<endl
#define max 100000




int main()
{
#ifndef ONLINE_JUDGE
	clock_t tStart = clock();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base:: sync_with_stdio(false);
	cin.tie(0);
//////////////////////////////////////start...............

	int n, data;
	vector <int> vec;

	cin >> n;
	for1(0, n)
	{
		cin >> data;
		vec.pb(data);
	}
	int xmin = *min_element(vec.begin(), vec.end());
	int xmax = *max_element(vec.begin(), vec.end());

	//cout << xmin << " " << xmax << endl;
	ll ans = 99999999999; ll sum;
	for (int j = xmin; j <= xmax; j++) {
		sum = 0;
		int s;
		for1(0, n)
		{	s = vec[i] - j;
			sum = sum + (s * s);

		}
		if (sum < ans)
			ans = sum;
	}



	cout << ans;


/////////////////////////////end.......................................
#ifndef ONLINE_JUDGE
	cout << "\nDone in " << (double) clock() / CLOCKS_PER_SEC << "sec" << endl;
#endif
	return 0;

}

//c v a s selecting text or x for selecting cut
//ctrl+d after selecting text to select same type
//ctrl+shift+d for copy and paste the line below it
//ctrl+del to delete a text
//ctrl+left to jump left of line or vice versa
//ctrl+shift+"/"  to comment whole block and vice versa for undo
//ctrl+"/" for commenting a line

/*
when N <= 10, then both O(N!) and O(2N) are ok (for 2N probably N <= 20 is ok too)
when N <= 100, then O(N3) is ok (I guess that N4 is also ok, but never tried)
when N <= 1.000, then N2 is also ok
when N <= 1.000.000, then O(N) is fine (I guess that 10.000.000 is fine too, but I never tried in contest)
finally when N = 1.000.000.000 then O(N) is NOT ok, you have to find something better…*/

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    map<string, ll> m;
    for (ll i = 0; i < n; i++)
    {
        string t;
        cin >> t;
        m[t]++;
    }
    ll _max = 0;
    vector<string> ans;
    for (auto t : m)
    {
        if (_max < t.second)
        {
            vector<string> a;
            a.push_back(t.first);
            ans = a;
            _max = t.second;
        }
        else if (_max == t.second)
        {
            ans.push_back(t.first);
        }
    }
    sort(ALL(ans));
    for (auto t : ans)
    {
        cout << t << endl;
    }
}

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

int main(){
ll h,n,sum=0;
cin>>h>>n;
int a[n];
REP(i,n){
    cin>>a[i];
    sum+=a[i];
}
if (sum>=h)
{
    cout<<"Yes"<<endl;
}
else
{
    cout<<"No"<<endl;
}



}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  long int a,b,x,d,e;
  cin>>a>>b>>x;
  d=a*x/b;
  e=a*(b-1)/b;
  if(x>=b-1)cout<<e<<endl; 
  else cout<<d<<endl;
}


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

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

int h, w;
vector<string> g;

int bfs(vector<P> &bs) {
  queue< pair<P, int> > q;
  for (int i = 0; i < (int)bs.size(); ++i) {
    q.emplace(bs[i], 0);
  }
  int ans = 0;

  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, -1, 0, 1};
  while (!q.empty()) {
    P cur = q.front().first;
    int cost = q.front().second;
    ans = max(ans, cost);
    q.pop();
    for (int i = 0; i < 4; ++i) {
      int next_y = cur.first + dy[i];
      int next_x = cur.second + dx[i];
      if (next_x < 0 || next_x >= w || next_y < 0 || next_y >= h || g[next_y][next_x] != '.') continue;
      g[next_y][next_x] = '#';
      q.emplace(make_pair(next_y, next_x), cost + 1);
    }
  }
  return ans;
}

int main() {
  cin >> h >> w;
  g.resize(h);
  vector<P> bs;
  for (int i = 0; i < h; ++i) {
    cin >> g[i];
    for (int j = 0; j < w; ++j) {
      if (g[i][j] == '#') {
	bs.emplace_back(i, j);
      }
    }
  }

  cout << bfs(bs) << endl;
  return 0;
}



Measured memory_bytes: 21244
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

int main() {

	int N, K, D[15];
	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		cin >> D[i];
	}

	int num = N;
	while(1) {
		bool flag = true;
		int tmp = num;
		for (int i = 0; i < 5; i++) {
			for (int j = 0; j < K; j++) {
				if (tmp % 10 == D[j]) flag = false;
			}
			tmp /= 10;
			if (tmp == 0) break;
		}
		if (flag) break;
		num++;
	}

	cout << num << endl;

	return 0;
}

Measured memory_bytes: 256