akhauriyash/Code-Regression huggingface dataset:
//break the given number into digits , check if that digit is present in the given number if flag==0 
//then skip and print else increase the number by 1 and check again.... 

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
  int n,k;
  cin >> n >> k;

  vector<int> v;
  
  for(int i = 0; i < k; ++i){
    int s;
    cin >> s;
    v.push_back(s);
  }

  while(true){
    int d = n;
    int flag = 0;
    while(d > 0){
      for(int i = 0; i < v.size(); ++i){
        if(d%10 == v[i])
          flag++;
      }
      d /= 10;
    }
    if(flag == 0)
      break;
    ++n;
  }

  cout << n << endl;

  return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> sw(N);

  // ボタンを消した後、次に光るボタンの番号を配列に格納
  for(int i = 0; i < N; i++)
    cin >> sw.at(i);

  int cnt = 0;
  int next = 0; // ボタン1を消した後、光るボタンの番号は要素0にある
  while(1){
    if(cnt >= N) { // 全てのボタンを調べたら終了
      cnt = -1;
      break;
    }else if(next + 1 == 2){  // ボタン2が光っている状態でやめる
      break;
    }
    next = sw[next] - 1;  //次のボタン(要素の内容 - 1)
    cnt++;
  }

  cout << cnt << endl;

}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl);
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;


vector<vector<int> > G;
int n, k;
void rec(int v, int p, int depth, vector<int> &dis){
    dis[v] = depth;
    for(auto nv : G[v]) {
        if(nv == p) continue;
        rec(nv, v, depth+1, dis);
    }
}


int main(){

    cin >> n >> k;
    G.resize(n);
    rep(i, n-1){
        int a, b;
        scanf("%d%d", &a, &b);
        --a; --b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    int ans = n;
    vector<int> dis(n);
    if(k%2) {
        rep(i, n){
            for(auto v : G[i]) {
                dis[v] = 0;
                rec(i, v, 0, dis);
                rec(v, i, 0, dis);
                int cut = count_if(dis.begin(), dis.end(), [](int d){
                    return d > k/2;
                });
                chmin(ans, cut);
            }
        }
    }
    else{
        rep(i, n){
            rec(i, -1, 0, dis);
            int cut = count_if(dis.begin(), dis.end(), [](int d){
                return d > k/2;
            });
            chmin(ans, cut);
        }
    }

    ppp(ans);



    return 0;
}


Measured memory_bytes: 512
#include <iostream>                                                                                                   
#include <vector>
#include <algorithm>
  
  int main(){
     int N;
     std::cin >> N;
     std::vector<int> d(N);
     for(int i=0; i<N; ++i)
        std::cin >> d[i];
  
     std::sort(d.begin(),d.end());
  
     int ans = 1;
     for(int i=N-2; i>=0; --i){
        if(d[i]!=d[i+1]) ++ans;
     }
     std::cout << ans << std::endl;
     return 0;
  }

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

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define obit __builtin_popcount
#define pof pop_front
#define mod (int)1e9 + 7
#define For(i,a,n) for(i=a;i<n;i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned short int us;
typedef short int ss;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    /*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    //*/
    ll n,cnt = 0;
    cin>>n;
    ll ar[n],i;
    For(i,0,n){
        cin>>ar[i];
        ar[i]--;
    }
    For(i,0,n){
        if(ar[i] != i && ar[ar[i]] == i) cnt++;
    }
    cout<<cnt/2;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>

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

    int val;
    std::vector<int> a(n);
    for(int i = 0; i < n; ++i){
        std::cin >> val;
        a.at(i) = val - (i + 1);
//        std::cout << a.at(i) << std::endl;
    }

    std::sort(a.begin(), a.end());
    int median = a.at(n / 2);
    if(0 == n % 2){
        median = (a.at(n / 2 - 1) + a.at(n / 2)) / 2;
    }
    long long ans = 0;
    for(int i = 0; i < n; ++i){
        ans += abs(a.at(i) - median);
    }

//    std::cout << median << std::endl;
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
struct SegmentTree {
    int N;
    vector<int> A;  // value = idx + A[i]
    vector<bool> B; // lazy value?
    vector<int> M;  // min [value]
    SegmentTree(int n) {
        N = 1;
        while (n > N) N *= 2;
        A.resize(2*N), B.resize(2*N), M.resize(2*N);
    }
    void set_(int L, int R, int val, int node, int nodeL, int nodeR) {
        if (R <= nodeL || nodeR <= L) {
            return;
        } else if (L <= nodeL && nodeR <= R) {
            A[node] = val;
            B[node] = true;
            M[node] = val + nodeL;
        } else {
            if (B[node]) {
                A[2*node+0] = A[2*node+1] = A[node];
                B[2*node+0] = B[2*node+1] = true;
                M[2*node+0] = A[node] + nodeL;
                M[2*node+1] = A[node] + (nodeL+nodeR)/2;
                B[node] = false;
            }
            set_(L, R, val, 2*node+0, nodeL, (nodeL+nodeR)/2);
            set_(L, R, val, 2*node+1, (nodeL+nodeR)/2, nodeR);
            M[node] = min(M[2*node+0], M[2*node+1]);
        }
    }
    int minimum_(int L, int R, int node, int nodeL, int nodeR) {
        if (R <= nodeL || nodeR <= L) {
            return INT_MAX;
        } else if (L <= nodeL && nodeR <= R) {
            return M[node];
        } else {
            if (B[node]) {
                A[2*node+0] = A[2*node+1] = A[node];
                B[2*node+0] = B[2*node+1] = true;
                M[2*node+0] = A[node] + nodeL;
                M[2*node+1] = A[node] + (nodeL+nodeR)/2;
                B[node] = false;
            }
            int v1 = minimum_(L, R, 2*node+0, nodeL, (nodeL+nodeR)/2);
            int v2 = minimum_(L, R, 2*node+1, (nodeL+nodeR)/2, nodeR);
            return min(v1, v2);
        }
    }
    void set(int L, int R, int val) {
        set_(L, R, val - L, 1, 0, N);
    }
    int minimum(int L, int R) {
        return minimum_(L, R, 1, 0, N);
    }
};
int main() {
    int H, W; cin >> H >> W;
    SegmentTree st(W + 1);
    st.set(0, 1, 1e9);
    for (int i = 0; i < H; i++) {
        int a, b; cin >> a >> b;
        st.set(a, b+1, st.minimum(a-1, a) + 1);
        int val = st.minimum(1, W+1);
        cout << (val >= 1e9 ? -1 : val + i + 1) << '\n';
    }
    return 0;
}


Measured memory_bytes: 7412
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int A = sc.nextInt();
   int B = sc.nextInt();
   int C = sc.nextInt();

   if(B>=A*C) System.out.println(C);
   else System.out.println(B/A);
 }
}

