akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 31)
using namespace std;

int main(){
    string s;
    map<char, int> m;
    cin >> s;
    rep(i,s.size()){
        m[s[i]]++;
    }
    cout << min(min(m['K'],m['U']), min(m['P'],m['C'])) << endl;
}

Measured memory_bytes: 1192
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 6666
int n,a[SZ],an=0,b[SZ],bn=0,fy[SZ]; char s[SZ];
string ss[SZ]; int sn=0;
string work(int l,int r)
{
	int tl=-1,tr;
	for(int g=1;g<=n;++g)
		if(a[g]>=l&&a[g]<=r)
		{
			if(tl==-1) tl=g; tr=g;
		}
	if(a[tl]<b[tl])
	{
		int cp=0; string op="";
		for(int i=tl;i<=tr;++i)
			if(cp<a[i]) op=op+"ab",cp=b[i];
		return op;
	}
	string mx="";
	for(int i=tl;i<=tr;++i)
	{
		string c="";
		for(int j=l;j<=r;++j)
			if(fy[j]>=i) c.pb(s[j]);
		mx=max(mx,c);
	}
	return mx;
}
string f[SZ];
int main()
{
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=n+n;++i)
	{
		if(s[i]=='a') a[++an]=i,fy[i]=an;
		else b[++bn]=i,fy[i]=bn;
	}
	int cl=1,cs=0;
	for(int i=1;i<=n+n;++i)
	{
		if(s[i]=='a') ++cs; else --cs;
		if(!cs) ss[++sn]=work(cl,i),cl=i+1;
	}
	for(int i=sn;i>=1;--i)
		f[i]=max(ss[i]+f[i+1],f[i+1]);
	cout<<f[1]<<"\n";
}


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

using namespace std;


