akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

struct union_find {
    vector<int> parent; //親の番号を格納する。親だった場合は-(その集合のサイズ)
    union_find(int N) {
        parent = vector<int>(N, -1); //parentの値を-1にする(すべてバラバラ)
     }
    int root(int A) { //Aがどのグループに属しているか調べる
        if (parent[A] < 0) return A;
        return parent[A] = root(parent[A]);
    }
    int size(int A) { //自分のいるグループの頂点数を調べる
        return -parent[root(A)];//親をとってきたい
    }
    bool connect(int A, int B) { //AとBをくっ付ける．すでにつながっていた場合false
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) return false; //すでにくっついてるからくっ付けない
        if (size(A) < size(B)) swap(A, B); //大小が逆だったらひっくり返しちゃう。
        parent[A] += parent[B]; //Aのサイズを更新する
        parent[B] = A; //Bの親をAに変更する
        return true;
    }
};

int main(void)
{
    int N,K,L;
    cin >> N >> K >> L;
    union_find road(N);
    union_find train(N);
    REP(i, K){
        int p,q;
        cin >> p >> q;
        p--;q--;
        road.connect(p,q);
    }
    REP(i, L){
        int r,s;
        cin >> r >> s;
        r--;s--;
        train.connect(r,s);
    }
    map<pii, int> m;
    REP(i, N){
        pii t(road.root(i), train.root(i));
        m[t]++;
    }
    REP(i, N){
        pii t(road.root(i), train.root(i));
        cout << m[t] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

int add(int a, int b, int m = MOD){
	return a + b < m? a + b : a + b - m;
}

int mul(ll a, ll b, int m = MOD){
	return (a * b) % m;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 3000+5;
const int MAX = 200000+5;

int n;
int h, w;
int x[N];
int y[N];
int f[MAX];
int fi[MAX];
int memo[N];

void init(){
	f[0] = 1;
	for(int i=1; i<MAX; i++){
		f[i] = mul(i, f[i-1]);
	}
	fi[MAX-1] = pow_mod(f[MAX-1], MOD-2);
	for(int i=MAX-2; i>=0; i--){
		fi[i] = mul(i + 1, fi[i + 1]);
	}
}

int C(int n, int k){
	return mul(f[n], mul(fi[n-k], fi[k]));
}

int main(){
	init();
	ri3(h, w, n);
	for(int i=0; i<n; i++){
		ri2(x[i], y[i]);
	}
	x[n] = h;
	y[n] = w;
	n += 1;
	vi p(n);
	iota(all(p), 0);
	sort(all(p), [&] (int i, int j){
		if(x[i] == x[j]) return y[i] < y[j];
		return x[i] < x[j];
	});
	for(int i=0; i<n; i++){
		int posi = p[i];
		memo[i] = C(x[posi] + y[posi] - 2, x[posi] - 1);
		for(int j=0; j<i; j++){
			int posj = p[j];
			if(y[posj] <= y[posi]){
				int paths = mul(memo[j], C(x[posi] - x[posj] + y[posi] - y[posj], x[posi] - x[posj]));
				memo[i] = add(memo[i], mul(MOD-1, paths));
			}
		}
	}
	printf("%d\n",memo[n-1]);
	return 0;
}

Measured memory_bytes: 1792
class WordCount
  def sentence(array)
    result = array.each_with_object(Hash.new(0)) { |w, h| h[w] += 1 }
    [
      result.max_by { |_, v| v },
      result.max_by { |k, _| k.length }
    ].map { |a| a[0].to_s }
  end
end

mode, max_length = WordCount.new.sentence(STDIN.gets.split)
printf "%s %s\n", mode, max_length

Measured memory_bytes: 8600
import java.util.Scanner;
import java.util.LinkedList;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int r = sc.nextInt();
			if (n == 0 && r == 0) break;
			LinkedList<Integer> list = new LinkedList<>();
			for (int i = 0; i < n; ++i)
				list.add(i + 1);
			for (int k = 0; k < r; ++k) {
				int p = sc.nextInt();
				int c = sc.nextInt();
				for (int j = 0; j < c; ++j) {
					int idx = n - (p - 1 + c);
					int mv = list.get(idx);
					list.remove(idx);
					list.add(mv);
				}
			}
			System.out.println(list.get(list.size() - 1));
		}
	}
}


