akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        sc.close();

        // 主処理
        final int LON_A = a.length();
        final int LON_B = b.length();
        final int LON_C = c.length();

        int ia = 0;
        int ib = 0;
        int ic = 0;

        char turn = 'a';
        while (ia <= LON_A && ib <= LON_B && ic <= LON_C) {
            if (turn == 'a' && ia < LON_A) {
                turn = a.charAt(ia);
                ia++;
            } else if (turn == 'b' && ib < LON_B) {
                turn = b.charAt(ib);
                ib++;
            } else if (turn == 'c' && ic < LON_C) {
                turn = c.charAt(ic);
                ic++;
            } else {
                break;
            }
        }

        String result = String.valueOf(turn).toUpperCase();

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <cmath>
#include <map>

using namespace std;

char win(char op) {
  if (op == 'p')
    return 's';
  else if (op == 's')
    return 'r';
  else
    return 'p';
}

int main(int argc, char* argv[]) {
  int N, K, R, S, P;
  cin >> N >> K >> R >> S >> P;

  map<char, int> score;
  score['p'] = P;
  score['s'] = S;
  score['r'] = R;

  string t;
  cin >> t;

  bool won[N];
  long long ret = 0;
  for (int i = 0; i < K; ++i) {
    int j = 0;
    won[i] = true;
    while (true) {
      int index = i + j * K;
      if (index >= N)
        break;
      if (j == 0)
        ret += score[win(t[index])];
      else {
        int prev_index = i + (j - 1) * K;
        if (t[index] == t[prev_index] && won[prev_index]) {
          won[index] = false;
        } else if (t[index] == t[prev_index] && !won[prev_index]) {
          ret += score[win(t[index])];
          won[index] = true;
        } else {
          ret += score[win(t[index])];
          won[index] = true;
        }
      }
      ++j;
    }
  }

  cout << ret << endl;

  return 0;
}

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

int main(){
  int N, K;
  int KEIJI = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++){
    if (KEIJI > K){
      KEIJI = K + KEIJI;
    }
    else {
      KEIJI = 2 * KEIJI;
    }
  }
  cout << KEIJI << endl;
}



Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int gcd(int a,int b){
    int temp;
    while(b!=0){
        temp=b;
        b=a%b; a=temp;
    }
    return a;
}

int main() {
    int k,ans=0; cin>>k;
    for(int a=1;a<=k;a++){
        for(int b=1;b<=k;b++){
            for(int c=1;c<=k;c++){
                ans+=gcd(gcd(a,b),c);
            }
        }
    }
    cout<<ans<<endl;
    
}

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

int main(){
	int a[3],k;
	cin>>a[0]>>a[1]>>a[2]>>k;
	sort(a,a+3);
	for(int i=0;i<k;i++) a[2]*=2;
	cout<<a[0]+a[1]+a[2]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
#include<time.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ")
#define pdd(a,n,m)for(int i=0;i<m;i++)pd(a,m)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

int n;

int main(){
  cin>>n;
  int ans=0;
  for(int i=1;i<=n;i++){
    int cnt=0;
    for(int j=1;j<=n;j++)if(i%j==0)cnt++;
    if(i%2==1&&cnt==8)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<int,int> P;

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

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;
typedef tuple<ll,int,int,int> T;
int main(){
    int X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    vector<ll>a(X),b(Y),c(Z);
    map<T,int>mp;
    rep(i,X){
        cin >>a[i];
    }
    rep(i,Y){
        cin >>b[i];
    }
    rep(i,Z){
        cin >>c[i];
    }
    sort(a.begin(),a.end(), greater<ll>());
    sort(b.begin(),b.end(), greater<ll>());
    sort(c.begin(),c.end(), greater<ll>());

    priority_queue<T, vector<T>>que;
    que.push(T(a[0]+b[0]+c[0], 0,0,0));
    mp[T(a[0]+b[0]+c[0], 0,0,0)]++;

    for(int l=0; l<K; l++){
        int i=get<1>(que.top()),j=get<2>(que.top()),k=get<3>(que.top());
        cout << get<0>(que.top()) << endl;
        que.pop();
        if(i<X-1 && mp[T(a[i+1]+b[j]+c[k], i+1,j,k)]==0) {
            que.push(T(a[i + 1] + b[j] + c[k], i + 1, j, k));
            mp[T(a[i+1]+b[j]+c[k], i+1,j,k)]=1;
        }
        if(j<Y-1 && mp[T(a[i]+b[j+1]+c[k], i,j+1,k)]==0) {
            que.push(T(a[i] + b[j + 1] + c[k], i, j + 1, k));
            mp[T(a[i]+b[j+1]+c[k], i,j+1,k)]=1;
        }
        if(k<Z-1 && mp[T(a[i]+b[j]+c[k+1], i,j,k+1)]==0) {
            que.push(T(a[i] + b[j] + c[k + 1], i, j, k + 1));
            mp[T(a[i] + b[j] + c[k + 1], i, j, k + 1)]=1;
        }
    }
    return 0;
}



Measured memory_bytes: 1024
N,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
DP = [1000000000]*N
DP[0] = 0
def handan(i,x):
    if DP[i] > x:
        DP[i] = x
for i in range(1,N):
    for j in range(min(i,k)):
        x = DP[i-j-1] + abs(h[i]-h[i-j-1])
        handan(i,x)
print(DP[N-1])

Measured memory_bytes: 52704
// この問題をDPだと思いこんでいる精神異常者

#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
using ll = long long;
const ll INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N), add(N+1);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];

    for (int i = N-1; i >= 0; i--) {
        if ((A[i] + add[i+1]) % B[i] == 0) {
            add[i] = add[i+1];
        } else {
            add[i] = add[i+1] + B[i] - (A[i] + add[i+1]) % B[i];
        }
    }

    cout << add[0] << endl;

    return 0;
}

