akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int x = in.nextInt();
			int y = in.nextInt();
			
			out.println(gcd(x, y));

		}
	}
	
	public static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	public static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}
	
}



Measured memory_bytes: 24292
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

typedef pair<P,Ps> PIS;
PIS team[10];

int main(){
	int n;
	while(cin >> n && n){
		rep(i, n){
			cin >> team[i].second.second;
			team[i].second.first = i;
			team[i].first = P(n-1, 0);
			rep(j, n - 1) {
				int num;
				cin >> num;
				if(num == 0) team[i].first.first--;
				if(num == 1) team[i].first.second++;
			}
		}
		sort(team, team + n);
		rep(i, n) cout << team[i].second.second << endl;
	}
	return 0;
}

Measured memory_bytes: 0
N = int(input())
S = input()

s = [0] * 26
for c in S:
    s[ord(c) - 97] += 1
num = 1
for i in range(26):
    if s[i] > 0:
        num *= (s[i] + 1)
print((num - 1) % (10**9 + 7))

Measured memory_bytes: 3188
//! # Bundled libraries

use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        dss: [(u32, u32)],
    }

    let ans = dss.windows(3).any(|w| {
        let (a, b) = w[0];
        let (c, d) = w[1];
        let (e, f) = w[2];
        a == b && c == d && e == f
    });
    println!("{}", if ans { "Yes" } else { "No" });
}

// The following code was expanded by `cargo-equip`.


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

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, pll> ppll;

#define MOD 1000000007
#define f(a, b, c) for (ll(a) = (b); (a) < (c); ++(a))
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define rep(i, n) f(i, 0, n)
#define ff first
#define ss second
#define pb push_back
#define all(v) v.begin(), v.end()
#define wh(t) while (t--)
#define inf (ll)1e18
#define modd 998244353
#define pp(var) cout<<var<<"\n";
#define pm(var1, var2) cout<<var1<<" "<<var2<<"\n";
#define pv(i,v) rep(i,v.size()) cout<<v[i]<<" "; pp("");
#define pa(i,n,v) rep(i,n) cout<<v[i]<<" "; pp("");

ll binpow(ll a, ll n)
{
	ll i = 1;
	while (n > 0)
	{
		if (n & 1)
			i = (i * a) % MOD;
		a = (a * a) % MOD;
		n = n >> 1;
	}
	return i % MOD;
}

ll isprime(ll n)
{
	if (n == 0 || n == 1)
		return n;
	if (n % 2 == 0)
		return (ll)2;
	if (n % 3 == 0)
		return (ll)3;
	else
	{
		for (ll i = 5; i * i <= n; i += 6)
		{
			if (n % i == 0)
				return i;
			if (n % (i + 2) == 0)
				return (i + 2);
		}
		return n;
	}
}

const ll N = 5e5 + 5;
ll fact[N];
void precalc() {
	fact[0] = 1;
	for (ll i = 1; i < N; ++i) {
		fact[i] = (fact[i - 1] * i) % MOD;
	}
}

ll ncr(ll n, ll r) {
	ll res = (fact[n] * binpow(fact[n - r], MOD - 2)) % MOD;
	return (res * binpow(fact[r], MOD - 2)) % MOD;
}

int main() {
	fast;
	ll l, r, n, m, i, j, k, x, y, t, q;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	cin >> n >> m;
	precalc();

	ll ans = (ncr(m, n) * fact[n]) % MOD;
	ans = (ans * ans) % MOD;
	j = -1;
	for (i = 1; i <= n; ++i) {
		x = (ncr(m, i) * ncr(n, i)) % MOD;
		x = (x * fact[i]) % MOD;
		y = (ncr(m - i, n - i) * fact[n - i]) % MOD;
		y = (y * y) % MOD;

		x = (x * y) % MOD;

		x =  j * x;
		ans = (ans + x) % MOD;
		if (ans < 0) ans += MOD;
		j = -j;
	}
	pp(ans);
}

Measured memory_bytes: 7496
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    vector<pair<string, int>> a;
    string x;
    cin >> n;
    a.resize(n);
    for(auto &i : a) cin >> i.first >> i.second;
    cin >> x;
    ll ans = 0, b = 0;
    for(auto  i : a) {
    	if(b) ans += i.second;
    	b|=(i.first==x);
    }
    cout << ans;
}


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

#define SIZE 40

