akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return (rand()<<16|rand())%x;
}
const int N=100005,mod=4000007;
int n,father[N];
queue<PI> q;
ll ycl[N];
vector<int> v[N];
struct has_table{
	bool has[mod]; int b[mod];
	ll a[mod],v[mod];
	inline void insert(int xx,int yy,int jb){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				has[i]=1; a[i]=x; b[i]+=jb; return;
			}
		}
	}
	inline void clear(int xx,int yy){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				has[i]=1; a[i]=x; b[i]=0; return;
			}
		}
	}
	inline int find(int xx,int yy){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				return b[i];
			}
		}
	}
}Ma;
inline int getfather(int x){
	return father[x]==x?x:father[x]=getfather(father[x]);
}
int main(){
	srand(time(0));
	n=read();
	for(int i=1;i<=n;i++)ycl[i]=(ll)rand()<<32|rand();
    for(int i=1;i<=n*2-2;i++){
        int x=read(),y=read(); 
        v[x].push_back(y); v[y].push_back(x);
        Ma.insert(x,y,1); Ma.insert(y,x,1);
        if(Ma.find(x,y)==2)q.push(mp(x,y));
    }
    for(int i=1;i<=n;i++)father[i]=i;
    while(!q.empty()){
    	int x=q.front().first,y=q.front().second; q.pop();
		x=getfather(x); y=getfather(y); if(x==y){continue; return 0;}
		if(v[x].size()<v[y].size()) swap(x,y); 
		//cout<<x<<" "<<y<<endl;
        for(unsigned i=0;i<v[y].size();i++){ 
            int to=v[y][i];
            //if(y!=3||to!=3)cout<<x<<" "<<y<<" "<<to<<" "<<er.find(y,to)<<endl;
            v[to].push_back(x);
            Ma.insert(to,x,1); Ma.insert(x,to,1);
            if(Ma.find(to,x)==2)q.push(mp(to,x));
            v[x].push_back(to);
        }
        father[y]=x; v[y].clear();
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans+=father[i]==i;
    if(ans==1) puts("YES"); else puts("NO");
    return 0;
}

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

/*
   AtCoder contest
   coder : yoichidon
 */
import java.util.*;
import java.io.*;

class Mod{
    static final int MOD = 1000_000_007;
    static final long[] fact = makeFactorialArray(1000000);
    static final long[] factInv = makeInversedArray(fact);

    public static long add(long a, long b){
        long tmp = (a+b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long sub(long a, long b){
        return add(a,-b);
    }
    public static long mult(long a, long b){
        long tmp = (a*b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long power(long a, long x){ //calculate a^x
        if(x<0)return 0;
        if(x==0)return 1;
        if(x%2==0) {
            long half = power(a,x/2);
            return mult(half,half);
        }
        return (a*power(a,x-1)) % MOD;
    }
    public static long inverse(long a){
        return power(a,MOD-2);
    }
    public static long div(long a, long b){
        return mult(a, inverse(b));
    }
    public static long[] makeFactorialArray(int size){
        long[] array = new long[size];
        array[0]=1;
        for(int i=1;i<size;i++){
            array[i]=mult(array[i-1],i);
        }
        return array;
    }
    public static long[] makeInversedArray(long[] original){
        long[] array = new long[original.length];
        for(int i=0;i<original.length;i++){
            array[i] = inverse(original[i]);
        }
        return array;
    }
    public static long combination(int n, int r){
        if(n<0 || r<0 || n<r) return 0;
        return mult(fact[n], mult(factInv[r],factInv[n-r]));
    }
    public static long gcd(long a, long b){
        if(a<b) return gcd(b,a);
        if(b==0) return a;
        if(a%b==0) return b;
        return gcd(b,a%b);
    }
    public static long lcm(long a, long b){
        return (a/gcd(a,b))*b;
    }

}

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long ans = sc.nextLong();
        for(int n=1; n<N; n++){
            ans = Mod.gcd(ans, sc.nextLong());
        }
        System.out.println(ans);


    }
}


Measured memory_bytes: 70296
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 100000000000000000; // = 10^17
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7
//前処理テーブルの大きさ指定
const int MAX = 1200000; // = 10^6 + 2*(10^5)
//ちなみに、1024MBで持てる最大長の配列は10^8程度

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる。
  ll cost; // e.costでその辺の重みにアクセスできる。
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける。
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す。
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す。
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}

//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  ll ans = 1;
  vector<int> M(N + 1, 0);
  M.at(0) = 3;
  for (int i = 0; i < N; i++) {
    ans *= (M.at(A.at(i)) - M.at(A.at(i) + 1));
    M.at(A.at(i) + 1)++;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int a, b;
  cin >> a >> b;
  cout << (a-1) * (b-1) << endl; 
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i, n) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    rep(i, n) {
        if (a[i] != b[0]) {
            cout << b[0] << endl;
        } else {
            cout << b[1] << endl;
        }
    }
    return 0;
}

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

// input
string S;


void input() {
    cin >> S;
}


int main() {
    input();
    S[3] = '8';
    cout << S << endl;
}


Measured memory_bytes: 3536
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
string s;
int sum;
int ans;
int main(void) {
    cin >> s;
    ans = 999;
    for (int i = 0; i < s.size() - 2; ++i) {
        sum = 100 * (s.at(i) - '0') + 10 * (s.at(i + 1) - '0') + (s.at(i + 2) - '0');
        ans = min(ans, abs(753 - sum));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define HAIRETU(N,A) for(int i=0;i<N;i++) cin >>A[i]
using namespace std;

int findSumOfDigits(int n){
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int N;
    cin >> N;
    
    int a;
    a=findSumOfDigits(N);
    if (N % a == 0) {
        cout << "Yes" << endl;
    } else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

const int MOD = 1000000007;

class Prime {
  ll _size;
  vector<ll> _min;

 public:
  Prime(ll size) {
    _size = size;
    _min.resize(size);

    for (ll i = 2; i < _size; i++) {
      ll cur = i * 2;
      for (;;) {
        if (cur >= _size) {
          break;
        }
        if (_min[cur] != 0) {
          cur += i;
          continue;
        }
        _min[cur] = i;
      }
    }
  }

  void show() {
    for (ll i = 0; i <= 36; i++) {
      cout << i << ":" << _min[i] << endl;
    }
  }

  vector<ll> v(ll num) {
    vector<ll> result;
    for (;;) {
      ll v = _min[num];
      if (v == 0) {
        result.emplace_back(num);
        break;
      }
      num /= v;
      result.emplace_back(v);
    }
    return result;
  }

  map<ll, ll> m(ll num) {
    map<ll, ll> result;
    for (;;) {
      ll v = _min[num];
      if (v == 0) {
        result[num] += 1;
        break;
      }
      num /= v;
      result[v] += 1;
    }
    return result;
  }
};

void calc_cmul(map<ll, ll> &cmul, map<ll, ll> &primes) {
  for (auto e : primes) {
    ll num = e.first;
    ll count = e.second;

    if (cmul[num] < count) {
      cmul[num] = count;
    }
  }
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) {
    u += m;
  }
  return u;
}

int main() {
  Prime prime(1000005);

  map<ll, ll> cmul;
  ll n;
  scanf("%lld", &n);

  vector<map<ll, ll>> alist(n);
  for (ll i = 0; i < n; i++) {
    ll a;
    scanf("%lld", &a);

    auto primes = prime.m(a);
    calc_cmul(cmul, primes);

    alist[i] = primes;
  }

  ll ans = 0;
  ll sum = 1;

  for (auto e : cmul) {
    for (ll i = 0; i < e.second; i++) {
      sum = (sum * e.first) % MOD;
    }
  }
  for (ll i = 0; i < n; i++) {
    ll val = sum;
    auto primes = alist[i];

    for (auto e : primes) {
      for (ll i = 0; i < e.second; i++) {
        val = val * modinv(e.first, MOD) % MOD;
      }
    }
    ans = (ans + val) % MOD;
  }

  // for (ll i = 0; i < n; i++) {
  //   auto primes = alist[i];

  //   ll val = 1;
  //   for (auto e : cmul) {
  //     ll count = e.second - primes[e.first];
  //     for (ll j = 0; j < count; j++) {
  //       val = (val * e.first) % MOD;
  //     }
  //   }

  //   sum = (sum + val) % MOD;
  // }

  cout << ans << endl;
}


Measured memory_bytes: 11648
#include<stdio.h>
int main(void)
{
	int n,t,a,h[100000],i,min,x,y;
	min=1000000;
	y=0;
	scanf("%d",&n);
	scanf("%d %d",&t,&a);
	for(i=1;i<=n;i++){
		scanf("%d",&h[i]);
		h[i]=t*1000-h[i]*6;
	}
	for(i=1;i<=n;i++){
		x=h[i]-a*1000;
		if(x<0){
			x*=-1;
		}
		if(min>x){
			min=x;
			y=i;
		}
		x=0;
	}
	printf("%d\n",y);
	return 0;
}


Measured memory_bytes: 128
/*
*	author:		richardjcy
*	created:	2020/09/26/08:07.13
*/

#include <bits/stdc++.h>
using namespace std;



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

    int n, k;
    cin >> n >> k;
    long double ans = 0.0;
    for (int i = 1; i <= min(n, k - 1); i++)
    {
        int idx = ceil(log2(k / (i + 0.0)));
        long double tmp = pow(0.5, idx);
        tmp /= (n + 0.0);
        ans += tmp;
    }
    ans += max(0.0, (n - k + 1) / (n + 0.0));
    cout << setprecision(15) << ans << endl;
    return 0;
}

Measured memory_bytes: 4180
def find_lcd(A,B):
  if A==1 or B==1:
    return 1
  if A==B:
    return A
  else:
    return find_lcd(min(A,B), abs(A-B))
  
def find_num_prime(X):
  if X==1:
    return 1
  count = 1 # 1
  i=2
  sqrt_org=int(X**0.5)
  while X != 1:
    if i**2 > X:
      count += 1
      break
    if X%i == 0:
      count += 1
      while X%i == 0:
        #print(str(X)+' '+str(i))
        X = int(X/i)
    if i== 2:
      i += 1
    else:
      i += 2
  return count
  
A,B = map(int, input().split())
lcd=find_lcd(A,B)
#print(lcd)
print(find_num_prime(lcd))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dir[4][2]={1,0,0,1,-1,0,0,-1};
int qpow(int a,int b)
{
    int ret=1;
    while(b!=0)
    {
        if(b&1)
            ret*=a;
        a*=a;
        b>>=1;
    }
    return ret;
}
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    int n;
    cin>>n;
    int x=n,len=0,ans=0;
    while(x!=0)
    {
        x/=10;
        len++;
    }
    for(int i=1;i<len;i+=2)
    {
        ans+=9*qpow(10,i-1);
    }
    if(len&1)
        ans+=n-qpow(10,len-1)+1;
    cout<<ans;
	return 0;
}


Measured memory_bytes: 256
import random

def calc_score(D, C, S, T):
    score = 0
    last = [0]*26
    for d in range(D):
        t = T[d] - 1
        score += S[d][t]
        last[t] = d + 1
        for i in range(26):
            score -= C[i]*(d + 1 - last[i])
    return score

def main():
    D = int(input())
    C = list(map(int, input().split()))
    S = []
    for i in range(D):
        S.append(list(map(int, input().split())))

    sorted_scores = []
    for i in range(D):
        scores = [(j, S[i][j]) for j in range(26)]
        sorted_scores.append(sorted(scores, key=lambda x: x[1], reverse=True))
    # print(sorted_scores)
    sorted_c = []
    sorted_c = [(i, C[i]) for i in range(26)]
    sorted_c.sort(key=lambda x: x[1], reverse=True)
    # print(sorted_c)
    last = [0]*26
    ans = []
    for d in range(D):
        score = -100*365*365
        t = 0
        for i in range(26):
            tmp = S[d][i]
            for j in range(26):
                if i != j:
                    tmp -= C[j]*(d + 1 - last[j])
            if tmp > score:
                score = tmp
                t = i + 1
        last[t - 1] = d + 1
        ans.append(t)
    score = calc_score(D, C, S, ans)

    # try to reduce penalty
    for i in range((10**3)*6):
        d = random.randint(0, D - 1)
        t = random.randint(0, 12)
        org_t = ans[d]
        ans[d] = sorted_c[t][0] + 1
        s = calc_score(D, C, S, ans)
        if s <= score:
            ans[d] = org_t
        else:
            score = s

    # try to increase score
    for i in range((10**3)*6):
        d = random.randint(0, D - 1)
        t = random.randint(0, 12)
        org_t = ans[d]
        ans[d] = sorted_scores[d][t][0] + 1
        s = calc_score(D, C, S, ans)
        if s <= score:
            ans[d] = org_t
        else:
            score = s
    print('\n'.join(map(str, ans)))

if __name__ == '__main__':
    main()


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    for(int i=0;i<n;++i)cin>>a[i];
    for(int i=0;i<n;++i)cin>>b[i];
    for(int i=0;i<n-1;++i)cin>>c[i];
    int ans=0;
    int tmp=-5;
    for(int i=0;i<n;++i){
        ans+=b[a[i]-1];
        if(a[i]-tmp==1)ans+=c[tmp-1];
        tmp=a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{

    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int K = int.Parse(Console.ReadLine());
            double ans = double.MaxValue;
            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j <= N; j++)
                {
                    if(i + j ==N){
                        double obj = Math.Pow(2,i) + (K * j);
                        if (ans>obj)
                        {
                            ans = obj;
                        }
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
 
const int N = 1e5 + 5;
 
int n;
vector <int> G[N];
bool visited[N];
int dist[N];
char color[N];
 
void dfs1(int x, int d) {
    visited[x] = 1;
    color[x] = 'B';
    dist[x] = d;
 
    for(int y: G[x]) {
        if(!visited[y])
            dfs1(y, d + 1);
    }
}
 
void dfs2(int x, int d) {
    if(dist[x] <= d)
        return;
 
    visited[x] = 1;
    color[x] = 'W';
 
    for(int y: G[x]) {
        if(!visited[y])
            dfs2(y, d + 1);
    }
}
 
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n;
 
    for(int i = 1 ; i < n; i++)
    {
        int x, y;
        cin>>x>>y;
        G[x].pb(y);
        G[y].pb(x);
    }
 
    dfs1(1, 0);
    memset(visited, 0, sizeof(visited));
    dfs2(n, 0);
 
    int b = 0, w = 0;
    for(int i = 1; i <= n; i++)
    {
        if(i != 1 and color[i] == 'B')
            b++;
        if(i != n and color[i] == 'W')
            w++;
    }
 
    cout<<( b > w ? "Fennec" : "Snuke")<<"\n";
    return 0;
}

Measured memory_bytes: 9472
#include <iostream>
#include<cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
ll dp[105][105];
const ll INF = 0x3f3f3f3f;
int main()
{
    int n,i,m,j,a,b,k;
    scanf("%d",&n);
    for(i = 0;i < n;i++)
        for(j = 0;j < n;j++)
            dp[i][j] = INF;
    dp[0][0] = 0;
    for(j = 0;j < n;j++)
    {
        cin >> i >> m;
        while(m--)
        {
            cin >> a ;
            cin >> dp[i][a];
        }
    }
    for(k = 0;k < n;k++)
        for(i = 0;i < n;i++)
            for(j = 0;j < n;j++)
                dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
    for(i = 0;i < n;i++)
        cout << i << ' ' << dp[0][i] << endl;
    return 0;
}



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

int main() {
	int n; scanf("%d", &n);
	
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int a; scanf("%d", &a);
		
		while ((a & 1) == 0) {
			a /= 2;
			++ans;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  vector<int> mao(n);
  for (int i=0; i<n; i++) {
    cin>>mao.at(i);
  }
  
  int answer=0;
  int research =0;
  for (int i=0; i<n-1; i++) {
    if (mao.at(i) >= mao.at(i+1)) {
      research++;
      if (answer<research)
        answer = research;
    }
    
    else {
      if (answer<research)
        answer = research;
      
      research = 0;
    }
  }
  
  cout<< answer<<endl;
}


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

int main() { 
    int64_t n;
    cin >> n;
    vector<int64_t> a(n-1);
    vector<int64_t> b(n);
    for(int i = 0; i < n-1 ;i++){
        cin >> a.at(i);
        b.at(a.at(i) - 1)++;
    }
    for(int c : b){
        cout << c << endl;
    }
}

Measured memory_bytes: 6428
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
	vector<string> r;
	int n[5];
	while (scanf("%d,%d,%d,%d,%d",&n[0],&n[1],&n[2],&n[3],&n[4]) != EOF)
	{
		int two=0,three=0,four=0,straight=0;
		int hand[13]={0};
		for (int i=0; i<5; i++)
			hand[n[i]-1]++;
		for (int i=0; i<13; i++)
		{
			switch(hand[i])
			{
			case 4:
				four++;
				break;
			case 3:
				three++;
				break;
			case 2:
				two++;
				break;
			default:
				break;
			}
		}
		int count=0;
		for (int i=0; i<14; i++)
		{
			if (count>0)
			{
				if (hand[i%13] == 1)
				{
					count++;
				} else {
					count=0;
				}
				if (count == 5)
				{
					straight=1;
					break;
				}
			} else {
				if (hand[i%13] == 1)
				{
					count=1;
				} else if(hand[i%13]!=0) {
					break;
				}
			}
		}
		string handname;
		if (four == 1) {
			handname = "four card";
		} else if (three == 1 && two == 1) {
			handname = "full house";
		} else if (straight == 1) {
			handname = "straight";
		} else if (three == 1) {
			handname = "three card";
		} else if (two == 2) {
			handname = "two pair";
		} else if (two == 1) {
			handname = "one pair";
		} else {
			handname = "null";
		}
		r.push_back(handname);
	}
	for (int i=0; i<r.size(); i++)
	{
		cout << r[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>

using namespace std;

int main(){
int n;
cin>>n;
vector<int> w(n);
vector<int> left(n);
vector<int> right(n);
for(int i=0;i<n;i++){
cin>>w[i];
}
left[0]=w[0];
right[n-1]=w[n-1];
for(int i=1;i<n;i++){
left[i]=left[i-1]+w[i];
right[n-1-i]=right[n-i]+w[n-1-i];
}
int min=100001;
for(int i=0;i<n;i++){
int tmp=left[i]-right[i+1];
if(tmp<0) tmp=-tmp;
if(min>tmp) min=tmp;
//printf("left[%d]=%d\n",i,left[i]);
//printf("right[%d]=%d\n",i,right[i]);
}
cout<<min<<endl;
return 0;
}

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

using namespace std;

using ll =  long long int;

#define int  long long int
#define mod  1000000007

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
            res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;
    
    cin >> n;
    
    vector<pair<int,int>> a(n);
    
    int m1 = 0;
    int m2 = 1e10;
    int m3 = -1e10;
    int m4 = 1e10;
    
    for(int i = 0; i < n; ++i) {
    	cin >> a[i].first >> a[i].second;
    	
    	int x = a[i].first;
    	int y = a[i].second;
    	
    	m1 = max(m1 , x+y);
    	m2 = min(m2 , x+y);
    	m3 = max(m3 , x-y);
    	m4 = min(m4 , x-y);
    }
    
    cout << max({abs(m1 - m2) , abs(m3 - m4)});
    
  
    return 0;
}

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

int main()
{
	int n; string s;
	cin >> n >> s;
	ll r=0,g=0,b=0;
	for (auto c : s)
	{
		if (c == 'R') r++;
		else if (c == 'G') g++;
		else b++;
	}
	ll all = r*g*b;
	ll minus=0;
	for (int i=0; i<n; i++)
		for (int j=i+1; j<n; j++)
		{
			if (s[i] == s[j]) continue;
			ll k = j*2-i;
			if (k >= n || s[k] == s[i] || s[k] == s[j])
				continue;
			minus++;
		}
	cout<<all-minus<<"\n";

	return 0;
}

Measured memory_bytes: 3628
// ABC142 B

#include <bits/stdc++.h>
#define RI register int
typedef long long LL;


using namespace std;

int main() {

  int n; cin >> n;
  int m; cin >> m;
  int ans = 0;
  for (RI i = 1, x; i <= n; ++i)
    cin >> x, ans += (x >= m);
  cout << ans;

  return 0;
}

// created by Daniel yuan

Measured memory_bytes: 384
A,B,C=map(int,input().split())

if A==B==C and A%2==0:
    print(-1)
else:
    K=0
    while (A%2)+(B%2)+(C%2)==0:
        A,B,C=(B+C)//2,(C+A)//2,(A+B)//2
        K+=1
    print(K)


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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int t = n;
  int sum = 0;
  while (t) {
    sum += t % 10;
    t /= 10;
  }
  if (sum == 1) {
    cout << 10 << endl;
  } else {
    cout << sum << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;


int main(){
	const long long INF = 1ll << 60;
  	int n,k; cin >> n >> k;
  	long long h[100010];
    for ( int i = 0 ; i < n ; i++ ) cin >> h[i];
  
	long long dp[100010];
    for ( int i = 0 ; i < 100010; i++ ) dp[i]=INF;

    dp[0] = 0;
    for ( int i = 0 ; i < n ; i++ ){
        for ( int j = 1 ; j <= k ; j++ ){
            if(i+j<n)dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

//????????????.
void swap(int *x, int *y);

//??????????????????????????°?????????.
int bubbleSort(int *a, int n);

int main(void) {
	int i = 0;

	int n = 0;		//?????????????´???°.
	int a[100] = {};//??????.

	int ex = 0;		//???????????°.

	scanf("%d", &n);

	for(i = 0; i < n; i++)
		scanf("%d", &a[i]);

	ex = bubbleSort(a, n);

	for (i = 0; i < n; i++) {
		if (i != n - 1)
			printf("%d ", a[i]);
		else
			printf("%d\n%d\n", a[i], ex);
	}

	return 0;
}

void swap(int *x, int *y) {
	int tmp = 0;

	tmp = *x;
	*x = *y;
	*y = tmp;
}

int bubbleSort(int *a, int n) {
	int ex = 0;		//???????????°.
	int j = 0;
	int flag = 1;	//????????£??\????´?????????¨??????.

	while (flag) {
		flag = 0;
		for (j = n - 1; j > 0; j--) {
			if (a[j] < a[j - 1]) {
				swap(&a[j], &a[j - 1]);
				flag = 1;
				ex++;
			}
		}
	}

	return ex;
}

Measured memory_bytes: 600
num1 = int(input())

while(num1 >= 0):
  if num1 < 1200:
    print(f"ABC")
  elif num1 >= 1200 and num1 < 2800:
    print(f"ARC")
  elif num1 >= 2800 and num1 <= 4208:
    print(f"AGC")
  break


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

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

  string s, t;
  cin >> s >> t;

  int ans = t.size();
  for (int i = 0; i + t.size() <= (int)s.size(); ++i) {
    int cur = 0;
    for (int j = 0; j < (int)t.size(); ++j) {
      if (s[i+j] != t[j]) ++cur;
    }
    ans = min(ans, cur);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3588
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
left=1
right=A[-1]
ans=(left+right)//2
if N==1:
    if A[0]%(K+1)==0:
        print(A[0]//(K+1))
    else:
        print(A[0]//(K+1)+1)
else:
    while 1:
        count=0
        for i in range(N)[::-1]:
            if A[i]%ans==0:
                count+=A[i]//ans-1
            else:
                count+=A[i]//ans
            if count>K:
                break
        if count<=K:
            right=ans
        else:
            left=ans
        if right-left<=1:
            break
        ans=(left+right)//2
    for i in range(N):
        if A[i]%left==0:
            count+=A[i]//left-1
        else:
            count+=A[i]//left
        if count>K:
            break
    if count<=K:
        print(left)
    else:
        print(right)

Measured memory_bytes: 93720
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int A, B; cin >> A >> B;

    int K = (A + B) / 2;

    if (abs(A - K) == abs(B - K)) cout << K << endl;
    else cout << "IMPOSSIBLE" << endl;

    return 0;
}

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

int main()
{
  int n,k;
  cin>>n>>k;
  vector <int> h(n);
  for(int i=0;i<n;i++) cin>>h[i];
  vector <int> dp(n);
  dp[n-1]=0;
  for(int i=n-2;i>=0;i--)
  {
      dp[i]=dp[i+1]+abs(h[i]-h[i+1]);
      for(int j=i+2;j<min(i+1+k,n);j++)
      {
          dp[i]=min(abs(h[i]-h[j])+dp[j],dp[i]);
      }
  }

  cout<<dp[0];

  return 0;
}


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

using namespace std;
int n,a[100001],b[100001],c[100001],da[100001],db[100001],dc[100001],i,k,j,minim;
int main()
{
    cin>>n;

    for(i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    da[1]=a[1];
    db[1]=b[1];
    dc[1]=c[1];
    for(i=1;i<=n;i++)
    {
        da[i]=max(dc[i-1],db[i-1])+a[i];
         db[i]=max(dc[i-1],da[i-1])+b[i];
          dc[i]=max(da[i-1],db[i-1])+c[i];
    }
     cout<<max(max(da[n],db[n]),dc[n]);
    return 0;
}


Measured memory_bytes: 2560
using System;

class Program
{
  static void Main()
  {
    char[] data = { '#', '.' };
    short h, w, i, j;

    string[] vals;
    while (true)
    {
      vals = Console.ReadLine().Split(' ');
      h = short.Parse(vals[0]);
      w = short.Parse(vals[1]);
      if (h == 0 && w == 0) break;

      for (i = 0; i < h; i++)
      {
        for (j = 0; j < w; j++)
        {
          Console.Write("{0}", data[(i % 2) ^ (j % 2)]);
        }
        Console.WriteLine();
      }
      Console.WriteLine();
    }
  }
}

Measured memory_bytes: 8928
import java.util.*;

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

    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    int k=sc.nextInt();
    int max=Math.max(a,Math.max(b,c));
    System.out.println(a+b+c+(int)Math.pow(2,k)*max-max);
    sc.close();
  }
}



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

const ll INF = 1e18;
const int MX = 2005;

vector<int>H;
vector<vector<int>>G;
int n , m;

bool cal(int i){
  bool res = true;
  rep(j,G[i].size()){
    if(H[i] > H[G[i][j]]){
      continue;
    }else{
      res = false;
      break;
    }
  }
  return res;
}

int main() {
  ll cnt = 0;
  cin >> n >> m;
  H.resize(n);
  G.resize(n);
  rep(i,n){
    cin >> H[i];
  }
  rep(i,m){
    ll a,b;
    cin >> a >> b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }
  rep(i,n){
    if(cal(i)){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

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

#define rep(i,a,b)                for(ll i=a;i<b;i++)
#define re(i,b)                for(ll i=0;i<b;i++)
#define repr(i,n)                for(ll i=n-1;i>=0;i--)
#define ll long long
#define ld long double
#define pll std::pair<ll, ll> 
#define ppll std::pair<ll, pll>
#define vll std::vector<ll> 
#define vpll std::vector<pll> 
#define vppll std::vector<ppll> 
#define mll std::unordered_map<ll, ll> 
#define mpll std::unordered_map<pll, ll>
#define mppll std::unordered_map<ppll, ll>
#define sll std::set<ll>
#define ff first
#define ss second
#define msll std::multiset<ll>
#define all(c) c.begin(), c.end()
#define allr(c) c.rbegin(), c.rend()
#define srt(x) sort(all(x))
#define rsrt(x) sort(allr(x))
#define eb emplace_back
#define pb push_back
#define s(yy) ll yy;cin>>yy
#define len length()
#define sz size()
const ll mod = 1e9 + 7;
const ll INF = 0x7FFFFFFFFFFFFFFF>>1;

/*#################################################### 
#                                                    #
#                     @author                        #
#                  Parth Lathiya                     #
#      https://www.cse.iitb.ac.in/~parthiitb/        #
#                                                    #
####################################################*/

int a[10];

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	#ifdef PARTH_LATHIYA_HOME

		freopen("A_in.txt","r",stdin);

		ll ttt,bkkk;
		cin>>ttt;
		bkkk=ttt;
		while(ttt--) {
			cout<<"Testcase - "<<bkkk-ttt<<"\n";
	#endif

//--------------------------------------------------------------------------------------

	s(n);
	ll x=n%10;
	ll y=(n/10)%10;
	if( (y==x && (n/100)%10==x) || ((n/100)%10==y  && (n/1000)%10==y) )
		cout<<"Yes";
	else
		cout<<"No";
//--------------------------------------------------------------------------------------
	
	#ifdef PARTH_LATHIYA_HOME
		cout<<"\n"; }
	#endif

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{
    int a=0,w=0,t=0,r=0,i,n;
    scanf("%d ",&n);
    char S[10];
    for(i=0;i<n;i++)
    {
        fgets(S,sizeof(S),stdin);
        if(S[0]=='A')
        {
            a++;
        }
        else if(S[0]=='W')
        {
            w++;
        }
        else if(S[0]=='T')
        {
            t++;
        }
        else if(S[0]=='R')
        {
            r++;
        }
    }
    printf("AC x %d\n",a);
    printf("WA x %d\n",w);
    printf("TLE x %d\n",t);
    printf("RE x %d",r);

}

Measured memory_bytes: 1720
class RollingHash:

    def __init__(self, string, root, mod):
        self.root = root
        self.mod = mod
        self.hs = [0] * (len(string) + 1)
        self.pw = [1] * (len(string) + 1)
        for i in range(len(string)):
            self.hs[i + 1] = (self.hs[i] * self.root + ord(string[i])) % self.mod
            self.pw[i + 1] = self.pw[i] * self.root % self.mod

    def get_hash(self, l, r):
        "get the hash of s[l:r] (0 <= l <= r <= len(s))"
        return (self.hs[r] - self.hs[l] * self.pw[r - l]) % self.mod

    def __getitem__(self, index):
        if isinstance(index, slice):
            return self.get_hash(index.start, index.stop)
        else:
            return 0


RHMOD = (1 << 61) - 1
POSITIVIZER = RHMOD << 61
class RollingHashMOD61:
    """
    MOD == 2 ** 61 - 1
    参考: https://qiita.com/keymoon/items/11fac5627672a6d6a9f6
    """


    def __init__(self, string, root):
        self.root = root
        self.hs = [0] * (len(string) + 1)
        self.pw = [1] * (len(string) + 1)
        for i in range(len(string)):
            tmp = self.hs[i] * self.root + ord(string[i])
            self.hs[i + 1] = (tmp >> 61) + (tmp & RHMOD)
            tmp = self.pw[i] * self.root
            self.pw[i + 1] = (tmp >> 61) + (tmp & RHMOD)

    def get_hash(self, l, r):
        "get the hash of s[l:r] (0 <= l <= r <= len(s))"
        ret = (self.hs[r] - self.hs[l] * self.pw[r - l] + POSITIVIZER)
        ret = (ret >> 61) + (ret & RHMOD)
        if ret >= RHMOD:
            ret -= RHMOD
        assert 0 <= ret < RHMOD
        return ret

    def __getitem__(self, index):
        if isinstance(index, slice):
            return self.get_hash(index.start, index.stop)
        else:
            return 0
        
if __name__ == "__main__":
    N = int(input())
    S = input()

    MOD = 2 ** 61 - 1
    root = 10000

    rh = RollingHashMOD61(S, root)

    ok = 0
    ng = N
    while ng - ok > 1:
        mid = (ok + ng) // 2
        hashes = dict()
        flg = False
        for i in range(N - mid + 1):
            hashofsub = rh[i:i+mid]
            if hashofsub in hashes:
                if i >= hashes[hashofsub] + mid:
                    flg = True
                    break
            else:
                hashes[hashofsub] = i
        
        if flg:
            ok = mid
        else:
            ng = mid

    print(ok)


Measured memory_bytes: 76504
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();
		int tempx = x - k + 1;
		do {
			System.out.println(tempx);
			tempx++;
		} while(tempx <= x + k - 1);
	}
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
#define eoi ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
    eoi;
double a,b,c;
cin>>a>>b>>c;
double n=(a+b)/2;
cout<<n*c;


}







Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    H,W,A,B=MI()
    if H!=1 and W!=1:
        s=[[0]*W for _ in range(H)]
        for i in range(H):
            for j in range(W):
                if i<B and j<A:
                    s[i][j]=1
                elif i>=B and j>=A:
                    s[i][j]=1
                else:
                    pass
                
        for i in range(H):
            print(''.join(map(str, s[i])))
    else:
        if H==1:
            ans=([1]*A)+([0]*(W-A))
            print(''.join(map(str,ans)))
        else:
            for i in range(H):
                if i<B:
                    print(1)
                else:
                    print(0)
            

main()


Measured memory_bytes: 51548
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef long long int i64;
typedef pair<int, int> pint;

struct UnionFind {
    vector<int> data; int group;
    UnionFind(int N) : data(N, -1), group(N){}
    void clear(int N) { data = vector<int>(N, -1); group = N;}
    void unite(int x, int y) {
        x = root(x); y = root(y);
        if(x != y){
            data[x] += data[y];
            data[y] = x;
            --group;
        }
    }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]);}
    bool same(int a, int b) { return root(a) == root(b);}
};

struct Edge {
    int from, to, cost;
    Edge(int f, int t, int c)
         :from(f), to(t), cost(c){}
    bool operator < (const Edge& E) const {
        return cost < E.cost;
    }
};

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N, M;
    while(cin >> N >> M && N) {
        int a_, b_, w_;
        vector<Edge> edges;
        rep(i, M) {
            cin >> a_ >> b_ >> w_;
            --a_; --b_;
            edges.push_back(Edge(a_, b_, w_));
        }
        sort(edges.begin(), edges.end());
        UnionFind uf(N);
        int ans = INF;
        rep(start, M) {
            uf.clear(N);
            int mi = edges[start].cost, ma = 0;
            REP(i, start, M) {
                Edge e = edges[i];
                if(uf.same(e.from, e.to)) continue;
                uf.unite(e.from, e.to);
                ma = max(ma, e.cost);
            }
            if(uf.group != 1) break;
            ans = min(ans, ma - mi);
        }
        cout << (ans == INF ? -1 : ans) << endl;
    }
    return 0;
}

Measured memory_bytes: 1356
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10000005,M=5005,inf=0x3f3f3f3f,p=1000000007;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int qpow (int x,int k){
	int t=1;
	for (;k;k>>=1){
		if (k&1) t=(ll)t*x%p;
		x=(ll)x*x%p;
	}
	return t;
}
int n,m,fac[N],ifac[N],s[M][M],sum[M],f[M][M],g[M],ans;
void check(int &x,int y){if((x+=y)>=p) x-=p;}
int C(int n,int m){return (n<m) ? 0 : (ll)fac[n]*ifac[m]%p*ifac[n-m]%p;}
int P(int n,int m){return (n<m) ? 0 : (ll)fac[n]*ifac[n-m]%p;}
int main(){
//	freopen("a.in","r",stdin);
	n=read();m=read();
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=(ll)fac[i-1]*i%p;
	ifac[n]=qpow(fac[n],p-2);
	for (int i=n;i;i--) ifac[i-1]=(ll)ifac[i]*i%p;
	s[0][0]=sum[0]=1;
	for(int i=1;i<=m;i++)
	for(int j=1;j<=i;j++)
		s[i][j]=(s[i-1][j-1]+(ll)(i-1)*s[i-1][j])%p,check(sum[i],s[i][j]);

	f[0][0]=1;
	for (int i=0;i<=m;i++)
	for (int j=0;j<=i;j++){
		check(f[i][j],(ll)g[j]*ifac[m-i]%p);
		if (i!=0)
			check(ans,(ll)f[i][j]*P(n-m,j)%p*P(n-m-j+i-1,n-m-j)%p*sum[max(0,m-i-1)]%p);
		if (i!=m){
			check(f[i+1][j+1],f[i][j]);
			if (i!=0) check(g[j],(ll)f[i-1][j]*fac[m-(i-1)-1]%p);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 215496
n, m = map(int,input().split())
ac = [0]*(n+1)
wa = [0]*(n+1)

for i in range(m):
    p, s = map(str, input().split())
    p= int(p)
    if s == 'AC':
        ac[p] = 1
    elif ac[p] == 0:
        wa[p] += 1

wa_sum = 0
for w, a in zip(wa, ac):
    wa_sum += w*a
print(sum(ac), wa_sum)


Measured memory_bytes: 45784
import random


def main():
    X = int(input())
    for i in range(X, 10 ** 6):
        if is_prime(i) == True:
            print(i)
            break


def is_prime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    if n == 561:
        return False
    if n == 1729:
        return False
    for _ in range(100):
        a = random.randint(2, n - 1)
        if gcd(n, a) != 1:
            return False
        if pow(a, n - 1, n) != 1:
            return False
    return True


def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a


if __name__ == "__main__":
    main()


Measured memory_bytes: 4208
from sys import stdin
input = stdin.readline

def VI(N, init=0):
  return [init for _ in range(N)]
def VVI(N, M, init=0):
  return [[init for _ in range(M)] for _ in range(N)]

def VD(N, init=0.0):
  return [init for _ in range(N)]
def VVD(N, M, init=0.0):
  return [[init for _ in range(M)] for _ in range(N)]

def Decimal(x):
  print("{0:.10f}".format(x))

class Pair:
  def __init__(self, x=0, y=0):
    self.first = x
    self.second = y

  def __repr__(self):
    return '{0} {1}'.format(self.first, self.second)

  def __lt__(self, pi):
    return self.first < pi.second

def POW(x, n):
  ret = 1
  while n:
    if n&1:
      ret *= x
    x *= x
    n >>= 1
  return ret

towers = [0 for _ in range(999)]
towers[0] = 1

for i in range(1, 999):
  towers[i] = towers[i-1] + (i+1)

a, b = map(int, input().rstrip().split())

ans = -1
for i in range(998):
  if towers[i] - a == towers[i+1] - b:
    ans = towers[i]-a
    if ans >= 0:
      break

print(ans)



Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

int main() {
  long long int N;
  string S;
  vector<long long int> a_v, b_v, c_v, k_v(26, 0);
  std::map<std::string, int> mp;
  int flag = 0;
  cin >> S;
  for (int i = 0 ; i < S.size(); i++) {
    k_v[S[i] - 'A'] ++;
  }
  for (int i = 0; i < 26; i++) {
    if (k_v[i] == 4 || k_v[i] == 1 || k_v[i] == 3)
      flag = 1;
  }
  if (flag == 1) printf("No\n");
  else printf("Yes\n");
  // for (int i = 0; i < N; i++) {
  //   //cout << i << endl;
  //   long long int t;
  //   cin >> t;
  //   a_v.push_back(t);
  // }
  // sort(a_v.begin(), a_v.end());
  // for (int i = 0; i < N; i++) {
  //   //cout << i << endl;
  //   long long int t;
  //   cin >> t;
  //   b_v.push_back(t);
  // }
  // sort(b_v.begin(), b_v.end());
  // for (int i = 0; i < N; i++) {
  //   //cout << i << endl;
  //   long long int t;
  //   cin >> t;
  //   c_v.push_back(t);
  // }
  // sort(c_v.begin(), c_v.end());

  // int min_j = 0, max_k = N;
  // long long int sum = 0, a_cnt = 0, c_cnt = 0;
  // for (int i = 0; i < N; i++) {//b
  //   a_cnt = c_cnt = 0;
  //   for (int j = N-1; j >= 0; j--) { // a
  //     if (a_v[j] >= b_v[i]) {
  //       break;
  //     }
  //     else {
  //       a_cnt++;
  //     }
  //   }

  //   for (int k = 0; k < N; k++) { // c
  //     if (c_v[k] <= b_v[i]) {
  //       break;
  //     }
  //     else {
  //       c_cnt++;
  //     }
  //   }
  //   sum += a_cnt*c_cnt;
  // }

  // cout << sum << endl;
  // // int min_j = 0, min_k = 0;
  // // for (int i = 0; i < N; i++) {//c
  // //   int flag = -1;
  // //   for (int j = 0; j < N; j++) {//b
  // //     if (c_v[i] < b_v[j]) {
  // //       flag = 0;
  // //       min_j = j;
  // //       for (int k = 0; k < N; k++) {//a
          
          
  // //       }
  // //     }
  // //   }
  // // }
  // // if (N == 1) {
  // //   printf("%lld", t_v[0]);
  // //   return 0;
  // // }
  // // long long int mul = lcm(t_v[0], t_v[1]);
  // // //printf("%lld\n", mul);

  // for (int i = 2; i < N; i++) {
  //   mul = lcm(mul, t_v[i]);
  //   //printf("%d %lld\n", i, mul);
  //   // cout << i << " " <<  mul << endl;
  // }
  // cout << mul << endl;
  return 0;
}


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

int main(int argc, const char * argv[]) {
    
    int nyuuryoku[6][10];
    int print[6];
    int a=0;
    int sum=0;
    
    for(int i=0;i<6;i++){
        for(int j=0;j<10;j++){
            cin >> nyuuryoku[i][j];
            if(j==0){
                if(nyuuryoku[i][j]==0){
                    a=1;
                    break;
                }
            }
        }
        if(a==1){
            break;
        }
    }
    
    a=0;
    
    for(int i=0;i<6;i++){
        
        if(nyuuryoku[i][0]==0){
            a=i;
            break;
        }
        
        sum=0;
        for(int j=1;j<10;j++){
            sum=sum+nyuuryoku[i][j];
        }
        print[i]=nyuuryoku[i][0]-sum;
        
        
    }
    
    for(int i=0;i<a;i++){
        cout << print[i] << endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 2976