akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int ans = Integer.MIN_VALUE;
        ans = Math.max(ans, A + B);
        ans = Math.max(ans, A - B);
        ans = Math.max(ans, A * B);
        System.out.println(ans);
    }

    private class MyScanner {
        String[] s;int i;BufferedReader br;String reg = " ";
        MyScanner () { s = new String[0];i = 0;br = new BufferedReader(new InputStreamReader(System.in)); }
        public String next() {
            try {
                if (i < s.length) return s[i++]; String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0); i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 21076
function Main(input: string) {
  const lines = input.split('\n');
  const params1 = lines[0].split(' ');

  const a = parseInt(params1[0]);
  const b = parseInt(params1[1]);


  const msg = (a * b % 2 === 0) ? 'No' : 'Yes';

  console.log(msg);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int rev_mod(long long int num){
	long long int pow_num = MOD - 2;
	long long int mod_num = MOD;
	long long int pow_cur = num;
	long long int ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

long long int pow_n(long long int num, long long int pow_num){
	long long int mod_num = MOD;
	long long int pow_cur = num;
	long long int ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

int main(){
	long long int n, a, b;
	cin >> n >> a >> b;
	long long int ans = pow_n(2, n);
	long long int S = 1;
	for(int i = 0; i < a; i++){
		S *= n - i;
		S %= MOD;
		S *= rev_mod(i + 1);
		S %= MOD;
	}
	ans += MOD - S;
	S = 1;
	for(int i = 0; i < b; i++){
		S *= n - i;
		S %= MOD;
		S *= rev_mod(i + 1);
		S %= MOD;
	}
	ans += MOD - S;
	ans %= MOD;
	ans += MOD - 1;
	ans %= MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
	map<string, bool> S;
	int n;

	cin>>n;
	for(int i=0; i<n; i++){
		string s;
		string tem;
		cin>>s;
		cin>>tem;
		if(s == "insert") {
			S[tem]=true;
		}else{
			
			if(S[tem]){
				cout<<"yes"<<endl;
			}
			else{
				cout<<"no"<<endl;
			}
		}
	}

	/*for(map<string, bool>::iterator it=S.begin(); it!=S.end(); it++){
		cout<<it->first<<" "<<it->second<<endl;
	}*/
	return 0;
}


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

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

    int n;
    cin >> n;
    
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    
    int sum = 0;
    
    for(int i = 1; i < n; i++){
        for(int j = 0; j < i; j++){
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main ()
{
    cin.sync_with_stdio(0);
  ll T; cin >> T; if (T>=30) cout << "Yes"; else cout << "No";
  cout << endl;
} //cin.tie(0) bei schnellem Wechseln

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

int main(){
	int x;
  	cin >> x;
  	vector<int> vec;
  	for(int i=0;i<x;i++){
    	int n;
      	cin >> n;
      	vec.push_back(n);
    }
  	int ans=0, tog = 1;
  	for(int i=0;i<x;i++){
    	if(vec[i]==tog) tog++;
      	else ans++;
    }
  	cout << (ans==vec.size()?-1:ans) << endl;
}

Measured memory_bytes: 1400
N,K = map(int,input().split())
P = list(map(int,input().split()))
for i in range(N):
    P[i] = (1+P[i])/2
A = 0
for i in range(K):
    A = A+P[i]
    B = A
for i in range(1,N-K+1):
    B = B-P[i-1]+P[i+K-1]
    if A < B:
        A = B
print(A)

Measured memory_bytes: 24812
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int d0[50],d1[50],m,mm;
long long ans,d,wei,te,ten[18];
//81000 wei+3
void dfs(int x,long long v,long long s){
	//if (abs(v)>d*10000) return;//12
	if (v<-d*11) return;//*105
	if (v>d*11&&v>(ten[m-x]-ten[x-1])*11) return;//*105
	//printf("%d %lld %lld\n",x,v,s);
	if (x>mm){//>m
		if (v==d){
			//printf("%d %lld %lld\n",x,v,s);
			if (m&1) ans+=s*10;else ans+=s;//(m>2)&&
		}
		return;
	}
	if (x==1){
		fo(i,-9,8) dfs(x+1,v+i*(ten[m-x]-ten[x-1]),s*d1[i+20]);//m-i+1 i
		return;
	}
	fo(i,-9,9) dfs(x+1,v+i*(ten[m-x]-ten[x-1]),s*d0[i+20]);
}
inline void sol(int wei){
	if (wei<=1) return;
	m=wei;mm=m/2;
	dfs(1,0,1);
}
int main(){
	scanf("%lld",&d);
	if (d%9!=0){
		printf("0\n");
		return 0;
	}
	if (d==9){
		printf("8\n");
		return 0;
	}
	ten[0]=1;fo(i,1,17) ten[i]=ten[i-1]*10;
	fo(i,0,9) fo(j,0,9) d0[i-j+20]++;
	fo(i,0,9) fo(j,1,9) d1[i-j+20]++;
	te=d;
	while (te){
		wei++;
		te/=10;
	}
	//printf("%lld\n",wei);
	fo(i,-2,9) sol(wei+i);//-8..8
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
     
public class Main{
    
    static InputReader ir;
    static PrintWriter out;

    static void solve(){
        Deque<int[]> que=new ArrayDeque<int[]>();
	int n=ir.nextInt();
	int q=ir.nextInt();
	String[] name=new String[n];
	for(int i=0;i<n;i++){
	    name[i]=ir.next();
	    que.offerLast(new int[]{i,ir.nextInt()});
	}
	int cur=0;
	while(!que.isEmpty()){
	    int[] a=que.pollFirst();
	    if(a[1]<=q){
		cur+=a[1];
		out.println(name[a[0]]+" "+cur);
	    }
	    else{
		cur+=q;
		que.offerLast(new int[]{a[0],a[1]-q});
	    }
	}
    }
 
    public static void main(String[] args) throws Exception {
	ir = new InputReader(System.in);
     	out = new PrintWriter(System.out);
	solve();
	out.flush();
     }
 
    static class InputReader {
	private InputStream in;
	private byte[] buffer=new byte[1024];
	private int curbuf;
	private int lenbuf;

	public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
   
	public boolean hasNextByte() {
	    if(curbuf>=lenbuf){
		curbuf= 0;
		try{
		    lenbuf=in.read(buffer);
		}catch(IOException e) {
		    throw new InputMismatchException();
		}
		if(lenbuf<=0) return false;
	    }
	    return true;
	}
  
	private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
	private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
  
	private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
	public boolean hasNext(){skip(); return hasNextByte();}
  
	public String next(){
	    if(!hasNext()) throw new NoSuchElementException();
	    StringBuilder sb=new StringBuilder();
	    int b=readByte();
	    while(!isSpaceChar(b)){
		sb.appendCodePoint(b);
		b=readByte();
	    }
	    return sb.toString();
	}
  
	public int nextInt() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    int res=0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public long nextLong() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    long res = 0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public double nextDouble(){return Double.parseDouble(next());}
  
	public int[] nextIntArray(int n){
	    int[] a=new int[n];
	    for(int i=0;i<n;i++)
		a[i]=nextInt();
	    return a;
	}
  
	public char[][] nextCharMap(int n,int m){
	    char[][] map=new char[n][m];
	    for(int i=0;i<n;i++)
		map[i]=next().toCharArray();
	    return map;
	}
    }
}



Measured memory_bytes: 47840
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

class UnionFind {
public:
  VI par, rank;
  UnionFind(int n) {
    par = VI(n); iota(par.begin(), par.end(), 0);
    rank = VI(n, 0);
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) { return; }
    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) { rank[x]++; }
    }
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};

struct edge { int u, v, cost; };
bool comp(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
int kruskal(int V, vector<edge>& es) {
  sort(es.begin(), es.end(), comp);
  UnionFind uf(V);
  int ans = 0;
  for (edge e: es) {
    if (uf.same(e.u, e.v)) { continue; }
    uf.unite(e.u, e.v);
    ans += e.cost;
  }
  return ans;
}
signed main() {
  int N;
  cin >> N;
  vector<P> xs(N), ys(N);
  REP (i, N) {
    cin >> xs[i].first >> ys[i].first;
    xs[i].second = i; ys[i].second = i;
  }
  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  vector<edge> es;
  REP (i, N-1) {
    es.push_back({xs[i].second, xs[i+1].second, xs[i+1].first - xs[i].first});
    es.push_back({ys[i].second, ys[i+1].second, ys[i+1].first - ys[i].first});
  }
  cout << kruskal(N, es) << endl;
}


Measured memory_bytes: 11632
#include <stdio.h>

int main() {

  int a, h, m, s;
  scanf("%d", &a);
  h = a / 3600;
  m = (a % 3600) / 60;
  s = (a % 60);
  printf("%d:%d:%d\n", h, m, s);

  return 0;

}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int Rmax = count(all(s),'R');
  vector<int> Rsum(n,Rmax);
  vector<int> Wsum(n,0);
  int ans = Rsum[0];
  rep(i,n){
    if(i == 0){
      Rsum[i] -= s[i] == 'R';
      Wsum[i] += s[i] == 'W';
    }else{
      Rsum[i] = Rsum[i-1] - (s[i] == 'R');
      Wsum[i] = Wsum[i-1] + (s[i] == 'W');
    }
    ans = min(ans,max(Rsum[i],Wsum[i]));
  }
  cout << ans << endl;
}


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

#define x first
#define y second

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(
      max(
        a * c,
        b * c
        ),
      max(
        a * d,
        b * d
        )
      ) << '\n';

  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
 
int main(){
    std::vector<int> number;
    int inputNum,tmp;
 
    std::cin >> inputNum;
 
    //input
    for(int i = 0; i < inputNum; ++i){
        std::cin >> tmp;
        number.push_back(tmp);
    }
 
    std::vector<std::vector<long int>> vec(inputNum + 1, std::vector<long int>(21, 0));
 
    vec[0][number[0]] = 1;
 
    for(int i = 0; i < inputNum; ++i){
        for(int j = 0; j < 21; j++){
            if(vec[i][j] != 0){
 
                //addition
                if(j + number[i + 1] <= 20) vec[i+1][j + number[i + 1]] += vec[i][j];
 
                //subtraction
                if(j - number[i + 1] >= 0) vec[i+1][j - number[i + 1]] += vec[i][j];
            }
        }
    }
    //output
    std::cout << vec[inputNum - 2][number[inputNum - 1]] << std::endl;
 
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  float nums[n];
  float sum = 0.0;
  
  for(int i = 0; i < n; i++) {
    cin >> nums[i];
    sum += (1.0/nums[i]);
  }
  
  cout << 1/sum << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Gcd{
    
    public static long gcd(long m, long n){
        if(n==0) {return m;}
        if(m >= n) {return gcd(n, m % n);}

        if(m==0) {return n;}
        if(m < n) {return gcd(m, n % m);}

        return 0;
    }
    
}

public class Main{

    static int INFTY = Integer.MAX_VALUE;
    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        long ans=0;
        
        //0からBまでのCの倍数
        //0からA-1までのCの倍数
        long cNum=B/C-(A-1)/C;

        //0からBまでのDの倍数
        //0からA-1までのDの倍数
        long dNum=B/D-(A-1)/D;
        

        long maxKouyakusuu =C*D/Gcd.gcd(C,D);
        //0からBまでのC,Dの最小公倍数の倍数
        //0からA-1までのC,Dの最小公倍数の倍数
        long kouyakuNum=B/maxKouyakusuu-(A-1)/maxKouyakusuu;

        ans=(B-A+1)-(cNum+dNum-kouyakuNum);

        System.out.println(ans);
       

    }


}

Measured memory_bytes: 21844
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;




int main() {

ll N;
cin>>N;
int num=(int)floorl(logl(N)/logl(10));
cout<<(N+1)/(ll)powl(10,num)-1+9*num<<endl;
return 0;
}

Measured memory_bytes: 3680
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    long long int  n,tmp;
    cin>>n;
    long long int ans=1;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    rep(i,n){if(a[i]==0){
                cout<<0;
                return 0;
            }
        }
    rep(i,n){
        if(a[i] <= 1000000000000000000/ans){
            ans*=a[i];
        }else{
            cout<<-1;
            return 0;       
        }
    }
    
    cout<<ans;

    return 0;
}

Measured memory_bytes: 3988
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <list>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <cstring>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;

const int SIZE=100005;
int n;
long long a[SIZE],b[SIZE],c[SIZE];

int main(){
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	for(int i=0;i<n;i++) cin>>c[i];
	long long ans=0;
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	for(int i=0;i<n;i++){
		int cur=b[i];
		int p=lower_bound(a,a+n,cur)-a;
		int q=upper_bound(c,c+n,cur)-c;
		ans+=((long long)p)*((long long)(n-q));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2560
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

#[allow(unused_macros)]
macro_rules! chmin {
    ( $ x : expr , $ y : expr ) => { if $ x > $ y { $ x = $ y ; true } else { false } };
}

fn main() {
    input! {
        n: usize
    }

    std::thread::Builder::new()
        .name("BIG".into())
        .stack_size(32 * 1024 * 1024)
        .spawn(move || {
            let mut dp = vec![None;n+1];
            dp[0] = Some(0);
            println!("{}", rec(n,&mut dp));
        })
        .unwrap()
        .join()
        .unwrap();
}

fn rec(n: usize, dp: &mut [Option<u64>]) -> u64 {
    if let Some(src) = dp[n] {
        return src;
    }

    let mut ret = 1u64 << 60;
    chmin!(ret, rec(n-1,dp));
    for i in (1..).take_while(|&i| 6usize.pow(i) <= n) {
        chmin!(ret, rec(n-6usize.pow(i),dp));
        if n >= 9usize.pow(i) {
            chmin!(ret, rec(n-9usize.pow(i),dp));
        }
    }
    ret += 1;
    dp[n] = Some(ret);
    ret
}


Measured memory_bytes: 16764
#include<bits/stdc++.h>
using namespace std;
string s,t;
set<string> st;
set<string>::iterator ip;
int l,k;
int main()
{
    cin>>(s);
    l=s.length();
    cin>>k;
    for(int i=0;i<=l;i++)
    {
        for(int le=1;le<=k&&i+le-1<l;le++)
        {
            t=s.substr(i,le);
            //cout<<t<<endl;
            st.insert(t);
        }
        
    }
    ip=st.begin();
    for(int i=1;i<k;i++) ip++;
    cout<<*ip;
    //cout<<*st.begin();
    //system("pause");
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int h,w;
    cin >> h >> w;
    int mar[20][20];
    rep(i,10){
        rep(j,10){
            cin >> mar[i][j];
        }
    }
    rep(k,10){
        rep(i,10){
            rep(j,10){
                mar[i][j]=min(mar[i][j],mar[i][k]+mar[k][j]);
            }
        }
    }
    int ans=0;
    rep(i,h){
        rep(j,w){
            int a;
            cin >> a;
            if(a==-1)continue;
            ans += mar[a][1];
        }
    }
    cout << ans << endl;

    

    return 0;
}

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

using namespace std;

void isSquareNum(double num){
	if(sqrt(num)-((int)sqrt(num)) == 0.0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main(){
    string a, b;
    cin >> a >> b;
    isSquareNum((double)(stoi(a+b)));
    return 0;
}



Measured memory_bytes: 256
/*
Author : shah_entrance
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,i,sum=0;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    sort(arr,arr+n);
    sum-=(arr[n-1]/2);
    cout<<sum<<endl;
    return 0;
}


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

X,Y,Z,K=MAP()
A=sorted(LIST(), reverse=True)
B=sorted(LIST(), reverse=True)
C=sorted(LIST(), reverse=True)

ABC=[]
for i in range(X):
    for j in range(Y):
        if (i+1)*(j+1)>K:
            break
        for k in range(Z):
            if (i+1)*(j+1)*(k+1)>K:
                break
            ABC.append(A[i]+B[j]+C[k])
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])



Measured memory_bytes: 8728
import itertools
n = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
p_list = list(itertools.permutations(P, n))
p_list = sorted(p_list)

for i in range(len(p_list)):
    if p_list[i] == tuple(P):
        pnum = i

    if p_list[i] == tuple(Q):
        qnum = i

print(abs(pnum-qnum))

Measured memory_bytes: 8308
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int N;cin >> N;
    map<char,int> mp;
    string s; cin >> s;
    for(int i = 0; i < N; i++){
        mp[s[i]]++;
    }
    if(mp['R'] > mp['B']) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> t(n);
  vector<pair<int,int>> z(n);

  for(int i=0; i<n; i++){
    cin >> t.at(i);
    int x, y;
    cin >> x >> y;
    z[i]=make_pair(x, y);
  }

  bool flg=true;
  if(t.at(0)<abs(z.at(0).first)+abs(z.at(0).second) ||
     (t.at(0)-(abs(z.at(0).first)+abs(z.at(0).second)))%2!=0) flg=false;

  int i=0;
  while(flg==true && i<n-1){
    if(t.at(i+1)-t.at(i)<abs(z.at(i+1).first-z.at(i).first)+abs(z.at(i+1).second-z.at(i).second) ||
       (t.at(i+1)-t.at(i)-(abs(z.at(i+1).first-z.at(i).first)+abs(z.at(i+1).second-z.at(i).second)))%2!=0) flg=false;
    else i++;
  }

  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;  
}


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

int main(){
    string s;
    cin >> s;
    int a,b;
    a=0;b=0;
    for(int i=0; i<s.length(); i++){
        if(i%2==0){
            if(s.at(i) == '0') b++;
            else a++;
        }
        else{
            if(s.at(i) == '0') a++;
            else b++;
        }
    }
    cout << min(a,b) << endl;
}

Measured memory_bytes: 3716
import std.stdio : writefln;
import std.array;
import std.range;
import std.math : sqrt;


void main(){
	while(true){
		int x = next!int();
		int h = next!int();
		if( (x|h)== 0){ return; }
		
		auto x_ = x.to!double;
		auto h_ = h.to!double;
		writefln("%.8f", x_*(x_*x_ + 4.*h_*h_).sqrt + x_*x_);
	}
}


import std.stdio : readln, chomp;
import std.conv : to;
import std.string : split;
shared string[] input;
shared string delim = " ";
T next(T)()
in
{
	assert(hasNext());
}
out
{
	input.popFront;
}
body
{
	return input.front.to!T;
}

void next(T)(ref T v){
	v = next!T();
}

bool hasNext(){
	if(input.length > 0){
		return true;
	}
	
	string str = readln;
	if(str.length > 0){
		input ~= str.chomp.split(delim);
		return true;
	}else{
		return false;
	}
}


void dbg(T...)(T vs)
{
	import std.stdio : stderr;
	foreach(v; vs)
		stderr.write(v.to!string ~ " ");
	stderr.write("\n");
}

T clone(T)(T v){
	T v_;
	static if(isInputRange!(T)){
		foreach(ite; v){
			v_ ~= ite.clone;
		}
	}else{
		v_ = v;
	}
	
	return v_;
}

Measured memory_bytes: 1080
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")


template<typename A>
using P = pair<A, A>;


int main() {
	int n, a;
	cin >> n >> a;
	if (n % 500 <= a) PRIY;
	else PRIN;
	return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// N, Sの入力
		int N = sc.nextInt();
		String S = sc.next();
		
		char[] Sarray = S.toCharArray();
		StringBuilder result = new StringBuilder();
		result.append(Sarray[0]);
		for (int i = 1; i < N; i++) {
			if (Sarray[i] != Sarray[i-1]) {
				result.append(Sarray[i]);
			}
		}
		
		// 結果の出力
		System.out.println(result.length());
		
		sc.close();
	}

}


Measured memory_bytes: 25808
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
int n;
vint v;
vint tt;
vint used;
bool f=false;
int cnt=0;
int foo(int x);
int foo2(int c,int x,int y){
	if(c==0){
		return foo(x+1);
	}
	if(y>=n){
		return 0;
	}
	int ret=0;
	if(v[y]<=c&&used[y]==0){
		used[y]=1;
		++cnt;
		if(foo2(c-v[y],x,y+1)&&cnt==n){
			return 1;
		}
		used[y]=0;
		--cnt;
	}
	return foo2(c,x,y+1);
}
int foo(int x){
	if(x==n){
		return 1;
	}
	if(used[x]==0) return 0;
	if(used[x]==2) return foo(x+1);
	int ret=0;
	used[x]=2;
	if(foo2(v[x],x,x+1)) return 1;
	used[x]=1;
	return foo(x+1);
}
void mainmain(){
	while(cin>>n,n){
		v=vint(n);
		rep(i,n){
			cin>>v[i];
		}
		sort(ALL(v));
		reverse(ALL(v));
		tt=vint(n,0);
		used=vint(n,0);
		// rep(i,n) cout<<used[i]<<" ";
		// cout<<endl;
		used[0]=1;
		tt[0]=v[0];
		cnt=1;
		if(foo(0)) cout<<"YES\n";
		else cout<<"NO\n";
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1180
#include<stdio.h>
main(){

	int x,y,p1,p2,sum;
	scanf("%d %d %d %d",&x,&y,&p1,&p2);
    if(x<y)
	{
		sum=x*p1;

	}

	else{
	sum=y*p1+(x-y)*p2;
	}
	printf("%d",sum);
}

Measured memory_bytes: 128
use std::io::{self, BufRead};

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let (n, k) = (xs[0], xs[1]);
  let ans = if k % 2 == 0 {
    let x = n / k;
    let y = (n + k / 2) / k;
    x * x * x + y * y * y
  } else {
    let x = n / k;
    x * x * x
  };
  println!("{}", ans);
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

//Zeller's conguence

int main()
{
    int a[101]={0};
    int n;
    while(cin>>n){
        a[n]++;
    }
    //cout<<"hoge"<<endl;
    int temp=0;
    rep(i,101) temp=max(temp,a[i]);
    vector<int> hoge;
    rep(i,101) if(temp==a[i]) hoge.push_back(i);
    SORT(hoge);
    rep(i,hoge.size()){
        cout<<hoge[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3112
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	    int buildcnt = sc.nextInt();
        int hights[]= new int[buildcnt];
            boolean reach =false;
      String answer = "Yes";
        for(int i=0 ; i<buildcnt ; i++){
         hights[i]=sc.nextInt(); 
        }
//      List<Integer> numlist = new ArrayList<Integer>();
//      while(sc.hasnext()){
  //      numlist.add(sc.nextInt());
    //  }
      for(int i=buildcnt-1 ; i>0 ; i--){
          if(hights[i-1] - hights[i] >1 ){
            answer = "No";
            break;
          }else if(hights[i-1]-hights[i]==1 && !reach){
            reach=true;
          }else if(hights[i-1]-hights[i]==1 && reach){
            answer="No";
            break;
          }else if(hights[i-1]-hights[i]==0 && reach){
            reach=true;
          }else{
            reach=false;
          }
      }

//      int now = sc.nextInt();
//      while(sc.hasNext()){
//       int next = sc.nextInt();
       //今-次が2以上ならNG
 //      if(now - next >= 2){
//         answer="NO";
  //       break;
  //     }else if(now - next == 1){
        
  //       if(reach == true){
  //        answer ="NO";
  //         break;
  //       }else{
  //         reach=true;
  //         now = next;
  //       }
  //     }else{
  //      now = next;
  //      reach=false;
  //     }
   //   }
        // 出力 
		System.out.println(answer);
//      		System.out.println(buildcnt);
//      for(int i=0;i<buildcnt;i++){
//      		System.out.println(hights[i]);
//      }
	}
}


Measured memory_bytes: 50636
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  string t = "abcdefghijklmnopqrstuvwxyz";
  set<char> st;
  for (int i = 0; i < s.length(); i++) {
    st.insert(s[i]);
  }
  for (auto x : t) {
    if (st.find(x) == st.end()) {
      cout << x << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e5+5, M=1e5+5, oo=0x3f3f3f3f, mod = 1e9+7;

int n, k, dp[N], arr[N];
int main()
{
    _69e27
    cin >> n >> k;
    for(int i=0; i<n; i++)
        cin >> arr[i];
    for(int i=1; i<=k; i++){
        for(int j=0; j<n; j++){
            if(arr[j]<=i && !dp[i-arr[j]])
                dp[i]=1;
        }
    }
    if(dp[k]) cout << "First";
    else cout << "Second";
    return 0;
}


Measured memory_bytes: 640
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::collections::*;

fn main() {
    input! {
        n:usize,
        k:i32,
        a:[i32;n],
    }
    let mut ok = *a.iter().max().unwrap();
    let mut no = 0;
    while (ok - no).abs() > 1 {
        let mid = (ok + no) / 2;
        let ope_num = a
            .iter()
            .fold(0, |acc, &len| acc + (len + mid - 1) / mid - 1);
        if ope_num <= k {
            ok = mid;
        } else {
            no = mid;
        }
    }
    println!("{}", ok);
}

Measured memory_bytes: 4580
// AGC020_A
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

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

    // input
    ll N, Alice, Borys;
    cin >> N >> Alice >> Borys;
    
    // calculation
    if (N == 2) {
        // アリスは動けない
        cout << "Borys" << "\n";
    } else if ((Borys - Alice) == 1) {
        // 隣り合っているときアリスは左にしか動けない
        cout << "Borys" << "\n";
    } else if ((Borys - Alice) == 2) {
        // アリスが先にボリスの左を埋めることができる
        cout << "Alice" << "\n";
    } else {
        if ((Borys - Alice - 1)%2 == 1) {
            cout << "Alice" << "\n";
        } else {
            cout << "Borys" << "\n";
        }
    }
    
    return 0;
}


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

int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  if(N >= B -1) {
    cout << A*(B-1)/B - A*((B-1)/B) << endl;
  }
  else {
  if(A*(N-1)/B - A*((N-1)/B) >= A*N/B - A*(N/B)) {
    cout << A*(N-1)/B - A*((N-1)/B) << endl;
  }
  else {
    cout << A*N/B - A*(N/B) << endl;
  }
  }
}


Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main() {
  int N, A, B, SUM = 0;
  cin >> N >> A >> B;
  for (int i = 1; i <= N; i++) {
    int temp = i, sum = 0;
    while (temp != 0) {
      sum += temp % 10;
      temp /= 10;
    }
    if (sum >= A && sum <= B)
      SUM += i;
  }
  cout << SUM << endl;
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc120/tasks/abc120_d

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <regex>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }
struct UnionFind {
    vector<int> par; // 親の番号
    UnionFind(int size) : par(size, -1) {}
    // xとyの木を併合
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (par[y] < par[x])
                swap(x, y);
            par[x] += par[y];
            par[y] = x;
            return true;
        } else {
            return false;
        }
    }
    // 2つのデータx, yが属する木が同じならtrueを返す
    bool same(int x, int y) { return root(x) == root(y); }
    // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
    // 頂点 v が属するグループと同じグループに属する頂点数を得る
    int size(int x) { return -par[root(x)]; }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m, t1, t2;
    cin >> n >> m;
    vector<ll> ans, a, b;

    for (int i = 0; i < m; i++) {
        cin >> t1 >> t2;
        a.push_back(--t1);
        b.push_back(--t2);
    }
    reverse(ALL(a));
    reverse(ALL(b));
    UnionFind tree(n);

    ll cur = n * (n - 1) / 2;
    for (int i = 0; i < m; i++) {
        ans.push_back(cur);
        t1 = tree.size(a[i]);
        t2 = tree.size(b[i]);
        if (tree.unite(a[i], b[i])) {
            cur -= t1 * t2;
        }
    }
    reverse(ALL(ans));
    for (auto x : ans) {
        cout << x << '\n';
    }

    return 0;
}

Measured memory_bytes: 4204
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  ll K, N;
  cin >> K >> N;
  vector<ll> A(N, 0);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<ll> d(N, 0);

  for (ll i = 0; i < N - 1; i++) {
    // cout << A[i + 1] << " - " << A[i] << endl;
    d[i] = A[i + 1] - A[i];
  }

  d[N - 1] = A[0] + (K - A[N - 1]);

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

  // cout << d[0] << endl;

  cout << K - d[0] << endl;
  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    x %= 1000;
    if(x) x = 1000 - x;
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<char,int> pci;
typedef vector<pair<int,int>> vpii;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
#define sci(a) scanf("%d",&a)
#define scii(a,b) scanf("%d %d",&a,&b)
#define sciii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sciiii(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld %lld",&a,&b)
#define sclll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c
#define scllll(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define print(a) printf("%d ",a)
#define println(a) printf("%d\n",a)
#define ln printf("\n")
#define pb(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define rep(i,s,n) for(int i=s;i<=n;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define repv(i,m) for(auto i = m.begin();i != m.end();i++)
#define FileIO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const long long INF = 4000000000000000000LL;
/************************************* Chocolate *************************************/
vi in_degree;
vvi edge;
vb vis;
vll dist;
void dfs(int node){
    if(vis[node]) return;
    vis[node] = true;
    for(int i:edge[node]){
        dist[i] = max(dist[i],dist[node] + 1);
        --in_degree[i];
        if(!in_degree[i]) dfs(i);
    }

}
int main(){
    int n,m;
    scii(n,m);
    edge.resize(n+1);
    in_degree.resize(n+1);
    dist.resize(n+1);
    vis.resize(n+1);
    rep(i,1,m){
        int a,b;
        scii(a,b);
        edge[a].pb(b);
        ++in_degree[b];
    }
    rep(i,1,n){
        if(!in_degree[i]) dfs(i);
    }
    ll ans = 0;
    rep(i,1,n){
        ans = max(ans,dist[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 14488
from math import sqrt, floor

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    N = int(input())

    # x = prime_factorize(N)
    # D = []
    # for i in range(2 ** len(x)):
    #     a = format(i, '0{}b'.format(len(x)))
    #     D.append(a)

    # mn = 1 + N
    # for di in D:
    #     a = 1
    #     b = 1
    #     for i, dii in enumerate(di):
    #         if dii == '0':
    #             a = a * x[i]
    #         else:
    #             b = b * x[i]
    #     mn = min(mn, a + b)
    # print(mn - 2)

    NN = floor(sqrt(N))
    mn = N + 100
    for i in range(1, NN + 1):
        if N % i == 0:
            a = i
            b = N // i
            # print(a, b)
            mn = min(mn, a + b)

    print(mn - 2)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
//
// Created by kuroneko on 2019-07-06.
//

using namespace std;

#include <iostream>
#include <vector>

typedef long long ll;

int main() {
    int N; cin >> N;
    int A; cin >> A;
    if (N < A) cout << 0 << endl;
    else cout << 10 << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    int d, n = 0;
    cin >> d;

    string s = "Christmas";
    string s2 = "Eve";
    if (d <= 25 && d >= 22) {
        cout << s;

        if (d == 24) n = 1;
        if (d == 23) n = 2;
        if (d == 22) n = 3;

        for (int i = 0; i < n; ++i) {
            cout << " " << s2;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
h = []
ans = 10**10

for i in range(n):
    h.append(int(input()))
h.sort()

for i in range(n-k+1):
    buf = h[i+k-1] - h[i]
    if buf < ans:
        ans = buf
print(ans)



Measured memory_bytes: 7384