int main() {
    string s;
    cin >> s;
    int i = 0, j = s.length() - 1;
    int total = 0;
    while(i < j) {
        if(s[i] == s[j]) {
            i++;
            j--;
            continue;
        }
        if(s[i] == 'x') {
            i++;
            total++;
            continue;
        }
        if(s[j] == 'x') {
            j--;
            total++;
            continue;
        }
        total = -1;
        break;
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut done: bool = false;

    while !done {
        let h = read();
        let w = read();
        if h == 0 && w == 0 {
            done = true;
        } else {
            for index_h in 0..h {
                for index_w in 0..w {
                    if index_h == 0 || index_h == (h - 1) {
                        print!("#");
                    } else if index_w == 0 || index_w == (w - 1) {
                        print!("#");
                    } else {
                        print!(".");
                    }
                }
                println!();
            }
            println!();
        }
    }
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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;
}

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

template <class T>
T find_min(T l, T r, bool f(T)) {
  T c;
  while (r - l > 1) {
    c = (r + l) / 2;
    if (f(c)) {
      r = c;
    } else {
      l = c;
    }
  }

  return r;
}

template <class T>
T find_max(T l, T r, bool f(T)) {
  T c;
  while (r - l > 1) {
    c = (r + l) / 2;
    if (f(c)) {
      l = c;
    } else {
      r = c;
    }
  }

  return l;
}

int K;
vector<ll> A;

ll sim(ll N) {
  rep(i, K) {
    N = (N / A[i]) * A[i];
  }
  return N;
}

bool sub(ll trial) {
  return sim(trial) >= 2;
}


bool sup(ll trial) {
  return sim(trial) <= 2;
}


signed main() {
  cin >> K;
  A = vector<ll>(K);
  rep(i, K) {
    cin >> A[i];
  }

  ll temp = find_min(1LL, LINF, sub);
  if (sim(temp) != 2) {
    cout << -1 << endl;
    return 0;
  }

  cout << find_min(1LL, LINF, sub) << ' ' << find_max(1LL, LINF, sup) << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int N = 1e5 + 5;

int n, x, y;
int fi[N], to[N * 2], nt[N * 2], tot = 1;

void link(int x, int y) {
	nt[++ tot] = fi[x], to[tot] = y, fi[x] = tot;
}

char str[N]; int cr[N];

int d[N], d0, r[N], ky[N];

void Init() {
	scanf("%d", &n);
	fo(i, 1, n - 1) {
		scanf("%d %d", &x, &y);
		r[x] ++, r[y] ++;
		link(x, y); link(y, x);
	}
	scanf("%s", str + 1);
	fo(i, 1, n) cr[i] = str[i] == 'B' ? 1 : 0;
}

void build() {
	fo(i, 1, n) ky[i] = 1;
	fo(i, 1, n) if(r[i] == 1 && cr[i] == 1)
		d[++ d0] = i;
	for(int i = 1; i <= d0; i ++) {
		int x = d[i]; ky[x] = 0;
		for(int j = fi[x]; j; j = nt[j]) {
			int y = to[j];
			if(-- r[y] == 1 && cr[y] == 1) d[++ d0] = y;
		}
	} 
}

int rt, fa[N], c[N];
int sum, ans;
int s[N], f[N], g[N];

void dg(int x) {
	c[x] = !((r[x] & 1) ^ cr[x]);
	d[x] = (c[x] ? 1 : -1) + 1;
	s[x] = s[fa[x]] + d[x];
	sum += c[x];
	f[x] = s[x], g[x] = s[x] - d[x];
	for(int i = fi[x]; i; i = nt[i]) if(to[i] != fa[x] && ky[to[i]]) {
		int y = to[i];
		fa[y] = x;
		dg(y);
		ans = max(ans, max(f[x] + g[y], g[x] + f[y]) - 2 * s[x] + d[x]);
		f[x] = max(f[x], f[y]);
		g[x] = max(g[x], g[y]);
	}
}

void work() {
	sum = -2;
	fo(i, 1, n) if(ky[i])
		rt = i, sum += 2;
	if(!rt) {
		pp("0\n");
		exit(0);
	}
	dg(rt);
}
int main() {
	Init();
	build();
	work();
	pp("%d\n", sum - ans);
}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>
#include <algorithm>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    vector<uint> v(3,0);
    for (auto &&i: irange(0U, 3U)){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    cout << v.at(0) + v.at(1);
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  int m = sqrt(N);
  int ans = m * m;
  printf("%d\n", ans);
  return 0;
}


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

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

    int ans = 0;
    rep(i,n) {
        int p;
        cin >> p;
        if (i + 1 == p) {
            ans++;
            cin >> p;
            ++i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
 
using namespace std;
using namespace __gnu_pbds;
 
// template<typename T>
using o_set=tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define M 1000010


int main(){
	IOS;
	ll n;cin>>n;
	ll a[n];
	ll ans=0,mx=-1,mn=inf;
	rep(i,0,n){
		cin>>a[i];
		mn=min(mn,a[i]);
		if(a[i]==mn)ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int a,b,k,i,j;
    scanf("%d%d%d",&a,&b,&k);
    for (i=a,j=1;i<=b&&j<=k;i++,j++) printf("%d\n",i);
    for (j=max(i,b-k+1);j<=b;j++) printf("%d\n",j);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b,c,n;
    cin>>a>>b>>c>>n;
    int ans = 0;
    for(int i=0;i*a<=n;i++){
        for(int j=0;j*b + i*a<=n;j++){
            if((n-i*a-j*b)%c==0){ans++;}
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n;
    string s;
    cin >> n >> s;
    vector<vector<int>> pos(10);
    for(int i = 0; i < n; ++i){
        pos[s[i] - '0'].emplace_back(i);
    }
    for(int i = 0; i < 10; ++i) pos[i].emplace_back(n);
    int ans = 0;
    for(int i = 0; i < 10; ++i){
        int p1 = *lower_bound(pos[i].begin(), pos[i].end(), 0);
        if(p1 == n) continue;
        for(int j = 0; j < 10; ++j){
            int p2 = *upper_bound(pos[j].begin(), pos[j].end(), p1);
            if(p2 == n) continue;
            for(int k = 0; k < 10; ++k){
                int p3 = *upper_bound(pos[k].begin(), pos[k].end(), p2);
                if(p3 < n)  ++ans;
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
	string s;
	cin >> s;
	if (s[0] == '9' || s[1] == '9') {
		cout << "Yes" << endl;
	}
	else {
		cout << " No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int INF=1e9;
const int MOD=1e9+7;
const double pi=acos(-1);
// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
int main(){
  int n,m;
  cin >> n >> m;
  UnionFind tree(n);
  vector<int>p(n);
  rep(i,n)cin>>p[i];
  rep(i,m){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    tree.merge(x,y);
  }
  int ans=0;
  rep(i,n){
    if(tree.issame(p[i]-1,i))ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define inf 1000000007
using namespace std;

ll a[100001],b[100001];
int main()
{
    ll i,j,k,h,n,m,t,f=0;
    cin>>n;
    FOR(i,1,n)  cin>>a[i]>>b[i];
    i=n;
    while(i>0)  {
        if((a[i]+f)%b[i]==0) ;
        else f = f + b[i] - (a[i]+f)%b[i];
        i--;
    }
    cout<<f<<endl;
    return 0;
}

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

int main() {
	int a, b;
	int s;
	cin >> a >> b;
	int count = a;
	while (count <= 20) {
		if (count == b) {
			cout << a + b;
			//cin >> s;
			return 0;
		}
		else
			count += a;
	}
	cout << b - a;
	//cin >> s;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		int ans = 0;
		for (int i = 0; i < s.length(); i++) {
			for (int o = i; o <= s.length(); o++) {
				if (ans < ok(s.substring(i, o))) {
					ans = ok(s.substring(i, o));
				}
			}
		}
		System.out.println(ans);
	}

	static public int ok(String s) {
		char c[] = s.toCharArray();
		boolean ans = true;
		for (int i = 0; i < c.length; i++) {
			if (!(c[i] == 'A' || c[i] == 'C' || c[i] == 'G' || c[i] == 'T')) {
				ans = false;
			}
		}
		int a = 0;
		if (ans) {
			a = s.length();

		} else {
			a = 0;

		}
		return a;
	}
}

Measured memory_bytes: 22736
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = int(input())
a = inpl()
flag = 0
t = 1
for i in range(0, n):
    if a[i] == 0:
        flag = 1
        print(0)
        break

aaa = 0

if not flag:

    for i in range(0, n):
        t *= a[i]
        if t > 1000000000000000000:
            print(-1)
            aaa = 1
            break
    if not aaa:
        print(t)


Measured memory_bytes: 21600
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s = str(readline().rstrip().decode('utf-8'))
    s = s.replace("><", ">_<").split("_")
    cnt = 0
    for sv in s:
        r = l = 0
        for i in range(len(sv)):
            if sv[i] == ">":
                r += 1
            else:
                l += 1
        cnt += r * (0 + r-1) // 2 + l * (0 + l-1) // 2 + max(r, l)
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 58480
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

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

void solve()
{
	int i,j;
	int n;
	cin>>n;


	cout<<pow(n,3)<<endl;

}

Measured memory_bytes: 4140
#include <iostream>
#include <map>
#include <queue>
#include <cstdio>
#include <utility>
#include <stdio.h>
#define F first
#define S second
using namespace std;
int n,m;
int cost[111][111];
int dics(int st,int go);
int main(){
  int st,go,yo,ha;//左からスタート、ゴール、予算、柱代金
  int a,b,c,d;//a,b=つないでる街 c=aからbのコスト　d=bからaのコスト
  int iki,kaeri;
  int ans=0;
  cin >> n >> m;
  for(int i=0;i<21;i++){
    for(int j=0;j<21;j++){
      cost[i][j]=999999;
    }
  }
  for(int i=0;i<m;i++){
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    cost[a][b]=c;//aからbへのコスト
    cost[b][a]=d;//bからaへのコスト
  }
  scanf("%d,%d,%d,%d",&st,&go,&yo,&ha);
  iki=dics(st,go);
  kaeri=dics(go,st);
  ans=iki+kaeri;
  cout << yo-ha-ans << endl;//予算から柱代金と運賃を引いた褒美
}

int dics(int st,int go){//運賃図りますよー
  int d[1111];//エッジのコスト格納用
  queue<pair<int,int> > q;
  pair<int,int> p;
  for(int i=0;i<21;i++){//めっちゃ多い数を
    d[i]=999999;
  }
  d[st]=0;//スタート地点はコスト0確定だから
  q.push( make_pair(0, st) );
  while(!q.empty()){//見るところが無くなりすべての値が確定するまで
    p=q.front();
    q.pop();
    for(int i=1;i<=n;i++){//各街は1?nで表されるから
      if(cost[p.S][i]!=999999){//通れたら
	if(d[i]>p.F+cost[p.S][i]){//現在のそのエッジまでの最小値よりも小さかったら
	  d[i]=cost[p.S][i]+p.F;
	 q.push( make_pair(d[i], i) );//そこまでのコストと今いる場所
	}
      }
    }
  }
  return d[go];
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
using namespace std;
     
#define int  unsigned long long
#define endl '\n'
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e5 + 11;

void solve(){
  map<int, char> m;
  m[1] = 'A';
  m[2] = 'B';
  m[3] = 'C';
  m[4] = 'D';
  m[5] = 'E'; 
  m[6] = 'F';
  m[7] = 'G'; 
  m[8] = 'H';
  m[9] = 'I';
  m[10] = 'J';
  m[11] = 'K';
  m[12] = 'L'; 
  m[13] = 'M';
  m[14] = 'N';
  m[15] = 'O';
  m[16] = 'P';
  m[17] = 'Q';
  m[18] = 'R';
  m[19] = 'S';
  m[20] = 'T';
  m[21] = 'U';
  m[22] = 'V'; 
  m[23] = 'W';
  m[24] = 'X';
  m[25] = 'Y';
  m[26] = 'Z';
  int h, w;
  cin >> h >> w;
  string grid[h][w];
  for (int i = 0; i < h; i++)
	for (int j = 0; j < w; j++) 
       cin >> grid[i][j];
  int curr_x, curr_y;
  for (int i = 0; i < h; i++)
   for (int j = 0; j < w; j++)
     if (grid[i][j]  == "snuke")
       curr_x = i + 1, curr_y = j + 1;
  cout << m[curr_y];
  cout << curr_x << endl;
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  solve();	
}


Measured memory_bytes: 256
#include <cstdio>

template<class T>void fr(T &a) {
    T s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=w*s;
}
template<class T>T fr() {T a;fr(a);return a;}
#define R() fr<int>()

const int N=2e5;
int a[N+10];

int main() {
	int n=R(),now=1,ans=0;
	for(int i=1;i<=n;i++) fr(a[i]);
	for(int i=1;i<=n;i++)
		if(a[i]==now)now++;
		else ans++;
	return !printf("%d\n",ans!=n?ans:-1);
}

Measured memory_bytes: 896
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define TM ((int)6000)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

int n,t;
int ans;

vector <pii> v;

int dp[TM + 5];

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> n >> t;
	v.resize(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i].first >> v[i].second;

	sort(all(v));

	for (int i = 0; i < v.size(); ++i)
	{
		for (int j = t-1; j >= 0; --j)
		{
			int a = v[i].first;
			int b = v[i].second;
			dp[j + a] = max(dp[j + a], dp[j] + b);

			ans = max(ans, dp[j + a]);

		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
const ll nmax=8;
bool graph[nmax][nmax];
ll dfs(ll v,ll N,bool visited[nmax]){
   bool all_visited=true;
   for(ll i=0;i<N;++i){
     if(visited[i]==false)all_visited=false;
   }
   if(all_visited){
     return 1;
    }
ll ret=0;
for(ll i=0;i<N;++i){
  if(graph[v][i]==false) continue;
  if(visited[i]) continue;
  visited[i]=true;
  ret+=dfs(i,N,visited);
  visited[i]=false;
  }
  return ret;
} 
int main()
{
  ld X;
  cin>>X;
  ld A=100;
  ll ans=0;
  while(A<X){
    ans++;
    A=floor(A*101/100);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3748
#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <vector>
#include <set>
#include <cstring>
using namespace std;

typedef pair<pair<int,int>,pair<int,int> > pii;
#define REP(i,n) for(int i=0; i<n; ++i)

bool state[50][50][50][50];

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int main() {
    int w,h;
    while(cin>>w>>h, w|h) {
        vector<string> left(h),right(h);
        REP(i,h) cin>>left[i]>>right[i];

        int lx,ly,rx,ry;
        int glx,gly,grx,gry;
        REP(i,h) REP(j,w) {
            if(left[i][j] == 'L') lx = j, ly = i, left[i][j] = '.';
            if(left[i][j] == '%') glx = j, gly = i, left[i][j] = '.';
        }
        REP(i,h) REP(j,w) {
            if(right[i][j] == 'R') rx = j, ry = i, right[i][j] = '.';
            if(right[i][j] == '%') grx = j, gry = i, right[i][j] = '.';
        }

        memset(state, false, sizeof(state));
        queue<pii> Q;
        Q.push(make_pair(make_pair(lx,ly),make_pair(rx,ry)));
        while(!Q.empty()) {
            pii now = Q.front(); Q.pop();
            int lx = now.first.first, ly = now.first.second;
            int rx = now.second.first, ry = now.second.second;
            if(lx == glx && ly == gly
               && rx == grx && ry == gry) {
                goto SUCCESS;
            }
            if(lx == glx && ly == gly) continue;
            if(rx == grx && ry == gry) continue;
            if(state[lx][ly][rx][ry]) continue;
            state[lx][ly][rx][ry] = true;
            for(int i=0; i<4; ++i) {
                int nlx = lx + dx[i],nly = ly + dy[i];
                int nrx = rx + dx[(i+2)%4],nry = ry + dy[i];
                nlx = min(w-1, max(0, nlx));
                nrx = min(w-1, max(0, nrx));
                nly = min(h-1, max(0, nly));
                nry = min(h-1, max(0, nry));
                if(nlx < 0 || nlx >= w || nrx < 0 || nrx >= w) continue;
                if(nry < 0 || nry >= h || nly < 0 || nly >= h) continue;
                if(left[nly][nlx] == '#') {
                    nly = ly;
                    nlx = lx;
                }
                if(right[nry][nrx] == '#') {
                    nry = ry;
                    nrx = rx;
                }
                Q.push(make_pair(make_pair(nlx,nly),make_pair(nrx,nry)));
            }
        }

        goto BAD;
    SUCCESS:
        cout<<"Yes"<<endl;
        continue;
    BAD:
        cout<<"No"<<endl;
    }
}

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

int main() {
  
  int N=0;
  
  cin >> N;
  
  int div = N/3;
  
  if(0 < div) {
    
    cout << div << endl;
    
  } else {
    
    cout << "0" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func digit(x int64) int {
	if x == 0 {
		return 1
	}
	ret := 0
	for x > 0 {
		x /= 10
		ret++
	}
	return ret
}

func main() {
	var n int64
	fmt.Scan(&n)
	iMax := int64(math.Sqrt(float64(n)))
	max := int64(1)
	for i := int64(1); i <= iMax; i++ {
		if n%i == 0 {
			max = n / i
		}
	}
	fmt.Println(digit(max))
}


Measured memory_bytes: 512
abc = list(map(int,input().split()))
five_count = 0
seven_count = 0
for i in abc:
    if i == 5:
        five_count += 1
    elif i == 7:
        seven_count += 1
if five_count == 2 and seven_count == 1:
    print("YES")
else:
    print("NO")

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

using namespace std;

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

    cin >> a >> b >> c;

    if (a >= b && a >= c) {
        cout << a * 10 + b + c << endl;
    } else if (b >=a && b >= c) {
        cout << b * 10 + a + c << endl;
    } else {
        cout << c * 10 + a + b << endl;
    }


    return 0;
}


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

int main() {
    int n, a[1010][1010];
    cin >> n;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n-1; j++) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    queue<set<int>> q;
    set<int> q0;
    for (int i=0; i<n; i++) q0.insert(i);
    q.push(q0);
    int g = 0;
    int p[1010] = {0};
    int ans = 0;
    while(q.front().size() > 0 && g<n*(n-1)/2) {
        set<int> q1 = q.front(); q.pop();
        set<int> q2;
        for (auto itr=q1.begin(); itr!=q1.end(); itr++) {
            int x = *itr;
            int op_x = a[x][p[x]];
            if (p[x] == n || p[op_x] == n) continue;
            if (x == a[op_x][p[op_x]]) {
                q2.insert(x);
                q2.insert(op_x);
            }
        }
        int g1 = 0;
        for (auto itr=q2.begin();itr!=q2.end();itr++) {
            int x = *itr;
            p[x]++;
            g1++;
        }
        g+=g1/2;
        q.push(q2);
        ans++;
    }
    if (g==n*(n-1)/2) cout << ans << endl;
    else cout << "-1" << endl;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

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

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

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

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

typedef struct{ 
    int array[100]; 
}abc; 



int main() {

  string S;;
  cin>>S;
  ll K;
  cin>>K;
  vector <string> vec;

  if(S.size()==1){
        cout<<S<<endl;
        return 0;
  }

  FOR(i,0,S.size()-1){
    FOR(j,1,5){
      string tmp;
      if((i+j)<=S.size()){
        tmp=S.substr(i,j);
        //cout<<tmp<<endl;
        vec.push_back(tmp);
      }
    }
  }
  sort(vec.begin(),vec.end());

  ll kosuu=0;
  for(int i=0;i<vec.size()-1;i++){
        //cout<<vec[i]<<endl;
    if(vec[i]!=vec[i+1]){
      kosuu++;
      if(kosuu==K){
        cout<<vec[i]<<endl;
        return 0;
      }
    }
  }
  cout<<vec[vec.size()-1]<<endl;
  return 0;
}
 


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
string s;
int len;
bool chk(int a,int b)
{
	if(((s[a]=='d')&&(s[b]=='b'))||((s[a]=='b')&&(s[b]=='d'))||((s[a]=='p')&&(s[b]=='q'))||((s[a]=='q')&&(s[b]=='p')))
		return true;
	return false;
}
int main()
{
	cin>>s;
	len=s.length();
	if(len&1)
	{
		cout<<"No";
		return 0;
	}
	for(int i=0;i<(len/2);i++)
	{
		if(!chk(i,len-i-1))
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;

}

Measured memory_bytes: 512
from collections import defaultdict
def dfs(v, g, d, p=-1):
    r = v
    for u in g[v]:
        if p == u:
            continue
        d[u] = d[v] + 1
        t = dfs(u, g, d, v)
        if d[r] < d[t]:
            r = t
    return r
def main():
    n = int(raw_input())
    g = defaultdict(list)
    e = []
    for _ in xrange(n - 1):
        u, v = map(int, raw_input().split())
        u -= 1
        v -= 1
        g[u].append(v)
        g[v].append(u)
        e.append((u, v))
    for i in xrange(n):
        e.append((i, -1))
    ans = (n, 2 ** 64)
    for u, v in e:
        dc = [1] * n
        k = dfs(u, g, dc, v)
        l = dc[k]
        if v != -1:
            k = dfs(v, g, dc, u)
            if l < dc[k]:
                l = dc[k]
        ch = [0] * (l + 1)
        for i in xrange(n):
            if v == -1 and i == u:
                ch[dc[i]] = len(g[i])
            else:
                x = len(g[i]) - 1
                if ch[dc[i]] < x:
                    ch[dc[i]] = x
        p = 1 if v == -1 else 2
        for i in xrange(1, l):
            p *= ch[i]
        x = (l, p)
        if ans > x:
            ans = x
    print ans[0], ans[1]
main()


Measured memory_bytes: 2936
import itertools

N = int(input())
P_list = list(map(int, input().split()))
Q_list = list(map(int, input().split()))
sort_list = sorted(P_list)
factorial_list = list(itertools.permutations(sort_list))
a = 1 + factorial_list.index(tuple(P_list))
b = 1 + factorial_list.index(tuple(Q_list))
print(abs(a-b))


Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
string S,T;
int dp[1005][1005];
int solve(string a,string b){
  int A=a.size(),B=b.size();
  memset(dp,0,sizeof(dp));
  for(int i=0;i<A;i++){
    for(int j=0;j<B;j++){
      if(a[i]==b[j]){
        dp[i+1][j+1]=dp[i][j]+1;
      }else{
        dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
      }
    }
  }
  return dp[A][B];
}
  
int main(){
  cin>>S>>T;
  string sa="",sb="";
  for(int i=0;i<(int)S.size();i++){
    if(i%2==0)sa.push_back(S[i]);
    else sb.push_back(S[i]);
  }
  if( solve(sa,T) == (int)sa.size() )cout<<"Yes"<<endl;
  else if( solve(sb,T) == (int)sb.size() )cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

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

  int a=1;
  int b=1;
  int c=1;

  int ans=0;

  for(int i=1;i<=k;i++){
      for(int j=1;j<=k;j++){
          for(int l=1;l<=k;l++){
              ans += __gcd(__gcd(i,j),l);
          }
      }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
const int INF = 1e9;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  VVI es(n, VI(n, INF));
  for (int i = 0; i < m; i++) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;
    es[a][b] = es[b][a] = c;
  }
  VVI d = es;
  for (int i = 0; i < n; i++) {
    d[i][i] = 0;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (d[i][k] + d[k][j] < d[i][j]) {
          d[i][j] = d[i][k] + d[k][j];
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      bool used = false;
      for (int k = 0; k < n; k++) {
        if (abs(d[i][k] - d[k][j]) == es[i][j]) used = true;
      }
      if (not used) res++;
    }
  }
  cout << m - (n * n - res) / 2 << '\n';
}

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

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; }
const ll INF = 1LL << 60;

//---main---------------------------------------------
int main(){
    //main
    int N;
    cin >> N;

    vector<ll> A(N);
    ll x=0;
    rep(i,N) cin >> A[i];

    for(int i = 0; i<N; i+=2) x+=A[i];
    for(int i = 1; i<N; i+=2) x-=A[i];
    
    rep(i,N-1){
        cout << x << " ";
        x = 2*A[i] - x;
    }
    cout << x << endl;

    return 0;
}

Measured memory_bytes: 4040
//====================================================================
//Name       :
//Author     :hxf
//copyright  :http://www.cnblogs.com/Free-rein/
//Description:
//Data       :2012.8.11
//========================================================================
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
#define MAX 101000
#define inf 10100
using namespace std;
int prime[MAX];//雍ィ謨ー逧?焚扈?シ御サ?~MAX
bool visit[inf];//蛻、譁ュ隨ャi荳ェ謨ー譏ッ蜷ヲ荳コ雍ィ謨ー
int ans[MAX];
void get_prime()
{
    int temp=1;//莉」陦ィprime逧?ク区??悟?temp-1荳ェ謨ー
    for(int i=2;i<=inf;i++)
        visit[i]=true;
    for(int i=2;i*i<=inf;i++)
    {
        if(visit[i]==1)
        {
            for(int j=i;i*j<=inf;j++)
                visit[i*j]=false;
        }
    }
    for(int i=2;i<=inf;i++)
        if(visit[i]==true)
        {
            prime[temp++]=i;
        }
}
////////////////////////////////////////
void get_ans()
{
    for(int i=1;prime[i]<=10050;i++)
    {
        int kkk=0;
        for(int j=i;kkk<=10050;j++)
        {
            kkk=kkk+prime[j];
            ans[kkk]++;
        }
    }
}
int main()
{
    get_prime();
   // for(int i=0;i<50;i++)
      //  printf("%d\n",prime[i]);
    memset(ans,0,sizeof(ans));
    get_ans();
    while(1)
    {
        int n;
        scanf("%d",&n);
        if(n==0)
            break;
        printf("%d\n",ans[n]);
    }
    return 0;
}

Measured memory_bytes: 1604
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(x) for(auto it=(x).begin();it!=(x).end();it++) 
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
 
using namespace std;

int main(){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    
    int z=x*a+y*b;
    int p=min(x,y)*2*c+(x-min(x,y))*a+(y-min(x,y))*b;
    int q=max(x,y)*2*c;
    cout<<min(z,min(q,p))<<endl;
    
    
    
    return 0;
}

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

using namespace std;

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    A *= 100;
    B *= 100;

    int max_water = 0;
    int max_sugar = 0;
    for (int a = 0; a * A <= F; a++) {
        for (int b = 0; a * A + b * B <= F; b++) {
            int current_water = a * A + b * B;
            for (int c = 0; c * C <= F; c++) {
                for (int d = 0; c * C + d * D <= F; d++) {
                    int current_sugar = c * C + d * D;
                    int current = current_water + current_sugar;
                    if (current == 0) {
                        continue;
                    } else if (current > F || current_sugar > current_water * E / 100) {
                        break;
                    }

                    if (max_water == 0 || (double) current_sugar / (double) current >
                                          (double) max_sugar / (double) (max_water + max_sugar)) {
                        max_water = current_water;
                        max_sugar = current_sugar;
                    }
                }
            }
        }
    }

    printf("%d %d\n", max_water + max_sugar, max_sugar);
    return 0;
}


Measured memory_bytes: 256
// keyence2020_a
#include <iostream>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>

#define US unsigned short
#define UI unsigned int
#define UC unsigned char
#define UL unsigned long
#define ULL unsigned long long
using namespace std;

int main(int argc, char const *argv[])
{
    UI h, w, n;
    cin >> h >> w >> n;
    UI m = max(h, w);
    cout << ceil(float(n) / m) << endl;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MOD 1000000007
#define INF 100100100

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

long long comb(int n, int r) {
  if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
  long long ans = 1;

  for(int i = 1; i <= r; i++) {
    ans *= n - r + i;
    ans /= i;
  }

  return ans;
}

int main(){
  int n, p;
  cin >> n >> p;
  vector<ll> v(n);
  int kisu = 0;
  int gusu = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if(v[i] % 2 == 1) kisu++;
    else gusu++;
  }

  ll res = 0;
  ll tmp = pow(2, gusu);

  if(p == 0){
    for (int i = 0; i <= kisu; i+=2) {
      res += tmp * comb(kisu, i);
    }
  }else{
    for (int i = 1; i <= kisu; i+=2) {
      res += tmp * comb(kisu, i);
    }
  }

  cout << res << endl;



}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s1 = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();
		
		String s = String.valueOf(s1.toUpperCase().charAt(0)) + String.valueOf(s2.toUpperCase().charAt(0)) + String.valueOf(s3.toUpperCase().charAt(0));
		
		System.out.println(s);

	}

}

Measured memory_bytes: 22736
s = input()
n = len(s) 

rs = [1]*n
for i in range(1,n):
  rs[i] = rs[i-1]*10 %2019
  
ls = [0]*2019
ls[0]+=1

r = 0
for i in range(n-1,-1,-1):
  r += int(s[i]) * (rs[n-i-1])
  r %= 2019
  ls[r] += 1

ans = 0
for a in ls:
  ans += a*(a-1)//2
print(ans)
       

Measured memory_bytes: 16256
from functools import reduce

N=int(input())
A=list(map(int, input().split()))

def gcd(a, b):
    if a < b:
        a,b = b,a
    if b == 0:
        return a
    return gcd(b, a % b)

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

l = reduce(lcm, A)

ans = 0
for a in A:
    ans += (l - 1) % a

print(ans)


Measured memory_bytes: 50544
import sys, re
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
from bisect import bisect
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

for i in range(int(N**(1/2))+1, 0, -1):
	if N%i == 0:
		a = i
		b = N//i
		break
print(max(len(str(a)), len(str(b))))


Measured memory_bytes: 5440
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int dp[10001] = { 0 };
    int n, W;
    int v[100], w[100];
    cin >> n >> W;
    for (int i = 0; i < n; i++){
        cin >> v[i] >> w[i];
    }
    for (int i = 0; i < n; i++){
        for (int i2 = W-w[i]; i2 >= 0; i2--){
            dp[i2 + w[i]] = max(dp[i2 + w[i]], dp[i2] + v[i]);
        }
    }
    cout << dp[W] << endl;
}

Measured memory_bytes: 1208