Measured memory_bytes: 22868
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int MOD = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        const double EPS = 1e-8;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };
        //static List<List<int>> G = new List<List<int>>();
        //static List<List<Edge>>G = new List<List<Edge>>();
        //static List<Edge> E = new List<Edge>();
        
        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            int[] ans = { 1, 2, 3 };
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            for(var i = 0; i < 3; i++)
            {
                if (ans[i] != a && ans[i] != b) { Console.WriteLine(ans[i]); }
            }

            //Console.Out.Flush();
        }
        struct Edge
        {
            public int from;

            public int to;
            public long dist;
            public Edge(int t, long c)
            {
                from = -1;
                to = t;
                dist = c;
            }
            public Edge(int f, int t, long c)
            {
                from = f;
                to = t;
                dist = c;
            }

        }
    }
    public class Scanner
    {
        public int[] ReadSplit()
        {
            return ConvertAll(Console.ReadLine().Split(), int.Parse);
        }
        public long[] ReadSplitL()
        {
            return ConvertAll(Console.ReadLine().Split(), long.Parse);
        }
        public double[] ReadSplitD()
        {
            return ConvertAll(Console.ReadLine().Split(), double.Parse);
        }
    }
    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
        static public void Swap<T>(ref T a, ref T b)
        {
            T keep = a;
            a = b;
            b = keep;
        }

        static public void Display<T>(T[,] array2d, int n, int m)
        {
            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < m; j++)
                {
                    Console.Write($"{array2d[i, j]} ");
                }
                Console.WriteLine();
            }
        }

    }
}


Measured memory_bytes: 11092
from queue import Queue
K = int(input())
q = Queue()
for i in range(1,10):
    q.put(i)

cnt = 9
ans = 0
while True:
    if K <= cnt:
        print(K)
        break
    l = q.get()
    end = l % 10
    for i in range(-1,2):
        i += end
        if 0 <= i <= 9:
            q.put(l*10+i)
            cnt += 1
            if cnt == K:
                ans = l*10+i

    if cnt >= K:
        print(ans)
        break


