akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct UnionFind {
    vector<int> id;
    vector<vector<int> > groups;
    int gn; //number of groups
    UnionFind(int n){
        id = vector<int>(n);
        groups = vector<vector<int> >(n);
        gn = n;
        for(int i=0;i<n;++i){
            id[i]=i;
            groups[i]={i};
        }
    }
    void unite(int a, int b) {
        if(same(a,b)) return;
        gn--;
        int x = id[a];
        int y = id[b];
        if(groups[x].size()<groups[y].size()) swap(x,y);
        for(int j : groups[y]){
            id[j] = x;
            groups[x].push_back(j);
        }
        groups[y].clear();        
    }
    bool same(int a, int b) {
        return id[a] == id[b];
    }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    UnionFind uf(n);
    int m;
    cin >> m;
    REP(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
    }
    int ans = 0;
    REP(i,n){
        int x = uf.id[i];
        ans = max(ans, (int)uf.groups[x].size());
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18192
#include <bits/stdc++.h>
#include<set>
#include <algorithm>
#define ll long long 
#include <string.h>
#define pb push_back
#define mp make_pair
# define pi 3.14159265358979323846
using namespace std;
const int MAX = 10000001; 
  
// array to store prime factors 
ll int factor[MAX] = { 0 }; 
  
// function to generate all prime factors 
// of numbers from 1 to 10^6 
void generatePrimeFactors() 
{ 
    factor[1] = 1; 
  
    // Initializes all the positions with their value. 
    for (ll int i = 2; i < MAX; i++) 
        factor[i] = i; 
  
    // Initializes all multiples of 2 with 2 
    for (ll int i = 4; i < MAX; i += 2) 
        factor[i] = 2; 
  
    // A modified version of Sieve of Eratosthenes to 
    // store the smallest prime factor that divides 
    // every number. 
    for (ll int i = 3; i * i < MAX; i++) { 
        // check if it has no prime factor. 
        if (factor[i] == i) { 
            // Initializes of j starting from i*i 
            for (ll int j = i * i; j < MAX; j += i) { 
                // if it has no prime factor before, then 
                // stores the smallest prime divisor 
                if (factor[j] == j) 
                    factor[j] = i; 
            } 
        } 
    } 
} 
  
// function to calculate number of factors 
ll int calculateNoOFactors(int n) 
{ 
    if (n == 1) 
        return 1; 
  
    ll int ans = 1; 
  
    // stores the smallest prime number 
    // that divides n 
    ll int dup = factor[n]; 
  
    // stores the count of number of times 
    // a prime number divides n. 
    ll int c = 1; 
  
    // reduces to the next number after prime 
    // factorization of n 
    ll int j = n / factor[n]; 
  
    // false when prime factorization is done 
    while (j != 1) { 
        // if the same prime number is dividing n, 
        // then we increase the count 
        if (factor[j] == dup) 
            c += 1; 
  
        /* if its a new prime factor that is factorizing n,  
           then we again set c=1 and change dup to the new  
           prime factor, and apply the formula explained  
           above. */
        else { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
  
        // prime factorizes a number 
        j = j / factor[j]; 
    } 
  
    // for the last prime factor 
    ans = ans * (c + 1); 
  
    return ans; 
}

int main()
{
	ll int n;
	cin>>n;
	generatePrimeFactors();
	
	ll int i,j,p,ans=0;
	for(i=1;i<=n;i++)
	{
		ll int p=calculateNoOFactors(i);
		
		ans+=p*i;
	}
	cout<<ans<<endl;
	
	
}
    
	
		

	
			

		


 






Measured memory_bytes: 81732
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[500000],b[500000];

signed main(){
	int n;scanf("%d",&n);
	string s;cin>>s;
	int cnt=0;
	rep(i,s.size()){
		a[i+1]=a[i];
		b[i+1]=b[i];
		if(s[i]=='W')a[i+1]=a[i]+1;
		else b[i+1]=b[i]+1,cnt++;
	}
	int Min=INT_MAX;
	rep(i,s.size()){
		int c=a[i],d=cnt-b[i+1];
		Min=min(Min,c+d);
	}
	cout<<Min<<endl;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define ll  long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
ll countSol(ll coeff[], ll n, ll rhs)
{
    ll dp[rhs + 1];
    memset(dp, 0, sizeof(dp));
    dp[0] = 1;

    for (ll i = 0; i < n; i++)
    for (ll j = coeff[i]; j <= rhs; j++)
        dp[j] += dp[j - coeff[i]];

    return dp[rhs];
}
void solve()
{
    ll n,m,k,x,y,res=0,l,cnt=0,sum=0,z,sum1=0,cnt1=0,h,res1;
   cin>>x>>y>>z>>n;
   ll coeff[3]={x,y,z};
   cnt=countSol(coeff,3,n);
   cout<<cnt;

}
int main()
{   speed_up
    ll t;
   // cin>>t;
    t=1;
    while(t--)
        solve();
}


Measured memory_bytes: 256
#include <cstdio>


#define gc getchar
#define pc putchar
#define sp pc(' ')
#define lnn pc('\n')
template <class t>
inline void read(t &num) {
    register bool flag = 0;
    register char c = gc();
    while ((c < '0' || c > '9') && c != '-') c = gc();
    if (c == '-') flag = 1, c = gc();
    num = 0;
    while (c >= '0' && c <= '9') num = (num << 1) + (num << 3) + c - '0', c = gc();
    flag && (num = ~(num - 1));
}
template <class t>
inline void print(t num) {
    if (num < 0) pc('-'), num = ~(num - 1);
    if (num >= 10) print(num / 10);
    pc(num % 10 + '0');
}
int min(int a, int b) {
    return a > b ? b : a;
}

typedef long long ll;

int n;
int h[100001];
bool v[1000001];

int main() {
    read(n);
    for (int i = 1; i <= n; i++) {
        read(h[i]);
    }
    for (int i = 1; i < n; i++) {
        if (h[i] - h[i + 1] > 1) {
            puts("No");
            return 0;
        }
        if (h[i] - h[i + 1] > 0) {
            int now = i;
            do {
                h[now]--;
                if (v[now]) {puts("No"); return 0;}
                v[now] = 1;
                now--;
            } while(h[now] > h[now + 1]);
        }
    }
    puts("Yes");
}

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

int main(){
    string s;
    cin >> s;
    if(s.at(0)==s.at(1)&&s.at(1)==s.at(2)){
        cout << "Yes" << endl;
    }else if(s.at(1)==s.at(2)&&s.at(2)==s.at(3)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(4100000)

INF = 1 << 60

# ここから書き始める
n = int(input())
x = [[int(j) for j in input().split()] for i in range(n)]
# print(x)
dp = [[-INF for j in range(3)] for i in range(n)]
for i in range(3):
    dp[0][i] = x[0][i]
for i in range(1, n):
    dp[i][0] = max(dp[i][0], dp[i - 1][1] + x[i][0])
    dp[i][0] = max(dp[i][0], dp[i - 1][2] + x[i][0])
    dp[i][1] = max(dp[i][1], dp[i - 1][0] + x[i][1])
    dp[i][1] = max(dp[i][1], dp[i - 1][2] + x[i][1])
    dp[i][2] = max(dp[i][2], dp[i - 1][0] + x[i][2])
    dp[i][2] = max(dp[i][2], dp[i - 1][1] + x[i][2])

print(max(dp[-1]))


Measured memory_bytes: 103380
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

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

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	int n, h, m, diff;
	
	cin >> n;
	
	string str;
	
	for(int loop = 0; loop < n; loop++){
		cin >> str;
		h = (str[0] - '0') * 10 + (str[1] - '0');
		m = (str[3] - '0') * 10 + (str[4] - '0');
		diff = abs((h * 60 + m) - m * 12);
		if(diff > 360){
			diff = 720 - diff;
		}
		if(diff < 60){
			printf("alert\n");
		}else if(diff < 180){
			printf("warning\n");
		}else{
			printf("safe\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 1172
fun main(args: Array<String>) {
    val (x, y) = readLine()!!.split(" ").map { it.toInt() }
    val l = readLine()!!.split(" ").map { it.toInt() }
    var boundAt = mutableListOf(0)
    l.forEach{
        boundAt.add(boundAt.last() + it)
    }
    println(boundAt.filter { it <= y }.count())
}

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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int n;

signed main()
{

    cin >> n;

    cout << n * n * n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	ll k ; cin >> k ;
	vll p(n) ;
	for(auto &i:p) cin >> i ;
	vll sum(n+1,0) ;
	for(int i=1;i<=n;i++){
		sum.at(i) = sum.at(i-1)+p.at(i-1) ;
//		cout << sum.at(i) << endl ;
	}
	ll ans = 0 ;
	for(int i=k;i<=n;i++){
//		cout << ans << endl ;
		if(ans<sum.at(i)-sum.at(i-k)) ans = sum.at(i)-sum.at(i-k) ;
	}
	cout << fixed << setprecision(15) << (ans+k)/2.0 << endl ;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PLL> VP;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "

int main()
{
    ll K, A, B;
    cin >> K >> A >> B;
    ll m=1;
    ll count=0;
    while(count!=K){
        if(m<A){
            m++;
            count++;
            continue;
        }
        if(count==K-1){
            m++;
            count++;
            continue;
            
        }
        if((m+2-m)<-A+B){
            m=m-A+B;
            count+=2;
            continue;
        }
        else{
            m++;
            count++;
        }
    }
    cout << m << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main()
{
	int n, m, i, j, k; cin >> n >> m;
	std::vector<string> v;
	string s;
	for (i = 0; i < n; i++) cin >> s, v.push_back(s);
	int a[n][m];

	a[0][0] = v[0][0] == '.' ? 1 : 0;

	for (i = 0; i < n; i++)
	{
		a[i][0] = i != 0 ? (v[i][0] != '#' ? a[i - 1][0] : 0) : a[0][0];
		for (j = 1; j < m; j++)
		{
			if (v[i][j] == '#')
			{
				a[i][j] = 0;
			}
			else if (i == 0)
			{
				a[i][j] = a[i][j - 1];
			}
			else
			{
				a[i][j] = (a[i - 1][j] + a[i][j - 1]) % mod;
			}

			//cout << a[i][j] << " ";

		}
		//cout << endl;

	}
	cout << a[n - 1][m - 1] << endl;



}



Measured memory_bytes: 8532
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
                                                                                                
  
int prime( int x ){

           int i;

           if( x < 2 ) return 0;

           for( i = 2 ; i * i <= x ; i = i + 1 ){

                if( x % i == 0 ) return 0;

                }

           return 1;

           }


int main(){
                                                                                                
   
    int q, i, j, x, y;

         
    cin >> q;

    vector<int> l(q + 1);

    vector<int> r(q + 1);

    vector<int> like(100010);


    for( i = 0 ; i < q ; i = i + 1 ){

         cin >> l.at(i) >> r.at(i);

         }


    for( i = 3 ; i <= 100000 ; i = i + 2 ){

         if( prime( i ) == 1 && prime( ( i + 1 ) / 2 ) == 1 ){

             like.at( i ) = 1;

             }

         }

    for( i = 3 ; i <= 100000 ; i = i + 1 ){

         like.at( i ) += like.at( i - 1 );       

         }
    

    for( i = 0 ; i < q ; i = i + 1 ){

         x = l.at(i);

         y = r.at(i);

         cout << like.at( y ) - like.at( x - 1 ) << endl;

         }


    return 0;
                                                          
}

Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

int n;
double dp[310][310][310];

double rec(int x, int y, int z){
    if(dp[x][y][z] != 0) return dp[x][y][z];
    if(x == 0 && y == 0 && z == 0) return 0;

    double ans = 0;
    if(x > 0) ans += rec(x - 1, y, z) * x;
    if(y > 0) ans += rec(x + 1, y - 1, z) * y;
    if(z > 0) ans += rec(x, y + 1, z - 1) * z;
    ans += n;
    ans *= 1. / (x + y + z);

    return dp[x][y][z] = ans;
}

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

    cin>>n;
    vector<int> cnt(4, 0);
    for(int i=0; i<n; i++){
        int a; cin>>a;
        cnt[a]++;
    }

    double ans = rec(cnt[1], cnt[2], cnt[3]);

    printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 225536
#include <bits/stdc++.h>
    
#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
    
using namespace std;

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

int32_t main(){
    int n;
    cin >> n;
    vector<int> m(100005, 0);
    REP(i, n){
        int a;
        cin >> a;
        m[a]++;
        m[a+1]++;
        if(a!=0) m[a-1]++;
    }
    SORT(m);
    cout << m[100004] << endl;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline int ubnd(T&v,ET(T) x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T) x){return lower_bound(begin(v),end(v),x)-begin(v);}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline void inpt(T&v,int n,function<ET(T)()>f=In<ET(T)>){for(v.reserve(n);n--;v.emplace_back(f()));}
TT inline void show(T&v,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),cout<<x;cout<<e;}
#undef TT
#undef ET

inline void fast_io(){ios::sync_with_stdio(0); cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline string instr(){string x;cin>>x;return x;}
inline ll pow_mod(ll a, ll k, ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a, ll p){return pow_mod(a,p-2,p);}

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

int main()
{
  int n;
  while (n = in()){
    queue<int> q;
    int flag = 0;
    for (int i = 0; i < n; i++) q.push(in());
    while (!q.empty()){
      int x = q.front();
      q.pop();
      int a = x;
      while (!q.empty() && a + 1 == q.front()){
        a++;
        q.pop();
      }
      if (flag++) printf(" ");
      if (x == a) printf("%d", x);
      else printf("%d-%d", x, a);
    }
    puts("");
  }
  return (0);
}

// priority_queue queue deque front top push pop map set stringstream max_element min_element insert count find get tie make_tuple

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i ++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i --)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return 1;}return 0;}

constexpr ll INF = (1ll << 60);
constexpr ll MOD = 1000000007ll;

ll llgcd(ll a, ll b){
    if(b == 0)
        return a;
    return llgcd(b, a % b);
}

ll llpow(ll a, ll n){
    ll res = 1;
    while(n > 0){
        if(n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    ll x;
    cin >> x;
    ll n = 100, cnt = 0;
    while(n < x){
        n = double(n) * double(1.01);
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int w, h, n;
    cin >> w >> h >> n;
    int xmax = -1;
    int xmin = 1e8;
    int ymax = -1;
    int ymin = 1e8;
    rep(i, n) {
        int x, y;
        int a;
        cin >> x >> y >> a;
        if ( a == 1 ) {
            xmax = max(xmax, x);
        }
        if ( a == 2 ) {
            xmin = min(xmin, x);
        }
        if ( a == 3 ) {
            ymax = max(ymax, y);
        }
        if ( a == 4 ){
            ymin = min(ymin, y);
        }
    }
    if ( xmax > xmin || ymax > ymin ) {
        cout << 0 << endl;
    }
    else if ( xmax == xmin && ymax == ymin ) {
        cout << 1 << endl;
    }
    else if ( xmax < xmin && xmax != -1 && xmin == 1e8 && ymax == ymin ) {
        cout << ( xmin - xmax ) << endl;
    }
    else if ( xmax == xmin && ymax < ymin && ymax != -1 && ymin != 1e8 ) {
        cout << ( ymin - ymax ) << endl;
    }
    else {
        if ( xmin == 1e8 ) xmin = w;
        if ( xmax == -1 )  xmax = 0;
        if ( ymin == 1e8 ) ymin = h;
        if ( ymax == -1 )  ymax = 0;
        cout << ( xmin - xmax ) * ( ymin - ymax ) << endl;
    } 
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_ST = 3005;
int dp[3005][3005];

int main()
{
	string s,t;
	cin >> s >> t;
	/*
	if (s[0] == t[0]) dp[0][0] = 1;
	rep(i,s.size()-1)
	{
		if (dp[i][0] == 1) dp[i+1][0] = 1;
		else if (s[i+1] == t[0]) dp[i+1][0] = 1;
	}
	rep(i,t.size()-1)
	{
		if (dp[0][i] == 1) dp[0][i+1] = 1;
		else  if (s[0] == t[i+1]) dp[0][i+1] = 1;
	}
	*/
	rep(i,s.size())
	{
		rep(j,t.size())
		{
			if (s[i] == t[j])
			{
				dp[i+1][j+1] = dp[i][j] + 1;
			}
			else
			{
				dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
			}
		}
	}
	/*
	rep(i,s.size()+1)
	{
		rep(j,t.size()+1)
		{
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	*/
	string ans = "";
	int x = s.size(), y = t.size();
	while(x > 0 && y > 0)
	{
		//cout << x << " " << y << " ";
		if (dp[x][y] == dp[x-1][y])
		{
			x--;
			//cout << "1";
		}
		else if (dp[x][y] == dp[x][y-1])
		{
			y--;
			//cout << "2";
		}
		else
		{
			x--; y--;
			ans.push_back(s[x]);
			//cout << "3";
		}
		//cout << endl;
	}
	reverse(ans.begin(),ans.end());
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 35456
N = int(input())
S = input()
L = []
L.append(S[1:].count('E'))
for i in range(1,N):
    if S[i-1] =='E' and S[i]=='E':
        a = L[-1] -1 
    elif S[i-1] =='W' and S[i]=='W':
        a = L[-1] +1 
    else:
        a = L[-1]
    L.append(a)
print(min(L))

Measured memory_bytes: 15564
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    ll n;
    cin >> n;
    vector<ll> total(1, 0);
    ll times=26, sum=26, len=1;
    while(n>sum){
      total.push_back(sum);
      times *= 26;
      sum += times;
      len++;
    }
    vector<char> word;
    n -= total[len - 1] + 1;
    rep(i, len){
        ll x = n % 26;
        char w = (char)((int)'a' + x);
        word.push_back(w);
        n /= 26;
    }
    rep(i, len){
        cout << word[len - i - 1];
    }
    cout << endl;
    // rep(i, 11){
    //     cout << len << " : " << times << endl;
    //     sum += times;
    //     times *= 26;
    //     len++;
    // }
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
using namespace std;
int main(){
  int a,b,c;
  string ans="NO";
  cin>>a>>b>>c;
  if(a==5){
    if(b==5){
      if(c==7)ans="YES";
    }
    else if(b==7){
      if(c==5)ans="YES";
    }
  }
  else if(a==7){
    if(b==5){
      if(c==5)ans="YES";
    }
  }
  cout<<ans<<endl;
}

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

#define rp(i,t) for(int i=0;i<(t);i++)
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rsp(i,s,t) for(int i=(s);i<(t);i++)
#define rrp(i,t,s) for(int i=(t);i>=(s);i--)
#define rcp(i,s,b,d) for(int i=(s);b;d)
#define mst(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f

#define Dp puts("")
#define Dw printf
#define Ds printf("#")

typedef long long ll;
char ch;
int n,x;
set<int> Q;
set<int>::iterator it;

inline void read(int &x){x=0;do{ch=getchar();}while(ch<'0'||'9'<ch);do{x=x*10+ch-'0';ch=getchar();}while('0'<=ch&&ch<='9');}

int main(void)
{
	read(n);
	rep(i,1,n)
	{
		read(x);
		it=Q.find(x);
		if(it!=Q.end())Q.erase(it);
		else Q.insert(x);
	}
	printf("%u",Q.size());
	return 0;
}


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

int main(){
  string s;
  cin>>s;
  cout<<s[0]<<s[1]<<s[2]<<s[3]<<s[4]<<" "<<s[6]<<s[7]<<s[8]<<s[9]<<s[10]<<s[11]<<s[12]<<" "<<s[14]<<s[15]<<s[16]<<s[17]<<s[18]<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int shift = sc.nextInt();
    String origin = sc.next();
    int limit = (int)'Z';
    StringBuilder out = new StringBuilder();
    for (int i = 0; i < origin.length(); i++) {
      int val = (int)origin.charAt(i) + shift;
      if (val > limit) val -= 26;
      out.append((char)val);
    }
    System.out.println(out.toString());
  }
}


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

int main() {
    map <char, string> map1;
    map1[' '] = "101";
    map1['\''] = "000000";
    map1[','] = "000011";
    map1['-'] = "10010001";
    map1['.'] = "010001";
    map1['?'] = "000001";
    map1['A'] = "100101";
    map1['B'] = "10011010";
    map1['C'] = "0101";
    map1['D'] = "0001";
    map1['E'] = "110";
    map1['F'] = "01001";
    map1['G'] = "10011011";
    map1['H'] = "010000";
    map1['I'] = "0111";
    map1['J'] = "10011000";
    map1['K'] = "0110";
    map1['L'] = "00100";
    map1['M'] = "10011001";
    map1['N'] = "10011110";
    map1['O'] = "00101";
    map1['P'] = "111";
    map1['Q'] = "10011111";
    map1['R'] = "1000";
    map1['S'] = "00110";
    map1['T'] = "00111";
    map1['U'] = "10011100";
    map1['V'] = "10011101";
    map1['W'] = "000010";
    map1['X'] = "10010010";
    map1['Y'] = "10010011";
    map1['Z'] = "10010000";

    map <string, char> map2;
    map2["00000"] = 'A';
    map2["00001"] = 'B';
    map2["00010"] = 'C';
    map2["00011"] = 'D';
    map2["00100"] = 'E';
    map2["00101"] = 'F';
    map2["00110"] = 'G';
    map2["00111"] = 'H';

    map2["01000"] = 'I';
    map2["01001"] = 'J';
    map2["01010"] = 'K';
    map2["01011"] = 'L';
    map2["01100"] = 'M';
    map2["01101"] = 'N';
    map2["01110"] = 'O';
    map2["01111"] = 'P';

    map2["10000"] = 'Q';
    map2["10001"] = 'R';
    map2["10010"] = 'S';
    map2["10011"] = 'T';
    map2["10100"] = 'U';
    map2["10101"] = 'V';
    map2["10110"] = 'W';
    map2["10111"] = 'X';

    map2["11000"] = 'Y';
    map2["11001"] = 'Z';
    map2["11010"] = ' ';
    map2["11011"] = '.';
    map2["11100"] = ',';
    map2["11101"] = '-';
    map2["11110"] = '\'';
    map2["11111"] = '?';

    string line;
    while ( getline( cin, line ) ) {
        string to1;
        for ( string ::iterator it = line.begin(); it != line.end(); it++ ) {
            to1 += map1[*it];
        }

        string to2( ( to1.size()%5 != 0 ? to1.size()/5*5+5 : to1.size() ), '0' );
        for ( int i = 0; i < to1.size(); i++ ) {
            to2[i] = to1[i];
        }

        string answer;
        for ( int i = 0; i < to2.size(); i += 5 ) {
            string key = to2.substr( i, 5 );
            answer += map2[key];
        }

        cout << answer << endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);++i)
using edge = struct edge{ll from,to,cost;edge(ll from,ll to,ll cost):from(from),to(to),cost(cost){}};
using weighted_edge = vector<edge>;

class Union_Find {
private:
  ll n;
  vector<ll> parent;

public:
  Union_Find(ll v){
    n=v;
    parent.resize(n,-1);
  }

  ll root(ll v){
    if(parent[v]<0)return v;
    return parent[v]=root(parent[v]);
  }
  ll size(ll v){
    return -parent[root(v)];
  }
  bool connect(ll a,ll b){
    a=root(a);
    b=root(b);
    if(a==b)return false;
    if(size(a)<size(b)) swap(a,b);
    parent[a]+=parent[b];
    parent[b]=a;
    return true;
  }
  bool same(ll a,ll b){
    return root(a)==root(b);
  }

};

void solve(){

  ll v,e;
  cin>>v>>e;
  weighted_edge edges;
  rep(i,e){
    ll u,v,w;
    cin>>u>>v>>w;
    edges.emplace_back(u,v,w);
  }
  auto cmp = [](auto a,auto b){return a.cost<b.cost;};
  sort(edges.begin(),edges.end(),cmp);
  Union_Find uni(v);
  ll ans=0;
  for(const auto& e:edges){
    if( uni.same(e.from,e.to) )continue;
    uni.connect(e.from,e.to);
    ans+=e.cost;
  }
  cout<<(ans)<<endl;

}

main(){
  solve();
}


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


int main() {

   ll n;
   cin>>n;
   map<int,int> m;

   for(int i=0;i<n;i++)
   {
       int x;
       cin>>x;
       m[x]++;
   }
       ll ans=0;
         for(auto p:m)
         {
             ans+=p.first*p.second;
         }
      int q;
      cin>>q;
      for(int i=0;i<q;i++)
      {
          int x,y;
          cin>>x>>y;
           
           int t=(y-x)*m[x];
            m[y]+=m[x];
            m[x]=0;
            ans+=t;

        
           cout<<ans<<"\n";

      }


    
    
    
    return 0;
}


Measured memory_bytes: 8080
n=int(input())
arr=list(map(int,input().split()))
flag=[-1]*n
ans=[]
for i in range(n-1,-1,-1):
  cnt=0
  for j in range(2*i+1,n,i+1):
    if flag[j]==1:
      cnt+=1
  if (arr[i]+cnt)%2==0:
    flag[i]=0
  else:
    flag[i]=1
    ans.append(i+1)
num=len(ans)
if num==0:
  print(0)
else:
  print(num)
  print(*ans)

Measured memory_bytes: 14000
def solve(items, n, W):
    V = sum([v for _, v in items])
    dp = [float('inf')] * (V + 1)
    dp[0] = 0

    for w, v in items:
        for i in range(V, v-1, -1):
            dp[i] = min(dp[i], dp[i-v] + w)
    
    for i in range(V, -1, -1):
        if dp[i] <= W:
            return i

    return 0


def main():
    inp = lambda: [int(x) for x in input().split()]
    n, w = inp()
    items = [inp() for _ in range(n)]
    print(solve(items, n, w))


if __name__ == '__main__':
    main()


Measured memory_bytes: 70100
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    int a, b;
    cin >> a >> b;
    if (a == 1) a = 14;
    if (b == 1) b = 14;

    if (a > b) {
        cout << "Alice" << endl;
        return 0;
    } else if (a < b) {
        cout << "Bob" << endl;
        return 0;
    } else {
        cout << "Draw" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int data[10000];
	int num,i=0,s=0,a=1;
	while(a!=0){
		scanf("%d",&num);
		if(num==0)
			break;
		data[i]=num;
		i++;
		s++;
	}
	for(i=0;i<s;i++){
		printf("Case %d: %d\n",i+1,data[i]);
	}
	return 0;
}


Measured memory_bytes: 1792
d, g = map(int, input().split())
src = [list(map(int, input().split())) for _ in range(d)]

ans = 10**10
for b in range(2**d):
  score = 0
  ac = 0
  for k in range(d):
    if b&(1<<k):
      p,c = src[k]
      score += c
      ac += p
      score += p*(k+1)*100
  if score >= g:
    ans = min(ans, ac)
    continue
  for k in range(d-1, -1, -1):
    if b&(1<<k)==0:
      p, c = src[k]
      if score +p*(k+1)*100 < g:
        score += p*(k+1)*100
        ac += p
      else:
        rem = g-score
        ac += -(-rem // (k+1) // 100)
        ans = min(ans, ac)
        break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <deque>

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

using namespace std;

int main()
{
	unsigned long long int x, y;
	cin >> x >> y;

	if (x % y == 0)
		cout << -1 << endl;

	else
		cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
l,r = map(int,input().split())
minv = 2019
if r-l > 2019:
    minv = 0
else:  
    for i in range(l,r):
        for j in range(i+1,r+1):
            if minv > (i*j)%2019:
                minv = (i*j)%2019
            
        
print(minv)

Measured memory_bytes: 40940
#include <bits/stdc++.h>
using namespace std;
#define int long long
int nC2(int n){
	return n * (n - 1) / 2;
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cout << fixed << setprecision(6);
  int n; cin >> n;
  int a[n + 1];
  map<int, int> m;
  vector<int> curr;
  int ret = 0;
  for (int i = 1; i <= n; i++) {int x; cin >> x; a[i] = x, m[x]++;}
  for (int i = 1; i <= n; i++){
  	if (m[i] < 2) continue;
  	ret += nC2(m[i]);
  }
  for (int i = 1; i <= n; i++){
  	if (m[a[i]] < 2) curr.push_back(ret);
  	else{
  	 int val = ret;
  	 val -= nC2(m[a[i]]);
  	 val += nC2(m[a[i]] - 1);
  	 curr.push_back(val);
  	}
  }
  for (auto it : curr) cout << it << endl;
}


Measured memory_bytes: 18416
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>

#include <random>
#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

//#define solvsh
//#define multi
#ifdef solvsh

void solve(){

}

#else

void solve() {

    ll k;
    cin >> k;
    int n;
    cin >> n;

    vector<ll> v;

    for (int i = 0; i < n; ++ i){
        int c;
        cin >> c;
        v.push_back(c);
    }
    ll a = abs(v[1] - v[0]);

    for (int i = 0; i < n - 1; ++ i){
        a = max(a, abs(v[i + 1] - v[i]));
    }
    a = max(a, v[0] + k - v.back());

    cout << k - a;

}

#endif

void multisolve() {
    int t;
    cin >> t;

    int i = 1;
    while (t--) {
//        cout << "Case #" << (i++)  << ": ";
        solve();
//        cout << "\n";
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);


#ifdef multi
    multisolve();
#else
    solve();
//    gen();
#endif

#ifdef LOCAL
    //cout << '\n' << (double)clock() / CLOCKS_PER_SEC << '\n';
#endif
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A[9];
  for(int i = 0; i < 9; i++) cin >> A[i];
  int N,b;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> b;
    for(int i = 0; i < 9; i++) if(A[i] == b) A[i] = 0;
  }
  if((A[0] + A[1] + A[2]) == 0) cout << "Yes" << endl;
  else if((A[3] + A[4] + A[5]) == 0) cout << "Yes" << endl;
  else if((A[6] + A[7] + A[8]) == 0) cout << "Yes" << endl;
  
  else if((A[0] + A[3] + A[6]) == 0) cout << "Yes" << endl;
  else if((A[1] + A[4] + A[7]) == 0) cout << "Yes" << endl;
  else if((A[2] + A[5] + A[8]) == 0) cout << "Yes" << endl;
  
  else if((A[0] + A[4] + A[8]) == 0) cout << "Yes" << endl;
  else if((A[2] + A[4] + A[6]) == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
package main

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

// BIT stands for binary indexed tree.
type BIT []int

func newBIT(n int) BIT {
	return make([]int, n)
}

func (bit *BIT) add(i, x int) {
	for i++; i <= len(*bit)-1; i += i & -i {
		(*bit)[i-1] += x
	}
}

func (bit *BIT) sum(i int) int {
	result := 0
	for i++; i > 0; i -= i & -i {
		result += (*bit)[i-1]
	}
	return result
}

type t struct {
	X int
	H int
}
type byX []t

func (a byX) Len() int           { return len(a) }
func (a byX) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a byX) Less(i, j int) bool { return a[i].X < a[j].X }

func main() {
	N := readInt()
	D := readInt()
	A := readInt()
	XH := make([]t, N)
	for i := 0; i < N; i++ {
		XH[i].X = readInt()
		XH[i].H = (readInt() + A - 1) / A
	}

	sort.Sort(byX(XH))
	result := 0
	bit := newBIT(N + 1)
	for i := 0; i < N; i++ {
		x, h := XH[i].X, XH[i].H
		h -= bit.sum(i)
		if h <= 0 {
			continue
		}
		result += h
		bit.add(i, h)

		ok := i
		ng := N
		for ng-ok != 1 {
			m := ok + (ng-ok)/2
			if XH[m].X <= x+2*D {
				ok = m
			} else {
				ng = m
			}
		}
		bit.add(ng, -h)
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

int main(){
    int N,M;

    cin>>N>>M;
  vector<string> c(N);
  vector<int>a(N),b(M);
    for(int i = 0; i < N; i++){
        cin>>c[i];
      for(int j=0;j<M;j++){
      if(c[i][j]=='#'){
        a[i]=1;
        b[j]=1;
      }
      }
    }
      for(int i = 0; i < N; i++){
      for(int j=0;j<M;j++){
        if(a[i]!=1){
          break;
        }
      if(a[i]==1&&b[j]==1){
        cout<<c[i][j];
      }
        if(j==M-1){
          cout<<endl;
        }
      }
 
    }
}


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

using namespace std;

int main(){
    int n, cur = 1;
    cin >> n;
    vector<int> v;
    bool flag = 0;
    for(int i = 0; i < n; ++i){
        int tmp; cin >> tmp;
        if(tmp == 1)flag = 1;
        v.push_back(tmp);
    }
    if(!flag){
        cout << -1;
        return 0;
    }
    else{
       bool garbo = true;

       for(int i = 0; i < v.size(); ++i){
            if(garbo){
                if(v[i] == 1)garbo = false;
            }else {
                if(v[i] == cur + 1){
                    cur++;
                }
            }
       }
    }
    cout << v.size() - cur;
    return 0;

}


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

using namespace std;

#define ll long long 
#define pi 3.14159265358979323

void solve(){
    double r;
    cin>>r;
    cout<<fixed<<setprecision(10)<<pi*2*r;
}

int main() {
    int t = 1;
    while(t--)
        solve();
    return 0;
}



Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class UnionFind {
    int n;
    vector<int> uni;
public:
    explicit UnionFind(int n) : uni(static_cast<u32>(n), -1) , n(n){};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        return true;
    }

    int size(int i){ return -uni[root(i)]; }
    bool same(int a, int b) { return root(a) == root(b); }
};



int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    vector<vector<int>> G(n+1);
    UnionFind uf(n);
    for (int i = 0; i < n; ++i) {
        if(v[i]) uf.unite(i, v[i]+i);
    }
    vector<int> dp(n, -1);
    for (int i = 0; i < n; ++i) {
        if(!v[i]){
            dp[uf.root(i)] = i;
        }
    }
    for (int i = 0; i < n; ++i) {
        if(dp[uf.root(i)] == -1) dp[uf.root(i)] = n;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 1; j <= 6 && i+j < n; ++j) {
            G[i].emplace_back(dp[uf.root(i+j)]);
        }
    }
    queue<int> Q;
    Q.push(0);
    vector<int> dis(n+1, MOD);
    dis[0] = 0;
    while(!Q.empty()){
        int i = Q.front(); Q.pop();
        for (auto &&j : G[i]) {
            if(dis[i]+1 < dis[j]){
                Q.emplace(j);
                dis[j] = dis[i]+1;
            }
        }
    }
    cout << dis[n-1] << "\n";
    return 0;
}


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

const int maxn = 200000 + 5;

struct node {
	int x;
	int y;
	int v;
}r[maxn];

int n,m;
int f[maxn];

bool cmp(node a,node b){
	return a.v < b.v;
}

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

int Kruskal(){
	int ans = 0;
	for(int i = 1;i <= n; i++)f[i] = i;
	sort(r+1,r+m+1,cmp);
	for(int i = 1;i <= m; i++){
		int x = find(r[i].x),y = find(r[i].y);
		if(x != y){
			ans += r[i].v;
			f[x] = y;
		}
	}
	return ans;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= m; i++)scanf("%d%d%d",&r[i].x,&r[i].y,&r[i].v);
	int ans = Kruskal();
	printf("%d\n",ans);
} 

Measured memory_bytes: 4408
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
int main()
{
    int n,a,b,iwa=0;
    cin>>n>>a>>b;
    for(int i=1;i<n+1;i++){
        if(i/10000+(i%10000)/1000+(i%1000)/100+(i%100)/10+i%10>=a&&i/10000+(i%10000)/1000+(i%1000)/100+(i%100)/10+i%10<=b){
            iwa+=i;
        }
    }
        cout<<iwa<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll fact[101010],invfact[101010];
ll comb(int n,int k){
  ll ret=invfact[n-k]*invfact[k]%mod;
  return ret*fact[n]%mod;
  }

ll inv(ll n){
  ll k=mod-2;
  ll ret=1;
  while(k>0){
    if(k%2)ret=ret*n%mod;
    n=n*n%mod;
    k>>=1;
    }
  return ret;
  }
 


int main(){
  int s=101010;
  bool isprime[101010];
  rep(i,s)isprime[i]=true;
  isprime[0]=isprime[1]=false;
  vector<int>prime;
  rep(i,s){
    if(!isprime[i])continue;
    prime.push_back(i);
    for(int j=2*i;j<s;j+=i){
      isprime[j]=false;
      }
    }
    s=prime.size();
    int n,m;cin>>n>>m;
    vector<int> cnt(s);
    rep(i,s){
      while(m%prime[i]==0){
        cnt[i]++;
        m/=prime[i];
        }
      }
    if(m!=1)cnt.push_back(1);
  fact[0]=invfact[0]=1;
  rep(i,101000){
    fact[i+1]=fact[i]*(i+1)%mod;
    invfact[i+1]=inv(fact[i+1]);
    }
  ll ans=1;
  for(auto e:cnt){
    ans*=comb(n+e-1,e);
    ans%=mod;
    }
  cout<<ans<<endl;
  //cout<<comb(5,2)<<endl;
    
    return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
#define int ll
signed main(){
    int q,h,s,d,n; cin>>q>>h>>s>>d>>n;
    vector<int>v(4);
    v[0]=q;
    v[1]=h;
    v[2]=s;
    v[3]=d;
    int eq[]={8,4,2,1};
    if(n==1){
        int mini=INT_MAX;
        mini=min(q*4,min(h*2,s));
        cout<<mini<<endl;
        return 0;
    }
    int cost=0;
    int mini=INT_MAX;
    rep(i,v.size()){
        if(v[i]*eq[i]<mini){
            mini=v[i]*eq[i];
        }
    }
    while(n>=2){n-=2;cost+=mini;}
    if(!n){cout<<cost<<endl; return 0;}
    mini=INT_MAX;
    rep(i,v.size()){
        if(v[i]*eq[i]/2<mini&&i!=3){
            if(i!=3)mini=v[i]*eq[i]/2;
        }
    }
    
    cost+=mini;
    cout<<cost<<endl;
}


Measured memory_bytes: 256
#import<bits/stdc++.h>
int a,b;
main()
{
scanf("%2d%2d",&a,&b);
puts(a>12?b>12?"NA":b?"YYMM":"NA":a?b>12?"MMYY":b?"AMBIGUOUS":"MMYY":b>12|!b?"NA":"YYMM");
}

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

const ll mod = 1000000007;
const int INF = 1001001001;

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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int h, w; cin >> h >> w;
	int m; cin >> m;
	vector<int> x(h+1), y(w+1);
	set<pair<int, int>> st;
	for(int i = 0; i < m; i++){
		int a, b; cin >> a >> b;
		x[a]++;
		y[b]++;
		st.insert({a, b});
	}
	int xmx = *max_element(x.begin(), x.end()), ymx = *max_element(y.begin(), y.end());
	vector<int> tmpx, tmpy;
	for(int i = 1; i <= h; i++){
		if(x[i] == xmx) tmpx.push_back(i);
	}
	for(int i = 1; i <= w; i++){
		if(y[i] == ymx) tmpy.push_back(i);
	}
	bool ok = false;
	for(int i = 0; i < tmpx.size(); i++){
		for(int j = 0; j < tmpy.size(); j++){
			if(!st.count({tmpx[i], tmpy[j]})){
				ok = true;
				break;
			}
		}
	}
	int ans = xmx + ymx;
	if(!ok) ans--;
	cout << ans << endl;

} 



Measured memory_bytes: 23728
#include<set>  
#include<map>  
#include<stack>  
#include<cmath>  
#include<cstdio>  
#include<queue>  
#include<vector>  
#include<cstring> 
#include<climits>  
#include<iostream> 
#include<algorithm> 
using namespace std; 
int read(){ 
    int f=1,x=0; 
    char c=getchar(); 
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();} 
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();} 
    return f*x; 
}
#define MAXN 100
#define LL long long
#define INF 0x3f3f3f3f
#define MOD int(1e9+7)
int a[MAXN+5];
int main(){
	int n=read(),ans=0,l=1;
	for(int i=1;i<=n;i++){
		a[i]=read();
		if(a[i]!=a[i-1]) ans+=l/2,l=1;
		else l++;
	}
	printf("%d\n",ans+l/2);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926435;

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2LL);
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, k / 2LL);
        tmp *= tmp;
        tmp %= MOD;
        return tmp * n % MOD;
    }
}

map<ll, ll> sosuu(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i] += 1;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] += 1;
    }
    return res;
}

int main()
{
    ll x, y;
    cin >> x >> y;

    bool ok = false;
    for (ll i = 0; i <= x; i++)
    {
        if (i * 2 + (x-i) * 4 == y) {
            ok = true;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3632