akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
int main()
{
    uint64_t n{}, k{};
    std::cin >> n >> k;
    std::vector<uint64_t> enemy(n);
    for (uint64_t i = 0; i < n; i++) {
        std::cin >> enemy[i];
    }
    // TODO
    if (enemy.size() <= k) {
        std::cout << 0;
        return 0;
    }
    std::nth_element(enemy.begin(), enemy.end() - k, enemy.end());
    std::cout << std::accumulate(enemy.begin(), enemy.end() - k, uint64_t{});
    return 0;
}

Measured memory_bytes: 1792
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <bitset>
#include <iterator>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <random>
#include <numeric>
#include <set>
#include <cassert>
#include <cmath>
#include <cinttypes>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}
template<class T> T read_val() { throw 1; }
template<> int read_val() { int tmp; scanf("%" PRId32, &tmp); return tmp; }
template<> long long read_val() { long long tmp; scanf("%" PRId64, &tmp); return tmp; }
auto read_int = read_val<int>; auto read_long = read_val<long long>;
template<class T> void scanf_vec(vector<T>& vec) { for (int i = 0; i < vec.size(); i++) vec[i] = read_val<T>(); }

#define MOD 1000000007
#define inf 2000000000
#define FWT_SIZE 2000000
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define sort_all(x) sort(all(x))
#define make_unique(x) (x).erase(unique(all(x)), (x).end())

vector<int> step(vector<int> vec)
{
	vector<int> ans;
	for (int i = 0; i + 1 < vec.size(); i++)
	{
		ans.push_back(abs(vec[i] - vec[i + 1]));
	}
	return ans;
}

int solve(vector<int> &vec)
{
	int n = vec.size() - 1;
	vector<int> ans;
	ans.push_back(0);
	for (int j = 30; j >= 0; j--)
	{
		if ((1<<j) & n)
		{
			vector<int> newans;
			for (int jj : ans)
			{
				newans.push_back(jj);
				newans.push_back(jj + (1 << j) );
			}
			ans = newans;
		}
	}
	int resp = 0;
	for (int x : ans)
	{
		if (x < vec.size())
			resp ^= vec[x];
	}
	return resp;
}

int main() {

#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	string str;
	cin >> str;
	n = str.size();
	vector<int> vec;
	bool any2 = false, any1 = false;
	for (char c : str)
	{
		vec.push_back(c - '0');
	}

	vector<int> orig_vec = vec;
	vec = step(vec);
	for (int c : vec)
	{
		if (c == 2) any2 = true;
		if (c == 1) any1 = true;
	}

	if (any1)
	{
		for (int& x : vec)
		{
			if (x == 2)x = 0;
		}
		cout << solve(vec);
	}
	else
	{
		cout << solve(vec);
	}

	return 0;
	cout << "\n";
	vec = orig_vec;
	while (vec.size() > 1)
	{
		vec = step(vec);

		cout << vec << "\n";

	}



	return 0;
}

Measured memory_bytes: 21140
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    stack<char> st;
    int ans = s.size();
    rep(i, 0, s.size()){
        if(s[i] == 'S') st.push(s[i]);
        else if(s[i] == 'T'){
            if(!st.empty()){
                st.pop(); ans -= 2;
            }
        }
    }
    cout << ans << endl;
}

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

const int MAX = 200000;
const int MOD = 1000000007;
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;
}