Measured memory_bytes: 45192
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
      Scanner sc = new Scanner(System.in);
      ArrayList<Integer> mountains = new ArrayList<Integer>();
      for(int i = 0; i < 10; i++){
          mountains.add(sc.nextInt());
      }
      Collections.sort(mountains);
      Collections.reverse(mountains);
      for(int i = 0; i < 3; i++){
          System.out.println(mountains.get(i));
      }
    }
}

Measured memory_bytes: 26144
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,n;
  cin>>k>>n;
  int x=k-1;
  
  for(int i=0;i<=x;i++)
  {
    int max=n-k+i+1;
    if(max>=-1000000){
      cout<<max<<" ";
    }
    
  }
  for(int i=1;i<=x;i++){
    int min=n+i;
      if(min<=1000000){
        cout<<min<<" ";
      }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e7+9;
int main()
{
    FASTINOUT;
    int x,k,y;
    cin>>x>>k;
    int sum=0;
    for (int i=0;i<k;i++)
    {
        cin>>y;
        sum+=y;
    }
    if (sum<=x)
        cout<<x-sum<<endl;
    else
        cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 3656
S = input()
T = S[:len(S)//2]
U = S[(1+len(S)//2):]

def kaibun(s):
    for k in range(len(s)//2):
        if s[k] != s[-k-1]:
            return False
    return True
if kaibun(S) == kaibun(U) == kaibun(T) == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int k;
    string s;
    cin>>k>>s;
    if(s.size() <= k){
        cout<<s<<endl;
    }else{
        for(int i =0; i<k; i++){
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
    return 0;
}


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

int main() {
	char a1[3], a2[3];
	scanf("%s", a1);
	scanf("%s", a2);
	int ans = 0;
	for (int i = 0; i < 3; ++i)
		if (a1[i] == a2[i]) ++ans;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
using System;

namespace tst
{
    class Program
    {
        public static void Main()
        {
            string In = Console.ReadLine();
            bool flag = false;
            if (In[2] == In[3] && In[4] == In[5]) flag = true;
            if (flag) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13140
k,n=map(int,input().split())
a=list(map(int,input().split()))

ans=a[-1]-a[0]
for i in range(n-1,-1,-1):
    temp=a[i-1]+(k-a[i])
    #print(temp)
    if temp>0 and temp<ans:ans=temp
print(ans)

Measured memory_bytes: 26420
from collections import Counter

N =int(input())
cntA = Counter(map(int, input().split()))
len_cntA = len(cntA)
if len_cntA == 1:
    print(1)
    exit()

dif = 0
for key in cntA:
    dif += cntA[key] - 1

if dif % 2 == 1:
    print(len_cntA - 1)
else:
    print(len_cntA)


Measured memory_bytes: 22636
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	era := make([]int, n+2)
	for i := 0; i < n+2; i++ {
		era[i] = 1
	}
	for i := 2; i < n+2; i++ {
		for j := i; j < n+2; j += i {
			era[j]++
		}
	}
	var ans int64
	for i := 0; i < n+1; i++ {
		ans += int64(i) * int64(era[i])
	}
	fmt.Fprintln(writer, ans)
}


Measured memory_bytes: 82556
#include<bits/stdc++.h> 
using namespace std;
 
int main(){
 
  long long int N,D;
  long long count=0;
  cin >> N>>D;
  long double X[N][D];
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
    cin >> X[i][j];
    }
  }
 for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      long double T=0;
      for(int k=0;k<D;k++){
          T+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
      }
      T=sqrt(T);
      if(abs(T-floor(T))<0.00001){
          count++;
    }
  }
 }
  cout << count;
 return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define All(a) (a).begin(),(a).end()

int main(){ 
  ll n,cnt=0;
  string s;
  int tmp;
  ll ans[1000]={};
  cin>>n>>s;
  ll S[n][10]={};
  for(int i=0;i<n;i++){
    tmp=s[i]-'0';
    for (int j = i; j<n; j++){
      S[j][tmp]++;
    }
  }

  for(int i=1; i < s.size()-1;i++){
    tmp=s[i]-'0';
    for(int j=0;j<10;j++){
      if(S[i-1][j]){
        for(int k=0;k<10;k++){
          if(S[n-1][k]-S[i][k]){
            ans[tmp*100+10*j+k]++;
          }
        }
      }
    }
  }
  for (int i = 0; i <1000; i++)
  {
    if (ans[i]>0)cnt++;
  }


  cout << cnt <<endl;
  return 0;
}

Measured memory_bytes: 6012
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/**
 * 境界部分には気をつける(そこだけ別で処理するというのもあり)
 * 逆再生することで簡単になることもある
 */
public class Main {
    public Main() {
    }

    public static void main(String[] args ) {
            Main main = new Main();
            main.exec();
    }

    public void exec() {
        BufferedReader bf = null;
        try{
            bf = new BufferedReader(new InputStreamReader(System.in));
            exec_body(bf);
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally{
            if( bf != null ) {
                try {
                    bf.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public ArrayList<Integer> toList( String line ) {
    		ArrayList<Integer> list = new ArrayList<>();
    		if ( line == null || line.length() == 0 ) {
    			return list;
    		}

    		String[] lines = line.split(" ");
    		for( int i = 0; i < lines.length; i++ ) {
    			String element = lines[i];
    			list.add(Integer.valueOf(element));
    		}

    		return list;
    }

    public boolean isCalculable( int mVal, int index, ArrayList<Integer> aList ) {
    		if( mVal == 0 ) {
    			return true;
    		}
    		if( mVal < 0 ) {
    			return false;
    		}

    		if( index >= aList.size()) {
    			return false;
    		}

    		return isCalculable(mVal,index+1,aList) || isCalculable(mVal - aList.get(index).intValue(),index+1,aList);
    }

    public void exec_body( BufferedReader bf ) throws IOException {
    		bf.readLine();
    		ArrayList<Integer> aList = toList(bf.readLine());
    		bf.readLine();
    		ArrayList<Integer> mList = toList(bf.readLine());

    		for( Integer mVal : mList ) {
    			boolean isCalculable = isCalculable(mVal.intValue(),0,aList);
    			String msg = isCalculable ? "yes" : "no";
    			System.out.println(msg);
    		}
    }
}


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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

Int H,W;

int main(){
	cin>>H>>W;
	Int ans = 1e+18;
	REP(ct,2){
		if(H%3==0)ans = min(ans,0ll);
		else ans = min(ans,W);
		swap(H,W);
	}
	REP(ct,2){
		//H<=W
		Int tmin = W/3-10, tmax = W/3+10;
		for(Int t = tmin;t<=tmax;t++){
			if(t<0 or W<t)continue;
			Int h = H/2;
			Int A = H*t, B = (W-t)*h, C = (W-t)*(H-h);
			ans = min(ans,max({A,B,C})-min({A,B,C}));
		}
		swap(H,W);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct{
  int num1;
  int num2;
}Int;

int Cmp(const void *a, const void *b){
  return ((Int *)a)->num2 - ((Int *)b)->num2;
}

void Medians(int N, Int X[N]){
  int i, B[N];
  qsort(X, N, sizeof(Int), Cmp);
  for(i = 0;i < N;i++){
    if(i < N / 2) B[X[i].num1] = X[N/2].num2;
    else B[X[i].num1] = X[N/2-1].num2;
  }
  for(i = 0;i < N;i++) printf("%d\n", B[i]);
}

void Do(int N){
  int i;
  Int X[N];
  for(i = 0;i < N;i++){
    X[i].num1 = i;
    scanf("%d", &X[i].num2);
  }
  Medians(N, X);
}

int main(void){
  int N;
  scanf("%d", &N);
  Do(N);
  return 0;
}


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

int main() {
    string s;
    cin >> s;
    string coffee = "coffee";

    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
import numpy as np
a_list = list(map(int, input().split()))
sorted_list = sorted(a_list)
sorted_list[2] = sorted_list[2] - sorted_list[1]
sorted_list[1] = sorted_list[1] - sorted_list[0]
sorted_list[0] = 0
print(np.sum(sorted_list))

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

int n, a[202020];

int main()
{
    cin >> n;
    map<int, ll> mp1;
    map<int, ll> mp2;
    rep(i, n)
    {
        ll a;
        cin >> a;
        mp1[a + i]++;
        if(i - a > 0)
        {
            mp2[i - a]++;
        }
    }

    ll res = 0;
    for(auto x : mp1)
    {
        res += x.second * mp2[x.first];
    }
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 28864
#
# abc059 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4
1 -3 1 0"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """5
3 -6 4 -5 7"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """6
-1 4 3 2 -5 4"""
        output = """8"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    # n = odd : plus
    ansa = 0
    sa = 0
    for i in range(N):
        sa += A[i]
        if i % 2 == 0:
            if sa >= 0:
                ansa += abs(sa) + 1
                sa = -1
        else:
            if sa <= 0:
                ansa += abs(sa) + 1
                sa = 1

    # n = even : plus
    ansb = 0
    sb = 0
    for i in range(N):
        sb += A[i]
        if i % 2 == 0:
            if sb <= 0:
                ansb += abs(sb) + 1
                sb = +1
        else:
            if sb >= 0:
                ansb += abs(sb) + 1
                sb = -1

    print(min(ansa, ansb))


if __name__ == "__main__":
    #unittest.main()
    resolve()


Measured memory_bytes: 27604
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    ll G=A[0];
    rep(i,N){
        G=gcd(G,A[i]);
    }
    
    cout<<G<<endl;
}


Measured memory_bytes: 4060
#include<bits/stdc++.h>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
typedef long long ll;
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,ans=0,minus=0;
  cin>>N;
  vector<ll> A(N),B(N);
  REP(i,N){
    cin>>A[i];
    if(A[i]<0)minus++;
  }
  sort(all(A));
  REP(i,N){
    if(A[i]<0){
      B[i] = -A[i];
    }else{
      B[i]=A[i];
    }
  }
  sort(all(B));
  
  if(minus%2==0){
    REP(i,N){
      ans+=B[i];
    }
  }else{
    REP(i,N){
      ans+=B[i];
    }
    ans-=2*B[0];
  }
  cout<<ans;
  
  return 0;
}


Measured memory_bytes: 1792
// C - 4-adjacent
#include <bits/stdc++.h>
using namespace std;
int in(){int x;scanf("%d",&x);return x;}

int main(){
	int N = in(), c2 = 0, c4 = 0;
	for(int a,i=0; i<N; ++i){
		a = in();
		if(!(a&3)) c4++; else if(!(a&1)) c2++;
	}
	puts(N <= c4*2 + c2 + (c2>0?0:1)? "Yes":"No");
}

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

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		final int INF = 1 << 28;
		while (true) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int p = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			if ((n | m | p | a | b) == 0)
				break;
			int t[] = new int[n];
			for (int i = 0; i < n; i++) {
				t[i] = sc.nextInt();
			}
			int dis[][] = new int[m][m];
			for (int i = 0; i < m; i++) {
				Arrays.fill(dis[i], -1);
				dis[i][i] = 0;
			}
			for (int i = 0; i < p; i++) {
				int x = sc.nextInt()-1;
				int y = sc.nextInt()-1;
				int z = sc.nextInt();
				dis[x][y] = dis[y][x] = z;
			}
			double dp[][] = new double[1 << n][m];
			for (int i = 0; i < 1 << n; i++) {
				Arrays.fill(dp[i], Double.POSITIVE_INFINITY);
			}
			dp[(1 << n) - 1][a - 1] = 0;
			double res = Double.POSITIVE_INFINITY;
			for (int S = (1 << n) - 1; S >= 0; S--) {
				res = Math.min(res, dp[S][b - 1]);
				for (int v = 0; v < m; v++) {
					for (int i = 0; i < n; i++) {
						if((S>>i & 1) == 1)
						for (int u = 0; u < m; u++) {
							if (dis[v][u] < 0)
								continue;
							dp[S & ~(1 << i)][u] = Math.min(
									dp[S & ~(1 << i)][u], dp[S][v] + 1.0
											* dis[v][u] / t[i]);
						}
					}
				}
			}
			if (res == Double.POSITIVE_INFINITY) {
				System.out.println("Impossible");
			} else {
				System.out.printf("%.7f\n",res);
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
// URLD
double dx[4]={0,1,-1,0};
double dy[4]={1,0,0,-1};
long double eps = 1e-6;
long double pi = acos(-1);

int b = 100010;

class UnionFind{
    public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> parent;
    vector<array<ll,2>> x;


    UnionFind(int N){
        parent = vector<int>(N,-1);
        x = vector<array<ll,2>>(N);
        for(int i=0;i<N;i++){
            if(i<b)x[i] = {1,0};
            else x[i] = {0,1};
        }
    }

    int root(int A){
        if(parent[A] < 0) return A;
        return parent[A]=root(parent[A]);
    }

    array<ll,2> totori(int a){
        return x[a];
    }
    int size(int A){
        return -parent[root(A)];
    }

    bool unite(int A, int B) {
        A = root(A), B = root(B);
        if(A == B) return false; 

        if(size(A) < size(B)) swap(A,B);
        parent[A] += parent[B];
        parent[B] = A;
        x[A][0] += x[B][0];
        x[A][1] += x[B][1];
        return true;
    }

    bool same(int A, int B){
        return root(A)==root(B);
    } 
};

UnionFind uni(2*b);

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        uni.unite(x,y+b);
    }
    ll ans = 0;
    for(int i=0;i<2*b;i++){
        if(i == uni.root(i)){
            ll x = uni.totori(i)[0], y = uni.totori(i)[1];
            ans += x * y;
        }
    }
    cout << ans - n << endl;
}

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

int main(){

  string S;
  char p,q,r;

  cin>>S;

  p=S.at(0);
  q=S.at(1);
  r=S.at(2);

  if(p!=q&&p!=r&&q!=r){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, x;
  
  cin >> a;
  cin >> b;
  x = (a+b)/2;
  
  if((a+b)%2 == 0){
    cout << x << endl;
  }
  else{
    cout << x+1 << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int Ap = s.nextInt();
		int Bp = s.nextInt();
		int C = s.nextInt();
		int P = Ap;
		int t[] = new int[n];
		
		for(int i=0; i<n; i++){
			t[i] = s.nextInt();
		}
		
		Arrays.sort(t);
		
		for(int i=n-1; i>=0; i--)
		  if((double)t[i]/Bp > (double)C/P){
			   C+=t[i];
			   P+=Bp;
			  }

		System.out.println(C/P);

	}
}

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

using namespace std;

int read() {
  int res = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) res = res * 10 + c - '0', c = getchar();
  return res;
}

const int maxn = 2e6 + 5;
typedef vector<int> poly;

const int mod = 924844033;
void Inc(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }
void Dec(int &x, int y) { x -= y, x += x < 0 ? mod : 0; }
int inc(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
int dec(int x, int y) { return x < y ? x - y + mod : x - y; }
int mul(int x, int y) { return 1LL * x * y % mod; }
int fastpow(int base, int x) {
  int res = 1;
  while (x) {
    if (x & 1) res = mul(res, base);
    base = mul(base, base), x >>= 1;
  }
  return res;
}

namespace Poly {
const int G = 5, IG = 554906420;
int lim, tim, rev[maxn << 3];
void init(int N) {
  lim = 1, tim = rev[0] = 0;
  while (lim <= N) lim <<= 1, tim++;
  for (int i = 0; i < lim; i++)
    rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (tim - 1));
}
void NTT(poly &arr, int type) {
  for (int i = 0; i < lim; i++)
    if (i < rev[i]) swap(arr[i], arr[rev[i]]);
  for (int mid = 1; mid < lim; mid <<= 1) {
    int Wn = fastpow(type == 1 ? G : IG, (mod - 1) / (mid << 1));
    for (int j = 0; j < lim; j += (mid << 1)) {
      for (int k = 0, w = 1; k < mid; k++, w = mul(w, Wn)) {
        int x = arr[j + k], y = mul(arr[j + k + mid], w);
        arr[j + k] = inc(x, y);
        arr[j + k + mid] = dec(x, y);
      }
    }
  }
  if (type == -1) {
    int Ny = fastpow(lim, mod - 2);
    for (int i = 0; i < lim; i++) arr[i] = mul(arr[i], Ny);
  }
}
poly operator*(poly f, poly g) {
  int len_f = f.size(), len_g = g.size();
  init(len_f - 1 + len_g - 1);
  f.resize(lim, 0), NTT(f, 1);
  g.resize(lim, 0), NTT(g, 1);
  for (int i = 0; i < lim; i++) f[i] = mul(f[i], g[i]);
  NTT(f, -1), f.resize(len_f + len_g - 1);
  return f;
}
}  // namespace Poly
using Poly::operator*;

vector<int> G[maxn];
void link(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

int N, cnt[maxn], size[maxn];
void dfs(int x, int fa) {
  size[x] = 1;
  for (auto to : G[x]) {
    if (to == fa) continue;
    dfs(to, x);
    size[x] += size[to];
    cnt[size[to]]++;
  }
  if (fa) cnt[N - size[x]]++;
}

int fact[maxn], ifact[maxn], Ans[maxn];
int C(int x, int y) { return mul(fact[x], mul(ifact[y], ifact[x - y])); }
poly A, B;

int main() {
  N = read(), fact[0] = 1;
  for (int i = 1; i < N; i++) link(read(), read());
  for (int i = 1; i <= N; i++) fact[i] = mul(fact[i - 1], i);
  ifact[N] = fastpow(fact[N], mod - 2);
  for (int i = N; i >= 1; i--) ifact[i - 1] = mul(ifact[i], i);
  dfs(1, 0), assert(!cnt[0] && !cnt[N]);
  A.resize(N + 1), B.resize(N + 1);
  for (int i = 0; i <= N; i++) A[i] = mul(cnt[N - i], fact[N - i]);
  for (int i = 0; i <= N; i++) B[i] = ifact[i];
  A = A * B, A.resize(N + 1);
  for (int i = 1; i <= N; i++) Ans[i] = mul(N, C(N, i));
  for (int i = 0; i <= N; i++) Dec(Ans[N - i], mul(ifact[N - i], A[i]));
  for (int i = 1; i <= N; i++) printf("%d\n", Ans[i]);
  return 0;
}


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

ll pow(int x, int n){
    if(n==0) return 1;
    ll fh = pow(x,n/2);
    fh *= fh;
    if(n%2==1) fh *= x;
    return fh;
}

int main(void){
    ll h;
    cin >> h;
    
    int count = 0;
    while(h>0){
        count++;
        h /= 2;
    }

    cout << pow(2,count) - 1 << endl;


}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;

public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();
		int n = r.ri();
		int[] arr = r.ria();
		Arrays.sort(arr);
		print(arr[n-1]-arr[0]);
	}
	
	public static int getDigitSum(int n) {
		String str = ""+n;
		int sum = 0;
		for(int i = 0; i<str.length();i++) {
			sum += Integer.parseInt(""+str.charAt(i));
		}
		return sum;
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}
	
	public static void swap(int[] arr, int pos1, int pos2) {
		int temp = arr[pos1];
		arr[pos1] = arr[pos2];
		arr[pos2] = temp;
	}
	public static void swap(long[] arr, int pos1, int pos2) {
		long temp = arr[pos1];
		arr[pos1] = arr[pos2];
		arr[pos2] = temp;
	}
	
	public static String al(String s) {
		return s + "\n";
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
}

class Node {
	public int val;
	public boolean visited;
	public Node(int v) { val=v; }
}


Measured memory_bytes: 22612
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n; cin >> n;
  vector<ll> a(3 * n); rep(i, 3 * n) cin >> a[i];

  ll sum = 0;
  sort(a);
  for (int i = 3 * n - 2, j = 0; j < n; j++, i -= 2) {
    sum += a[i];
  }
  outl(sum);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 2560
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

class UnionFind {
 public:
  // parentの番号を格納する。親だった場合は-(その集合のサイズ)
  vector<int> Parent;

  //作成時は全て-1なので木が全て独立している状態
  UnionFind(int N) { Parent = vector<int>(N, -1); }

  // Aがどのグループに属しているか調べる
  int root(int A) {
    if (Parent[A] < 0)
      return A;
    else {
      return Parent[A] = root(Parent[A]);
    }
  }

  //自分のいるグループの頂点数を調べる //rootで親を取ってくる
  int size(int A) { return -Parent[root(A)]; }

  // AとBをくっつける
  bool connect(int A, int B) {
    // AとBを繋げるのではなくroot(A)とroot(B)を繋げる
    A = root(A);
    B = root(B);
    if (A == B) {
      //すでに繋がれているので繋がない
      return false;
    }

    //大きい方（A）に小さい方（B）をくっつけたい
    if (size(A) < size(B)) swap(A, B);

    // Aのサイズを変更する
    Parent[A] += Parent[B];
    // Bの親をAに変更する
    Parent[B] = A;

    return true;
  }
};

// https://www.youtube.com/watch?v=zV3Ul2pA2Fw
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);

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

  vector<long long> ans(M);
  ans[M - 1] = (long long)N * (N - 1) / 2;  // nC2

  UnionFind UF(N);  //頂点数はN個

  for (int i = M - 1; i >= 1; --i) {
    //繋がっていないものが繋がった場合
    if (UF.root(A[i]) != UF.root(B[i])) {
      ans[i - 1] = ans[i] - (long long)UF.size(A[i]) * UF.size(B[i]);
      UF.connect(A[i], B[i]);
    } else {
      ans[i - 1] = ans[i];
    }
  }

  for (int i = 0; i < M; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}


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

int main(){

	ll N;
	cin >> N;
	vector< pair<ll,ll> > A;
	for(int i=0;i<N;i++){
		ll a,b;
		cin >> a >> b;
		A.push_back(make_pair(a,b));
	}
	sort(A.begin(),A.end());
	ll ans = A[N-1].first + A[N-1].second;
	cout << ans << endl;
}


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

int saiki(int c[][10], int min, int my, int sum){
  if(min > sum + c[my][1]){
    min = sum + c[my][1];
  }
  for(int i = 0; i < 10; i++){
    if(i != 1 && my != i && min > c[my][i]+sum){
      int tmin = saiki(c, min , i, c[my][i]+sum);
      if(tmin < min){
	min = tmin;
      }
    }
  }
  return min;
}

int main(){
  int h,w;
  cin >> h >> w;
  int c[10][10],a;
  //a[h][w];
  
  for(int i = 0; i < 10; i++){
    for(int j = 0; j < 10; j++){
      cin >> c[i][j];
    }
  }

  int cost[10];
  for(int i = 0; i < 10; i++){
    int min = c[i][1];
    cost[i] = saiki(c,min,i,0);
  }
  int count = 0;
  for(int i = 0;i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> a;
      if(a != -1){
	count += cost[a];
      }
    }
  }
  
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a;
    scanf("%d",&a);
    if((a==19)||(a==29)||(a==39)||(a==49)||(a==59)||(a==69)||(a==79)||(a==89)||((a>=90)&&(a<=99)))
    printf("Yes");
    else
    printf("No");
}

Measured memory_bytes: 1728
#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

int a,b,sp=0;
	
	while(cin >> a >> b){
		if(a==0  && b==0 || cin.eof()) break;
		int cnt=0;
		if(sp != 0) cout << endl;
		while(1){
			if(a%400 == 0 || a%100 != 0 && a%4 == 0 ){
				cout << a << endl;
				cnt++;
			}
			a++;
			if(a > b) break;
		}	
		if(cnt==0) cout << "NA" << endl;
		sp = 1;
	}
	return 0;
	
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, m;
vector<PS> vps;

int main(){
	while (cin >> n >> m&&n){
		vps.clear();
		ll ans = 0;
		REP(i, n){
			string s;
			int k;
			cin >> s >> k;
			vps.push_back(PS(s, k));
		}
		REP(i, m){
			string s;
			cin >> s;
			REP(j, vps.size()){
				string t = vps[j].first;
				bool f = 1;
				REP(k, s.size()){
					if (t[k] != '*'&&s[k] != t[k])f = 0;
				}
				if (f){
					ans += vps[j].second;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1212
import java.util.*;
 
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long ans = 0;
		if ((B-A)%2 == 0) {
			ans = (B-A)/2;
		} else {
			ans = Math.min(A-1, N-B) + 1 + (B-A)/2;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23636
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll N) {
  cout << (N / 10 == 9 || N % 10 == 9) << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	solve(N);
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define MAX 1000000007
#define ull unsigned long long int
#define ll long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
using namespace std;

int main(){
    // fast i/o
    ios_base::sync_with_stdio(false);
    // unties cout and cin streams....
    cin.tie(0); cout.tie(0);
//    int t;
//    cin>>t;
//    while(t--){
//
//    }
      int n,m;
      int mp[100001]={0};
      cin>>n>>m;
      int h[n];
      fo(i,n){
          cin>>h[i];
      }
      int a,b;
      for(int i=0;i<m;i++){
          cin>>a>>b;
          if(h[a-1] > h[b-1]){
              mp[b]++;
          }
          else if (h[a-1] < h[b-1]){
              mp[a]++;
          }
          else{
              mp[a]++; mp[b]++;
          }
      }
      int ct=0;
      for(int i=1;i<=n;i++){
          if(mp[i]==0){
              ct++;
          }
      }
      cout<<ct<<endl;
    return 0;
}

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string get;
  cin >> get;
  bool ans = false;
  for(int i = 0; i < get.length(); i++){
    if(get[i] == '7'){
      ans = true;
      break;
    }
  }
  if(ans)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

Measured memory_bytes: 3652