Measured memory_bytes: 2560
def main():
    from collections import defaultdict
    from operator import itemgetter

    n = int(input())
    s = [input() for _ in range(n)]

    d = defaultdict(int)
    for w in s:
        d[w] += 1

    mx = max(d.values())
    for key, cnt in sorted(d.items(), key=itemgetter(0)):
        if cnt != mx: continue
        print(key)


if __name__ == '__main__':
    main()


Measured memory_bytes: 48432
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long k = scan.nextLong();
		scan.close();
		if(k-a>0) {
			System.out.print("0 ");
			System.out.println((b-(k-a)>0)? b-(k-a):"0");
		}
		else System.out.println(a-k+" "+ b);

	}

}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if(a<=c&&c<=b){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MAX = 990000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
  int x,y;
  cin >> x >> y;
  if((x+y)%3!=0){
    cout << 0 << endl;
    return 0;
  }
  int k=(x+y)/3;
  x-=k;
  y-=k;
  COMinit();
  cout << COM(x+y,x) << endl;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

template< typename Data, typename T >
struct ReRooting {
 
  struct Node {
    int to, rev;
    Data data;
  };
 
  using F1 = function< T(T, T) >;
  using F2 = function< T(T, Data) >;
 
  vector< vector< Node > > g;
  vector< vector< T > > ldp, rdp;
  vector< int > lptr, rptr;
  const F1 f1;
  const F2 f2;
  const T ident;
 
  ReRooting(int n, const F1 &f1, const F2 &f2, const T &ident) :
      g(n), ldp(n), rdp(n), lptr(n), rptr(n), f1(f1), f2(f2), ident(ident) {}
 
  void add_edge(int u, int v, const Data &d) {
    g[u].emplace_back((Node) {v, (int) g[v].size(), d});
    g[v].emplace_back((Node) {u, (int) g[u].size() - 1, d});
  }
 
  void add_edge_bi(int u, int v, const Data &d, const Data &e) {
    g[u].emplace_back((Node) {v, (int) g[v].size(), d});
    g[v].emplace_back((Node) {u, (int) g[u].size() - 1, e});
  }
 
 
  T dfs(int idx, int par) {
 
    while(lptr[idx] != par && lptr[idx] < g[idx].size()) {
      auto &e = g[idx][lptr[idx]];
      ldp[idx][lptr[idx] + 1] = f1(ldp[idx][lptr[idx]], f2(dfs(e.to, e.rev), e.data));
      ++lptr[idx];
    }
    while(rptr[idx] != par && rptr[idx] >= 0) {
      auto &e = g[idx][rptr[idx]];
      rdp[idx][rptr[idx]] = f1(rdp[idx][rptr[idx] + 1], f2(dfs(e.to, e.rev), e.data));
      --rptr[idx];
    }
    if(par < 0) return rdp[idx][0];
    return f1(ldp[idx][par], rdp[idx][par + 1]);
  }
 
  vector< T > solve() {
    for(int i = 0; i < g.size(); i++) {
      ldp[i].assign(g[i].size() + 1, ident);
      rdp[i].assign(g[i].size() + 1, ident);
      lptr[i] = 0;
      rptr[i] = (int) g[i].size() - 1;
    }
    vector< T > ret;
    for(int i = 0; i < g.size(); i++) {
      ret.push_back(dfs(i, -1));
    }
    return ret;
  }
};

int main(void) {
  int64 N;
  cin >> N;
  vector<int64> d(N);
  REP(i, N) cin >> d[i];
  sort(all(d));
  int64 res = 0;
  res = d[N/2]-d[N/2-1];
  cout << res << endl;
}

Measured memory_bytes: 1024
data = [int(x) for x in input().split(' ')]
n, h = data[0], data[1]
maxa = 0
b = [0]*n
for i in range(n):
	data = [int(x) for x in input().split(' ')]
	b[i] = data[1]
	maxa = max(maxa, data[0])
answer = 0
b.sort()
b.reverse()
for bi in b:
	if bi >= maxa:
		h -= bi
		answer += 1
		if h <= 0:
			print(answer)
			exit()
answer += (h + maxa - 1) // maxa
print(answer)

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

typedef long long ll;
typedef long double ld;

#define MOD 1000000007


void solve() {
	string s, t; cin >> s >> t;
	int c = 0;
	for (int i = 0; i < (int) s.length(); i++ ) {
		if (s[i] != t[i]) c++;
	}
	
	cout << c << endl;
}

int t = 1;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	//freopen("data.in", "r", stdin);
	//cin >> t;
	while (t--) solve();
	return 0;
}


