akhauriyash/Code-Regression huggingface dataset:
# define _CRT_SECUREj_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

const int M = 100010;



int main()
{
	int n;
	vi a,b;
	cin >> n;
	FOR(i, n)
	{
		INT(x);
		a.push_back(x);
		b.push_back(x);
	}
	sort(ALL(b));
	lint ans = 0;
	FOR(i, n)
	{
		auto it = lower_bound(ALL(b), a[i]);
		a[i] = (int)(it - b.begin());
		if (a[i] % 2 != i % 2)ans++;
	}
	cout << ans/2 << endl;

}

Measured memory_bytes: 1276
#include <stdio.h>
int main(void){
	int h1,m1,h2,m2,k,ans,s,e;
	scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&k);
	s=h1*60+m1;
	e=h2*60+m2;
	ans=e-s-k;
	printf("%d\n",ans);
	return 0;
}

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

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL_DEFINE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
   
#define int long long
typedef pair<int, int> pii;
const int mod = (int) 1000000007;


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	
	int na, nb, m;
	cin >> na >> nb >> m;
	vector<int> a(na + 1), b(nb + 1);
	for(int i = 1; i <= na; ++ i)
		cin >> a[i];
	for(int i = 1; i <= nb; ++ i)
		cin >> b[i];
	int glob = 1e15;
	for(int i = 1; i <= m; ++ i)
	{
		int x, y, c;
		cin >> x >> y >> c;
		int cur = max(0LL, a[x] + b[y] - c);
		glob = min(glob, cur);
	}
	glob = min(glob, *min_element(a.begin() + 1, a.begin() + na + 1) + *min_element(b.begin() + 1, b.begin() + nb + 1));
	cout << glob << '\n';
	
	return 0;
}






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

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

    if (N % 2 == 0)
    {
        long long ans = 0;
        for (int i = 1; i <= 25; i++)
        {
            long long n = N / 2;
            for (int j = 0; j < i; j++)
            {
                n /= 5;
            }
            ans += n;
        }
        cout << ans << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

void operator+=(pii &a, pii &b) {
    a.first += b.first;
    a.second += b.second;
}

struct UnionFind {
    int H, W;
    vector<int> par, rnk;
    vector<pii> cnt;

    UnionFind(int H, int W) : H(H), W(W) {
        int N = H + W;
        par.resize(N);
        rnk.resize(N);
        cnt.resize(N);
        for (int i = 0; i < N; ++i) {
            par[i] = i;
            if (i < H)
                cnt[i].first = 1;
            else
                cnt[i].second = 1;
        }
    }

    int root(int x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x), y = root(y);
        if (x == y)
            return;
        if (rnk[x] < rnk[y])
            swap(x, y);
        if (rnk[x] == rnk[y])
            rnk[x]++;
        par[y] = x;
        cnt[x] += cnt[y];
    }
};

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

    int N;
    cin >> N;
    UnionFind uf(100000, 100000);
    for (int i = 0; i < N; ++i) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        x += 100000;
        uf.unite(x, y);
    }

    ll ans = 0;
    static bool seen[200000];
    for (int i = 0; i < 200000; ++i) {
        int rt = uf.root(i);
        if (!seen[rt]) {
            ans += (ll)uf.cnt[rt].first * uf.cnt[rt].second;
            seen[rt] = true;
        }
    }

    cout << ans - N << endl;

    return 0;
}


Measured memory_bytes: 6512
n = gets.chop.to_i
arr = gets.chop.split.map(&:to_i)

result = 0
min = arr[0]
for i in 0..arr.size-1
  back_row = i == 0 ? i : i-1
  back_number = arr[back_row]
  if arr[i] <= min
    result += 1
    min = arr[i]
  end
end
print result

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


int main(){
    string s;
    cin >> s;
    rep(i, s.size()){
        cout << 'x';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;

	if (s == u) {
		a--;
		cout << a << ' ' << b << endl;
	}
	else {
		b--;
		cout << a << ' ' << b << endl;

	}

	return 0;
}


Measured memory_bytes: 3552
//DavitMarg//
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <bitset>
#include <cassert>
#include <unordered_map>
#include <time.h>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;

int count(int x)
{
	int res = 0;
	while (x)
	{
		res += x % 2;
		x /= 2;
	}
	return res;
}

int n,a[25][25],dp[(1<<21)+10];

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> a[i][j];
	dp[0] = 1;
	for (int mask = 0; mask < (1 << n); mask++)
	{
		int nxt = count(mask);
		for (int i = 0; i < n; i++)
			if (a[i][nxt] && !(mask&(1 << i)))
			{
				dp[mask | (1 << i)] += dp[mask];
				dp[mask | (1 << i)] %= mod;
			}
	}
	cout << dp[(1 << n) - 1] << endl;
	return 0;
}

