akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

int main() {
    string a, b;
    cin >> a >> b;
    if(a.size() == b.size()) {
        for(int i = 0; i < a.size(); i++) {
            if(a[i] == b[i]) {
                if(i == 0) printf("EQUAL\n");
            } else {
                if(a[i] > b[i]) printf("GREATER\n");
                else if(a[i] < b[i]) printf("LESS\n");
                break;
            }
        }
    } else if(a.size() > b.size()) printf("GREATER\n");
    else printf("LESS\n");
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <set>

using namespace std;

#define FOR( i, k, n ) for ( int i = ( k ); i < ( int )( n ); ++i )
#define REP( i, n ) FOR( i, 0, n )

int main() {
	int n, q;
	set< int > nums;
	scanf( "%d", &n );
	REP( i, n ) {
		int num;
		scanf( "%d", &num );
		nums.insert( num );
	}
	scanf( "%d", &q );
	int ans = 0;
	REP( i, q ) {
		int num;
		scanf( "%d", &num );
		if( nums.find( num ) != nums.end() ) ++ans;
	}
	printf( "%d\n", ans );
	return 0;
}

Measured memory_bytes: 1076
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

int main(void)
{
    size_t n;
    scanf("%zu", &n);
    uint_fast32_t t[n];
    for (size_t i = 0; i < n; ++i) {
        scanf("%" SCNuFAST32, &t[i]);
    }
    size_t m;
    scanf("%zu", &m);
    for (size_t i = 0; i < m; ++i) {
        uint_fast32_t total = 0;
        size_t p;
        uint_fast32_t x;
        scanf("%zu %" SCNuFAST32, &p, &x);
        for (size_t j = 0; j < n; ++ j) {
            total += (j == p - 1) ? x : t[j];
        }
        printf("%" PRIuFAST32 "\n", total);
    }

    return 0;
}


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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll n; cin>>n;
	set<ll> st;
	for (ll d=1; d*d<=n; d++)
		if(n%d==0)
			st.insert(d), st.insert(n/d);
	ll ret=0;
	for (auto q : st) {
		ll m=n/q-1;
		if(m<=0||q>=m) continue;
		ret+=m;
	}
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 640
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
int gcd(int x, int y) {
    int r;
    // ユーグリッドの互除法
    while ((r = x % y) != 0) {
        x = y;
        y = r;
    }
    return y;
}
int main() {
    int N, ans;
    cin >> N;
    int A[N];
    rep(i, N) cin >> A[i];
    ans = A[0];
    loop(i, 1, N) ans = gcd(ans, A[i]);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

const int CMax = 100002;

int n, A[CMax], a, b;

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

    sort(A, A+n);

    for (int i = n-1; i > 0 && b == 0; i--) {
        if (A[i] == A[i-1]){
            if (a == 0) a = A[i];
            else b = A[i];
            i--;
        }
    }

    cout << (long long)a*(long long)b << endl;
}


Measured memory_bytes: 640
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
const int maxn = 200005;
#define endl '\n'
#define int ll
#define ld long double
#define all(x) (x).begin(),(x).end()
int32_t main()
{ 
  IOS
 
  for(int i = 1;i<=5;i++){
    int x;
    cin>>x;
    if(x == 0){
      cout<<i<<endl;
    }
  }
  




}

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

#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 repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }


int n, k;
int a[105];
bool dp[100005];
void solve() {
    cin >> n >> k;
    rep(i, n) cin >> a[i];
    reps(i, k) rep(j, n) {
        if (i >= a[j]) dp[i] |= !dp[i - a[j]];
    }
    if (dp[k]) cout << "First" << endl;
    else cout << "Second" << endl;
}

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


Measured memory_bytes: 384
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <math.h> // sqrt()
#include <iomanip>
#define rep(i , n) for (int i = 1; i < (int)(n); i++)
#define repz(i , n) for (int i = 0; i < (int) n; i++)
#define repi(i , r, n) for (int i = r; i <= (int)(n); i++)


using namespace std;

int main() {
    int n, q, l, r;
    cin >> n >> q;
    vector<int> num;
    vector<int> answer;
    string var;
    cin >> var;
    int variable = 0;
    num.push_back(0);
    rep(i , n){
        if (var.at(i - 1) == 'A' && var.at(i) == 'C')
            variable++;
        num.push_back(variable);
        
    }
    repz(i, q){
        cin >> l >> r;
        int kazu = num.at(r - 1) - num.at(l - 1);
        answer.push_back(kazu);
    }
    for (int i : answer)
        cout << i << endl;
    
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;


signed main(){
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<bool>> S(H, vector<bool>(W));
    rep(i,0,H) rep(j,0,W) {
        char c;
        cin >> c;
        S[i][j] = c == '1';
    }
    int answer = INT_MAX;
    rep(i,0,1 << (H-1)) {
        int cnt = 0;
        int splitted = i + (1 << (H-1));
        int lines = 0;
        rep(j,0,H) if (splitted & (1 << j)) lines++;
        cnt += lines - 1;
        vector<int> cnts(lines);
        int current = 0, prevCurrent = 0;
        while (current < W && cnt < answer) {
            int lineNum = 0;
            rep(j,0,H) {
                if (S[j][current]) cnts[lineNum]++;
                if (splitted & (1 << j)) lineNum++;
            }
            bool isValid = true;
            rep(j,0,lines) {
                if (cnts[j] > K) {
                    isValid = false;
                    break;
                }
            }
            if (prevCurrent == current && !isValid) break;
            if (!isValid) {
                cnt++;
                fill(all(cnts), 0);
                prevCurrent = current;
            } else {
                current++;
            }
        }
        if (current == W && cnt < answer) answer = cnt;
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<functional>
#include<math.h>
#include<algorithm>
typedef long long ll;
using namespace std;
//cout << << endl;
int main(){
  int a,b,c,e,f,g;
  int d[5];
  string s,t;
  cin >> d[0] >> d[1] >> d[2] >> d[3] >> d[4];
  int ans=0;
  int max=0;
  int index;
  for(int i=0;i<5;i++){
  /*  ans += d[i] + (10-d[i]%10);
    if(d[i]%10==0){
      ans -= 10;
    }*/
    if(10 - d[i]%10 >= max && d[i]%10!=0){
      max = 10 - d[i]%10;
      index = i;
    }
  }
  for(int i=0;i<5;i++){
    if(i!=index){
      ans += d[i] + (10-d[i]%10);
      if(d[i]%10==0){
        ans -= 10;
      }
    }
  }
  cout << ans+d[index] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#define LL long long
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;

int main()
{
	FIO;
	LL n, sum=0; cin>>n;
	for(LL i=1; i<=n; i++) if(i%3!=0&&i%5!=0) sum+=i;
	cout<<sum<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fastio() ios::sync_with_stdio(0);cin.tie(0);
#define nl "\n"
#define wi(x) cerr << #x << " is " << x << nl

void solve(){
	char ch; cin >> ch;
	if(ch >= 'a' && ch <= 'z') cout << "a";
	else cout << "A";
}

int main(){
	fastio()
	
	int T=1;
	//int T; cin>>T;
	while(T--) solve();

	return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25
 
int main()
{
	string s;
	string t = "abcdefghijklmnopqrstuvwxyz";
	cin >> s;
	map<char, int> mp;
	rep(i, t.size()) {
		mp[t[i]] = 0;
	}
	rep(i, s.size()) {
		mp[s[i]] = 1;
	}
	rep(i, t.size()) {
		if (mp[t[i]] != 1) {
			s += t[i];
			cout << s << endl;
			return 0;
		}
	}
	for(int i = t.size() - 1; i > 0; i--) {
		mp[s[i]] = 0;
		s.pop_back();
		rep(j, t.size()) {
			if (mp[t[j]] == 0 && t[j] > s[i - 1]) {
				s[i-1] = t[j];
				cout << s << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <iomanip>
#include<math.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
int  main(){
  ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	cout.tie(0);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int x,y,z;
    if(k<=a)
      cout<<k<<endl;
    else if(k<=a+b&&k>a)
      cout<<a<<endl;
    else
      cout<<2*a+b-k<<endl;
    }


Measured memory_bytes: 3640
import java.util.Scanner;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(true) {
			String first = scanner.next();
			if(first.equals("-")) {
				break;
			}
			int m = scanner.nextInt();
			for(int i = 0; i < m; i++) {
				int h = scanner.nextInt();
				first = first.substring(h, first.length()) + first.substring(0, h);
			}
			System.out.println(first);
		}
	}
}


Measured memory_bytes: 26304
using System;
using System.Linq;
using System.Numerics;
using System.Text;

namespace TaskB
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ConsoleReader.Read<int>();
            var res = BigInteger.One;
            var threshold = (ulong)1e18;
            var numbers = ConsoleReader.ReadArray<ulong>(n);
            Array.Sort(numbers);
            if (numbers.Any(num => num == 0)) {
                Console.WriteLine(0);
                return;
            }
            for (var i = n - 1; i >= 0; i--)
            {
                res *= numbers[i];
                if (res > threshold)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            Console.WriteLine(res);
        }
    }
}

public static class ConsoleReader
{
    public static T Read<T>()
    {
        var inputBuffer = new StringBuilder();
        int currChar;

        while ((currChar = Console.Read()) != -1)
        {
            if (!char.IsWhiteSpace((char)currChar))
            {
                inputBuffer.Append((char)currChar);
            }
            else if (inputBuffer.Length != 0)
            {
                break;
            }
        }

        return (T)Convert.ChangeType(inputBuffer.ToString(), typeof(T));
    }

    public static T[] ReadArray<T>(int count)
    {
        if (count < 0)
        {
            throw new ArgumentOutOfRangeException(nameof(count), $"'{nameof(count)}' must be >= 0");
        }

        var result = new T[count];

        for (var i = 0; i < count; i++)
        {
            result[i] = Read<T>();
        }

        return result;
    }
}

Measured memory_bytes: 42168
#include <bits/stdc++.h>
using namespace std;
typedef float fl;
typedef long long ll;
#define INF 10000000001;
int S[500001];
int cnt = 0;

void merge(int a[], int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    ll L[n1+1], R[n2+1];
    for(int i =0; i < n1; i++){
        L[i] = a[left+i];
    }
    for(int i =0; i < n2; i++){
        R[i] = a[mid+i];
    }
    L[n1] = INF;
    R[n2] = INF;
    int i = 0, j = 0;
    for(int k = left; k < right; k++){
        cnt++;
        if(L[i]<=R[j]){
            a[k] = L[i++];
        }
        else{
            a[k] = R[j++];
        }
    }
}

void mergeSort(int a[], int left, int right){
    if((left + 1) < right){
        int mid = (left + right) / 2;
        mergeSort(a, left, mid);
        mergeSort(a, mid, right);
        merge(a, left, mid, right);
    }
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> S[i];
    mergeSort(S,0,n);
    for(int i = 0; i < n; i++){
        if(i) cout << " ";
        cout << S[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int k;
string s;
cin>>k>>s;
if(s.size()<=k){
    cout<<s<<endl;
}
else{
    cout<<s.substr(0,k)+"..."<<endl;
}
return 0;
}

Measured memory_bytes: 3644
'use strict';

const input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const NM = input[0].split(' ');
const N = +NM[0];
const M = +NM[1];
const ABs = input.slice(1).map(ab => ab.split(' ').map(Number));

const edges = new Map();
ABs.forEach(ab => {
    if (edges.has(ab[0])) {
        edges.get(ab[0]).push(ab[1]);
    } else {
        edges.set(ab[0], [ab[1]]);
    }
    if (edges.has(ab[1])) {
        edges.get(ab[1]).push(ab[0]);
    } else {
        edges.set(ab[1], [ab[0]]);
    }
});

let que = [{
    edges: edges,
    count: 1,
    current: 1,
    visited: new Set()
}];

let result = 0;

while (que.length != 0) {
    let state = que.shift();

    let newVisited = new Set(state.visited);
    if (newVisited.has(state.current)) continue;
    newVisited.add(state.current);

    if (state.count == N) {
        result++;
        continue;
    }

    let edges = state.edges;
    let currentEdges = edges.get(state.current);
    if (!currentEdges) continue;

    let newEdges = new Map(edges);
    newEdges.delete(state.current);

    for (let next of currentEdges) {
        que.push({
            edges: newEdges,
            count: state.count + 1,
            current: next,
            visited: newVisited
        });
    }
}

console.log(result);

Measured memory_bytes: 46856
res = []
res0 = []
count = 0
5.times do
  p = gets.to_i
  if p%10 == 0
    res0 << p
  else
    res << p
  end
end
nres = res.sort {|a, b| (-1) * (a%10 <=> b%10) }
res0.push(nres)
res0.flatten!

for i in 0..4 do
  count += res0[i]
  if res0[i]%10 != 0 and i != 4
    count += (10 - res0[i]%10)
  end
end
#count += res0[4]
puts count

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>

#define rep(i,m,n) for(int i=(m);i<(n);++i)
#define rem(i,m,n) for(int i=(m);i>(n);--i)
#define MOD 1000000007

using namespace std;

using ll = long long int;
using std::swap;

vector<long long int> v;
vector<long long int> w;

int main() {
	int a, b, c, d;
	int tak, aok;
	cin >> a >> b >> c >> d;
	tak = c / b + (c%b > 0);
	aok = a / d + (a%d > 0);
	if (tak <= aok)cout << "Yes" << '\n';
	else cout << "No" << '\n';

	return 0;

}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int fx(int x)
{
	return x * x;
}


int main()
{
	int i, d, s;
	
	while(cin >> d)
	{
		s = 0;
		for(i = 1; d * i <= (600 - d); i++)
		{
			s = s + fx(d * i) * d;
		}
		
		cout << s << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class UnionFind():
    def __init__(self, n):
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    # グループの数を返す
    def group_count(self):
        return len(self.roots())
    # 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    # print()での表示用
    # all_group_members()をprintする
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = MAP()
P = LIST()
L = [LIST() for i in range(M)]

dic = defaultdict(list)
tree = UnionFind(N+1)
for a, b in L:
    tree.union(a, b)

# a = tree.all_group_members()

ans = 0
for i in range(1, N+1):
    if tree.find(i) == tree.find(P[i-1]):
        ans += 1
print(ans)
# print(a)
# for key, l in a.items():
#     for y in l:
#         dic[key].append(P[y-1])

# print(a)
# youso_set = set()
# graph_set = set()
# ans = 0
# for key, l in a.items():
#     if key == 0:
#         continue
#     youso_set = set(dic[key])
#     graph_set = set(l)
#     intersec = len(youso_set & graph_set)
#     ans += intersec
# print(ans)





Measured memory_bytes: 34312
(defn formula [ X Y x y]
  (unchecked-add-int (Math/abs (unchecked-subtract-int X x)) (Math/abs (unchecked-subtract-int Y y))))
 
(def formula (memoize formula))
 
(defn zero-case [X Y zs]
  (apply min (map (fn [[x y _]] (formula X Y x y)) zs)))
 
(defn Pyramid [ls]
  (let [{lsn false zs true} (group-by (fn [[_ _ h]] (zero? h)) ls)
        ^const range_it (range (unchecked-int 0) (unchecked-int 101))]
    (first
      (for [X range_it
            Y range_it
            :let [Hs (map (fn [[x y h]] (unchecked-add-int h (formula X Y x y))) lsn)
                  H  (first Hs)]
            :when (and (every? #(= H %) (rest Hs))
                    (if (nil? zs)
                      (<= 1 H)
                      (>= (zero-case X Y zs) H)))]
        (format "%d %d %d" X Y H)))))
 
(defn input [N]
  (when-not (zero? N)
    (let [x (unchecked-int (read)) y (unchecked-int (read)) h (unchecked-int (read))]
      (cons [x y h] (input (unchecked-dec-int N))))))
(-> (read) int input Pyramid println) 

Measured memory_bytes: 217088
# ABC333
A,B = gets.chomp.split(" ").map(&:to_i)
flg = false
for i in 1..3 do
    if A * B * i % 2 == 1
        flg = true 
        break
    end
end
if flg == true
    puts "Yes"
elsif flg == false
    puts "No"
end

Measured memory_bytes: 1788
// C.

#include <iostream>
#include <sstream>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

typedef long long LL;

int n, m, q;
vector<tuple<int, int, int, int>> v;
LL ans;

void dfs(int c, vector<int> &seq) {
	if (c < n) {
		for (int d = seq[c - 1]; d <= m; ++d) {
			seq[c] = d;
			dfs(c + 1, seq);
		}
	} else {
		LL score = 0;
		for (int i = 0; i < q; ++i) {
			if (seq[get<1>(v[i])] - seq[get<0>(v[i])] == get<2>(v[i])) {
				score += get<3>(v[i]);
			}
		}
		ans = max(ans, score);
	}
}

int main(int argc, char* argv[]) {
	cin >> n >> m >> q;
	for (int i = 0; i < q; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		v.emplace_back(a - 1, b - 1, c, d);
	}
	for (int i = 1; i <= m; ++i) {
		vector<int> seq(n, i);
		dfs(1, seq);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/10/02  Problem: Nagoya_univ_contest16_c  / Link:   ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;
LL a[100005];
LL ans = 0LL;

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

	cin >> N;
	set<LL>se;
	FOR(i, 0, N) {
		cin >> a[i];
		if (se.count(a[i])==1) {
			se.erase(a[i]);
		}
		else {
			se.insert(a[i]);
		}
	}
	cout << se.size() << endl;

	return 0;
}

Measured memory_bytes: 5760
a = gets.split(" ")

N = a[0].to_i
K = a[1].to_i

num_div = []
for i in 1..K do
  num_div[i-1] = 0
end
for i in 1..N do
  j = i % K
  num_div[j] += 1
end

ans = 0
for i in 0..K-1 do
  res = (K - i) % K
  if (res * 2) % K == 0 then
    ans += num_div[i] * (num_div[res] ** 2)
  end
end
puts ans

Measured memory_bytes: 15856
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		for(int i = 0 ; i < n; i++) s[i] = sc.next();
		long[] a = new long[5];
		for(int i = 0 ; i < n ; i++) {
			if(s[i].charAt(0) == 'M') a[0]++;
			if(s[i].charAt(0) == 'A') a[1]++;
			if(s[i].charAt(0) == 'R') a[2]++;
			if(s[i].charAt(0) == 'C') a[3]++;
			if(s[i].charAt(0) == 'H') a[4]++;
		}
		long ans = 0;
		for(int i = 0 ; i < 5 ; i++) {
			for(int j = i + 1 ; j < 5 ; j++) {
				for(int k = j + 1 ; k < 5 ; k++) {
					ans += a[i] * a[j] * a[k];
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 50604
#include <iostream>

using namespace std;


int main()
{
    int n,d1,d2,j=0;
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>d1;
        cin>>d2;
        if (d1==d2){
            j++;
        }else if(d1!=d2 && j<3){
            j=0;
        }
    }
    if (j>2){
        cout<<"Yes";
    }else {
        cout<<"No";
    }
}


Measured memory_bytes: 3132
using System;
using System.Linq;
using System.Collections.Generic;

class Amondai
{
    static void Main()
    {
        var b = Console.ReadLine();
        var ans = 'C';
        switch(b){
            case "A": ans = 'T';break;
            case "T": ans = 'A';break;
            case "C": ans = 'G';break;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 9044
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;

public class Main{
	static ArrayList<ArrayList<Edge>> tree;
	static long[] depth;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		tree = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			tree.add(new ArrayList<>());
		}
		for (int i = 0; i < n - 1; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			long c = sc.nextLong();
			tree.get(a).add(new Edge(b, c));
			tree.get(b).add(new Edge(a, c));
		}
		int q = sc.nextInt();
		int k = sc.nextInt() - 1;
		int[] x = new int[q];
		int[] y = new int[q];
		for (int i = 0; i < q; i++) {
			x[i] = sc.nextInt() - 1;
			y[i] = sc.nextInt() - 1;
		}
		depth = new long[n];
		for (int i = 0; i < n; i++) {
			depth[i] = -1;
		}
		depth[k] = 0;
		dfs(k);
		for (int i = 0; i < q; i++) {
			System.out.println(depth[x[i]] + depth[y[i]]);
		}
	}
	static void dfs(int n) {
		for (Edge edge :
				tree.get(n)) {
			if (depth[edge.to] == -1) {
				depth[edge.to] = depth[n] + edge.distance;
				dfs(edge.to);
			}
		}
	}
}

class Edge {
	int to;
	long distance;
	Edge(int to, long distance) {
		this.to = to;
		this.distance = distance;
	}
}

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


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

#define loop(i, x, y) for (i = x; i < y; i++)
#define loopr(i, x, y) for (i = x; i > y; i--)

//use *it instead of it
#define vloop(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define vloopr(it, x) for (auto it = x.end() - 1; it != x.begin() - 1; it--)

#define yes printf("YES\n")
#define no printf("NO\n")
#define pb push_back
#define mp make_pair

#define debug(x) cerr << #x << ":" << x << endl
#define yo cerr << "yo" << endl

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;

#define test(t) \
    ll t;       \
    cin >> t;   \
    while (t--)

//use double
#define precision(x)       \
    cout.setf(ios::fixed); \
    cout << setprecision(10) << x << endl;

// ll gcd(ll x_f, ll y_f)
// {
//     if (x_f == 0)
//         return y_f;
//     return gcd(y_f % x_f, x_f);
// }

// ll power(ll x_f, ll y_f, ll m_f)
// {
//     ll res_f = 1;

//     x_f = x_f% m_f;
//     while (y_f)
//     {
//         if (y_f & 1)
//             res_f = (res_f * x_f) % m_f;
//         y_f = y_f >> 1;
//         x_f = (x_f * x_f) % m_f;
//     }
//     return res_f;
// }

// ll less(ll x_f, ll y_f)
// {
//     return (x_f > y_f) ? y_f : x_f;
// }
// ll more(ll x_f, ll y_f)
// {
//     return (x_f < y_f) ? y_f : x_f;
// }

ll fac(ll x_f)
{
    ll fac_f = 1;
    for (ll i = 1; i <= x_f; i++)
        fac_f *= i;

    return fac_f;
}

bool composite[1000007] = {false};
ll seive(ll x)
{
    composite[0] = true;
    composite[1] = true;
    for (ll i = 2; i <= x; i++)
    {
        if (!composite[i])
        {
            for (ll j = 2 * i; j <= x; j += i)
            {
                composite[j] = true;
            }
        }
    }
}

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

    ll x;
    cin >> x;
    if (x == 1)
        cout << 0 << endl;
    else
    {
        cout << 1 << endl;
    }

    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

#define INF 1<<29

template <typename T>
struct BipartiteMatching {
  struct edge { int to, rev; T cap; };

  typedef vector<edge> Edges;
  vector<Edges> G;
  int V, source, sink;
  vector<int> level, iter;
  
  BipartiteMatching(int V1, int V2) {
    V = V1 + V2 + 2, source = V-2, sink = V-1;
    G.resize(V);
    add_sink_source(V1, V2);
  }

  void add_edge(int from, int to) {
    G[from].push_back((edge){to, (int)G[to].size(), 1});
    G[to].push_back((edge){from, (int)G[from].size()-1, 0});
  }

  void add_sink_source(int V1, int V2) {
    for (int i = 0; i < V1; i++) add_edge(source, i);
    for (int i = V1; i < V1+V2; i++) add_edge(i, sink);
  }

  void bfs(int source) {
    level.assign(V, -1);
    queue<int> que;
    que.push(source);
    level[source] = 0;
    while (!que.empty()) {
      int v = que.front(); que.pop();
      for (int i = 0; i < (int)G[v].size(); i++) {
	edge &e = G[v][i];
	if (e.cap > 0 && level[e.to] < 0) {
	  level[e.to] = level[v] + 1;
	  que.push(e.to);
	}
      }
    }
  }

  T dfs(int v, int sink, T flow) {
    if (v == sink) return flow;
    for (int &i = iter[v]; i < (int)G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
	T d = dfs(e.to, sink, min(e.cap, flow));
	if (d > 0) {
	  e.cap -= d;
	  G[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }

  T dinic() {
    T flow = 0;
    while (true) {
      bfs(source);
      if (level[sink] < 0) return flow;
      iter.assign(V, 0);
      T f;
      while ((f = dfs(source, sink, INF)) > 0) {
	flow += f;
      }
    }
  }
};


int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int X, Y, E;
  cin >> X >> Y >> E;
  BipartiteMatching<int> bp(X, Y);
  REP(i, E) {
    int x, y;
    cin >> x >> y;
    bp.add_edge(x, X+y);
  }
  cout << bp.dinic() << endl;
  return 0;
}

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

#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1000000000
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

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

void solution() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<char>> A(n, vector<char>(m));
  vector<vector<int>> dist(n, vector<int>(m, INF));
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  a--, b--, c--, d--;
  rep(i, 0, n, 1) {
    rep(j, 0, m, 1) { cin >> A[i][j]; }
  }
  int dx[] = {0, 1, 0, -1};
  int dy[] = {-1, 0, 1, 0};
  auto valid = [&](const int x, const int y) {
    return x >= 0 && x < n && y >= 0 && y < m;
  };

  set<tuple<int, int, int>> q;
  q.insert(mt(0, a, b));
  dist[a][b] = 0;
  while (!q.empty()) {
    int x = get<1>(*q.begin());
    int y = get<2>(*q.begin());
    int dd = get<0>(*q.begin());
    q.erase(q.begin());
    if (dd > dist[x][y]) continue;
    for (int w = 0; w < 4; w++) {
      for (int i = 1; i <= k; i++) {
        if (!valid(x + dx[w] * i, y + dy[w] * i)) break;
        if (dist[x + dx[w] * i][y + dy[w] * i] < dist[x][y] + 1) break;
        if (A[x + dx[w] * i][y + dy[w] * i] == '@') break;
        // cout << x + dx[w] * i << " " << y + dy[w] * i << " " << dist[x][y] +
        // 1
        //<< endl;
        dist[x + dx[w] * i][y + dy[w] * i] = dist[x][y] + 1;
        q.insert(mt(dist[x][y] + 1, x + dx[w] * i, y + dy[w] * i));
      }
    }
  }
  cout << (dist[c][d] == INF ? -1 : dist[c][d]) << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


Measured memory_bytes: 15604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<bitset>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll inf = 1LL<<60;

ll n,k;
int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    cin>>n>>k;
    ll a[n];
    REP(i,n){
        cin >> a[i];
    }
    ll ans = inf;
    for(ll bit=0; bit < (1<<n); bit++){
        ll now = 0;
        ll max_l = 0;
        if(bitset<64>(bit).count() >= k && (bit & 1)){
            REP(i,n){
                if(bit & (1<<i)){
                    if(max_l >= a[i]){
                        now += max_l+1 - a[i];
                        max_l = max_l+1;
                    }
                    else{
                        max_l = a[i];
                    }
                }
                else{
                    if(max_l < a[i]){
                        max_l = a[i];
                    }
                }
            }
            ans = min(ans,now);
        }
    }

    cout << ans << endl;
}

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

const int N = 3001000;
set<long long> pset;

void prime(){
  vector<int> plist(N);
  for (int i=0; i<N; i++) plist[i] = i;
  for (int i=2; i<N; i++){
    if (plist[i] > 1){
      pset.insert(i);
      for (int j=2; i*j<N; j++){
        plist[i*j] = 0;
      }
    }
  }
}

int main(){
  long long A, B;
  cin >> A >> B;
  prime();
  set<long long> setA, setB;
  setA.insert(1);
  setB.insert(1);
  for (auto p : pset){
    if (A%p==0) {
      setA.insert(p);
      while (A%p==0){
        A /= p;
      }
    }
    if (B%p==0) {
      setB.insert(p);
      while (B%p==0){
        B /= p;
      }
    }
  }
  setA.insert(A);
  setB.insert(B);
  int ans = 0;
  for (auto a : setA){
    if (setB.find(a)!=setB.end()) {
      ans++;
    }
  }
  cout << ans << endl;
}


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

int main(){
  vector<int> a(4);
bool ab = false,b=false,c=false,d=false;
for(int i=0; i<4; i++){
cin >> a[i];
if(a[i] == 1) ab=true;
if(a[i] == 9) b=true;
if(a[i] == 7) c=true;
if(a[i] == 4) d=true;
}
if(ab == true && b == true && c  == true && d== true){
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String S = "";
        String T = "";
        try {
            S = reader.readLine();
            T = reader.readLine();
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (T.startsWith(S)) {
          System.out.println("Yes");
        } else {
          System.out.println("No");
        }
    }
}

Measured memory_bytes: 32408
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){

  int N, C, K, T;
  cin >> N >> C >> K;
  vector<int> vec(N);

  for (int i = 0; i < N; i++){
    cin >> T;
    vec.at(i) = T;
  }
  sort(vec.begin(), vec.end());
  int ans = 1, sum = 1, memo=vec[0];

  for (int i = 1; i < N; i++) {
    if(sum == C || memo+K < vec[i]){ // バスに全員乗り、かつ、memo+Kが時刻より大きい場合
      ans++;
      sum = 1;
      memo = vec[i];
    }
    else sum++;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
t = [tuple(map(int, input().split())) for i in range(N)] 
t = sorted(t, key = lambda tt: tt[0])
n = 0
ans = 0
for a,b in t:
    if n+b < M:
        ans += a*b
        n += b
    else:
        ans += (M-n)*a
        break
print(ans)



Measured memory_bytes: 18884
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <iomanip>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
ll a,b;
bool isprime(ll n) {
    if(n == 2)return true;
    if(n < 2 || n%2 == 0) return false;
    for(ll i=3;i*i<=n;i+=2)
    	if(n%i == 0)
    		return false;
    return true;
}
int get_div(ll x){
    ll cnt=1;
	for(ll i=1;i*i<=x;i++){
	    if(x%i==0){
            cnt+=(isprime(i));
            cnt+=(x/i!=i&&isprime(x/i));
	    }
	}
	return cnt;
}
int main() {
	cin>>a>>b;
    cout<<get_div(__gcd(a,b));
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int n,m,l,r,i;
  scanf("%d%d",&n,&m);
  int lmax=0,rmin=n;
  for(i=0;i<m;i++){
    scanf("%d%d",&l,&r);
    if(lmax<l)lmax=l;
    if(rmin>r)rmin=r;      
  }
  int ans=rmin-lmax+1;
    printf("%d\n",ans>0?ans:0);
}


Measured memory_bytes: 128
#include<stdio.h>

int main(void){
  
  char S[100000];
  int i;
  int count = 0;
 
  scanf("%s", &S);
  
  for(i = 1; S[i]; i++){
    
    if(S[i - 1] == S[i]){
      
      count++;
      if(S[i] == '0') S[i] = '1';
      else if(S[i] == '1') S[i] = '0';
      
    }
    
  }
 
  printf("%d\n", count);

  
  
  

  
  return 0;
}
  

Measured memory_bytes: 256
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
    char ch;
    const int length = 26;
    int counter[length] = {};

    while (cin >> ch) {
        ch = tolower(ch);
        if (!isalpha(ch)) {
            continue;
        }

        int index = ch - 'a';
        counter[index]++;
    }

    for (int i = 0; i < length; i++) {
        printf("%c : %d\n", i + 'a', counter[i]);
    }

    return 0;
}



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

long long n, m, k;

long long read(){
	long long x, f = 1;
	char c = getchar();
	while (c < '0' || c > '9'){
		if (c == '-') f = -1;
		c = getchar();
	}
	x = c ^ '0';
	c = getchar();
	while (c >= '0' && c <= '9'){
		x = (x << 1) + (x << 3) + (c ^ '0');
		c = getchar();
	}
	return f == 1 ? x : -x;
}

void print(long long x){
	if (x < 0){
		putchar('-');
		print(-x);
		return ;
	}
	if (x >= 10) print(x / 10);
	putchar(char(x % 10 + '0'));
}

int main(){
	n = read(), m = read(), k = read();
	for (int i = 1; i <= k; ++i)
	{
		if (i % 2 == 1){
			if (n == 0) continue ;
			if (n % 2 == 1) n -= 1;
			m += n / 2;
			n /= 2;
		}
		else {
			if (m == 0) continue ;
			if (m % 2 == 1) m -= 1;
			n += m / 2;
			m /= 2;
		}
	}
	print(n);
	putchar(' ');
	print(m);
	putchar('\n'); 
	return 0;
}


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

int     main() {
        int X;
        cin >>X;
        int qq=1;
        for (int i=2; X>=i*i; i++) {
                int ii=i;
                while (X>=ii*i) ii *=i;
                qq=max(qq, ii);
        }
        cout <<qq <<endl;
        return 0;
};

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

int main()
{
  int n;
  cin >> n;
  vector<int> FizzBuzz(n+1);//FizzBuzz列の０番は使用しない
  for(int i = 1;i <= n;i++){
    if(i % 3 == 0 || i % 5 == 0){
      continue;
    }
    else if(i % 3 != 0 && i % 5 != 0){
      FizzBuzz[i] = i;
    }
  }
  int64_t sum = 0;
  for(int i = 1;i <= n;i++){
    sum += FizzBuzz[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 7212
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
int main() {
	int N, M, ar[100004];
	scanf("%d %d", &N, &M);
	for(int i=0;i<N;++i)
		scanf("%d", &ar[i]);
	sort(ar, ar+N);
	vector<pair<int, int> > v;
	for(int i=0;i<M;++i) {
		int x, y;
		scanf("%d %d", &x, &y);
		v.push_back(make_pair(y, x));
	}
	sort(v.begin(), v.end());
	int pos = 0;
	for(int i=M-1;i>=0 && pos<N;--i) {
		while(pos<N && ar[pos] < v[i].first && v[i].second) {
			ar[pos] = v[i].first;
			v[i].second--;
			pos++;
		}
	}
	long long ans = 0;
	for(int i=0;i<N;++i)
		ans += ar[i];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1784
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
using namespace std;
int main(){
    string S;
    cin >> S;
    long long int count = 0;
    long long int w_count = 0;
    for(int i = 0; i < S.length(); i++){
        if(S[i] == 'W'){
            count += (i-w_count);
            w_count ++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 644
from collections import deque
n,m = map(int, input().split())
ikisaki=[[] for _ in range(n+1)]

for _ in range(m):
    a,b = map(int, input().split())
    ikisaki[a].append(b)
    ikisaki[b].append(a)
ans=[0]+[1]+[0]*(n-1)
tansakuheya=deque([1])
tmp=deque()

for _ in range(1000009):

    for bangou in tansakuheya:

        for heya in ikisaki[bangou]:
            if ans[heya]==0:
                ans[heya]=bangou
                tmp.append(heya)

    tansakuheya=tmp.copy()
    tmp=deque()


    if not tansakuheya:
        break

print("Yes")
for i in range(2,n+1):
	print(ans[i])

Measured memory_bytes: 34580
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll M = 998244353;


int main() {
  int n;
  cin >> n;
  vector<int> dis(n);
  rep(i,n) {
    int x;  cin >> x;
    if(i==0&&x!=0) {
      cout << 0 << endl;
      return 0;
    } 
    dis[x]++;
  }
  if(dis[0]!=1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  for(int i=1; i<n; i++) {
    rep(j,dis[i]) {
      ans*=dis[i-1];
      ans%=M;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3752