akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main{
    public static void main(String[]args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
        String[] arr;
        int n=0;
         
        while((str=br.readLine())!=null){
            if(n==0){
                n=Integer.parseInt(str);
                continue;
            }
            arr=str.split(" ");
            int[] array=new int[n];
 
            for(int i=1;i<=n;i++){
            	array[n-i] = Integer.parseInt(arr[n-i]);
                System.out.print(array[n-i]);
                if(i!=n) System.out.print(" ");
            }
            break;
        }
        System.out.println("");
        br.close();
    }
}

Measured memory_bytes: 16916
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

struct State {
  int point;
  int total_cost;
  int cost2zero_times;
  State(int p) : point(p),total_cost(0),cost2zero_times(0) {}
  State(int p,int tc,int cz)
    : point(p), total_cost(tc),cost2zero_times(cz) {}
  bool operator<(const State& s) const{
    return cost2zero_times < s.cost2zero_times;
  }
  bool operator>(const State& s) const{
    return cost2zero_times > s.cost2zero_times;
  }
};

int dp[101][1001];

int bfs(const vector<P> edges[101],int num_of_nodes,int target_cost){
  int res = INF;
  priority_queue<State,vector<State>,greater<State> > que;
  que.push(State(0));
  while(!que.empty()){
    State s = que.top();
    if(s.point == num_of_nodes - 1 && dp[s.point][s.cost2zero_times] <= target_cost){
      return s.cost2zero_times;
    }
    que.pop();
    for(int edge_i = 0; edge_i < edges[s.point].size(); edge_i++){
      int next = edges[s.point][edge_i].first;
      int cost = edges[s.point][edge_i].second;
      if(dp[next][s.cost2zero_times] > s.total_cost + cost){
        dp[next][s.cost2zero_times] = s.total_cost + cost;
        que.push(State(next,s.total_cost + cost,s.cost2zero_times));
      }
      if(dp[next][s.cost2zero_times + 1] > s.total_cost){
        dp[next][s.cost2zero_times + 1] = s.total_cost;
        que.push(State(next,s.total_cost,s.cost2zero_times + 1));
      }
    }
  }
  return res;
}

int main(){
  int num_of_nodes;
  int num_of_edges;
  int target_cost;
  while(~scanf("%d %d %d",
               &num_of_nodes,
               &num_of_edges,
               &target_cost)){
    if(num_of_nodes == 0 && num_of_edges == 0 && target_cost == 0){
      break;
    }
    memset(dp,0x3f,sizeof(dp));
    vector<P> edges[101];
    for(int edge_i = 0; edge_i < num_of_edges; edge_i++){
      int src,dst,cost;
      scanf("%d %d %d",&src,&dst,&cost);
      src--; dst--;
      edges[src].push_back(P(dst,cost));
    }
    vector<int> current_cost;
    dp[0][0] = 0;
    printf("%d\n",bfs(edges,num_of_nodes,target_cost));
  }
}