Measured memory_bytes: 3900
#include <bits/stdc++.h>
using namespace std;
#define d double
const int sa=101;
const int sb=1e5+1;
bool dp[sb];
bool solve(vector<int>& picks,int n,int stone){
    for(int i=1;i<=stone;++i){
        for(int j=1;j<=n;++j){
            if(picks[j]>i)
                continue;
            if(dp[i-picks[j]]==0)
                dp[i]=1;
        }
    }
    return dp[stone];
}   

int main() {
	int n=0;cin>>n;int stone=0;cin>>stone;
    for(int i=0;i<sb;++i)
        dp[i]=false;
    vector<int> picks(n+1,0);
    for(int i=1;i<=n;++i)
        cin>>picks[i];
    bool ans=solve(picks,n,stone);
    if(ans)
        cout<<"First\n";
    else
        cout<<"Second\n";
    return 0;
}


Measured memory_bytes: 384
gets.to_i.times do 
  arr = gets.split.map{|x| x.to_i}
  pipe = [0,0]
  flag = false
  arr.each do |i|
    if pipe[0] < i then
      pipe[0] = i
    elsif pipe[1] < i then
      pipe[1] = i
    else
      flag = true
      break;
    end
    pipe.sort!{|a,b| b<=>a}
  end
  if flag then
    puts 'NO'
    next
  else
    puts 'YES'
  end
end

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<long long> a(m);
  for(int i=0; i<m;i++){
    cin >> a.at(i);
  }
  cout << max(n-accumulate(a.begin(),a.end(),0LL),(long long)-1);
}


Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#define PI 3.141592653589
typedef long long ll;
const int MOD = 1000000007;
const int INF = 2002002002;
const int di[] = { -1, 0, 1, 0 };
const int dj[] = { 0, -1, 0, 1 };
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> d(k);
	int a[101][101];
	vector<int> snk(n + 1, 0);
	for (int i = 0; i < k; i++) {
		cin >> d[i];
		for (int j = 0; j < d[i]; j++) {
			cin >> a[i][j];
			snk[a[i][j]]++;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		if (snk[i] == 0)
			ans++;
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main() {
    long l, r;
    cin >> l >> r;
    long ans;
    if (r - l > 2019) {
        ans = 0;
    } else {
        vector<long> x;
        for (long a = l; a <= r; ++a) {
            x.push_back(a%2019);
        }
        ans = 2019;
        for (int i = 0; i < x.size()-1; ++i) {
            for (int j = i+1; j < x.size(); ++j) {
                if (ans > (x[i]*x[j])%2019) {
                    ans = (x[i]*x[j])%2019;
                }
            }
        }
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s = list(input())
s.append(" ")
n = len(s)
i = 0
ans = []
j = 1
while i<n-1:
    if s[i]==s[i+1]:
        i+=1
        j+=1
    else:
        ans.append([s[i],j])
        i+=1
        j =1
m = len(ans)
answer = 0
i = 0
while i<m:
    if i==m-1:
        x = ans[i][1]*(ans[i][1]+1)
        x = x//2
        answer +=x
        break
    
    if ans[i][0]=="<" and ans[i][1]>=ans[i+1][1]:
        x = ans[i][1]*(ans[i][1]+1)
        x = x//2
        answer +=x 
        y = ans[i+1][1]*(ans[i+1][1]-1)
        y = y//2
        answer +=y
        i+=2
    elif ans[i][0]=="<" and ans[i][1]<ans[i+1][1]:
        x = ans[i][1]*(ans[i][1]-1)
        x = x//2
        answer+=x
        y = ans[i+1][1]*(ans[i+1][1]+1)
        y = y//2
        answer +=y
        i +=2
    else:
        x = ans[i][1]*(ans[i][1]+1)
        x = x//2
        answer +=x
        i+=1
print(answer)

Measured memory_bytes: 106300
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static int getInt(){
		return Integer.parseInt(s.next());
	}
	static IntStream REPS(int r){
		return IntStream.range(0,r);
	}
	static IntStream REPS(int l,int r){
		return IntStream.rangeClosed(l,r);
	}
	static IntStream INTS(int l){
		return REPS(l).map(i->getInt());
	}
	public static void main(String[] __){
		int h=getInt(),w=getInt();
		for(int i=1;i<=h;i++)
			for(char c='A';c-'A'<w;c++)
				if(s.next().equals("snuke"))
					System.out.println(""+c+i);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;

using namespace std;

int ans = 0;

void visit(int n, int k, v2_bool graph, v_bool &seen)
{
    int check = 0;
    for(auto s : seen) { if(s) check++; }
    if(check == n) { ans++; }

    for(int i = 0; i < n; i++) {
        if(seen[i] == false && graph[k][i] == true) {
            seen[i] = true;
            visit(n, i, graph, seen);
            seen[i] = false;
        }
        if(seen[i] == false && graph[i][k] == true) {
            seen[i] = true;
            visit(n, i, graph, seen);
            seen[i] = false;
        }
    }
}

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

    v2_bool graph(n, v_bool(n, false));

    irep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a][b] = true;
    }
    
    v_bool seen(n, false); 
    seen[0] = true;
    visit(n, 0, graph, seen);

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define sz(x) ((int)(x).size())
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 2e5 + 5;



void solve()
{
    int n; cin >> n;
    int mx_sum = INT_MIN, mn_sum = INT_MAX, mx_dif = INT_MIN, mn_dif = INT_MAX;
    int ans = 0;
    FOR(i, 0, n)
    {
        int x, y; cin >> x >> y;
        if (x + y > mx_sum) mx_sum = x + y;
        if (x + y < mn_sum) mn_sum = x + y;
        if (x - y > mx_dif) mx_dif = x - y;
        if (x - y < mn_dif) mn_dif = x - y;
        ans = max({ ans, mx_sum - mn_sum, mx_dif - mn_dif });
    }
    cout << ans;
}


int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); //cout.tie(NULL);
    /*int tc; cin >> tc;
    while (tc--)*/
        solve();

    return 0;
}


Measured memory_bytes: 3640
/*
g++ -std=c++14 -O2 -Wall a.cpp -o a && a
*/

//  io
#include <iostream>
//#include <fstream> //http://www.cplusplus.com/reference/fstream/fstream/
//#include <cstdio>
#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
#include <limits>
//  util
#include <string>
#include <cstring>
#include <algorithm>
//#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
//#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <vector>
//#include <queue>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
//#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> arri;
typedef vector<float> arrf;
typedef pair<int, int> pairi;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

//int modadd(int a, int b) { return ((a += b) < mod) ? a : (a - mod); }
//int modmult(int a, int b) { return (int)((a * b) % mod) }

//file input routed to stdinout
/*
std::ifstream inFile("input.txt");
std::ofstream outFile("output.txt");
std::cin.rdbuf(inFile.rdbuf());
std::cout.rdbuf(outFile.rdbuf());
*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    double sum = 0;
    for (int i = 0; i < n; i++)
    {
        double aux;
        cin >> aux;

        sum += 1.0 / aux;
    }
    sum = 1.0 / sum;
    cout << setprecision(std::numeric_limits<long double>::digits10 + 1) << sum;
}


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

int main() {
	int sec, min, hour;
	cin >> sec;
	hour = sec / 3600;
	min = (sec % 3600) / 60;
	sec = sec % 60;
	
	cout << hour << ":" << min << ":" << sec << endl;
	return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
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;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll X,Y,A,B,C;
    cin>>X>>Y>>A>>B>>C;
    vector<ll> p(A),ps(A+1);
    vector<ll> q(B),qs(B+1);
    vector<ll> r(C),rs(C+1);
    rep(i,A) cin>>p[i];
    rep(i,B) cin>>q[i];
    rep(i,C) cin>>r[i];
    RSORT(p);
    RSORT(q);
    RSORT(r);
    rep(i,A) ps[i+1]+=ps[i]+p[i];
    rep(i,B) qs[i+1]+=qs[i]+q[i];
    rep(i,C) rs[i+1]+=rs[i]+r[i];
    ll ans=0;
    rep(i,X+1){
        ll c=X-i;
        if(c>C) continue;
        /*bis*/ ll low= 0 , high= C-c+1 ; // min-1, max+1
        while( abs(high-low)>1 ){ ll mid=(high+low)/2;
            bool ok=false;
            if(Y-mid>=0 and r[mid+c-1]>q[Y-mid]) ok=true;
            ( ok ? low : high ) = mid;
        }// okdir : ngdir
        ll buf=ps[i]+qs[Y-low]+rs[c+low];
        maxi(ans,buf);
    }
    cout<< ans <<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 4992