/**/

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> ab(n);
    rep(i, n) cin >> ab[i].first >> ab[i].second;
    sort(all(ab), [](pair<ll, ll> &a, pair<ll, ll> &b){ return a.first < b.first; });
    auto it = ab.begin();
    priority_queue<ll> pq;
    ll ans = 0;
    rrep(i, m) {
        while((it != ab.end()) && (i <= (m - it->first))) {
            pq.push(it->second);
            it++;
        }
        if (pq.empty()) continue;
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    // rep(i, n) printf("%lld:%lld\n", ab[i].first, ab[i].second);
    return 0;
}


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

int main(void) {
	ll X;
	cin >> X;
	ll R = 100;

	if (X <= 100) {
		cout << 0;
		return 0;
	}

	else {
		for (ll i = 0; i < pow(10, 18) + 2;i++) {
			R = R + (R / 100);
			if (X <= R) {
				cout << i+1;
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;

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

        double ans1 = num * num * Math.PI;
        double ans2 = (num * 2) * Math.PI;

        System.out.println(String.format("%.5f", ans1) + " " + String.format("%.5f", ans2));


    }
}

Measured memory_bytes: 26316
#include<bits/stdc++.h>
#define fori(x,a,b) for (int x=a;x<=b;x++)
#define int long long
using namespace std;
const int maxn=10e5+10;
int n,k,w[maxn],v[maxn],f[101][maxn],oo=127;
main ()
{
    cin>>n>>k;
    int sum=0;
    fori(i,1,n)
    {
        cin>>w[i]>>v[i];
    }

    memset(f,oo,sizeof(f));
    int inf=f[0][0];
    f[0][0] = 0;
    /// f[i][val] = j;
    int res=0;
    fori(i,1,n)
    {
        sum+=v[i];
        fori(j,0,sum)
        {
            f[i][j] = f[i-1][j];
            if (j>=v[i])
            {
                if (f[i-1][j-v[i]]+w[i]<=k)
                {
                    f[i][j] = min(f[i][j],f[i-1][j-v[i]] + w[i]);
                }
            }
            if (f[n][j]!=inf)
            {
                res=max(res,j);
            }
        }

    }
  cout<<res;
}

Measured memory_bytes: 792832
N=int(input())
G=[[] for i in range(N)]
for i in range(N-1):
    u,v,w=map(int,input().split())
    u,v=u-1,v-1
    G[u].append((v,w))
    G[v].append((u,w))
reached=[0]*N
stack=[0]
reached[0]=[1]
res=[-1]*N
res[0]=0
while(stack):
    v=stack.pop()
    for nv,w in G[v]:
        if reached[nv]:
            continue
        if w & 1:
            res[nv]=1-res[v]
        else:
            res[nv]=res[v]
        stack.append(nv)
        reached[nv]=1
for i in res:
    print(i)


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

using namespace std;

int a [100000], m[100000];

int main (){
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);

    int n, t, div = 0, sum = 0;
    bool f = false;

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

    m[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--){
        m[i] = max (m[i + 1], a[i]);
        div = max (div, m[i] - a[i]);
    }

    for (int i = n - 2; i >= 0; i--){
        if (div == m[i] - a[i]){
            sum ++;
        }
    }

    cout << sum;

    return 0;
}


Measured memory_bytes: 1024
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
    auto N = readln.split[0].to!ulong;
    auto A = readln.split.to!(ulong[]);
    N = A.length;
    auto grps = sort(A.dup).group;
    size_t[ulong] nums;
    
    //grps.array.writeln;
    
    foreach (tup; grps) {
        nums[tup[0]] = tup[1];
    }
    //nums.writeln; 
    
    ulong all_num = grps.map!(a => a[1] * (a[1]-1)).sum / 2;
    ulong all_num_true = nums.values.dup.map!(a => a*(a-1)).sum / 2;
    
    int[] re; re.length = N;
    if (all_num != all_num_true) { re[N+1] = 1; }
    /*if (
        all_num != all_num_true || (
            equal( sort(grps.map!(a => a[1]).array), sort(nums.values) ) &&
            !equal( sort(grps.map!(a => a[1] * (a[1]-1)).array), sort(nums.values.map!(a => a * (a-1)).array) )
        )
    ) {
        if (all_num_true > all_num) re[N+1] = 1;  // RE
        else if (all_num_true < all_num) writeln("aaa");   // WA
        else while (true) { writeln("tle"); }    // TLE
    }*/
    
    foreach (k; 0 .. N) {
        writeln( all_num_true - (nums[A[k]] - 1) );
    }
}



