akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cassert>


using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template <class T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	for (const auto& e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, K;
	cin >> N >> K;

	vector<Int> a(N);
	for (Int i = 0; i < N; i++) {
		cin >> a[i];
	}

	vector<pair<mint, mint>> count(N, pair<mint, mint>());

	mint before;
	mint after;
	for (Int i = 0; i < N; i++) {
		before = 0;
		after = 0;
		for (Int j = 0; j < N; j++) {
			if (i == j) continue;
			if ((j < i) && (a[i] > a[j]))before+=1;
			if ((j > i) && (a[i] > a[j]))after+=1;
		}
		count[i].first = before;
		count[i].second = after;
	}

	mint ans = 0;
	for (Int i = 0; i < N; i++) {
		ans += count[i].second * K + (count[i].second + count[i].first) * K * (K - 1) / 2;
	}

	cout << ans << endl;
}

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

int main() {
	int n;
	int a[5];
	int ans = 0;
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		ans += a[i];
	}
	int ra[5];
	int max = 0;
	for (int i = 0; i < 5; i++) {
		ra[i] = 10 - (a[i] % 10);
		if (ra[i] == 10)ra[i] = 0;
		ans += ra[i];
		if (ra[i] > max) max = ra[i];
	}
	ans = ans - max;
	cout << ans << endl;

	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;

int main(){
    int n, m; cin >> n >> m;
    vector<vector<int>> s(m);
    rep(i, m){
        int k; cin >> k;
        rep(j, k){
            int a; cin >> a; a--;
            s[i].push_back(a);
        }
    }
    vector<int> p(m);
    rep(i, m) cin >> p[i];
    ll res = 0;
    for(int bit = 0; bit < (1 << n); bit++){
        bool ok = true;
        rep(i, m){
            int con = 0;
            for(auto v : s[i]){
                if(bit & (1 << v)) con++;
            }
            if(con % 2 != p[i]) ok = false;
        }
        if(ok) res++;
    }
    cout << res << endl;
    return 0;
}



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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int h, w;
    cin >> h >> w;
    char f[51][51] = {};
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            cin >> f[i][j];
        }
    }
    bool check = true;
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            if (f[i][j] == '.') continue;
            bool flg = false;
            Int dx[] = {1, 0, -1, 0};
            Int dy[] = {0, -1, 0, 1};
            for (Int k = 0; k < 4; k++) {
                Int ny = i + dy[k];
                Int nx = j + dx[k];
                if (ny < 0 or ny == h or nx < 0 or nx == w) continue;
                if (f[ny][nx] == '#') {
                    flg = true;
                }
            }
            check = check and flg;
        }
    }
    dump(check ? "Yes" : "No");
    return 0;
}


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

void boost1() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    int n,modd=1000000007,i;
    cin>>n;
    int dp[2001]={0};
    vector<int>nums;
    for(i=3;i<=n;i++)
        nums.push_back(i);
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int x : nums) {
            if (i >= x)
                dp[i] = (dp[i] + dp[i - x])%modd;
        }
    }
    cout<<dp[n]<<endl;
    // return dp[target];
}

