akhauriyash/Code-Regression huggingface dataset:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound, __gcd, count, find, next_permutation
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   // setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cassert> // assert
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  // abs, sin, cos, tan
#include <ctime> // clock

// __builtin_popcountll

using namespace std;
using Graph = vector<vector<int>>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n, k; cin >> n >> k;
  vll a(n); rep(i, n) { cin >> a[i]; a[i]--; }
  vll loop;
  map<ll, ll> twin;
  ll my = 0;
  twin[0] = 0;
  ll frist, end;
  rep(i, n)
  {
    my = a[my];
    if(twin.count(my))
    {
      frist = twin[my];
      end = i + 1;
      break;
    }
    else
    {
      twin[my] = i + 1;
    }
  }

  //e
  if(k < 2 * 1000000)
  {
    my = 0;
    rep(i, k)
    {
      my = a[my];
    }
    cout << my + 1 << endl;
    return;
  }
 
  k -= frist;
  my = 0;
  for(ll i = 0;i < end;i++)
  {
    if(i >= frist)
    {
      loop.pb(my);
    }
    my = a[my];
  }
  cout << loop[k % loop.size()] + 1 << endl;
  return;
}

//前処理
int main()
{
  int ti = clock();
  srand((unsigned)time(NULL));
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); //0埋め４桁
  Main();
  //printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC); // 実行時間計測
  return 0;
}

Measured memory_bytes: 17128
n=int(input())
ab=[]
for _ in range(n):
    ax=list((map(int,input().split())))
    ab.append(ax)
cd=[]
for _ in range(n):
    cx=list(map(int,input().split()))
    cd.append(cx)
ans=0
cd=sorted(cd)
ab=sorted(ab,key=lambda x:x[1],reverse=True)
ans=0
for c in cd:
    for a in ab:
        if a[0]<c[0] and a[1]<c[1]:
            ans+=1
            ab.remove(a)
            break
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int main(void)
{
	double x1, y1, x2, y2;
	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
	printf("%.8lf\n", sqrt(pow(x2 - x1, 2.0) + pow(y2 - y1, 2.0)));
	return 0;
}



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