Measured memory_bytes: 36628
#include<iostream>
#include<stdio.h>
using namespace std;

int main() 
{
	int n,num;
	char moji;
	bool cards[4][13];//[0]:S,[1]:H,[2]:C,[3]:D

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			cards[i][j] = false;
		}
	}

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> moji >> num;
		if (moji == 'S') cards[0][num - 1] = true;
		else if (moji == 'H') cards[1][num - 1] = true;
		else if (moji == 'C') cards[2][num - 1] = true;
		else cards[3][num - 1] = true;
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			if (cards[i][j] == false) {
				switch (i) {
				case 0: cout << "S " << j + 1 << endl; break;
				case 1: cout << "H " << j + 1 << endl; break;
				case 2: cout << "C " << j + 1 << endl; break;
				default:cout << "D " << j + 1 << endl;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3092
while True:
  a,op,b=input().split()
  a=int(a)
  b=int(b)
  if op=='?':
       break
  if op=='+':
      print(a+b)
  elif op=='-':
      print(a-b)
  elif op=='*':
      print(a*b)
  elif op=='/':
      print(a//b)
      


Measured memory_bytes: 5592
#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 For(i,a,n) for(i=a;i<n;i++)
#define all(ar) ar.begin(),ar.end() 
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;
const ll mod = 1000000007;

ll n2(ll a){
    ll ans = a * (a-1);
    return ans/2;
}

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;
    cin>>n;
    ll ar[n],i,res[n];
    For(i,0,n) cin>>ar[i];
    map<ll, vector<ll> > occ;
    For(i,0,n){
        occ[ar[i]].pb(i);
    }
    ll ans = 0;
    for(auto k: occ) ans += n2((ll) k.S.size());
    //cout<<"->"<<ans el;
    for(auto k: occ){
        ll tem, pp; pp = k.S.size();
        tem = ans - n2(pp);
        tem += n2(pp-1);
        for(ll h: k.S) res[h] = tem;
    }
    for(ll a: res) cout<<a el; 
    return 0;
}

Measured memory_bytes: 18816
def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    class combination():
        # 素数のmod取るときのみ　速い
        def __init__(self, n, mod):
            self.n = n
            self.mod = mod
            self.fac = [1] * (n + 1)
            self.inv = [1] * (n + 1)
            for j in range(1, n + 1):
                self.fac[j] = self.fac[j - 1] * j % mod

            self.inv[n] = pow(self.fac[n], mod - 2, mod)
            for j in range(n - 1, -1, -1):
                self.inv[j] = self.inv[j + 1] * (j + 1) % mod

        def comb(self, n, r):
            if r > n or n < 0 or r < 0:
                return 0
            return self.fac[n] * self.inv[n - r] * self.inv[r] % self.mod
        def combinv(self,n,r):
            if r > n or n < 0 or r < 0:
                return 0
            return self.inv[n] * self.fac[n - r] * self.fac[r] % self.mod
    N, A, B, C, D = LI()
    Comb = combination(N+1,mod)
    dp = [[0]*(N+1)for _ in range(B+1)]
    for i in range(A):
        dp[i][0] = 1
    for i in range(A,B+1):
        for j in range(N+1):
            loop = (N-j) // i + 1
            cnt_comb = 1
            dp[i][j] += dp[i-1][j]
            for k in range(C):
                cnt_comb *= Comb.comb(N-j-k*i,i)
                cnt_comb %= mod
            for k in range(C,min(loop,D+1)):
                dp[i][k*i+j] += dp[i-1][j]*cnt_comb * Comb.inv[k]
                dp[i][k*i+j] %= mod
                cnt_comb *= Comb.comb(N-j-k*i,i)
                cnt_comb %= mod
                #print(Comb.comb(N-j-k*i,i),Comb.inv[k+1])
    #print(dp)
    ans = dp[-1][-1]%mod
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return


from decimal import Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
10 1 1 1 10
"""


Measured memory_bytes: 150836
#include <stdio.h>
int main()
{
     int n,i,sum=1;
    scanf("%d",&n);
        if(n==1)
            printf("1");
        else
        {
             int ans = n+2;
        for(i=1; i<n; i++)
        {
            ans = sum;
            sum = i * i;
            if(sum>n)
                break;
        }
        printf("%d",ans);

    }

}

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

int64_t n,a[300005],f1[300005],f2[300005];
multiset<int64_t> s;

void Process1()
{
    int64_t sum=0;
    for(int i=1;i<=n;i++)
    {
        s.insert(a[i]);
        sum+=a[i];
    }
    f1[n]=sum;
    for(int i=n+1;i<=2*n;i++)
    {
        s.insert(a[i]);
        sum+=a[i];
        if(s.size()>n)
        {
            int64_t tmp=*s.begin();
            s.erase(s.find(tmp));
            sum-=tmp;
        }
        f1[i]=sum;
    }
}

void Process2()
{
    int64_t sum=0;
    s.clear();
    for(int i=3*n;i>=2*n+1;i--)
    {
        s.insert(a[i]);
        sum+=a[i];
    }
    f2[2*n+1]=sum;
    for(int i=2*n;i>=n+1;i--)
    {
        s.insert(a[i]);
        sum+=a[i];
        if(s.size()>n)
        {
            int64_t tmp=*s.rbegin();
            s.erase(s.find(tmp));
            sum-=tmp;
        }
        f2[i]=sum;
    }
}

int main()
{
    cin>>n;
    for(int i=1;i<=3*n;i++)
        cin>>a[i];
    Process1();
    Process2();
    int64_t res=-1e18;
    for(int i=n;i<=2*n;i++)
        res=max(res,f1[i]-f2[i+1]);
    cout<<res;
}


Measured memory_bytes: 10752
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=1e5+7,K=1000;

int f[2][2][K][K];// d,col,rx,ry
int n,k,i,j;

il int getv(int c1,int c2,int i,int j){
	if(i<0||j<0) return 0;
	return f[c1][c2][i][j];
}

il int getans(int c1,int c2,bool tp){
	int v1=f[c1][c2][i][k-1]+f[c1][c2][k-1][j]-(f[c1][c2][i][j]<<1);
	if(tp) return v1;
	else return f[c1][c2][k-1][k-1]-v1;
}

int main(){
//	fileio("test");
	scanf("%d%d",&n,&k);
	rep(i,1,n){
		int x,y;
		char tmp[5];
		scanf("%d%d%s",&x,&y,tmp);
		int d=x/k+y/k;
		++f[d%2][tmp[0]=='W'?1:0][x%k][y%k];
	}
	rep0(c1,2){
		rep0(c2,2){
			rep0(i,k){
				rep0(j,k){
					f[c1][c2][i][j]+=getv(c1,c2,i-1,j)+getv(c1,c2,i,j-1)-getv(c1,c2,i-1,j-1);
				}
			}
		}
	}
	int ans=0;
	for(i=0;i<k;++i) for(j=0;j<k;++j){
		rep0(c,2){
			int tot=0;
			tot+=getans(0,c,0);
			tot+=getans(1,c,1);
			tot+=getans(0,c^1,1);
			tot+=getans(1,c^1,0);
			getmax(ans,tot);
		}
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 15872
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        long x=sc.nextLong();
        long a[] = new long[n];
        for(int i=0;i<n;i++)a[i]=sc.nextLong();
        long ans =0;

        for(int i=1;i<n;i++){
            long total = a[i-1]+a[i];
            if(total>x){
                long dif = total -x;
                ans+=dif;

                if(a[i]>dif)a[i]-=dif;
                else {
                    a[i-1]-=dif-a[i];
                    a[i]=0;
                }
            }
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 57816
from itertools import permutations
N = int(input())
P = tuple(map(int,input().split(' ')))
Q = tuple(map(int,input().split(' ')))

perm = permutations([x for x in range(1,N+1)]) 
perm = list(perm)

print(abs((perm.index(P)+1)-(perm.index(Q)+1)))

Measured memory_bytes: 8052
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main(void){
  vector<int> a(3);
  for(int i = 0; i < 3; i++){
    cin >> a[i];
  }

  sort(a.begin(), a.end());

  int p, q;

  p = a[1] - a[0];
  q = a[2] - a[1];

  int ans = (p%2 == 0)? p/2 + q:(p+3)/2+q;
  cout << ans << endl;

  
  return 0; 
}


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

using namespace std;

#define ll long long
#define v(dt) vector<dt>
#define pr(x, y) pair<x,y>
#define loop(x, s, e) for(int x = 0; x <=e; x++)
#define in_arr(n) loop(i,0,n-1){cin>>a[i];}
#define out_arr(n) loop(i,0,n-1){cout<<a[i];}

const int N = 1e5 + 5;
const int INF = 1 << 30;
const int MOD = 2019;

inline void boost() {
    cin.tie(0), cout.tie(0), cin.sync_with_stdio(0), cout.sync_with_stdio(0);
}


int main() {
    boost();
    ll l, r;
    cin >> l >> r;
    if ((r / MOD) != (l / MOD)) {
        cout << 0;
        return 0;
    }
    l %= MOD;
    r %= MOD;
    ll mn = INF;
    ll s = min(l, r);
    ll e = max(l, r);
    for (ll i = s; i <= e; ++i) {
        for (ll j = i + 1; j <= e; ++j) {
            mn = min(mn, (i * j) % MOD);
        }
    }
    cout << mn;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  int nn = n;
  int sum = 0;
  while(n){
    sum += n % 10;
    n /= 10;
  }
  if(nn % sum == 0) cout << "Yes\n";
  else cout << "No\n";

  
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.NoSuchElementException;
import java.util.concurrent.PriorityBlockingQueue;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String s = sc.next();

        if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }

    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}



Measured memory_bytes: 23124
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)*}
    };
}

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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        k: usize,
        x: usize,
        y: usize
    }
    if n <= k {
        println!("{}", n * x);
    } else {
        println!("{}", k * x + (n - k) * y);
    }
}


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

bool prime(int n){
    int root = sqrt(n);
    for(int i=2;i<=root;++i)if(n%i==0)return false;
    return true;
}

int main (void){
    int n,cnt;
    while(cin>>n,n){
        cnt=0;
        for(int i=n+1;i<=2*n;++i)if(prime(i))cnt++;
        cout<<cnt<<endl;
    }
    return 0;
}

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

int main()
{
	int n,k,a[100001],x,b,ans;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	x=n-1;
	b=k-1;
	ans=x/b;
	if(x%b==0) cout<<ans;
	else cout<<ans+1;
}

Measured memory_bytes: 640
// ---------- begin chmin, chmax ----------
trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------

use proconio::*;
use proconio::marker::*;
use std::cmp::*;

fn run() {
    input! {
        h: usize,
        w: usize,
        n: usize,
        p: [(Usize1, Usize1, u64); n],
    }
    let mut item = vec![vec![]; h];
    for (a, b, c) in p {
        item[a].push((b, c));
    }
    let m = 3;
    let mut dp = vec![0u64; w + 1];
    for item in item.iter().rev() {
        let mut cost = vec![0; w + 1];
        for &(b, c) in item.iter() {
            cost[b] = c;
        }
        let mut next = vec![vec![0u64; w + 1]; m + 1];
        for i in 0..=m {
            for j in (0..w).rev() {
                let mut val = 0;
                val.chmax(next[i][j + 1]);
                val.chmax(dp[j]);
                if i > 0 {
                    val.chmax(next[i - 1][j + 1] + cost[j]);
                }
                if i == 1 {
                    val.chmax(dp[j] + cost[j]);
                }
                next[i][j] = val;
            }
        }
        for (i, dp) in dp.iter_mut().enumerate() {
            *dp = 0;
            for next in next.iter() {
                dp.chmax(next[i]);
            }
        }
    }
    let ans = dp[0];
    println!("{}", ans);
}

fn main() {
    run();
}


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

using namespace std;

int main(void) {
	int n;
	cin >> n;
	vector<int>a(n);
	bool enter = true;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		
		if (a[i] % 2 == 0) {
			if (a[i] % 3 != 0 && a[i] % 5 != 0) {
				enter = false;
			}
		}
	}

	if (enter)
	{
		cout << "APPROVED";
	}else{
		cout << "DENIED";
	}
	return 0;
}

Measured memory_bytes: 256
import sys
n = int(input())
a = list(map(int, input().split()))

if 0 in a:
    print(0)
    sys.exit()

else:
    multi = 1
    for i in a:
        multi *= i
        if multi > 10 ** 18:
            print(-1)
            sys.exit()

    print(multi)

Measured memory_bytes: 21540
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

count = 0
(0..a).each do |ia|
  (0..b).each do |ib|
    (0..c).each do |ic|
      if ia * 500 + ib * 100 + ic * 50 == x
        count += 1
      end
    end
  end
end
 
puts count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    const long long L = 1000000000000000000LL;
    int N;
    cin>>N;
    vector<long long> A;
    rep(i,N){
        long long t;
        cin>>t;
        if(t==0){
            cout << 0 << endl;
            return 0;
        }
        A.push_back(t);
    }
    long long ans=1;
    rep(i,N){
        
        if(ans>(L/A[i])+1){
                        cout << -1 << endl;
            return 0;
        }
        ans=ans*A[i];
        if(ans>L){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

int main() {
    int n,t;cin>>n>>t;
    int ans = 9999;
    rep(i,n){
        int c,t2;cin>>c>>t2;
        if(t2<=t)ans = min(ans,c);
    }
    if(ans==9999)cout<<"TLE"<<endl;
    else cout<<ans<<endl;
    
	return 0;
}

Measured memory_bytes: 3632
<?php
fscanf(STDIN, "%d %d", $max, $select);

$itemList = [];
for( $i=0; $i<$max; $i++ )
{ $itemList[] = trim(fgets(STDIN)); }
sort($itemList);

$distanceList = [];
$max -= $select;
$select--;
for( $i=0; $i<=$max; $i++ )
{
  $distanceList[] = $itemList[$i+$select] - $itemList[$i];
}

echo min($distanceList);


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

int main() {
    int a, b;
    cin >> a >> b;
    if(a+b>=a-b && a+b>=a*b) cout << a+b << endl;
    else if(a-b>=a+b && a-b>=a*b) cout << a-b << endl;
    else cout << a*b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

#pragma warning(disable:4996)

int x[30][30], D[30];
int N, M, a, b, c, d;
int s, t, p, q;

int gr(int st, int go) {
	for (int i = 0; i < 30; i++) { D[i] = 1145141919; }
	D[st] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			for (int k = 1; k <= N; k++) {
				if (x[j][k] < 1145141919) {
					D[k] = min(D[k], D[j] + x[j][k]);
				}
			}
		}
	}
	return D[go];
}

int main() {
	while (cin >> N) {
		cin >> M;
		for (int i = 0; i < 30; i++) {
			for (int j = 0; j < 30; j++) {
				x[i][j] = 1145141919;
			}
		}
		for (int i = 0; i < M; i++) {
			scanf("%d,%d,%d,%d", &a, &b, &c, &d);
			x[a][b] = c;
			x[b][a] = d;
		}
		scanf("%d,%d,%d,%d", &t, &s, &p, &q);
		
		cout << p - q - gr(s, t) - gr(t, s) << endl;
	}
	return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
#define maxn 10003

int a,b;

int main(){
	scanf("%d",&a);
	for (int i=0;i*4<=a;i++){
		int p=a-i*4;
		if (p%7==0){
			printf("Yes");
			return 0;	
		}
	}
	printf("No");
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,ans;
vector<ll>v1,v2,v3;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        v1.push_back(a);
    }
    for(int i=0;i<n;i++){
        cin>>a;
        v2.push_back(a);
    }
    for(int i=0;i<n;i++){
        cin>>a;
        v3.push_back(a);
    }
    sort(v1.begin(),v1.end());
    sort(v3.begin(),v3.end());
    for(int i=0;i<n;i++){
        ans+=(lower_bound(v1.begin(),v1.end(),v2[i])-v1.begin())*(n-(upper_bound(v3.begin(),v3.end(),v2[i])-v3.begin()));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int n,len1,len2,fail[1000],bj,v,x,y;
char S[10000],U[1000];
int find(int i){
	while(U[i+1] != U[v]){
		if(i == -1) return -1;
		else i = fail[i];
	}
	return i+1;
}
int f(int i){
	while(U[i+1] != S[y]){
		if(i == -1) return -1;
		else i = fail[i];
	}
	return i+1;
}
int main(){
	scanf("%s",S);
	len1 = 2;
	len2 = strlen(S);
	U[0] = 'A';U[1] = 'C'; 
	fail[0] = -1;
	for(int i = 1; i < len1; ++i){
		v = i;
		fail[v] = find(fail[v-1]);
	}
	x = -1;
	y = -1;
	for(int i = 0; i < len2; ++i){
		y++;
		if(U[x+1] == S[y]) x++;
		else x = f(x);
		if(x == len1 - 1){
			printf("Yes");
			bj = 1;
			break;
		}
	}
	if(!bj) printf("No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int           long long
#define pb            push_back
#define ppb           pop_back
#define si            set <int>
#define endl          '\n'
#define fr            first
#define sc            second
#define mii           map<int ,int >
#define msi           map<string,int >
#define mis           map<int , string>
#define mci       	  map<char,int>  	
#define rep(i,a,b)    for(int  i=a;i<b;i++)
#define all(v)        v.begin(),v.end()
#define srt(v)        sort(all(v))
#define pii           pair<int ,int >
#define vi            vector<int >
#define vii           vector<pair<int , int >>
#define vs            vector<string>
#define sz(x)         (int )x.size()
#define M             1000000007
#define bs            binary_search
#define mp            make_pair
#define sp(n)         setprecision(n)
#define spl           " "
#define arr(a,n)      rep(i,0,n) cin>>a[i]
#define mod           998244353
#define MAXN   		  1000000
#define f(n) for(int i=0;i<n;i++)
using namespace std;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	int k,x;
	cin>>k>>x;
	rep(i,x-k+1,x+k)
	cout<<i<<" ";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define int long long

using namespace std;

int mod = 1e9 + 7;
int n, k;

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	
	int ans = 0;
	for (int i = k; i <= n + 1; i++) {
		int low = (i - 1) * i / 2;	//[0, i)
		int high = n * (n + 1) / 2 - (n - i) * (n - i + 1) / 2;	//(n - i, n]
		ans += high - low + 1;
		ans %= mod;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int H,W;
  cin >> H >> W;
  v(string) A(H);
  int cnt = 0;
  rep(i,H) {
    cin >> A[i];
    rep(j,W) {
      if(A[i][j] == '#') cnt++;
    }
  }
  if(cnt == H + W -1) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

////////////////////////////////////////////////////////////////////////

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val abc = Array(N) { IntArray(3) { sc.next().toInt() } }
        val dp = Array(N) { IntArray(3) }
        for (j in 0 until 3) dp[0][j] = abc[0][j]
        for (i in 1 until N) {
            for (j in 0 until 3) {
                dp[i][j] = arrayOf(
                    dp[i - 1][(j + 1) % 3] + abc[i][j],
                    dp[i - 1][(j + 2) % 3] + abc[i][j]
                ).max()!!
            }
        }
        pw.println(dp[N - 1].max()!!)
    }
}


Measured memory_bytes: 57876
line = int(input())
nums = []
for n in range(line):
    nums.append(int(input()))

# res = nums[1] - nums[0]
# for i in range(line):
#     for j in range(i+1, line):
#         dif = nums[j] - nums[i]
#         res = dif if dif > res else res
maxd = nums[1] - nums[0]
minv = nums[0]

for j in range(1, line):
    maxd = max(maxd, nums[j] - minv)
    minv = min(minv, nums[j])


print(maxd)

Measured memory_bytes: 15580
#include <iostream>
#include <utility>
#include <stdint.h>
#include <string>

using namespace std;

int main()
{
  string S;
  cin >> S;

  int count = 0;
  
  for (int ii=0; ii<S.size()/2; ++ii) {
    if (S[ii] != S[S.size()-ii-1])
      ++count;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#参考させて頂いたサイト
#http://eromog.hatenablog.com/entry/2019/03/13/232245

N = int(input())
h = list(map(int, input().split()))
count = h[0]

for i in range(1, N):
    if h[i] > h[i-1]:
        count += h[i] - h[i-1]

print(count)


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

using namespace std;

int main(){

   int N, M;
   cin>> N>> M;
   int g[10][10];
   for(int i=0; i<N; i++){
      for(int j=0; j<N; j++){
         g[i][j]=0;
      }
   }
   for(int i=0; i<M; i++){
      int a, b;
      cin>> a>> b;
      a--; b--;
//      g[a].push_back(b);
//      g[b].push_back(a);
      g[a][b]=g[b][a]=1;
   }

   vector<int> _v;
   int r=0;
   for(int i=1; i<N; i++) _v.push_back(i);
   do{
      bool ok=true;
      int p=0;
      for(int j: _v){
         ok&=g[p][j];
         p=j;
      }
      if(ok) r++;
   }while(next_permutation(_v.begin(), _v.end()));

   cout<< r<< endl;

   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
  int n,c=0;
  double d1;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    if(i%2==1)
      c++;
  }
 d1=(double)c/n;
  cout<<fixed<<setprecision(10)<<d1;
  return 0; 
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

#define NDEBUG 1

#ifndef NDEBUG
#define _DBG 1
#include <stdio.h>
#else
#define _DBG 0
#endif
#define DbgP(fmt, ...) \
    do { if (_DBG){ fprintf(stderr, fmt, __VA_ARGS__); }} while (0)

#define DbgFunc(fmt, ...) \
    do { if (_DBG){ fprintf(stderr, "%s(", __FUNCTION__); fprintf(stderr, fmt, __VA_ARGS__); fputs(")\n", stderr); }} while (0)

template<typename I, typename F>
void for_each2(I begin, I end, F fnc){
    if (begin == end) return;
    fnc(true, begin == end - 1, *begin);
    while(++begin <= end - 1) fnc(false, begin == end - 1, *begin);
}

int cnt = 0;

template<typename T>
void shell_sort(T ar, int n, int g){
    for (int i = g; i < n; i++) {
        auto v = ar[i];
        int j = i - g;
        while (j >= 0 && ar[j] > v ) {
            ar[j+g] = ar[j];
            j -= g;
            cnt++;
        }
        ar[j+g] = v;
    }
}

int main(int argc, char const* argv[])
{
    int n;
    vector<int> ar, gar;

    scanf("%d ", &n);
    ar.resize(n);
    for (int i = 0; i < n; i++) {
        scanf("%d ", &ar[i]);
    }
    
    int g = 1;
    while(g <= n){
        gar.push_back(g);
        g = 3 * g + 1;
    }

    reverse(gar.begin(), gar.end());
    for (auto&& v : gar) {
        shell_sort(ar.begin(), ar.size(), v);
    }

    printf("%d\n", gar.size());

    for_each2(gar.begin(), gar.end(), [](bool is_first, bool is_last, int &v)
            { printf(!is_last ? "%d " : "%d\n", v); });

    printf("%d\n", cnt);

    for_each2(ar.begin(), ar.end(), [](bool is_first, bool is_last, int &v)
            { printf("%d\n",v); });

    
    return 0;
}

Measured memory_bytes: 6320
#include<bits/stdc++.h>
using namespace std;
int main(){
   int n,s=0;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++) {cin>>a[i]; s+=a[i];}
   double avg=double(s)/n;
   int ans=0;
   double val=abs(avg-a[0]);
   for(int i=1;i<n;i++){
       if(abs(avg-a[i])<val) {ans=i; val=abs(avg-a[i]);}
   }
   cout<<ans;
}

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

const long long MOD = 1000000007;

int main() {
    long long n, m;
    cin >> n >> m;
    long long factorial[max(n, m) + 1];
    factorial[0] = 1;
    for (long long i = 1; i <= max(n, m); i++) {
        factorial[i] = factorial[i - 1] * i % MOD;
    }
    if (abs(n - m) <= 1) {
        if ((n + m) % 2 == 0) {
            cout << factorial[n] * factorial[m] * 2 % MOD;
        } else {
            cout << factorial[n] * factorial[m] % MOD;
        }
    } else {
        cout << 0;
    }
    return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3

n = int(input())
c = [ [0]*10 for _ in range(10) ]

for x in range(1, n+1):
    beg = int(str(x)[0])
    end = x%10
    c[end][beg] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]

print(ans)


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

int main(){
	int N; cin>>N;
	vector<int> A(N), C(N);
	rep(i, N){cin>>A[i]; A[i]--;}//値補正

	rep(i, N) C[A[i]]++;//値の種類毎の計数

	ll all = 0;//組み合わせの総計
	rep(a, N){
		ll c = C[a];
		if(c>=2) all += c*(c-1)/2;//組み合わせ
	}

	rep(k, N){
		int c = C[A[k]];// ak の値の個数
		ll del = c>=2? c*(c-1)/2: 0;// ak の値の組み合わせ
		c--;// 1 個減
		ll add = c>=2? c*(c-1)/2: 0;// ak の値の組み合わせ
		cout<< all - del + add <<endl;
	}
}

Measured memory_bytes: 4096
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

struct union_find{
    VI par, sz;

    void init(int n){
        par.resize(n);
        sz.resize(n);
        REP(i,n) par[i] = i;
        REP(i,n) sz[i] = 1;
    }

    int find(int x){
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

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

    void merge(int x, int y){
        x = find(x);
        y = find(y);
        if (x == y) return;
        sz[y] += sz[x];
        par[x] = y;
    }

    int size(int x){
        return sz[find(x)];
    }
};

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

    VI u(m), v(m);
    REP(i,m){
        u[i] = in() - 1;
        v[i] = in() - 1;
    }

    reverse(ALL(u));
    reverse(ALL(v));

    ll tmp = n * (n - 1) / 2;
    union_find uf;
    uf.init(n);
    VL ans(m);
    REP(i,m){
        ans[m - i - 1] = tmp;
        if (!uf.same(u[i], v[i])){
            ll x = uf.size(u[i]);
            ll y = uf.size(v[i]);
            tmp -= x * y;
            uf.merge(u[i], v[i]);
        }
    }
    REP(i,m){
        printf("%lld\n", ans[i]);
    }

    return 0;
}


Measured memory_bytes: 3712
X = int(input())

# 素数と個数を求める
def factorize(n):
    res = list()
    i = 2
    while i*i <= n:
        if n%i == 0:
            c = 0
            while n%i == 0:
                n /= i
                c += 1
            res.append([i,c])
        i += 1
    if n != 1:
        res.append([n,1])
    return res

for a in range(-200,200+1):
    a5 = a**5
    b5 = a5 - X
    sign = 1
    if b5 < 0:
        b5 = -b5
        sign = -1

    pc = factorize(b5)

    b = 1
    if b5 == 0: b = 0
    for p,c in pc:
        if c == 5:
            b *= p
        else:
            break

    if b**5 == b5:
        print(a, sign*b)
        break


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

int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i = 0;i < n;i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    int cnt = 0;
    for(int i = 0;i < n-2;i++){
        for(int j = i+1;j < n-1;j++){
            for(int k = j+1;k < n;k++){
                int a = l[i];
                int b = l[j];
                int c = l[k];
                if(!((a < b+c) && (b < c+a) && (c < a+b))){
                    break;
                }else{
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(r.readLine());
		StringTokenizer st;
		
		int side[] = new int[3];
		
		for (int i = 0; i < n; i++) {
			st = new StringTokenizer(r.readLine());
			for(int j = 0;j < 3;j++){
				 side[j] = Integer.parseInt(st.nextToken());
			}
			Arrays.sort(side);
            if((side[0]*side[0] + side[1]*side[1]) == side[2]*side[2]) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
		}
		
	}
}

Measured memory_bytes: 26188
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size()) 
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
#define rep(i, n) for(int i=0;i<n;i++)

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x1f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-12;

map <int, int> Mx;
int main() {
	int N, M, i, j;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &j);
		Mx[j]++;
	}
	scanf("%d", &M);
	for (i = 1; i <= M; i++) {
		scanf("%d", &j);
		Mx[j]--;
	}
	for (auto it : Mx) if (it.second < 0) return !printf("NO\n");
	return !printf("YES\n");
}

Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] sum = new int[26];

		while(sc.hasNext()) {
			String line = sc.next();

			char[] chars =  line.toCharArray();
			for(int i = 0;i < chars.length; i++) {
				for(int j = 0;j < 26; j++) {
					if(chars[i] == 'a' + j || chars[i] == 'A' + j) {
						sum[j]++;
					}
				}
			}

		}

		for(int i = 0;i < sum.length;i++) {
			int ab = 'a' + i;

			System.out.println((char)ab + " : " + sum[i]);
		}
		sc.close();

	}
}

Measured memory_bytes: 26252
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

//解説参考.
int main(){
	llong x,y;
	cin>>x>>y;
	
	llong ans=1e18;
	REP(i,2)REP(j,2){
		llong cnt=0;
		llong xx=x, yy=y;
		if(i){
			xx=-x;
			cnt++;
		}
		if(j){
			yy=-y;
			cnt++;
		}
		if(xx<=yy){
			cnt+=yy-xx;
			ans=min(ans,cnt);
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256