akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <bitset>
#include <string>
#include <map>
#include <queue>
#include <functional>
#include <assert.h>
using namespace std;
inline int pack(int p, int ps, int n) {
  return (p << n) | ps;
}
int main(int argc, char *argv[])
{
  for(;;) {
    int n;
    cin >> n;
    if(n==0) break;
    string sa, sb;
    getline(cin, sa);
    getline(cin, sa);
    getline(cin, sb);
    auto conv = [n](string &s) {
      int r = 0;
      for(int i = 0; i < n; i++) {
        r = (r<<1) + (s[i] == 'W' ? 1 : 0); 
      }
      return r;
    };
    int a = conv(sa);
    int b = conv(sb);
    //cout << "a = " << static_cast<std::bitset<8> >(a) << endl;
    //cout << "b = " << static_cast<std::bitset<8> >(b) << endl;

    // state = (pos, panels)
    vector<int> ds(n<<n, 100000000);
    priority_queue<pair<int,int>> que;
    for(int i = 0; i < n; i++) {
      int v = pack(i, a, n);
      ds[v] = 0;
      que.push(make_pair(-ds[v], v));
      
    }
    vector<bool> done(n, false);
    int rest = n;
    while(que.size() > 0) {
      auto dv = que.top(); que.pop();
      const int v = dv.second;
      const int d = -dv.first;
      const int p = v >> n;
      const int s = v & ((1<<n) - 1);
      //cout << "popped: " << static_cast<std::bitset<8> >(s) << " at " << p << " with cost " << d << endl;
      if(s == b) {
        if(!done[p]) {
          done[p] = true;
          rest--;
        }
        if(rest == 0) {
          int e = d;
          for(int i = 0; i < n; i++) {
            e = min(e, ds[pack(i, b, n)]);
          }
          cout << e << endl;
          break;
        }
      }
      // generate all possible transitions: marking i, and then j.
      for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
          if(i == j) continue;
          if((((s>>i) ^ (s>>j))&1) == 0) continue;
          const int c = abs(i - p) + abs(j - i);
          const int u = pack(j, s ^ (1<<i) ^ (1<<j), n); // swap
          if(ds[u] > d + c) {
            ds[u] = d + c;
            que.push(make_pair(-ds[u], u));
            //cout << " to " << i << " and " << j << " cost " << ds[u] << " for " << static_cast<std::bitset<8> >(u) << endl;
          }
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 13796
using System;

namespace _095c
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] ABCXY = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            int A = ABCXY[0];
            int B = ABCXY[1];
            int C = ABCXY[2];
            int X = ABCXY[3];
            int Y = ABCXY[4];
            int total_normal = A*X+B*Y;
            int total_special = 0;
            if(X>Y){
                total_special = Math.Min(C * 2 * Y + (X-Y)*A,C*2*X);
            }else{
                total_special = Math.Min(C * 2 * X + (Y-X)*B,C*2*Y);
            }
            Console.WriteLine(total_special>total_normal?total_normal:total_special);
        }
    }
}

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

long cnt;
vector<int> G;