Measured memory_bytes: 3608
/**
 * Created by hiramekun at 13:48 on 2020-05-17.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    string s;
    ll k;
    cin >> s >> k;
    ll n = s.size();

    ll dp[n + 1][k + 1][2];
    rep(i, n + 1)rep(j, k + 1)rep(l, 2)dp[i][j][l] = 0;
    dp[0][0][0] = 1;

    rep(i, n) {
        rep(j, k + 1) {
            rep(l, 2) {
                rep(d, 10) {
                    ll now = s[i] - '0', nj = j, nl = l;
                    if (d != 0) nj++;
                    if (nj > k) continue;
                    if (nl == 0) {
                        if (d > now) continue;
                        if (d < now) nl = 1;
                    }
                    dp[i + 1][nj][nl] += dp[i][j][l];
                }
            }
        }
    }
    cout << dp[n][k][0] + dp[n][k][1] << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,a[55],P;
ll f[55][2];
int main()
{
	n=read();P=read();f[0][0]=1;
	for(int i=1;i<=n;++i)
	{
		int x=read()&1;
		f[i][0]=f[i-1][0];f[i][1]=f[i-1][1];
		f[i][0^x]+=f[i-1][0];f[i][1^x]+=f[i-1][1];
	}
	printf("%lld\n",f[n][P]);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int sx,sy,tx,ty,i;
    cin>>sx>>sy>>tx>>ty;
    int l=tx-sx,b=ty-sy;
    for (i=0;i<b;i++)
        cout<<"U";
    for (i=0;i<l;i++)
        cout<<"R";
    for (i=0;i<b;i++)
        cout<<"D";
    for (i=0;i<l;i++)
        cout<<"L";
    cout<<"L";
    for (i=0;i<=b;i++)
        cout<<"U";
    for (i=0;i<=l;i++)
        cout<<"R";
    cout<<"DR";
    for (i=0;i<=b;i++)
        cout<<"D";
    for (i=0;i<=l;i++)
        cout<<"L";
    cout<<"U";
}


Measured memory_bytes: 256
#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define int long long

constexpr ll LINF = (1LL << 62);

signed main(void){
	int N; cin >> N;
	vector<int> A(N + 1);
	for (int i = 0; i <= N; ++i)
		cin >> A[i];
	
	if (N == 0){
		if (A[0] == 1)
			cout << 1 << endl;
		else
			cout << -1 << endl;
		return 0;
	}

	if (A[0] != 0){
		cout << -1 << endl;
		return 0;
	}

	vector<int> ls(N + 1), rs(N + 1);

	int l, r; l = r = 1;
	ls[0] = rs[0] = 1;
	for (int i = 1; i <= N; ++i){
		int l_nx = l - A[i - 1];
		l_nx = max({1LL, A[i], l_nx});
		int r_nx;
		if ((r - A[i - 1]) >= LINF / 2) r_nx = LINF;
		else r_nx = (r - A[i - 1]) * 2;
		l = l_nx, r = r_nx;
		if (r_nx < l_nx){
			cout << -1 << endl;
			return 0;
		}
		ls[i] = l, rs[i] = r;
	}

	if (ls[N] > A[N] || rs[N] < A[N]){
		cout << -1 << endl;
		return 0;
	}

	int c = A[N];
	ll res = A[N];

	for (int i = N - 1; i >= 0; --i){
		l = (c + 1) / 2 + A[i];
		l = max({1LL, A[i], l});
		r = c + A[i];
		c = min(rs[i], r);
		if (!(l <= c && c <= r)){
			cout << -1 << endl;
			return 0;
		}
		if (!(ls[i] <= c && c <= rs[i])){
			cout << -1 << endl;
			return 0;
		}
		res += c;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 5636
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	res := "Yes"
	odd := true
	for _, r := range s {
		if (r == 'R' && !odd) || (r == 'L' && odd) {
			res = "No"
			break
		}
		if odd {
			odd = false
		} else {
			odd = true
		}
	}

	fmt.Println(res)
}


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

int main(void)

{
	double r;
	double menseki;
	double syuu;
	
	scanf("%lf",&r);
	
	menseki=r*r*3.1415926535897932;
	syuu=r*2*3.1415926535897932;
	
	printf("%lf %lf\n", menseki, syuu);
	
	return (0);
}

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

using namespace std;

int main() {
    set<int> st;

    int q;
    cin >> q;
    while (q--) {
        int op, x;
        cin >> op >> x;

        switch (op) {
            case 0:
                st.insert(x);
                cout << st.size() << endl;
                break;
            case 1:
                cout << st.count(x) << endl;
                break;
            case 2:
                st.erase(x);
                break;
            case 3:
                int r;
                cin >> r;
                for (auto itr = st.lower_bound(x); itr != st.end() and *itr <= r; ++itr) {
                    cout << *itr << endl;
                }
                break;
        }
    }
    return 0;
}


Measured memory_bytes: 12448
#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 k, s;
    cin >> k >> s;
    int res = 0;
    for (int x = 0; x <= k; x++)
        for (int y = 0; y <= k; y++)
        {
            int z = s - x - y;
            if (z >= 0 && z <= k)
                res++;
        }
    cout << res << endl;
    return 0;
}

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

int main() {
  int N, A;
  
  cin >> N >> A;
  
  if(N%500 == 0) cout << "Yes" << endl;
  else if((N%500) <= A) cout << "Yes" << endl;
  else cout << "No" << endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}

class UnionFind {
  public:
    // 親の番号を格納する。親の場合 -1 になる
    vector<int> Parent;

    // 宣言されたとき Parent の値はすべて -1 にする
    UnionFind(int N) { Parent = vector<int>(N, -1); }

    // 与えられた値 x がどの親であるか調べる
    int root(int x) {
        if (Parent[x] < 0)
            return x;
        return Parent[x] = root(Parent[x]);
    }

    // 木の全体の数を返す
    int size(int x) { return -Parent[root(x)]; }

    // 2つの引数を同じ親にする
    bool update(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (size(x) < size(y))
            swap(x, y);
        Parent[x] += Parent[y];
        Parent[y] = x;
        return true;
    }

    // 引数の親が同じか判定する
    bool is_same(int x, int y) { return root(x) == root(y); }
};

// 最小全域木
class Kruskal {
  private:
    struct Edge {
        int u, v, cost;
    };
    int vertex_max, edge_max;
    long long cost_sum = 0;
    vector<Edge> edge;

  public:
    Kruskal(int edge_in, int vertex_in) {
        edge_max   = edge_in;
        vertex_max = vertex_in;
    }
    // 辺を追加する
    void update(int u, int v, int c) { edge.push_back({u, v, c}); }
    // 最小全域木を求める。そのときの最小コストを返す。
    long long cal() {
        sort(edge.begin(), edge.end(),
             [](const Edge e1, const Edge e2) { return e1.cost < e2.cost; });
        auto uni = UnionFind(vertex_max);
        for (int i = 0; i < edge_max; i++) {
            auto e = edge[i];
            if (!uni.is_same(e.u, e.v)) {
                uni.update(e.u, e.v);
                cost_sum += (long long)e.cost;
            }
        }
        return cost_sum;
    };
};

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

    int N, M;
    while (true) {
        cin >> N;
        if (N == 0)
            break;
        cin >> M;
        auto kr = Kruskal(M, N);
        REP(i, M) {
            int a, b, d;
            char c;
            cin >> a >> c >> b >> c >> d;
            d -= 100;
            kr.update(a, b, d);
        }
        auto sum = kr.cal();
        std::cout << sum / 100 << '\n';
    }

    return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 199;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    ll n;
    cin >> n;
    ll l[n+1];
    rep1(i,n){
        cin >> l[i];
    }
    ll cnt = 0;
    for(int i = 1;i <= n; i++){
        for(int j = i+1;j <= n; j++){
            for(int k = j+1;k <= n; k++){
                ll a = l[i];
                ll b = l[j];
                ll c = l[k];
                if(a == b || b == c || c == a) continue;
                if(a + b > c && b + c > a && c + a > b) cnt++;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}

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

int main() {
  int N, m; cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  sort(A.begin(), A.end());
  cout << A[N-1]-A[0] << endl;
}

Measured memory_bytes: 256
import sys
import collections

readline = sys.stdin.readline

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n
        self.rank = [0]*n
        self.size = [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.rank[x] < self.rank[y]:
            self.size[y] += self.size[x]
            self.parents[x] = y
        else:
            self.size[x] += self.size[y]
            self.parents[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def msize(self, x):
        return -self.size[self.find(x)]

def main():
    N, M = map(int, readline().split())
    nodelist = []
    for _ in range(M):
        A, B = map(int, readline().split())
        A -= 1; B -= 1
        nodelist.append((A, B))
    
    uf = UnionFind(N)
    anstmp = (N*(N-1))//2
    anslist = [anstmp]
    for _ in range(M):
        node = nodelist.pop()
        n0 = uf.find(node[0])
        n1 = uf.find(node[1])
        if n0 != n1:
            n0size = uf.size[n0]
            n1size = uf.size[n1]
        else:
            n0size = 0; n1size = 0
        uf.union(node[0], node[1])
        anstmp = anslist[-1]
        ans = anstmp - n0size*n1size
        anslist.append(ans)
    anslist = anslist[:-1]
    for _ in range(len(anslist)):
        ans = anslist.pop()
        print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 20108
n,k = map(int,input().split())
mod = 10**9+7
print(((-(2*(n+1)**3+3*(n+1)**2+n+1)//6)+(n*(n+1)**2+n*(n+1))//2+((n+1)**2+n+1)//2-((k-1)*n+(k-1)**2*n)//2+n+(k+2*(k-1)**3+3*(k-1)**2-1)//6-(k+(k-1)**2-1)//2-k+2) % mod)


Measured memory_bytes: 61792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>

using namespace std;

using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const int inf = 1e+9;



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

	vector<pair< int, int> > red, blue;

	rep(i, n) {
		int a, b;
		cin >> a >> b;
		red.push_back(mkp(a, b));
	}

	rep(i, n) {
		int c, d;
		cin >> c >> d;
		blue.push_back(mkp(c, d));
	}

	sort(red.begin(), red.end());
	sort(blue.begin(), blue.end());

	int cur_red = 0;


	vector <int> red_y;
	int ans = 0;
	for(int cur_blue = 0; cur_blue < blue.size(); cur_blue++) {
		pair<int, int> cur_b = blue[cur_blue];
		int b_x = cur_b.first;
		int b_y = cur_b.second;

		while(cur_red < n && red[cur_red].first < b_x) {
			red_y.push_back(red[cur_red].second);
			cur_red++;
		}

		int max_y = -1;
		int max_i = -1;
		for(int i = 0; i < red_y.size(); i++) {
			if (red_y[i] < b_y) {
				if (red_y[i] > max_y) {
					max_i = i;
					max_y = red_y[i];
				}
			}
		}

		if (max_y == -1) continue;

		red_y.erase(red_y.begin() + max_i);
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};

void score(int D,vector<int> c,vector<vector<int>> s,vector<int> t){
    vector<int> last(26,0);  
    int ans = 0;
    rep(i,D){
        last[t[i]-1] = i+1;
        ans += s[i][t[i]-1];
        int tmp =  0;
        rep(j,26){
            tmp += c[j] * (i+1-last[j]);
        }
        ans -= tmp;
        cout << ans << endl;   
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int D;
    cin >> D;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(D,vector<int> (26,0));
    vector<int> smax(D,0);
    vector<int> tt(D);
    rep(i,D){
        rep(j,26){
            cin >> s[i][j];
            int old = smax[i];
            smax[i] = max(smax[i],s[i][j]);
            if(old != smax[i]){
                tt[i] = j+1;
            }
        }
    }
    vector<int> t(D);
    vector<int> mis(26,0);
    int mismax = 0;
    int misi = 0;
    mis = c;
    int sum = 0;
    rep(j,26){
        int t = mismax;
        mismax = max(mismax,mis[j]);
        if(t != mismax){
            misi = j;
        }
    }
    rep(i,D) {
        sum = 0;
        rep(j,26){
            sum += mis[j];
        }
        if(smax[i] > sum){
            t[i] = tt[i];
            mis[tt[i]-1] = 0;
        }else{
            t[i] = misi+1;
            mis[misi] = 0;
        }
        rep(j,26){
            int t = mismax;
            mis[j] += c[j];
            mismax = max(mismax,mis[j]);
            if(t != mismax){
                misi = j;
            }
        }
    }    
    rep(i,D){
        cout << t[i] << endl;
    }
    
    
    cout << endl;
    return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int main () {
	int n,ans=0;
	cin>>n;
	int a[n],b,c[n];
	for (int i=0;i<n;i++) {
		cin>>a[i];
	}
	for (int i=0;i<n;i++) {
		cin>>b;
		ans+=b;
	}
	for (int i=0;i<n-1;i++) {
		cin>>c[i];
	}
	for (int i=0;i<n-1;i++) {
		if (a[i]+1==a[i+1]) {
			ans+=c[a[i]-1];
		}
	}
	cout<<ans;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <memory.h>
#include <math.h>

#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
#define SWAP(t, a, b) do{t c = a; a = b; b = c;}while(0)

int main (int argc, char **argv)
{
  int64_t a = 0;
  int64_t b = 0;
  int64_t c = 0;

  scanf("%lld %lld %lld", &a, &b ,&c);

  printf("%lld\n", MIN(b / a, c));

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;
using ll = long long;

int a,b,c,x,y;
ll num[4];

int main(){
  cin >> a >> b >> c >> x >> y;
  ll ans = a * x + b * y;
  num[0] = x;
  num[1] = y;
  num[2] = 0;
  if(a + b > 2*c){
    int s = min(num[0], num[1]);
    num[0] -= s;
    num[1] -= s;
    num[2] += s * 2;
    //cout << num[0] << endl;
    ans = num[0] * a + num[1] * b + num[2] * c;
  }
  if(a > 2 * c){
    int k = num[0];
    num[0] = 0;
    num[2] += 2 * k;
    ans = num[0] * a + num[1] * b + num[2] * c;
  }
  if(b > 2 * c){
    int k = num[1];
    num[1] = 0;
    num[2] += 2 * k;
    ans = num[0] * a + num[1] * b + num[2] * c;
  }
  cout << ans << endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;


int main()
{
	long N, M, num;

	cin >> N >> M;

	if (N == 1&&M == 1) {
		num = 1;
	}
	else if (N == 1) {
		num = M - 2;
	}
	else if (M == 1) {
		num = N - 2;
	}
	else{
		num = (N-2) * (M-2);
	}

	cout << num << endl;
	
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    char a[1201];
    int i=0,j=0;
    
    while(1){
        scanf("%c",&a[i]);
        
        if('a'<=a[i] && a[i]<='z'){
            a[i]=a[i]-32;
        }else if('A'<=a[i] && a[i]<='Z'){
            a[i]=a[i]+32;
        }
        
        if ( a[i] == '\n' ) break;
        
        i++;
    }
    
    for(;j<i;j++){
        printf("%c",a[j]);
    }
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int a,b,c;
	cin>>a>>b>>c;
	int t;
	t=a;
	a=b;
	b=t;
	t=a;
	a=c;
	c=t;
	cout<<a<<" "<<b<<" "<<c<<endl;
	 
	return 0;
 }

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
char s[101010];
int a[101010];
int main()
{
	int l,k;
	scanf("%s",s);
	l=strlen(s);
	scanf("%d",&k);
	for(int i=0;i<l;i++)
		a[i]=s[i]-'a';
	for(int i=0;i<l;i++)
		if(k>=(26-a[i])%26)
		{
			k-=(26-a[i])%26;
			a[i]=0;
		}
	(a[l-1]+=k)%=26;
	for(int i=0;i<l;i++)
		printf("%c",'a'+a[i]);
	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>

int main(){
	
	int n,i,m,z;
	
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		
		z=0;
		
		for(i=0;i<n/4;i++){
			scanf("%d",&m);
			z+=m;
		}
		
		printf("%d\n",z);
	}
	
return 0;
}

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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  ld sol = sqrt(a * a + b * b - 2 * a * b * cos(acos(0.0) / 90.0 * min(fabs((h + m / (ld) 60) * 30 - m * 6), 360 - fabs((h + m / (ld) 60) * 30 - m * 6))));
  cout << fixed << setprecision(9) << sol << "\n";
  return 0;
}


Measured memory_bytes: 4116
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll A,V,B,W,T;
  cin>>A>>V>>B>>W>>T;
  ll D=abs(A-B);
  ll D2=(V-W)*T;
  puts(D<=D2?"YES":"NO");
}

Measured memory_bytes: 3532
# https://atcoder.jp/contests/abc065/tasks/abc065_b
require 'set'

n = gets.to_i
nums = []
visited = Set.new
n.times { nums << gets.to_i }
current = 0
res = 0

while ! visited.include?(current)
  break if current == 1
  visited.add(current)
  current = nums[current] - 1
  res += 1
end

puts current == 1 ? res : -1

Measured memory_bytes: 9464
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    ll N;
    input(N);

    vector<ll> p(N, 0);
    input(p);

    ll m = p[0];

    ll res = 0;
    rep(i, 0, N)
    {
        if (m >= p[i])
        {
            res++;
            m = min(m, p[i]);
        }
    }

    cout << res << endl;
    return 0;
}

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

#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 1e9

int main() {
    long long N;
    cin >> N;

    vector<pair<long long, long long>> p;

    for (long long i=2; i*i<=N; i++){
        if(N%i != 0)continue;

        long long e = 0;

        while (N%i == 0){
            e++;
            N /= i;
        }
        p.push_back({i, e});
    }
    if (N!=1){
        p.push_back({N,1});
    }

    int count = 0;
    for (long long j=0; j<p.size(); j++){
        int ex = p[j].second;
        int counter = 1;
        while (ex >= counter){
            ex -= counter;
            count ++;
            counter ++;

        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
struct k
{
    int b,e;
} num[100001];
bool cmp(struct k a,struct k b)
{
    return a.e<b.e;
}
int main()
{
    int n,cnt=0,t=0;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%d%d",&num[i].b,&num[i].e);
    sort(num,num+n,cmp);
    for(int i=0; i<n; i++)
        if(t<num[i].b)
        {
            t=num[i].e;
            cnt++;
        }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 4012
#include<stdio.h>
#include<math.h>
double d,r,s,z[6];
int n,i,j,a[50];
int main(){
	for(scanf("%d",&n);n--;){
		for(i=0;i<6;i++)
			scanf("%lf",z+i);
		r=z[2];
		s=z[5];
		d=hypot(*z-z[3],z[1]-z[4]);
		printf("%d\n",a[j++]=d>r+s?0:r>d+s?2:s>d+r?-2:1);
	}
	return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int K, N; cin >> K >> N;
    int sz = N*2;
    ll A[sz];
    ll ans = 1000000000000000ll;
    rep(i, N) cin >> A[i];
    rep(i, N) A[i+N] = A[i]+K;
    for(int i = 0; i < sz; i++){
        if(i+(N-1) < sz) ans = min(ans, A[i+(N-1)]-A[i]);
    }
    cout << ans << endl;
    return 0;
}

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

int findIndex(int value, vector<auto> array) {
    auto iter = find(array.begin(), array.end(), value);
    size_t index = distance(array.begin(), iter);
    if (index == array.size()) {
      return -1;
    }
    return index;
}

int func_int_div_ceil(int dividend, int divisor) {
  return (dividend + (divisor - 1)) / divisor;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i=0; i<N; ++i) { 
    cin >> A.at(i);
  }
  int index = findIndex(1, A);
  int num_lower = func_int_div_ceil(index, K-1);
  int num_upper = func_int_div_ceil(N - 1 - (K-1) * num_lower, K-1);
  int ans = num_lower + num_upper;
  cout << ans << endl;
  return 0;
}





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

using namespace std;


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int counter = 0, cur = a[0];
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] == cur) {
            counter++;
        } else {
            if(counter % 2 == 0) {
                ans += counter / 2;
            } else {
                ans += (counter - 1) / 2;
            }
            cur = a[i];
            counter = 1;
        }
    }
    if(counter % 2 == 0) {
        ans += counter / 2;
    } else {
        ans += (counter - 1) / 2;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        while (true) {
            int H = scan.nextInt(), W = scan.nextInt();
            if (H == 0 && W == 0) {
                break;
            }

            for (int h = 0; h < H; h++) {
                for (int w = 0; w < W; w++) {
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();

        }
    }
}

Measured memory_bytes: 37160
#include <iostream>

using namespace std;

int main()
{
    int x=0;
string s;
cin>>s;
char arr1[s.size()/2];
char arr2[s.size()/2];
for(int i=0;i<s.size()/2;i++)
{
    arr1[i]=s[i];
    arr2[i]=s[((s.size())-i)-1];

}
for(int i=0;i<s.size()/2;i++)
{
    if(arr1[i]!=arr2[i]) x++;
}
cout<<x;
return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
VVI wy;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n,a;
  cin>>n>>a;
  wy.resize(n+1,VI(50*n+1));
  wy[0][0]=1;
  in x;
  forn(z,n){
    cin>>x;
    for(in p=n-1;p>=0;--p){
      forn(i,50*(n-1)+1)
	wy[p+1][i+x]+=wy[p][i];
    }
  }
  in sm=0;
  for(in i=1;i<=n;++i)
    sm+=wy[i][a*i];
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> list(n);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            v--;
            list[u].push_back(v);
        }
    }
    vector<int> d(n, -1);
    queue<int> q;
    q.push(0);
    d[0] = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int v : list[u]) {
            if (d[v] == -1) {
                q.push(v);
                d[v] = d[u] + 1;
            }
        }
    }
    for (int i = 0; i < n; i++) {;
        cout << (i + 1) << " " << d[i] << endl;
    }
    return 0;
}




Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

//priority que pair
using llpair = pair<ll,ll>;
bool operator>(const llpair a,const llpair b){return a.second > b.second;};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N, M;
    cin >> N >> M;
    //vector<priority_queue<llpair,vector<llpair>,greater<llpair>>> city(N);
    // mapだと間に合わない
    //vector<map<ll, ll>> city(N);
    vector<vector<ll>> city(N);
    ll P[M], Y[M];
    //std::distance(std::begin(myMap), myMap.find("myKey"))
    for(size_t i=0;i<M; i++)
    {
        cin >> P[i] >> Y[i];
        city[P[i]-1].push_back(Y[i]);
    }
    for(size_t i=0;i<N; i++)
    {
        cerr << city[i].size() << endl;
        sort(city[i].begin(), city[i].end());
    }
    /*
    for(size_t i=0;i<N; i++)
    {
        for(const auto& m:city[i])
        {
            //cerr << i << ":" << m.first << ":" << m.second << endl;
            cerr << i << ":" << m << endl;
        }
    }
    */
    for(size_t i=0;i<M; i++)
    {
        cout << setw(6) << setfill('0') << P[i];
        cout << setw(6) << setfill('0') << distance(city[P[i]-1].begin(), lower_bound(city[P[i]-1].begin(), city[P[i]-1].end(), Y[i])) + 1 << endl;
    }
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MAX max<ll>
#define MIN min<ll>
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
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 (b<a) { a=b; return 1; } return 0; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