n,x,y = map(int, input().split())
a = [0] * (n-1)
for i in range(1,n):
    for j in range(i+1 ,n+1):
        d = min(j-i, 1 + abs(j-y) + abs(i-x)) - 1
        a[d] += 1
print(*a, sep="\n")


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

int cnt[5];

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

	for (int i = 0; i < 3; i++) {
		int x, y;
		cin >> x >> y;
		cnt[x]++; cnt[y]++;
		if (cnt[x] >= 3 || cnt[y] >= 3) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
}

Measured memory_bytes: 256
# include <cstdio>
# include <iostream>
# define R register int
# define mod 1000000007
# define ll long long

using namespace std;

const int maxn=100005;
int n;
ll t[maxn],x[maxn];
ll s=1,ans=0;

ll inv (int a,int b)
{
	ll s=1;
	while (b)
	{
		if(b&1) s=s*a%mod;
		a=1LL*a*a%mod;
		b=b>>1;
	}
	return s;
}

int main()
{
	cin>>n;
	for (R i=1;i<=n;++i) s=s*i%mod;
	for (R i=1;i<=n;++i)
		t[i]=(t[i-1]+s*inv(i,mod-2))%mod;
	for (R i=1;i<=n;++i)
	{
		scanf("%lld",&x[i]);
		ans=(ans+(t[i]+t[n-i+1]-s)%mod*x[i]%mod)%mod;
	}
	printf("%lld",((ans%mod)+mod)%mod);
	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

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

	vector<ll> v(n);

	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}

	ll ans = 0;
	ll MIN = 1e9;

	for (int i = 0; i < n; i++) {
		MIN =min(MIN, v[i]);
		if (MIN == v[i]) {
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LEN (100000)
#define NUM_MOD (1000000007L)

int main() {
  // read inputs
  int N;
  char cs[MAX_LEN + 1];
  scanf("%s", cs);
  N = strlen(cs);

  // solve
  long dpss[MAX_LEN + 1][4] = {};
  for (int i = 0; i <= N; i++) {
    dpss[i][0] = 1;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 4; j++) {
      dpss[i + 1][j] = dpss[i][j];
    }
    switch (cs[i]) {
      case 'A':
        dpss[i + 1][1] = (dpss[i][1] + dpss[i][0]) % NUM_MOD;
        break;
      case 'B':
        dpss[i + 1][2] = (dpss[i][2] + dpss[i][1]) % NUM_MOD;
        break;
      case 'C':
        dpss[i + 1][3] = (dpss[i][3] + dpss[i][2]) % NUM_MOD;
        break;
      case '?':
        for (int j = 0; j < 4; j++) {
          dpss[i + 1][j] =
              (3 * dpss[i][j] + (j > 0 ? dpss[i][j - 1] : 0)) % NUM_MOD;
        }
        break;
    }
    // printf("i = %d, c = %c\n", i, cs[i]);
    // for (int j = 0; j < 4; j++) {
    //   printf("%ld ", dpss[i + 1][j]);
    // }
    // printf("\n");
  }
  printf("%ld\n", dpss[N][3]);
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);i++)
#define FORE(x,arr) for(auto &x:arr)
#define FOR(i,a,n) for(int i=a;i<(int)(n);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;