int main(){
    vector<long long int> a(3);
    for(int i=0; i<3; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());

    if(a[0] % 2 == 0
    || a[1] % 2 == 0
    || a[2] % 2 == 0) cout << 0 << endl;
    else{
        cout << a[0] * a[1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

/*
テストケース全てに目を通す
テストケースが2個以下だったらなんかある
N最小のコーナーケースがないか調べる
制約をしっかりと確認する（1からNまでの順列、全て異なる値などの制約も含め）
制約のn*mとn,mを読み違えない
操作の逆順を考える
オーバーフローしないか確かめる
Codeforcesではscanfを使う
modの引き算には+modをする
エラー出力は消す
エラー出力を消せ！！！！！
cout << fixed;
cout << setprecision(n) << ans;
 */

ll powmod(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = powmod(N, P/2, M);
        return t*t % M;
    }
    return N*powmod(N, P-1, M)%M;
}

int main() {
    int n;
    cin >> n;
    int a[n]={};
    a[0]++;
    rep(i,n){
        int x;
        cin >> x;
        a[x]++;
    }
    if(n%2==0){
        rep(i,n){
            if(i%2){
                if(a[i]!=2){
                    cout << 0;
                    return 0;
                }
            }
        }
    }
    if(n%2==1){
        rep(i,n){
            if(!i%2){
                if(a[i]!=2){
                    cout << 0;
                    return 0;
                }
            }
        }
    }
    cout << powmod(2,n/2,mod);



    
}

/*
*/



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int N,K;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
    cin >> N >> K;
	//cout << fixed << setprecision(15);
    vector<bool> okashi(N);
    REP(i,N){
        okashi[i] = false;
    }

    //cin >> N >> K;
    REP(i,K){
        int d; cin >> d;
        REP(l,d){
            int a; cin >> a;
            okashi[a-1] = true;
        }
    }

    int ans = 0;
    REP(i,N){
        if(okashi[i] == false) ans++;
    }

    cout << ans << endl;
}

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

int main(){
    long long n,m;
    cin >> n >> m;
    vector<pair<long long, long long>> ab(n),cd(m);
    for (long long i = 0; i < n; i++){
        cin >> ab[i].first >> ab[i].second;
    }
    for (long long i = 0; i < m; i++){
        cin >> cd[i].first >> cd[i].second;
    }
    long long ans;
    for (long long i = 0; i < n; i++){
        ans = 1;
        long long dist = 0;
        long long min_dist = 0;
        for (long long j = 0; j < m; j++){
            dist = abs(ab[i].first-cd[j].first)+abs(ab[i].second-cd[j].second);
            if (j == 0){
                min_dist = dist;
                continue;
            }else if (j > 0 && dist < min_dist){
                min_dist = dist;
                ans = j+1;
            }
        }
        cout << ans << endl;
    }
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{   
    gearup;
    int n,k; cin >> n >> k;
    vl x(n),y(n);
    rep(i,n)cin>>x[i]>>y[i];
    ll res = LLONG_MAX;
    rep(i,n){
        for(int ii = i+1;ii<n;ii++){
            rep(j,n){
                for(int jj = j+1;jj<n;jj++){
                    ll ma_x = max(x[i],x[ii]);
                    ll ma_y = max(y[j],y[jj]);
                    ll mi_x = min(x[i],x[ii]);
                    ll mi_y = min(y[j],y[jj]);
                    ll area = (ma_x - mi_x)*(ma_y - mi_y);
            
                    //4点に囲まれた点が何個あるかカウント
                    ll cnt = 0;
                    rep(idx,n){
                        //x座標
                        if(x[idx] < mi_x || x[idx] > ma_x)continue;
                        //y
                        if(y[idx] < mi_y || y[idx] > ma_y)continue;
                        cnt++;
                    }
                    if(cnt >= k)res = min(area,res);
                }
            }
        }
    }
    out(res);
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n,m,q;
    cin >> n >> m >> q;
    vector<int> vi(n+1,0);
    vector< vector<int> > vvi(n+1,vi);
    
    for (int i=0 ; i<m ; i++){
        int l,r;
        cin >> l >> r;
        vvi[l][r]++;
    }
    
    for (int i=1 ; i<=n ; i++){
        int sum=0;
        for (int j=1 ; j<=n ; j++){
            sum += vvi[i][j];
            vvi[i][j] = vvi[i-1][j]+sum;
        }
    }
    
    for (int i=0 ; i<q ; i++){
        int a,b;
        cin >> a >> b;
        int ans = 0;
        ans = vvi[n][b]-vvi[a-1][b];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1920
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

string my_readln() { return chomp(readln()); }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto tokens = my_readln.split;
	auto N = tokens[0].to!long;
	auto A = tokens[1].to!long;
	auto B = tokens[2].to!long;

	writeln(min(A, B), " ", max(0, (A + B) - N));
	stdout.flush();
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	parseProblem()
}

func parseProblem() {
	a, b := scanString(sc), scanString(sc)
	switch lessThan(a, b) {
	case -1:
		fmt.Println("LESS")
	case 0:
		fmt.Println("EQUAL")
	case 1:
		fmt.Println("GREATER")
	}
}

func lessThan(a, b string) int {
	if la, lb := len(a), len(b); la < lb { // no 0 at head
		return -1
	} else if la > lb {
		return 1
	} else {
		for i := 0; i < la; i++ {
			if a[i] < b[i] {
				return -1
			} else if a[i] > b[i] {
				return 1
			}
		}
		return 0
	}
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1796
l = gets.split
ln = {:mx => 0, :wd => ""}
lm = {:mx => 0, :wd => ""}
l.each{|w|
  if lm[:mx] < l.count(w)
    lm[:mx] = l.count(w)
    lm[:wd] = w
  end
  if ln[:mx] < w.length
    ln[:mx] = w.length
    ln[:wd] = w
  end
}
puts "#{lm[:wd]} #{ln[:wd]}"

Measured memory_bytes: 8560
n = int(input())

ans = 0
if(n >= 100):
    ans += 9
    if(n >= 10000):
        ans += 900
        if(n >= 100000):
            ans += 90000
        else:
            ans += n-9999
    else:
        ans += min(n-99, 900)
else:
    ans += min(n,9)

print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)

























int main(){
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> v(m);
    REP(i, m){
        ll k;
        cin >> k;
        v[i].resize(k);
        REP(j, k){
            cin >> v[i][j];
            v[i][j]--;
        }
    }
    vector<ll> p(m);
    REP(i, m){
        cin >> p[i];
    }
    
    ll ans = 0;
    REP(i, (1 << n)){
        vector<ll> f(n);
        REP(j, n){
            if(i & (1 << j)){
                f[j] = true;
            }
        }
        bool ok = true;
        REP(j, m){
            ll cnt = 0;
            REP(k, v[j].size()){
                if(f[v[j][k]]) cnt++;
            }
            if(cnt % 2 != p[j]){
                ok = false;
                break;
            }
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
double n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  double ans = 0.0;
  double sum = 0.0;
  FOR(i, 1, n + 1) {
    if(i % 2 == 1) sum++;
  }

  cout << setprecision(7) << sum / n << endl;
}


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

int main() {
  string S;
  cin >> S;
  
  if((S.at(0) == S.at(1))||(S.at(1) == S.at(2))||(S.at(2) == S.at(3))){
    cout << "Bad" << endl;
  }
  
  else{
    cout << "Good" << endl;
  }
}


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

int main(void) {
	int A, B, ans = 0;
	cin >> A>>B;
	for (int i = A;i <= B;i++) {
		int kai = (i % 10) * 10000 + ((i / 10) % 10) * 1000 + ((i / 100) % 10) * 100 + ((i / 1000) % 10) * 10 + ((i / 10000) % 10);
		if (kai == i)
			ans++;
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd
#include <limits> // std::numeric_limits<long int>::max()

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 

template<typename T>
T powint (const T& x, const T& y) {
  T ret = 1;
  for(int i=0; i<y; ++i) ret *= x;
  return ret;
}

int H, W;
vector<string> S;

void move(int y, int x, int steps, vector<vector<int> >& count) {
  if (0 <= x && x < W && 0 <= y && y < H && S[y][x] != '#') {
    if (steps < count[y][x] || count[y][x] == -1) {
      count[y][x] = steps++;
      move(y+1, x, steps, count);
      move(y-1, x, steps, count);
      move(y, x+1, steps, count);
      move(y, x-1, steps, count);
    }
  }
}

int main() {
  cin >> H >> W;
  S.resize(H);
  for(int i=0; i<H; ++i) cin >> S[i];
  
  int ans = 0;
  int x, y;
  for(int i=0; i<H; ++i) {
    for(int j=0; j<W; ++j) {
      vector<vector<int> > count(H);
      for(int k=0; k<H; ++k) count[k].resize(W, -1);
      x = j;
      y = i;
      if(S[y][x] == '#') continue;
      move(y, x, 0, count);
      for(int k=0; k<H; ++k) {
        for(int l=0; l<W; ++l) {
          ans = max(ans, count[k][l]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
using namespace std;
typedef long long ll;
// cd test ; rm -R ./*; cd .. 

int main(void) {
  int x, y;
  cin >> x >> y;
  int ans = 0;

  if (x == 1) ans += 300000;
  if (x == 2) ans += 200000;
  if (x == 3) ans += 100000;
  if (y == 1) ans += 300000;
  if (y == 2) ans += 200000;
  if (y == 3) ans += 100000;
  if (x == 1 && y == 1) ans += 400000;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
 
using namespace std;
 
const int maxn = 5000 + 7;
 
int n, A, B, pos[maxn], dp[maxn], a[maxn], ans;
 
int32_t main()
{
    cin >> n >> A >> B;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    a[n + 1] = 1e15;
    for(int i = 1; i <= n + 1; i++)
    {
        dp[i] = 1e15;
        ans = 0;
        for(int j = i - 1; j >= 0; j--)
        {
            if(a[j] > a[i]) ans++;
            else
            {
                dp[i] = min(dp[i], dp[j] + ans * A + (i - j - 1 - ans) * B);
            }
        }
    }
    cout << dp[n + 1];
}

Measured memory_bytes: 384
m, d = list(map(int, input().split()))

ans = 0
for i in range(1, d + 1):
  d1 = i % 10
  d10 = i // 10
  if d1 >= 2 and d10 >= 2:
    if 1 <= d10 * d1 <= m:
      ans += 1

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int AA,BB,MM;
const int max_n = 100000;
int a[max_n],b[max_n];
int d[max_n];
int main(){
  cin >> AA >> BB >> MM;
  int mma =  1e8;
  for(int i=0 ; i<AA ; i++){
    cin >> a[i];
    mma = min(a[i], mma);
  }
  int mmb = 1e8;
  for(int i= 0; i<BB ; i++){
    cin >> b[i];
    mmb = min(mmb, b[i]);
  }
  int mi = mma+mmb;
  for(int i=0 ; i<MM ; i++){
    int x,y,c;
    cin >> x >> y>> c;
    --x;  --y;
    mi = min(a[x]+b[y]-c, mi);
  }

  cout << mi << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

map<s64, int> fac;

void prime_factorical(s64 x)
{
    for (s64 i = 2; i * i < x; ++i)
    {
        while (x % i == 0)
        {
            ++fac[i];
            x /= i;
        }
    }
    if (x != 1) fac[x];
}

s64 gcd(s64 x, s64 y)
{
    if (y == 0) return x;
    return gcd(y, x % y);
}

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

    s64 a, b;
    cin >> a >> b;

    ++fac[1];
    prime_factorical(gcd(a, b));

    cout << fac.size() << "\n";

    return 0;
}



Measured memory_bytes: 384
import numpy as np

N=int(input())
A=list(map(int,input().split()))
F=[]
for i in np.arange(len(A)-1):
    if(A[i]>A[i+1]):
        F.append(A[i]-A[i+1])
        A[i+1]=A[i]

print(sum(F))

Measured memory_bytes: 50988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
int n,m;
vector<int> v[10];
int p[11];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      s--;
      v[i].push_back(s);
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) cin >> p[i];
  for (int i = 0; i < (1 << n); i++) {
    int cnt = 0;
    for (int j = 0; j < m; j++) {
      int cnt1 = 0;
      for (int k = 0; k < v[j].size(); k++) {
        if ((i >> v[j][k]) & 1) {
          cnt1++;
        }
      }
      if ((cnt1 & 1) == p[j]) cnt++;
    }
    if (cnt == m) ans++;
  }
  cout << ans << endl;
}

/*　【提出前に確認すること】
・コンパイルできるか
・テストケース試したか
・オーバーフローあるか
*/


Measured memory_bytes: 256
/**
 * 	author: MahfuzAhmed
 * 	created: 09.08.2019 
**/

#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define forn(var,from,to) for(int var=(from);var<(to);var++)
#define forx(var,from,to) for(int var=(from);var<=(to);var++)
#define fory(var,from,to) for(int var=(from);var>=(to);var--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vvi vector<vi>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(p) p.begin(),p.end()
typedef long long ll;
//~ const double pi = 2*acos(0.0);
//~ const long long mod = 1e9+7;
//~ const int MAX_N = 1e6+5;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
       
    #ifdef _DEBUG
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    
    string s; cin >> s;
    int sz = s.length();
    
    int cnt = 0;
    forn(i, 0, sz-1){
        if(s[i] == s[i+1]){
            s[i+1] = (s[i+1] == '0' ? '1' : '0');
            cnt++;
        }
    }
    
    cout << cnt << "\n";
    
    return 0;
}

Measured memory_bytes: 512
import collections
import itertools

n = int(input())
ls = list(map(int, input().split()))
counter = collections.Counter()
for x in ls:
    counter[x] += 1
if len(counter.keys()) > 3:
    print('No')
else:
    for a, b in itertools.combinations_with_replacement(counter.keys(), 2):
        if a == b and counter[a] == 1:
            continue
        counter2 = collections.Counter()
        x = a
        counter2[a] += 1
        counter2[b] += 1
        for _ in range(n - 2):
            a, b = b, a ^ b
            counter2[b] += 1
            if counter2[b] > counter[b]:
                break
        else:
            if a ^ b != x:
                continue
            else:
                print('Yes')
                break
    else:
        print('No')

Measured memory_bytes: 14468
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if ((a == b && a != c) || (a == c && a != b) || (b == c && a != b)){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left
N,K=map(int, input().split())
A=list(map(int, input().split()))
p=10**9+7
A=sorted(A)
thresh=bisect_left(A,0)
minus=A[:thresh]
plus=A[thresh:][::-1]

#print(plus, minus)
if len(plus)==0:
    ans=1
    if K%2!=0:
        minus=minus[::-1]
        for i in range(K):
            ans*=minus[i]
            ans%=p
    else:
        for i in range(K):
            ans*=minus[i]
            ans%=p
    print(ans)
    exit()

if len(minus)==0:
    ans=1
    for i in range(K):
        ans*=plus[i]
        ans%=p
    print(ans)
    exit()

midx=0
pidx=0
ans=1

while K>0 and (0<=midx<len(minus) or 0<=pidx<len(plus)):
    if midx==len(minus)-1:
        nexmin=minus[midx]
    elif midx>=len(minus):
        nexmin=-1
    else:
        if K>=2:
            nexmin=minus[midx]*minus[midx+1]
        else:
            nexmin=minus[midx]

    if pidx==len(plus)-1:
        nexplus=plus[pidx]
        fact=nexplus
    elif pidx>=len(plus):
        nexplus=-float("INF")
        fact=nexplus
    else:
        #if plus[pidx+1]!=0:
        #    nexplus=plus[pidx]*plus[pidx+1]
        #else:
        #    nexplus=plus[pidx]
        if K>=2:
            nexplus=plus[pidx]*plus[pidx+1]
        else:
            nexplus=plus[pidx]
        fact=plus[pidx]

    if nexmin>=nexplus:
        ans*=nexmin
        ans%=p
        midx+=2
        K-=2
    else:
        ans*=fact
        ans%=p
        pidx+=1
        K-=1


print(ans)

Measured memory_bytes: 97124
input()
xs = map(int, input().split())

d = dict()
for x in xs:
    if x in d.keys():
        d[x] += 1
    else:
        d[x] = 1

res = 0
for x, c1 in d.items():
    if c1 >= 4:
        if res < x * x: res = x * x

v = sorted(list(map(lambda s: s[0], (filter(lambda x: x[1] >= 2, d.items())))), reverse=True)

if len(v) >= 2:
    if res < v[0] * v[1]: res = v[0] * v[1]

"""
    for y, c2 in d.items():
        if x != y and c1 >= 2 and c2 >= 2:
            if res < x * y: res = x * y
"""


print(res)


Measured memory_bytes: 23692
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <string>
#include<time.h>
using namespace std;
typedef unsigned long long ull;

int main(void) {
	int a, b, k;
	int count = 0;
	cin >> a >> b >> k;
	for (int i = min(a, b); i > 0; --i) {
		if (a % i == 0 && b % i == 0) {
			++count;
			if (count == k) {
				cout << i;
				return 0;
			}
		}
	}
	return 0;
}

/*
*/

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int i;
	int N;
	int H[100000];

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &H[i]);
		if (H[i] < H[i+1]) {

		}
	}

	for (i = N - 1; i > 0; i--) {
		if (H[i - 1] > H[i]) {
			H[i - 1]--;
			if (H[i - 1] > H[i]) {
				printf("No");
				return 0;
			}
		}
	}

	printf("Yes");
	return 0;
}

Measured memory_bytes: 512
S=input()
S1=list(S)
T=input()
T1=list(T)
ans=[]
for i in range(len(S1)-len(T1)+1):
  d=len(T1)
  for j in range(len(T1)):
    if T1[j]==S1[j+i]:
      d-=1
  ans.append(d)
an=min(ans)
print(an)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
            ll a;cin>>a;
            vector<pair<ll,ll>>v;
            rep(i,a){
                     ll b,c;cin>>b>>c;
                     v.push_back({b,c});
                     }
            sort(v.begin(),v.end());
            rep(i,a){
                     cout<<v[i].first<<" "<<v[i].second<<endl;
                     }
                     
                     
}




Measured memory_bytes: 4932
#include<iostream>
#include<iomanip>
#define _USE_MATH_DEFINES
#include<cmath>
int main()
{
	int a, b;
	char op;
	int result[10000];
	int number;
	bool is_end = false;
	for(int i = 0;; i++)
	{
		std::cin >> a >> op >> b;
		switch(op)
		{
			case '+':
				result[i] = a + b;
				break;
			case '-':
				result[i] = a - b;
				break;
			case '*':
				result[i] = a * b;
				break;
			case '/':
				result[i] = a / b;
				break;
			case '?' :
				is_end = true;
				break;
		}
		if(is_end)
		{
			number = i;
			break;
		}
	}
	for(int i = 0; i < number; i++)
	{
		std::cout << result[i] << std::endl;
	}
	return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,int> LP;
int n;
vector<P> G[100001];
ll one_max[100005];
ll two_max[100005];
ll ans=0;

ll dfs(int v,int p){
	ll val=0;
	for(int i=0;i<G[v].size();i++){
		int nv=G[v][i].first;
		if(nv==p)continue;
		val=max(val,(ll)dfs(nv,v)+G[v][i].second);
	}
	return (one_max[v]=val);
}

ll dfs2(int v,int p){
	ll val=0,val2=0;
	ll val3=0;
	for(int i=0;i<G[v].size();i++){
		int nv=G[v][i].first;
		if(nv==p)continue;
		val3=max((ll)dfs2(nv,v),val3);
		if(one_max[nv]+G[v][i].second>val2){
			val2=one_max[nv]+G[v][i].second
			;
			if(val2>val){
				swap(val2,val);
			}
		}
	}
	return (two_max[v]=max(val+val2,val3));
}

void dfs3(int v,int p,ll one_best,ll two_best){
	//printf("a %d %d %lld %lld\n",v,p,one_best,two_best);
	priority_queue<LP> one_que,two_que;
	one_que.push(LP(0,-1));
	one_que.push(LP(0,-1));
	two_que.push(LP(0,-1));
	for(int i=0;i<G[v].size();i++){
		int nv=G[v][i].first;
		if(nv==p)continue;
		//printf("push %lld %d\n",(ll)one_max[nv]+G[v][i].second,nv);
		one_que.push(LP(one_max[nv]+G[v][i].second,nv));
		two_que.push(LP(two_max[nv],nv));
	}
	for(int i=0;i<G[v].size();i++){
		int nv=G[v][i].first;
		if(nv==p)continue;
		bool one_flag=false;
		bool two_flag=false;
		if(one_que.top().second==nv){
			one_flag=true;
			one_que.pop();
		}
		LP tmp=one_que.top();
		one_que.pop();
		if(one_que.top().second==nv){
			one_flag=true;
			one_que.pop();
		}
		if(two_que.top().second==nv){
			two_flag=true;
			two_que.pop();
		}

		dfs3(nv,v,max(one_best,tmp.first)+G[v][i].second,max(max(two_best,tmp.first+one_que.top().first),two_que.top().first));
		ans=max(ans,(ll)two_max[nv]+G[v][i].second);
		ans=max(ans,(ll)one_best+tmp.first+G[v][i].second);
		ans=max(ans,(ll)tmp.first+one_que.top().first+G[v][i].second);
		ans=max(ans,(ll)max(two_best,two_que.top().first)+G[v][i].second);
		if(one_flag){
			one_que.push(LP(one_max[nv]+G[v][i].second,nv));
		}
		one_que.push(tmp);
		if(two_flag){
			two_que.push(LP(two_max[nv],nv));
		}
	}
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[i+1].push_back(P(a,b));
		G[a].push_back(P(i+1,b));
	}
	dfs(0,-1);
	dfs2(0,-1);
	dfs3(0,-1,0,0);
	printf("%lld\n",ans);
	return 0;
} 


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

int main(void){   
    int H, W;
    cin >> H >> W;
    string board[50];
    for (int i = 0; i < H; ++i) cin >> board[i];

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

    for (int i = 0; i < H; ++i){
    	for (int j = 0; j < W; ++j){
    		if (board[i][j] == '#') continue;

    		int num = 0;
    		for (int d = 0; d < 8; ++d){
    			const int ni = i + dy[d];
    			const int nj = j + dx[d];

    			if (ni < 0 or H <= ni) continue;
    			if (nj < 0 or W <= nj) continue;
    			if (board[ni][nj] == '#') num++;
    		}

    		board[i][j] = char(num + '0');
    	}
    }
    for (int i = 0; i < H; ++i) cout << board[i] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"GREATER":"LESS")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    string a, b;
    cin >> a >> b;

    while (a.size() < b.size()) a = "0" + a;
    while (a.size() > b.size()) b = "0" + b;

    if (a == b) {
        put("EQUAL");
    }
    else if (a < b) {
        put("LESS");
    }
    else {
        put("GREATER")
    }
    return 0;
}

Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Math.*;
import java.util.*;
import java.math.*;
import java.text.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(8);
        nf.setGroupingUsed(false);
        //aのほうが大きい
        //S=1/2ab sin0;
        //h = bsin0
        //L = a + b + √a^2+b^2-2abcosθ 
        System.out.println(nf.format(1*a*b*Math.sin(Math.toRadians(c)) / 2));
        System.out.println(nf.format(a + b + Math.sqrt(Math.pow(a,2) + Math.pow(b,2) - 2 * a * b * Math.cos(Math.toRadians(c)))));
        System.out.println(nf.format(b * Math.sin(Math.toRadians(c))));
    }
}

Measured memory_bytes: 18576
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        // 宝石の数N個
        Integer n = Integer.valueOf(sc.nextLine());

        // 宝石の価値
        String vStr = sc.nextLine();
        Map<Integer, Integer> vList = str2List(vStr);

        // 宝石のコスト
        String cStr = sc.nextLine();
        Map<Integer, Integer> cList = str2List(cStr);
        
        Integer max = 0;
        for (Integer i = 0; i < n; i++) {
            Integer profit = vList.get(i) - cList.get(i);
            if (profit > 0) {
                max += profit;
            }
        }

        System.out.println(max);
    }

    static Map<Integer, Integer> str2List(String str) {
        String[] vArrStr = str.split(" ");

        Map<Integer, Integer> ret = new HashMap<>();
        Integer key = 0;
        for (String val:vArrStr) {
            ret.put(key, Integer.valueOf(val));
            key++;
        }

        return ret;
    }
}


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

int main()
{
	int n,k;
	cin >> n>> k;
	vector<int> l(n);
	for(int i =0;i<n;i++)cin >> l[i];
	sort(l.begin(),l.end(),greater<int>());
	ll ans = 0;
	for(int i =0;i<k;i++)ans+=l[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int a[200000];
map<int, int> mp;

int target[32];

int f(int n){
  rep(i, 32){
    int num = target[i] - n;
    if(num > n) continue;
    if(num < 0) continue;
    if(n != num && mp[n] && mp[num] ||
        n == num && mp[n] >= 2
        ){
      //cout << n << " "<< num << endl;
      mp[n]--;
      mp[num]--;
      return 1;
    }
  }
  return 0;
}

int main(){
  int N;
  cin >> N;
  target[0] = 1;
  rep(i, 1, 32){
    target[i] = target[i - 1] * 2;
  }
  rep(i, N){
    cin >> a[i];
    mp[a[i]]++;
  }
  sort(a, a + N);
  reverse(a, a + N);
  ll ans = 0;
  rep(i, N){
    ans += f(a[i]);
  }
  cout << ans << endl;
  return 0;
}


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

int min(int a,int b){
  if(a>=b) return b;
  else return a;
}

void _mode(int a, int b, int max, int *A, int *mode, int *count){
  int *num;
  num=(int*)malloc((max+1)*sizeof(int));
  for(int i=0;i<=max;i++) num[i]=0;
  for(int i=a;i<=b;i++){
    num[A[i]]++;
  }
  for(int i=0;i<=max;i++){
    if(*count<num[i]){
      *count=num[i];
      *mode=i;
    }
  }
  free(num);
  return;
}

void _mode2(int a, int b, int max, int *A, int mode, int *count){
  int *num;
  num=(int*)malloc((max+1)*sizeof(int));
  for(int i=0;i<=max;i++) num[i]=0;
  for(int i=a;i<=b;i++){
    num[A[i]]++;
  }
  for(int i=0;i<=max;i++){
    if(i!=mode){
      if(*count<num[i]){
        *count=num[i];
      }
    }
  }
  free(num);
  return;
}

int main(){
  int n;
  int *v;
  scanf("%d",&n);
  v=(int*)malloc(n*sizeof(int));
  for(int i=0;i<n;i++) scanf("%d",&v[i]);

  int *odd;
  int *even;
  int odd_max=0;
  int even_max=0;
  odd=(int*)malloc((n/2)*sizeof(int));
  even=(int*)malloc((n/2)*sizeof(int));
  for(int i=0;i<(n/2);i++){
    odd[i]=v[2*i];
    if(odd[i]>odd_max) odd_max=odd[i];
    even[i]=v[2*i+1];
    if(even[i]>even_max) even_max=even[i];
  }
  /*for(int i=0;i<(n/2);i++){
    printf("odd[%d]=%d\neven[%d]=%d\n",i,odd[i],i,even[i]);
  }*/
  int mode_odd=-1;
  int mode_even=-1;
  int count_odd=0;
  int count_even=0;
  _mode(0,n/2-1,odd_max,odd,&mode_odd,&count_odd);
  _mode(0,n/2-1,even_max,even,&mode_even,&count_even);

  //printf("mode_odd=%d count_odd=%d\n",mode_odd,count_odd);
  //printf("mode_even=%d count_even=%d\n",mode_even,count_even);

  int count_odd2=0;
  int count_even2=0;
  _mode2(0,n/2-1,odd_max,odd,mode_odd,&count_odd2);
  _mode2(0,n/2-1,even_max,even,mode_even,&count_even2);

  //printf("count_odd2=%d count_even2=%d\n",count_odd2,count_even2);

  int times;
  if(mode_odd!=mode_even){
    times=n-count_odd-count_even;
  }else{
    times=min(n-count_odd-count_even2,n-count_odd2-count_even);
  }

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

  free(v);
  free(odd);
  free(even);
  return 0;
}

Measured memory_bytes: 1408
N, M, C = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)
ans = 0
N.times do
    as = gets.split.map(&:to_i)
    sum = M.times.map{|i| as[i]*bs[i]}.inject(:+)
    ans += 1 if sum + C > 0
end
puts ans

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

struct unionfind{
    vector<int> par,rank;
    unionfind(int x){
        par.resize(x);
        rank.resize(x);
        for(int i=0; i<x; i++)par[i]=-1,rank[i]=0;
    }
    int root(int x){
        if(par[x]<0)return x;
        return par[x]=root(par[x]);
    }
    void uni(int x,int y){
        x=root(x),y=root(y);
        if(x==y)return;
        if(rank[x]<rank[y]){
            par[y]+=par[x];
            par[x]=y;
        }
        else{
            par[x]+=par[y];
            par[y]=x;
            if(rank[x]==rank[y])rank[x]++;
        }
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

int main(){
    ll n,m;
    cin>>n>>m;
    vector<int> a(m),b(m);
    for(int i=0; i<m; i++){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
    }
    vector<ll> ans(m+1);//a[k]:k本生えたときの不便さ
    ans[0]=(n*n-n)/2;
    unionfind uf(n);
    for(int i=1; i<=m; i++){
        int A=uf.root(a[m-i]),B=uf.root(b[m-i]);
        if(A!=B){
            ans[i]=ans[i-1]-uf.par[A]*uf.par[B];
            uf.uni(A,B);
        }
        else ans[i]=ans[i-1];
    }
    for(int i=0; i<m; i++)cout<<ans[m-i-1]<<endl;
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

bool check(int n) {
	std::string s;
	s = std::to_string(n);
	return s == std::string(s.rbegin(), s.rend());
}

int main(){
	int n;
	std::cin >> n;
	for (int i = 0; i < 1000; ++i) {
		if (check(n - i)) {
			std::cout << n - i << std::endl;
			break;
		}
		else if (check(n + i)) {
			std::cout << n + i << std::endl;
			break;
		}
	}

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P; 
typedef tuple<ll,ll,ll> T;
ll INF = 1e15;

vector<string> area;
ll H,W,K;
ll dx[]={-1,0,1,0};
ll dy[]={0,1,0,-1};


ll bfs(ll sy, ll sx){
	priority_queue<T> que;
	que.push(T(K,sy,sx));
	vector<vector<ll>> visited(H+2,vector<ll>(W+2, 1));
	ll ans=min(min(abs(sy - 1), abs(sy - H)) , min(abs(sx - 1), abs(sx - W)));
	while(!que.empty()){
		ll y,x,k;
		tie(k,y,x) = que.top();
		if(visited[y][x]==0){
			que.pop();
			continue;
		}
		visited[y][x]=0;
		//k=-k;
		que.pop();
		if(k==0)
			continue;
		for(int i=0;i<4;i++){
			if(area[y+dy[i]][x+dx[i]]!='#'){
				que.push(T((k-1),y+dy[i], x+dx[i]));
				ans = min(ans, min(min(abs(y+dy[i] - 1), abs(y+dy[i] - H)) , min(abs(x+dx[i] - 1), abs(x+dx[i] - W))));
			}
		}
	}
	return ans;
}

int main(){
	cin >> H >> W >> K;
	area.assign(H+2, string(W+2, '#'));
	for(int i=1;i<=H;i++){
		cin >> area[i];
		area[i] = "#" + area[i] + "#";
	}
	for(int y=1;y<=H;y++)
		for(int x=1;x<=W;x++)
			if(area[y][x]=='S'){
				ll ret = bfs(y,x);
				if(y==1 || y==H || x==1 || x==W)
					cout << 0 << endl;
				else if(ret == 0)
					cout << 1 << endl;
				else
					cout << 1 + (ret+K-1)/K << endl;
				return 0;
				break;
			}
	return 0;
}
/*
9 11 3
###########
###########
###########
####...####
####S..####
###########
###########
###########
###########

*/


Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n,k; cin >> n >> k;
  int x,ans = 0;
  REP(i,n) {
    cin >> x;
    ans += min(x,abs(k-x))*2;
  }
  COUT(ans);
  return 0;
}


Measured memory_bytes: 256
import math
minimum = 10**100
def prime_divisors(X):
    L=[]
    for i in range(2,math.floor(X**0.5)+1):
        if X % i == 0:
            L.append(i)
    return L
N = int(input())
L = prime_divisors(N)
L.append(1)
for prime in L:
    if (prime + N//prime - 2) < minimum:
        minimum = (prime + N//prime - 2)
print(minimum)

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

const int N = 100007;

int n;
vector<int> G[N];
int par[N], siz[N];

void dfs(int v) {
  siz[v]++;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    if (u != par[v]) {
      par[u] = v;
      dfs(u);
      siz[v] += siz[u];
    }
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(1);

  int v = par[n], cnt = 0;
  while (v != 1) {
    cnt++;
    v = par[v];
  }
//  printf("%d\n", cnt);
  v = n;
  for (int i = 0; i < cnt / 2; i++) {
    v = par[v];
  }
  if (siz[1] - siz[v] > siz[v]) puts("Fennec");
  else puts("Snuke");

  return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
/*
あなたは、
500円玉を A 枚、100 円玉を B 枚、50 円玉を C 枚持っています。 
これらの硬貨の中から何枚かを選び、合計金額をちょうど 
X円にする方法は何通りありますか。
同じ種類の硬貨どうしは区別できません。2 通りの硬貨の選び方は、
ある種類の硬貨についてその硬貨を選ぶ枚数が異なるとき区別されます。
*/


int main (){
  int a=0, b=0, c=0, x=0, ans=0;
  cin >>a >>b >>c >>x;
  for (int i=0; i<=a; ++i){
    for (int j=0; j<=b; ++j){
     for (int k=0; k<=c; ++k){
       if (x == i * 500 + j * 100 + k * 50) ++ans;
     }
    }
  }
  cout <<ans<< endl;
}

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

int main(){
  int x;
  cin >> x;
  
  if(x == 3) cout << "YES" << endl;
  else if(x == 5) cout << "YES" << endl;
  else if(x == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n; cin >> n;
  vector<vector<int>> a(n,vector<int>(n)), b(n,vector<int>(n,1));
  rep(i,n)rep(j,n) cin >> a[i][j];
  
  rep(k,n)rep(i,n)rep(j,n){
    if(k != i && k != j){
      if(a[i][j] > a[i][k]+a[k][j]){
        cout << -1 << endl;
        return 0;
      }else if(a[i][j] == a[i][k] + a[k][j]){
        b[i][j] = 0;
      }
    }  
  }
  ll ans = 0;
  rep(i,n)rep(j,i){
    if(b[i][j]) ans += a[i][j];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict
N = int(input())

counter = defaultdict(int)
for i in range(1, N+1):
    A = str(i)[0]
    B = str(i)[-1]
    counter[A+B] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += counter[str(i)+str(j)] * counter[str(j)+str(i)]

print(ans)


Measured memory_bytes: 40428
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = long.Parse(Console.ReadLine());
        long[] hw = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var h = hw[0];
        var w = hw[1];

        long[][] c = new long[10][];
        for (int i = 0; i < c.Length; i++)
        {
            c[i] = Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

        long[][] a = new long[h][];
        for (int i = 0; i < h; i++)
        {
            a[i] = Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

        // ワーシャルフロイド法
        for (int k = 0; k < 10; k++)
        {
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    c[i][j] = Math.Min(c[i][j], c[i][k] + c[k][j]);
                }
            }
        }

        var ans = 0L;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (a[i][j] == -1) continue;
                ans += c[a[i][j]][1];
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 30476
n, m = map(int, input().split())
l = [0] * n
f = [True] * n
for _ in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == 'WA':
        if f[p]:
            l[p] += 1
    else:
        f[p] = False
ans = 0
for i in range(n):
    if not f[i]:
        ans += l[i]
print(f.count(False), ans)


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

b = a
ans = 0
for i, item in enumerate(a):
  if i == 0:
    continue
  if b[i-1] <= item:
    continue
  else:
    b[i] += a[i-1] - item
    ans += a[i-1] - item
print(ans)

Measured memory_bytes: 94212