akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int X = (A); X <= (Y);++X)
#define _rep2(X, Y) for (int X = 0; X < (Y); ++X)
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X, Y) for (int X = (Y-1); X >= 0; --X)
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%(m))
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll X;

ll pow_5(ll x) {
    return x * x * x * x * x;
}

int main() {
    cin >> X;

    for (ll A = 0; pow_5(A) <= X; ++A) {
        ll pA = pow_5(A);
        ll pB = X - pA;
        ll lb = -1;
        ll ub = 1000;
        while ((ub - lb) > 1) {
            ll mid = (ub + lb) / 2;
            ll p = pow_5(mid);
            if (p < pB) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        if (pow_5(ub) == pB) {
            cout << A << ' ' << -ub << endl;
            cerr << pow_5(A) - pow_5(-ub) << endl;
            return 0;
        }
    }

    for (ll A = 0; pow_5(A) - pow_5(A - 1) <= X; ++A) {
        if (pow_5(A) <= X) continue;
        ll pB = pow_5(A) - X;
        ll lb = -1;
        ll ub = 1000;
        while ((ub - lb) > 1) {
            ll mid = (ub + lb) / 2;
            ll p = pow_5(mid);
            if (p < pB) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        if (pow_5(ub) == pB) {
            cout << A << ' ' << ub << endl;
            cerr << pow_5(A) - pow_5(ub) << endl;
            return 0;
        }
    }

}


Measured memory_bytes: 3596
n = int(input())
w = list(map(int,input().split()))
ans = 0
for i in range(n):
    ans += w[i]
    if ans >= sum(w)//2:
        print(min(abs(sum(w[:i+1])-sum(w[i+1:])), abs(sum(w[:i])-sum(w[i:]))))
        break

Measured memory_bytes: 3060
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string s;
    ll k;
    cin >> s >> k;
    bool all_same_flg = true;
    ll n = s.size();
    rep(i, n-1) {
        if (s[i] != s[i+1]) all_same_flg = false;
    }
    if (all_same_flg) {
        cout << s.size() * k / 2 << endl;
        return 0;
    }
    string ss = s + s;
    ll m = ss.size();
    ll cnt = 1;
    ll change_cnt = 0;
    rep(i, n) {
        if (s[i] == s[i+1]) {
            ++cnt;
        }
        else {
            change_cnt += cnt / 2LL;
            cnt = 1;
        }
    }
    cnt = 1;
    ll change_cnt2 = 0;
    rep(i, m) {
        if (ss[i] == ss[i+1]) {
            ++cnt;
        }
        else {
            change_cnt2 += cnt / 2LL;
            cnt = 1;
        }
    }
    //cout << change_cnt << " " << change_cnt2 << endl;
    cout << change_cnt + (change_cnt2 - change_cnt) * (k - 1LL) << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <string.h>
int same(char*,char*,int,int);
int main(){
  char t[1000];
  char p[1000];
  int i,j;
  int alt;
  int res;
  scanf("%s",t);
  scanf("%s",p);
  alt=strlen(t);
  res=strlen(p);
  for(i=0;i<alt;i++){
    if(same(t,p,i,res)){
      printf("%d\n",i);
    }     
  }
  return 0;
}
int same(char *t,char *p,int i,int pl){
  int j;
  for(j=0;j<pl;j++){
    if(t[i+j]!=p[j]) return 0;
  }
    
  return 1;
}

Measured memory_bytes: 540
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 0;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
vector<int>l, r;
signed main() {
	n = read();
	for (int i = 0; i < n; i++) {
		l.push_back(read());
		r.push_back(read());
	}
	l.push_back(0); r.push_back(0);
	sort(all(l)); reverse(all(l));
	sort(all(r));
	int ans = 0;
	for (int i = 0; i < n + 1; i++) {
		ans += max_0(l[i] - r[i]) * 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2036
#include <stdio.h>

int main(){
	int N;
	scanf("%d",&N);
	int Y;
	scanf("%d",&Y);
	int a;//10000
	int b;//5000
	int A;
	int B;
	int C;
	A=-1;
	B=-1;
	C=-1;
	for(a=0;a<=N;a++){
		for(b=0;b<=N-a;b++){
			if(Y==a*10000+b*5000+(N-a-b)*1000){
				A=a;
				B=b;
				C=N-a-b;
				break;
			}
		}
	}
	printf("%d %d %d",A,B,C);
}

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

using namespace std;

int main(){

    int n;cin>>n;
    vector<int> v(n+1,0);
    for(int i=1;i<n;i++){
        int a;cin>>a;
        v[a]+=1;
    }
    //for(int i=1;i<n;i++) cout<<v[i];
    for(int i=1;i<=n;i++){
        if(v[i]>0) cout<<v[i]<<endl;
        else cout<<0<<endl;
    }



return 0;

}


Measured memory_bytes: 4048
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <functional>
#include <cstring>
#include <cmath>
#include <random>
using namespace std;

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

    int64_t r;
    if (n >= m / 2) {
        r = m / 2;
    } else {
        r = n;
        m -= n * 2;
        r += m / 4;
    }

    cout << r << endl;

    return 0;
}


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

using namespace std;


int main() {
    int N; cin >> N;
    vector<pair<int,int>> V;
    for(int i=1;i<=N;i++) {
        int tmp;
        cin >> tmp;
        V.push_back({tmp, i});
    }

    sort(V.begin(), V.end());
    reverse(V.begin(), V.end());

    multiset<int> S;
    S.insert(0);
    S.insert(0);
    S.insert(N+1);
    S.insert(N+1);
    long long int ans = 0ll;
    for(int i=0;i<N;i++) {
        long long int num = V[i].first;
        long long int id = V[i].second;
        auto it = S.lower_bound(id);
        long long int r1 = *it++;
        long long int r2 = *it--;
        it--;
        long long int l1 = *it--;
        long long int l2 = *it;
        ans += num * max(0ll, id - l1) * (r2 - r1);
        ans += num * max(0ll, r1 - id) * (l1 - l2);
        S.insert(id);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5748
using System;
using System.Linq;

namespace _0515
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x[0] == 0 && x[1] == 0)
                {
                    break;
                }
                int[,] road = new int[x[0] + 1, x[1] + 1];
                bool[,] b = new bool[x[0] + 1, x[1] + 1];
                int n = int.Parse(Console.ReadLine());
                for (int i = 0; i < n; i++)
                {
                    int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    b[a[0], a[1]] = true;
                }
                road[1, 1] = 1;
                for (int i = 1; i <= x[0]; i++)
                {
                    for (int j = 1; j <= x[1]; j++)
                    {
                        if (!(i == 1 && j == 1))
                        {
                            if (b[i, j] == false)
                            {
                                road[i, j] = road[i - 1, j] + road[i, j - 1];
                            }
                        }
                    }
                }
                Console.WriteLine(road[x[0], x[1]]);
            }
        }
    }
}