int main()
{
	int k; cin >>k;
	int a,b; cin >> a >> b;
	for(int i = a; i <= b; i++){
		if(i%k == 0){
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
	return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <math.h>
#define abs(x) ((x)<0 ? -(x) : (x))
#define PI 3.1415926535897

int main(){
  double a, b;  scanf("%lf %lf", &a, &b);
  int h, m;  scanf("%d %d", &h, &m);

  double radi = (double)abs((m*0.5+h*30) - (m*6));
  long double coss = cosl(PI * radi/180);

  long double ans = (long double)(a*a + b*b - 2*a*b*coss);
  ans = sqrtl(ans);
  
  printf("%.14Lf\n", ans);
  return 0;
}
  
  


Measured memory_bytes: 2584
n = int(input())
A = [list(map(int, input().split())) for i in range(n)]
p = 10**9+7
DP = [-1 for s in range(1 << n)]
DP[0] = 1
def dp(s, l):
    if DP[s] != -1:
        return DP[s]
    tmp = 0
    for i in range(n):
        if s & (1 << i) and A[l-1][i]:
            tmp += dp(~(1 << i) & s, l-1)
    DP[s] = tmp % p
    return DP[s]
print(dp((1 << n)-1, n))


Measured memory_bytes: 123496
#include <stdio.h>
int main()
{
	int a[100],b[100],c[100];
	int N,sum=0;
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=N;i++)
	{
		scanf("%d",&b[i]);
	}
	for(int i=1;i<=N;i++)
	{
		c[i]=a[i]-b[i];
		if(c[i]>0)
		{
			sum+=c[i];
		}
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
int main(void)
{
	char s[9];
	scanf("%s", s);
	if (strlen(s) == 2) {
		printf("%s\n", s);
	}
	else {
		printf("%c%c%c\n", s[2], s[1], s[0]);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int sum = 0;
		for(int i = 0; i < N; i++) sum += (sc.nextInt()) - 1;
		System.out.println(sum);
	}
}

Measured memory_bytes: 26984
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn dfs(cur: usize, parent: usize, val: i64, edges: &Vec<Vec<usize>>, answers: &mut Vec<i64>) {
    let val2 = val + answers[cur];
    answers[cur] += val;
    for &to in edges[cur].iter().filter(|&&x| x != parent) {
        dfs(to, cur, val2, edges, answers);
    }
}

fn main() {
    let v = read_vec::<usize>();
    let (n, q) = (v[0], v[1]);
    let mut edges = vec![vec![]; n];
    for i in 0..n - 1 {
        let v = read_vec::<usize>();
        let (a, b) = (v[0] - 1, v[1] - 1);
        edges[a].push(b);
        edges[b].push(a);
    }
    let mut answers = vec![0; n];
    for i in 0..q {
        let v = read_vec::<usize>();
        let (p, x) = (v[0] - 1, v[1] as i64);
        answers[p] += x;
    }
    dfs(0, 0, 0, &edges, &mut answers);
    for ans in answers {
        print!("{} ", ans);
    }
    println!("");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 30664
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n';

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> p(n), q(n),r(n),s(n);
	rep(i, n)cin >> p[i];
	rep(i, n)cin >> q[i];
	r = p;
	sort(r.begin(), r.end());
	s = r;
	int a = 0;
	int b = 0;
	while (p != r) {
		next_permutation(r.begin(), r.end());
		a++;
	}
	sort(r.begin(), r.end());
	while (q != s) {
		next_permutation(s.begin(), s.end());
		b++;
	}
	cout << abs(b - a);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
//const int MODINF = 1000000007;
//const int64_t INF = 998244353;
using namespace std;

int main(){
    string S, T;
    cin >> S;
    T = S;
    reverse(all(T));
    int count = 0;
    rep(i, 0, S.size()/ 2){
        if(S.at(i) != T.at(i)) count++;
    }
    cout << count << endl;
}

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

using namespace std;

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

typedef long long ll;

void solve(){
	int n;
	cin >> n;
	vector<vector<int>> suc(n+1);
	for(int i = 2; i <= n; ++i) {
		int value;
		cin >> value;
		suc[value].emplace_back(i);
	}
	
	for(int i = 1; i <= n; ++i) {
		cout << suc[i].size() << "\n";
	}
}

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

	solve();
    
    return 0;
}


Measured memory_bytes: 14228
#include <stdio.h>
int main(){
    
    int a,b,k;
    
    scanf("%d" , &k);
    scanf("%d %d" , &a, &b);
    
    for(int i = a ; i <= b ; i++){
        if(i % k == 0){
            printf("OK");
            return 0;
          }
    }
    printf("NG");    
    return 0;
}

Measured memory_bytes: 1700
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			// 整数の入力
			long a = sc.nextLong();
			long b = sc.nextLong();
			long c = sc.nextLong();
			System.out.println(a + b + c >= 22 ? "bust" : "win");
		}
	}
}


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

int main(){
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  int M;
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++) {
    cin >> t.at(i);
  }

  int ans=0;
  for (int i = 0; i < N; i++) {
    int sum=0;
    for (int j = 0; j < N; j++) {
      if(s.at(i)==s.at(j)) sum++;
    }
    for (int j = 0; j < M; j++) {
      if(s.at(i)==t.at(j)) sum--;
    }
    ans=max(ans,sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
if n == 1 and m == 1:
    ans = 1
elif n == 1 and m != 1:
    ans = m-2
elif n != 1 and m == 1:
    ans = n-2
else:
    ans = n * m
    ans -= 2*n
    ans -= 2*m
    ans += 4
print(ans)

Measured memory_bytes: 61884
#include <bits/stdc++.h>
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);

int main () {
  int n = in();
  int ans = 0;
  
  for (int i = 1; i <= n; ++i) {
    if (to_string(i).size()%2 != 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

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

  map<ll, bool> ans;
  for (ll i = 1; i <= n/2; ++i) {
    if ((n-i)*2 == n) continue; 
    ans[n-i] = true;
  }

  cout << ans.size() << endl;
  
  return 0;
}

Measured memory_bytes: 31488
import java.util.Scanner;
import java.util.HashMap;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    String[] w = scanner.nextLine().split("");
    
    // 何種類文字があるのか
    HashMap<String, Integer> map = new HashMap<>();
    for(String word: w) {
      Integer num = map.get(word);
      if(num == null) {
        map.put(word, 1);
      } else {
      	map.put(word, num + 1);
      }
    }
        
    // その文字が2で割り切れる数あるかどうか
    boolean flg = true;
    for(String key : map.keySet()) {
      if(map.get(key) % 2 != 0) {
        flg = false;
      }
    }
    if(flg) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 35624
#include<stdio.h>
int main() {
	int n,i,p,q,r,P,Q,R,C,x,y=0;
	int a[1000][5]={0};
	while(scanf("%d",&n) && n!=0){
		for(x=0; x<n; x++){ 
			scanf("%d %d %d %d",&i,&p,&q,&r); 
			a[x][0]=i;
			a[x][1]=p;
			a[x][2]=q;
			a[x][3]=r;
			a[x][4]=p*4+q*9+r*4;
		}
		scanf("%d %d %d %d",&P,&Q,&R,&C);
		for(x=0; x<n; x++){
			if(a[x][1]<=P){
				if(a[x][2]<=Q){
					if(a[x][3]<=R){
						if(a[x][4]<=C){
							y=1;
							printf("%d\n",a[x][0]);
						}
					
				} 
				}
			}
		}
			if(y==0)
				printf("NA\n");
			y=0;
		}
		return 0;
}

Measured memory_bytes: 1068
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = max({a * c, a * d, b * c, b * d});
  cout << ans << endl; 

  return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

int H, W, A, B;

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
 cin >> H >> W;
 map<int,int> c2v;
 multiset<int> v;
 // if(c2v.lower_bound(22) == c2v.end()) cout<<"hello";
 rep(i,W) {
   c2v[i]=0;
   v.insert(0);
 }

 rep(i, H) {
   cin >> A >> B;
   A--;B--;
   auto it = c2v.lower_bound(A);
   while(it != c2v.end() && it->first <= B) {
     if((B+1) < W && c2v.count(B+1) == 0) {
       c2v[B+1] = it->second + B - it->first+1;
       v.insert(c2v[B+1]);
     }

     if((B+1) < W && ((it->second + B - it->first+1) < c2v[B+1])) {
       v.erase(v.find(c2v[B+1]));
       c2v[B+1] = it->second + B - it->first+1;
       v.insert(c2v[B+1]);
     }
     v.erase(v.find(it->second));
     c2v.erase(it);
     
     it = c2v.lower_bound(A);
   }
   if(v.size() == 0) cout<<-1<<endl;
   else cout<<*v.begin() + i + 1 << endl;
 }

 return 0;
}


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

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(100001);
    rep(i,n){
        int m;
        cin >> m;
        a[m]++;
    }
    int q;
    cin >> q;
    ll sum =0;
    for(int i=1;i<=100001;i++){
        if(a[i]!=0){
            sum += i*a[i];
        }
    }
    rep(i,q){
        int b,c;
        cin >> b >> c;
        int y = a[b];
        a[b] = 0;
        a[c]+=y;
        sum += (c-b)*y;
        
        cout << sum << endl;
    }


    return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S,T;
    cin >> S >> T;
    int N = S.size();
    map<char,char> mp,inv;
    bool ok = true;
    for(int i=0;i<N;i++){
        if(!mp.count(S[i])){
            mp[S[i]] = T[i];
        }
        if(!inv.count(T[i])){
            inv[T[i]] = S[i];
        }
        ok &= mp[S[i]]==T[i];
        ok &= inv[T[i]]==S[i];
    }
    cout << (ok? "Yes\n":"No\n");
}

Measured memory_bytes: 916
from collections import deque


N,M=list(map(int,input().split()))
graph=[[] for _ in range(N+1)]
for _ in range(M):
    a,b,c=map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
    
#seen[i]は、頂点iを訪問済みの場合はTrue、未訪問の場合はFalse
seen=[False]*(N+1)


count=0

for i in range(1,N+1):
    if seen[i]==False:
        seen[i]=True
        S=deque([i])
        
        while S:
            v=S.popleft()
            #訪問済みの頂点をTrueにする
            for i in graph[v]:
                if seen[i]==False:
                    seen[i]=True
                    S.append(i)
        count+=1

print(count)

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

const int MAXN = 100005; 
typedef pair <int, int> pii; 
vector <pii> edges [MAXN]; 
int cnt [16]; 
int dp [(1 << 16)]; 
int dfs (int node, int p = 0){
	int tot_xor = 0; 
	for (pii edge : edges[node]){
		if(edge.first==p) continue; 
		int sub_xor = dfs(edge.first, node); 
		cnt [sub_xor ^ edge.second]++; 
		
		tot_xor ^= (edge.second); 
	}
	return tot_xor; 
}
int main() {
	ios_base::sync_with_stdio(0); 
	int n; cin >> n; 
	for (int i=0; i<n-1; i++){
		int u, v, w; cin >> u >> v >> w; 
		u++; v++; 
		
		edges[u].push_back(pii(v, w)); 
		edges[v].push_back(pii(u, w)); 
	}
	
	dfs(1);
	
	cnt[0]=0; 
	
	int ans=0; 
	for (int i=0; i<16; i++){
		ans += cnt[i]/2; 
		cnt[i]%=2; 
	}
	int ans_msk=0; 
	for (int i=0;i<16; i++){
		if (cnt[i]) ans_msk |= (1 << i); 
	}
	for (int i=1; i<=ans_msk; i++){
		int cur_xor=0; 
		for (int j=0; j<16; j++){
			if (cnt[j]){
				if ((1 << j) & i) continue; 
				cur_xor ^= j; 
			}
		}
		if ((1 << cur_xor) & i){
			dp[i] = dp[i ^ (1 << cur_xor)]; 
		}
		else{
			int an=1e9; 
			for (int j=0; j<16; j++){
				if ((1<<j) & i) an = min(an, 1 + dp[(1 << j) ^ i]); 
			}
			dp[i] = an; 
		}
	}
	cout << ans + dp[ans_msk] << '\n'; 
	return 0;
}

Measured memory_bytes: 16724
using System;
using System.Linq;

class Program {
  static void Main() {
    var e = Console.ReadLine().Split().Select(int.Parse).ToArray();
    Array.Sort(e);
    if (e[0] == e[1] && e[2] == e[3]) {
      Console.WriteLine("yes");
    } else {
      Console.WriteLine("no");
    }
  }
}


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

using namespace std;

bool is_palindrome(string s, int i, int j) {
    while (s[i] == s[j]) {
       i++; j--;
    }
    return j <= i;
}

int main() {
    string s;

    cin >> s;
    int n = (int)s.size();

    if (is_palindrome(s, 0, n - 1) &&
        is_palindrome(s, 0, (n - 1) / 2 - 1) &&
        is_palindrome(s, (n + 3) / 2 - 1, n - 1))
        puts("Yes");
    else
        puts("No");

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;
using ll = long long;

ll lcd(ll a, ll b) {
	if (a < b) {
		swap(a,b);
	}
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int main() {
	ll N, X;
	cin >> N >> X;
	ll ans;
	vector<ll> x(N,0);
	for (int i=0; i<N; ++i) {
		cin >> x[i];
		x[i] = abs(x[i] - X); 
		if (i==0) { 
			ans = x[0];
			continue;
		}
		ans = lcd(x[i], ans);
	}	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll)(a.size())
#define pll pair<ll,ll>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for(i=a;i<b;i++)
const ll L = 2e5+1;
ll visited[L];
ll cnt;
vector<ll> ad[L];
void dfs(ll x)
{
	visited[x] = 1;
	ll i;
	cnt++;
	for(i=0;i<sz(ad[x]);i++)
		if(!visited[ad[x][i]])
			dfs(ad[x][i]);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll i,j,k,n,m,u,v;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>u>>v;
		ad[v].pb(u);
		ad[u].pb(v);	
	}
	ll ans = 0;
	for(i=1;i<=n;i++)
	{
		if(!visited[i])
		{
			cnt = 0;
			dfs(i);
			ans = max(ans, cnt);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(void)
{
  long int a, g, h, i, j, k, l, m, n, o, p;
  long int num, count = 0;
  
  scanf("%ld", &a);
  
  for( g = 0; g < 10; g++ ){
    for(  h= 0; h < 10; h++ ){
      for(  i= 0; i < 10; i++ ){
        
        for(  j= 0; j < 10; j++ ){
          
          for(  k= 0; k < 10; k++ ){
            if( abs(g-h) > 1 && g!=0){
          break;
        }
            for(  l= 0; l < 10; l++ ){
              if( abs(h-i) > 1 && g+h > 0){
            break;
          }
              for(  m= 0; m < 10; m++ ){
                if( abs(i-j) > 1 && g+h+i > 0){
            break;
          }
                for(  n= 0; n < 10; n++ ){
                   if( abs(j-k) > 1 && g+h+i+j > 0){
            break;
          }  
                  for(  o= 0; o < 10; o++ ){
                    if( abs(k-l) > 1 && g+h+i+j+k > 0){
            break;
          }      
                     
                    for(  p= 0; p < 10; p++ ){
                      if( abs(l-m) > 1 && g+h+i+j+k+l > 0){
                    break;
                  }
                      num = p + 10*o + 100*n + 1000*m + 10000*l + 100000*k + 1000000*j + 10000000*i + 100000000*h + 1000000000*g; 
                       
                      if( abs(m-n) < 2 || (g==0&&h==0&&i==0&&j==0&&k==0&l==0&&m==0) ){
                      if( abs(n-o) < 2 || (g==0&&h==0&&i==0&&j==0&&k==0&l==0&&m==0&&n==0) ){
                      if( abs(o-p) < 2 || (g==0&&h==0&&i==0&&j==0&&k==0&l==0&&m==0&&n==0&&o==0) ){
                        if( num > 0 ){
                          count++;

                         //printf("%ld\n", num);
                          if( count == a ){
                            printf("%ld\n", num);
                            return 0;
                          }
                        }
                      }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 int main(){
 
   int i,j,n;
   scanf("%d", &n);
 
   for ( i = 1 ; i <= n ; i++ ){
 
     if ( i % 3 == 0 ){
       printf(" %d", i);
       continue;
     }
     j = i;
      
     while(1){
       if ( j % 10 == 3 ){
     printf(" %d", i);
     break;
       }
       j /= 10;
       if ( j == 0 ) break;
     }
 
   }
 
   printf("\n");
    
   return 0;
 
 }

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

using namespace std;

typedef long long ll;

const int N = 1e8;
const int INF = 1e9;
const int MOD = 1e9 + 7;


int main() {
    string s, pre, cur;
    cin >> s;
    pre = cur = "";
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        cur += s[i];
        if (cur != pre) {
            ans++;
            pre = cur;
            cur = "";
        }
    }
    cout << ans;
}

Measured memory_bytes: 644
S=input()
l=len(S)
ls=''
for i in range(1,l):ls+=str(i)
sa=['']*(2*l-1)
for i in range(len(sa)):
    if i%2==0:
        sa[i]=S[i//2]

import copy
import itertools as it
ans=0
for i in range(l):
    for j in list(it.combinations(ls, i)):
        sx=copy.copy(sa)
        for k in j:
            k=int(k)
            sx[2*k-1]='+'
        ans+=eval(''.join(sx))
print(ans)

Measured memory_bytes: 9232
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin>>n>>s;
    if(n%2==1){
        cout<<"No"<<endl;
        return 0;
    }
    if(s.substr(0,n/2)==s.substr(n/2,n/2)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846

void solve()
{
    int n;cin>>n;
    set<string> s;
    while(n--)
    {
        string x;cin>>x;
        s.insert(x);
    }
    cout<<s.size()<<nl;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  ll n;
  cin >> n;
  ll res = 1;
  for(ll i = 2;i*i <= n;i++){
    if((n%i))continue;
    ll k = i;
    ll m = n;
    while(!(m%k))m /= k;
    if((m%k) == 1)res++;
    k = n/i;
    m = n;
    while(!(m%k))m /= k;
    if((m%k) == 1 && i*i != n)res++;
  }
  n--;
  for(ll i = 2;i*i <= n;i++){
    if((n%i))continue;
    res += 2;
    if(i*i == n)res--;
  }
  if(n != 1)res++;
  cout << res << endl;


  return 0;
}

Measured memory_bytes: 3628
def solve(s):
    if s == "AAA" or s == "BBB":
        return "No"
    else:
        return "Yes"


def main():
    s = input()
    res = solve(s)
    print(res)


def test():
    assert solve("ABA") == "Yes"
    assert solve("BBA") == "Yes"
    assert solve("BBB") == "No"


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <numeric>
#include <limits>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int64_t> A(N), B(N);
    bool zero = true;
    for(int i=0; i<N; i++) {
        cin >> A[i] >> B[i];
        if(A[i] != B[i]) zero = false;
    }

    if(zero) {
        cout << 0 << endl;
    } else {
        int64_t ans = accumulate(A.begin(), A.end(), 0L);
        for(int i=0; i<N; i++) {
            if(A[i] <= B[i]) {
                B[i] -= A[i];
                A[i] = 0;
            }
        }
        int64_t tmp = numeric_limits<int64_t>::max();
        for(int i=0; i<N; i++) {
            if(A[i]) tmp = min(tmp, B[i]);
        }
        cout << ans - tmp << endl;
    }
    return 0;
}


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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(int size) {
        prime.resize(size + 1, 1);
        prime[0] = 0;
        prime[1] = 0;
        FOR(i, 2, size) {
            if (prime[i]) {
                for (int j = 2 * i; j <= size; j += i) {
                    prime[j] = 0;
                }
            }
        }
    }

};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};


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

int N, M;
bool v[101010];

int main() {
    cin >> N >> M;
    v[1] = 1;
    vector<int> num(N + 1, 1);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        num[a]--;
        num[b]++;
        if (v[a])v[b] = 1;
        if (num[a] == 0)v[a] = 0;
    }
    int cnt = 0;
    FOR(i, 1, N)if (v[i])cnt++;
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 768
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int n,m,x,y,a[100005];
bool h[100005];
vector <int> u[100005],k;
int dp[100005],ans=0;
void dfs(int i)
{
	h[i]=1;	
	for(int j=0;j<u[i].size();j++)
	    if(!h[u[i][j]])
	        dfs(u[i][j]);
	k.push_back(i);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&x,&y);
		u[y].push_back(x);
	}	
	for(int i=1;i<=n;i++)    
	    if(!h[i])
	        dfs(i);
	for(int i=0;i<k.size();i++)
    {
    	int f=k[i];
    	//cout<<f<<endl;
    	for(int j=0;j<u[f].size();j++)
    	    dp[f]=max(dp[f],dp[u[f][j]]+1);
    	ans=max(ans,dp[f]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9720
from collections import deque, _heapq
N, K = map(int, input().split())
V = deque(map(int, input().split()))

class Money:
    def __init__(self):
        self.yen = 0
        self.red = []

    def value(self):
        return self.yen + sum(self.red)

    def add(self, yen):
        if yen >= 0:
            self.yen += yen
        else:
            self.red.append(yen)

    def remove(self, yen):
        if yen >= 0:
            self.yen -= yen
        else:
            self.red.remove(yen)

#mny = Money()
def get(cnt, mny, lstop, rstop):
    ans = mny.value()

    if cnt <= 0:
        return ans

    if len(V) > 0:

        if not lstop:
            w = V.popleft()
            mny.add(w)
            ans = max(ans, get(cnt-1, mny, lstop, rstop))
            mny.remove(w)
            V.appendleft(w)

        if not rstop:
            w = V.pop()
            mny.add(w)
            ans = max(ans, get(cnt-1, mny, True, rstop))
            mny.remove(w)
            V.append(w)

    if len(mny.red) > 0:
        w = min(mny.red)
        mny.red.remove(w)

        V.appendleft(w)
        ans = max(ans, get(cnt-1, mny, True, True))
        V.popleft()

        mny.red.append(w)    

    return ans

print(get(K, Money(), 0, 0))


Measured memory_bytes: 44760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  
  cin >> a >> b;
  if ( a*b%2==0 || a*b==0) {
    cout << "Even" << endl;
  }
  else 
    cout << "Odd" << endl;
    
  
}

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  
  int n; cin >> n;
  int sum = 0;
  
  int m = n;
  while (m) {
    sum += m % 10;
    m /= 10;
  }
  
  if (n % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL W = 0;
		ULL ans = 0;
		string S; cin >> S;
		rep(i, S.size()) {
			if (S[i] == 'B') W++;
			else ans += W;
		}
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
#define pi 3.141592653589
using namespace std;
signed main() {
	ll H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << (H - h)*(W - w) << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <iostream>
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{

    int n;
    cin>>n;
    if(n>=30)printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n+1,0);
    for(int i=2; i<=n; i++){
        cin >> a[i];
    }
    vector<int> ans(n+1,0);
    for(int i=1; i<=n; i++){
        ans[a[i]]++;
    }
    for(int i=1; i<=n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4836
package main

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

var sx, sy, tx, ty int

func main() {
	fsc := NewFastScanner()
	sx, sy, tx, ty = fsc.NextInt(), fsc.NextInt(), fsc.NextInt(), fsc.NextInt()
	diffx := tx - sx
	diffy := ty - sy
	for i := 0; i < diffx; i++ {
		fmt.Print("R")
	}
	for i := 0; i < diffy; i++ {
		fmt.Print("U")
	}

	for i := 0; i < diffx; i++ {
		fmt.Print("L")
	}
	for i := 0; i < diffy; i++ {
		fmt.Print("D")
	}
	fmt.Print("D")
	for i := 0; i < diffx+1; i++ {
		fmt.Print("R")
	}
	for i := 0; i < diffy+1; i++ {
		fmt.Print("U")
	}
	fmt.Print("L")

	fmt.Print("U")
	for i := 0; i < diffx+1; i++ {
		fmt.Print("L")
	}
	for i := 0; i < diffy+1; i++ {
		fmt.Print("D")
	}
	fmt.Print("R")
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 896
#include<cstdio>
#include<algorithm>

using namespace std;

int n, ans;
int a[100010];

int main(){
	int x, i;
	scanf("%d", &n);
	for(i = 1; i <= n; ++i){
		scanf("%d", &x);
		a[x]++;
	}
	for(i = 0; i <= 100000; ++i){
		if(i) x = a[i] + a[i-1] + a[i+1];
		else x = a[i] + a[i+1];
		ans = max(x, ans);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#define INF 100001

using namespace std;

int main(){
  int n;
  cin >> n;
  int dp[n+1][n+1],p[n+1];
  cin >> p[0] >> p[1];
  for(int i=2;i<=n;i++){
    int t; cin >> t;
    cin >> p[i];
  }
  for(int i=1;i<=n;i++) dp[i][i]=0;
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      int j=i+l-1;
      dp[i][j]=INF;
      for(int k=i;k<=j-1;k++)
        dp[i][j]=min(dp[i][j], dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j]);
    }
  }
  cout << dp[1][n] << endl;
}

Measured memory_bytes: 3116
n = int(input())
w = list(map(int,input().split()))
s = 0
for i in range(n):
    s = s + w[i]
    
s1 = 0
s2 = 0
ans = 100 * 100

for i in range(n): #i[0,1,2]
    for j in range(0,i + 1):
        s1 += w[j]
        
    s2 = s - s1
    if(ans > abs(s1 -s2)):
        ans = abs(s1 - s2)
    s1 = 0
        
print(ans)


Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(a-c) <= d){
      cout << "Yes" << endl;
      return 0;
    }
    if(abs(a-b) <= d && abs(b-c) <= d){
      cout << "Yes" << endl;
      return 0;
    }
    cout << "No"<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
/*
author : seryu
title : AGC015A_"A+...+B Problem"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans;
	if(a > b)ans = 0;
	else if(n == 1)ans = a==b?1:0;
	else ans = a+b*(n-1)-a*(n-1)-b+1;
	cout << ans << endl;
	return;	
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <algorithm>

using namespace std;

int dfs(int a, int b, int c, int n);
int calcAmount(int a, int b, int c);
int calcValue(int a, int b, int c);

int main() {
    int a, b, c;

    int n;

    while (cin >> n) {
        if(n == 0) break;
        a = 0; b = 0; c = 0;
        
        cout << dfs(a, b, c, n) << endl;
    }

        return 0;
}

int dfs(int a, int b, int c, int n) {
    int amount = calcAmount(a, b, c);

    if(amount == n) {
        return calcValue(a, b, c);
    } else if(amount > n) {
        return INT_MAX;
    } else {
        return min(min(dfs(a+1, b, c, n), dfs(a, b+1, c, n)), dfs(a, b, c+1, n));
    }
}

int calcAmount(int a, int b, int c) {
    return a*200 + b*300 + c*500;
}

int calcValue(int a, int b, int c) {
    a = 380*(a/5)*4 + 380*(a%5);
    b = 550*(b/4)*17/5 + 550*(b%4);
    c = 850*(c/3)*264/100 + 850*(c%3);

    return a+b+c;
}

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

using namespace std;

int main() {
  int D;
  long long G;
  cin >> D >> G;
  vector<int> p(D);
  vector<int> c(D);
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
  }
  int ans = 1000;
  for (int x = 0; x < (1 << D); x++) {
    int s = 0;
    int num = 0;  // # of problems solved
    int rest_max = -1;
    for (int i = 0; i < D; i++) {
      if ((x >> i) & 1) {
        s += 100 * (i + 1) * p[i] + c[i];
        num += p[i];
      } else {
        rest_max = i;
      }
    }
    if (s < G) {
      int v = 100 * (rest_max + 1);
      int rem = (G - s + v - 1) / v;
      if (rem >= p[rest_max]) {
        continue;
      }
      num += rem;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

void solve(int test_case) {
	string o,e;
	cin>>o>>e;
	string ans = "";
	REP(i,0,(int)(o.length()-1)) {
		ans+=o[i];
		if(i<(int)e.length()) {
			ans+=e[i];
		}
	}
	cout<<ans;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


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

const int N=1e5+5;
int v[N];

int main(int argc, char const *argv[])
{
	/* code */
	int n;
	while (cin>>n){
		for (int i=1;i<=n;i++) scanf("%d",v+i);
		int ans=0;
		for (int i=1;i<=n;i++){
			int t=v[i];
			if (v[t]==i) ans++;
		}
		cout<<ans/2<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define lowbit(x) ((x) & (- (x)))
#define rev(x) (((1 << n) - 1) ^ x)
#define R register
using namespace std;
const int N = 15, MAX = 1 << 15, MAX3 = 14348907, INF = 0x3f3f3f3f;
int n,m,su[N+2][MAX],dp[MAX][N + 2],trans[MAX],co[MAX3];
int main()
{
    int x,y,z;
    scanf("%d%d",&n,&m);
    for (int i = 1 ; i <= m ; ++ i)
    {
        scanf("%d%d%d",&x,&y,&z);
        su[x][1 << y >> 1] += z;
        su[y][1 << x >> 1] += z;
    }
    for (int i = 1 ; i <= n ; ++ i)
        for (R int j = 1 ; j < (1 << n) ; ++ j)
            su[i][j] = su[i][j - lowbit(j)] + su[i][lowbit(j)];

    for (R int i = 1 ; i < (1 << n) ; ++ i)
    {
        for (int j = 1, t = 1 ; j <= n ; ++ j, t *= 3)
            if ((i >> j-1)&1) trans[i] += t;
    }

    for (R int i = 1 ; i < (1 << n) ; ++ i)
        for (R int j = rev(i) ; j ; j = (j-1)&rev(i))
        {
            int t = trans[i] + 2 * trans[j];//保持特异性
            for (int k = 1 ; k <= n ; ++ k)
                if ((i >> k-1)&1) co[t] += su[k][j];//i集合与j集合所有边相连的权值和
        }

    memset(dp,0x3f,sizeof dp);
    dp[1][1] = 0;
    for (R int i = 1 ; i < (1 << n) ; ++ i)//遍历所有情况
    {
        for (int j = 1 ; j <= n ; ++ j)//遍历中间点
            if ((i >> j-1)&1)//若中间点在该情况下出现
            {
                if (dp[i][j] == INF) continue;
                for (R int k = rev(i) ; k ; k = (k-1)&rev(i))// k:另一集合
                    if (su[j][k] > 0)//中间边和该集合有相连的
                        dp[i | k][j] = min(dp[i|k][j],dp[i][j]+co[trans[i^(1<<j>>1)]+2*trans[k]]);//将i集合与k集合通过j相连
                if ((i >> n-1)&1) continue;
                for (int k = 1 ; k <= n ; ++ k)//单独加一个点k进去
                    if (!((i >> k-1)&1))//如果该点已经在i集合里跳出
                        if (su[k][1<<j>>1] > 0)//若k点与中间边有相连
                            dp[i|(1<<k>>1)][k] = min(dp[i|(1<<k>>1)][k],dp[i][j]+su[k][i^(1<<j>>1)]);//将集合i与点k通过j相连
            }
    }
    printf("%d\n",dp[(1 << n) - 1][n]);
    return 0;
}


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

template <class Abel> struct BIT {
    const Abel UNITY_SUM = 0;                       // to be set
    vector<Abel> dat;
    
    /* [1, n] */
    BIT(int n) : dat(n + 1, UNITY_SUM) { }
    void init(int n) { dat.assign(n + 1, UNITY_SUM); }
    
    /* a is 1-indexed */
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }
    
    /* [1, a], a is 1-indexed */
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }
    
    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    long long N; cin >> N;
    vector<int> a(N); for (int i = 0; i < N; ++i) cin >> a[i];
    int low = 0, high = 1<<30;
    const int geta = N+1;
    while (high - low > 1) {
        int mid = (low + high) / 2;
        long long num = 0;
        BIT<long long> bit(N*2+10);
        int sum = 0;
        bit.add(sum+geta, 1);
        for (int i = 0; i < N; ++i) {
            int val;
            if (a[i] <= mid) val = 1; else val = -1;
            sum += val;
            num += bit.sum(1, sum+geta);
            bit.add(sum+geta, 1);
        }
        if (num > (N+1)*N/2/2) high = mid;
        else low = mid;
    }
    cout << high << endl;
}

Measured memory_bytes: 5152