Measured memory_bytes: 26512
//AOJ0077からやること
#include<stdio.h>

int main(){
    int i,j;
    char s[100];

    while(scanf("%s",s)!=EOF){
        for(i=0;s[i]!='\0';i++){
            if(s[i]=='@'){
                for(j=0;j<s[i+1]-'0';j++)printf("%c",s[i+2]);
                i++;
                i++;
            }else{
                printf("%c",s[i]);
            }
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
int main(){
    double r, s, l;
    double PI = 3.14159265359;
    std::cin >> r;
    s = r*r*PI;
    l = 2*r*PI;
    std::cout << std::fixed << std::setprecision(5) << s << " " << l << std::endl;
}


Measured memory_bytes: 3208
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;

int main(){
	string s, w;
	int cnt=0, i;

	cin>>w;
	int l=w.size();

	for(i=0; i<l; i++){
		if(w[i]>='A' && w[i]<='Z')s[i]+=('a'-'A');
	}

	while(cin>>s){
		if(s=="END_OF_TEXT")break;
		int l=s.size();
		for(int i=0; i<l; i++){
			if(s[i]>='A' && s[i]<='Z')s[i]+=('a'-'A');
		}
		if(s==w){
			cnt+=1;
		}
	}
	cout<<cnt<<endl;


	return 0;
}


Measured memory_bytes: 3172
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int ac = 0;
		int wa = 0;
		int tle = 0;
		int re = 0;

		for(int i = 0;i<=a;i++) {
			String b = sc.nextLine();
			if(b.equals("AC")) {
				ac++;
			}
			if(b.equals("WA")) {
				wa++;
			}
			if(b.equals("TLE")) {
				tle++;
			}
			if(b.equals("RE")) {
				re++;
			}
		}
		System.out.println("AC x "+ac);
		System.out.println("WA x "+wa);
		System.out.println("TLE x "+tle);
		System.out.println("RE x "+re);

	}

}


Measured memory_bytes: 60228
let readAsInt () =
    stdin.ReadLine()
    |> fun s -> (int s.[0..1], int s.[2..3])

let isLikeMonth num = 1 <= num && num <= 12

()
|> readAsInt
|> fun (a, b) ->
    if isLikeMonth a && isLikeMonth b then "AMBIGUOUS"
    else if isLikeMonth a && isLikeMonth b |> not then "MMYY"
    else if isLikeMonth a |> not && isLikeMonth b then "YYMM"
    else "NA"
    |> printfn "%s"


Measured memory_bytes: 29748
import numpy as np
def make_prime(U):
    is_prime = np.zeros(U,np.bool)
    is_prime[2] = 1
    is_prime[3::2] = 1
    M = int(U**.5)+1
    for p in range(3,M,2):
        if is_prime[p]:
            is_prime[p*p::p+p] = 0
    return is_prime, is_prime.nonzero()[0]

lst=make_prime(100004)
n=int(input())
if lst[0][n]==True:
    print(n)
else:
    flag=False
    while flag==False:
        n+=1
        if lst[0][n]==True:
            flag=True
    print(n)

Measured memory_bytes: 12636
import java.util.*;

public class Main {
    public static void main(String...args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] men = new int[n];
        for(int i = 1; i <= n; i++) {
            men[sc.nextInt() - 1] = i;
        }
        StringBuilder sv = new StringBuilder();
        for ( int j : men) {
            sv.append(j + " ");
        }
        System.out.println(sv.toString().trim());
    }

}


Measured memory_bytes: 61756
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        a: [usize;n],
    }

    let mut ans = 100;
    for i in 0..n {
        let mut tmp = a[i];
        let mut cnt = 0;
        loop {
            if tmp%2!=0 {
                break;
            }
            tmp /= 2;
            cnt += 1;
        }
        ans = min(ans, cnt);
    }
    println!("{}", ans);
}


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

const int MAX=100005;

vector<int> A(MAX);
vector<int> parent(MAX);