Measured memory_bytes: 9516
#include <stdio.h>
void solve(void)
{
	int a,b,c,d;
	scanf("%d %d %d %d", &a,&b,&c,&d);
	printf("%d\n", a*b<c*d?c*d:a*b);
}
int main(int argc, char **argv)
{
	solve();
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
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; }
using namespace std;

int h,w;
int a[510][510];

signed main(){
    cin>>h>>w;
    rep(i,h)rep(j,w)cin>>a[i][j];
    vector<pair<P,P>> ans;
    rep(i,h){
        rep(j,w-1){
            if(a[i][j]%2==1){
                ans.push_back(pair<P,P>(P(i+1,j+1),P(i+1,j+2)));
                a[i][j]--;
                a[i][j+1]++;
            }
        }
        if(a[i][w-1]%2==1 and i<h-1){
            ans.push_back(pair<P,P>(P(i+1,w),P(i+2,w)));
            a[i][w-1]--;
            a[i+1][w-1]++;
        }
    }
    cout<<ans.size()<<endl;
    rep(i,ans.size()){
        cout<<ans.at(i).F.F<<' '<<ans.at(i).F.S<<' '<<ans.at(i).S.F<<' '<<ans.at(i).S.S<<endl;
    }
}

Measured memory_bytes: 8432
n, k = map(int, input().split())

cnt = [0] * (n + 1)
for _ in range(k):
    d = int(input())
    a = tuple(map(int, input().split()))
    for ai in a:
        cnt[ai] += 1

ans = 0
for i in range(1, n + 1):
    if cnt[i] == 0:
        ans += 1
print(ans)


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

