akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var l = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var d = l[0]; var n = l[1];
        long res;
        if (d == 0)
        {
            res = 1;
        }
        else if (d == 1)
        {
            res = 100;
        }
        else
        {
            res = 10000;
        }
        if (n == 100) n++;
        Console.WriteLine(res * n);
    }
}


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

struct Rect {
  int h, w;
  Rect(int h_, int w_) : h(h_), w(w_) { }
  bool operator <(const Rect &r) const {
    if(h*h + w*w != r.h*r.h + r.w*r.w) return h*h + w*w < r.h*r.h + r.w*r.w;
    return h < r.h;
  }
};

int main() {
  while(true) {
    int H, W; cin >> H >> W;
    if(H == 0 && W == 0) break;
    Rect m(150, 150);
    Rect n(H, W);
    for(int i = 1; i <= 150; ++i) {
      for(int j = i + 1; j <= 150; ++j) {
        Rect r(i, j);
        if(n < r && r < m) {
          m = r;
        }
      }
    }
    cout << m.h << ' ' << m.w << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

    if ((s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) ||
        (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) ||
        (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
bsreadInt :: BC.ByteString -> Int
bsreadInt = fst . fromJust . BC.readInt
strToInt s = (read :: String -> Int) s

main = do

   n <- readLn :: IO Int
   a <- readLn :: IO Int
   
   if (mod n 500) <= a then putStrLn "Yes"
                       else putStrLn "No"
   


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

int main(void)
{
	float x1, x2, x3, y1, y2, y3;
	float xp, yp, r;
	float rs;
	int n;
	
	scanf("%d", &n);
	
	while (n){
		scanf("%f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3);
		
		xp = ((y1 - y3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) - (y1 - y2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) / (2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3));
		yp = ((x1 - x3) * (x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2) - (x1 - x2) * (x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3)) / (2 * (x1 - x3) * (y1 - y2) - 2 * (x1 - x2) * (y1 - y3));
		r = sqrt((x1 - xp) * (x1 - xp) + (y1 - yp) * (y1 - yp));
		
		n--;
		
		printf("%.3f %.3f %.3f\n", xp, yp, r);
	}
	
	return (0);
}

Measured memory_bytes: 1080
_len = int(input())
nums = input().split(" ")

def isApprove(_len, nums):
  for i in range(_len):
    if int(nums[i]) % 2 == 0:
      if int(nums[i]) % 3 != 0 and int(nums[i]) % 5 != 0:
        return False
  
  return True

print('APPROVED' if isApprove(_len, nums) else 'DENIED')

Measured memory_bytes: 9012
# import bisect
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys

sys.setrecursionlimit(10 ** 5 + 10)


# input = sys.stdin.readline

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

    AA = Counter(A).most_common()

    ls = []
    for i in range(len(AA)):
        if AA[i][1] >= 2:
            ls.append(AA[i])
        else:
            break

    ls=sorted(ls, key=lambda x: x[0])

    try:
        ans = ls[-1][0] * ls[-2][0]
        for i in reversed(range(len(ls))):
            if ls[i][1] >= 4:
                ans = max(ans, ls[i][0] ** 2)
        print(ans)
    except:
        print(0)


resolve()

Measured memory_bytes: 71832
// B - Collecting Balls (Easy Version)
// 1≦N≦100
// 1≦K≦100
// 0<xi<K
// 入力値はすべて整数である。
//
//


#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int N,K;
    vector<int> X(N+1);

    int robo_A,robo_B;
    int sum =0;
    int distance;
    
    //標準入力から数値を受け取る
    cin >> N>>K;
    
    for(int i=1;i<N+1;i++)
    {
        cin >> X.at(i);
    
        robo_A = 2*X.at(i);
        robo_B = 2*(K-X.at(i));
        
        if(robo_A <= robo_B)
        {
            distance = robo_A;
        }
        else
        {
            distance = robo_B;
        }
        sum +=distance;
    }
    cout << sum << endl;
    
    
}

#if 0
// i番目のロボットＡの移動距離を返す関数
// i番目の点の座標Pi(xi,i）
// i番目のロボットＡの座標A(0,i)
int robo_A(int i)
{
    int retval=0;
    retval = 2*X.at(i);
    return retval;
}


// i番目のロボットＢの移動距離を返す関数
// i番目の点の座標Pi(xi,i）
// i番目のロボットＢの座標A(K,i)
int robo_B(int i)
{
    int retval=0;
    retval = 2*(K-X.at(i));
    return retval;
}

#endif


Measured memory_bytes: 16640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    int ans = 0;
    int temp = 0;
    char[] ch = new char[str.length()];
    for(int i = 0; i < str.length(); i++) {
      ch[i] = str.charAt(i);
      if(ch[i] == 'A' || ch[i] == 'T' || ch[i] == 'C' || ch[i] == 'G') {
        temp++;
      } else {
        ans = Math.max(ans, temp);
        temp = 0;
      }
    }
    ans = Math.max(ans, temp);
    System.out.println(ans);
  }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

string a, b, c;

int main(void){
	
	cin >> a >> b >> c;
	cout << a[0] << b[0] << c[0];
    
    return 0;
}


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

int main () {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  int limit = f / (100 * a);
  int water_max = -1;
  int sugar_max = -1;
  float concentration_max = -1;
  for (int i = 1; i <= limit; i++) {
    int water = a * i * 100; 
    int sugar = 0;
    int sugar_limit = water * e / 100;
    for (int j = 0; j <= sugar_limit / c; j++) {
      for (int l = 0; l <= sugar_limit / d; l++) {
        if (c * j + d * l <= sugar_limit) {
          sugar = c * j + d * l;
          if (sugar + water <= f) {
            float concentration_sub = 100 * sugar / ((float) (water + sugar));
            if (concentration_sub > concentration_max) {
              concentration_max = concentration_sub;
              water_max = water;
              sugar_max = sugar;  
            }   
          }  
        }  
      }  
    }  
  }  
  cout << water_max + sugar_max << " " << sugar_max << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i].second >> a[i].first;
  }
  sort(a.begin(),a.end());
  int sum = 0;
  std::string ans ="Yes";
  for(int i=0;i<n;i++){
    sum+=a[i].second;
    if(a[i].first<sum){
      ans="No";
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

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

ll cn[10];
string ve[] = {"AC", "WA","TLE","RE"};

int main() {
    ll n; cin >> n;
    rep(i, 0, n){
        string s; cin >> s;
        rep(j, 0, 4){
            if(s == ve[j]) cn[j]++;
        }
    }
    rep(i, 0, 4){
        co(ve[i] << " x " << cn[i] );
    }

    return 0;
}


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

int main() {
    int n, t, a;
    cin >> n >> t >> a;

    double x = (t - a) / 0.006;

    int j = -1;
    double min_d = INT_MAX;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;

        double d = abs(x - h);
        if (d < min_d) {
            j = i;
            min_d = d;
        }
    }

    cout << ++j << endl;
}

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

using namespace std;
#define deb(x) cout << #x << ": " << x << endl
#define fo(i, n) for (ll i = 0; i < n; i++)
#define fkn(i, k, n) for (i = k; i < n; i++)
#define ll long long
#define F first;
#define S second;
#define PB(x) push_back(x);
#define MP(x,y) make_pair(x,y);
typedef vector<ll> vll;

bool powerOfTwo(ll x)
{
    return !(x & (x - 1));
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int i=0;
    while(a > 0 && c>0)
    {
        //cout<<a<<" "<<c<<endl;
        if(!(i&1))
        {
        c-=b;

        }
        else{
            a-=d;
        }
        i++;

    }
     if (a>0)
    
            cout << "Yes";
        else{
        cout<<"No";
    }
    

}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  lint n, k;
  cin >> n >> k;
  vector<lint> a(n);
  rep (i, n) cin >> a[i];
  int limit = 1;
  while ((1LL << limit) < 1e12) ++limit;
  vector<int> digit_num(limit + 1);
  rep (i, n) {
    rep (j, limit + 1) {
      if (a[i] & (1LL << j)) ++digit_num[j];
    }
  }
  // inc[桁数][0or1] = 増加量
  vector<vector<lint>> inc(limit + 1, vector<lint>(2));
  rep (i, limit + 1) {
    inc[i][0] = (1LL << i) * digit_num[i];
    inc[i][1] = (1LL << i) * (n - digit_num[i]);
  }
  // dp[桁数][k以下が未確定or確定] = 合計
  vector<vector<lint>> dp(limit + 2, vector<lint>(2));
  rrep (i, limit + 1) {
    bool big = inc[i][0] < inc[i][1];
    if (dp[i + 1][1]) dp[i][1] = dp[i + 1][1] + inc[i][big];
    if (k & (1LL << i)) {
      dp[i][0] = dp[i + 1][0] + inc[i][1];
      dp[i][1] = max(dp[i][1], dp[i + 1][0] + inc[i][0]);
    } else {
      dp[i][0] = dp[i + 1][0] + inc[i][0];
    }
  }
  cout << max(dp[0][0], dp[0][1]) << endl;
  return 0;
}

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

int main() {
  int n,m;
  int sum=0;
  cin>>n>>m;
  vector<int>vec(m);
  for(int i=0;i<m;i++){
    cin>>vec.at(i);
    sum+=vec.at(i);
  }
  if(n-sum>=0){
    cout<<n-sum<<endl;
  }else{
    cout<<-1<<endl;
  }
  

}



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

int main() {
  int A, B, C, K, S = 0, b = 1;
  cin >> A >> B >> C >> K;
  if(b){
    if(A <= K && K != 0){
      S += A;
      K -= A;
    }
    else{
      S += K;
      b = 0;
    }
  }
  if(b){
    if(B <= K && K != 0){
      K -= B;
    }
    else{
      b = 0;
    }
  }
  if(b){
    if(C <= K && K != 0){
      S -= C;
      K -= C;
    }
    else{
      S -= K;
      b = 0;
    }
  }
  cout << S << endl;
  return 0;
    
}

Measured memory_bytes: 3676
#include<iostream>
#include<string>
using namespace std;
int main(){
  string a, b;
  cin >> a >> b;
  bool check = false;
  for(int i=a.length()-b.length();i>=0;i--){
    int j=0,k=i;
    while(1){
      if(a[k]!=b[j]&&a[k]!='?')break;
      if(j+1==b.length()){
        check=true;
        break;
      }
      k++;
      j++;
    }
    if(check){
      j=0,k=i;
      while(1){
        a[k]=b[j];
        if(j+1==b.length())break;
        k++;j++;
      }

      for(int l=0;l<=a.length()-1;l++){
        if(a[l]=='?')a[l]='a';
      }
      break;
    }
  }

  if(check==false){
    cout << "UNRESTORABLE" << endl;
    exit(0);
  }

  cout << a << endl;

}

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

int main()
{
    int h, w;
    cin>>h>>w;
    vector<int> cnt(128);
    for(int i=0; i<h; ++i) {
        string s;
        cin>>s;
        for(char c: s) ++cnt[c];
    }
    int n4=0, n2=0, n1=0;
    for(int c: cnt) {
        n4+=c/4;
        c%=4;
        n2+=c/2;
        c%=2;
        n1+=c;
    }
    if (n1>1) return cout<<"No"<<endl, 0;
    if (n1 and h*w%2==0) return cout<<"No"<<endl, 0;
    if (n2 and h%2==0 and w%2==0) return cout<<"No"<<endl, 0;

    if (h%2==0 and w%2) swap(h, w);
    if (h%2 and w%2) {
        cout<<(n2>(h-1)/2+(w-1)/2 ? "No" : "Yes")<<endl;
        return 0;
    }
    if (h%2) {
        cout<<(n2>w/2 ? "No" : "Yes")<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (A, B, M) = readIntList()
    val a = readIntList()
    val b = readIntList()

    var ans = a.min()!! + b.min()!!
    for (m in 0 until M) {
        val (x, y, c) = readIntList()
        val t = a[x-1] + b[y-1] - c
        ans = Math.min(t, ans)
    }
    println(ans)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 86684
//smartphone
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) tsort(v); reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

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

template<class T>bool maxi(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool mini(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int ret,d;
int sixonly(int n){ret=0;
    for(int i=6;i>=0;--i){d=pow(6,i);
        ret+=n/d;
        n-=n/d*d;
    }return ret;
}
int nineonly(int n){ret=0;
    for(int i=5;i>=0;--i){d=pow(9,i);
        ret+=n/d;
        n-=n/d*d;
    }return ret;
}

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

    int n,ans=INT_MAX;cin>>n;
    rep(i,n+1){
        ans=min(ans,sixonly(i)+nineonly(n-i));
    }co(ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int n[5];
  int ten[5];
  int ans = 0;
  rep(i, 0, 5) {
    scanf("%d", &n[i]);
    // n[i]以上で一番近い10の倍数を足す
    ten[i] = ((n[i] + 9) / 10) * 10;
    ans += ten[i];
  }

  int dif = 0;
  rep(i, 0, 5) {
    dif = max(dif, ten[i] - n[i]);
  }

  ans -= dif;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){
    int n, h, i, j, tmp, max, min;
    int num[8];

    scanf("%d", &n);
    for(h = 0; h < n; h++){
        for(i = 0; i < 8; i++){
            num[i] = 0;
            scanf("%1d", &num[i]);
        }

        for(i = 0; i < 7; i++){
            for(j = 7; j > i; j--){
                if(num[j] > num[j-1]){
                    tmp = num[j-1];
                    num[j-1] = num[j];
                    num[j] = tmp;
                }
            }
        }

        max = min = 0;
        for(i = 1, j = 7; j >= 0; i *= 10, j--){
            tmp = num[j] * i;
            max += tmp;
        }
        for(i = 1, j = 0; j < 8; i *= 10, j++){
            min += num[j] * i;
        }
        printf("%d\n", max-min);
    }
    return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int N;
    cin >> N;

    vector<int>a(N);
    rep(i,N) cin >> a[i];

    multiset<pair<int, int> > ans_pair;
    set<pair<int, int> > key;
    rep(i,N)
    {
        ans_pair.insert( make_pair(min(i+1, a[i]), max(i+1, a[i])) );
        key.insert( make_pair(min(i+1, a[i]), max(i+1, a[i])) );
    }

    int ans = 0;

    for(set<pair<int, int> >::iterator itr = key.begin(); itr != key.end(); itr++)
    {
        if( ans_pair.count( *itr ) > 1 ) ans++;
    }
    cout << ans << endl;

}


Measured memory_bytes: 9984
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] n = new int[]{0,5,6,6,6,6,6,8,6,8};
		char[][] c = new char[10][];
		c[1] = new char[]{'\'', ',', '.', '!', '?'};
		int cnt = 97;
		for(int i=2;i<10;i++){
			c[i] = new char[n[i]];
			for(int j=0;j<n[i]/2;j++){
				c[i][j] = (char)cnt;
				c[i][j+n[i]/2] = (char)(cnt-32);
				cnt++;
			}
		}
		
		while(sc.hasNext()){
			String s = sc.next() + "0";
			char[] cc = s.toCharArray();
			
			cnt = 0;
			for(int i=1;i<cc.length;i++){
				if(cc[i]==cc[i-1]){
					if(cc[i-1]=='0') System.out.print(' ');
					else cnt++;
				}else{
					if(cc[i-1]!='0'){
						int m = cc[i-1]-48;
						System.out.print(c[m][cnt%n[m]]);
						cnt = 0;
					}
				}
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 15396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    private static final long MOD = 998_244_353;

    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int a = scanner.nextInt();
        final int b = scanner.nextInt();
        final int c = scanner.nextInt();
        final int d = scanner.nextInt();

        if (a == c && b == d) {
            System.out.println(1);
            return;
        }

        final long[][] addedCol = new long[c + 1][d + 1];
        addedCol[a][b] = 1;
        for (int i = a + 1; i <= c; i++) {
            addedCol[i][b] = addedCol[i - 1][b] * b % MOD;
        }

        final long[][] addedRow = new long[c + 1][d + 1];
        addedRow[a][b] = 1;
        for (int i = b + 1; i <= d; i++) {
            addedRow[a][i] = addedRow[a][i - 1] * a % MOD;
        }

        for (int i = a + 1; i <= c; i++) {
            for (int j = b + 1; j <= d; j++) {
                addedCol[i][j] = (addedCol[i - 1][j] + addedRow[i - 1][j]) * j % MOD;
                addedRow[i][j] = (addedCol[i][j - 1] + addedRow[i][j - 1] * i) % MOD;
            }
        }

        System.out.println((addedCol[c][d] + addedRow[c][d]) % MOD);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}
    

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T, class U> using p = pair<T, U>;

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

template<class T> T read() { T x{}; cin >> x; return x; }
template<class T> v<T> read(int N){ v<T> x(N); REP(i, N) cin >> x[i]; return x; }

template<class T>
void write(const T &x){ cout << x << endl; }
void write(double x){ printf("%.15f\n", x); }

template<class T> T& chmin(T &obj, T val){ return obj = min(obj, val); }
template<class T> T& chmax(T &obj, T val){ return obj = max(obj, val); }

// 二分探索 : [low, high) の範囲で述語 pred がtrue を返す最大の値を返す
template<class Pred>
ll bsearch(ll low, ll high, Pred pred){
    while(low + 1 < high){
        const ll mid = low + (high - low) / 2;
        if(pred(mid)){ low = mid; }
        else{ high = mid; }
    }
    return low;
}

int main() {
    ll N;
    string S;
    cin >> N;
    cin >> S;
    string a = "ABC";
    ll ans = 0;
    for(auto p = S.find(a); p != S.npos; p = S.find(a, p+3)){
        ++ans;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
solve :: Int -> [Int] -> Int
solve p a
  | all even a = if p == 0 then c else 0
  | otherwise  = c `div` 2
  where
    n = length a
    c = 2^n

main :: IO ()
main = do
    [_,p] <- map read . words <$> getLine :: IO [Int]
    a <- map read . words <$> getLine :: IO [Int]
    print $ solve p a

Measured memory_bytes: 764
#include<iostream>
#include<map>
using namespace std;
int main()
{
  map<int,int>m;
  int x;
  for(int i=0;i<3;++i){
    cin>>x;
    m[x]++;
  }
  for(auto&a:m)
    if(a.second==1)cout<<a.first<<endl;
}


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

int main() {
    string S;
    string T;
    cin >> S >> T;
    bool a = true;
    for(int i=0; i<S.size(); i++){
        if(S.at(i)!=T.at(i)){
            a = false;
        }
    }

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


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

int main(void) {
  int n, k;
  cin >> n >> k;
  int D[k];
  for (int i = 0; i < k; i++) cin >> D[i];

  int r[5]; int i = 0;
  int nn = n;
  while(true) {
    i = 0;
      while(nn>0) {
      r[i++] = nn % 10;
      nn /= 10;
    }
    int len = i, key = 0; 
    for (int i = 0; i < len; i++) {
      for (int j = 0; j < k; j++) {
        if (D[j] == r[i]) {key = -1; break; }
      }
    }
    if (key == -1) {
      n++; nn = n;
    } else {
      cout << n << endl; break;
    }
  }
  
}

Measured memory_bytes: 3584
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}
int calc(int a, int b) {
   int d = abs(a - b);
   return min(d, 24 - d);
}

int main() {
   int N;
   cin >> N;
   int D[N];
   int log[13];
   memset(log, 0, sizeof(log));
   log[0]++;
   for (int i = 0; i < N; i++) {
      cin >> D[i];
      log[D[i]]++;
   }
  
   int cnt = 13;
   /*
   for (int i = 0; i < cnt; i++) {
      cout << log[i] << endl;
   }
   */
   vector<int> tmp;
   int ans = 0;
   for (int mask = 0; mask < (1 << cnt); mask++) {
      tmp.clear();
      int ansmin = 24;
      for (int i = 0; i < cnt; i++) {
         if (log[i] == 0) continue;
         if (log[i] >= 3) {
            ansmin = 0;
            break;
         }
         if (log[i] == 2) {
            if (i == 0 || i == 12) {
               ansmin = 0;
               break;
            }
            tmp.push_back(i);
            tmp.push_back(24 - i);
         } else if (log[i] == 1) {
            if (((mask >> i) & 1)) {
               tmp.push_back(i);
            } else {
               tmp.push_back(24 - i);
            }
         }
      }
      if (ansmin == 0) {
         chmax(ans, ansmin);
         continue;
      }
      sort(tmp.begin(), tmp.end());
      /*
      for (int i = 0; i < tmp.size(); i++) {
         cout << tmp[i] << " ";
      }
      cout << endl;
      */
      for (int i = 1; i < tmp.size(); i++) {
         chmin(ansmin, calc(tmp[i], tmp[i - 1]));
      }
      chmin(ansmin, calc(tmp[0], tmp[tmp.size() - 1]));
      // cout << ansmin << endl;
      chmax(ans, ansmin);
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
ans = 0
if A + B < 2 * C:
  print(A * X + B * Y)
else:
  while X > 0 and Y > 0:
    ans += 2 * C
    X -= 1
    Y -= 1  
  if A > 2 * C:
    A = 2 * C
  if B > 2 * C:
    B = 2 * C
  print(ans + A * X + B * Y)

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

#define ll long long
#define mod 1000000007

int main() {
    ll n,m;
    cin>>n>>m;
    string s1,s2;
    for(ll i=0;i<n;i++)s1+=m+'0';
    for(ll i=0;i<m;i++)s2+=n+'0';
    cout<<min(s1,s2);
    return 0 ;
}


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

/*０からｘまでのXOR*/
/*nが偶数の時、n^(n+1)==1*/
ll XOR(ll x){
    if (x % 4 == 0) return x;
    if (x % 4 == 1) return 1;
    if (x % 4 == 2) return x + 1;
    return 0;
}
int main(){
    ll A,B;
    cin >> A >> B;
    ll ans = XOR(A-1) ^ XOR(B);
    cout << ans << endl;
}

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

for i in range(n):
    minj = i
    for j in range(i,n):
        if a[j] < a[minj]:
            minj = j
    if minj != i:
        numSwap += 1
        a[i],a[minj] = a[minj],a[i]
a = [str(s) for s in a]
print(' '.join(a))
print(numSwap)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int n=s.length(),m=t.length();
    int dp[n+1][m+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(i==0 || j==0)
                dp[i][j]=0;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else

                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string ans="";
    while(n>0 && m>0)
    {
        if(dp[n-1][m]==dp[n][m])
        {

            n--;
        }
        else if(dp[n][m-1]==dp[n][m])
        {

            m--;
        }
        else
        {
                ans.push_back(s[n-1]);
                n--;
                m--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;

}


Measured memory_bytes: 38792
K = int(input())

A = [0 for d in range(20)]
A[0] = 1
dit_max = 0


for ct in range(2,K+1):
  dit_now = 0
  while dit_max > dit_now and (A[dit_now] == A[dit_now+1]+1 or A[dit_now] == 9):
    dit_now += 1
  if dit_max > dit_now:
    A[dit_now] += 1
  elif dit_max == dit_now:
    if A[dit_now] == 9:
      dit_max += 1
      dit_now += 1
    A[dit_now] += 1
  for d in range(dit_now-1,-1,-1):
      A[d] = max(A[d+1] - 1,0)
  #if ct > 30:
    #print(ct, A)
      
ans = 0
for i in range(20):
  ans += A[i] * 10**i
print(ans)


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

typedef long long int ll;

#define first fs
#define second se
#define make_pair mk
#define push_back pb

vector< pair<ll,ll> > vec;

void solve()
{
	ll n,k;
	cin>>n>>k;
	ll arr[n];
	for(ll i=0;i<n;i++)
	{
       cin>>arr[i];
	}
	ll dp[n+1];
	memset(dp,0,sizeof(dp));

	
	for(ll i=0;i<n;i++)
	{
        ll m = 1000000000000;
		for(ll j=i-1;j>=i-k and j>=0;j--)
		{
			m = min(m,dp[j]+abs(arr[i]-arr[j]));
		}
		if(i==0)m=0;
		dp[i]=m;
		//cout<<dp[i]<<endl;
	}
	cout<<dp[n-1]<<endl;

}

int main()
{
	ll t;
	t = 1;
	for(ll i=0;i<t;i++)solve();
}


Measured memory_bytes: 1792
d,g = map(int,input().split())
g //= 100
P,C = [],[]
for i in range(1, d+1):
    p,c = map(int,input().split())
    P.append(p)
    C.append(c//100)
ans = 10**9
for bin in range(1, 1<<d):
    cnt = tot = 0
    for j in range(d):
        if bin & 1<<j:
            cnt += P[j]
            tot += P[j]*(j+1) + C[j]
    if tot < g: continue
    ans = min(ans, cnt)
    for j in range(d):
        if bin & 1<<j:
            rest_g = g - (tot - P[j]*(j+1) - C[j])
            p = max(0, (rest_g+j)//(j+1)) # round up
            ans = min(ans, (cnt - P[j]) + min(p, P[j]))
print(ans)


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


using namespace std;

#define fastio() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


void go(){
	int n,d;
	cin >> n >> d;
	int ans=0;
	while(n--) {
		int x,y;
		cin >> x >> y;
		double dis=(double) sqrt(pow(x,2)+pow(y,2));
		if(dis<=d) {
			//cout << "[" << x << " " << y << "]" << endl;
			//cout <<"[" << dis <<"]" << endl;
			ans++;
		}else {
			//cout <<"[" << dis <<"]" << endl;
		}
	}
	cout << ans;
}
int main(){
   fastio();
   go();

   return 0;
}




Measured memory_bytes: 3664
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<long long>::max();
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, s, t, q, ans, sum, last, cnt = 25000, a[100000],dp[60][10000];
Pll b[100000];
struct Edge { LL to,cost; };
vector<Edge>vec[100000];
string str[3];
bool f;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Seg {
	LL n;
	vector<LL>node;
	Seg(vector<LL>v) {
		n = 1; while (n < v.size())n *= 2;
		node.resize(n * 2 - 1);
		rep(i, n)node[n + i - 1] = v[i];
		Mfor(i, n - 2)node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
	}
	Seg(LL n_) {
		n = 1; while (n < n_)n *= 2;
		node.resize(n * 2 - 1);
		rep(i, n)node[n + i - 1] = 0;
	}
	void update(LL i, LL x) {
		i = i + n - 1;
		node[i] += x;
		while (i > 0) {
			i = (i - 1) / 2;
			node[i] = (node[i * 2 + 1] + node[i * 2 + 2]);
		}
	}
	LL getsum(LL i, LL a, LL b, LL l, LL r) {
		if (b< l || r < a)return 0;
		if (l <= a&&b <= r)return node[i];
		return (getsum(i * 2 + 1, a, (a + b) / 2, l, r)+getsum(i * 2 + 2, (a + b + 1) / 2, b, l, r));
	}
};
int main() {
	cin >> n >> q;
	Seg seg(n);
	rep(i, q) {
		LL x, y, z;
		cin >> x >> y >> z;
		if (x == 0)seg.update(y-1, z);
		else cout << seg.getsum(0, 0, seg.n-1, y-1, z-1) << endl;
	}
	return 0;
}



Measured memory_bytes: 7248
#!/usr/bin/env python
# coding: utf-8

# In[2]:


import math


# In[7]:


N = int(input())
xy = []
for _ in range(N):
    xy.append(list(map(int, input().split())))


# In[8]:


dist = 0
for i in range(N):
    for j in range(i,N):
        dist += math.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)
print(dist*2/N)


# In[ ]:






Measured memory_bytes: 9156
using System;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            // 入力（スペース区切り）
            string[] input = Console.ReadLine().Split(' ');

            int M = int.Parse(input[0]);

            // 出力
            Console.WriteLine("{0}", (48 - M));
        }
    }
}

Measured memory_bytes: 13268
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine().Split().Select(e => decimal.Parse(e)).ToArray();
        var D = s[0];
        var T = s[1];
        var S = s[2];
        if (D / S <= T)
        {
            Console.WriteLine("Yes");
            return;
        }
        Console.WriteLine("No");
    }
}


Measured memory_bytes: 28208
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

ll XYtoU(ll x, ll y){return x + y;};
ll XYtoV(ll x, ll y){return x - y;};

string s[4] = {"L", "R", "D", "U"};
ll du[4] = {-1, 1, -1, 1};
ll dv[4] = {-1, 1, 1, -1};

int main(){

    ll N;
    cin >> N;
    vector<ll>X(N), Y(N), U(N), V(N);
    ll flg = 0;
    for(ll i = 0; i < N; i++){
        cin >> X[i] >> Y[i];
        U[i] = XYtoU(X[i], Y[i]);
        V[i] = XYtoV(X[i], Y[i]);
        if(abs(X[i] + Y[i]) % 2)flg |= 1;
        else flg |= 2;
    }
    if(flg == 3){
        cout << -1 << endl;
        return 0;
    }
    if(flg == 1){
        cout << 35 << endl;
        for(ll i = 34; i >= 0; i--){
            ll d = (1LL << i);
            cout << d;
            if(i == 0)cout << endl;
            else cout << " ";
        }
    }
    else{
        cout << 36 << endl;
        for(ll i = 34; i >= 0; i--){
            ll d = (1LL << i);
            cout << d << " ";
        }
        cout << 1 << endl;
    }
    for(ll i = 0; i < N; i++){
        if(flg == 2){
            U[i] = XYtoU(X[i] + 1, Y[i]);
            V[i] = XYtoV(X[i] + 1, Y[i]);
        }
        ll u = 0, v = 0;
        string ans = "";
        for(ll j = 34; j >= 0; j--){
            ll d = (1LL << j);
            ll k = 0;
            if(u < U[i] && v < V[i])k = 1;
            if(u > U[i] && v < V[i])k = 2;
            if(u < U[i] && v > V[i])k = 3;
            ans += s[k];
            u += d * du[k];
            v += d * dv[k];
        }
        if(flg == 2)ans += "L";
        cout << ans << endl;
    }
    return 0;
}

/*
u = x + y
v = x - y

(x, y) -> (u, v)
L : -d, 0 -> -d, -d
R : +d, 0 -> +d, +d
D : 0, -d -> -d, +d
U : 0, +d -> +d, -d
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int l, r;

int bits(int n){
   int bit = 0;
   while(n){
      bit++;
      n /= 2;
   }
   return bit;
}

string getBinary(int r){
   string nr = "";
   while(r){
      nr += (char)(r%2 + '0');
      r /= 2;
   }
   reverse(nr.begin(), nr.end());
   return nr;   
}

int getInteger(string s){
   int ans = 0;
   for (int i = 0; i < (int)(s.size()); ++i)
   {
      ans *= 2;
      ans += s[i] - '0';
   }
   return ans;
}

int solve(int l, int r){

   string nl = getBinary(l);
   string nr = getBinary(r);

   vector<vector<int>> intervals;
   intervals.push_back({l, r});
   int cnt1 = count(nr.begin(), nr.end(), '1');

   // tr(nl, nr, cnt1);
   if (cnt1 >= 2){
      intervals.pop_back();
      string tmp = nr;

      int pos = -1;
      for (int i = 1; i < (int)(tmp.size()); ++i)
      {
         if (tmp[i] == '1'){
            pos = i;
            break;
         }
      }

      for (int i = pos; i < (int)(tmp.size()); ++i)
      {
         tmp[i] = '1';
      }

      intervals.push_back({l, getInteger(tmp)});
   }

   string less_pow_2 = nr;
   for (int i = (int)(less_pow_2.size()); i > 0; --i)
   {
      less_pow_2[i] = '0';
   }

   string nxt_pow_2 = nr;
   for (int i = (int)(nxt_pow_2.size()); i >= 0; --i)
   {
      nxt_pow_2[i] = '1';
   }
   intervals.push_back({l | getInteger(less_pow_2), getInteger(nxt_pow_2)});

   // tr(intervals);
   int ans = 0;
   if (intervals.back()[0] > intervals[0][1]){
      ans += intervals[0][1] - intervals[0][0] + 1;
      ans += intervals.back()[1] - intervals.back()[0] + 1;
   }
   else{
      ans += intervals.back()[1] - intervals[0][0] + 1;
   }

   return ans;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
   uniform_int_distribution<int> uid(l, r);
   return uid(rng);
}
//shuffle(v.begin(), v.end(), rng);

void solve(){
   // l = rand(1,(1LL<<60)-1);
   // r = rand(1,(1LL<<60)-1);
   // if (l > r){
   //    swap(l, r);
   // }
   cin >> l >> r;

   if (l == r){
      cout<<1;
      exit(0);
   }

   if (bits(l) < bits(r)){
      cout << solve(l, r);
      return ;
   }

   string nl = getBinary(l);
   string nr = getBinary(r);

   int pos = 0;
   while(pos < (int)(nl.size()) and nl[pos] == nr[pos]){
      ++pos;
   }
   assert(pos != (int)(nl.size()));

   nl = nl.substr(pos);
   nr = nr.substr(pos);
   // tr(nl, nr);
   cout<<solve(getInteger(nl), getInteger(nr));
}

int32_t main(){_
   
   int t = 1;

   while(t--){
     solve();
     cout << endl;
   }
   

   return 0;
}

Measured memory_bytes: 384
package main

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

type DisjointSetUnion struct {
	n            int
	parentOrSize []int
}

func New(n int) *DisjointSetUnion {
	d := &DisjointSetUnion{
		n:            n,
		parentOrSize: make([]int, n),
	}
	for i := range d.parentOrSize {
		d.parentOrSize[i] = -1
	}
	return d
}

func (d *DisjointSetUnion) Merge(a, b int) int {
	if !(0 <= a && a < d.n) {
		panic("")
	}
	if !(0 <= b && b < d.n) {
		panic("")
	}
	x, y := d.Leader(a), d.Leader(b)
	if x == y {
		return x
	}
	if -d.parentOrSize[x] < -d.parentOrSize[y] {
		x, y = y, x
	}
	d.parentOrSize[x] += d.parentOrSize[y]
	d.parentOrSize[y] = x
	return x
}

func (d *DisjointSetUnion) Same(a, b int) bool {
	if !(0 <= a && a < d.n) {
		panic("")
	}
	if !(0 <= b && b < d.n) {
		panic("")
	}
	return d.Leader(a) == d.Leader(b)
}

func (d *DisjointSetUnion) Leader(a int) int {
	if !(0 <= a && a < d.n) {
		panic("")
	}
	if d.parentOrSize[a] < 0 {
		return a
	}
	d.parentOrSize[a] = d.Leader(d.parentOrSize[a])
	return d.parentOrSize[a]
}

func (d *DisjointSetUnion) Size(a int) int {
	if !(0 <= a && a < d.n) {
		panic("")
	}
	return -d.parentOrSize[d.Leader(a)]
}

func (d *DisjointSetUnion) Groups() [][]int {
	leaderBuf, groupSize := make([]int, d.n), make([]int, d.n)
	for i := 0; i < d.n; i++ {
		leaderBuf[i] = d.Leader(i)
		groupSize[leaderBuf[i]]++
	}
	result := make([][]int, d.n)
	for i := 0; i < d.n; i++ {
		result[i] = make([]int, 0, groupSize[i])
	}
	for i := 0; i < d.n; i++ {
		result[leaderBuf[i]] = append(result[leaderBuf[i]], i)
	}
	eraseEmpty := func(a [][]int) [][]int {
		result := make([][]int, 0, len(a))
		for i := range a {
			if len(a[i]) != 0 {
				result = append(result, a[i])
			}
		}
		return result
	}
	return eraseEmpty(result)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Connect Cities
	var N, M int
	fmt.Scan(&N, &M)

	d := New(N)
	sc.Split(bufio.ScanWords)
	var A, B, count int
	for i := 0; i < M; i++ {
		A, B = nextInt(), nextInt()
		A--
		B--
		if !d.Same(A, B) {
			d.Merge(A, B)
			count++
		}
	}

	fmt.Println(N - count - 1)
}


Measured memory_bytes: 3808
#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
const int MAXN=1010;
const int Inf=2147483647;
int n,Lim,Ans=Inf;
inline int Min(rg int A,rg int B){   return A<B?A:B;   }
int main()
{   scanf("%d%d",&n,&Lim);
	for(rg int i=1,C,T;i<=n;i++)
	{	scanf("%d%d",&C,&T);
		if(T<=Lim) Ans=Min(Ans,C);
	}
	if(Ans==Inf) puts("TLE");
	else printf("%d\n",Ans);
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <map>
#include <cstdio>
 
using namespace std;
 
int main(){
    int hand[5];
 
    while(~scanf("%d", &hand[0])){
        for(int i = 1; i < 5; i++){
            scanf(",%d", &hand[i]);
        }
        int num[15] = {0};
 
        for(int i = 0; i < 5; i ++){
			if(hand[i] == 1) num[14]++;
			num[hand[i]]++;
		} 
        int h[7] = {0};
        string s[] = {"null", "one pair", "two pair", "three card", "straight", "full house", "four card"};
        int seq = 0;
        h[0] = 1;
        for(int i = 1; i < 15; i++){
            if(num[i-1] && num[i]) seq++;
            if(num[i] == 2 && i != 14) h[1]++;
            if(num[i] == 3) h[3]++;
            if(num[i] == 4) h[6]++;
        }
        if(h[1] > 1) h[2]++;
        if(h[1] && h[3]) h[5]++;
        if(seq == 4)
			if(!(num[2] && num[13])) h[4]++;
 
        for(int i = 6; i >= 0; i--){
            if(h[i]){
                cout << s[i] << endl;
                break;
            }
        }
    }
 
 
    return 0;
}

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

int main() {
    int n, d, x;
    cin >> n >> d >> x;
    rep(i,n) {
        int a, cnt = 0;
        cin >> a;
        cnt = 1 + (d-1)/a;
        x+=cnt;
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vl v(MAX_N);
    rep(i, n) {
        ll a;
        cin >> a;
        v[a]++;
    }

    if(n%2 == 0) {
        for(ll i = 1; i < n; i += 2) {
            if(v[i] != 2) {
                out(0);
                re0;
            }
        }
    }
    else {
        if(v[0] != 1) {
            out(0);
            re0;
        }
        for(ll i = 2; i < n; i += 2) {
            if(v[i] != 2) {
                out(0);
                re0;
            }
        }
    }

    ll ans = 1;
    rep(i, n/2) {
        ans *= 2;
        ans %= mod;
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

template<typename V> class BIT {
private:
    int n; vector<V> bit;
public:
    void add(int i,V x){ i++; while(i < n) bit[i] += x, i += i & -i;}
    V sum(int i){ i++; V s = 0; while(i>0) s += bit[i], i -= i & -i; return s;}
    BIT(){} BIT(int sz){ n = sz + 1, bit.resize(n,0);} //?????????????????????0?????´???
    BIT(vector<V> v){ n = (int)v.size()+1; bit.resize(n); rep(i,n-1) add(i,v[i]);}
    void print(){ rep(i,n-1)cout<<sum(i)-sum(i-1)<< " ";cout<<endl;}
    void print_sum(){ rep(i,n)cout<<sum(i-1)<<" ";cout<<endl;}	//-1????????????
};

void zaatu(vector<int>& u,vector<int>& v, vector<int>& nu, vector<int>& nv)
{
    int n = (int)u.size();
    vector<int> sa = u;
    sort(all(sa));
    rep(i,n){
        nu[i] = lower_bound(all(sa),u[i]) - sa.begin();
        nv[i] = lower_bound(all(sa),v[i]) - sa.begin();
    }
}

ll inv_count(vector<int>& u,vector<int>& v)
{
    int n = len(u);
    vector<int> p(n);
    BIT<int> bt(n);
    ll ans = 0;
    rep(i,n){
        p[v[i]] = i;
    }
    rep(i,n){
        ans += i-bt.sum(p[u[i]]);
        bt.add(p[u[i]],1);
    }
    return ans;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi u(n);
    rep(i,n){
        cin >> u[i];
    }
    vi v = u;
    sort(all(v));
    vi nu(n),nv(n);
    zaatu(u,v,nu,nv);
    cout << inv_count(nu,nv) << "\n";
    return 0;
}

Measured memory_bytes: 7496