ll fact[200001];
ll fact_inv[200001];
ll bin_pow(ll a,ll b,ll mod) {
    if(a==0) return 1;
    a%=mod;
    ll product=1;
    while(b>0) {
        if(b&1) {
            product *= a;
            product %= mod;
        }
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return product%mod;
}
void init_fact(ll max,ll mod) {
    fact[0]=1, fact_inv[0]=1;
    FOR(i,1,max) {
        fact[i]=(fact[i-1]*i)%mod;
        fact_inv[i]=bin_pow(fact[i],mod-2,mod);
    }
}
ll nCr_mod(ll n,ll r,ll mod) {
    ll ret = fact[n] * fact_inv[r] % mod*fact_inv[n-r] % mod;
    return ret;
}

int main(int argc, char const *argv[]) {
    const int MOD=1e9+7;
    ll H,W,A,B;
    cin>>H>>W>>A>>B;
    init_fact(H+W,MOD);

    ll ans = 0;
    FOR(x,B,W) {
        // a = (x+H-A-1)C(x)
        // b = (A-1+W-x-1)C(A-1)
        ans += (nCr_mod(x+H-A-1,x,MOD)*nCr_mod(A+W-x-2,A-1,MOD))%MOD;
        ans %= MOD;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    ll N, X, D;
    cin >> N >> X >> D;
    if(D == 0 && X == 0) {cout << 1 << endl; return 0;}
    elif(D == 0) {cout << N+1 << endl; return 0;}
    elif(X == 0) {cout << N*(N-1)/2 + 1 << endl; return 0;}
    ll n = 0;
    rep(i, N+1){
        n++;
        if(n*abs(X)%abs(D) == 0) break;
    }
    ll step = n*X/D;
    priority_queue<pll, vector<pll>, greater<pll> > que[n];
    rep(i, N+1){
        ll j = i%n, k = step*(i/n);
        ll l = i*(i-1)/2, r = i*(2*N-i-1)/2;
        que[j].push(pll(k+l, k+r));
    }
    ll ans = 0;
    rep(i, n){
        ll pos = -INF;
        while(!que[i].empty()){
            pll p = que[i].top();
            que[i].pop();
            ll l = p.first, r = p.second;
            if(l > pos){
                ans += r-l+1;
                pos = r;
            }
            elif(r > pos){
                ans += r-pos;
                pos = r;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

int N;
ll T[100010], A[100010];
ll P[100010], Q[100010], R[100010], S[100010];

signed main(){
    cin >> N;
    REP(i, N) cin >> T[i];
    REP(i, N) cin >> A[i];
    ll m = 0;
    REP(i, N){
        if(m < T[i]){
            P[i] = Q[i] = T[i];
            m = T[i];
        }else{
            P[i] = 1; Q[i] = m; 
        }
    }
    m = 0;
    for(int i = N - 1; i >= 0; i--){
        if(m < A[i]){
            R[i] = S[i] = A[i];
            m = A[i];
        }else{
            R[i] = 1; S[i] = m;
        }
    }
    ll ans = 1;
    REP(i, N){
        ans *= max(0LL, min(Q[i], S[i]) - max(P[i], R[i]) + 1);
        ans %= MOD;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 4992
import itertools

n,m = map(int,input().split())
li = [[0 for _ in range(n)] for _ in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    a-=1
    b-=1
    li[a][b] = 1
    li[b][a] = 1

num = [i for i in range(1,n)]
ans = 0


for v in itertools.permutations(num):
    bre = False
    if li[0][v[0]] == 0:
        continue
    for i in range(len(v)-1):
        if li[v[i]][v[i+1]] == 0:
            bre = True
            break
    if bre:
        continue
    else:
        ans += 1
print(ans)






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

#define ll long long 

using namespace std;

int n;
int t,deadline;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    vector < pair<int,int> > v;
    for (int i=0; i<n; i++){
        cin>>t>>deadline;
        v.push_back({deadline,t});
    }
    sort(v.begin(),v.end());
    
    int r=0;
    
    for (int i=0; i<v.size(); i++){
        if(r+v[i].second<=v[i].first) r+=v[i].second;
        else {
            return cout<<"No",0;
        }
    }
    cout<<"Yes";
    
    return 0;
}

Measured memory_bytes: 2420
#include <stdio.h>
int main()
{
   int a, b, s, l;

   scanf("%d", &a);
   scanf("%d", &b);

   if (a >= 1 && b <= 100){
      s = a * b;
      l = a * 2 + b * 2;
      printf("%d %d\n", s, l);
   }
   return 0;
}

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

int main()
{

        int Q, H, S, D;
        cin >> Q >> H >> S >> D;
        long long N;
        cin >> N;
        long long n = N * 8;

        int q_min = Q;
        int h_min = 0;
        if (Q*2 < H) {
                h_min = Q*2;
        }
        else {
                h_min = H;
        }
        int s_min = 0;
        if (Q*4 < H*2) {
                s_min = Q*4;
        }
        else {
                s_min = H*2;
        }
        if (s_min > S) {
                s_min = S;
        }
        int d_min = D;
        if (D > Q*8) {
                d_min = Q*8;
        }
        if (d_min > H*4) {
                d_min = H*4;
        }
        if (d_min > S*2) {
                d_min = S*2;
        }
//      cout << "n= " << n << endl;
//      cout << "q_min= " << q_min << endl;
//      cout << "h_min= " << h_min << endl;
//      cout << "s_min= " << s_min << endl;
//      cout << "d_min= " << d_min << endl;

        long long ans = 0;

        long long  dd = n/16;
        long long dda = n % 16;
        long long  ss = dda / 8;
        long long ssa = dda % 8;
        long long  hh = ssa / 2;
        long long  hha = ssa % 2;
        long long  qq = hha / 1;
        ans = dd * d_min + (ss * s_min) + (hh * h_min) + (qq * q_min);
        cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>

int main () {
    ll a , b , c ;
    cin >> a >> b >> c ;
    ll temp ;
    temp = a ;
    a = b ;
    b = temp ;
    temp = a ;
    a = c ;
    c = temp ;
    cout << a <<" "<< b <<" "<< c << endl ;

    

    return 0 ;
}

 


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

#define int long long
#define all(V) (V).begin(),(V).end()
#define umap unordered_map
#define uset unordered_set
#define br cout<<"\n";

const int MAXN=1e5+10, MOD=1e9+7;
int n,m;
int arr[MAXN];
int t[5*MAXN],lazy[5*MAXN];

int doit(int a,int b){
	return min(a,b);
}

void build(int start,int end,int index=1){
	if(start==end){
		t[index]=INT_MAX;
		return ;
	}
	int mid = start+end >> 1;
	build(start,mid,index << 1);
	build(mid+1,end,index<<1|1);
	t[index] = doit(t[index<<1], t[index<<1|1]);
}
int pQuery(int start,int end,int l,int r,int index=1){
	// out range
	if(r<start or end<l){
		return INT_MAX;
	}
	// in Raange
	if( l<=start and end<=r){
		return t[index];
	}
	int mid = start+end >>1;
	return doit(pQuery(start,mid,l,r,index<<1), pQuery(mid+1,end,l,r,index<<1|1));
}

void pUpdate(int start,int end,int point,int val,int index=1){
	if(start==end){
		t[index]=val;
		return ;
	}
	int mid = start+end>>1;
	if(point <= mid){
		pUpdate(start,mid,point,val,index<<1);
	}
	else{
		pUpdate(mid+1,end,point,val,index<<1|1);
	}
	t[index] = doit(t[index <<  1] , t[index << 1 | 1]);
}




signed main()
{
// 	#ifndef ONLINE_JUDGE
// 		freopen("./input.txt","r",stdin);
// 		freopen("./output.txt","w",stdout);
// 	#endif
	ios::sync_with_stdio(false); cin.tie(nullptr);
	cin>>n>>m;
	build(0,n-1);
	for(int i=1; i<=m; i++){
		int q; cin>>q;
		int x,y; cin>>x>>y;
		if(q==1){
			cout<<pQuery(0,n-1,x,y,1); br;
		}
		else{
			pUpdate(0,n-1,x,y,1);
		}
	}	

}


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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

#define size(v) v.size()

template <class U, class C> struct ssp {
  struct edge {
    int to;
    U cap;
    C cost;
  };
  const U inf = numeric_limits<U>::max(), eps = 1e-10;
  int n, s, t;
  vector<edge> es;
  vector<vector<int>> g;
  vector<C> d;
  vector<int> pe;
  ssp(int _n, int _s, int _t) : n(_n), s(_s), t(_t), g(n), d(n), pe(n) {}
  void add(int from, int to, U cap, C cost) {
    g[from].push_back(size(es)), es.push_back({to, cap, cost});
    g[to].push_back(size(es)), es.push_back({from, 0, -cost});
  }
  bool spfa() {
    static vector<bool> in(n);
    static vector<int> que;
    fill(begin(d), end(d), numeric_limits<C>::max());
    que.clear();
    d[s] = 0, in[s] = true, que.push_back(s);
    for (int bg = 0; bg < (int)size(que); ) {
      int v = que[bg++];
      in[v] = false;
      for (int id : g[v]) {
        auto&& e = es[id];
        if (e.cap > eps and d[v] + e.cost < d[e.to]) {
          d[e.to] = d[v] + e.cost, pe[e.to] = id;
          if (not in[e.to]) in[e.to] = true, que.push_back(e.to);
        }
      }
    }
    return d[t] < numeric_limits<C>::max();
  }
  pair<U, C> min_cost_max_flow() {
    U flow = 0;
    C cost = 0;
    while (spfa()) {
      U df = inf;
      for (int v = t; v != s; v = es[pe[v] ^ 1].to) df = min(df, es[pe[v]].cap);
      for (int v = t; v != s; v = es[pe[v] ^ 1].to)
        es[pe[v]].cap -= df, es[pe[v] ^ 1].cap += df;
      flow += df, cost += df * d[t];
    }
    return {flow, cost};
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> x(m), y(m), s(m);
  for (int i = 0; i < m; ++i) {
    cin >> x[i] >> y[i] >> s[i];
    s[i] = -s[i];
  }
  auto f = [&](double l) {
    ssp<double, double> g(n + 2, n, n + 1);
    vector<double> b(n);
    b[0] = 1, b[n - 1] = -1;
    double off = 0;
    for (int i = 0; i < m; ++i) {
      b[x[i]] -= l;
      b[y[i]] += l;
      off += l * s[i];
      g.add(x[i], y[i], 1 - l, s[i]);
    }
    double sb = 0;
    for (int v = 0; v < n; ++v) {
      if (b[v] > g.eps) {
        g.add(g.s, v, b[v], 0);
        sb += b[v];
      } else if (b[v] < -g.eps) {
        g.add(v, g.t, -b[v], 0);
      }
    }
    double flow, cost;
    tie(flow, cost) = g.min_cost_max_flow();
    return flow + g.eps < sb ? 0 : -(off + cost);
  };
  double l = 1e-4;
  auto a = (f(0) - f(l)) / l;
  cout << (int)round(a) << '\n';
}



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

#define ll long long
#define ull unsigned long long
#define mod 1e9+7
#define INF 1 << 30
#define MAX (1 << 20)
#define NINF (-(1 << 30))
#define Point pair<int, int>
#define triplet pair<pair<int, int>, int>

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;

    cin >> n;

    vector<Point> vec(n);

    for (int i = 0; i < n; i++)
        cin >> vec[i].first >> vec[i].second;


    for (int i = 2; i < n; i++){
        if(vec[i].first == vec[i].second && vec[i-1].first == vec[i-1].second && vec[i-2].first == vec[i-2].second) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

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

using namespace std;

typedef vector <int> vi;
typedef vector <vi> vvi;

int A[100000];
vvi vex;

void dfs(int i) {
    A[i] = 1;
    for(int r : vex[i])
        if(!A[r]) dfs(r);
    
    return ;
}

int main() {
    int n, m; cin >> n >> m;
    vex.resize(n);
    int u, v, h;
    while(m--) {
        cin >> u >> v >> h;
        u -= 1; v -= 1;
        vex[u].push_back(v);
        vex[v].push_back(u);
    }
    
    int mx = 0;
    for(int i = 0; i < n; ++i)
        if(!A[i]) {
            mx += 1;
            dfs(i);
        }
    
    cout << mx;
    
    return 0;
}

Measured memory_bytes: 9216
from collections import Counter

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

b = Counter(A)

bnum = list(b.values())
ans = 0
for i in range(len(bnum)):
    ans = ans + bnum[i]*(bnum[i]-1)/2
    
    
for j in range(N):
    temp = b[A[j]]
    print(int(ans-temp+1))

Measured memory_bytes: 26908
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

bool is_palindrome(string S, int start, int end)
{
    rep (i, 0, end) {
        if (S.at(i) != S.at(end-i)) return false;
    }
    return true;
}

int main()
{
    string S; cin >> S;
    int N = S.length();

    bool flg1 = is_palindrome(S, 0, N-1);
    bool flg2 = is_palindrome(S, 0, (N-1)/2-1);
    bool flg3 = is_palindrome(S, (N+3)/2-1, N-1);

    if (flg1 and flg2 and flg3) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

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


int main() {
    string in;
    cin >> in;
    
    string a = "abcdefghijklmnopqrstuvwxyz";
    int pos = a.find(in);

    cout << a.at((pos + 1)%26) << endl;
}

Measured memory_bytes: 256
class Uf:
    def __init__(self, N):
        self.p = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N

    def root(self, x):
        if self.p[x] != x:
            self.p[x] = self.root(self.p[x])

        return self.p[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        u = self.root(x)
        v = self.root(y)

        if u == v: return

        if self.rank[u] < self.rank[v]:
            self.p[u] = v
            self.size[v] += self.size[u]
            self.size[u] = 0
        else:
            self.p[v] = u
            self.size[u] += self.size[v]
            self.size[v] = 0

            if self.rank[u] == self.rank[v]:
                self.rank[u] += 1

    def count(self, x):
        return self.size[self.root(x)]

from operator import itemgetter
from collections import defaultdict
from itertools import groupby
N = int(input())
XYI = []
for i in range(N):
    x, y = map(int, input().split())
    XYI.append([x, y, i])
XYx = sorted(XYI, key=itemgetter(0))
XYy = sorted(XYI, key=itemgetter(1))

uf = Uf(N)
px = py = -1
for x, y, i in XYx:
    if px==x:
        uf.unite(i, pi)
    px, pi = x, i
for x, y, i in XYy:
    if py==y:
        uf.unite(i, pi)
    py, pi = y, i
ddx = defaultdict(set)
ddy = defaultdict(set)
for x, y, i in XYI:
    ddx[uf.root(i)].add(x)
    ddy[uf.root(i)].add(y)
ans = 0
for i in range(N):
    if i==uf.root(i):
        ans += len(ddx[i]) * len(ddy[i])
print(ans - N)


Measured memory_bytes: 109912
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	ll l, r, res=2020;
	cin>>l>>r;
	if(r-l>=2019) return cout<<0, 0;
	for(ll j=l;j<=r;j++){
		for(ll i=l;i<j;i++)
			res=min(res,(i*j)%2019);
	}
	cout<<res;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    long long n,ans=1,ans2=1;
    cin>>n;
    long long x;
    f(i,0,n){
        cin>>x;
        if(x%2==0){
            ans*=2;
        }
        else{
            ans*=1;
        }
        ans2*=3;
    }
    cout<<ans2-ans<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=1<<20;
const int mod=1e9+7;
inline int Add(int x,int y)
{
    return (x+=y)>=mod?x-mod:x;
}
int n,a[max_n];
vector<int> v[max_n];
int cnt[max_n];
int dp[max_n][2];
int solve(int x)
{
    dp[0][0]=1;dp[0][1]=1;
    for(int i=1;i<v[x].size();i++)
    {
        int c=cnt[v[x][i]-1]-cnt[v[x][i-1]];
        dp[i][0]=Add(dp[i-1][0],1ll*c*dp[i-1][1]%mod);
        dp[i][1]=Add(dp[i-1][1],dp[i][0]);
    }
    return dp[v[x].size()-1][1];
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    for(int i=1;i<=n;i++)a[i]^=a[i-1];
    for(int i=1;i<=n;i++)v[a[i]].push_back(i);
    for(int i=1;i<=n;i++)cnt[i]=cnt[i-1]+(a[i]==0);
    if(a[n])
    {
        solve(a[n]);
        int ans=dp[v[a[n]].size()-1][1];
        if(v[a[n]].size()>1)ans=Add(ans,mod-dp[v[a[n]].size()-2][1]);
        printf("%d\n",ans);
    }
    else
    {
        int ans=1;
        for(int i=1;i<=cnt[n]-1;i++)ans=Add(ans,ans);
        for(int i=1;i<max_n;i++)
        {
            if(!v[i].empty())ans=Add(ans,solve(i));
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 38516
#pragma GCC optimize (2)
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
struct node{int to, nxt;}edge[N];
int head[N], deg[N], rnk[N], cnt=0, tot=0;
queue<int> q;

inline int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}

void add(int u, int v)
{
	edge[++cnt]=(node){v, head[u]};
	head[u]=cnt;
}

int main()
{
	int n=read(), m=read();
	for (int i=1; i<=n+m-1; i++) 
	{
		int u=read(), v=read();
		add(v, u); deg[u]++;
	}
	for (int i=1; i<=n; i++) if (!deg[i]) q.push(i);
	while (!q.empty())
	{
		int u=q.front(); q.pop(); rnk[u]=++tot;
		for (int i=head[u]; i; i=edge[i].nxt)
		{
			int v=edge[i].to;
			if (!(--deg[v])) q.push(v);
		}
	}
	for (int u=1; u<=n; u++) 
	{
		int ans=0, mn=N;
		for (int i=head[u]; i; i=edge[i].nxt)
		{
			int v=edge[i].to; 
			if (mn>rnk[v]) mn=rnk[v], ans=v;
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2816
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long K = sc.nextInt();
        long N = 0;
        long ans = -1;
        if(K%7==0) K/=7;
        N = 0;
        for(long i=1; i<=K && ans == -1; i++ ) {
            N = (N*10+1)%K;
            if (N == 0){
                ans = i;
                break;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35476
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;


int main(){
    ll n;
    cin>>n;
    vector<ll> a;
    for(int i=0;i<n;i++){
        ll b;
        cin>>b;
        a.push_back(b);
    }
    vector<ll> dp(n+1,0);
    for(int i=0;i<n;i++){
        dp[a[i]]=dp[a[i]-1]+1;
    }
    ll mx=0;
    for(int i=0;i<=n;i++){
        mx=max(mx,dp[i]);
    }
    cout<<n-mx<<endl;
    
    
    return 0;
}



Measured memory_bytes: 3440