double dis(double x1, double y1, double x2, double y2){
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

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

    ll N;
    cin >> N;
    vector<double> X(N), Y(N);
    rep(i, N) cin >> X[i] >> Y[i];

    vec A(N);
    iota(ALL(A), 0);

    double ans = 0;
    perm(A){
        double px = X[A[0]], py = Y[A[0]];
        double tp = 0;
        for (ll i = 1; i < N; ++i){
            tp += dis(px, py, X[A[i]], Y[A[i]]);
            px = X[A[i]], py = Y[A[i]];
        }
        ans += tp;
    }
    rep1(i, N) ans /= i;

    print(ans);

    return 0;
}

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


signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;

	int n ; 
	cin >> n; 
	int ans = n-1 ;
	for(int i = 2; i <= n ; ++i)
	{
		ans += n/i ; 
		if(n%i == 0 )
		 	ans-- ; 

	}
	cout << ans ;
}


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

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

    map<int,int> cnt;
    string s;
    for(int i=0;i<n;++i)
    {
        int k;
        cin >> k;
        for(int j = 0;j < k; ++j)
        {
            int x;
            cin >> x;
            cnt[x]++;
        }
    }    

    int ans = 0;
    for(auto x:cnt)
    {
        if(x.second >= n)
        {
            ans++; 
        }
    }
    cout << ans;
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    int n;
    cin >> n;
    vector<ll> b(n);
    vector<ll> a(n);
    ll inp;
    int mae=0;
    int usiro = n-1;
    REP(i,n){
        cin >> a[i];
    }

    for(int i=n-1; i >= 0; i--){
        if(i%2)
            b[usiro--] = a[i];
        else
            b[mae++] = a[i]; 
    }

    if(n % 2){
        for(int i=0; i < n; i++)
            printf("%lld ", b[i]);
    }
    else{
        for(int i=n-1; i >= 0; i--)
            printf("%lld ", b[i]);

    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 5248
import java.util.*;
 
public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        List<List<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < N-1; i++) {
            int a = sc.nextInt(); a--;
            int b = sc.nextInt(); b--;
            graph.get(a).add(b);
            graph.get(b).add(a);
        }

        long ans = K*dfs(K, graph, 0, -1);
        ans %= MOD;

        System.out.println(ans);
    }

    static long dfs(int K, List<List<Integer>> graph, int now, int from) {

        int colorNum = from == -1 ? K-1 : K-2;

        long ret = 1;
        for (int next : graph.get(now)) {
            if (next != from) {
                ret *= colorNum;
                ret %= MOD;
                colorNum--;

                ret *= dfs(K, graph, next, now);
                ret %= MOD;
            }
        }

        return ret;
    }
}