int main(){
  char s[100];
  int hug=0,i,j,x;

  scanf("%s",s);
  x=strlen(s);
  
    if(x%2==1){
    for(i=0;i<(x-1)/2;i++){
      if(s[i]!=s[x-i-1]){
	hug++;
      }
    }
  }	
  else{
    for(j=0;j<x/2;j++){
      if(s[j]!=s[x-j-1]){
	hug++;
     }
    }
  }

  printf("%d",hug);
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Vertex {
    vector<pll> node;
};

Vertex V[100005];
ll A[100005];
bool U[100005];

int main() {
    ll N;
    cin >> N;
    REP(i, N - 1) {
        ll a, b, w;
        cin >> a >> b >> w;
        a--;
        b--;
        V[a].node.push_back(pll(b, w));
        V[b].node.push_back(pll(a, w));
    }

    memset(A, 0, sizeof(A));
    memset(U, 0, sizeof(U));
    queue<pll> q;
    q.push(pll(0, 0));
    while (!q.empty()) {
        pll t = q.front();
        q.pop();
        U[t.first] = true;
        REP(i, V[t.first].node.size()) {
            pll n = V[t.first].node[i];
            if (U[n.first])
                continue;
            ll cost = n.second + t.second;
            A[n.first] = cost % 2;
            q.push(pll(n.first, cost));
        }
    }

    REP(i, N) {
        cout << A[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 8704
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# 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 REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, k;
LL a[201010];
LL rui[201010];
vector<LL>v;

//[1,n],size
LL bit[201010 + 1];

LL sum(int i) {
	LL s = 0;
	while (i > 0) {
		s += bit[i];
		//i&-iはiの最後の1ビット
		i -= i&-i;
	}
	return s;
}

void add(int i, int x) {
	while (i <= 202020) {
		bit[i] += x;
		i += i&-i;
	}
}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		rui[i] = rui[i - 1] + a[i];
	}
	for (int i = 1; i <= n; i++) {
		v.emplace_back((LL)rui[i] - (LL)k*i);
	}
	v.emplace_back(0);
	sort(ALL(v));
	UNIQ(v);
	LL ans = 0;
	add(lower_bound(ALL(v), 0) - v.begin() + 1, 1);
	for (int i = 1; i <= n; i++) {
		LL num = lower_bound(ALL(v), (LL)rui[i] - (LL)k*i) - v.begin() + 1LL;
		ans += sum(num);
		add(num, 1LL);
	}
	cout << ans << endl;
}

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

int main() {
    string a, b;
    cin >> a >> b;
    string c = a + b;
    int d = stoi(c);
    for (int i = 1; i * i <= d; ++i) {
        if (i * i == d) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	ll a, b, n; cin >> a >> b >> n;
	ll k=n-(n%b)-1;
	if(k<=0)
		k=n;
	ll ans=(a*k)/b-a*(k/b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,i;
  cin>>n;
  string s;
  set<string>a;

  for(i=0;i<n;i++)
  {
    cin>>s;
    a.insert(s);
  }
  cout<<a.size();
}



Measured memory_bytes: 19200
S = input()

keyword = 'keyence'
if (S[:7] == keyword) or (S[-7:] == keyword):
    print('YES')
    exit()

f, b = 0, 0
# forward
for i, (key, s) in enumerate(zip(keyword, S)):
    if key != s:
        f = i
        break
    else:
        # keyword = keyword[1:]
        pass
# print(keyword)
# backward
for i, (key, s) in enumerate(zip(keyword[::-1], S[::-1])):
    # print(key, s)
    if key != s:
        b = i
        break
    else:
        keyword = keyword[1:]

# print(f, b)
if f + b > 6:
    print('YES')
else:
    print("NO")


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

using namespace std;

int main () {
    int k, n;
    cin >> k >> n;
    vector<int> A(n);
    vector<int> D(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < n - 1; i++) {
        D[i] = A[i + 1] - A[i];
    }
    D[n - 1] = (k - A[n - 1]) + A[0];
    sort(D.begin(), D.end());
    cout << (k - D[n - 1]) << "\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int main()
{
	int n;
	cin >> n;
	cout << (n * n * n);
}


Measured memory_bytes: 31488
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long N, std::vector<long long> A){
  vector<long long> B(N);
  for (int i = 0; i < N; i++) {
    B[i] = A[i];
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < N; i++) {
    if (A.back() == B[i]) {
      std::cout << A[N-2] << std::endl;
    } else {
      std::cout << A[N-1] << std::endl;
    }
  }
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 4736
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, K, C;
  cin>>N>>K>>C;
  string S;
  cin>>S;
  map<int, int> amap;
  map<int, int> ans;
  for(int i=0;i<N;++i) {
    if(S[i]=='o') {
      amap[i]++;
      i += C;
    }
  }
  reverse(S.begin(), S.end());
  for(int i=0;i<N;++i) {
    if(S[i]=='o') {
      amap[N-1-i]++;
      i += C;
    }
  }
  int num = 0;
  for(int i=0;i<N;++i) {
    if(amap[i]==2) num++;
  }
  if(num>K) return 0;
  for(int i=0;i<N;++i) {
    if(amap[i]==2) cout<<i+1<<endl;
  }
}



Measured memory_bytes: 12988
#include<stdio.h>

void insertionSort(int a[1000], int N);

int main(void){
    int a[1000],N,i,j;
    scanf("%d",&N);
    
    for(i=0;i<N;i++){
        scanf("%d ",&a[i]);
    }

    insertionSort(a,N);

}

void insertionSort(int a[1000], int N){
    int i,j,k,v;

    printf("%d",a[0]);
    for(k=1;k<N;k++){
        printf(" %d",a[k]);
    }
    printf("\n");
 

    for(i=1;i<N;i++){
        v=a[i];
        j=i-1;
        while(j>=0 && a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;

        printf("%d",a[0]);
        for(k=1;k<N;k++){
            printf(" %d",a[k]);
        }
        printf("\n");
    }
        
}



Measured memory_bytes: 1996
nq = input().split()
n = int(nq[0])
Q = int(nq[1])

s = input()

prefix_sums = [0 for i in range(0,n+1)]

for i in range(1, n):

    prefix_sums[i+1] = prefix_sums[i]

    if s[i] == 'C' and s[i-1] == 'A': prefix_sums[i+1]+=1

for query in range(0,Q):

    lr = input().split()
    l=int(lr[0])
    r=int(lr[1])

    print(prefix_sums[r]-prefix_sums[l])

    


Measured memory_bytes: 6152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

bool check(ll n, ll x) {
    return n % x == n / x;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0 && n / i > 1) {
            ll x = n / i - 1;
            if (check(n, x)) {
                ans += x;
            }
                
        }
    }
    cout << ans << endl;
    /*
    for (ll i = 1; i <= n; i++) {
        if (n % i == n / i) {
            cout << n / i << " " << i << endl;
            cout << n / (i + 1) * i + n / (i + 1) << endl;
            ans -= i;
        }
    }
    dump(ans);
    */
    return 0;
}


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

/*
template<size_t max_N>
struct Prime{
    bool is_prime[max_N];
    constexpr Prime() : is_prime() {
        for(int i = 0; i < max_N; i++) is_prime[i] = true;
        is_prime[0] = is_prime[1] = false;
        for (int i = 0; i < max_N; i++)
        {
            if(!is_prime[i]) continue;
            for (int j = i*i; j < max_N; j+=i) is_prime[j] = false;
        }
        
    }
};
*/

template<size_t max_N, size_t prime_size>
struct Prime{
    bool sieve[max_N];
    int_fast64_t prime[prime_size];
    int_fast64_t nlike[max_N];
    size_t counter = 0;
    constexpr Prime() : sieve(), prime(), nlike() {
        for(int_fast64_t i = 0; i < max_N; ++i)
            sieve[i] = true;
        sieve[0] = sieve[1] = false;
        for(int_fast64_t i = 2; i < max_N; ++i){
            if(sieve[i]){
                prime[counter] = i;
                ++counter;
                if(counter > prime_size)break;
            }
            for(int_fast64_t j = i * i; j < max_N; j += i)
                sieve[j] = false;
        }
        for (int i = 1; i < max_N; i++)
        {
            if(i%2==1 && sieve[i] && sieve[(i+1)/2]) nlike[i] = nlike[i-1] + 1;
            else nlike[i] = nlike[i-1];
        }
    }
};

constexpr void check_like(std::vector<int>& n_like, const Prime<100100, 10000>& p){
}
int main(){
    using namespace std;
    const int PRIME_MAX = 1e5+100;
    int Q; cin >> Q;
    vector<int> l(Q), r(Q);
    vector<int> n_like(PRIME_MAX, 0);
    for (int i = 0; i < Q; i++) cin >> l[i] >> r[i];
    constexpr auto p = Prime<PRIME_MAX, 10000>();
    
    for (int i = 0; i < Q; i++)
    {
        cout << p.nlike[r[i]] - p.nlike[l[i]-1] << endl;
    }
}


Measured memory_bytes: 2816
#include<stdio.h>
int main(void){
  int N,A,B,i,tmp,sum=0,ans=0;
  scanf("%d %d %d",&N,&A,&B);
  for(i=1; i<=N; i++){
    tmp = i;
    sum = 0;
    while(tmp > 0){
      sum += tmp % 10;
      tmp /= 10;
    }
    if(A <=sum && sum <= B)
      ans += i;
  }
  printf("%d\n",ans);
 
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
int nx[4]={0,-1,0,1};
int ny[4]={-1,0,1,0};

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

int main(){
    int a,b,c;
    int ans=inf;
    cin >> a >> b >> c;
    int ma=max(a,max(b,c));
    int mapp=ma++;
    int sum=3*ma-(a+b+c);
    int sum1=3*mapp-(a+b+c);
    if(sum%2==0) cout << sum/2 << endl;
    else cout << sum1/2 <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int H, W, N; cin >> H >> W >> N;

  ll dp[10];
  rep(i, 10) dp[i] = 0LL;
  dp[0] = (ll)(H-2) * (W-2);

  int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
  int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
  set<pair<int, int>> st;

  rep(i, N) {
    int a, b; cin >> a >> b;
    st.insert(make_pair(b, a));

    rep(j, 9) {
      int nx = b + dx[j];
      int ny = a + dy[j];
      if (nx <= 1 || nx >= W || ny <= 1 || ny >= H) continue;

      int cnt = 0;
      rep(k, 9) {
        int nnx = nx + dx[k];
        int nny = ny + dy[k];
        cnt += st.count(make_pair(nnx, nny));
      }
      dp[cnt]++;
      dp[cnt-1]--;
    }

  }

  rep(i, 10) cout << dp[i] << endl;

  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
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;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long 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;
    }
}
// 二項係数計算
long long 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;
}

int main() {
    int a,b,k;
    cin >> a >> b >> k;
    int cnt = 0;
    vector<int> p;
    for(int i=1; i<=max(a,b); ++i) {
        if (a%i == 0 && b %i == 0) {
            p.pb(i);
        }
    }
    cout << p[p.size()-k] << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define rrep(i,a,b) for(ll i=a;i>b;i-=1)
#define vi vector<ll>
#define vii vector<vector<ll> >
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define tr(c,i) for( typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mp make_pair
#define hell 1000000007
#define F first
#define S second
//debug
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
ll t=1;
void solve()
{
    string a,b;
    cin>>a>>b;
    int n=a.length();
    int m=b.length();
    int dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i-1]==b[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    string ans;
    int i=n,j=m;
    while(i>0 && j>0)
    {
        if(dp[i][j] == dp[i-1][j]) {
			i--;
		} else if(dp[i][j] == dp[i][j-1]) {
			j--;
		} else {
			ans.push_back(a[i-1]);
			i--;
			j--;
		}
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}
int main()
{
    int i;
  	ios_base::sync_with_stdio(false);
	cin.tie(0);
    cout.tie(0);
  	//cin>>t;
  	while(t--)
	solve();
	return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <vector>

using namespace std;
int min(int a, int b){
	return a < b ? a : b;
}
int main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	int inf = 1e9 + 7;
	vector<int>dp(n, inf);
	dp[0] = 0;
	for (int i = 0; i < n; i++){
		for (int j = 1; j <= k && i + j < n; j++){
			dp[i + j] = min(dp[i + j], dp[i] + abs(a[i] - a[i + j]));
		}
	}
	cout << dp[n - 1];
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<string>
#include<cstdio>
#include<stack>
#include<cmath>
#include<bitset>
#include<memory>
#include<memory.h>
#include<utility>
#include<map>
using namespace std;
#define FOR(i,m,n) for(i=m;i<n;i++)
#define CLR(a,b) memset(a,b,sizeof(a))
#define ROF(i,m,n) for(i=m;i>=n;i--)
#define BUG cout<<"debug"<<endl;
#define RT return
#define BK break
#define HEAP priority_queue
#define SP " "
#define rd(x) (rand()%(x))
#define lowf(a,b,c) lower_bound(a,b,c)
#define upf(a,b,c) upper_bound(a,b,c)
#define sh(a) cout<<a<<endl
typedef long long LL;
typedef vector<int> VI;
const int INF = 2147483647;
const int NEN = -INF - 1;
const LL LINF = 9223372036854775807;
int W, H, I1, J1,N;char g[1005][1005];
bool vis[1005][1005];
bool can(int x, int y)
{
	return x >= 0 && y >= 0 && x < H&&y < W&&g[x][y]!='X';
}
typedef struct node
{
	int i, j, sum;
	node()
	{
		;
	}
	node(int a, int b, int c)
	{
		i = a; j = b; sum = c;
	}
}node;
queue<node>bfs;
typedef struct pos
{
	int x,y;
}pos;
pos all[10];
int dir[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };
int main()
{
	cin >> H >> W >> N;
	node temp;
	int T,i,j,ans=0;
	FOR(i, 0, H)
	{
		FOR(j, 0, W)
		{
			cin >> g[i][j];
			//scanf_s("%c", &g[i][j]);
			if (g[i][j] > '0'&&g[i][j] <='9')
			{
				all[g[i][j] - 48].x = i;
				all[g[i][j] - 48].y = j;
			}
			else if (g[i][j] == 'S')I1 = i, J1 = j;
		}
	}
	FOR(T,0,N)
	{
		CLR(vis, 0);
		while (!bfs.empty())bfs.pop();
		if(T>0)bfs.push(node(all[T].x, all[T].y, 0));
		else bfs.push(node(I1, J1, 0));
		while (!bfs.empty())
		{
			temp = bfs.front();
			bfs.pop();
			if (g[temp.i][temp.j] == T+48+1)
			{
				ans += temp.sum;
				break;
			}
			int k = 4,tx,ty;
			while (k--)
			{
				tx = temp.i + dir[k][0];
				ty = temp.j + dir[k][1];
				if (can(tx, ty) == true&&!vis[tx][ty])
				{
					vis[tx][ty] = 1;
					bfs.push(node(tx, ty, temp.sum + 1));
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 5088
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a;
	cin>>a;
	int b=a%10;
	a/=10;
	int c=a%10;
	a/=10;
	int d=a%10;
	a/=10;
	int e=a;
	if(b==c||c==d||d==e)
		puts("Bad");
	else puts("Good");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String string = sc.nextLine();
		boolean b = string.contains("a") && string.contains("b") && string.contains("c");
		System.out.println(b ? "Yes" : "No");
	}

}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,x;cin>>a>>b>>x;
  ll aa=a/x;
  ll bb=b/x;
  ll c=a%x;
  ll d=b%x;
  if(c==0&&d==0)cout<<bb-aa+1<<endl;
  if(c==0&&d!=0)cout<<bb-aa+1<<endl;
  if(c!=0&&d==0)cout<<bb-aa<<endl;
  if(c!=0&&d!=0)cout<<bb-aa<<endl;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
AB = A + B

if N >= AB:
    iters, div = divmod(N, AB)
    if div <= A:
        print((A*iters + div))
    else:
        print((A*(iters + 1)))
elif N >= A:
    print(A)
else:
    print(N)

Measured memory_bytes: 38384
from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


INT_MAX = 10 ** 10


if __name__ == "__main__":
    N = read()
    B = [INT_MAX]
    B.extend(readlist())
    B.append(INT_MAX)

    print(sum([min(B[i], B[i-1]) for i in range(1, N+1)]))



Measured memory_bytes: 3444
fun readList() = readLine()!!.split(" ").map{it.toInt()}
fun main(args:Array<String>){
  val n = readLine()!!.toInt()
  val a = readList()
  val b = readList()
  val c = readList()
  var score = 0
  for (i in a.indices){
    score += b[a[i]-1]
    if(i > 0)if(a[i] == a[i-1]+1)score += c[a[i-1]-1]
  }
  println(score)
}

Measured memory_bytes: 36200
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
using namespace std;



int main(){
    while(1){
        
        
    int m,n;
    cin>>m>>n;
    if(m==0 && n==0){break;}
    int y;
    bool t[7368792]={};
    for(int i=m;n>=0;i++){
        y=i;
        if(!t[i]){
            n--;
            for(int h=2;i*h<7368792;h++){
                t[h*i]=true;
            }
        }
    }
    
    cout<<y<<endl;
    
    }
    
    return 0;
}



Measured memory_bytes: 10260
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    double r;
    cin >> r;
    cout << precise(20) << 2 * M_PI * r;
}


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

int main() {
	long int arr[4];
	for(int i=0; i<4; i++){
		cin>>arr[i];
	}
	long int ans = -1e18;
	for(int i=0; i<2; i++)ans=max(ans, max(arr[i]*arr[2], arr[i]*arr[3]));
	cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード

//ループ
#define rep(i, n) for(int i = 0; i < n; i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ

//型名省略
typedef long long ll;
//値
static const ll MX = 1e18;
#define NIL = -1;

using namespace std;

//#include "./lib/generic/search.h"

int main(){
    int n;
    cin >> n;
    
    cout << n+n*n+n*n*n << endl;
}

Measured memory_bytes: 3592
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		double ans = (double)((N + 1) / 2) / (double)N;
		Console.WriteLine($"{ans:F9}");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 13268
import math
n=int(raw_input())
sq=math.sqrt(n)
ans=None



if str(sq)[-2]=='.':
    print len(str(sq))-2
else:
    nu=[]
    while sq>1:
        sq=int(sq)
        if n%sq==0:
            nu.append(str(sq))
            nu.append(str(n/sq))
            sq-=1
            break
        else:
            sq-=1
    if len(nu)!=0:
        nu.sort(key=len)
        print len((nu[1]))
    else:
        print len(str(n))

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	if( n % 2 == 1 )
	{
		for (int i = 1; i <= m; i++)
		{
			cout << i << ' ' << n - i << '\n';
		}
	}else
	{
		int t = ( n - 1 ) / 2;
		int begin1 = 1;
		int begin2 = 1 + t + 1;
		int num = 0;
		for (int i = t; i > 0; i -= 2)
		{
			if( num == m ) break;
			cout << begin1 << ' ' << begin1 + i << '\n';
			begin1 ++;
			num ++;	
		}
		for (int i = t - 1; i > 0; i -= 2)
		{
			if( num == m ) break;
			cout << begin2 << ' ' << begin2 + i << '\n';
			begin2 ++;
		}
	}
	return 0;
}


Measured memory_bytes: 3228
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    ll N, K;
    cin >> N >> K;
    map<ll,ll>cnt;
    for(ll i = 1; i <= N; i++){
        ll tmp = 0;
        for(ll I = i;I < K;){
            I += I;
            tmp++;
        }
        cnt[tmp]++;
    }
    double ans = 0;
    for(map<ll, ll>::iterator it = cnt.begin(); it != cnt.end(); it++){
        ll m = (*it).first;
        double tmp = (*it).second;
        for(ll i = 0; i < m; i++){
            tmp *= 0.5;
        }
        ans += tmp;
    }
    printf("%.12f\n", ans / N);

    return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  string s;
  int k;
  cin >> s >> k;
  for(int i=0;i<s.length();i++){
    if(s[i]!='a'&&26-(s[i]-'a')<=k) k-=26-s[i]+'a',s[i]='a';
  }
  if(k>0) s[s.length()-1]='a'+(s[s.length()-1]-'a'+k%26)%26;
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 512
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize, k: usize,
        av: [usize; n]
    };

    let mut map = HashMap::new();
    for a in av {
        *map.entry(a).or_insert(0) += 1;
    }
    let mut v = map.into_iter().collect::<Vec<_>>();
    v.sort_by_key(|(_, c)| -(*c as isize));
    let res = n - v.into_iter().take(k).fold(0, |acc, (_, c)| acc + c);
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 10432
N, M = map(int, input().split())
p = list(map(int, input().split()))
e = [list(map(int, input().split())) for _ in range(M)]
res = 0
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1] * (n + 1)
    self.rnk = [0] * (n + 1)

  def Find_Root(self, x):
    if self.root[x] < 0:
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]

  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if x == y:
      return 
    elif self.rnk[x] > self.rnk[y]:
      self.root[x] += self.root[y]
      self.root[y] = x
    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      if self.rnk[x] == self.rnk[y]:
        self.rnk[y] += 1

  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)

  def Count(self, x):
    return -self.root[self.Find_Root(x)]
uf = UnionFind(N)
childs = [[] for _ in range(N + 1)]
for i in range(M):
  uf.Unite(e[i][0], e[i][1])
for i in range(1, N + 1):
  childs[uf.Find_Root(i)].append(i)
for c in childs:
  temp = set([p[i - 1] for i in c])
  inter = temp & set(c)
  res += len(inter)
print(res)

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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define SORT(v) sort(ALL(v))
//#define scanf scanf_s
typedef pair<int, int> P;

int main()
{
	int n, m, a;
	int h, p, q;
	while (cin >> n >> m >> a, n)
	{
		vector<pair<int, P>> v;
		REP(i, m)
		{
			cin >> h >> p >> q;
			v.push_back(make_pair(-h, P(p, q)));
		}
		SORT(v);
		REP(i, m)
		{
			if (v[i].second.first == a)
			{
				a = v[i].second.second;
			}
			else if (v[i].second.second == a) a = v[i].second.first;
		}
		cout << a << endl;
	}

	return 0;
}

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

const int N = 2e5 + 10;

int ans[N], used[N];

int main(){
	int n, x, p;
	scanf("%d %d",&n,&x);
	if (x == 1 || x == n * 2 - 1){
		printf("No\n");
		return 0;
	}
	memset(used, 0, sizeof(used));
	memset(ans, 0, sizeof(ans));
	if (n == 2){
		ans[1] = 1; ans[2] = 2; ans[3] = 3;
	}
	else{
		ans[n] = x;
		used[x] = 1;
		ans[n - 1] = x - 1;
		used[x - 1] = 1;
		ans[n + 1] = x + 1;
		used[x + 1] = 1;
		if (x == 2){
			ans[n - 2] = x + 2;
			used[x + 2] = 1;
		}
		else{
			ans[n + 2] = x - 2;
			used[x - 2] = 1;
		}
		p = 1;
		for (int i = 1; i <= n * 2 - 1; i++){
			if (ans[i]) continue;
			while (used[p]) p++;
			ans[i] = p;
			used[p] = 1;
		}
	}
	printf("Yes\n");
	for (int i = 1; i <= n * 2 - 1; i++) printf("%d\n", ans[i]);
	return 0;
} 

Measured memory_bytes: 3072
#include <iostream>
using namespace std;
using int64 = int64_t;

int64 f(int64 x, int64 y){
  int64 mx = max(x, y);
  int64 mn = min(x, y);
  if (mx%mn == 0) return (mx/mn)*(2L*mn) - mn;
  return f(mn, mx%mn) + (mx/mn)*(2L*mn);
}

int main(){
  int64 n, x;
  cin >> n >> x;
  int64 ans = x + (n-x) + f(x, n-x);
  cout << ans << endl;
  return 0;
}

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

const int mod = 998244353;
struct mint {
    ll x;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) {
            x -= mod;
        }
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) {
            x -= mod;
        }
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<mint> nck(n, 0);
    nck[0] = 1;
    for(int i = 1; i < n; i++){
        nck[i] = nck[i-1] * (n - i);
        nck[i] /= i;
    }
    rep(i, n)nck[i] *= m;
    mint p = 1;
    for(int i = n - 1; i >= 0; i--){
        nck[i] *= p;
        p *= (m - 1);
    }
    mint ans = 0;
    rep(i, k + 1)ans += nck[i];
    cout << ans.x << endl;
}

Measured memory_bytes: 4840
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll x,y;
    std::cin >> x>>y;
    
    if( x == 0 || y == 0 ){
        if(x>0){
            std::cout << x+1 << std::endl;
            return 0;
        }else if(x==0){
            if(y>=0){
                std::cout << abs(y) << std::endl;
                return 0;
            }else{
                std::cout << abs(y)+1 << std::endl;
                return 0;
            }
        }else{
            std::cout << abs(x) << std::endl;
            return 0;
        }
    }
    
    if( (ll)abs(x) > (ll)abs(y) ){
        if(x>0){
            if(y>0){
                std::cout << 2+ (ll)abs(x) - (ll)abs(y)<< std::endl;
            }else{
                std::cout << 1+ (ll)abs(x) - (ll)abs(y)<< std::endl;
            }
        }else{
            if(y>0){
                std::cout << 1+ (ll)abs(x) - (ll)abs(y)<< std::endl;
            }else{
                std::cout << (ll)abs(x) - (ll)abs(y)<< std::endl;
            }
        }
    }else if((ll)abs(x)==(ll)abs(y)){
        if(x*y>0){
            std::cout << 0 << std::endl;
            return 0;
        }else{
            std::cout << 1 << std::endl;
            return 0;
        }
    }else{
        if(x>0){
            if(y>0){
                std::cout << (ll)abs(y) - (ll)abs(x)<< std::endl;
            }else{
                std::cout << 1+ (ll)abs(y) - (ll)abs(x)<< std::endl;
            }
        }else{
            if(y>0){
                std::cout << 1+ (ll)abs(y) - (ll)abs(x)<< std::endl;
            }else{
                std::cout << 2+(ll)abs(y) - (ll)abs(x)<< std::endl;
            }
        }
    }
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
judge_results = [input() for _ in range(n)]
count = Counter(judge_results)

print(f'AC x {count["AC"]}')
print(f'WA x {count["WA"]}')
print(f'TLE x {count["TLE"]}')
print(f'RE x {count["RE"]}')

Measured memory_bytes: 16496
#include <iostream>
#include <algorithm>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    int ans = 1;
    x -= y + 2*z;
    ans += x / (y + z);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"Yes"<<endl
#define cno cout<<"No"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

int main(){

    int cnt = 1;
    while(1){
        int x;
        cin >> x;
        if(x == 0) return 0;
        cout << "Case" sp cnt << ':' sp x << endl;
        cnt++;
    }
    return 0;
}


Measured memory_bytes: 3056
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if (a < b && b < c) {
		 System.out.println("Yes");   
		} else {
		 System.out.println("No");   
		}
	}
}


Measured memory_bytes: 26136