void insertionSort(int A[], int N, int g) {
	for (int i = g; i < N; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && v < A[j]) {
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[], int N) {
	for (int i = 1; ; ) {
		if (i > N) break;
		G.push_back(i);
		i = 3*i + 1;
	}
	
	for (int i = G.size() - 1; i >= 0; i--) {
		insertionSort(A, N, G[i]);
	}
}
	
int main() {
	int N;
	cin >> N;
	int A[N];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	cnt = 0;
	
	shellSort(A, N);
	
	cout << G.size() <<endl;
	for (int i = G.size() - 1; i > 0; i--) {
		cout << G[i] << " ";
	}
	cout << G[0] << endl;
	cout << cnt << endl;
	for (int i = 0; i < N; i++) {
		cout << A[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 5124
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

std::string N;

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

  ll sum = 0;

  rep( i, N.size() )
    sum = (sum+N[i]-'0')%9;

  std::cout << (!sum ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <list>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <ctime>
#include <assert.h>
using namespace std;

const unsigned long long MOD = (unsigned long long)(1e9 + 7);

#define FROM_0(i, n) for(int i = 0; i < (n); i++)
#define FROM_S(i, s, e) for(int i = (s); i < (e); i++)
#define ITER_BEGIN_END(iter, vec) for(auto iter = vec.begin(); iter != vec.end(); iter++)

bool isSorted(int * p, int n)
{
    FROM_0(i, n - 1)
    {
        if (p[i] > p[i + 1])
            return false;
    }
    return true;
}

int main()
{
    int n;
    int p[100];
    cin >> n;
    FROM_0(i, n)
        cin >> p[i];
    if (isSorted(p, n))
        cout << "YES" << endl;
    else
    {
        FROM_0(i, n)
        {
            FROM_0(j, n)
            {
                if (i == j)
                    continue;
                std::swap(p[i], p[j]);
                if (isSorted(p, n))
                {
                    cout << "YES" << endl;
                    return 0;
                }
                std::swap(p[i], p[j]);
            }
        }
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <iomanip>
using namespace std;
#define mod (long)(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
#define long long long
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int N;
vector<long> a;

long dp[3020][3020];

long game(int l, int r){
    if(l > r){
        return 0;
    }else if(dp[l][r] != -1){
        return dp[l][r];
    }
    return dp[l][r] = max(a[l] - game(l + 1, r), a[r] - game(l, r - 1));
}

int main(){
    cin >> N;
    a.resize(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << game(0, N - 1) << endl;
}


Measured memory_bytes: 71680
import java.util.Scanner

object Main {
  def solve(sc: => Scanner): Unit = {
    val N = sc.nextInt
    if (N != 0) {
      val y = sc.nextDouble
      var max = 0.0
      var ans = 0
      for (_ <- 0 until N) {
        val b = sc.nextInt
        val r, t = sc.nextDouble
        if (t == 1) (if (max < 1 + y * r / 100) {
          max = 1 + y * r / 100
          ans = b
        })
        else (if (max < math.pow((1 + r / 100), y)) {
          max = math.pow((1 + r / 100), y)
          ans = b
        })
      }
      println(ans)
      solve(sc)
    }
  }


  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)

    solve(sc)
  }
}

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

int main() {
	int N;
	cin >> N;
	
	vector<int64_t> L(100);
    L.at(0) = 2;
    L.at(1) = 1;
	for(int i = 2; i <= N; i++){
		L.at(i) = L.at(i - 1) + L.at(i - 2);
	}
	
	cout << L.at(N) << endl;
	
	return 0;
}

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

#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

using namespace std;

ll mod(ll a, ll b) { return (a % b + b) % b; }
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}

int main()
{
    fast;
   	unordered_map<ll,ll>m;
   	ll a,b,c;
   	cin>>a>>b>>c;
   	m[a]++; m[b]++; m[c]++;
   	if(m[5] == 2 && m[7] == 1) cout << "YES" << endl;
   	else cout << "NO" << endl;
    return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(void){
    int D, c[26], s[365][26];

    //入力
    scanf("%d", &D);
    for(int i=0; i<26; i++){
        scanf("%d", &c[i]);
    }
    for(int i=0; i<D; i++){
        for(int j=0; j<26; j++){
            scanf("%d", &s[i][j]);
        }
    }

    //出力
    /*
    printf("%d\n", D);
    for(int i=0; i<26; i++){
        printf("%d ", c[i]);
    }
    printf("\n");
    for(int i=0; i<D; i++){
        for(int j=0; j<26; j++){
            printf("%d ", s[i][j]);
        }
    }
    */

   /*ここから処理*/
    for(int i=0; i<D; i++){
        printf("%d\n", rand() % 26 + 1);
    }


    return 0;
}

Measured memory_bytes: 1772
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>

#define LL long long
using namespace std;
#define MAXN 200005
#define pp 1000000007

//set<int> s;
unordered_map<int,int> m;

int nums[MAXN];

int main() {
	int n;
	bool flag = true;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &nums[i]); 
		if (m.find(nums[i]) == m.end()) m.insert({ nums[i],1 });
		else {
			m[nums[i]]++;
		}
		//s.insert(nums[i]);
		if (nums[i] != 0) flag = false;
	}
	if (flag) {
		printf("Yes");
		return 0;
	}
	int ans = 0;
	if (n > 3) {
		if (n % 3 == 0) {
			if (m.size() > 3) {
				printf("No");
				return 0;
			}
			else {
				for (auto i : m) {
					while (i.second != 0) {
						ans ^= i.first;
						i.second -= n / 3;
						if (i.second < 0) {
							printf("No");
							return 0;
						}
					}
				}
			}
			if (ans == 0) {
				printf("Yes");
				return 0;
			}
			else {
				printf("No");
				return 0;
			}
		}
		else {
			printf("No");
			return 0;
		}
	}
	else {
		if ((nums[0] ^ nums[1]) == nums[2]) {
			printf("Yes");
			return 0;
		}
		else {
			printf("No");
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 4004
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	ll A, B;
	
	cin >> A >> B ;

	ll c = A + B;
	if (c & 0x01)
	{
		cout << "IMPOSSIBLE" << endl;
	}
	else
	{
		cout << (c >> 1) << endl;
	}
	

	
	return 0;
}


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

int main() {
	int T;
	cin >> T;
	for (int t = 0; t < T; t++) {
		long long N, M, A, B;
		cin >> N >> M >> A >> B;
		cout << floor_sum(N, M, A, B) << endl;
	}
}


Measured memory_bytes: 3592
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 6e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string s, t;
main() {
  file("lala");
  ios;
  cin >> s >> t;
  int ans = 0;
  for (int i = 0; i < s.size(); ++i) if (s[i] != t[i]) ++ans;
  cout << ans;
  return 0;
}
/**

*/


Measured memory_bytes: 3820
object Main {
  def main(args: Array[String]) = {
    import scala.io.StdIn.readLine

    val n = readLine.toInt
    val v = readLine.split(" ").take(n).map(_.toInt)
    val c = readLine.split(" ").take(n).map(_.toInt)

    val deltas = for {
      i <- (0 until n)
      if (v(i) - c(i) > 0)
    } yield v(i) - c(i)

    println(deltas.foldLeft(0) { (acc, x) => acc + x })
  }
}

Measured memory_bytes: 25432
#include <iostream>
#include <algorithm>

using namespace std;

main(){
  long long n, e[100][100], a = 0, i, j;
  cin >> n;
  for(i=0;i<n;i++) for(j=0;j<n;j++) cin >> e[i][j];
  for(i=0;i<n;i++) for(j=i;j<n;j++) a += min(e[i][j], e[j][i]);
  cout << a << endl;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace std;
#define ll long long int
#define ld long double
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> in_set;
#define rep(n) for(ll i=0;i<(n);i++)
#define jrep(n) for(ll j=0;j<(n);j++)
#define all(a) (a).begin(), (a).end()
#define dpp(a) cout<<(a).first<<" "<<(a).second<<endl;
#define append push_back
#define mod 1000000007
#define ff first
#define ss second
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fast ios::sync_with_stdio(0);
ll pw(ll x,ll y,ll p=mod){ll r=1; x=x%p;while(y>0){ if(y&1)r=(r*x)%p;
y=y>>1;x=(x*x)%p;} return r; } vector<ll> uniq(vector<ll> arr)
{vector<ll>brr;sort(all(arr));brr.append(arr[0]);
for(auto i:arr)if(brr.back()!=i)brr.append(i);return brr;}
 
void solve(){
    string s; cin>>s; if(s[0]!=s.back()||s[0]!=s[1]) cout<<"Yes\n"; else cout<<"No\n";
}
 
int main(){
    ffast
    ll t=1;
    //cin>>t;
    rep(t) solve();
}
 
 
// *p.find_by_order(n) : nth value (0 indexed)
// p.order_of_key(7): index of 7 (0 indexed)


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;

__attribute__((constructor))
void initial(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed <<setprecision(15);
}


int main(void){
	string S;
    cin >> S;
    string ans = "No";
    rep(i,2){
        if(S[i] != S[i+1]) ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
x = []
y = 100
for i in range(5):
	x.append(int(input()))
	if x[-1] % 10 == 0:
		y = min(y,10)
	else:
		y = min(y, x[-1]%10)

sum = 0
for i in range(5):
	if x[i] % 10 == 0:
		sum += x[i]
	else:
		sum += x[i] + 10 - (x[i]%10)
sum -= 10 - y
print(sum)

Measured memory_bytes: 38256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int n;
		if(b != 100) {
			if(b / 10 == 0) {
				n = a * 10 + b;
			}else {
				n = a * 100 + b;
			}
		}else {
			n = a * 1000 + b;
		}
		for(int i = 1; i * i <= n; i++) {
			if(i * i == n) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}


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

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

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#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 ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;


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

	int cnt = 0;

	int l = 0, r = n-1;
	string s;
	cin >> s;

	while(l < r) {
		if(s[l] == 'W' && s[r] == 'R') cnt++, l++, r--;
		else if(s[l] != 'W') l++;
		else r--;
	}
	cout << cnt << '\n';
}


int32_t main() {_
	
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	// tc(t)
		solve();
	cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}



Measured memory_bytes: 3960
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int n,m,start,end,money,price;
struct edge{int to,cost;};
vector<edge> g[30];
int d[30];
void dijkstra(int s)
{
	fill(d,d+n,INF);
	d[s]=0;
	priority_queue<P,vector<P>,greater<P> > q;
	q.push(mp(0,s));
	while(!q.empty())
	{
		P a=q.top();
		q.pop();
		int v=a.sec;
		if(d[v]<a.fi)continue;
		for(int i=0;i<g[v].size();i++)
		{
			edge e=g[v][i];
			if(d[e.to]>d[v]+e.cost)
			{
				d[e.to]=d[v]+e.cost;
				q.push(mp(d[e.to],e.to));
			}
		}
	}
	return;
}
int main()
{
	cin >> n;
	cin >> m;
	for(int i=0;i<m;i++)
	{
		int a,b,c,d;
		scanf("%d,%d,%d,%d",&a,&b,&c,&d);
		a--;b--;
		edge in;
		in.to=b;in.cost=c;
		g[a].pb(in);
		in.to=a;in.cost=d;
		g[b].pb(in);
	}
	scanf("%d,%d,%d,%d",&start,&end,&money,&price);
	start--;end--;
	money-=price;
	dijkstra(start);
	money-=d[end];
	dijkstra(end);
	money-=d[start];
	cout << money << endl;
	return 0;
}

Measured memory_bytes: 1264
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>
#include <numeric>

int main(){
	int a = 0, b = 0;
	std::string str;
	std::cin >> str;
	for(int i = 0; i < str.size(); i++){
		if(str[i] == '0'){
			a++;
		}
		if(str[i] == '1'){
			b++;
		}
	}
	std::cout << std::min(a, b) * 2 << std::endl;
	return 0;
}



Measured memory_bytes: 512
#include <stdio.h>

#define NUM_BUILDING 4
#define NUM_FLOOR 3
#define NUM_ROOM 10

int main (void) {
    int n, b, f, r, v;
    char e;
    int house[NUM_BUILDING][NUM_FLOOR][NUM_ROOM];

    for (int i=0; i<NUM_BUILDING; i++) {
        for (int j=0; j<NUM_FLOOR; j++) {
            for (int k=0; k<NUM_ROOM; k++) {
                house[i][j][k]=0;
            }
        }
    }

    scanf ("%d", &n);

    for (int i=0; i<n; i++) {
        scanf ("%d %d %d %d", &b, &f, &r, &v);
        house[b-1][f-1][r-1] += v;
    }

    for (int i=0; i<NUM_BUILDING; i++) {
        for (int j=0; j<NUM_FLOOR; j++) {
            for (int k=0; k<NUM_ROOM; k++) {
                printf (" %d", house[i][j][k]);
            }
            printf ("\n");
        }
        if (i==NUM_BUILDING-1) break;
        printf("####################\n");
    }

    return 0;
}


Measured memory_bytes: 2104
#include<string>
#include <iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a<b){
		for(int i=0 ;i<b; i++){
			cout<<a;
		}
	}
	else{
		for(int i=0 ;i<a; i++){
			cout<<b;
		}
	}
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var x, n int
	fmt.Scan(&x, &n)
	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
	}

	for i := 0; i < 10000; i++ {
		ok := true
		for j := 0; j < len(p); j++ {
			if x-i == p[j] {
				ok = false
			}
		}
		if ok {
			fmt.Println(x - i)
			return
		}
		ok = true
		for j := 0; j < len(p); j++ {
			if x+i == p[j] {
				ok = false
			}
		}
		if ok {
			fmt.Println(x + i)
			return
		}
	}
}


Measured memory_bytes: 1760
#include <iostream>

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

  int sw = 0;
  for (int i = 0; i < N - 1; ++i)
  {
    int mini = i;
    for (int j = i + 1; j < N; ++j)
    {
      if (A[mini] > A[j]) mini = j;
    }
    if (i != mini)
    {
      std::swap(A[i], A[mini]);
      ++sw;
    }
  }

  for (int i = 0; i < N; ++i)
  {
    if (i > 0) std::cout << " ";
    std::cout << A[i];
  }
  std::cout << std::endl;
  std::cout << sw << std::endl;

  return 0;
}



Measured memory_bytes: 3108
#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 N;

template<int um> class UF {
	public:
	vector<int> par,rank;
	UF() {rank=vector<int>(um,0); for(int i=0;i<um;i++) par.push_back(i);}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};

int X[101010],Y[101010];
vector<pair<int,int>> XX;
vector<pair<int,int>> YY;
vector<pair<int,pair<int,int>>> ev;
UF<500000> uf;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>X[i]>>Y[i];
		XX.push_back({X[i],i});
		YY.push_back({Y[i],i});
	}
	sort(ALL(XX));
	sort(ALL(YY));
	FOR(i,N-1) {
		ev.push_back({XX[i+1].first-XX[i].first,{XX[i].second,XX[i+1].second}});
		ev.push_back({YY[i+1].first-YY[i].first,{YY[i].second,YY[i+1].second}});
	}
	ll ret=0;
	sort(ALL(ev));
	FORR(e,ev) {
		if(uf[e.second.first]!=uf[e.second.second]) {
			uf(e.second.first,e.second.second);
			ret+=e.first;
		}
	}
	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);
	solve(); return 0;
}


Measured memory_bytes: 13296
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 2e3 + 5;
const int mod = 1e9 + 7;
int n, d, cnt[N][N];
int x[N * 100], y[N * 100];
int type[N][N];
int sum[N][N][2];
inline int S(int x, int y, int z) {
	if (x < 0 || y < 0) return 0;
	return sum[x][y][z];
}
bool check(int k) {
	int tmp, tmp1, tmp2, p = k % d;
	for (int i = 0; i < d; ++i) {
		for (int j = 0; j < d; ++j) {
			tmp = S(i + p - 1, j + p - 1, 1) - S(i + p - 1, j - 1, 1) - S(i - 1, j + p - 1, 1) + S(i - 1, j - 1, 1);
			//cout << i << " " << j << " " << tmp << endl;
			if (sum[d - 1][d - 1][1] != tmp) continue;
			tmp1 = S(d - 1, j + p - 1, 0) - S(d - 1, j - 1, 0);
			tmp2 = S(i + p - 1, d - 1, 0) - S(i - 1, d - 1, 0);
			tmp = S(i + p - 1, j + p - 1, 0) - S(i + p - 1, j - 1, 0) - S(i - 1, j + p - 1, 0) + S(i - 1, j - 1, 0);
			if (tmp1 + tmp2 - tmp != sum[d - 1][d - 1][0]) continue;
			return 1;
		}
	}
	return 0;
}
int main() {
	scanf("%d %d", &n, &d);
	int mmax = 0;
	for (int i = 1; i <= n; ++i) {
		scanf("%d %d", x + i, y + i);
		cnt[x[i] % d][y[i] % d]++;
		mmax = max(mmax, cnt[x[i] % d][y[i] % d]);
	}
	//check(4);return 0;
	int f = 1;
	for (int i = 0; i <= 1000; i++) {
		int x = i;
		if ((x + 1) * (x + 1) >= mmax) {
			f = i;
			break;
		}
 }
	int x = f;
	ll t1 = (x + 1) * (x + 1ll);
	ll t2 = (x + 1ll) * x;
	ll t3 = (ll)x * x;
	for (int i = 0; i < d; ++i) {
		for (int j = 0; j < d; ++j) {
			if (cnt[i][j] <= t3) {
				type[i][j] = 2;
			} else 
			if (cnt[i][j] <= t2) {
				type[i][j] = 0;
			} else 
			if (cnt[i][j] <= t1) {
				type[i][j] = 1;
			}
			//cout << type[i][j] << ",";
		} //cout << endl;
	}
	for (int i = 0; i < 2 * d; ++i) {
		for (int j = 0; j < 2 * d; ++j) {
			for (int k = 0; k < 2; ++k) {
				sum[i][j][k] = 0;
				if (i) sum[i][j][k] += sum[i - 1][j][k];
				if (j) sum[i][j][k] += sum[i][j - 1][k];
				if (i && j) sum[i][j][k] -= sum[i - 1][j - 1][k];
				if (k == type[i % d][j % d]) sum[i][j][k]++;
			}
		}
	}
	int l = 0, r = d;
	while (l < r) {
		int mid = l + r >> 1;
		//cout << mid << endl;
		if (l + 1 == r) {
			if (check(l))
				--r;
			else
				++l;
			break;
		}
		if (check(mid))
			r = mid; 
		else 
			l = mid;
	}
	cout << x * d + l - 1;
} 	

Measured memory_bytes: 51456
#include <iostream>
using namespace std; // c d h s 昇順

#define MAX 36
struct Card{char mark, number; }; // int

void BubbleSort(Card A[], int n){
  int i, j;
  Card swap;
  for (i = 0; i < n; i++){
    for (j = n - 1; j >= i; j--){
      if (A[j].number < A[j - 1].number) {
        swap = A[j];
        A[j] = A[j - 1];
        A[j - 1] = swap;
      }
    }
  }
}

void SelectionSort(Card A[], int n){
  int i, j, minj;
  Card swap;
  for (i = 0; i < n; i++){
    minj = i;
    for (j = i; j < n; j++){
      if (A[j].number < A[minj].number) minj = j;
    }
    swap = A[i];
    A[i] = A[minj];
    A[minj] = swap;
  }
}

bool isStable(Card Bubble[], Card Select[], int n){
  int i;
  for (i = 0; i < n; i++){
    if (Bubble[i].mark !=  Select[i].mark) return false;
  }
  return true;
}

int main(){
  int i, j, n;
  Card Bubble[MAX], Select[MAX];
  cin >> n;
  for (i = 0; i < n; i++) cin >> Bubble[i].mark >> Bubble[i].number;
  for (i = 0; i < n; i++) Select[i] = Bubble[i];

  BubbleSort(Bubble, n);
  SelectionSort(Select, n);

  cout << Bubble[0].mark << Bubble[0].number;
  for (i = 1; i < n; i++){
    cout << " " << Bubble[i].mark << Bubble[i].number;
  }
  cout << "\n";
  cout << "Stable" << "\n";

  cout << Select[0].mark << Select[0].number;
  for (i = 1; i < n; i++){
    cout << " " << Select[i].mark << Select[i].number;
  }
  cout << "\n";
  if ( isStable(Bubble, Select, n))   cout << "Stable" << "\n";
  else cout << "Not stable" << "\n";

  return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  ll N;
  cin >> N;

  ll A = N;
  ll B = 0;
  while(N!=0){
    B+=(N%10);
    N/=10;
  }

  if((A%B)==0)cout << "Yes" << endl;
  else cout << "No" << endl;

  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def bit_count(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#############
# Main Code #
#############

N = inputI()
data = inputSLL(N)

dic = {}
for i in range(N):
  c,p = data[i]
  if c not in dic:
    dic[c] = [(int(p),i)]
  else:
    dic[c].append((int(p),i))
    
key = [k for k in dic]
key.sort()
for k in key:
  dic[k].sort(reverse=True)
  for p,i in dic[k]:
    print(i+1)

Measured memory_bytes: 72868
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

#define fr(i,n)	for(int i=0;i<n;i++)
#define frr(i,n)	for(int i=1;i<=n;i++)

#define ms(x,i)	memset(x,i,sizeof(x))
#define dbg(x) cout << #x << " = " << x << endl
#define all(x) x.begin(),x.end()

#define gnl cout << endl
#define olar cout << "olar" << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef pair<ll,ll> pll;

const int INF = 0x3f3f3f3f;


int main(){
    fastio;
    string s;
    cin >> s;
    int n = s.size();
    int inicio,fim;
    for(int i = 0; i<n; i++){
        if(s[i] == 'A') {
            inicio = i;
            break;
        }
    }
    for(int i = n-1; i>=0; i--){
        if(s[i] == 'Z'){
            fim = i;
            break;
        }
    }
    cout << fim-inicio + 1 << endl;
}

Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#include <bitset>

#define Z class
#define ln cout<<'\n'
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
using pll = pair<long long, long long>;

template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

pair<pair<string, int>, int> p[110];
int main(){
    int A, B, C; cin >> A >> B >> C;
    cout << min({A+B, B+C, C+A}) << endl;
}


Measured memory_bytes: 256
def main():
	n,*a = map(int,open(0).read().split())
	dbl = sum(a)-n*(n+1)//2
	l,r = [i for i,j in enumerate(a) if j==dbl]
	const = n+l-r
	m = n + 1
	mod = 10**9+7
	fac = [1]*(m+1)
	inv = [1]*(m+1)
	for i in range(1,m+1):
		fac[i] = fac[i-1] * i % mod
	inv[-1] = pow(fac[-1], mod - 2, mod)
	for i in range(m-1, -1, -1):
		inv[i] = inv[i+1] * (i+1) % mod
	def cmb(n,r):
		if n<r:return 0
		return fac[n] * inv[n-r] * inv[r] % mod
	for k in range(1,n+2):
		print((cmb(n+1,k)-cmb(const,k-1)) % mod)
if __name__=="__main__":main()

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


n = int(input().strip())


d = {
    "M": 0,
    "A": 0,
    "R": 0,
    "C": 0,
    "H": 0
}
top = list("MARCH")


for _ in range(n):
    name = input().strip()
    if name[0] in top:
        d[name[0]] += 1

ans = 0

for a in range(3):
    for b in range(a + 1, 4):
        for c in range(b + 1, 5):
            ans += d[top[a]] * d[top[b]] * d[top[c]]

print(ans)


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    string ans = "No";
    FOR(i, 1, 10){
        FOR(j, 1, 10){
            if(i * j == n){
                ans = "Yes";
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int N, M;
vector<int> X, Y, Z;
vector<vector<int>> G;
vector<int> used;

void dfs(int v){
  for(int i = 0; i < (int)G[v].size(); i++){
    int u = G[v][i];
    if(used[u] == true) continue;
    used[u] = true;
    dfs(u);
  }
}

int main(void){
  int N, M; cin >> N >> M;
  G.resize(N);
  used.assign(N, 0);
  for(int i = 0; i < M; i++){
    int x, y, z; cin >> x >> y >> z;
    x--;y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  int ans = 0;
  for(int i = 0; i < N; i++){
    if(used[i] == true) continue;
    ans++;
    dfs(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 9216
import sys

#sys.stdin = open("first.txt","r")

def main():
	a, b = map(int, raw_input().split())
	print max([a + b, a - b,a * b])

raw_input = sys.stdin.readline

if __name__ == '__main__':
	#for j in xrange(int(raw_input())):
	main()

Measured memory_bytes: 2568
t = 'LRUD'
s = input()
for i in range(len(s)):
  if (i+1) % 2 == 1 and s[i] == 'L':
    print('No')
    exit()
  if (i+1) % 2 == 0 and s[i] == 'R':
    print('No')
    exit()
print('Yes')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c, d, e;
	e=0;
	cin >> a >> b >> c;
	for (d=a; d<100000; d++ ){
		if (d>b)break;
		else{
			if (c%d == 0){e+=1;}
			}
		}
		cout << e << endl;
	return 0;
}



Measured memory_bytes: 3088
using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 5010
int len;
char s[N],t[N];
int n,m,a[N],b[N];
int main(){
	scanf("%d%s%s",&len,s+1,t+1);
	for (int i=1;i<=len;++i){
		if (s[i]!=s[i+1])
			a[++n]=i;
		if (t[i]!=t[i+1])
			b[++m]=i;
	}
	int ans=0,res=0;
	for (int i=1;i<=n;++i)
		res+=a[i];
	for (int j=1;j<=m;++j)
		res+=len-b[j];
	ans=res;
	res=0;
	for (int i=1;i<=n;++i)
		res+=len-a[i];
	for (int j=1;j<=m;++j)
		res+=b[j];
	ans=min(ans,res);
	if (n>=1){
		for (int j=1;j<=m;++j){
			if (s[a[1]]!=t[b[j]])
				continue;
			int res=0,k=1;
			for (;k<j;++k)
				res+=b[k];
			for (;k<=m && k-j+1<=n;++k)
				res+=abs(b[k]-a[k-j+1]);
			if (k-j+1<=n)
				for (;k-j+1<=n;++k)
					res+=len-a[k-j+1];
			else
				for (;k<=m;++k)
					res+=len-b[k];
			ans=min(ans,res);
		}
	}
	if (m>=1){
		for (int i=1;i<=n;++i){	
			if (s[a[i]]!=t[b[1]])	
				continue;
			int res=0,k=1;
			for (;k<i;++k)
				res+=a[k];
			for (;k<=n && k-i+1<=m;++k)
				res+=abs(b[k-i+1]-a[k]);
			if (k-i+1<=m)
				for (;k-i+1<=m;++k)
					res+=len-b[k-i+1];
			else
				for (;k<=n;++k)
					res+=len-a[k];
			ans=min(ans,res);
		}
	}
	printf("%d\n",ans);
	return 0;
}















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

using namespace std;

const int INF = 1e9 + 5;

void a()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
}

int main()
{
    a();

    int n, k;
    cin >> n >> k;
    vector<int> val(n), dp(n, INF);

    for(int i = 0; i < n; i++) cin >> val[i];

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

   cout << dp[n-1];
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	int L, R, d; cin >> L >> R >> d;
    int ans = 0;
    for(int i = L; i <= R; i++) {
        if(i % d == 0) ans++;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3560
from bisect import bisect, bisect_left
from itertools import accumulate
from math import ceil


def solve(h, aa, bb):
    max_a = max(aa)
    bf = list(filter(lambda x: x > max_a, bb))
    if not bf:
        return ceil(h / max_a)
    bf.sort(reverse=True)
    bba = list(accumulate(bf))
    remain = h - bba[-1]
    slash_cnt = max(0, ceil(remain / max_a))
    slash_dmg = slash_cnt * max_a
    throw_dmg = h - slash_dmg
    for i, dmg in enumerate(bba):
        if dmg >= throw_dmg:
            break
    return slash_cnt + i + 1


n, h = map(int, input().split())
aa, bb = [], []
for _ in range(n):
    a, b = map(int, input().split())
    aa.append(a)
    bb.append(b)

print(solve(h, aa, bb))


Measured memory_bytes: 16044
#include<bits/stdc++.h>
using namespace std;
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double

int lower_then_left_right(vector<int>&A,vector<int>&B,int x)
{
	int c=LLONG_MAX;
	auto it=upper_bound(A.begin(),A.end(),x);
	
		it--;
		int y=*it;
		auto it2=upper_bound(B.begin(),B.end(),y);
		auto it3=lower_bound(B.begin(),B.end(),y);
		{
			it2--;
			int z=*it2;
			c=min(c,abs(x-y)+abs(y-z));
		}
		{
			
			int z=*it3;
			c=min(c,abs(x-y)+abs(y-z));
		}
	
	return c;
}

int upper_then_left_right(vector<int>&A,vector<int>&B,int x)
{
	int c=LLONG_MAX;
	auto it=lower_bound(A.begin(),A.end(),x);
	
		int y=*it;
		auto it2=upper_bound(B.begin(),B.end(),y);
		auto it3=lower_bound(B.begin(),B.end(),y);
		{
			it2--;
			int z=*it2;
			c=min(c,abs(x-y)+abs(y-z));
		}
		
		{
			
			int z=*it3;
			c=min(c,abs(x-y)+abs(y-z));
		}
	return c;
}
		
	
		
int32_t main()
{
	IOS
	int n,m,q;cin>>n>>m>>q;
	vector<int>A(n),B(m);
	for(int i=0;i<n;i++)cin>>A[i];
	for(int i=0;i<m;i++)cin>>B[i];
	A.push_back(1e15);
	A.push_back(-1e15);
	B.push_back(1e15);
	B.push_back(-1e15);
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	while(q--)
	{
		int x;cin>>x;
		int c1=lower_then_left_right(A,B,x);
		int c2=lower_then_left_right(B,A,x);
		int c3=upper_then_left_right(A,B,x);
		int c4=upper_then_left_right(B,A,x);
		cout<<min({c1,c2,c3,c4})<<endl;
	}
		
}
	
			
	
	
	
	
	

	

	

	
		


Measured memory_bytes: 4832
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

ll N, M;
ll x[100100], y[100100];

vector<vector<ll>> G;

vector<ll> memo;

ll dp(ll i)
{
    if(memo[i] != -1) return memo[i];
    ll res = 0;
    for(auto v : G[i]) res = max(res, dp(v) + 1);
    return memo[i] = res;
}

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

    cin >> N >> M;

    for(ll i = 0; i < M; i++){
        cin >> x[i] >> y[i];
    }

    G.resize(N+1);
    for(ll i = 0; i < M; i++){
        G[x[i]].push_back(y[i]);
    }

    memo.resize(N + 1, -1);

    ll ans = 0;

    for(ll i = 1; i <= N; i++){
        chmax(ans, dp(i));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10112
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
using namespace std;
int main() {
	while (true) {
		int n;
		scanf("%d", &n);
		if (n == 0) break;
		int count = 0;
		int k;
		bool hoge = false;
		for (int i = 0;i < n;++i) {
			scanf("%d", &k);
			if (k != 0) count++;
			if (k >= 2) hoge = true;
		}
		if(hoge == true)
		printf("%d\n", count+1);
		if (hoge == false)printf("NA\n");
	}
}


Measured memory_bytes: 1040
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int[][] cost = new int[10][10];
			for(int i=0;i<10;i++){
				for(int j=0;j<10;j++){
					cost[i][j] = Integer.MAX_VALUE;
				}
			}
			int a, b, c;
			int m = -1;
			for(int i=0;i<n;i++){
				a = sc.nextInt();
				b = sc.nextInt();
				c = sc.nextInt();
				cost[a][b] = c;
				cost[b][a] = c;
				m = Math.max(Math.max(a, b), m);
			}
			for(int i=0;i<=m;i++) cost[i][i] = 0;
			
			for(int i=0;i<=m;i++){
				for(int j=0;j<=m;j++){
					for(int k=0;k<=m;k++){
						if(cost[j][i]!=Integer.MAX_VALUE && cost[i][k]!=Integer.MAX_VALUE){
							cost[j][k] = Math.min(cost[j][k], cost[j][i]+cost[i][k]);
						}
					}
				}
			}
			
			int min = Integer.MAX_VALUE;
			int num = -1;
			int sum;
			for(int i=0;i<=m;i++){
				sum = 0;
				for(int j=0;j<=m;j++) sum += cost[i][j];
				if(min>sum){
					num = i;
					min = sum;
				}
			}
			System.out.println(num + " " + min);
		}	
	}	
}

Measured memory_bytes: 19516
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9+5;

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

Measured memory_bytes: 1024