Measured memory_bytes: 115948
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,n=INTM()
    ct=0
    c=min(a,b)
    for i in range(c,0,-1):
        if a%i==0 and b%i==0:
            ct+=1
            if ct==n:
                ans=i
    print(ans)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
N,M=[int(s) for s in input().split()]
if N%2==1:
  a=1
  b=N-1
  for i in range(M):
    print(*[a,b])
    a+=1
    b-=1
else:
  x=(N+2)//4
  a=1
  b=N-1
  for i in range(min([M,x-1])):
    print(*[a,b])
    a+=1
    b-=1
  a+=1
  for i in range(min([M-x+1,N//2-x])):
    print(*[a,b])
    a+=1
    b-=1

Measured memory_bytes: 9268
#include <bits/stdc++.h>
#define FOR(i, l, r) for (int i = l; i <= r; ++i)
#define ROF(i, l, r) for (int i = l; i >= r; --i)
#define ll long long
using namespace std;

long double r, d, pi;

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

    pi = 3.141592654;
    cin >>r;
    cout <<setprecision(10) << fixed <<2 * r * pi;

}


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

int main() {
  int N, K;
  cin >> N >> K;
  int i = 0;
  int x;
  int sum = 0;
  while(i < N) {
    cin >> x;
    if(x > (K - x)) {
      sum += ((K - x) * 2);
    }
    
    else {
      sum += (x * 2);
    }
    
    i++;
  }
  
  cout << sum << endl;
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 998244353

N, S = MAP()
A = LIST()

# dp0[i][j] := j番目の要素まで見て、総和がjで、使う区間が未確定の状態の通り数
dp0 = list2d(N+1, S+1, 0)
# dp1[i][j] := j番目の要素まで見て、総和がjで、使う区間がL確定済の状態の通り数
dp1 = list2d(N+1, S+1, 0)
# dp2[i][j] := j番目の要素まで見て、総和がjで、使う区間がLR確定済の状態の通り数
dp2 = list2d(N+1, S+1, 0)
dp0[0][0] = 1
for i, a in enumerate(A):
    for j in range(S+1):
        # aを総和に足さない遷移は全部OK
        dp0[i+1][j] += dp0[i][j]
        dp1[i+1][j] += dp0[i][j] + dp1[i][j]
        dp2[i+1][j] += dp0[i][j] + dp1[i][j] + dp2[i][j]
        # aを総和に足す遷移は、遷移元が状態2と遷移先が状態0は無理
        if j+a <= S:
            dp1[i+1][j+a] += dp0[i][j] + dp1[i][j]
            dp2[i+1][j+a] += dp0[i][j] + dp1[i][j]
        dp0[i+1][j] %= MOD
        dp1[i+1][j] %= MOD
        dp2[i+1][j] %= MOD
ans = dp2[N][S]
print(ans)


Measured memory_bytes: 246920
#include<iostream>
int main() {
	int n;
	std::cin>>n;
	int h[n];
	for (int i = 0; i < n; i++)
		std::cin>>h[i];
	int max_count = 0;
	int intermediate_count = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (i == n - 1)
			continue;
		else if (h[i] >= h[i + 1])
			intermediate_count++;
		else {
			if (intermediate_count > max_count) 
				max_count = intermediate_count;
			intermediate_count = 0;
		}
	}
	if (intermediate_count > max_count)
		max_count = intermediate_count;
	std::cout<<max_count<<std::endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
int main(){

  int n,q;
  vector<int> a;
  cin>>n;
  for(int i=0,t;i<n&&cin>>t;i++) a.push_back(t);
  cin>>q;
  for(int i=0;i<q;i++){
    int b,m,e;
    cin>>b>>m>>e;
    vector<int> a0(e-m);
    copy(a.begin()+m,a.begin()+e,a0.begin());
    a.erase(a.begin()+m,a.begin()+e);
    a.insert(a.begin()+b,a0.begin(),a0.end());
  }
  for(int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<a[i];
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3132
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;

  for(int i=0; i<A; ++i) {
    if(!(S[i] >= '0' && S[i] <= '9')) {
      cout << "No" << endl;
      return 0;
    }
  }

  if(S[A] != '-') {
    cout << "No" << endl;
    return 0;
  }

  for(int i=A+1; i<A+B+1; ++i) {
    if(!(S[i] >= '0' && S[i] <= '9')) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int a , b , s , i ;
  cin>>a;
  s=0;
  
  for  ( i=0 ; i < a ; i++)
  {
    cin>>b;
    if ( b % 2!=0 )
    {
      s++;
    }
  }
  if ( s % 2==0 )
  {
   cout<<"YES"<<endl;
  }
  else
  {
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int64_t calc(int64_t n) {
  int64_t a = 1, b = n-1;
  return (a+b)*b/2;
}

int main() {
  int64_t N; std::cin >> N;
  fin(calc(N));
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int h, w, i, j, k, cnt;
    char s[51][51];
    int p[8] = {-1, 0, 1,-1, 1,-1, 0, 1};
    int q[8] = {-1,-1,-1, 0, 0, 1, 1, 1};

    scanf("%d %d", &h, &w);

    for(i=0; i<h; i++){
        scanf("%s", s[i]);
    }

    for(i=0; i<h; i++){
        for(j=0; j<w; j++){
            if(s[i][j] == '#')
                printf("#");
            else{
                cnt=0;
                for(k=0; k<8; k++){
                    if(s[i+q[k]][j+p[k]] == '#')
                        cnt++;
                }
                printf("%d", cnt);
            }
        }

        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 128