int root(int a){
    if(parent[a]==a) return a;
    else return parent[a]=root(parent[a]);
}
void unite(int a,int b){
    if(root(a)!=root(b)){
        parent[root(b)]=root(a);
    }
}
bool check(int a,int b){
    if(root(a)==root(b)) return 1;
    else return 0;
}

int main(){
    
    int N,M;cin>>N>>M;
    for(int i=0;i<N;i++){
        cin>>A[i];
        A[i]--;
        parent[i]=i;
    }
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        unite(a,b);
    }
    int cnt=0;
    for(int i=0;i<N;i++){
        if(check(i,A[i])) cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <bitset>

#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define allr(x) x.begin(),x.end(),greater<int>()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
	
	int a,b;
	cin >> a >> b;
	if(a <= 2*b){
		cout << 0 << endl;
	}
	else{
		cout << a - 2*b << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

K = int(input())
MAX = 1000001
a = []
a.append(7 % K)
for i in range(1,K):
    a.append((a[i-1] * 10 + 7) % K)

for i in range(len(a)):
    if a[i] == 0:
        print(i+1)
        exit(0)

print(-1)

Measured memory_bytes: 48552
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
const int maxn = 10010;


int main(){
	long long n,a,b;
	long long cnt = 0;
	//cin >> n >> a >> b;
	scanf("%lld%lld%lld",&n,&a,&b);
	if(a > b) cnt = 0;
	else if(n==1&& a != b) cnt = 0;
	else if(n==1&& a == b) cnt = 1;
	else{
//		long long l = (n-1)*a+b;
//		long long r = a+(n-1)*b;
//		cnt = r-l+1; 
		cnt = (n-2)*(b-a)+1;
	}
	printf("%lld\n",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl
#define all(v) v.begin(), v.end()
#define rsort(v) sort(v.rbegin(), v.rend())


int main() {
  ll N;
  cin >> N;
  ll ans;
  ans = N*(N+1)*(N+2)/6;
  rep(i,N-1) {
    ll u,v;
    cin >> u >> v;
    if (u>v)
      swap(u,v);
    ans -= u*(N-v+1);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 3600
#include"stdio.h"

int main()
{
  int a,b;
  int num;
  scanf("%d%d",&a,&b);
  if(a<b)
    {
      num=a;
      a=b;
      b=num;
    }
  while((num=a%b)!=0)
    {
      a=b;
      b=num;
    }
  printf("%d\n",b);
  return 0;
}



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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n, d, a; std::cin >> n >> d >> a;
  vector<pair<ll, ll>> xh(n); rep(i, n) std::cin >> xh[i].fi >> xh[i].se;
  sort(rng(xh));
  ll sum = 0, ans = 0;
  queue<pair<ll, ll>> que;
  rep(i, n) {
    while (que.size() && que.front().fi+2*d<xh[i].fi)
      sum -= que.front().se*a, que.pop();
    xh[i].se -= sum;
    if (xh[i].se <= 0) continue;
    ll cnt = (xh[i].se+(a-1)) / a;
    sum += cnt * a;
    ans += cnt;
    que.push({xh[i].fi, cnt});
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 4992
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner stdIn = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = stdIn.nextInt();
		double cnt = 0;
		double sum = 0;
		for(int i = 0; i < n; i++) {
			double x = stdIn.nextDouble();
			String u = stdIn.next();
			if(u.equals("BTC")) {
				sum += x;
			}else {
				cnt += x;
			}
		}
		cnt += sum*380000.0;
		out.println(cnt);
		out.flush();
		
	}

}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 22996
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003;

int main()
{
	//File("");
	LL n = gl(), m = gl(), ans = 0;
	if (n == 1 || m == 1) {puts("1"); return 0;} 
	if (n * m % 2 == 1) ans = n * m / 2 + 1;
	else ans = n * m / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  long long int x;
  cin>>x;
  for(long long int i=-1000;i<=1000;i++){
    for(long long int j=-1000;j<=1000;j++){
      if(i*i*i*i*i-j*j*j*j*j==x){
        cout<<i<<" "<<j;
        return 0;
      }
    }
  }
    

}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;

    vector<ll> a;
    a.push_back(Q*4);
    a.push_back(Q*2+H*1);
    a.push_back(H*2);
    a.push_back(S);

    ll mi = INF;
    rep (i, a.size()) {
        mi = min(mi, a[i]);
    }

    if (N % 2 == 0) {
        cout << min(mi*N, D*N/2) << endl;
    } else {
        if (2*mi <= D) {
            cout << mi*N << endl;
        } else {
            cout << D*(N/2) + mi << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
    	String s = ns();
    	String tmp = "";
    	for (int i=0; i<s.length(); i++) {
    		if (s.charAt(i) == 'B') {
    			if (tmp.length() != 0) {
    				tmp = tmp.substring(0, tmp.length() - 1);
    			}
    		} else {
    			tmp += s.charAt(i);
    		}
    	}
    	out.println(tmp);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}


Measured memory_bytes: 8020
n = gets.chomp.to_i

a = gets.chomp.split(" ").map{|i|i = i.to_i}
#pp n
#pp a

m=1
n.times do|i|
  m=m.lcm(a[i])
end

#puts m.to_f
sum=0
n.times do|i|
  sum += m/a[i]
end

puts (m.to_f)/sum

Measured memory_bytes: 3836
#include<stdio.h>
int main(){
	unsigned short set;            	/* 使用できる最大値格納用変数 */
	int tag;            	/* 目標値格納用変数 */
	int mid;            	/* 計算用変数 */
	int agg[100];       	/* 計算結果格納用配列 */
	int i, j;           	/* ループ変数 */
	int input_count = 0;	/* 入力数カウンタ */
	int num_count = 0;  	/* 目標を満足する値のカウンタ */
	
	/* 配列の初期化 */
	for(i = 0;i < 100;i++){
		agg[i] = 0;
	}
	
	/* 数値の入力、演算を無限ループ */
	while(1){
		/* 使用できる最大値、目標値の入力 */
		scanf("%d %d", &set, &tag);
		
		/* 終了処理 */
		if(set == 0 && tag == 0){
			break;
		}
		/* カウンタをリセット */
		num_count = 0;
		
		/* 目標を満足する値をカウント */
		for(i = 1;i < set;i++){
			for(j = i;j <= set;j++){
				/* i + j と目標値の差をmidに代入 */
				mid = tag - (i + j);
				/* midがiとjの間にある場合カウント*/
				if(mid > i && mid < j){
					num_count++;
				}
			}
		}
		
		/* カウントした結果を格納 */
		agg[input_count] = num_count;
		/* 入力数をカウント */
		input_count++;
	}
	
	/* 結果の出力 */
	for(i = 0;i < input_count;i++){
		printf("%d\n", agg[i]);
	}
	
	return 0;
}



Measured memory_bytes: 2036
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <atcoder/modint>
#include <atcoder/convolution>

template <class T>
struct Combination {
    int max_n;
    std::vector<T> f, invf;

    explicit Combination(int n)
        : max_n(n), f(n + 1), invf(n + 1) {
        f[0] = 1;
        for (int i = 1; i <= n; ++i) {
            f[i] = f[i - 1] * i;
        }

        invf[max_n] = f[max_n].inv();
        for (int i = max_n - 1; i >= 0; --i) {
            invf[i] = invf[i + 1] * (i + 1);
        }
    }

    T fact(int n) const { return n < 0 ? T(0) : f[n]; }
    T invfact(int n) const { return n < 0 ? T(0) : invf[n]; }
    T perm(int a, int b) const {
        return a < b || b < 0 ? T(0) : f[a] * invf[a - b];
    }
    T binom(int a, int b) const {
        return a < b || b < 0 ? T(0) : f[a] * invf[a - b] * invf[b];
    }
};

namespace ac = atcoder;

using mint = ac::modint998244353;
const Combination<mint> C(100000);

// マッチングの個数
mint f(int n, int k) {
    return C.perm(n, k * 2) / (mint(2).pow(k) * C.fact(k));
}

void solve() {
    int n;
    std::cin >> n;

    std::map<int, int> cnt;  // 各グループのサイズ
    for (int i = 0; i < n * 2; ++i) {
        int h;
        std::cin >> h;

        if (!cnt.count(h)) cnt[h] = 0;
        ++cnt[h];
    }

    std::queue<std::vector<mint>> que;
    // グループ毎の不正マッチングの数を求める
    for (auto [h, m] : cnt) {
        std::vector<mint> pat;
        for (int k = 0; k * 2 <= m; ++k) {
            pat.push_back(f(m, k));
        }
        que.push(pat);
    }

    // マージ
    while ((int)que.size() > 1) {
        auto p1 = std::move(que.front());
        que.pop();
        auto p2 = std::move(que.front());
        que.pop();
        que.push(ac::convolution(p1, p2));
    }

    auto p = std::move(que.front());

    // 包除原理
    mint ans = 0;
    for (int k = 0; k < (int)p.size(); ++k) {
        ans += mint(-1).pow(k) * p[k] * f(n * 2 - k * 2, n - k);
    }
    std::cout << ans.val() << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 14096
#include<iostream>
using namespace std;
#define ll long long
#define MAMIME ll gcd(ll m1,ll m2){return (m2==0)? m1:gcd(m2,m1%m2);}int main(){ll n,t[10000],smp,ans=1;cin>>n;while(n--){cin>>smp;ans=smp/gcd(ans,smp)*ans;}cout<<ans<<endl;return 0;}




MAMIME





Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <bitset>
#include <string>
#include <set>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <stack>
#include <cstdlib>
#include <numeric>
#include <cassert>
#include <complex>
#include <iterator>
//#include <unordered_map>
using namespace std;
#define maxn 500007
#define maxm 400007
#define maxq 1000007
#define maxl 1234
#define modn 998244353 
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define scanl2(a,b) scanf("%lld%lld",&a,&b)
#define scans(a) scanf("%s",a)
#define scans2(a,b) scanf("%s%s",a,b)
#define scand(a) scanf("%lf",&a)
#define scan2(a,b) scanf("%d%d",&a,&b)
#define scand2(a,b) scanf("%lf%lf",&a,&b)
#define scan3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scan4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scan5(a,b,c,d,e) scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)
#define print(a) printf("%d\n",a);
#define printl(a) printf("%lld\n",a);
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i=a;i>= b;i--)
#define fscan(a) fscanf(stream,"%d", &a);
#define mp      make_pair	
#define pb      push_back
#define eb      emplace_back
#define mm(a,b) memset(a,b,sizeof a)
#define log2(n) (double)(log(n) / log(2.0))
#define _crt_disable_perfcrit_locks
#define bll __int128
#pragma warning(disable:4996)
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef map <char, int> mci;
typedef map <char, char> mcc;
typedef pair <char, int> pci;
typedef complex<double> cd;
typedef vector<complex<double> > vcd;
const double eps = 1e-8;
const double PI = 2 * acos(0.0);

int cc, bb; char ch; inline int F() {
	while (ch = getchar(), (ch < 48 || ch> 57) && ch != '-'); ch == '-' ? cc = bb = 0 : (cc = ch - '0', bb = 1);
	while (ch = getchar(), ch > 47 && ch < 58)cc = (cc << 1) + (cc << 3) + (ch ^ 48); return bb ? cc : -cc;
}
void write(int x) {
	int y = 10, len = 1;
	while (y <= x) { y *= 10; len++; }
	while (len--) { y /= 10; putchar(x / y + 48); x %= y; }
}
ll pow2(ll a, ll b, ll mod) {
	ll r = 1, base = a;
	while (b) {
		if (b & 1) r = r * base % mod;
		base = base * base % mod;
		b >>= 1;
	}
	return r;
}
ll inv(ll a, ll n) {
	return pow2(a, n - 2, n);
	//return pow2(a, oula(n) - 1, n);
}
ll gcd(ll a, ll b) {
	ll r;
	while (b != 0) {
		r = a % b;
		a = b;
		b = r;
	}
	return a;
}
int GCD[207][207];
int main() {
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	//FILE* stream = fopen("L:/20.in", "rb+")
	int k;
	cin >> k;
	for (int i = 1; i <= 200 ; i++){
		for (int j = 1; j <= 200 ; j++){
			GCD[i][j] = gcd(i, j);
		}
	}
	ll res = 0;
	rep(i, 1, k) {
		rep(j, 1, k) {
			rep(l, 1, k) {
				res += GCD[i][GCD[j][l]];
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3836
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
int ups(const void*a, const void*b){return strcmp((char*)a,(char*)b);}

char s[5010];
char ss[30000][8];
int main(){
	int k;
	scanf("%s%d",s,&k);
	int n=strlen(s);
	int cnt=0;
	rep(i,0,n)rep(j,0,5){
		rep(kk,0,j+1)ss[cnt][kk]=s[i+kk];
		cnt++;
	}
	qsort(ss,cnt,8,ups);
		
	if(k==1){
		puts(ss[0]);
		return 0;
	}
	int num=1,pre=0;
	rep(i,1,cnt){
		if(strcmp(ss[pre],ss[i])){
			num++;
			pre=i;
			if(num==k){
				puts(ss[i]);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 508
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};
const int NMAX=500000;
mint fact[NMAX],infac[NMAX];
void Make_Fact(){
  fact[0]=fact[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    fact[i]=fact[i-1]*(mint)i;
  }
}
void Make_InvFact(){
  infac[0]=infac[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    infac[i]=infac[i-1]/(mint)i;	
  }
}
mint Comb(int n,int k){
  if(n<0||k<0||n-k<0) return 0;
  return fact[n]*infac[k]*infac[n-k];
}

int main()
{
  Make_Fact();
  Make_InvFact();
  ll n,k;
  cin >> n >> k;
  if(k>=n-1){
    cout << Comb(2*n-1,n).x << "\n";
  }
  else{
    mint res;
    rep1(i,k){
      res += Comb(n-1,n-i-1)*Comb(n,i);
    }
    if(k!=1) res += (mint)1;
    cout << res.x << "\n";
  }
  return 0;
}


Measured memory_bytes: 8064
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int Y = scn.nextInt()/1000;
		boolean can = false;
		for(int i = 0;i < N+1 && !can;i++) {
			for(int j = 0;j < N-i+1;j++) {
				int k = N-i-j;
				if(10*i + 5*j + k == Y) {
					can = true;
					System.out.println(i + " " + j + " " + k);
				}
			}
		}
		if(!can)System.out.println(-1 + " " + -1 + " " + -1);
	}

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
static const int MAX=100000;
static const int NIL=-1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r,int c)
{
    stack<int> S;
    S.push(r);
    color[r]=c;
    while(!S.empty())
    {
        int u=S.top();
        S.pop();
        for(int i=0;i<G[u].size();i++)
        {
            int v=G[u][i];
            if(color[v]==NIL)
            {
                color[v]=c;
                S.push(v);
            }
        }
    }
}

void assignColor()
{
    int id=1;
    for(int i=0;i<n;i++)color[i]=NIL;
    for(int u=0;u<n;u++)
    {
        if(color[u]==NIL)dfs(u,id++);
    }
}

int main()
{
    int s,t,m,q;

    cin>>n>>m;

    for(int i=0;i<m;i++)
    {
        cin>>s>>t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    assignColor();

    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>s>>t;
        if(color[s]==color[t])
        {
            cout<<"yes"<<endl;
        }else
        {
            cout<<"no"<<endl;
        }
    }
 	return 0;
}



Measured memory_bytes: 8896
#include<stdio.h>
void main()
{
  int a,b,c,d,i=1;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  while(a>0 && c>0)
  {
    if(i%2==1)
    {
      c=c-b;
    }
    else
    {
      a=a-d;
    }
    i++;
  }
 if(a<=0)
   printf("No");
 else
   printf("Yes");
}

Measured memory_bytes: 1732
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
    int s,k,ans=0;
    cin>>k>>s;
    for(int x=0;x<=k;x++)
    	for(int y=0;y<=k;y++){
    		if(x+y>s)
    			break;
    		if(s-x-y<=k)
    			ans++;
		}
	cout<<ans; 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

int n, k, arr[300005], ans;

struct node {
	int s, e, m, v;
	node *l, *r;
	node (int S, int E) {
		s = S, e = E, m = (s+e)/2, v = 0;
		if (s != e) {
			l = new node(s, m);
			r = new node(m+1, e);
		}
	}
	void up(int x, int nv) {
		if (s == e) {v = nv; return;}
		else if (x <= m) l->up(x, nv);
		else r->up(x, nv);
		v = max(l->v, r->v);
	}
	int query(int x, int y) {
		if (s == x and e == y) return v;
		else if (y <= m) return l->query(x, y);
		else if (x > m) return r->query(x, y);
		else return max(l->query(x, m), r->query(m+1, y));
	}
} *seg;

int main() {
	fastio; cin >> n >> k;
	seg = new node(0, 300000);
	FOR(i, 1, n) {
		cin >> arr[i];
		int x = seg->query(max(0, arr[i]-k), min(300000, arr[i]+k)) + 1;
		ans = max(ans, x);
		seg->up(arr[i], x);
	}
	cout << ans;
}


Measured memory_bytes: 32964
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define MOD2 1000000009
#define sp fixed<<setprecision
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll add(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD + b%MOD + MOD)%MOD;}
ll sub(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD - b%MOD + MOD)%MOD;}
ll mul(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return ((a%MOD)*(b%MOD) + MOD)%MOD;}
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (sz(name)) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
int main(){
    setIO();
    ll n;
    cin>>n;
    ll sum = 0,res = 0;
    vector<ll>v(n);
    for(int i=0;i<n;i++){
      cin>>v[i];
      sum=add(sum,v[i]);
    }
    for(int i=0;i<n;i++){
      res = add(res,mul(v[i],sub(sum,v[i])));
    }
    res = mul(res,inv(2));
    cout<<res;

}


Measured memory_bytes: 4772
#include<bits/stdc++.h>
using namespace std;
int main()
{
	
	int x;
	cin>>x;
	for(int i=1;i<=x;i++)
		if(i*360%x==0)
		{
			cout<<i*360/x<<'\n';
			return 0;
		}
	
	return 0;
}

Measured memory_bytes: 3588
// D.

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>

using namespace std;

static const long long MOD = 1000000007;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	string s[2];
	cin >> s[0] >> s[1];
	int st = -1;
	long long ans = 1;
	for (int i = 0; i < n; ++i) {
		if (s[0][i] == s[1][i]) {
			switch (st) {
			case 1:
				ans *= 2;
				break;
			case 2:
				break;
			default:
				ans = 3;
				break;
			}
			st = 1;
		} else {
			switch (st) {
			case 1:
				ans *= 2;
				break;
			case 2:
				ans *= 3;
				break;
			default:
				ans = 6;
				break;
			}
			st = 2;
			++i;
		}
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)

int main(){
  int n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  a--;b--;c--;d--;
  string s;
  cin>>s;
  /*if(a>c || b>d){
    cout<<"No"<<endl;
    return 0;
  }
  if(a>b){
    swap(a,b);
    swap(c,d);
  }*/
  if(c<d){
    rep(i,a,d){
      if(s.at(i)=='#' && s.at(i+1)=='#'){
	cout<<"No"<<endl;
	return 0;
      }
    }cout<<"Yes"<<endl;
    return 0;
  }
  rep(i,a,c){
    if(s.at(i)=='#' && s.at(i+1)=='#'){
      cout<<"No"<<endl;
      return 0;
    }
  }
  rep(i,b,d+1){
    if(i>0 && i<n-1 && s.at(i-1)=='.' && s.at(i)=='.' && s.at(i+1)=='.'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>

int cards[10];

int k;
bool DFS(int i){
    if (i>k)
        return cards[3]>cards[2]&&cards[2]>cards[1];

    bool ret=false;
    for(int k=1;k<=3;k++){
        cards[k]*=2;
        if (ret=DFS(i+1))
            break;
        cards[k]/=2;
    }

    return ret;
}

int main(){

    for(int i=1;i<=3;i++) scanf("%d",cards+i);

    
    scanf("%d",&k);

    if (DFS(1))
        puts("Yes");
    else 
        puts("No");


    return 0;
}

Measured memory_bytes: 1620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=3000+10;
inline ll quick_pow(ll base,ll n,ll mod) {
	ll ans=1;
	while(n) {
		if(n&1ll)
			ans=ans*base%mod;
		base=base*base%mod;
		n>>=1;
	}
	return ans;
}
ll c[maxn][maxn];
ll g[maxn][maxn];
int main() {
	ll n,mod;
	scanf("%lld%lld",&n,&mod);
	for(int i=1; i<=n; i++) {  //求组合数
		c[i][0]=1;
		c[i][i]=1;
		for(int j=1; j<i; j++)
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	for(int i=0; i<=n; i++) {   //求g[i][j]
		g[i][0]=1;
		for(int j=1; j<=i; j++)
			g[i][j]=(g[i-1][j-1]+g[i-1][j]*(j+1)%mod)%mod;
	}
	ll ans=0;
	for(int i=0; i<=n; i++) {            //直接套公式
		ll k=c[n][i];
		if(i&1)
			k=(mod-k)%mod;
		ll kind=quick_pow(2,n-i,mod);
		ll x=quick_pow(2,n-i,mod-1);     //注意这里的模数
		x=quick_pow(2,x,mod);
		ll cnt=0,y=1;
		for(int j=0; j<=i; j++) {
			cnt=(cnt+(g[i][j]*y%mod))%mod;
			y=kind*y%mod;
		}
		ans=(ans+(k*cnt%mod*x%mod))%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 139904
#include <sstream>
#include <iostream>
#include <cstdlib>

using namespace std;
 
int main(){
    
   string  s;
    cin >> s;
    int sum; 
    for (int i = 0; i < 3; i++)
    {
    		if (s[i] == '1')
    				sum++;
    }
    cout << sum << endl;;
   return 0;
}

Measured memory_bytes: 256