Measured memory_bytes: 1648
#include <iostream>
#include<string>
using namespace std;
int main(void){
    string a,b,c,t="a";
    char ans;
    cin>>a>>b>>c;
    while(1){
        if(t=="a"&&a.empty()==1)break;
        if(t=="b"&&b.empty()==1)break;
        if(t=="c"&&c.empty()==1)break;
        if(t=="a"){t=a[0];a=a.substr(1);}
        else if(t=="b"){t=b[0];b=b.substr(1);}
        else{t=c[0];c=c.substr(1);}
    }
    if(t=="a")ans='A';
    else if(t=="b")ans='B';
    else ans='C';
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
void fo (){fflush(stdout);}
using namespace std;
int main ()
{
  int n , m ;
  cin >> n >> m ;
  n += m ;
  n%=24 ;
  cout << n <<"\n";
  //cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr){ sort(arr.begin(), arr.end()); }
template<typename Type> inline void reverse(Type& arr) { reverse(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    bool c = (W == x * 2) && (H  == y * 2);
    printf("%.10lf %d", double(W) * double(H) / 2.0, c ? 1 : 0);
    //
    return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

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

  int N,K;cin>>N>>K;
  vector<int>A(N);
  rep(i,0,N)cin>>A[i];
  sort(all(A));

  map<int,int>m;
  rep(i,0,N){
    m[A[i]]++;
  }

  vector<int>v;
  for(auto x:m){
    v.push_back(x.second);
  }
  sort(all(v));

  if(v.size()<=K){
    cout<<0<<endl;
  }
  else{
    cout<<accumulate(v.begin(),v.begin()+abs(v.size()-K),0ll)<<endl;
  }

  return 0;
}


Measured memory_bytes: 16500
/* Author : Pranav Deshmukh
            PICT,Pune
   Stay Focused!
*/

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define int             long long
#define float           double
#define dip(type,var)   type var; cin>>var;
#define dipi(x)         int x; cin>>x;
#define dipi2(x,y)      int x,y; cin>>x>>y;
#define w(x)            int x; cin>>x; while(x--)
#define mka(type,arr,n) type *arr=new type[n];
#define fo(i,n)         for(int i=0;i<n;i++)
#define mod             pow(10,9)+7
#define inf             1e18
#define pi              3.141592653589793238
#define endl            "\n"
#define F               first
#define S               second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >

void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
	c_p_c();
	dipi(n);
	dipi(a);
	dipi(b);
	int div = n / (a + b);
	int rem = n % (a + b);
	int blue = min(a, rem);
	cout << (div * a) + blue;
	return 0;
}


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

int main() {
    string s;
    long long k;
    cin >> s >> k;
    k--;
    long long n = s.length();
    bool one = false;
    if (k < s.length()) {
        one = true;
        for (int i = 0; i <= k; i++) {
            if (s[i] != '1') {
                one = false;
                break;
            }
        }
    }
    int ans = 1;
    if (!one) {
        for (char ch: s) {
            if (ch != '1') {
                ans = ch - '0';
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
L = sorted(map(int,input().split()))

cnt = 0

for i in range(N-2):
    a = L[i]
    
    for j in range(i+1,N-1):
        b = L[j]
        if a != b:
            
            for k in range(j+1,N):
                c = L[k]
                if b != c & c != a:
                    if a + b > c:
                        cnt += 1
print(cnt)

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

using namespace std;

int main() {
	int k, a, b, c;
	cin >> a >> b >> c >> k;

	int ans = 0;
	ans += min(k, a);
	k -= min(k, a);
	k -= min(k, b);
	ans -= min(k, c);

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 3636
package main

import (
        "fmt"
)

func main() {
        var a [5]int
        var ce int
        for i := 0; i < 5; i++ {
                fmt.Scanf("%d", &a[i])
                ce += ceilInt(a[i])
        }

        ft := 130 * 5
        var t int
        for i := 0; i < 5; i++ {
                t = ce - ceilInt(a[i]) + a[i]
                if t < ft {
                        ft = t
                }
        }
        fmt.Println(ft)
}

func ceilInt(a int) int {
        var c int
        if a % 10 == 0 {
                c = a
        } else {
                c = (a / 10)*10 + 10
        }
        return c
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <map>
#include <string.h>
#include <queue>

using namespace std;

struct bl
{
    int a, b;
    bool operator < (const bl &ano) const
    {
        int m = min(a, b);
        int n = min(ano.a, ano.b);
        return m < n;
    }
};

int n;
int a[200005];
long long ans;

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

    priority_queue<bl> pq;
    bl b;
    b.a = b.b = a[n-1];
    pq.push(b);
    for(int i=n-2; i>=0; i--){
        bl c = pq.top();
        pq.pop();
        ans += min(c.a, c.b);
        bl d;
        d.a = a[i];
        d.b = c.a;
        bl e;
        e.a = a[i];
        e.b = c.b;
        pq.push(d);
        pq.push(e);
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 5620
<?php
$n = intval(fgets(STDIN));
$s = intval(fgets(STDIN));

function f($b, $n){
    if($n < $b)return $n;
    return f($b, intdiv($n, $b)) + $n % $b;
}
if($n == $s){
    echo $n+1;exit;
}
for($i = 2, $I = sqrt($n); $i <= $I; $i++){
    if(f($i, $n) == $s){
        echo $i;exit;
    }
}
$minB = 10**18;
for($p = 1, $P = sqrt($n); $p <= $P; $p++){
    $q = $s - $p;
    if(($n-$q) % $p != 0)continue;
    $b = ($n-$q)/$p;
    if($b >= 2 && f($b, $n) == $s){
        $minB = min($minB, $b);
    }
}
if($minB == 10**18){
    echo -1;
}else{
    printf("%d", $minB);
}

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

#define ll long long
#define P pair<int, int>
#define F first
#define S second

const ll mod = 1000000007LL;

string s, t;
int dp[3001][3001];
void solve() {
  cin >> s >> t;
  ll n = s.length(), m = t.length();

  for (int x = 1; x <= n; x++) {
    for (int y = 1; y <= m; y++) {
      dp[x][y] = max({dp[x - 1][y], dp[x][y - 1],
                      dp[x - 1][y - 1] + (s[x - 1] == t[y - 1])});
    }
  }

  string ans = "";
  int i = n, j = m;
  while (i > 0 && j > 0 && ans.length() < dp[n][m]) {
    ll up = dp[i - 1][j], left = dp[i][j - 1], dia = dp[i - 1][j - 1];
    ll maximum = max({up, left, dia});

    if (maximum == dia && s[i - 1] == t[j - 1]) {
      ans = s[i - 1] + ans;
      i -= 1;
      j -= 1;
    } else if (maximum == left) {
      j -= 1;
    } else {
      i -= 1;
    }
  }
  cout << ans;
}

int main(int argc, char const *argv[]) {

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

  int T = 1;
  while (T--) {
    solve();
  }

  return 0;
}

Measured memory_bytes: 35456
const input = require("fs").readFileSync("/dev/stdin", "utf8")
const N = parseInt(input, 10)

let c = 0
let n = N
for (let i = 2; i * i < n; i++) {
    let _i = i
    while (n % _i === 0) {
        n /= _i
        c++
        _i = _i * i
    }
    while (n % i === 0) {
        n /= i
    }
}

if (n > 1) {
    c++
}
console.log(c)


Measured memory_bytes: 32972
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,h;
  string s;
  while(1){
    cin>>s;
    if(s=="-") break;
    cin>>m;
    for(int i=0;i<m;i++){
      string tmp=s;
      s="";
      cin>>h;
      for(int j=h;j<tmp.size();j++){
	s+=tmp[j];
      }
      for(int j=0;j<h;j++){
	s+=tmp[j];
      }
    }
    cout<<s<<endl;
  }
  return 0;
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    bool fg=false;
    while(n)
    {
        if(n%10==7)
            fg=true;
        n/=10;
    }
    if(fg)
        cout<<"Yes";
    else
        cout<<"No";
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
const ll MOD=1e9+7;
const int MAX = 100;
const int BLACK = 2;
const int GRAY = 1;
const int WHITE = 0;
using namespace std;

int n;
int M[MAX][MAX];

void prim(){
  int color[MAX];
  //d[i] : 自集合からの点iへの最短距離
  int d[MAX];
  //p[i]=s iの親はs
  int p[MAX];
  rep(i,n){
    color[i] = WHITE;
    d[i] = INT_MAX;
    p[i] = -1;
  }
  d[0] = 0;

  while(1){
    int u = -1,minv = INT_MAX;
    rep(i,n){
      if(color[i] != BLACK && minv > d[i]){
        u = i;
        minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;
    rep(v,n){
      if(M[u][v] != INT_MAX && color[v] != BLACK){
        if(d[v] > M[u][v]){
          d[v] = M[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }
  int sum = 0;
  rep(i,n){
    if(p[i] != -1) sum += M[i][p[i]];
  }
  cout << sum << endl;
}

int main(){
  cin >> n;
  rep(i,n){
    rep(j,n){
      int tmp;
      cin >> tmp;
      M[i][j] = (tmp == -1) ? INT_MAX : tmp;
    }
  }
  prim();
}



Measured memory_bytes: 3036
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    int a = 1;
    while(a * a <= n)
        ++ a;

    -- a;
    int ans = a * a;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
int main(){
    while(1){
        int n,x;
        scanf("%d",&n);
        if(n==0)
            break;
        for(int i=0;i<9;i++){
            scanf("%d",&x);
            n-=x;
        }
        printf("%d\n",n);
    }
    return 0;
}

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

int LCS(char X[1000] , char Y[1000]) {
    int Z[1010][1010];
    int MAX = 0;
    int i , j;
    
    int Len_X = strlen(X);
    int Len_Y = strlen(Y);
    
    for(i = 0 ; i <= Len_X ; i++)
        Z[i][0] = 0;
    for(j = 0 ; j <= Len_Y ; j++)
        Z[0][j] = 0;
    
    for(i = 1 ; i <= Len_X ; i++) {
        for(j = 1 ; j <= Len_Y ; j++){
            if(X[i - 1] == Y[j - 1])
                Z[i][j] = Z[i - 1][j - 1] + 1;
            else
                Z[i][j] = (Z[i - 1][j] > Z[i][j - 1]) ? Z[i - 1][j] : Z[i][j - 1];
            
            MAX = (MAX > Z[i][j]) ? MAX : Z[i][j];
        }
    }
    
    return MAX;
}

int main(void)
{
    int q , i;
    
    scanf("%d" , &q);
    
    char X[1000] , Y[1000];
    
    for (i = 0 ; i < q ; i++) {
        scanf("%s" ,X);
        scanf("%s" ,Y);
        
        printf("%d\n" , LCS(X , Y));
    }
    
    return 0;
}



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

int main() {
  int a, b;
  cin >> a >> b;
  if ((a*b/2)*2 < a*b ){
   cout << "Odd" << endl; 
  }
  else {
    cout << "Even" << endl;
  }
  // ここにプログラムを追記
}


Measured memory_bytes: 256
import sys
N=input()
#print N
a=[]
a=map(int,raw_input().split())
#print a

if max(a)==min(a):
	print 0
	sys.exit()
elif abs(max(a))>abs(min(a)):
	num=(max(a),a.index(max(a)))
else:
	num=(min(a),a.index(min(a)))
#print num

ans=[]
for i in range(N):
	a[i]+=num[0]
	ans.append((num[1]+1,i+1))

if num[0]>=0:
	for i in range(N-1):
		ans.append((i+1,i+2))
else:
	for i in range(N,1,-1):
		ans.append((i,i-1))

print len(ans)
for i,j in ans:
	print i,j

Measured memory_bytes: 2696
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif
 
using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	int n = fetch<int>();
	vector<ll> A, B;
	ll curadd = 0;

	for(int i = 0; i < n; ++i) {
		A.push_back(fetch<ll>());
		B.push_back(fetch<ll>());
	}

	for(int i = n - 1; i >= 0; --i) {
		A[i] += curadd;
		ll inc = (B[i] - A[i] % B[i]) % B[i];

		curadd += inc;
	}

	cout << curadd << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


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

int a[100005];
int n;
int main() 
{
  	cin >> n;
  	for (int i = 0; i < n; i++) 
  		cin >> a[i];
  	sort(a, a + n);
    cout<< a[n / 2] - a[n / 2 - 1];

  return 0;
}

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

using namespace std;
int main()
{
    long A;
    long B;
    long C;
    long X;
    long Y;

    cin >> X;
    cin >> Y;
    cin >> A;
    cin >> B;
    cin >> C;

    vector<long> AQ(A);
    vector<long> BQ(B);
    vector<long> CQ(C);

    long ans = 0;

    //   vector<long> ANS(X+Y); 

    for (long i = 0; i < A; i++) {
        cin >> AQ[i];
    }
    for (long i = 0; i < B; i++) {
        cin >> BQ[i];
    }
    for (long i = 0; i < C; i++) {
        cin >> CQ[i];
    }
    sort(AQ.begin(), AQ.end());
    sort(BQ.begin(), BQ.end());
    sort(CQ.begin(), CQ.end());

    reverse(AQ.begin(), AQ.end());
    reverse(BQ.begin(), BQ.end());
    reverse(CQ.begin(), CQ.end());

    AQ.erase(AQ.begin() + X, AQ.end());
    BQ.erase(BQ.begin() + Y, BQ.end());

    AQ.insert(AQ.end(), BQ.begin(), BQ.end());
    AQ.insert(AQ.end(), CQ.begin(), CQ.end());  
    sort(AQ.begin(), AQ.end());
    reverse(AQ.begin(), AQ.end());


//    for (long i = 0; i < (X + Y); i++) {
//        if(((AQ[i]) < CQ[0]) && CQ.size()!=0){
//            AQ[i] = CQ[0];
//            CQ.erase(CQ.begin());
//        }
//    }

    for (long i = 0; i < (X + Y); i++) {
        ans += AQ[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5872
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,a,b = m()

if a > b:
    print(0)
elif n == 1:
    if a == b:
        print(1)
    else:
        print(0)
else:
    print((n-1)*b + a - (b + (n-1)*a) + 1) 


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll ;

const ll inf = 1e18 + 7;
const int maxn = 1e5 + 10;
const int maxq = 5e2 + 10;
const int alf = 26;
const ll dlm = 1e9 + 7;
const int del = 998244353 ;
const int eps = 1e-7 ;


int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
 	string st;
 	cin>>st;
 	ll ans = 0;
 	ll q = 0;
 	for(int i=st.size()-1;i>=0;i--){
        if(st[i]=='W')q++;
        else ans+=q;
 	}
 	cout<<ans;
    return 0;
}


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

int main() {
    int64_t N;
    std::cin >> N;

    int64_t cnt[N + 1] = {0};
    int64_t A[N];
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
        cnt[A[i]] += 1;
    }

    int64_t all = 0;
    for (int i = 1; i <= N; ++i) {
        if (cnt[i] > 1) {
            all += (cnt[i] * (cnt[i] - 1) / 2);
        }
    }

    for (int i = 0; i < N; ++i) {
        const int64_t a = cnt[A[i]];
        int64_t d = 0;
        if (a < 2) {
            d = 0; 
        } else if (a == 2) {
            d = 1;
        } else {
            d = a * (a - 1) / 2 - (a - 1) * (a - 2) / 2;
        }

        std::cout << all - d << std::endl;
    }

    return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    int N;
    cin >> N;
    unsigned int A[N], B[N];
    Fp(i, 0, N + 1) cin >> A[i];
    Fp(i, 0, N) cin >> B[i];
    unsigned long long int sum = 0;
    Fp(i, 0, N){
        if(A[i] < B[i]){
            sum += A[i];
            //cout << "speak1: " << sum << endl;
            B[i] -= A[i];
            if(A[i + 1] < B[i]){
                sum += A[i + 1];
                //cout << "speak2: " << sum << endl;
                A[i + 1] = 0;
            }else{
                sum += B[i];
                //cout << "speak3: " << sum << endl;
                A[i + 1] -= B[i];
            }
        }else{
            sum += B[i];
            //cout << sum << endl;
        }
        //cout << i << ": " << sum << endl;
    }
    cout << sum << endl;
}


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

int main() {
	int n; cin >> n;
	vector<int> x(n);
	rep(i, n) cin >> x[i];
	int ans = 1001001001;
	for (int i = 1; i <= 100; ++i) {
		int tmp = 0;
		rep(j, n) tmp += (x[j] - i) * (x[j] - i);
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
e = []
for i in range(h):
    e.append(list(input()))
e.insert(0, ["#"] * (w + 2))
e[0] = "".join(e[0])
e.insert(len(e), ["#"] * (w + 2))
e[len(e)-1] = "".join(e[len(e)-1])
for i in range(h):
    e[i + 1].insert(0, "#")
    e[i + 1].insert(len(e[i + 1]), "#")
    e[i+1] = "".join(e[i+1])
for i in e:
    print(i)

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

vector<vector<int>> g;
vector<bool> f;

void dfs(vector<int>& res, int p) {
	f[p] = true;
	res.push_back(p);
	for (auto x : g[p]) {
		if (!f[x]) {
			dfs(res, x);
			return;
		}
	}
}

vector<int> solve() {
	int N, M; cin >> N >> M;
	g.resize(N);
	f.resize(N, false);
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b; a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for (int i = 0; ; i++) {
		if (g[i].size() == 1) {
			vector<int> res;
			dfs(res, i);
			return res;
		} else if (g[i].size()) {
			vector<int> l, r{i};
			f[i] = f[g[i][1]] = true;
			dfs(r, g[i][0]);
			dfs(l, g[i][1]);
			reverse(l.begin(), l.end());
			copy(r.begin(), r.end(), back_inserter(l));
			return l;
		}
	}
}

int main() {
	auto res = solve();
	cout << res.size() << endl;
	for (int i = 0; i < int(res.size()); i++) {
		if (i) cout << " ";
		cout << res[i] + 1;
	}
	cout << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if (b == 1) cout << 0 << endl;
  else {
    int n = 1;
    while (n*a-(n-1) < b) ++n;
    cout << n << endl;
  }
  return 0;
}

Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const list = input.split(' ');

const a = Number(list[0]);

const b = Number(list[1]);

const x = Number(list[2]);

if (x > a + b) {
  console.log('NO');
} else if (a <= x ) {
  console.log('YES');
} else {
  console.log('NO');
}


Measured memory_bytes: 7372
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, K,W, H, Q, X, Y;
  ll ans;
  cin >> A >> B >> C >> D;
  cout << C-(D-B) << " " << D+(C-A) << " " << A-(D-B) << " " << B+(C-A);
  
  
}


Measured memory_bytes: 256
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
INF = 10**18

S=input()
N=len(S)

buf = []
h = 0
ans = 0
for s in S:
    if s=='0':
        h -= 1
    else:
        h += 1
ans = N-abs(h)

print(ans)


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int L,R,D;


void solve() {
	int i,j,k,l,r,x,y; string s;
	int ret=0;
	cin>>L>>R>>D;
	for(i=L;i<=R;i++) if(i%D==0) ret++;
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((int)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

void print(vector<ll> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

////////////////////////////////////////////////////////
int kuro[1005][1005];
ll H, W, cnt = 0; 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
string field[1005];
ll d[1005][1005];


ll dfs(){
    rep(i, 0, H) rep(j, 0, W) d[i][j] = -1;
    queue<pair<ll, ll>> qu;
    rep(i, 0, H) rep(j, 0, W){
        if(field[i][j] == '#'){
            qu.push({i, j});
            d[i][j] = 0;
        }
    }
    pair<ll, ll> now;
    ll ne_h, ne_w;
    int z = 0;
    while(!qu.empty()){
        // rep(i, 0, H){
        //     rep(j, 0, W) cout << d[i][j];
        //     cout << endl;
        // }
        // cout << endl;
        now = qu.front(); qu.pop();
        rep(i, 0, 4){
            ne_h = now.first+dy[i], ne_w = now.second+dx[i];
            if(ne_h < 0 || ne_h >= H || ne_w < 0 || ne_w >= W) continue;
            if(d[ne_h][ne_w] != -1) continue;
            d[ne_h][ne_w] = d[now.first][now.second]+1;
            chmax(cnt, d[ne_h][ne_w]);
            qu.push({ne_h, ne_w});
        }
        // z++;
        // if(z == 5) break;
    }
}

int main() {   
    cin >> H >> W;
    rep(i, 0, H) cin >> field[i];

    dfs();

    co(cnt);

    return 0;
}


Measured memory_bytes: 25780
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
using ull =unsigned long long;
const ll INF =1001001001;
const double PI = 3.14159265358979323846;
//10億7。　　　100000007

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}


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

int A,B;
  cin>>A>>B;
  cout<<A*B<<endl;
}



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

vector<ll> bfs(wgraph v,int x){
    priority_queue<pli,vector<pli>,greater<pli>> q;
    vector<ll> dist(v.size(),longinf);
    dist[x]=0;
    q.push({0LL,x});
    while(q.size()){
        pli p=q.top();q.pop();
        ll d=p.first,now=p.second;
        if(dist[now]<d)continue;
        for(auto to:v[now]){
            if(dist[to.second]>d+to.first){
                dist[to.second]=d+to.first;
                q.push({dist[to.second],to.second});
            }
        }
    }
    return dist;
}
int main(){
    int n,m,s;
    cin>>n>>m>>s;
    wgraph v(n);
    rep(i,m){
        ll x,y,z;
        cin>>x>>y>>z;;
        v[x].push_back({z,y});
    }
    vector<ll> ans=bfs(v,s);
    rep(i,n){
        if(ans[i]==longinf)cout<<"INF"<<endl;
        else cout<<ans[i]<<endl;
    }
   return 0;
}


Measured memory_bytes: 30756
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N, K;
    cin >> N >> K;
    vec p(N);
    Rep (i, N) cin >> p[i];

    cout << fixed << setprecision(10);

    vec s(N+1, 0);
    Rep (i, N) {
        s[i+1] = s[i] + p[i];
    }

    ll ans = 0;
    Rep (i, N-K+1) {
        chmax(ans, s[i+K]-s[i]);
    }

    cout << (ans + K) / 2.0 << "\n";
}

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


int main() {
  int X, Y ;
  cin >> X >> Y ;
  if (Y % 2 == 1 ) {
    cout << "No" << endl; 
  } else if (X*4 < Y) {
    cout << "No" << endl; 
  } else if ((X*2 > Y)) {
    cout << "No" << endl; 
  } else {
    cout << "Yes" << endl; 
  }
}


Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int main()
{
	long long visit[6]={0};    // M A R C H
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		char ch[11];
		cin>>ch;
		if(ch[0]=='M')visit[0]++;
		else if(ch[0]=='A')visit[1]++;
		else if(ch[0]=='R')visit[2]++;
		else if(ch[0]=='C')visit[3]++;
		else if(ch[0]=='H')visit[4]++;
	}
	int mis=0;
	for(int i=0;i<=4;i++)
	{
		if(visit[i]==0)mis++;
	}
	if(mis>2)cout<<0<<endl;
	else{
		long long count=0;
		count=visit[0]*visit[1]*visit[2]+visit[0]*visit[1]*visit[3]+visit[0]*visit[1]*visit[4]
	    +visit[0]*visit[2]*visit[3]+visit[0]*visit[2]*visit[4]+visit[0]*visit[3]*visit[4]
		+visit[1]*visit[2]*visit[3]+visit[1]*visit[2]*visit[4]+visit[1]*visit[3]*visit[4]
		+visit[4]*visit[2]*visit[3];
		cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    double n;cin>>n;
    double res=0;
    rep(i,n){
        double tmp;
        cin>>tmp;
        res += 1.0/tmp;
    }
    printf("%lf\n",1.0/res);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
#define req(i,n) for(int i = 1;i <= n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define fix  fixed << setprecision(10)
const ll INF = (1LL << 60);
string s,t; ll n,m,p, q, ans = 0, sum = 0,r;
bool f = true;
const ll MOD = 1000000007;
int main() {
    cin >> n >> m; vector<ll> a(n + 1,0);
    req(i, n) {
        a[i] = a[i - 1] + i;
    }
    for (int i = m; i <= n; i++) {
        sum += (a[n] - a[n - i] - a[i - 1] + 1);
        sum %= MOD;
    }
    cout << sum + 1 << endl;
}

Measured memory_bytes: 4840
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

template <class T>
class WeightedUnionFind
{
    vector<int> par;
    vector<T> dist;

public:
    WeightedUnionFind(int n) : par(n, -1), dist(n, 0) {}

    int root(int x)
    {
        if (par[x] < 0)
            return x;
        else
        {
            //rootから降りて足していく
            int r = root(par[x]);
            //親までの累積和は計算し終わっている
            dist[x] += dist[par[x]];
            return par[x] = r;
        }
    }

    //d[y] = d[x] + w
    bool merge(int x, int y, T w)
    {
        //par[y] = x
        w += weight(x) - weight(y);
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
        {
            w = -w;
            swap(x, y);
        }
        par[x] += par[y];
        par[y] = x;
        dist[y] = w;
        return true;
    }

    T weight(int x)
    {
        root(x);
        return dist[x];
    }

    T dis(int x, int y) { return weight(y) - weight(x); }

    int size(int x) { return -par[root(x)]; }
};

//verified @ https://onlinejudge.u-aizu.ac.jp/solutions/problem/DSL_1_B/review/3922525/sifi_border/C++14

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, m;
    cin >> n >> m;
    WeightedUnionFind<int> wuf(n);
    while (m--)
    {
        int l, r, d;
        cin >> l >> r >> d;
        l--, r--;
        if (!wuf.merge(l, r, d) && wuf.dis(l, r) != d)
        {
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";
}

int main()
{
    solve();
    return 0;
}


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

int main() {
	vector<vector<int>> a(3, vector<int>(3));
  	for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a.at(i).at(j);
          }}
  
  	int n;
  	cin>>n;
  	vector<int> b(15);
  	for(int k=0;k<n;k++){
     	cin>>b[k] ;
    }
  
  //読み込みまで
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < n; k++) {
      		if(a.at(i).at(j)==b[k]){
            	a.at(i).at(j)=-1;
            }
      }
    }
  }
  
	//当たりを-１にした
  
  if(a.at(1).at(1)==-1&&a.at(0).at(0)==a.at(2).at(2)){
  	cout<<"Yes"<<endl;
  }
  
  //これ全部書くのは嘘な気がするけどわかんない
  
   else if(a.at(1).at(1)==-1&&a.at(1).at(0)==a.at(1).at(2)){
  	cout<<"Yes"<<endl;
  }
  
    else if(a.at(1).at(1)==-1&&a.at(0).at(2)==a.at(2).at(0)){
  	cout<<"Yes"<<endl;
  }
  
    else if(a.at(1).at(1)==-1&&a.at(0).at(1)==a.at(0).at(2)){
  	cout<<"Yes"<<endl;
  }
  
     else if(a.at(1).at(1)==-1&&a.at(0).at(0)==a.at(2).at(2)){
  	cout<<"Yes"<<endl;
   }
  
  //斜め二本と十字の二本
  
  	else if(a.at(0).at(1)==-1&&a.at(0).at(0)==a.at(0).at(2)){
  	cout<<"Yes"<<endl;
   }
  
 	else if(a.at(0).at(0)==-1&&a.at(1).at(0)==a.at(2).at(0)){
  	cout<<"Yes"<<endl;
   }

  	else if(a.at(2).at(2)==-1&&a.at(2).at(1)==a.at(2).at(0)){
  	cout<<"Yes"<<endl;
   }  
  
  	else if(a.at(2).at(2)==-1&&a.at(1).at(2)==a.at(0).at(2)){
  	cout<<"Yes"<<endl;
   }  
  
  	//これで全部だとおもうけど
  
  	else{
    cout<<"No"<<endl;
    }
  
}

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

int main(){

    ll N; cin >> N;
    string ans = "";

    while(N){
        N--;
 	    ans += (char)(N % 26 + 'a');
 	    N/=26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
} 

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n,K;
int main()
{
	scanf("%d%d",&n,&K);
	if (n*2<K) { puts("0");return 0;}
	long long y=n/K;
	if (K&1) { printf("%lld\n",y*y*y);return 0;}
	long long x=(n-(K/2))/K+1;
	printf("%lld\n",x*x*x+y*y*y);
	return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  vector<int> V;
  char c = S[0];
  int l = 0;
  for(int i = 0; i < N; ++i){
    if(c == S[i]){
      ++l;
      continue;
    }else{
      V.push_back(l);
      l = 1;
      c = S[i];
    }
  }
  V.push_back(l);
  int ans = 0;
  for(auto e : V) ans += e-1;
  ans = min({N-1,ans+2*K,ans+(int)V.size()-1});
  cout << ans << endl;
}


Measured memory_bytes: 1020
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

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

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n,d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    for(int i=0;i<n;++i){
        for(int j=0;j<d;++j) {
            cin >> x[i][j];
        }
    }

    set<int> st;
    for(int i=1;i<=1000;++i) {
        st.insert(i*i);
    }

    int ans = 0;

    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j) {
            int dist = 0;
            for(int k=0;k<d;++k) {
                dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            if(st.find(dist) != st.end()) {
                ++ans;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int r,x,d;
  scanf("%d%d%d",&r,&d,&x);
  int a[11];
  a[0]=x;
  for(int i=0;i<10;i++){
    a[i+1]=r*a[i]-d;
    printf("%d\n",a[i+1]);
  }
  return 0;
}

Measured memory_bytes: 1728
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<stdio.h>
using namespace std;

int n, m;
int a, k;
int ans[40];
int ANS;

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> a;
			ans[a]++;
		}
	}

	for (int i = 1; i <= m; i++) {
		if (ans[i] == n) {
			ANS++;
		}
	}

	cout << ANS << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main()
{
	scanf("%d %d",&a,&b);
	for(int i=1;i<=a;++i) c=c*10+b;
	for(int i=1;i<=b;++i) d=d*10+a;
	printf("%d\n",max(c,d));return 0;
}

Measured memory_bytes: 256
// AOJ ALDS1_3_C Doubly Linked List
// 2018.5.1 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void skip(int k) { while (k--) gc(); }

void out(int n)
{
	int i;
	char ob[20];

	if (!n) { pc('0'); return; }
	i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
	while (i--) pc(ob[i]); 
}

typedef struct { int key; char f; } Q;
Q que[2000005]; int top, end;

int main()
{
	int n, i, t;
	char op;

	n = in(); top = 0, end = 1;
	while (n--) {
		op = gc();
		if (op == 'i') {
			skip(6);
			que[end].f = 1, que[end++].key = in();
		} else {
			skip(5);
			op = gc();
			if (op == 'F') {
				skip(5);
				while (que[end-1].f == 0) end--;
				end--;
			} else if (op == 'L') {
				skip(4);
				while (que[top+1].f == 0) top++;
				top++;
			} else {
				t = in();
				for (i = end-1; i > top; i--) {
					if (que[i].key == t && que[i].f) {
						que[i].f = 0;
						break;
					}
				}
			}
		}
	}
	t = 0;
	for (i = end-1; i > top; i--) if (que[i].f) {
		if (!t) t = 1; else pc(' ');
		out(que[i].key);
	}
	pc('\n');
	return 0;
}


Measured memory_bytes: 9356
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
using namespace std;
#define INF 100000000
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define rep(i, n) for(int (i)=1; (i)<=(n); (i)++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int A, B;
    cin >> A >> B;
    for(int C=1; C<=3; C++){
        if(A*B*C % 2 == 1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int serch_str(char *string, char str);
void judge_game(int a_point, int b_point);

int main(void)
{
	char serve_data[3][101];
	int i;
	
	while (1){
		scanf("%s", serve_data[0]);
		
		if (serve_data[0][0] == '0'){
			break;
		}
		
		for (i = 1; i < 3; i++){
			scanf("%s", serve_data[i]);
		}
		
		for (i = 0; i < 3; i++){
			judge_game(serch_str(serve_data[i], 'A'), serch_str(serve_data[i], 'B'));
		}
	}
	
	return (0);
}

int serch_str(char *string, char str)
{
	int i;
	int count;
	
	count = 0;
	
	for (i = 1; string[i] != '\0'; i++){
		if (string[i] == str){
			count++;
		}
	}
	
	return (count);
}

void judge_game(int a_point, int b_point)
{
	if (a_point > b_point){
		a_point++;
	}
	
	else {
		b_point++;
	}
	
	printf("%d %d\n", a_point, b_point);
}

Measured memory_bytes: 0