map<long long, int> factorize(long long n) {
    map<long long, int> ret;
    for(long long i=2; i * i <= n; ++i) {
        while(n % i == 0) {
            ++ret[i];
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

int main() {
    int N;
    long long M;
    cin >> N >> M;
    map<long long, int> b = factorize(M);
    COMinit();
    long long ans = 1;
    for(auto itr = b.begin(); itr != b.end(); ++itr) {
        ans *= COM(itr->second + N - 1, N - 1);
        ans %= MOD;
    }
    cout << ans << endl;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int m = s.size();
    for (int i = 0;i < m;++i) cout << (char)('A'+(s[i]-'A'+n)%26);
    return 0;
}

Measured memory_bytes: 256
package main
import "fmt"
func main(){
    var N int
    var V, C [20]int
    fmt.Scan(&N)
    for i:=0;i<N;i++{
        fmt.Scan(&V[i])
    }
    for i:=0;i<N;i++{
        fmt.Scan(&C[i])
        V[i] -= C[i]
    }
    ans := 0
    for i:=0;i<N;i++{
        if V[i] >0{
            ans += V[i]
        }
    }
    fmt.Println(ans)
    
}


Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, m;
string str;

int main(){
	cin >> n;
	
	ll ans = 0;
	for(ll i = 1; i < n; i++){
		ans += i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, n) for (int i = int(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to; double cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
using DI = pair<double, int>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2, mod);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

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

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

int main() {
	int a, b;
	cin >> a >> b;
	cout << 6 - a - b << endl;
}

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

void outPut(int Array[],char mark)
{
	for(int i = 1; i <= 13; i++){
		if(Array[i] == 0) 
            cout<<mark<<" "<<i<<endl;
	}
}
int main(void)
{
	char mark[2];
	int n,S[14],H[14],C[14],D[14],tmp;
	for(int i = 0; i < 14; i++) 
        S[i] = H[i] = C[i] = D[i] = 0;
	cin>>n;
	for(int i = 0; i < n; i++)
	{
		cin>>mark>>tmp;
		switch(mark[0])
		{
		case 'S':
			S[tmp] = 1;
			break;
		case 'H':
			H[tmp] = 1;
			break;
		case 'C':
			C[tmp] = 1;
			break;
		case 'D':
			D[tmp] = 1;
			break;
		}
	}
	outPut(S,'S');
	outPut(H,'H');
	outPut(C,'C');
	outPut(D,'D');
}



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

int main()
{
  int n;
  while ( cin >> n )
  {
    set<int> s;
    int now = n, cnt = 0;
    while ( !s.count(now) )
    {
      cnt++ ;
      s.insert(now);
      if ( now%2 ) now = 3*now +1;
      else now /= 2;
    }
    printf("%d\n", cnt+1);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h ,w ,K, ck, ans=0, pi, pj;
  char bw;
  cin >> h >> w >> K;
  vector<vector<int>> data(h, vector<int>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
        cin >> bw;
        if(bw == '#') data.at(i).at(j) = 1;
    }
  }

  for(int k=0;k<pow(2,h);k++){
    for(int l=0;l<pow(2,w);l++){
        ck = 0;
        for(int i=0;i<h;i++){
          	pi = pow(2,h-i-1);
            for(int j=0;j<w;j++){
              	pj = pow(2,w-j-1);
                if((pi&k) == 0){
                    if((pj&l) == 0){
                        ck += data.at(i).at(j);
                    }
                }
            }
        }
        if(ck == K){
            ans++;
        }
    }
  }
  cout << ans;
  
  
}

Measured memory_bytes: 4108
#include <cstdio>
#include <vector>
#include <algorithm>

using std::vector;

const int MaxK = 18, MaxN = 1 << MaxK, MaxS = 1 << 12;
const int MaxQ = 100005;

int n, q, W = 0;

struct item_t {
	int w, v;
	
	inline item_t add(const item_t &other) const {
		return {w + other.w, v + other.v};
	}
} items[MaxN];

struct query_t {
	int w, id;
};
vector<query_t> buk[MaxN];

int ans[MaxQ];

inline void append(vector<item_t> &f, const item_t &cur) {
	if (f.empty() || cur.v > f.back().v) f.push_back(cur);
}

vector<item_t> trans(const vector<item_t> &f, const item_t &item) {
	vector<item_t> res;
	auto it = f.begin();
	for (auto cur: f) {
		while (it != f.end() && it->w + item.w <= cur.w) append(res, it++->add(item)); 
		append(res, cur);
	}
	while (it != f.end() && it->w + item.w <= W) append(res, it++->add(item));
	return res;
}

inline bool cmp_w(const item_t &a, const item_t &b) {
	return a.w < b.w;
}

struct solve {
	const vector<item_t> &dp;
	vector<item_t> tmp;
	int res;
	
	solve(int u, int w, const vector<item_t> &f): dp(f), res(0) {
		for (; u >= MaxS; u >>= 1) tmp.push_back(items[u]);
		dfs(tmp.begin(), w, 0);
	}
	
	void dfs(vector<item_t>::iterator cur, int w, int v) {
		if (w < 0) return;
		if (w == 0 || cur == tmp.end()) {
			auto it = --std::upper_bound(dp.begin(), dp.end(), (item_t){w, 0}, cmp_w);
			res = std::max(res, v + it->v);
			return;
		}
		auto nxt = std::next(cur);
		dfs(nxt, w, v);
		dfs(nxt, w - cur->w, v + cur->v);
	}
};

void dfs(int u, const vector<item_t> &f) {
	if (u > n) return;
	const vector<item_t> &g = u < MaxS ? trans(f, items[u]) : f;
	for (auto q: buk[u]) ans[q.id] = solve(u, q.w, g).res;
	dfs(u << 1, g);
	dfs(u << 1 | 1, g);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &items[i].v, &items[i].w);
	}
	scanf("%d", &q);
	for (int i = 0; i < q; ++i) {
		int u, w;
		scanf("%d%d", &u, &w);
		buk[u].push_back({w, i});
		W = std::max(W, w);
	}
	dfs(1, {{0, 0}});
	for (int i = 0; i < q; ++i) printf("%d\n", ans[i]);
	return 0;
}


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

int main(){
    int a[5], min = 10,mini, sum = 0, sumi, sumj, sumk, suml, summ;
    for(int i = 0; i < 5; i++){
        cin >> a[i];
        if(min > a[i] % 10 && a[i] % 10 != 0) min = a[i] % 10;
        sum += ((a[i]-1) / 10 + 1) * 10;
    }
    sum -= (10- min);
    /*
    for(int i = 0; i < 5 ; i++){
        sumi = ((a[i]-1) / 10 + 1) * 10;
        for(int j = 0; j < 5 ; j++){
            if(j != i){
                sumj = ((a[j]-1) / 10 + 1) * 10;
                for(int k = 0; k < 5; k++){
                    if(k != i && k != j){
                        sumk = ((a[k]-1) / 10 + 1) * 10;
                        for(int l = 0; l  < 5; l++){
                            if(l != i && l != j && l != k){
                                suml = ((a[l]-1) / 10 + 1) * 10;
                                for(int m = 0; m < 5; m++){
                                    if(m != i && m != j && m != k && m != l){
                                        summ = ((a[m]-1) / 10 + 1) * 10;
                                        sum = sumi + sumj + sumk + suml + summ;
                                        if(sum < min) min = sum;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    */

    cout << sum << endl;
    
}

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

ll n;
void Output(ll x,ll y,ll z) {printf("%lld %lld %lld\n", x, y, z);}
void Find_Ans() {
    for (int i = 1; i <= 3500; ++i) {
    	for (int j = 1; j <= 3500; ++j) {
            ll c = n * i * j, m = ((i * j) << 2) - n * (i + j);
            if (m > 0 && !(c % m)) {Output(i, j, c / m); return;}
        }
    }
}
int main() {
    scanf("%lld", &n);
    if (!(n & 1)) {Output(n, n, n >> 1); return 0;}
    if (!(n % 3)) {Output(n, (n / 3) << 1, (n / 3) << 1); return 0;}
    if (!((n + 1) & 3)) {Output((n + 1) >> 2,(n + 1) * (n + 1) >> 2,(n + 1) * (n + 1) * n>> 2); return 0;}
    if (!((n - 1) & 3)) Find_Ans();
    return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m, q;
	cin >>n >>m >>q;
	vector<VI> b(q, VI(4));
	rep(i, q){
		cin >>b[i][0] >>b[i][1] >>b[i][2] >>b[i][3];
		b[i][0]--; b[i][1]--;
	}
	ll ans = 0;
	int ym=n, xmx=m;
	vector<int> ct(ym,0);
	auto rcf =[&](auto rcf, int idx){
		if(idx==ym){
			ll sm =0;
			for(auto& x: b){
				if(ct[x[1]] - ct[x[0]] == x[2]) sm +=x[3];
			}
			//for(auto& x :ct) cerr<<x<<" "; dbg("::", sm);
			ans = max(ans, sm);
			return ;
		}
		rep(i, xmx){
			if(idx>0 && ct[idx-1]>i) continue;
			ct[idx]=i;
			rcf(rcf, idx+1);
		}
	};

	rcf(rcf, 0);
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

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

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

    ll n, m;
    cin >> n >> m;
    m -= n;
    ll rez = 1;
    for (int ctr1 = 0; ctr1 < n; ++ctr1)
        rez = rez * (n + m - ctr1) % MOD;

    ll dp[3];
    dp[0] = 1;
    dp[1] = m;
    for (int ctr1 = 2; ctr1 <= n; ++ctr1) {
        dp[ctr1 % 3] = (dp[(ctr1 + 2) % 3] * (ctr1 - 1 +  m) + dp[(ctr1 + 1) % 3] * (ctr1 - 1)) % MOD;
    }
    rez = rez * dp[n % 3] % MOD;

    cout << rez << '\n';
    return 0;
}


Measured memory_bytes: 3616
import sys
l = sys.stdin.readline().strip()
N, M = map(int, l.split())
impossible = set()

l = sys.stdin.readline().strip()
heights = [-1] + list(map(int, l.split()))

for i in range(M):
    l = sys.stdin.readline().strip()
    A, B = map(int, l.split())
    if A==B:
        continue
    if heights[A] == heights[B]:
        impossible.add(A)
        impossible.add(B)
    elif heights[A] < heights[B]:
        impossible.add(A)
    else:
        impossible.add(B)

print (N - len(impossible))

Measured memory_bytes: 84996
import itertools
N,K = map(int,input().split())
zahyou = []
for i in range(N):
  zahyou.append(list(map(int,input().split())))
ans = float('inf')
X = []
Y = []
for i in range(N):
  X.append(zahyou[i][0])
  Y.append(zahyou[i][1])
P = list(itertools.combinations(X,2))
Q = list(itertools.combinations(Y,2))
for i in range(len(P)):
  for j in range(len(Q)):
    x1 = min(P[i][0],P[i][1])
    x2 = max(P[i][0],P[i][1])
    y1 = min(Q[j][0],Q[j][1])
    y2 = max(Q[j][0],Q[j][1])
    cnt = 0
    for k in range(N):
      if x1 <= zahyou[k][0] <= x2 and y1 <= zahyou[k][1] <= y2:
        cnt += 1
    if cnt >= K:
      if ans >= (x2-x1)*(y2-y1):
        ans = (x2-x1)*(y2-y1)
print(ans)


Measured memory_bytes: 52572
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	int cnt = 0;
	if( n >= 105 ) ++cnt;
	if( n >= 135 ) ++cnt;
	if( n >= 165 ) ++cnt;
	if( n >= 189 ) ++cnt;
	if( n >= 195 ) ++cnt;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    for i in range(3):
        for j in range(3):
            if A[i][j] in b:
                A[i][j] = 0
    for i in range(3):
        row_flag = True
        for j in range(3):
            if A[i][j]!=0:
                row_flag = False
        if row_flag == True:
            print(YES)
            return
    for j in range(3):
        line_flag = True
        for i in range(3):
            if A[i][j]!=0:
                line_flag = False
        if line_flag == True:
            print(YES)
            return
    if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
        print(YES)
        return
    if A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
        print(YES)
        return
    print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [[int(next(tokens)) for _ in range(3)] for _ in range(3)]  # type: "List[List[int]]"
    N = int(next(tokens))  # type: int
    b = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(A, N, b)

if __name__ == '__main__':
    main()


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

using namespace std;

using ll = long long;

int const nmax = 1000000;
int const modulo = 998244353;
int v[1 + nmax];
ll sum[1 + nmax], sol[1 + nmax];

void gcd(int a, int b, int &x, int &y) {
  if(b == 0){
    x = 1;
    y = 0;
  } else {
    gcd(b, a % b, x, y);
    int aux = x;
    x = y;
    y = aux - a / b * y;
  }
}

int inv(int number){
  int x, y;
  gcd(number, modulo, x, y);
  x %= modulo;
  if(x < 0)
    x += modulo;
  return x;
}

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

  int n;
  cin >> n;

  for(int i = 1;i <= n; i++){
    cin >> v[i];
    sum[v[i]] += v[i];
  }

  for(int i = 1;i <= nmax; i++)
    for(int j = 2 * i; j <= nmax; j += i)
      sum[i] += sum[j];
  ll result = 0;

  for(int i = nmax; 1 <= i; i--) {
    sol[i] = 1LL * (sum[i] / i) % modulo * (sum[i] % modulo) % modulo;
    for(int j = 2 * i; j <= nmax; j += i) {
      sol[i] -= 1LL * sol[j] * (j / i) % modulo;
      if(sol[i] < 0)
        sol[i] += modulo;
    }

    result += sol[i];
    if(modulo <= result)
      result -= modulo;
  }
  cout << 1LL * ((modulo + result - sum[1] % modulo) * inv(2)) % modulo;
  return 0;
}


Measured memory_bytes: 18688
N = int(input())
S = list(input())
S_l = len(S)
ans = 0
from collections import deque
R = deque([])
G = deque([])
B  = deque([])
for i,s in enumerate(S):
    if s=='R':
        R.append(i)
    elif s=='G':
        G.append(i)
    elif s=='B':
        B.append(i)

def res(X,Y,S,i,a,b):
  x = X.copy()
  ret = 0
  for y in Y:
    if len(x)!=0:
      while x[0]<y:
        x.popleft()
        if len(x)==0:
          break
    ret+=len(x)
    tmp = 2*y-i
    if tmp>=S_l:
      continue
    if S[tmp]==a:
      ret-=1
  
  y = Y.copy()
  for x in X:
    if len(y)!=0:
      while y[0]<x:
        y.popleft()
        if len(y)==0:
          break
    ret+=len(y)
    tmp = 2*x-i
    if tmp>=S_l:
      continue
    if S[tmp]==b:
      ret-=1

      
  return ret
    
for i in range(len(S)):
    if S[i]=='R':
      r = R.popleft()
      ans += res(G,B,S,i,'G','B')
    elif S[i]=='G':
      g = G.popleft()
      ans += res(R,B,S,i,'R','B')
    else:
      b = B.popleft()
      ans += res(R,G,S,i,'R','G')
      
print(ans)

Measured memory_bytes: 84600
s = input()
t = input()
S = [""] * len(s)
T = [""] * len(s)
for i in range(len(s)):
    S[i] = s[i]
    T[i] = t[i]

chrset = set()
res = "Yes"
for i,s,t in zip(range(len(S)),S,T):
    if s == t:
        continue
    if (s in chrset) or (t in chrset):
        res = "No"
        break 
    for j in range(i,len(S)):
        if S[j] == s:
            S[j] = t 
        elif S[j] == t:
            S[j] = s 
    chrset.add(t)
print(res)

Measured memory_bytes: 6704
N,X,Y=map(int,input().split())
b=[0 for i in range(N+1)]
#print(b)
for i in range(1,N):
    for j in range(i+1,N+1):
        #print('{},{}'.format(i,j))
        minmin=min([abs(j-i),abs(X-i)+1+abs(Y-j)])
        #print(minmin)
        b[minmin]=1+b[minmin]

for i in range(1,N):

    print(b[i])


Measured memory_bytes: 45788
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
using namespace std;

#define F(i, n) for(int i = 0; i < n; ++i)
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 200*1000+47;

LL A[MAX];
int main()
{
    int n;
    scanf("%d", &n);
    LL s = 0;
    LL k = n *1LL* (n+1) / 2;
    FOR(i, 0, n)
    {
        scanf("%d", A + i);
        s += A[i];
    }
    A[n] = A[0];
    if (s % k)
    {
        printf("NO");
        return 0;
    }
    FOR(i, 0, n)
    {
        LL d = s/k - (A[i+1] - A[i]);
        if ( d < 0 || d % n)
        {
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    
    
    
    
}











Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
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; }

int main() {
  int N; cin >> N;
  vector<int> a(N);
  rep(i, 0, N) cin >> a[i];
  vector<int> e, o;
  rep(i, 0, N) {
    if(i & 1) e.push_back(a[i]);
    else o.push_back(a[i]);
  }
  if(N & 1) {
    reverse(o.begin(),o.end());
    rep(i, 0, o.size()) cout << o[i] << " ";
    rep(i, 0 ,e.size()) cout << e[i] << " ";
  } else {
    reverse(e.begin(),e.end());
    rep(i, 0, e.size()) cout << e[i] << " ";
    rep(i, 0 ,o.size()) cout << o[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define ll long long
#define INF INT_MAX 
#define mod 1000000007
using namespace std;
int main(){
    int N;
    cin >> N;
    int K,P;
    for(int i=0;i<N;i++){
        cin >> K >> P;
        if(K%P==0){
            cout << P << endl;
        }else{
            cout << K%P << endl;
        }
    }
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string a,b,c;
	cin>>a>>b>>c;
	cout<<a[0]<<b[1]<<c[2]<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

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

Measured memory_bytes: 22356
from collections import defaultdict
N = int(input())
ans = 0
c = defaultdict(int)

for i in range(1, N+1):
  s = int(str(i)[0])
  t = int(str(i)[-1])
  if s != 0 and t != 0:
    c[(s, t)] += 1

for i in range(1, 10):
  for j in range(1, 10):
    ans += c[(i, j)] * c[(j, i)]
print(ans)


Measured memory_bytes: 3316
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int S = sc.nextInt();
		int h, m, s;
		
		h = S / 3600;
		m = S % 3600 / 60;
		s = S % 60;
		System.out.println(h + ":" + m + ":" + s);
		sc.close();
	}
}


Measured memory_bytes: 26308
#include <iostream>
using namespace std;
int main(){
  int a;
  int b;
  cin>>a>>b;
  if(b>=100){
  a*=1000;
  }
  else if(b>=10){
  a*=100;
  }
  else if(b>=1){
  a*=10;
  }
  int thenum=a+b;
  for(int i=1;i<=thenum;i++){
  if(i*i==thenum){
    cout<<"Yes";
    return 0;
  }
  }
  cout<<"No";
}

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--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using P = pair<int,int>;

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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  vector<vector<int>> vec(200010);
  vec[A[0]].push_back(0);
  REP(i,N-1){
    if(A[i]!=A[i+1]){
      vec[A[i+1]].push_back(i+1);
    }
  }

  mint dp[200010]={0};
  vector<mint> memo(200010,0);
  dp[0]=1;
  memo[A[0]]+=1;
  REP(i,N-1){
    if(A[i+1]==A[i]){
      dp[i+1]=dp[i];
    }else{
      dp[i+1]=dp[i];
      dp[i+1]+=memo[A[i+1]];
      memo[A[i+1]]=dp[i+1];
    }
  }

  cout << dp[N-1] << endl;
}

Measured memory_bytes: 17944
#include<bits/stdc++.h>
#define re register
int g(re long long n)
{
	if(n==1)return 0;
	for(re int i=1;i<=64;i++)if((1ll<<i)>=n&&(1ll<<i)-g(i)>=n)return i;
}
int qq[110],ta,ans,fac[110],shu[210][110],p[10],p1[10];
bool ar[(1<<5)+1];
void init()
{
	fac[0]=1;
	for(re int i=1;i<=10;i++)fac[i]=fac[i-1]*i;
	for(re int i=1;i<=5;i++)p[i]=i;
	re int xx=0;
	do
	{
		xx++;
		re int xy=0;
		for(re int i=0;i<=4;i++)p1[i]=5-p[5-i];
		for(re int i=0;i<=31;i++)
		{
			xy=0;
			for(re int j=0;j<=4;j++)if(i&(1<<j))xy+=1<<p1[j];
			shu[xx][i]=xy;
		}
	}while(std::next_permutation(p+1,p+6));
}
bool check(re int k)
{
	memset(ar,0,sizeof(ar));
	for(re int i=1;i<=ta;i++)ar[qq[i]]=1;
	for(re int i=2;i<=fac[k];i++)
	{
		re bool all=1;
		for(re int j=1;j<=ta;j++)all&=ar[shu[i][qq[j]]];
		if(all)return 0;
	}
	//printf("****%d %d %d %d %d\n",qq[1],qq[2],qq[3],qq[4],ta);
	return 1;
}
void dfs(re int k,re int n)
{
	if(n==0){ans+=check(k);return;}
	for(re int i=qq[ta]+1;i<(1<<k)-n+1&&ans<=fac[k]*1000;i++)
	{
		qq[++ta]=i;
		dfs(k,n-1);
		ta--;
	}
}
void sol(re long long n,re long long k)
{
	if(n<k)sol(k,n);
	else if(n>(1ll<<k)-n)sol((1ll<<k)-n,k);
	else
	{
		if(k>=6)puts("-1"),exit(0);//printf("****%lld %lld %d\n",n,k,ta);
		dfs(k,n);
		if(ans>fac[k]*1000)puts("-1"),exit(0);ans/=fac[k];
	}
}
int main()
{
	re long long n;
	init();
	qq[0]=-1;
	scanf("%lld",&n);
	sol(n,g(n));
    if(n==4)ans++;
    if(n==7)ans+=2;
    printf("%d\n",ans);
}

Measured memory_bytes: 3880
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<climits>
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>

using namespace std;

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

int main(){
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n && n != 0){
    vector<pair<int,int> > v;
    v.push_back(make_pair(0,0));
    for(int i = 0;i < n-1;i++){
      int n,d;
      cin >> n >> d;
      v.push_back(make_pair(v[n].first + dx[d], v[n].second + dy[d]));
    }
    int wmin = 0,wmax = 0;
    int hmin = 0,hmax = 0;
    for(int i = 0;i < n;i++){
      wmin = min(v[i].first,wmin);
      wmax = max(v[i].first,wmax);
      hmin = min(v[i].second,hmin);
      hmax = max(v[i].second,hmax);
    }
    cout << wmax - wmin + 1 << ' ' << hmax - hmin + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#binary search

def binary_search(A,x):

	target = x

	def bin_rec(left=0, right=len(A) - 1):

		if left > right:
			print("0")
			return

		else:
			mid = (left + right) // 2

			if A[mid] == target:
				print("1")
				return
			elif A[mid] < target:
				return bin_rec(mid + 1, right)
			else:
				return bin_rec(left, mid - 1)

	bin_rec()

if __name__ == '__main__':

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

	for _ in range(n):
		x = int(input())
		binary_search(A,x)




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

using namespace std;
int main() {
    int n;
    cin >> n;
    std::vector<int> A(n);
    int a;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
        cout << A[0];
        for (int i = 1; i < n; i++) {
            cout << ' ' << A[i];
        }
        cout << endl;
    
    for (int i = 1; i < n; i++) {
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        
        cout << A[0];
        for (int i = 1; i < n; i++) {
            cout << ' ' << A[i];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
struct st
{
    ll a,b;
};
bool cmp(st x, st y)
{
    return x.a<y.a;
}
int main()
{
    ll ans, i, n;
    st arr[100005];
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>arr[i].a>>arr[i].b;
    }
    sort(arr, arr+n, cmp);

    ans= arr[n-1].a+arr[n-1].b;
    cout<<ans<<endl;
}


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

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

    int s = 1;
    int cou = 1;
    while (1){
        if(cou == k || s > n){
            if(s > n){
                cout << "NO" << endl;
            }else{
                cout << "YES" << endl;
            }
            break;
        }
        s += 2;
        cou++;
    }
    
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

a = [i-1 for i in a]

d = [1]*n
p = 0
b = []
while d[p]:
    b.append(p)
    d[p] = 0
    p = a[p]
avant = b.index(p)
loop_count = len(b) - avant
c = b[avant:]

if k <= avant:
    print(b[k]+1)
else:
    k -= avant
    k %= loop_count
    print(c[k]+1)


Measured memory_bytes: 32320
n, k = [int(i) for i in input().split()]
heights = [int(input()) for i in range(n)]

heights.sort()

# あり得る最大のサイズ差
answer = max(heights) - min(heights)

for i in range(0, n-k+1):
    candidate = heights[i+k-1] - heights[i]
    if candidate < answer:
        answer = candidate

print(answer)

Measured memory_bytes: 7384
/* << IN THE NAME OF GOD >> */
#include <bits/stdc++.h>
using namespace std;



#define err(x) cerr << #x  << " = "<<  x << '\n'
#define out(x) cout << x << '\n'
#define forp(i, r, l) for(int i = int(r); i < int(l); i++)
#define forn(i, r, l) for(int i = int(r); i > int(l); i--)
#define FAST ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll ,ll> pll;
const int maxn = 1e2 + 120;

bool t[maxn][maxn] ,a[maxn] ,b[maxn];
int h ,w;

int main(){FAST;   
    cin >> h >> w;
    forp(i ,0 ,h){
        bool s = 1;

        forp(j ,0 ,w){
            char ch;
            
            cin >> ch;
            ch == '#'? t[i][j] : t[i][j] = 1;
            if(!t[i][j])
                s = 0;
            }
        if(s)
            a[i] = 1;
    }
    forp(i ,0 ,w){
        bool s = 1;
        forp(j ,0 ,h)
            if(!t[j][i])
                s = 0;
        if(s)
            b[i] = 1;
    }
    forp(i ,0 ,h){
        forp(j ,0 ,w)
            if(!a[i] && !b[j])
                t[i][j] ? cout << '.' : cout << '#';
        cout << '\n';
    }



return 0;
}
 










Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  a <- unsafeTextToInt <$> T.getLine :: IO Int
  s <- T.getLine :: IO T.Text
  T.putStrLn $ if a < 3200 then T.pack "red" else s

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


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

using namespace std;

bool comp(string a, string b);

int main(){
    string s, t, copied, result;
    vector<string> ans;
    //cin >> s >> t;
    getline(cin, s);
    getline(cin, t);
    string::iterator j, ti;
    copied.resize(s.size());
    result.resize(s.size());
    if(s.size() < t.size() || t.size() == 0){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for(int i = 0; i < s.size() - t.size() + 1; i++){
        copy(s.begin(),s.end() , copied.begin());
        j = copied.begin() + i;
        for(ti = t.begin(); ti < t.end(); ti++){
            if(*j == '?'){
                *j = *ti;
            }else if(*j != *ti){
                break;
            }
            j++;
        }
        
        if(ti == t.end()){
            transform(copied.begin(), copied.end(), result.begin(), [](char c){ return c == '?' ? 'a' : c; });
            ans.push_back(result);
        }
    }
    if(ans.size() != 0){
        sort(ans.begin(), ans.end(), comp);
        cout << ans[0] << endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }
    return 0;
}

bool comp(string a, string b){
    for(int i = 0; i < min(a.size(), b.size()); i++){
        if(a[i] < b[i]) 
            return true;
        else if(a[i] > b[i])
            return false;
    }
    if(a.size() < b.size())
        return true;
    else
        return false;
}


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()

int main() {
   string s,t;
   cin >> s >> t;
   string u=s, ans="No";
   while(1){
      u=u[u.size()-1]+u;
      u.pop_back();
      if(u==t)
      ans="Yes";
      if(u==s)
      break;
   }
   cout << ans << endl;
}

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

class UnionFind {
public:
  vector<int> par, rank;
  UnionFind(int n) {
    par.resize(n), rank.resize(n);
    for (int i = 0; i < n; i++) par[i] = i;
  }

  int root(int a) {
    if (par[a] == a) return a;
    else return par[a] = root(par[a]);
  }

  bool isConnect(int a, int b) { return root(a) == root(b); }

  void connect(int a, int b) {
    a = root(a);
    b = root(b);
    if (a == b) return;
    if (rank[a] < rank[b]) {
      par[a] = b;
    } else {
      par[b] = a;
      if (rank[a] == rank[b]) rank[a]++;
    }
  }
};

bool solve() {
  int N, M;
  cin >> N >> M;
  UnionFind uf(N + M);
  vector<int> used(N + M);
  rep(i, 0, N) {
    int K; cin >> K;
    used[i] = true;
    rep(j, 0, K) {
      int L; cin >> L; L--;
      uf.connect(i, N + L);
      used[N+L] = true;
    }
  }
  set<int> st;
  rep(i, 0, N + M) if(used[i]) st.insert(uf.root(i));
  return st.size() == 1;
}

int main() {
  cout << (solve() ? "YES" : "NO") << endl;
  return 0;
}


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

int main(void){
    long long int i, j, min, ans=0;
    double w, h, x, y;
    scanf("%lf %lf %lf %lf", &w, &h, &x, &y);
    if(x==w/2&&y==h/2) ans++;
    printf("%lf %lld", w*h/2, ans);
    
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>

using namespace std;

int  P(pair<string,int>* A,int p,int r);
void Quicksort(pair<string,int>* A,int p,int r);

int main()
{
    pair<string,int> *a,*da;
    int N,num;
	cin>>N;
	a=new pair<string,int>[N];
	da=new pair<string,int>[N];
	for(int i=0;i<N;i++){
		cin>>a[i].first>>a[i].second;
		da[i]=a[i];
	}

	Quicksort(a,0,N-1);

	stable_sort(da,da+N,[](const pair<string,int>& wa,const pair<string,int>& wb){
        return wa.second<wb.second;
	});
    
	int j;
	for(j=0;j<N;j++){
		if(da[j].first!=a[j].first){
			cout<<"Not stable"<<endl;
			break;
		}
	}
	if(j==N){
		cout<<"Stable"<<endl;
	}
	for(int i=0;i<N;i++){
        cout<<a[i].first<<' '<<a[i].second<<endl;
    }
}
int  P(pair<string,int>* A,int p,int r)
{
	int x=A[r].second;
	int i=p-1;
	for(int j=p;j<r;j++){
		if(A[j].second <= x){
            i++;
			swap(A[i],A[j]);
		}
	}
	swap(A[i+1],A[r]);
	return i+1;
}
void Quicksort(pair<string,int>* A,int p,int r)
{
	if(p<r){
		int q=P(A,p,r);
		Quicksort(A, p, q-1);
		Quicksort(A, q+1, r);
	}
}

Measured memory_bytes: 10504
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    ll n,m;
    cin >> n >> m;
    vi a(n);
    cin >> a;
    sort(all(a));
    int ok = 2,ng = inf;
    auto f = [&](int x) {
        ll cnt = 0;
        rep(i,n) {
            auto it = lower_bound(all(a),x-a[i]);
            cnt += a.end()-it;
        }
        return cnt >= m;
    };
    while(abs(ok-ng) > 1) {
        int mid = (ng+ok)/2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    vl sum(n+1,0);
    rrep(i,n) sum[i] = sum[i+1]+a[i];
    ll ans = 0;
    ll cnt = 0;
    rep(i,n) {
        auto it = lower_bound(all(a),ok-a[i]);
        ans += sum[it-a.begin()];
        ans += (ll)a[i]*(a.end()-it);
        cnt += a.end()-it;
    }
    if(cnt > m) ans -= ok*(cnt-m);
    cout << ans << endl;
}


Measured memory_bytes: 1408
num = gets.chomp.to_i
out_time = 0
array = []
score = 0
while true
    str = gets.chomp
    break if str.nil?
    case str
    when "HIT"
    array << 1
    if array.length >= 4
        array.delete_at(array.length - 1)
        score += 1
    end
    when "HOMERUN"
    score += array.length + 1
    array = []
    when "OUT"
    out_time += 1
    else
    end
    if out_time == 3
        puts score.to_s
        out_time = 0
        score = 0
        array = []
        num -= 1
        if num == 0
            break
        end
    end
end

Measured memory_bytes: 8664
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    return format!("{}", n / 3);
}


Measured memory_bytes: 2076